Kernel.st 36 KB

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