Kernel.st 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482
  1. nil subclass: #Object
  2. instanceVariableNames: ''
  3. category: 'Kernel'!
  4. !Object methodsFor: 'accessing'!
  5. yourself
  6. ^self
  7. !
  8. class
  9. <return self.klass>
  10. !
  11. size
  12. self error: 'Object not indexable'
  13. !
  14. instVarAt: aString
  15. <return self['@'+aString]>
  16. !
  17. instVarAt: aString put: anObject
  18. <self['@' + aString] = anObject>
  19. !
  20. basicAt: aString
  21. <return self[aString]>
  22. !
  23. basicAt: aString put: anObject
  24. <return self[aString] = anObject>
  25. !
  26. basicDelete: aString
  27. <delete self[aString]>
  28. ! !
  29. !Object methodsFor: 'comparing'!
  30. = anObject
  31. <return self == anObject>
  32. !
  33. ~= anObject
  34. ^(self = anObject) == false
  35. ! !
  36. !Object methodsFor: 'converting'!
  37. -> anObject
  38. ^Association key: self value: anObject
  39. !
  40. asString
  41. ^self printString
  42. !
  43. asJavascript
  44. ^self asString
  45. !
  46. asJSON
  47. <return JSON.stringify(self._asJSONObject())>
  48. !
  49. asJSONObject
  50. | object |
  51. object := Object new.
  52. self class instanceVariableNames do: [:each |
  53. object basicAt: each put: (self instVarAt: each) asJSONObject].
  54. ^object
  55. ! !
  56. !Object methodsFor: 'copying'!
  57. copy
  58. ^self shallowCopy postCopy
  59. !
  60. shallowCopy
  61. <
  62. var copy = self.klass._new();
  63. for(var i in self) {
  64. if(/^@.+/.test(i)) {
  65. copy[i] = self[i];
  66. }
  67. }
  68. return copy;
  69. >
  70. !
  71. deepCopy
  72. <
  73. var copy = self.klass._new();
  74. for(var i in self) {
  75. if(/^@.+/.test(i)) {
  76. copy[i] = self[i]._deepCopy();
  77. }
  78. }
  79. return copy;
  80. >
  81. !
  82. postCopy
  83. ! !
  84. !Object methodsFor: 'error handling'!
  85. error: aString
  86. Error signal: aString
  87. !
  88. subclassResponsibility
  89. self error: 'This method is a responsibility of a subclass'
  90. !
  91. shouldNotImplement
  92. self error: 'This method should not be implemented in ', self class name
  93. !
  94. try: aBlock catch: anotherBlock
  95. <try{aBlock()} catch(e) {anotherBlock(e)}>
  96. !
  97. doesNotUnderstand: aMessage
  98. MessageNotUnderstood new
  99. receiver: self;
  100. message: aMessage;
  101. signal
  102. !
  103. halt
  104. self error: 'Halt encountered'
  105. ! !
  106. !Object methodsFor: 'initialization'!
  107. initialize
  108. ! !
  109. !Object methodsFor: 'message handling'!
  110. perform: aSymbol
  111. ^self perform: aSymbol withArguments: #()
  112. !
  113. perform: aSymbol withArguments: aCollection
  114. ^self basicPerform: aSymbol asSelector withArguments: aCollection
  115. !
  116. basicPerform: aSymbol
  117. ^self basicPerform: aSymbol withArguments: #()
  118. !
  119. basicPerform: aSymbol withArguments: aCollection
  120. <return self[aSymbol].apply(self, aCollection);>
  121. ! !
  122. !Object methodsFor: 'printing'!
  123. printString
  124. ^'a ', self class name
  125. !
  126. printNl
  127. <console.log(self)>
  128. ! !
  129. !Object methodsFor: 'testing'!
  130. isKindOf: aClass
  131. ^(self isMemberOf: aClass)
  132. ifTrue: [true]
  133. ifFalse: [self class inheritsFrom: aClass]
  134. !
  135. isMemberOf: aClass
  136. ^self class = aClass
  137. !
  138. ifNil: aBlock
  139. ^self
  140. !
  141. ifNil: aBlock ifNotNil: anotherBlock
  142. ^anotherBlock value
  143. !
  144. ifNotNil: aBlock
  145. ^aBlock value
  146. !
  147. ifNotNil: aBlock ifNil: anotherBlock
  148. ^aBlock value
  149. !
  150. isNil
  151. ^false
  152. !
  153. notNil
  154. ^self isNil not
  155. !
  156. isClass
  157. ^false
  158. !
  159. isMetaclass
  160. ^false
  161. !
  162. isNumber
  163. ^false
  164. !
  165. isString
  166. ^false
  167. !
  168. isParseFailure
  169. ^false
  170. ! !
  171. !Object class methodsFor: 'initialization'!
  172. initialize
  173. "no op"
  174. ! !
  175. Object subclass: #Smalltalk
  176. instanceVariableNames: ''
  177. category: 'Kernel'!
  178. !Smalltalk methodsFor: 'accessing'!
  179. classes
  180. <return self.classes()>
  181. !
  182. readJSON: anObject
  183. <return self.readJSObject(anObject)>
  184. !
  185. at: aString
  186. <return self[aString]>
  187. !
  188. removeClass: aClass
  189. aClass isMetaclass ifTrue: [self error: aClass asString, ' is a Metaclass and cannot be removed!!'].
  190. aClass methodDictionary values do: [:each |
  191. aClass removeCompiledMethod: each].
  192. aClass class methodDictionary values do: [:each |
  193. aClass class removeCompiledMethod: each].
  194. self basicDelete: aClass name
  195. ! !
  196. Smalltalk class instanceVariableNames: 'current'!
  197. !Smalltalk class methodsFor: 'accessing'!
  198. current
  199. <return smalltalk>
  200. ! !
  201. Object subclass: #Behavior
  202. instanceVariableNames: ''
  203. category: 'Kernel'!
  204. !Behavior methodsFor: 'accessing'!
  205. name
  206. <return self.className || nil>
  207. !
  208. superclass
  209. <return self.superclass || nil>
  210. !
  211. subclasses
  212. <return smalltalk.subclasses(self)>
  213. !
  214. allSubclasses
  215. | result |
  216. result := self subclasses.
  217. self subclasses do: [:each |
  218. result addAll: each allSubclasses].
  219. ^result
  220. !
  221. withAllSubclasses
  222. ^(Array with: self) addAll: self allSubclasses; yourself
  223. !
  224. prototype
  225. <return self.fn.prototype>
  226. !
  227. methodDictionary
  228. <var dict = smalltalk.Dictionary._new();
  229. var methods = self.fn.prototype.methods;
  230. for(var i in methods) {
  231. if(methods[i].selector) {
  232. dict._at_put_(methods[i].selector, methods[i]);
  233. }
  234. };
  235. return dict>
  236. !
  237. methodsFor: aString
  238. ^ClassCategoryReader new
  239. class: self category: aString;
  240. yourself
  241. !
  242. addCompiledMethod: aMethod
  243. <smalltalk.addMethod(aMethod.selector._asSelector(), aMethod, self)>
  244. !
  245. instanceVariableNames
  246. <return self.iVarNames>
  247. !
  248. comment
  249. ^(self basicAt: 'comment') ifNil: ['']
  250. !
  251. comment: aString
  252. self basicAt: 'comment' put: aString
  253. !
  254. commentStamp
  255. ^ClassCommentReader new
  256. class: self;
  257. yourself
  258. !
  259. removeCompiledMethod: aMethod
  260. <delete self.fn.prototype[aMethod.selector._asSelector()];
  261. delete self.fn.prototype.methods[aMethod.selector];
  262. smalltalk.init(self);>
  263. !
  264. protocols
  265. | protocols |
  266. protocols := Array new.
  267. self methodDictionary do: [:each |
  268. (protocols includes: each category) ifFalse: [
  269. protocols add: each category]].
  270. ^protocols sort
  271. !
  272. protocolsDo: aBlock
  273. "Execute aBlock for each method category with
  274. its collection of methods in the sort order of category name."
  275. | methodsByCategory |
  276. methodsByCategory := Dictionary new.
  277. self methodDictionary values do: [:m |
  278. (methodsByCategory at: m category ifAbsentPut: [Array new])
  279. add: m].
  280. self protocols do: [:category |
  281. aBlock value: category value: (methodsByCategory at: category)]
  282. !
  283. allInstanceVariableNames
  284. | result |
  285. result := self instanceVariableNames copy.
  286. self superclass ifNotNil: [
  287. result addAll: self superclass allInstanceVariableNames].
  288. ^result
  289. !
  290. methodAt: aString
  291. <return smalltalk.methods(self)[aString]>
  292. ! !
  293. !Behavior methodsFor: 'instance creation'!
  294. new
  295. ^self basicNew initialize
  296. !
  297. basicNew
  298. <return new self.fn()>
  299. !
  300. inheritsFrom: aClass
  301. ^aClass allSubclasses includes: self
  302. ! !
  303. Behavior subclass: #Class
  304. instanceVariableNames: ''
  305. category: 'Kernel'!
  306. !Class methodsFor: 'accessing'!
  307. category
  308. <return self.category>
  309. !
  310. category: aString
  311. <self.category = aString>
  312. !
  313. rename: aString
  314. <
  315. smalltalk[aString] = self;
  316. delete smalltalk[self.className];
  317. self.className = aString;
  318. >
  319. ! !
  320. !Class methodsFor: 'class creation'!
  321. subclass: aString instanceVariableNames: anotherString
  322. ^self subclass: aString instanceVariableNames: anotherString category: nil
  323. !
  324. subclass: aString instanceVariableNames: aString2 category: aString3
  325. ^ClassBuilder new
  326. superclass: self subclass: aString instanceVariableNames: aString2 category: aString3
  327. ! !
  328. !Class methodsFor: 'printing'!
  329. printString
  330. ^self name
  331. ! !
  332. !Class methodsFor: 'testing'!
  333. isClass
  334. ^true
  335. ! !
  336. Behavior subclass: #Metaclass
  337. instanceVariableNames: ''
  338. category: 'Kernel'!
  339. !Metaclass methodsFor: 'accessing'!
  340. instanceClass
  341. <return self.instanceClass>
  342. !
  343. instanceVariableNames: aCollection
  344. ClassBuilder new
  345. class: self instanceVariableNames: aCollection
  346. ! !
  347. !Metaclass methodsFor: 'printing'!
  348. printString
  349. ^self instanceClass name, ' class'
  350. ! !
  351. !Metaclass methodsFor: 'testing'!
  352. isMetaclass
  353. ^true
  354. ! !
  355. Object subclass: #CompiledMethod
  356. instanceVariableNames: ''
  357. category: 'Kernel'!
  358. !CompiledMethod methodsFor: 'accessing'!
  359. source
  360. ^(self basicAt: 'source') ifNil: ['']
  361. !
  362. source: aString
  363. self basicAt: 'source' put: aString
  364. !
  365. category
  366. ^(self basicAt: 'category') ifNil: ['']
  367. !
  368. category: aString
  369. self basicAt: 'category' put: aString
  370. !
  371. selector
  372. ^self basicAt: 'selector'
  373. !
  374. selector: aString
  375. self basicAt: 'selector' put: aString
  376. !
  377. fn
  378. ^self basicAt: 'fn'
  379. !
  380. fn: aBlock
  381. self basicAt: 'fn' put: aBlock
  382. !
  383. messageSends
  384. ^self basicAt: 'messageSends'
  385. !
  386. methodClass
  387. ^self basicAt: 'methodClass'
  388. !
  389. referencedClasses
  390. ^self basicAt: 'referencedClasses'
  391. ! !
  392. Object subclass: #Number
  393. instanceVariableNames: ''
  394. category: 'Kernel'!
  395. !Number methodsFor: 'arithmetic'!
  396. + aNumber
  397. <return self + aNumber>
  398. !
  399. - aNumber
  400. <return self - aNumber>
  401. !
  402. * aNumber
  403. <return self * aNumber>
  404. !
  405. / aNumber
  406. <return self / aNumber>
  407. !
  408. max: aNumber
  409. <return Math.max(self, aNumber);>
  410. !
  411. min: aNumber
  412. <return Math.min(self, aNumber);>
  413. !
  414. modulo: aNumber
  415. <return self % aNumber>
  416. ! !
  417. !Number methodsFor: 'comparing'!
  418. = aNumber
  419. <return Number(self) == aNumber>
  420. !
  421. > aNumber
  422. <return self >> aNumber>
  423. !
  424. < aNumber
  425. <return self < aNumber>
  426. !
  427. >= aNumber
  428. <return self >>= aNumber>
  429. !
  430. <= aNumber
  431. <return self <= aNumber>
  432. ! !
  433. !Number methodsFor: 'converting'!
  434. rounded
  435. <return Math.round(self);>
  436. !
  437. truncated
  438. <return Math.floor(self);>
  439. !
  440. to: aNumber
  441. | array first last count |
  442. first := self truncated.
  443. last := aNumber truncated + 1.
  444. count := 1.
  445. (first <= last) ifFalse: [self error: 'Wrong interval'].
  446. array := Array new.
  447. (last - first) timesRepeat: [
  448. array at: count put: first.
  449. count := count + 1.
  450. first := first + 1].
  451. ^array
  452. !
  453. asString
  454. ^self printString
  455. !
  456. asJavascript
  457. ^'(', self printString, ')'
  458. !
  459. atRandom
  460. ^(Random new next * self) truncated + 1
  461. !
  462. @ aNumber
  463. ^Point x: self y: aNumber
  464. !
  465. asPoint
  466. ^Point x: self y: self
  467. !
  468. asJSONObject
  469. ^self
  470. ! !
  471. !Number methodsFor: 'enumerating'!
  472. timesRepeat: aBlock
  473. | integer count |
  474. integer := self truncated.
  475. count := 1.
  476. [count > self] whileFalse: [
  477. aBlock value.
  478. count := count + 1]
  479. !
  480. to: aNumber do: aBlock
  481. ^(self to: aNumber) do: aBlock
  482. ! !
  483. !Number methodsFor: 'printing'!
  484. printString
  485. <return String(self)>
  486. ! !
  487. !Number methodsFor: 'testing'!
  488. isNumber
  489. ^true
  490. !
  491. even
  492. ^ 0 = (self modulo: 2)
  493. !
  494. odd
  495. ^ self even not
  496. ! !
  497. !Number methodsFor: 'timeouts/intervals'!
  498. clearInterval
  499. <clearInterval(Number(self))>
  500. !
  501. clearTimeout
  502. <clearTimeout(Number(self))>
  503. ! !
  504. !Number class methodsFor: 'instance creation'!
  505. pi
  506. <return Math.PI>
  507. ! !
  508. Object subclass: #BlockClosure
  509. instanceVariableNames: ''
  510. category: 'Kernel'!
  511. !BlockClosure methodsFor: 'accessing'!
  512. compiledSource
  513. <return self.toString()>
  514. ! !
  515. !BlockClosure methodsFor: 'controlling'!
  516. whileTrue: aBlock
  517. <while(self()) {aBlock()}>
  518. !
  519. whileFalse: aBlock
  520. <while(!!self()) {aBlock()}>
  521. ! !
  522. !BlockClosure methodsFor: 'error handling'!
  523. on: anErrorClass do: aBlock
  524. self try: self catch: [:error |
  525. (error isKindOf: anErrorClass)
  526. ifTrue: [aBlock value: error]
  527. ifFalse: [error signal]]
  528. ! !
  529. !BlockClosure methodsFor: 'evaluating'!
  530. value
  531. <return self();>
  532. !
  533. value: anArg
  534. <return self(anArg);>
  535. !
  536. value: firstArg value: secondArg
  537. <return self(firstArg, secondArg);>
  538. !
  539. value: firstArg value: secondArg value: thirdArg
  540. <return self(firstArg, secondArg, thirdArg);>
  541. !
  542. valueWithPossibleArguments: aCollection
  543. <return self.apply(null, aCollection);>
  544. ! !
  545. !BlockClosure methodsFor: 'printing'!
  546. printString
  547. ^ String streamContents: [:aStream|
  548. aStream
  549. nextPutAll: super printString;
  550. nextPutAll: '(';
  551. nextPutAll: self compiledSource;
  552. nextPutAll: ')';
  553. cr.
  554. ]
  555. ! !
  556. !BlockClosure methodsFor: 'timeout/interval'!
  557. valueWithTimeout: aNumber
  558. <return setTimeout(self, aNumber)>
  559. !
  560. valueWithInterval: aNumber
  561. <return setInterval(self, aNumber)>
  562. ! !
  563. Object subclass: #Boolean
  564. instanceVariableNames: ''
  565. category: 'Kernel'!
  566. !Boolean methodsFor: 'comparing'!
  567. = aBoolean
  568. <return Boolean(self == true) == aBoolean>
  569. !
  570. asJSONObject
  571. ^self
  572. ! !
  573. !Boolean methodsFor: 'controlling'!
  574. ifTrue: aBlock
  575. ^self ifTrue: aBlock ifFalse: []
  576. !
  577. ifFalse: aBlock
  578. ^self ifTrue: [] ifFalse: aBlock
  579. !
  580. ifFalse: aBlock ifTrue: anotherBlock
  581. ^self ifTrue: anotherBlock ifFalse: aBlock
  582. !
  583. ifTrue: aBlock ifFalse: anotherBlock
  584. <
  585. if(self == true) {
  586. return aBlock();
  587. } else {
  588. return anotherBlock();
  589. }
  590. >
  591. !
  592. and: aBlock
  593. ^self = true
  594. ifTrue: aBlock
  595. ifFalse: [false]
  596. !
  597. or: aBlock
  598. ^self = true
  599. ifTrue: [true]
  600. ifFalse: aBlock
  601. !
  602. not
  603. ^self = false
  604. ! !
  605. !Boolean methodsFor: 'copying'!
  606. shallowCopy
  607. ^self
  608. !
  609. deepCopy
  610. ^self
  611. ! !
  612. !Boolean methodsFor: 'printing'!
  613. printString
  614. <return self.toString()>
  615. ! !
  616. Object subclass: #Date
  617. instanceVariableNames: ''
  618. category: 'Kernel'!
  619. !Date commentStamp!
  620. The Date class is used to work with dates and times.!
  621. !Date methodsFor: 'accessing'!
  622. year
  623. <return self.getFullYear()>
  624. !
  625. month
  626. <return self.getMonth() + 1>
  627. !
  628. month: aNumber
  629. <self.setMonth(aNumber - 1)>
  630. !
  631. day
  632. ^self dayOfWeek
  633. !
  634. dayOfWeek
  635. <return self.getDay() + 1>
  636. !
  637. dayOfWeek: aNumber
  638. <return self.setDay(aNumber - 1)>
  639. !
  640. day: aNumber
  641. self day: aNumber
  642. !
  643. year: aNumber
  644. <self.setFullYear(aNumber)>
  645. !
  646. dayOfMonth
  647. <return self.getDate()>
  648. !
  649. dayOfMonth: aNumber
  650. <self.setDate(aNumber)>
  651. !
  652. time
  653. <return self.getTime()>
  654. !
  655. time: aNumber
  656. <self.setTime(aNumber)>
  657. !
  658. hours: aNumber
  659. <self.setHours(aNumber)>
  660. !
  661. minutes: aNumber
  662. <self.setMinutes(aNumber)>
  663. !
  664. seconds: aNumber
  665. <self.setSeconds(aNumber)>
  666. !
  667. milliseconds: aNumber
  668. <self.setMilliseconds(aNumber)>
  669. !
  670. hours
  671. <return self.getHours()>
  672. !
  673. minutes
  674. <return self.getMinutes()>
  675. !
  676. seconds
  677. <return self.getSeconds()>
  678. !
  679. milliseconds
  680. <return self.getMilliseconds()>
  681. ! !
  682. !Date methodsFor: 'arithmetic'!
  683. - aDate
  684. <return self - aDate>
  685. !
  686. + aDate
  687. <return self + aDate>
  688. ! !
  689. !Date methodsFor: 'comparing'!
  690. < aDate
  691. <return self < aDate>
  692. !
  693. > aDate
  694. <return self >> aDate>
  695. !
  696. <= aDate
  697. <self <= aDate>
  698. !
  699. >= aDate
  700. <self >>= aDate>
  701. ! !
  702. !Date methodsFor: 'converting'!
  703. asString
  704. <return self.toString()>
  705. !
  706. asMilliseconds
  707. ^self time
  708. !
  709. asDateString
  710. <return self.toDateString()>
  711. !
  712. asTimeString
  713. <return self.toTimeString()>
  714. !
  715. asLocaleString
  716. <return self.toLocaleString()>
  717. !
  718. asNumber
  719. ^self asMilliseconds
  720. !
  721. asJSONObject
  722. ^self
  723. ! !
  724. !Date methodsFor: 'printing'!
  725. printString
  726. ^self asString
  727. ! !
  728. !Date class methodsFor: 'instance creation'!
  729. new: anObject
  730. <return new Date(anObject)>
  731. !
  732. fromString: aString
  733. "Example: Date fromString('2011/04/15 00:00:00')"
  734. ^self new: aString
  735. !
  736. fromSeconds: aNumber
  737. ^self fromMilliseconds: aNumber * 1000
  738. !
  739. fromMilliseconds: aNumber
  740. ^self new: aNumber
  741. !
  742. today
  743. ^self new
  744. !
  745. now
  746. ^self today
  747. !
  748. millisecondsToRun: aBlock
  749. | t |
  750. t := Date now.
  751. aBlock value.
  752. ^Date now - t
  753. ! !
  754. Object subclass: #UndefinedObject
  755. instanceVariableNames: ''
  756. category: 'Kernel'!
  757. !UndefinedObject methodsFor: 'class creation'!
  758. subclass: aString instanceVariableNames: anotherString
  759. ^self subclass: aString instanceVariableNames: anotherString category: nil
  760. !
  761. subclass: aString instanceVariableNames: aString2 category: aString3
  762. ^ClassBuilder new
  763. superclass: self subclass: aString instanceVariableNames: aString2 category: aString3
  764. ! !
  765. !UndefinedObject methodsFor: 'copying'!
  766. shallowCopy
  767. ^self
  768. !
  769. deepCopy
  770. ^self
  771. ! !
  772. !UndefinedObject methodsFor: 'printing'!
  773. printString
  774. ^'nil'
  775. ! !
  776. !UndefinedObject methodsFor: 'testing'!
  777. ifNil: aBlock
  778. ^self ifNil: aBlock ifNotNil: []
  779. !
  780. ifNotNil: aBlock
  781. ^self
  782. !
  783. ifNil: aBlock ifNotNil: anotherBlock
  784. ^aBlock value
  785. !
  786. ifNotNil: aBlock ifNil: anotherBlock
  787. ^anotherBlock value
  788. !
  789. isNil
  790. ^true
  791. !
  792. notNil
  793. ^false
  794. ! !
  795. !UndefinedObject class methodsFor: 'instance creation'!
  796. new
  797. self error: 'You cannot create new instances of UndefinedObject. Use nil'
  798. ! !
  799. Object subclass: #Collection
  800. instanceVariableNames: ''
  801. category: 'Kernel'!
  802. !Collection methodsFor: 'accessing'!
  803. size
  804. self subclassResponsibility
  805. !
  806. readStream
  807. ^self stream
  808. !
  809. writeStream
  810. ^self stream
  811. !
  812. stream
  813. ^self streamClass on: self
  814. !
  815. streamClass
  816. ^self class streamClass
  817. ! !
  818. !Collection methodsFor: 'adding/removing'!
  819. add: anObject
  820. self subclassResponsibility
  821. !
  822. addAll: aCollection
  823. aCollection do: [:each |
  824. self add: each].
  825. ^aCollection
  826. !
  827. remove: anObject
  828. self subclassResponsibility
  829. ! !
  830. !Collection methodsFor: 'converting'!
  831. asArray
  832. | array index |
  833. array := Array new.
  834. index := 0.
  835. self do: [:each |
  836. index := index + 1.
  837. array at: index put: each].
  838. ^array
  839. ! !
  840. !Collection methodsFor: 'copying'!
  841. , aCollection
  842. ^self copy
  843. addAll: aCollection;
  844. yourself
  845. !
  846. copyWith: anObject
  847. ^self copy add: anObject; yourself
  848. !
  849. copyWithAll: aCollection
  850. ^self copy addAll: aCollection; yourself
  851. ! !
  852. !Collection methodsFor: 'enumerating'!
  853. do: aBlock
  854. <for(var i=0;i<self.length;i++){aBlock(self[i]);}>
  855. !
  856. collect: aBlock
  857. | newCollection |
  858. newCollection := self class new.
  859. self do: [:each |
  860. newCollection add: (aBlock value: each)].
  861. ^newCollection
  862. !
  863. detect: aBlock
  864. ^self detect: aBlock ifNone: [self errorNotFound]
  865. !
  866. detect: aBlock ifNone: anotherBlock
  867. <
  868. for(var i = 0; i < self.length; i++)
  869. if(aBlock(self[i]))
  870. return self[i];
  871. return anotherBlock();
  872. >
  873. !
  874. do: aBlock separatedBy: anotherBlock
  875. | first |
  876. first := true.
  877. self do: [:each |
  878. first
  879. ifTrue: [first := false]
  880. ifFalse: [anotherBlock value].
  881. aBlock value: each]
  882. !
  883. inject: anObject into: aBlock
  884. | result |
  885. result := anObject.
  886. self do: [:each |
  887. result := aBlock value: result value: each].
  888. ^result
  889. !
  890. reject: aBlock
  891. ^self select: [:each | (aBlock value: each) = false]
  892. !
  893. select: aBlock
  894. | stream |
  895. stream := self class new writeStream.
  896. self do: [:each |
  897. (aBlock value: each) ifTrue: [
  898. stream nextPut: each]].
  899. ^stream contents
  900. ! !
  901. !Collection methodsFor: 'error handling'!
  902. errorNotFound
  903. self error: 'Object is not in the collection'
  904. ! !
  905. !Collection methodsFor: 'testing'!
  906. includes: anObject
  907. <
  908. var i = self.length;
  909. while (i--) {
  910. if (smalltalk.send(self[i], "__eq", [anObject])) {return true;}
  911. }
  912. return false
  913. >
  914. !
  915. notEmpty
  916. ^self isEmpty not
  917. !
  918. isEmpty
  919. ^self size = 0
  920. ! !
  921. !Collection class methodsFor: 'accessing'!
  922. streamClass
  923. ^Stream
  924. ! !
  925. !Collection class methodsFor: 'instance creation'!
  926. with: anObject
  927. ^self new
  928. add: anObject;
  929. yourself
  930. !
  931. with: anObject with: anotherObject
  932. ^self new
  933. add: anObject;
  934. add: anotherObject;
  935. yourself
  936. !
  937. with: firstObject with: secondObject with: thirdObject
  938. ^self new
  939. add: firstObject;
  940. add: secondObject;
  941. add: thirdObject;
  942. yourself
  943. !
  944. withAll: aCollection
  945. ^self new
  946. addAll: aCollection;
  947. yourself
  948. ! !
  949. Collection subclass: #SequenceableCollection
  950. instanceVariableNames: ''
  951. category: 'Kernel'!
  952. !SequenceableCollection methodsFor: 'accessing'!
  953. at: anIndex
  954. ^self at: anIndex ifAbsent: [
  955. self errorNotFound]
  956. !
  957. at: anIndex ifAbsent: aBlock
  958. self subclassResponsibility
  959. !
  960. at: anIndex put: anObject
  961. self subclassResponsibility
  962. !
  963. first
  964. ^self at: 1
  965. !
  966. fourth
  967. ^self at: 4
  968. !
  969. last
  970. ^self at: self size
  971. !
  972. second
  973. ^self at: 2
  974. !
  975. third
  976. ^self at: 3
  977. !
  978. allButFirst
  979. ^self copyFrom: 2 to: self size
  980. !
  981. allButLast
  982. ^self copyFrom: 1 to: self size - 1
  983. !
  984. indexOf: anObject
  985. ^self indexOf: anObject ifAbsent: [self errorNotFound]
  986. !
  987. indexOf: anObject ifAbsent: aBlock
  988. <
  989. for(var i=0;i<self.length;i++){
  990. if(self[i].__eq(anObject)) {return i+1}
  991. }
  992. return aBlock();
  993. >
  994. ! !
  995. !SequenceableCollection methodsFor: 'adding'!
  996. removeLast
  997. self remove: self last
  998. !
  999. addLast: anObject
  1000. self add: anObject
  1001. ! !
  1002. !SequenceableCollection methodsFor: 'copying'!
  1003. copyFrom: anIndex to: anotherIndex
  1004. self subclassResponsibility
  1005. ! !
  1006. !SequenceableCollection methodsFor: 'enumerating'!
  1007. withIndexDo: aBlock
  1008. <for(var i=0;i<self.length;i++){aBlock(self[i], i+1);}>
  1009. ! !
  1010. SequenceableCollection subclass: #String
  1011. instanceVariableNames: ''
  1012. category: 'Kernel'!
  1013. !String methodsFor: 'accessing'!
  1014. size
  1015. <return self.length>
  1016. !
  1017. at: anIndex
  1018. <return self[anIndex - 1]>
  1019. !
  1020. at: anIndex put: anObject
  1021. self errorReadOnly
  1022. !
  1023. at: anIndex ifAbsent: aBlock
  1024. (self at: anIndex) ifNil: [aBlock]
  1025. !
  1026. escaped
  1027. <return escape(self)>
  1028. !
  1029. unescaped
  1030. <return unescape(self)>
  1031. ! !
  1032. !String methodsFor: 'adding'!
  1033. add: anObject
  1034. self errorReadOnly
  1035. !
  1036. remove: anObject
  1037. self errorReadOnly
  1038. ! !
  1039. !String methodsFor: 'comparing'!
  1040. = aString
  1041. <return String(self) == aString>
  1042. !
  1043. > aString
  1044. <return String(self) >> aString>
  1045. !
  1046. < aString
  1047. <return String(self) < aString>
  1048. !
  1049. >= aString
  1050. <return String(self) >>= aString>
  1051. !
  1052. <= aString
  1053. <return String(self) <= aString>
  1054. ! !
  1055. !String methodsFor: 'converting'!
  1056. asSelector
  1057. "If you change this method, change smalltalk.convertSelector too (see js/boot.js file)"
  1058. | selector |
  1059. selector := '_', self.
  1060. selector := selector replace: ':' with: '_'.
  1061. selector := selector replace: '[+]' with: '_plus'.
  1062. selector := selector replace: '-' with: '_minus'.
  1063. selector := selector replace: '[*]' with: '_star'.
  1064. selector := selector replace: '[/]' with: '_slash'.
  1065. selector := selector replace: '>' with: '_gt'.
  1066. selector := selector replace: '<' with: '_lt'.
  1067. selector := selector replace: '=' with: '_eq'.
  1068. selector := selector replace: ',' with: '_comma'.
  1069. selector := selector replace: '[@]' with: '_at'.
  1070. ^selector
  1071. !
  1072. asJavascript
  1073. <
  1074. if(self.search(/^[a-zA-Z0-9_:.$ ]*$/) == -1)
  1075. return "unescape(\"" + escape(self) + "\")";
  1076. else
  1077. return "\"" + self + "\"";
  1078. >
  1079. !
  1080. tokenize: aString
  1081. <return self.split(aString)>
  1082. !
  1083. asString
  1084. ^self
  1085. !
  1086. asNumber
  1087. <return Number(self)>
  1088. !
  1089. asParser
  1090. ^PPStringParser new string: self
  1091. !
  1092. asChoiceParser
  1093. ^PPChoiceParser withAll: (self asArray collect: [:each | each asParser])
  1094. !
  1095. asCharacterParser
  1096. ^PPCharacterParser new string: self
  1097. !
  1098. asJSONObject
  1099. ^self
  1100. !
  1101. asLowercase
  1102. <return self.toLowerCase()>
  1103. !
  1104. asUppercase
  1105. <return self.toUpperCase()>
  1106. ! !
  1107. !String methodsFor: 'copying'!
  1108. , aString
  1109. <return self + aString>
  1110. !
  1111. copyFrom: anIndex to: anotherIndex
  1112. <return self.substring(anIndex - 1, anotherIndex)>
  1113. !
  1114. shallowCopy
  1115. ^self class fromString: self
  1116. !
  1117. deepCopy
  1118. ^self shallowCopy
  1119. ! !
  1120. !String methodsFor: 'error handling'!
  1121. errorReadOnly
  1122. self error: 'Object is read-only'
  1123. ! !
  1124. !String methodsFor: 'printing'!
  1125. printString
  1126. ^'''', self, ''''
  1127. !
  1128. printNl
  1129. <console.log(self)>
  1130. ! !
  1131. !String methodsFor: 'regular expressions'!
  1132. replace: aString with: anotherString
  1133. ^self replaceRegexp: (RegularExpression fromString: aString flag: 'g') with: anotherString
  1134. !
  1135. replaceRegexp: aRegexp with: aString
  1136. <return self.replace(aRegexp, aString)>
  1137. !
  1138. match: aRegexp
  1139. <return self.search(aRegexp) !!= -1>
  1140. !
  1141. trimLeft: separators
  1142. ^self replaceRegexp: (RegularExpression fromString: '^[', separators, ']+' flag: 'g') with: ''
  1143. !
  1144. trimRight: separators
  1145. ^self replaceRegexp: (RegularExpression fromString: '[', separators, ']+$' flag: 'g') with: ''
  1146. !
  1147. trimLeft
  1148. ^self trimLeft: '\s'
  1149. !
  1150. trimRight
  1151. ^self trimRight: '\s'
  1152. !
  1153. trimBoth
  1154. ^self trimBoth: '\s'
  1155. !
  1156. trimBoth: separators
  1157. ^(self trimLeft: separators) trimRight: separators
  1158. ! !
  1159. !String methodsFor: 'split join'!
  1160. join: aCollection
  1161. ^ String
  1162. streamContents: [:stream | aCollection
  1163. do: [:each | stream nextPutAll: each asString]
  1164. separatedBy: [stream nextPutAll: self]]
  1165. ! !
  1166. !String methodsFor: 'testing'!
  1167. isString
  1168. ^true
  1169. !
  1170. includesSubString: subString
  1171. < return self.indexOf(subString) !!= -1 >
  1172. ! !
  1173. !String class methodsFor: 'accessing'!
  1174. streamClass
  1175. ^StringStream
  1176. !
  1177. cr
  1178. <return '\r'>
  1179. !
  1180. lf
  1181. <return '\n'>
  1182. !
  1183. space
  1184. <return ' '>
  1185. !
  1186. tab
  1187. <return '\t'>
  1188. !
  1189. crlf
  1190. <return '\r\n'>
  1191. ! !
  1192. !String class methodsFor: 'instance creation'!
  1193. fromString: aString
  1194. <return new self.fn(aString)>
  1195. !
  1196. streamContents: blockWithArg
  1197. |stream|
  1198. stream := (self streamClass on: String new).
  1199. blockWithArg value: stream.
  1200. ^ stream contents
  1201. ! !
  1202. SequenceableCollection subclass: #Array
  1203. instanceVariableNames: ''
  1204. category: 'Kernel'!
  1205. !Array methodsFor: 'accessing'!
  1206. size
  1207. <return self.length>
  1208. !
  1209. at: anIndex put: anObject
  1210. <return self[anIndex - 1] = anObject>
  1211. !
  1212. at: anIndex ifAbsent: aBlock
  1213. <
  1214. var value = self[anIndex - 1];
  1215. if(value === undefined) {
  1216. return aBlock();
  1217. } else {
  1218. return value;
  1219. }
  1220. >
  1221. ! !
  1222. !Array methodsFor: 'adding/removing'!
  1223. add: anObject
  1224. <self.push(anObject); return anObject;>
  1225. !
  1226. remove: anObject
  1227. <
  1228. for(var i=0;i<self.length;i++) {
  1229. if(self[i] == anObject) {
  1230. self.splice(i,1);
  1231. break;
  1232. }
  1233. }
  1234. >
  1235. !
  1236. removeFrom: aNumber to: anotherNumber
  1237. <self.splice(aNumber - 1,anotherNumber - 1)>
  1238. ! !
  1239. !Array methodsFor: 'converting'!
  1240. asJavascript
  1241. ^'[', ((self collect: [:each | each asJavascript]) join: ', '), ']'
  1242. !
  1243. asJSONObject
  1244. ^self collect: [:each | each asJSONObject]
  1245. ! !
  1246. !Array methodsFor: 'copying'!
  1247. shallowCopy
  1248. | newCollection |
  1249. newCollection := self class new.
  1250. self do: [:each | newCollection add: each].
  1251. ^newCollection
  1252. !
  1253. deepCopy
  1254. | newCollection |
  1255. newCollection := self class new.
  1256. self do: [:each | newCollection add: each deepCopy].
  1257. ^newCollection
  1258. !
  1259. copyFrom: anIndex to: anotherIndex
  1260. | array |
  1261. array := self class new.
  1262. anIndex to: anotherIndex do: [:each |
  1263. array add: (self at: each)].
  1264. ^array
  1265. ! !
  1266. !Array methodsFor: 'enumerating'!
  1267. join: aString
  1268. <return self.join(aString)>
  1269. !
  1270. sort
  1271. ^self basicPerform: 'sort'
  1272. !
  1273. sort: aBlock
  1274. <
  1275. return self.sort(function(a, b) {
  1276. if(aBlock(a,b)) {return 1} else {return -1}
  1277. })
  1278. >
  1279. !
  1280. sorted
  1281. ^self copy sort
  1282. !
  1283. sorted: aBlock
  1284. ^self copy sorted: aBlock
  1285. !
  1286. printString
  1287. | str |
  1288. str := '' writeStream.
  1289. str nextPutAll: super printString, ' ('.
  1290. self
  1291. do: [:each | str nextPutAll: each printString]
  1292. separatedBy: [str nextPutAll: ' '].
  1293. str nextPutAll: ')'.
  1294. ^str contents
  1295. ! !
  1296. Object subclass: #RegularExpression
  1297. instanceVariableNames: ''
  1298. category: 'Kernel'!
  1299. !RegularExpression methodsFor: 'evaluating'!
  1300. compile: aString
  1301. <return self.compile(aString)>
  1302. !
  1303. exec: aString
  1304. <return self.exec(aString) || nil>
  1305. !
  1306. test: aString
  1307. <return self.test(aString)>
  1308. ! !
  1309. !RegularExpression class methodsFor: 'instance creation'!
  1310. fromString: aString flag: anotherString
  1311. <return new RegExp(aString, anotherString)>
  1312. !
  1313. fromString: aString
  1314. ^self fromString: aString flag: ''
  1315. ! !
  1316. Object subclass: #Error
  1317. instanceVariableNames: 'messageText'
  1318. category: 'Kernel'!
  1319. !Error methodsFor: 'accessing'!
  1320. messageText
  1321. ^messageText
  1322. !
  1323. messageText: aString
  1324. messageText := aString
  1325. !
  1326. context
  1327. <return self.context>
  1328. ! !
  1329. !Error methodsFor: 'signaling'!
  1330. signal
  1331. <self.context = thisContext; self.smalltalkError = true; throw(self)>
  1332. ! !
  1333. !Error class methodsFor: 'instance creation'!
  1334. signal: aString
  1335. ^self new
  1336. messageText: aString;
  1337. signal
  1338. ! !
  1339. Object subclass: #MethodContext
  1340. instanceVariableNames: ''
  1341. category: 'Kernel'!
  1342. !MethodContext methodsFor: 'accessing'!
  1343. receiver
  1344. <return self.receiver>
  1345. !
  1346. selector
  1347. <return smalltalk.convertSelector(self.selector)>
  1348. !
  1349. home
  1350. <return self.homeContext>
  1351. !
  1352. temps
  1353. <return self.temps>
  1354. !
  1355. printString
  1356. ^super printString, '(', self asString, ')'
  1357. !
  1358. asString
  1359. ^self receiver class printString, ' >> ', self selector
  1360. ! !
  1361. Object subclass: #Association
  1362. instanceVariableNames: 'key value'
  1363. category: 'Kernel'!
  1364. !Association methodsFor: 'accessing'!
  1365. key: aKey
  1366. key := aKey
  1367. !
  1368. key
  1369. ^key
  1370. !
  1371. value: aValue
  1372. value := aValue
  1373. !
  1374. value
  1375. ^value
  1376. ! !
  1377. !Association methodsFor: 'comparing'!
  1378. = anAssociation
  1379. ^self class = anAssociation class and: [
  1380. self key = anAssociation key and: [
  1381. self value = anAssociation value]]
  1382. ! !
  1383. !Association class methodsFor: 'instance creation'!
  1384. key: aKey value: aValue
  1385. ^self new
  1386. key: aKey;
  1387. value: aValue;
  1388. yourself
  1389. ! !
  1390. Collection subclass: #Dictionary
  1391. instanceVariableNames: 'keys'
  1392. category: 'Kernel'!
  1393. !Dictionary methodsFor: 'accessing'!
  1394. size
  1395. ^keys size
  1396. !
  1397. associations
  1398. | associations |
  1399. associations := #().
  1400. keys do: [:each |
  1401. associations add: (Association key: each value: (self at: each))].
  1402. ^associations
  1403. !
  1404. keys
  1405. ^keys copy
  1406. !
  1407. values
  1408. ^keys collect: [:each | self at: each]
  1409. !
  1410. at: aKey put: aValue
  1411. (keys includes: aKey) ifFalse: [keys add: aKey].
  1412. ^self basicAt: aKey put: aValue
  1413. !
  1414. at: aKey ifAbsent: aBlock
  1415. ^(self keys includes: aKey)
  1416. ifTrue: [self basicAt: aKey]
  1417. ifFalse: aBlock
  1418. !
  1419. at: aKey ifAbsentPut: aBlock
  1420. ^self at: aKey ifAbsent: [
  1421. self at: aKey put: aBlock value]
  1422. !
  1423. at: aKey ifPresent: aBlock
  1424. ^(self basicAt: aKey) ifNotNil: [aBlock value: (self at: aKey)]
  1425. !
  1426. at: aKey ifPresent: aBlock ifAbsent: anotherBlock
  1427. ^(self basicAt: aKey)
  1428. ifNil: anotherBlock
  1429. ifNotNil: [aBlock value: (self at: aKey)]
  1430. !
  1431. at: aKey
  1432. ^self at: aKey ifAbsent: [self errorNotFound]
  1433. ! !
  1434. !Dictionary methodsFor: 'adding/removing'!
  1435. add: anAssociation
  1436. self at: anAssociation key put: anAssociation value
  1437. !
  1438. addAll: aDictionary
  1439. super addAll: aDictionary associations.
  1440. ^aDictionary
  1441. !
  1442. remove: aKey
  1443. self removeKey: aKey
  1444. !
  1445. removeKey: aKey
  1446. keys remove: aKey
  1447. ! !
  1448. !Dictionary methodsFor: 'comparing'!
  1449. = aDictionary
  1450. self class = aDictionary class ifFalse: [^false].
  1451. self associationsDo: [:assoc |
  1452. (aDictionary at: assoc key ifAbsent: [^false]) = assoc value
  1453. ifFalse: [^false]].
  1454. ^true
  1455. ! !
  1456. !Dictionary methodsFor: 'converting'!
  1457. asJSONObject
  1458. | object |
  1459. object := Object new.
  1460. self keysAndValuesDo: [:key :value |
  1461. object basicAt: key put: value asJSONObject].
  1462. ^object
  1463. ! !
  1464. !Dictionary methodsFor: 'copying'!
  1465. shallowCopy
  1466. | copy |
  1467. copy := self class new.
  1468. self associationsDo: [:each |
  1469. copy at: each key put: each value].
  1470. ^copy
  1471. !
  1472. , aCollection
  1473. self shouldNotImplement
  1474. !
  1475. copyFrom: anIndex to: anotherIndex
  1476. self shouldNotImplement
  1477. ! !
  1478. !Dictionary methodsFor: 'enumerating'!
  1479. associationsDo: aBlock
  1480. self associations do: aBlock
  1481. !
  1482. keysAndValuesDo: aBlock
  1483. self associationsDo: [:each |
  1484. aBlock value: each key value: each value]
  1485. !
  1486. do: aBlock
  1487. self values do: aBlock
  1488. !
  1489. select: aBlock
  1490. | newDict |
  1491. newDict := self class new.
  1492. self keysAndValuesDo: [:key :value |
  1493. (aBlock value: value) ifTrue: [newDict at: key put: value]].
  1494. ^newDict
  1495. !
  1496. collect: aBlock
  1497. | newDict |
  1498. newDict := self class new.
  1499. self keysAndValuesDo: [:key :value |
  1500. newDict at: key put: (aBlock value: value)].
  1501. ^newDict
  1502. !
  1503. detect: aBlock ifNone: anotherBlock
  1504. ^self values detect: aBlock ifNone: anotherBlock
  1505. !
  1506. includes: anObject
  1507. ^self values includes: anObject
  1508. ! !
  1509. !Dictionary methodsFor: 'initialization'!
  1510. initialize
  1511. super initialize.
  1512. keys := #()
  1513. ! !
  1514. !Dictionary methodsFor: 'printing'!
  1515. printString
  1516. ^ String streamContents: [:aStream|
  1517. aStream
  1518. nextPutAll: super printString;
  1519. nextPutAll: '('.
  1520. self associations
  1521. do: [:anAssociation|
  1522. aStream
  1523. nextPutAll: anAssociation key printString;
  1524. nextPutAll: ' -> ';
  1525. nextPutAll: anAssociation value printString]
  1526. separatedBy: [aStream nextPutAll: ' , '].
  1527. aStream nextPutAll: ')'.
  1528. ]
  1529. ! !
  1530. Object subclass: #ClassBuilder
  1531. instanceVariableNames: ''
  1532. category: 'Kernel'!
  1533. !ClassBuilder methodsFor: 'class creation'!
  1534. superclass: aClass subclass: aString
  1535. self superclass: aClass subclass: aString instanceVariableNames: '' category: nil
  1536. !
  1537. superclass: aClass subclass: aString instanceVariableNames: aString2 category: aString3
  1538. | newClass |
  1539. newClass := self addSubclassOf: aClass named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2).
  1540. self setupClass: newClass.
  1541. newClass category: (aString3 ifNil: ['unclassified'])
  1542. !
  1543. class: aClass instanceVariableNames: aString
  1544. aClass isMetaclass ifFalse: [self error: aClass name, ' is not a metaclass'].
  1545. aClass basicAt: 'iVarNames' put: (self instanceVariableNamesFor: aString).
  1546. self setupClass: aClass
  1547. ! !
  1548. !ClassBuilder methodsFor: 'private'!
  1549. instanceVariableNamesFor: aString
  1550. ^(aString tokenize: ' ') reject: [:each | each isEmpty]
  1551. !
  1552. addSubclassOf: aClass named: aString instanceVariableNames: aCollection
  1553. <smalltalk.addClass(aString, aClass, aCollection);
  1554. return smalltalk[aString]>
  1555. !
  1556. setupClass: aClass
  1557. <smalltalk.init(aClass);>
  1558. ! !
  1559. Object subclass: #ClassCategoryReader
  1560. instanceVariableNames: 'class category chunkParser'
  1561. category: 'Kernel'!
  1562. !ClassCategoryReader methodsFor: 'accessing'!
  1563. class: aClass category: aString
  1564. class := aClass.
  1565. category := aString
  1566. ! !
  1567. !ClassCategoryReader methodsFor: 'fileIn'!
  1568. scanFrom: aStream
  1569. | nextChunk |
  1570. nextChunk := (chunkParser emptyChunk / chunkParser chunk) parse: aStream.
  1571. nextChunk isEmptyChunk ifFalse: [
  1572. self compileMethod: nextChunk contents.
  1573. self scanFrom: aStream].
  1574. ! !
  1575. !ClassCategoryReader methodsFor: 'initialization'!
  1576. initialize
  1577. super initialize.
  1578. chunkParser := ChunkParser new.
  1579. ! !
  1580. !ClassCategoryReader methodsFor: 'private'!
  1581. compileMethod: aString
  1582. | method |
  1583. method := Compiler new load: aString forClass: class.
  1584. method category: category.
  1585. class addCompiledMethod: method
  1586. ! !
  1587. Object subclass: #Stream
  1588. instanceVariableNames: 'collection position streamSize'
  1589. category: 'Kernel'!
  1590. !Stream methodsFor: 'accessing'!
  1591. collection
  1592. ^collection
  1593. !
  1594. setCollection: aCollection
  1595. collection := aCollection
  1596. !
  1597. position
  1598. ^position ifNil: [position := 0]
  1599. !
  1600. position: anInteger
  1601. position := anInteger
  1602. !
  1603. streamSize
  1604. ^streamSize
  1605. !
  1606. setStreamSize: anInteger
  1607. streamSize := anInteger
  1608. !
  1609. contents
  1610. ^self collection
  1611. copyFrom: 1
  1612. to: self streamSize
  1613. !
  1614. size
  1615. ^self streamSize
  1616. ! !
  1617. !Stream methodsFor: 'actions'!
  1618. reset
  1619. self position: 0
  1620. !
  1621. close
  1622. !
  1623. flush
  1624. !
  1625. resetContents
  1626. self reset.
  1627. self setStreamSize: 0
  1628. ! !
  1629. !Stream methodsFor: 'enumerating'!
  1630. do: aBlock
  1631. [self atEnd] whileFalse: [aBlock value: self next]
  1632. ! !
  1633. !Stream methodsFor: 'positioning'!
  1634. setToEnd
  1635. self position: self size
  1636. !
  1637. skip: anInteger
  1638. self position: ((self position + anInteger) min: self size max: 0)
  1639. ! !
  1640. !Stream methodsFor: 'reading'!
  1641. next
  1642. self position: self position + 1.
  1643. ^collection at: self position
  1644. !
  1645. next: anInteger
  1646. | tempCollection |
  1647. tempCollection := self collection class new.
  1648. anInteger timesRepeat: [
  1649. self atEnd ifFalse: [
  1650. tempCollection add: self next]].
  1651. ^tempCollection
  1652. !
  1653. peek
  1654. ^self atEnd ifFalse: [
  1655. self collection at: self position + 1]
  1656. ! !
  1657. !Stream methodsFor: 'testing'!
  1658. atEnd
  1659. ^self position = self size
  1660. !
  1661. atStart
  1662. ^self position = 0
  1663. !
  1664. isEmpty
  1665. ^self size = 0
  1666. ! !
  1667. !Stream methodsFor: 'writing'!
  1668. nextPut: anObject
  1669. self position: self position + 1.
  1670. self collection at: self position put: anObject.
  1671. self setStreamSize: (self streamSize max: self position)
  1672. !
  1673. nextPutAll: aCollection
  1674. aCollection do: [:each |
  1675. self nextPut: each]
  1676. ! !
  1677. !Stream class methodsFor: 'instance creation'!
  1678. on: aCollection
  1679. ^self new
  1680. setCollection: aCollection;
  1681. setStreamSize: aCollection size;
  1682. yourself
  1683. ! !
  1684. Stream subclass: #StringStream
  1685. instanceVariableNames: ''
  1686. category: 'Kernel'!
  1687. !StringStream methodsFor: 'reading'!
  1688. next: anInteger
  1689. | tempCollection |
  1690. tempCollection := self collection class new.
  1691. anInteger timesRepeat: [
  1692. self atEnd ifFalse: [
  1693. tempCollection := tempCollection, self next]].
  1694. ^tempCollection
  1695. ! !
  1696. !StringStream methodsFor: 'writing'!
  1697. nextPut: aString
  1698. self nextPutAll: aString
  1699. !
  1700. nextPutAll: aString
  1701. self setCollection:
  1702. (self collection copyFrom: 1 to: self position),
  1703. aString,
  1704. (self collection copyFrom: (self position + 1 + aString size) to: self collection size).
  1705. self position: self position + aString size.
  1706. self setStreamSize: (self streamSize max: self position)
  1707. !
  1708. cr
  1709. ^self nextPutAll: String cr
  1710. !
  1711. crlf
  1712. ^self nextPutAll: String crlf
  1713. !
  1714. lf
  1715. ^self nextPutAll: String lf
  1716. !
  1717. space
  1718. self nextPut: ' '
  1719. ! !
  1720. Object subclass: #ClassCommentReader
  1721. instanceVariableNames: 'class chunkParser'
  1722. category: 'Kernel'!
  1723. !ClassCommentReader methodsFor: 'accessing'!
  1724. class: aClass
  1725. class := aClass
  1726. ! !
  1727. !ClassCommentReader methodsFor: 'fileIn'!
  1728. scanFrom: aStream
  1729. | nextChunk |
  1730. nextChunk := (chunkParser emptyChunk / chunkParser chunk) parse: aStream.
  1731. nextChunk isEmptyChunk ifFalse: [
  1732. self setComment: nextChunk contents].
  1733. ! !
  1734. !ClassCommentReader methodsFor: 'initialization'!
  1735. initialize
  1736. super initialize.
  1737. chunkParser := ChunkParser new.
  1738. ! !
  1739. !ClassCommentReader methodsFor: 'private'!
  1740. setComment: aString
  1741. class comment: aString
  1742. ! !
  1743. Object subclass: #Random
  1744. instanceVariableNames: ''
  1745. category: 'Kernel'!
  1746. !Random methodsFor: 'accessing'!
  1747. next
  1748. <return Math.random()>
  1749. !
  1750. next: anInteger
  1751. ^1 to: anInteger collect: [:each | self next]
  1752. ! !
  1753. Object subclass: #Point
  1754. instanceVariableNames: 'x y'
  1755. category: 'Kernel'!
  1756. !Point methodsFor: 'accessing'!
  1757. x
  1758. ^x
  1759. !
  1760. y
  1761. ^y
  1762. !
  1763. y: aNumber
  1764. y := aNumber
  1765. !
  1766. x: aNumber
  1767. x := aNumber
  1768. ! !
  1769. !Point methodsFor: 'arithmetic'!
  1770. * aPoint
  1771. ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
  1772. !
  1773. + aPoint
  1774. ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
  1775. !
  1776. - aPoint
  1777. ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
  1778. !
  1779. / aPoint
  1780. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  1781. ! !
  1782. !Point methodsFor: 'converting'!
  1783. asPoint
  1784. ^self
  1785. ! !
  1786. !Point class methodsFor: 'instance creation'!
  1787. x: aNumber y: anotherNumber
  1788. ^self new
  1789. x: aNumber;
  1790. y: anotherNumber;
  1791. yourself
  1792. ! !
  1793. Object subclass: #Message
  1794. instanceVariableNames: 'selector arguments'
  1795. category: 'Kernel'!
  1796. !Message methodsFor: 'accessing'!
  1797. selector
  1798. ^selector
  1799. !
  1800. selector: aString
  1801. selector := aString
  1802. !
  1803. arguments: anArray
  1804. arguments := anArray
  1805. !
  1806. arguments
  1807. ^arguments
  1808. ! !
  1809. !Message class methodsFor: 'instance creation'!
  1810. selector: aString arguments: anArray
  1811. ^self new
  1812. selector: aString;
  1813. arguments: anArray;
  1814. yourself
  1815. ! !
  1816. Error subclass: #MessageNotUnderstood
  1817. instanceVariableNames: 'message receiver'
  1818. category: 'Kernel'!
  1819. !MessageNotUnderstood methodsFor: 'accessing'!
  1820. message
  1821. ^message
  1822. !
  1823. message: aMessage
  1824. message := aMessage
  1825. !
  1826. receiver
  1827. ^receiver
  1828. !
  1829. receiver: anObject
  1830. receiver := anObject
  1831. !
  1832. messageText
  1833. ^self receiver asString, ' does not understand #', self message selector
  1834. ! !
  1835. Object subclass: #ErrorHandler
  1836. instanceVariableNames: ''
  1837. category: 'Kernel'!
  1838. !ErrorHandler methodsFor: 'error handling'!
  1839. handleError: anError
  1840. anError context ifNotNil: [self logErrorContext: anError context].
  1841. self logError: anError
  1842. ! !
  1843. !ErrorHandler methodsFor: 'private'!
  1844. logContext: aContext
  1845. aContext home ifNotNil: [
  1846. self logContext: aContext home].
  1847. self log: aContext receiver asString, '>>', aContext selector
  1848. !
  1849. logErrorContext: aContext
  1850. aContext ifNotNil: [
  1851. aContext home ifNotNil: [
  1852. self logContext: aContext home]]
  1853. !
  1854. logError: anError
  1855. self log: anError messageText
  1856. !
  1857. log: aString
  1858. console log: aString
  1859. ! !
  1860. ErrorHandler class instanceVariableNames: 'current'!
  1861. !ErrorHandler class methodsFor: 'accessing'!
  1862. current
  1863. ^current
  1864. !
  1865. setCurrent: anHandler
  1866. current := anHandler
  1867. ! !
  1868. !ErrorHandler class methodsFor: 'initialization'!
  1869. initialize
  1870. self register
  1871. !
  1872. register
  1873. ErrorHandler setCurrent: self new
  1874. ! !