Kernel.st 40 KB

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