Kernel.st 40 KB

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