Kernel.st 34 KB

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