Kernel.st 37 KB

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