1
0

Kernel.st 40 KB

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