Kernel.st 34 KB

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