Kernel.st 40 KB

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