Kernel.st 38 KB

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