Kernel.st 36 KB

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