Kernel.st 40 KB

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