Kernel.st 37 KB

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