1
0

Kernel.st 40 KB

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