Kernel.st 37 KB

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