Kernel.st 40 KB

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