1
0

Kernel.st 40 KB

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