1
0

Kernel.st 40 KB

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