Kernel.st 40 KB

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