2
0

Kernel.st 36 KB

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