Kernel.st 36 KB

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