Kernel.st 36 KB

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