Kernel.st 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175
  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. ^self == anObject
  32. !
  33. ~= anObject
  34. ^(self = anObject) = false
  35. !
  36. == anObject
  37. <return self === anObject>
  38. !
  39. ~~ anObject
  40. ^(self == anObject) = false
  41. ! !
  42. !Object methodsFor: 'converting'!
  43. -> anObject
  44. ^Association key: self value: anObject
  45. !
  46. asString
  47. ^self printString
  48. !
  49. asJavascript
  50. ^self asString
  51. !
  52. asJSON
  53. <return JSON.stringify(self._asJSONObject())>
  54. !
  55. asJSONObject
  56. | object |
  57. object := Object new.
  58. self class instanceVariableNames do: [:each |
  59. object basicAt: each put: (self instVarAt: each) asJSONObject].
  60. ^object
  61. ! !
  62. !Object methodsFor: 'copying'!
  63. copy
  64. ^self shallowCopy postCopy
  65. !
  66. shallowCopy
  67. <
  68. var copy = self.klass._new();
  69. for(var i in self) {
  70. if(/^@.+/.test(i)) {
  71. copy[i] = self[i];
  72. }
  73. }
  74. return copy;
  75. >
  76. !
  77. deepCopy
  78. <
  79. var copy = self.klass._new();
  80. for(var i in self) {
  81. if(/^@.+/.test(i)) {
  82. copy[i] = self[i]._deepCopy();
  83. }
  84. }
  85. return copy;
  86. >
  87. !
  88. postCopy
  89. ! !
  90. !Object methodsFor: 'error handling'!
  91. error: aString
  92. Error signal: aString
  93. !
  94. subclassResponsibility
  95. self error: 'This method is a responsibility of a subclass'
  96. !
  97. shouldNotImplement
  98. self error: 'This method should not be implemented in ', self class name
  99. !
  100. try: aBlock catch: anotherBlock
  101. <try{aBlock()} catch(e) {anotherBlock(e)}>
  102. !
  103. doesNotUnderstand: aMessage
  104. MessageNotUnderstood new
  105. receiver: self;
  106. message: aMessage;
  107. signal
  108. !
  109. halt
  110. self error: 'Halt encountered'
  111. !
  112. deprecatedAPI
  113. "Just a simple way to deprecate methods.
  114. #deprecatedAPI is in the 'error handling' protocol even if it doesn't throw an error,
  115. but it could in the future."
  116. console warn: thisContext home asString, ' is deprecated!!'
  117. ! !
  118. !Object methodsFor: 'initialization'!
  119. initialize
  120. ! !
  121. !Object methodsFor: 'message handling'!
  122. perform: aSymbol
  123. ^self perform: aSymbol withArguments: #()
  124. !
  125. perform: aSymbol withArguments: aCollection
  126. ^self basicPerform: aSymbol asSelector withArguments: aCollection
  127. !
  128. basicPerform: aSymbol
  129. ^self basicPerform: aSymbol withArguments: #()
  130. !
  131. basicPerform: aSymbol withArguments: aCollection
  132. <return self[aSymbol].apply(self, aCollection);>
  133. ! !
  134. !Object methodsFor: 'printing'!
  135. printString
  136. ^'a ', self class name
  137. !
  138. printNl
  139. <console.log(self)>
  140. !
  141. log: aString block: aBlock
  142. | result |
  143. console log: aString, ' time: ', (Date millisecondsToRun: [result := aBlock value]) printString.
  144. ^result
  145. ! !
  146. !Object methodsFor: 'testing'!
  147. isKindOf: aClass
  148. ^(self isMemberOf: aClass)
  149. ifTrue: [true]
  150. ifFalse: [self class inheritsFrom: aClass]
  151. !
  152. isMemberOf: aClass
  153. ^self class = aClass
  154. !
  155. ifNil: aBlock
  156. "inlined in the Compiler"
  157. ^self
  158. !
  159. ifNil: aBlock ifNotNil: anotherBlock
  160. "inlined in the Compiler"
  161. ^anotherBlock value
  162. !
  163. ifNotNil: aBlock
  164. "inlined in the Compiler"
  165. ^aBlock value
  166. !
  167. ifNotNil: aBlock ifNil: anotherBlock
  168. "inlined in the Compiler"
  169. ^aBlock value
  170. !
  171. isNil
  172. ^false
  173. !
  174. notNil
  175. ^self isNil not
  176. !
  177. isClass
  178. ^false
  179. !
  180. isMetaclass
  181. ^false
  182. !
  183. isNumber
  184. ^false
  185. !
  186. isString
  187. ^false
  188. !
  189. isParseFailure
  190. ^false
  191. ! !
  192. !Object class methodsFor: 'initialization'!
  193. initialize
  194. "no op"
  195. ! !
  196. Object subclass: #Smalltalk
  197. instanceVariableNames: ''
  198. category: 'Kernel'!
  199. !Smalltalk methodsFor: 'accessing'!
  200. classes
  201. <return self.classes()>
  202. !
  203. readJSON: anObject
  204. <return self.readJSObject(anObject)>
  205. !
  206. at: aString
  207. <return self[aString]>
  208. !
  209. basicParse: aString
  210. <return smalltalk.parser.parse(aString)>
  211. !
  212. parse: aString
  213. | result |
  214. self try: [result := self basicParse: aString] catch: [:ex | (self parseError: ex parsing: aString) signal].
  215. ^result
  216. !
  217. parseError: anException parsing: aString
  218. | row col message lines badLine code |
  219. <row = anException.line;
  220. col = anException.column;
  221. message = anException.message;>.
  222. lines := aString lines.
  223. badLine := lines at: row.
  224. badLine := (badLine copyFrom: 1 to: col - 1), ' ===>', (badLine copyFrom: col to: badLine size).
  225. lines at: row put: badLine.
  226. code := String streamContents: [:s |
  227. lines withIndexDo: [:l :i |
  228. s nextPutAll: i asString, ': ', l, String lf]].
  229. ^ Error new messageText: ('Parse error on line ' , row , ' column ' , col , ' : ' , message , ' Below is code with line numbers and ===> marker inserted:' , String lf, code)
  230. !
  231. reservedWords
  232. "JavaScript reserved words"
  233. <return self.reservedWords>
  234. ! !
  235. !Smalltalk methodsFor: 'classes'!
  236. removeClass: aClass
  237. aClass isMetaclass ifTrue: [self error: aClass asString, ' is a Metaclass and cannot be removed!!'].
  238. aClass methodDictionary values do: [:each |
  239. aClass removeCompiledMethod: each].
  240. aClass class methodDictionary values do: [:each |
  241. aClass class removeCompiledMethod: each].
  242. self basicDelete: aClass name
  243. ! !
  244. !Smalltalk methodsFor: 'packages'!
  245. packages
  246. "Return all Package instances in the system."
  247. <return self.packages.all()>
  248. !
  249. packageAt: packageName
  250. <return self.packages[packageName]>
  251. !
  252. packageAt: packageName ifAbsent: aBlock
  253. ^(self packageAt: packageName) ifNil: aBlock
  254. !
  255. removePackage: packageName
  256. "Removes a package and all its classes."
  257. | pkg |
  258. pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  259. pkg classes do: [:each |
  260. self removeClass: each].
  261. self deletePackage: packageName
  262. !
  263. renamePackage: packageName to: newName
  264. "Rename a package."
  265. | pkg |
  266. pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
  267. (self packageAt: newName) ifNotNil: [self error: 'Already exists a package called: ', newName].
  268. <smalltalk.packages[newName] = smalltalk.packages[packageName]>.
  269. pkg name: newName.
  270. self deletePackage: packageName.
  271. ! !
  272. !Smalltalk methodsFor: 'private'!
  273. createPackage: packageName
  274. "Create and bind a new package with given name and return it."
  275. <return smalltalk.addPackage(packageName)>
  276. !
  277. deletePackage: packageName
  278. "Deletes a package by deleting its binding, but does not check if it contains classes etc.
  279. To remove a package, use #removePackage instead."
  280. <delete smalltalk.packages[packageName]>
  281. ! !
  282. Smalltalk class instanceVariableNames: 'current'!
  283. !Smalltalk class methodsFor: 'accessing'!
  284. current
  285. <return smalltalk>
  286. ! !
  287. Object subclass: #Package
  288. instanceVariableNames: ''
  289. category: 'Kernel'!
  290. !Package commentStamp!
  291. A Package is similar to a "class category" typically found in other Smalltalks like Pharo or Squeak. Amber does not have class categories anymore, it had in the beginning but now each class in the system knows which package it belongs to.
  292. A Package has a name, an Array of "requires", a comment and a Dictionary with other optional key value attributes. A Package can also be queried for its classes, but it will then resort to a reverse scan of all classes to find them.
  293. Packages are manipulated through "Smalltalk current", like for example finding one based on a name:
  294. Smalltalk current packageAt: 'Kernel'
  295. ...but you can also use:
  296. Package named: 'Kernel'
  297. A Package differs slightly from a Monticello package which can span multiple class categories using a naming convention based on hyphenation. But just as in Monticello a Package supports "class extensions" so a Package
  298. can define behaviors in foreign classes using a naming convention for method categories where the category starts with an asterisk and then the name of the owning package follows. This can easily be seen in for example class
  299. String where the method category "*IDE" defines #inspectOn: which thus is a method belonging to the IDE package.!
  300. !Package methodsFor: 'accessing'!
  301. name
  302. <return self.pkgName || nil>
  303. !
  304. requires
  305. <return self.requires || nil>
  306. !
  307. name: aString
  308. <return self.pkgName = aString>
  309. ! !
  310. !Package methodsFor: 'classes'!
  311. classes
  312. "We need to do a reverse scan."
  313. ^Smalltalk current classes select: [:c | c package == self]
  314. ! !
  315. !Package methodsFor: 'printing'!
  316. printString
  317. ^self name
  318. ! !
  319. !Package class methodsFor: 'not yet classified'!
  320. named: aPackageName
  321. ^Smalltalk current packageAt: aPackageName
  322. !
  323. named: aPackageName ifAbsent: aBlock
  324. ^Smalltalk current packageAt: aPackageName ifAbsent: aBlock
  325. ! !
  326. Object subclass: #Behavior
  327. instanceVariableNames: ''
  328. category: 'Kernel'!
  329. !Behavior methodsFor: 'accessing'!
  330. name
  331. <return self.className || nil>
  332. !
  333. superclass
  334. <return self.superclass || nil>
  335. !
  336. subclasses
  337. <return smalltalk.subclasses(self)>
  338. !
  339. allSubclasses
  340. | result |
  341. result := self subclasses.
  342. self subclasses do: [:each |
  343. result addAll: each allSubclasses].
  344. ^result
  345. !
  346. withAllSubclasses
  347. ^(Array with: self) addAll: self allSubclasses; yourself
  348. !
  349. prototype
  350. <return self.fn.prototype>
  351. !
  352. methodDictionary
  353. <var dict = smalltalk.Dictionary._new();
  354. var methods = self.fn.prototype.methods;
  355. for(var i in methods) {
  356. if(methods[i].selector) {
  357. dict._at_put_(methods[i].selector, methods[i]);
  358. }
  359. };
  360. return dict>
  361. !
  362. methodsFor: aString
  363. ^ClassCategoryReader new
  364. class: self category: aString;
  365. yourself
  366. !
  367. addCompiledMethod: aMethod
  368. <smalltalk.addMethod(aMethod.selector._asSelector(), aMethod, self)>
  369. !
  370. instanceVariableNames
  371. <return self.iVarNames>
  372. !
  373. comment
  374. ^(self basicAt: 'comment') ifNil: ['']
  375. !
  376. comment: aString
  377. self basicAt: 'comment' put: aString
  378. !
  379. commentStamp
  380. ^ClassCommentReader new
  381. class: self;
  382. yourself
  383. !
  384. removeCompiledMethod: aMethod
  385. <delete self.fn.prototype[aMethod.selector._asSelector()];
  386. delete self.fn.prototype.methods[aMethod.selector];
  387. smalltalk.init(self);>
  388. !
  389. protocols
  390. | protocols |
  391. protocols := Array new.
  392. self methodDictionary do: [:each |
  393. (protocols includes: each category) ifFalse: [
  394. protocols add: each category]].
  395. ^protocols sort
  396. !
  397. protocolsDo: aBlock
  398. "Execute aBlock for each method category with
  399. its collection of methods in the sort order of category name."
  400. | methodsByCategory |
  401. methodsByCategory := Dictionary new.
  402. self methodDictionary values do: [:m |
  403. (methodsByCategory at: m category ifAbsentPut: [Array new])
  404. add: m].
  405. self protocols do: [:category |
  406. aBlock value: category value: (methodsByCategory at: category)]
  407. !
  408. allInstanceVariableNames
  409. | result |
  410. result := self instanceVariableNames copy.
  411. self superclass ifNotNil: [
  412. result addAll: self superclass allInstanceVariableNames].
  413. ^result
  414. !
  415. methodAt: aString
  416. <return smalltalk.methods(self)[aString]>
  417. !
  418. methodsFor: aString stamp: aStamp
  419. "Added for compatibility, right now ignores stamp."
  420. ^self methodsFor: aString
  421. !
  422. commentStamp: aStamp prior: prior
  423. ^self commentStamp
  424. ! !
  425. !Behavior methodsFor: 'compiling'!
  426. compile: aString
  427. self compile: aString category: ''
  428. !
  429. compile: aString category: anotherString
  430. | method |
  431. method := Compiler new load: aString forClass: self.
  432. method category: anotherString.
  433. self addCompiledMethod: method
  434. ! !
  435. !Behavior methodsFor: 'instance creation'!
  436. new
  437. ^self basicNew initialize
  438. !
  439. basicNew
  440. <return new self.fn()>
  441. !
  442. inheritsFrom: aClass
  443. ^aClass allSubclasses includes: self
  444. ! !
  445. Behavior subclass: #Class
  446. instanceVariableNames: ''
  447. category: 'Kernel'!
  448. !Class methodsFor: 'accessing'!
  449. category
  450. ^self package ifNil: ['Unclassified'] ifNotNil: [self package name]
  451. !
  452. rename: aString
  453. <
  454. smalltalk[aString] = self;
  455. delete smalltalk[self.className];
  456. self.className = aString;
  457. >
  458. !
  459. package
  460. <return self.pkg>
  461. !
  462. package: aPackage
  463. <self.pkg = aPackage>
  464. ! !
  465. !Class methodsFor: 'class creation'!
  466. subclass: aString instanceVariableNames: anotherString
  467. "Kept for compatibility."
  468. ^self subclass: aString instanceVariableNames: anotherString package: nil
  469. !
  470. subclass: aString instanceVariableNames: aString2 category: aString3
  471. "Kept for compatibility."
  472. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  473. !
  474. subclass: aString instanceVariableNames: aString2 classVariableNames: classVars poolDictionaries: pools category: aString3
  475. "Just ignore class variables and pools. Added for compatibility."
  476. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  477. !
  478. subclass: aString instanceVariableNames: aString2 package: aString3
  479. ^ClassBuilder new
  480. superclass: self subclass: aString instanceVariableNames: aString2 package: aString3
  481. ! !
  482. !Class methodsFor: 'printing'!
  483. printString
  484. ^self name
  485. ! !
  486. !Class methodsFor: 'testing'!
  487. isClass
  488. ^true
  489. ! !
  490. Behavior subclass: #Metaclass
  491. instanceVariableNames: ''
  492. category: 'Kernel'!
  493. !Metaclass methodsFor: 'accessing'!
  494. instanceClass
  495. <return self.instanceClass>
  496. !
  497. instanceVariableNames: aCollection
  498. ClassBuilder new
  499. class: self instanceVariableNames: aCollection
  500. ! !
  501. !Metaclass methodsFor: 'printing'!
  502. printString
  503. ^self instanceClass name, ' class'
  504. ! !
  505. !Metaclass methodsFor: 'testing'!
  506. isMetaclass
  507. ^true
  508. ! !
  509. Object subclass: #CompiledMethod
  510. instanceVariableNames: ''
  511. category: 'Kernel'!
  512. !CompiledMethod methodsFor: 'accessing'!
  513. source
  514. ^(self basicAt: 'source') ifNil: ['']
  515. !
  516. source: aString
  517. self basicAt: 'source' put: aString
  518. !
  519. category
  520. ^(self basicAt: 'category') ifNil: ['']
  521. !
  522. category: aString
  523. self basicAt: 'category' put: aString
  524. !
  525. selector
  526. ^self basicAt: 'selector'
  527. !
  528. selector: aString
  529. self basicAt: 'selector' put: aString
  530. !
  531. fn
  532. ^self basicAt: 'fn'
  533. !
  534. fn: aBlock
  535. self basicAt: 'fn' put: aBlock
  536. !
  537. messageSends
  538. ^self basicAt: 'messageSends'
  539. !
  540. methodClass
  541. ^self basicAt: 'methodClass'
  542. !
  543. referencedClasses
  544. ^self basicAt: 'referencedClasses'
  545. !
  546. arguments
  547. <return self.args || []>
  548. ! !
  549. Object subclass: #Number
  550. instanceVariableNames: ''
  551. category: 'Kernel'!
  552. !Number methodsFor: 'arithmetic'!
  553. + aNumber
  554. "Inlined in the Compiler"
  555. <return self + aNumber>
  556. !
  557. - aNumber
  558. "Inlined in the Compiler"
  559. <return self - aNumber>
  560. !
  561. * aNumber
  562. "Inlined in the Compiler"
  563. <return self * aNumber>
  564. !
  565. / aNumber
  566. "Inlined in the Compiler"
  567. <return self / aNumber>
  568. !
  569. max: aNumber
  570. <return Math.max(self, aNumber);>
  571. !
  572. min: aNumber
  573. <return Math.min(self, aNumber);>
  574. !
  575. negated
  576. ^0 - self
  577. !
  578. \\ aNumber
  579. <return self % aNumber>
  580. ! !
  581. !Number methodsFor: 'comparing'!
  582. = aNumber
  583. aNumber class = self class ifFalse: [^false].
  584. <return Number(self) == aNumber>
  585. !
  586. > aNumber
  587. "Inlined in the Compiler"
  588. <return self >> aNumber>
  589. !
  590. < aNumber
  591. "Inlined in the Compiler"
  592. <return self < aNumber>
  593. !
  594. >= aNumber
  595. "Inlined in the Compiler"
  596. <return self >>= aNumber>
  597. !
  598. <= aNumber
  599. "Inlined in the Compiler"
  600. <return self <= aNumber>
  601. !
  602. == aNumber
  603. aNumber class = self class ifFalse: [^false].
  604. <return Number(self) === Number(aNumber)>
  605. ! !
  606. !Number methodsFor: 'converting'!
  607. rounded
  608. <return Math.round(self);>
  609. !
  610. truncated
  611. |result|
  612. self >= 0
  613. ifTrue: [<result = Math.floor(self);>]
  614. ifFalse: [<result = (Math.floor(self * (-1)) * (-1));>].
  615. ^ result
  616. !
  617. to: aNumber
  618. | array first last count |
  619. first := self truncated.
  620. last := aNumber truncated + 1.
  621. count := 1.
  622. array := Array new.
  623. (last - first) timesRepeat: [
  624. array at: count put: first.
  625. count := count + 1.
  626. first := first + 1].
  627. ^array
  628. !
  629. asString
  630. ^self printString
  631. !
  632. asJavascript
  633. ^'(', self printString, ')'
  634. !
  635. atRandom
  636. ^(Random new next * self) truncated + 1
  637. !
  638. @ aNumber
  639. ^Point x: self y: aNumber
  640. !
  641. asPoint
  642. ^Point x: self y: self
  643. !
  644. asJSONObject
  645. ^self
  646. !
  647. to: stop by: step
  648. | array value pos |
  649. value := self.
  650. array := Array new.
  651. pos := 1.
  652. step = 0 ifTrue: [self error: 'step must be non-zero'].
  653. step < 0
  654. ifTrue: [[ value >= stop ] whileTrue: [
  655. array at: pos put: value.
  656. pos := pos + 1.
  657. value := value + step]]
  658. ifFalse: [[ value <= stop ] whileTrue: [
  659. array at: pos put: value.
  660. pos := pos + 1.
  661. value := value + step]].
  662. ^array
  663. !
  664. to: stop by: step do: aBlock
  665. | value |
  666. value := self.
  667. step = 0 ifTrue: [self error: 'step must be non-zero'].
  668. step < 0
  669. ifTrue: [[ value >= stop ] whileTrue: [
  670. aBlock value: value.
  671. value := value + step]]
  672. ifFalse: [[ value <= stop ] whileTrue: [
  673. aBlock value: value.
  674. value := value + step]]
  675. ! !
  676. !Number methodsFor: 'copying'!
  677. deepCopy
  678. ^self copy
  679. !
  680. copy
  681. ^self
  682. ! !
  683. !Number methodsFor: 'enumerating'!
  684. timesRepeat: aBlock
  685. | integer count |
  686. integer := self truncated.
  687. count := 1.
  688. [count > self] whileFalse: [
  689. aBlock value.
  690. count := count + 1]
  691. !
  692. to: stop do: aBlock
  693. "Evaluate aBlock for each number from self to aNumber."
  694. | nextValue |
  695. nextValue := self.
  696. [nextValue <= stop]
  697. whileTrue:
  698. [aBlock value: nextValue.
  699. nextValue := nextValue + 1]
  700. ! !
  701. !Number methodsFor: 'printing'!
  702. printString
  703. <return String(self)>
  704. !
  705. printShowingDecimalPlaces: placesDesired
  706. <return self.toFixed(placesDesired)>
  707. ! !
  708. !Number methodsFor: 'testing'!
  709. isNumber
  710. ^true
  711. !
  712. even
  713. ^ 0 = (self \\ 2)
  714. !
  715. odd
  716. ^ self even not
  717. ! !
  718. !Number methodsFor: 'timeouts/intervals'!
  719. clearInterval
  720. <clearInterval(Number(self))>
  721. !
  722. clearTimeout
  723. <clearTimeout(Number(self))>
  724. ! !
  725. !Number class methodsFor: 'instance creation'!
  726. pi
  727. <return Math.PI>
  728. ! !
  729. Object subclass: #BlockClosure
  730. instanceVariableNames: ''
  731. category: 'Kernel'!
  732. !BlockClosure methodsFor: 'accessing'!
  733. compiledSource
  734. <return self.toString()>
  735. ! !
  736. !BlockClosure methodsFor: 'controlling'!
  737. whileTrue: aBlock
  738. "inlined in the Compiler"
  739. <while(self()) {aBlock()}>
  740. !
  741. whileFalse: aBlock
  742. "inlined in the Compiler"
  743. <while(!!self()) {aBlock()}>
  744. !
  745. whileFalse
  746. "inlined in the Compiler"
  747. self whileFalse: []
  748. !
  749. whileTrue
  750. "inlined in the Compiler"
  751. self whileTrue: []
  752. ! !
  753. !BlockClosure methodsFor: 'error handling'!
  754. on: anErrorClass do: aBlock
  755. self try: self catch: [:error |
  756. (error isKindOf: anErrorClass)
  757. ifTrue: [aBlock value: error]
  758. ifFalse: [error signal]]
  759. ! !
  760. !BlockClosure methodsFor: 'evaluating'!
  761. value
  762. "inlined in the Compiler"
  763. <return self();>
  764. !
  765. value: anArg
  766. "inlined in the Compiler"
  767. <return self(anArg);>
  768. !
  769. value: firstArg value: secondArg
  770. "inlined in the Compiler"
  771. <return self(firstArg, secondArg);>
  772. !
  773. value: firstArg value: secondArg value: thirdArg
  774. "inlined in the Compiler"
  775. <return self(firstArg, secondArg, thirdArg);>
  776. !
  777. valueWithPossibleArguments: aCollection
  778. <return self.apply(null, aCollection);>
  779. !
  780. new
  781. "Use the receiver as a JS constructor.
  782. *Do not* use this method to instanciate Smalltalk objects!!"
  783. <return new self()>
  784. !
  785. applyTo: anObject arguments: aCollection
  786. <return self.apply(anObject, aCollection)>
  787. !
  788. timeToRun
  789. "Answer the number of milliseconds taken to execute this block."
  790. ^ Date millisecondsToRun: self
  791. ! !
  792. !BlockClosure methodsFor: 'timeout/interval'!
  793. valueWithTimeout: aNumber
  794. <return setTimeout(self, aNumber)>
  795. !
  796. valueWithInterval: aNumber
  797. <return setInterval(self, aNumber)>
  798. ! !
  799. Object subclass: #Boolean
  800. instanceVariableNames: ''
  801. category: 'Kernel'!
  802. !Boolean methodsFor: 'comparing'!
  803. = aBoolean
  804. aBoolean class = self class ifFalse: [^false].
  805. <return Boolean(self == true) == aBoolean>
  806. !
  807. == aBoolean
  808. aBoolean class = self class ifFalse: [^false].
  809. <return Boolean(self == true) === Boolean(aBoolean == true)>
  810. ! !
  811. !Boolean methodsFor: 'controlling'!
  812. ifTrue: aBlock
  813. "inlined in the Compiler"
  814. ^self ifTrue: aBlock ifFalse: []
  815. !
  816. ifFalse: aBlock
  817. "inlined in the Compiler"
  818. ^self ifTrue: [] ifFalse: aBlock
  819. !
  820. ifFalse: aBlock ifTrue: anotherBlock
  821. "inlined in the Compiler"
  822. ^self ifTrue: anotherBlock ifFalse: aBlock
  823. !
  824. ifTrue: aBlock ifFalse: anotherBlock
  825. "inlined in the Compiler"
  826. <
  827. if(self == true) {
  828. return aBlock();
  829. } else {
  830. return anotherBlock();
  831. }
  832. >
  833. !
  834. and: aBlock
  835. ^self = true
  836. ifTrue: aBlock
  837. ifFalse: [false]
  838. !
  839. or: aBlock
  840. ^self = true
  841. ifTrue: [true]
  842. ifFalse: aBlock
  843. !
  844. not
  845. ^self = false
  846. !
  847. & aBoolean
  848. <
  849. if(self == true) {
  850. return aBoolean;
  851. } else {
  852. return false;
  853. }
  854. >
  855. !
  856. | aBoolean
  857. <
  858. if(self == true) {
  859. return true;
  860. } else {
  861. return aBoolean;
  862. }
  863. >
  864. ! !
  865. !Boolean methodsFor: 'converting'!
  866. asJSONObject
  867. ^self
  868. ! !
  869. !Boolean methodsFor: 'copying'!
  870. shallowCopy
  871. ^self
  872. !
  873. deepCopy
  874. ^self
  875. ! !
  876. !Boolean methodsFor: 'printing'!
  877. printString
  878. <return self.toString()>
  879. ! !
  880. Object subclass: #Date
  881. instanceVariableNames: ''
  882. category: 'Kernel'!
  883. !Date commentStamp!
  884. The Date class is used to work with dates and times.!
  885. !Date methodsFor: 'accessing'!
  886. year
  887. <return self.getFullYear()>
  888. !
  889. month
  890. <return self.getMonth() + 1>
  891. !
  892. month: aNumber
  893. <self.setMonth(aNumber - 1)>
  894. !
  895. day
  896. ^self dayOfWeek
  897. !
  898. dayOfWeek
  899. <return self.getDay() + 1>
  900. !
  901. dayOfWeek: aNumber
  902. <return self.setDay(aNumber - 1)>
  903. !
  904. day: aNumber
  905. self day: aNumber
  906. !
  907. year: aNumber
  908. <self.setFullYear(aNumber)>
  909. !
  910. dayOfMonth
  911. <return self.getDate()>
  912. !
  913. dayOfMonth: aNumber
  914. <self.setDate(aNumber)>
  915. !
  916. time
  917. <return self.getTime()>
  918. !
  919. time: aNumber
  920. <self.setTime(aNumber)>
  921. !
  922. hours: aNumber
  923. <self.setHours(aNumber)>
  924. !
  925. minutes: aNumber
  926. <self.setMinutes(aNumber)>
  927. !
  928. seconds: aNumber
  929. <self.setSeconds(aNumber)>
  930. !
  931. milliseconds: aNumber
  932. <self.setMilliseconds(aNumber)>
  933. !
  934. hours
  935. <return self.getHours()>
  936. !
  937. minutes
  938. <return self.getMinutes()>
  939. !
  940. seconds
  941. <return self.getSeconds()>
  942. !
  943. milliseconds
  944. <return self.getMilliseconds()>
  945. ! !
  946. !Date methodsFor: 'arithmetic'!
  947. - aDate
  948. <return self - aDate>
  949. !
  950. + aDate
  951. <return self + aDate>
  952. ! !
  953. !Date methodsFor: 'comparing'!
  954. < aDate
  955. <return self < aDate>
  956. !
  957. > aDate
  958. <return self >> aDate>
  959. !
  960. <= aDate
  961. <return self <= aDate>
  962. !
  963. >= aDate
  964. <return self >>= aDate>
  965. ! !
  966. !Date methodsFor: 'converting'!
  967. asString
  968. <return self.toString()>
  969. !
  970. asMilliseconds
  971. ^self time
  972. !
  973. asDateString
  974. <return self.toDateString()>
  975. !
  976. asTimeString
  977. <return self.toTimeString()>
  978. !
  979. asLocaleString
  980. <return self.toLocaleString()>
  981. !
  982. asNumber
  983. ^self asMilliseconds
  984. !
  985. asJSONObject
  986. ^self
  987. ! !
  988. !Date methodsFor: 'printing'!
  989. printString
  990. ^self asString
  991. ! !
  992. !Date class methodsFor: 'instance creation'!
  993. new: anObject
  994. <return new Date(anObject)>
  995. !
  996. fromString: aString
  997. "Example: Date fromString('2011/04/15 00:00:00')"
  998. ^self new: aString
  999. !
  1000. fromSeconds: aNumber
  1001. ^self fromMilliseconds: aNumber * 1000
  1002. !
  1003. fromMilliseconds: aNumber
  1004. ^self new: aNumber
  1005. !
  1006. today
  1007. ^self new
  1008. !
  1009. now
  1010. ^self today
  1011. !
  1012. millisecondsToRun: aBlock
  1013. | t |
  1014. t := Date now.
  1015. aBlock value.
  1016. ^Date now - t
  1017. ! !
  1018. Object subclass: #UndefinedObject
  1019. instanceVariableNames: ''
  1020. category: 'Kernel'!
  1021. !UndefinedObject methodsFor: 'class creation'!
  1022. subclass: aString instanceVariableNames: anotherString
  1023. ^self subclass: aString instanceVariableNames: anotherString package: nil
  1024. !
  1025. subclass: aString instanceVariableNames: aString2 category: aString3
  1026. "Kept for compatibility."
  1027. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  1028. !
  1029. subclass: aString instanceVariableNames: aString2 package: aString3
  1030. ^ClassBuilder new
  1031. superclass: self subclass: aString instanceVariableNames: aString2 package: aString3
  1032. ! !
  1033. !UndefinedObject methodsFor: 'copying'!
  1034. shallowCopy
  1035. ^self
  1036. !
  1037. deepCopy
  1038. ^self
  1039. ! !
  1040. !UndefinedObject methodsFor: 'printing'!
  1041. printString
  1042. ^'nil'
  1043. ! !
  1044. !UndefinedObject methodsFor: 'testing'!
  1045. ifNil: aBlock
  1046. "inlined in the Compiler"
  1047. ^self ifNil: aBlock ifNotNil: []
  1048. !
  1049. ifNotNil: aBlock
  1050. "inlined in the Compiler"
  1051. ^self
  1052. !
  1053. ifNil: aBlock ifNotNil: anotherBlock
  1054. "inlined in the Compiler"
  1055. ^aBlock value
  1056. !
  1057. ifNotNil: aBlock ifNil: anotherBlock
  1058. "inlined in the Compiler"
  1059. ^anotherBlock value
  1060. !
  1061. isNil
  1062. ^true
  1063. !
  1064. notNil
  1065. ^false
  1066. ! !
  1067. !UndefinedObject class methodsFor: 'instance creation'!
  1068. new
  1069. self error: 'You cannot create new instances of UndefinedObject. Use nil'
  1070. ! !
  1071. Object subclass: #Collection
  1072. instanceVariableNames: ''
  1073. category: 'Kernel'!
  1074. !Collection methodsFor: 'accessing'!
  1075. size
  1076. self subclassResponsibility
  1077. !
  1078. readStream
  1079. ^self stream
  1080. !
  1081. writeStream
  1082. ^self stream
  1083. !
  1084. stream
  1085. ^self streamClass on: self
  1086. !
  1087. streamClass
  1088. ^self class streamClass
  1089. ! !
  1090. !Collection methodsFor: 'adding/removing'!
  1091. add: anObject
  1092. self subclassResponsibility
  1093. !
  1094. addAll: aCollection
  1095. aCollection do: [:each |
  1096. self add: each].
  1097. ^aCollection
  1098. !
  1099. remove: anObject
  1100. self subclassResponsibility
  1101. ! !
  1102. !Collection methodsFor: 'converting'!
  1103. asArray
  1104. | array index |
  1105. array := Array new.
  1106. index := 0.
  1107. self do: [:each |
  1108. index := index + 1.
  1109. array at: index put: each].
  1110. ^array
  1111. !
  1112. asSet
  1113. ^Set withAll: self
  1114. ! !
  1115. !Collection methodsFor: 'copying'!
  1116. , aCollection
  1117. ^self copy
  1118. addAll: aCollection;
  1119. yourself
  1120. !
  1121. copyWith: anObject
  1122. ^self copy add: anObject; yourself
  1123. !
  1124. copyWithAll: aCollection
  1125. ^self copy addAll: aCollection; yourself
  1126. !
  1127. copyWithoutAll: aCollection
  1128. "Answer a copy of the receiver that does not contain any elements
  1129. equal to those in aCollection."
  1130. ^ self reject: [:each | aCollection includes: each]
  1131. ! !
  1132. !Collection methodsFor: 'enumerating'!
  1133. do: aBlock
  1134. <for(var i=0;i<self.length;i++){aBlock(self[i]);}>
  1135. !
  1136. collect: aBlock
  1137. | newCollection |
  1138. newCollection := self class new.
  1139. self do: [:each |
  1140. newCollection add: (aBlock value: each)].
  1141. ^newCollection
  1142. !
  1143. detect: aBlock
  1144. ^self detect: aBlock ifNone: [self errorNotFound]
  1145. !
  1146. detect: aBlock ifNone: anotherBlock
  1147. <
  1148. for(var i = 0; i < self.length; i++)
  1149. if(aBlock(self[i]))
  1150. return self[i];
  1151. return anotherBlock();
  1152. >
  1153. !
  1154. do: aBlock separatedBy: anotherBlock
  1155. | first |
  1156. first := true.
  1157. self do: [:each |
  1158. first
  1159. ifTrue: [first := false]
  1160. ifFalse: [anotherBlock value].
  1161. aBlock value: each]
  1162. !
  1163. inject: anObject into: aBlock
  1164. | result |
  1165. result := anObject.
  1166. self do: [:each |
  1167. result := aBlock value: result value: each].
  1168. ^result
  1169. !
  1170. reject: aBlock
  1171. ^self select: [:each | (aBlock value: each) = false]
  1172. !
  1173. select: aBlock
  1174. | stream |
  1175. stream := self class new writeStream.
  1176. self do: [:each |
  1177. (aBlock value: each) ifTrue: [
  1178. stream nextPut: each]].
  1179. ^stream contents
  1180. ! !
  1181. !Collection methodsFor: 'error handling'!
  1182. errorNotFound
  1183. self error: 'Object is not in the collection'
  1184. ! !
  1185. !Collection methodsFor: 'testing'!
  1186. includes: anObject
  1187. <
  1188. var i = self.length;
  1189. while (i--) {
  1190. if (smalltalk.send(self[i], "__eq", [anObject])) {return true;}
  1191. }
  1192. return false
  1193. >
  1194. !
  1195. notEmpty
  1196. ^self isEmpty not
  1197. !
  1198. isEmpty
  1199. ^self size = 0
  1200. !
  1201. ifNotEmpty: aBlock
  1202. self notEmpty ifTrue: aBlock.
  1203. !
  1204. ifEmpty: aBlock
  1205. self isEmpty ifTrue: aBlock.
  1206. ! !
  1207. !Collection class methodsFor: 'accessing'!
  1208. streamClass
  1209. ^Stream
  1210. ! !
  1211. !Collection class methodsFor: 'instance creation'!
  1212. with: anObject
  1213. ^self new
  1214. add: anObject;
  1215. yourself
  1216. !
  1217. with: anObject with: anotherObject
  1218. ^self new
  1219. add: anObject;
  1220. add: anotherObject;
  1221. yourself
  1222. !
  1223. with: firstObject with: secondObject with: thirdObject
  1224. ^self new
  1225. add: firstObject;
  1226. add: secondObject;
  1227. add: thirdObject;
  1228. yourself
  1229. !
  1230. withAll: aCollection
  1231. ^self new
  1232. addAll: aCollection;
  1233. yourself
  1234. ! !
  1235. Collection subclass: #SequenceableCollection
  1236. instanceVariableNames: ''
  1237. category: 'Kernel'!
  1238. !SequenceableCollection methodsFor: 'accessing'!
  1239. at: anIndex
  1240. ^self at: anIndex ifAbsent: [
  1241. self errorNotFound]
  1242. !
  1243. at: anIndex ifAbsent: aBlock
  1244. self subclassResponsibility
  1245. !
  1246. at: anIndex put: anObject
  1247. self subclassResponsibility
  1248. !
  1249. first
  1250. ^self at: 1
  1251. !
  1252. fourth
  1253. ^self at: 4
  1254. !
  1255. last
  1256. ^self at: self size
  1257. !
  1258. second
  1259. ^self at: 2
  1260. !
  1261. third
  1262. ^self at: 3
  1263. !
  1264. allButFirst
  1265. ^self copyFrom: 2 to: self size
  1266. !
  1267. allButLast
  1268. ^self copyFrom: 1 to: self size - 1
  1269. !
  1270. indexOf: anObject
  1271. ^self indexOf: anObject ifAbsent: [self errorNotFound]
  1272. !
  1273. indexOf: anObject ifAbsent: aBlock
  1274. <
  1275. for(var i=0;i<self.length;i++){
  1276. if(self[i].__eq(anObject)) {return i+1}
  1277. }
  1278. return aBlock();
  1279. >
  1280. !
  1281. indexOf: anObject startingAt: start ifAbsent: aBlock
  1282. <
  1283. for(var i=start-1;i<self.length;i++){
  1284. if(self[i].__eq(anObject)) {return i+1}
  1285. }
  1286. return aBlock();
  1287. >
  1288. !
  1289. indexOf: anObject startingAt: start
  1290. "Answer the index of the first occurence of anElement after start
  1291. within the receiver. If the receiver does not contain anElement,
  1292. answer 0."
  1293. ^self indexOf: anObject startingAt: start ifAbsent: [0]
  1294. !
  1295. atRandom
  1296. ^ self at: self size atRandom
  1297. ! !
  1298. !SequenceableCollection methodsFor: 'adding'!
  1299. removeLast
  1300. self remove: self last
  1301. !
  1302. addLast: anObject
  1303. self add: anObject
  1304. ! !
  1305. !SequenceableCollection methodsFor: 'converting'!
  1306. reversed
  1307. self subclassResponsibility
  1308. ! !
  1309. !SequenceableCollection methodsFor: 'copying'!
  1310. copyFrom: anIndex to: anotherIndex
  1311. self subclassResponsibility
  1312. ! !
  1313. !SequenceableCollection methodsFor: 'enumerating'!
  1314. withIndexDo: aBlock
  1315. <for(var i=0;i<self.length;i++){aBlock(self[i], i+1);}>
  1316. ! !
  1317. SequenceableCollection subclass: #String
  1318. instanceVariableNames: ''
  1319. category: 'Kernel'!
  1320. !String methodsFor: 'accessing'!
  1321. size
  1322. <return self.length>
  1323. !
  1324. at: anIndex
  1325. <return self[anIndex - 1]>
  1326. !
  1327. at: anIndex put: anObject
  1328. self errorReadOnly
  1329. !
  1330. at: anIndex ifAbsent: aBlock
  1331. (self at: anIndex) ifNil: [aBlock]
  1332. !
  1333. escaped
  1334. <return escape(self)>
  1335. !
  1336. unescaped
  1337. <return unescape(self)>
  1338. !
  1339. asciiValue
  1340. <return self.charCodeAt(0);>
  1341. ! !
  1342. !String methodsFor: 'adding'!
  1343. add: anObject
  1344. self errorReadOnly
  1345. !
  1346. remove: anObject
  1347. self errorReadOnly
  1348. ! !
  1349. !String methodsFor: 'comparing'!
  1350. = aString
  1351. aString class = self class ifFalse: [^false].
  1352. <return String(self) == aString>
  1353. !
  1354. > aString
  1355. <return String(self) >> aString>
  1356. !
  1357. < aString
  1358. <return String(self) < aString>
  1359. !
  1360. >= aString
  1361. <return String(self) >>= aString>
  1362. !
  1363. <= aString
  1364. <return String(self) <= aString>
  1365. !
  1366. == aString
  1367. aString class = self class ifFalse: [^false].
  1368. <return String(self) === String(aString)>
  1369. ! !
  1370. !String methodsFor: 'converting'!
  1371. asSelector
  1372. "If you change this method, change smalltalk.convertSelector too (see js/boot.js file)"
  1373. | selector |
  1374. selector := '_', self.
  1375. selector := selector replace: ':' with: '_'.
  1376. selector := selector replace: '[+]' with: '_plus'.
  1377. selector := selector replace: '-' with: '_minus'.
  1378. selector := selector replace: '[*]' with: '_star'.
  1379. selector := selector replace: '[/]' with: '_slash'.
  1380. selector := selector replace: '>' with: '_gt'.
  1381. selector := selector replace: '<' with: '_lt'.
  1382. selector := selector replace: '=' with: '_eq'.
  1383. selector := selector replace: ',' with: '_comma'.
  1384. selector := selector replace: '[@]' with: '_at'.
  1385. ^selector
  1386. !
  1387. asJavascript
  1388. <
  1389. if(self.search(/^[a-zA-Z0-9_:.$ ]*$/) == -1)
  1390. return "unescape(\"" + escape(self) + "\")";
  1391. else
  1392. return "\"" + self + "\"";
  1393. >
  1394. !
  1395. tokenize: aString
  1396. <return self.split(aString)>
  1397. !
  1398. asString
  1399. ^self
  1400. !
  1401. asNumber
  1402. <return Number(self)>
  1403. !
  1404. asJSONObject
  1405. ^self
  1406. !
  1407. asLowercase
  1408. <return self.toLowerCase()>
  1409. !
  1410. asUppercase
  1411. <return self.toUpperCase()>
  1412. !
  1413. reversed
  1414. <return self.split("").reverse().join("")>
  1415. !
  1416. asJavaScriptSelector
  1417. ^(self asSelector replace: '^_' with: '') replace: '_.*' with: ''.
  1418. ! !
  1419. !String methodsFor: 'copying'!
  1420. , aString
  1421. <return self + aString>
  1422. !
  1423. copyFrom: anIndex to: anotherIndex
  1424. <return self.substring(anIndex - 1, anotherIndex)>
  1425. !
  1426. shallowCopy
  1427. ^self class fromString: self
  1428. !
  1429. deepCopy
  1430. ^self shallowCopy
  1431. ! !
  1432. !String methodsFor: 'error handling'!
  1433. errorReadOnly
  1434. self error: 'Object is read-only'
  1435. ! !
  1436. !String methodsFor: 'printing'!
  1437. printString
  1438. ^'''', self, ''''
  1439. !
  1440. printNl
  1441. <console.log(self)>
  1442. ! !
  1443. !String methodsFor: 'regular expressions'!
  1444. replace: aString with: anotherString
  1445. ^self replaceRegexp: (RegularExpression fromString: aString flag: 'g') with: anotherString
  1446. !
  1447. replaceRegexp: aRegexp with: aString
  1448. <return self.replace(aRegexp, aString)>
  1449. !
  1450. match: aRegexp
  1451. <return self.search(aRegexp) !!= -1>
  1452. !
  1453. trimLeft: separators
  1454. ^self replaceRegexp: (RegularExpression fromString: '^[', separators, ']+' flag: 'g') with: ''
  1455. !
  1456. trimRight: separators
  1457. ^self replaceRegexp: (RegularExpression fromString: '[', separators, ']+$' flag: 'g') with: ''
  1458. !
  1459. trimLeft
  1460. ^self trimLeft: '\s'
  1461. !
  1462. trimRight
  1463. ^self trimRight: '\s'
  1464. !
  1465. trimBoth
  1466. ^self trimBoth: '\s'
  1467. !
  1468. trimBoth: separators
  1469. ^(self trimLeft: separators) trimRight: separators
  1470. ! !
  1471. !String methodsFor: 'split join'!
  1472. join: aCollection
  1473. ^ String
  1474. streamContents: [:stream | aCollection
  1475. do: [:each | stream nextPutAll: each asString]
  1476. separatedBy: [stream nextPutAll: self]]
  1477. !
  1478. lineIndicesDo: aBlock
  1479. "execute aBlock with 3 arguments for each line:
  1480. - start index of line
  1481. - end index of line without line delimiter
  1482. - end index of line including line delimiter(s) CR, LF or CRLF"
  1483. | cr lf start sz nextLF nextCR |
  1484. start := 1.
  1485. sz := self size.
  1486. cr := String cr.
  1487. nextCR := self indexOf: cr startingAt: 1.
  1488. lf := String lf.
  1489. nextLF := self indexOf: lf startingAt: 1.
  1490. [ start <= sz ] whileTrue: [
  1491. (nextLF = 0 and: [ nextCR = 0 ])
  1492. ifTrue: [ "No more CR, nor LF, the string is over"
  1493. aBlock value: start value: sz value: sz.
  1494. ^self ].
  1495. (nextCR = 0 or: [ 0 < nextLF and: [ nextLF < nextCR ] ])
  1496. ifTrue: [ "Found a LF"
  1497. aBlock value: start value: nextLF - 1 value: nextLF.
  1498. start := 1 + nextLF.
  1499. nextLF := self indexOf: lf startingAt: start ]
  1500. ifFalse: [ 1 + nextCR = nextLF
  1501. ifTrue: [ "Found a CR-LF pair"
  1502. aBlock value: start value: nextCR - 1 value: nextLF.
  1503. start := 1 + nextLF.
  1504. nextCR := self indexOf: cr startingAt: start.
  1505. nextLF := self indexOf: lf startingAt: start ]
  1506. ifFalse: [ "Found a CR"
  1507. aBlock value: start value: nextCR - 1 value: nextCR.
  1508. start := 1 + nextCR.
  1509. nextCR := self indexOf: cr startingAt: start ]]]
  1510. !
  1511. linesDo: aBlock
  1512. "Execute aBlock with each line in this string. The terminating line
  1513. delimiters CR, LF or CRLF pairs are not included in what is passed to aBlock"
  1514. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1515. aBlock value: (self copyFrom: start to: endWithoutDelimiters)]
  1516. !
  1517. lines
  1518. "Answer an array of lines composing this receiver without the line ending delimiters."
  1519. | lines |
  1520. lines := Array new.
  1521. self linesDo: [:aLine | lines add: aLine].
  1522. ^lines
  1523. !
  1524. lineNumber: anIndex
  1525. "Answer a string containing the characters in the given line number."
  1526. | lineCount |
  1527. lineCount := 0.
  1528. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1529. (lineCount := lineCount + 1) = anIndex ifTrue: [^self copyFrom: start to: endWithoutDelimiters]].
  1530. ^nil
  1531. ! !
  1532. !String methodsFor: 'testing'!
  1533. isString
  1534. ^true
  1535. !
  1536. includesSubString: subString
  1537. < return self.indexOf(subString) !!= -1 >
  1538. ! !
  1539. !String class methodsFor: 'accessing'!
  1540. streamClass
  1541. ^StringStream
  1542. !
  1543. cr
  1544. <return '\r'>
  1545. !
  1546. lf
  1547. <return '\n'>
  1548. !
  1549. space
  1550. <return ' '>
  1551. !
  1552. tab
  1553. <return '\t'>
  1554. !
  1555. crlf
  1556. <return '\r\n'>
  1557. ! !
  1558. !String class methodsFor: 'instance creation'!
  1559. fromString: aString
  1560. <return new self.fn(aString)>
  1561. !
  1562. streamContents: blockWithArg
  1563. |stream|
  1564. stream := (self streamClass on: String new).
  1565. blockWithArg value: stream.
  1566. ^ stream contents
  1567. !
  1568. value: aUTFCharCode
  1569. <return String.fromCharCode(aUTFCharCode);>
  1570. ! !
  1571. SequenceableCollection subclass: #Array
  1572. instanceVariableNames: ''
  1573. category: 'Kernel'!
  1574. !Array methodsFor: 'accessing'!
  1575. size
  1576. <return self.length>
  1577. !
  1578. at: anIndex put: anObject
  1579. <return self[anIndex - 1] = anObject>
  1580. !
  1581. at: anIndex ifAbsent: aBlock
  1582. <
  1583. var value = self[anIndex - 1];
  1584. if(value === undefined) {
  1585. return aBlock();
  1586. } else {
  1587. return value;
  1588. }
  1589. >
  1590. ! !
  1591. !Array methodsFor: 'adding/removing'!
  1592. add: anObject
  1593. <self.push(anObject); return anObject;>
  1594. !
  1595. remove: anObject
  1596. <
  1597. for(var i=0;i<self.length;i++) {
  1598. if(self[i] == anObject) {
  1599. self.splice(i,1);
  1600. break;
  1601. }
  1602. }
  1603. >
  1604. !
  1605. removeFrom: aNumber to: anotherNumber
  1606. <self.splice(aNumber - 1,anotherNumber - 1)>
  1607. ! !
  1608. !Array methodsFor: 'comparing'!
  1609. = aCollection
  1610. (self class = aCollection class and: [
  1611. self size = aCollection size]) ifFalse: [^false].
  1612. self withIndexDo: [:each :i |
  1613. (aCollection at: i) = each ifFalse: [^false]].
  1614. ^true
  1615. ! !
  1616. !Array methodsFor: 'converting'!
  1617. asJavascript
  1618. ^'[', ((self collect: [:each | each asJavascript]) join: ', '), ']'
  1619. !
  1620. asJSONObject
  1621. ^self collect: [:each | each asJSONObject]
  1622. !
  1623. reversed
  1624. <return self._copy().reverse()>
  1625. ! !
  1626. !Array methodsFor: 'copying'!
  1627. shallowCopy
  1628. | newCollection |
  1629. newCollection := self class new.
  1630. self do: [:each | newCollection add: each].
  1631. ^newCollection
  1632. !
  1633. deepCopy
  1634. | newCollection |
  1635. newCollection := self class new.
  1636. self do: [:each | newCollection add: each deepCopy].
  1637. ^newCollection
  1638. !
  1639. copyFrom: anIndex to: anotherIndex
  1640. | array |
  1641. array := self class new.
  1642. anIndex to: anotherIndex do: [:each |
  1643. array add: (self at: each)].
  1644. ^array
  1645. ! !
  1646. !Array methodsFor: 'enumerating'!
  1647. join: aString
  1648. <return self.join(aString)>
  1649. !
  1650. sort
  1651. ^self basicPerform: 'sort'
  1652. !
  1653. sort: aBlock
  1654. <
  1655. return self.sort(function(a, b) {
  1656. if(aBlock(a,b)) {return -1} else {return 1}
  1657. })
  1658. >
  1659. !
  1660. sorted
  1661. ^self copy sort
  1662. !
  1663. sorted: aBlock
  1664. ^self copy sort: aBlock
  1665. !
  1666. printString
  1667. | str |
  1668. str := '' writeStream.
  1669. str nextPutAll: super printString, ' ('.
  1670. self
  1671. do: [:each | str nextPutAll: each printString]
  1672. separatedBy: [str nextPutAll: ' '].
  1673. str nextPutAll: ')'.
  1674. ^str contents
  1675. ! !
  1676. Object subclass: #RegularExpression
  1677. instanceVariableNames: ''
  1678. category: 'Kernel'!
  1679. !RegularExpression methodsFor: 'evaluating'!
  1680. compile: aString
  1681. <return self.compile(aString)>
  1682. !
  1683. exec: aString
  1684. <return self.exec(aString) || nil>
  1685. !
  1686. test: aString
  1687. <return self.test(aString)>
  1688. ! !
  1689. !RegularExpression class methodsFor: 'instance creation'!
  1690. fromString: aString flag: anotherString
  1691. <return new RegExp(aString, anotherString)>
  1692. !
  1693. fromString: aString
  1694. ^self fromString: aString flag: ''
  1695. ! !
  1696. Object subclass: #Error
  1697. instanceVariableNames: 'messageText'
  1698. category: 'Kernel'!
  1699. !Error methodsFor: 'accessing'!
  1700. messageText
  1701. ^messageText
  1702. !
  1703. messageText: aString
  1704. messageText := aString
  1705. !
  1706. context
  1707. <return self.context>
  1708. ! !
  1709. !Error methodsFor: 'signaling'!
  1710. signal
  1711. <self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
  1712. ! !
  1713. !Error class methodsFor: 'instance creation'!
  1714. signal: aString
  1715. ^self new
  1716. messageText: aString;
  1717. signal
  1718. ! !
  1719. Object subclass: #MethodContext
  1720. instanceVariableNames: ''
  1721. category: 'Kernel'!
  1722. !MethodContext methodsFor: 'accessing'!
  1723. receiver
  1724. <return self.receiver>
  1725. !
  1726. selector
  1727. <return smalltalk.convertSelector(self.selector)>
  1728. !
  1729. home
  1730. <return self.homeContext>
  1731. !
  1732. temps
  1733. <return self.temps>
  1734. !
  1735. printString
  1736. ^super printString, '(', self asString, ')'
  1737. !
  1738. asString
  1739. ^self receiver class printString, ' >> ', self selector
  1740. ! !
  1741. Object subclass: #Association
  1742. instanceVariableNames: 'key value'
  1743. category: 'Kernel'!
  1744. !Association methodsFor: 'accessing'!
  1745. key: aKey
  1746. key := aKey
  1747. !
  1748. key
  1749. ^key
  1750. !
  1751. value: aValue
  1752. value := aValue
  1753. !
  1754. value
  1755. ^value
  1756. ! !
  1757. !Association methodsFor: 'comparing'!
  1758. = anAssociation
  1759. ^self class = anAssociation class and: [
  1760. self key = anAssociation key and: [
  1761. self value = anAssociation value]]
  1762. ! !
  1763. !Association class methodsFor: 'instance creation'!
  1764. key: aKey value: aValue
  1765. ^self new
  1766. key: aKey;
  1767. value: aValue;
  1768. yourself
  1769. ! !
  1770. Collection subclass: #Dictionary
  1771. instanceVariableNames: 'keys'
  1772. category: 'Kernel'!
  1773. !Dictionary methodsFor: 'accessing'!
  1774. size
  1775. ^keys size
  1776. !
  1777. associations
  1778. | associations |
  1779. associations := #().
  1780. keys do: [:each |
  1781. associations add: (Association key: each value: (self at: each))].
  1782. ^associations
  1783. !
  1784. keys
  1785. ^keys copy
  1786. !
  1787. values
  1788. ^keys collect: [:each | self at: each]
  1789. !
  1790. at: aKey put: aValue
  1791. (keys includes: aKey) ifFalse: [keys add: aKey].
  1792. ^self basicAt: aKey put: aValue
  1793. !
  1794. at: aKey ifAbsent: aBlock
  1795. ^(self keys includes: aKey)
  1796. ifTrue: [self basicAt: aKey]
  1797. ifFalse: aBlock
  1798. !
  1799. at: aKey ifAbsentPut: aBlock
  1800. ^self at: aKey ifAbsent: [
  1801. self at: aKey put: aBlock value]
  1802. !
  1803. at: aKey ifPresent: aBlock
  1804. ^(self basicAt: aKey) ifNotNil: [aBlock value: (self at: aKey)]
  1805. !
  1806. at: aKey ifPresent: aBlock ifAbsent: anotherBlock
  1807. ^(self basicAt: aKey)
  1808. ifNil: anotherBlock
  1809. ifNotNil: [aBlock value: (self at: aKey)]
  1810. !
  1811. at: aKey
  1812. ^self at: aKey ifAbsent: [self errorNotFound]
  1813. ! !
  1814. !Dictionary methodsFor: 'adding/removing'!
  1815. add: anAssociation
  1816. self at: anAssociation key put: anAssociation value
  1817. !
  1818. addAll: aDictionary
  1819. super addAll: aDictionary associations.
  1820. ^aDictionary
  1821. !
  1822. remove: aKey
  1823. self removeKey: aKey
  1824. !
  1825. removeKey: aKey
  1826. keys remove: aKey
  1827. ! !
  1828. !Dictionary methodsFor: 'comparing'!
  1829. = aDictionary
  1830. self class = aDictionary class ifFalse: [^false].
  1831. self size = aDictionary size ifFalse: [^false].
  1832. ^self associations = aDictionary associations
  1833. ! !
  1834. !Dictionary methodsFor: 'converting'!
  1835. asJSONObject
  1836. | object |
  1837. object := Object new.
  1838. self keysAndValuesDo: [:key :value |
  1839. object basicAt: key put: value asJSONObject].
  1840. ^object
  1841. ! !
  1842. !Dictionary methodsFor: 'copying'!
  1843. shallowCopy
  1844. | copy |
  1845. copy := self class new.
  1846. self associationsDo: [:each |
  1847. copy at: each key put: each value].
  1848. ^copy
  1849. !
  1850. , aCollection
  1851. self shouldNotImplement
  1852. !
  1853. copyFrom: anIndex to: anotherIndex
  1854. self shouldNotImplement
  1855. ! !
  1856. !Dictionary methodsFor: 'enumerating'!
  1857. associationsDo: aBlock
  1858. self associations do: aBlock
  1859. !
  1860. keysAndValuesDo: aBlock
  1861. self associationsDo: [:each |
  1862. aBlock value: each key value: each value]
  1863. !
  1864. do: aBlock
  1865. self values do: aBlock
  1866. !
  1867. select: aBlock
  1868. | newDict |
  1869. newDict := self class new.
  1870. self keysAndValuesDo: [:key :value |
  1871. (aBlock value: value) ifTrue: [newDict at: key put: value]].
  1872. ^newDict
  1873. !
  1874. collect: aBlock
  1875. | newDict |
  1876. newDict := self class new.
  1877. self keysAndValuesDo: [:key :value |
  1878. newDict at: key put: (aBlock value: value)].
  1879. ^newDict
  1880. !
  1881. detect: aBlock ifNone: anotherBlock
  1882. ^self values detect: aBlock ifNone: anotherBlock
  1883. !
  1884. includes: anObject
  1885. ^self values includes: anObject
  1886. ! !
  1887. !Dictionary methodsFor: 'initialization'!
  1888. initialize
  1889. super initialize.
  1890. keys := #()
  1891. ! !
  1892. !Dictionary methodsFor: 'printing'!
  1893. printString
  1894. ^ String streamContents: [:aStream|
  1895. aStream
  1896. nextPutAll: super printString;
  1897. nextPutAll: '('.
  1898. self associations
  1899. do: [:anAssociation|
  1900. aStream
  1901. nextPutAll: anAssociation key printString;
  1902. nextPutAll: ' -> ';
  1903. nextPutAll: anAssociation value printString]
  1904. separatedBy: [aStream nextPutAll: ' , '].
  1905. aStream nextPutAll: ')'.
  1906. ]
  1907. ! !
  1908. !Dictionary class methodsFor: 'instance creation'!
  1909. fromPairs: aCollection
  1910. | dict |
  1911. dict := self new.
  1912. aCollection do: [:each | dict add: each].
  1913. ^dict
  1914. ! !
  1915. Object subclass: #ClassBuilder
  1916. instanceVariableNames: ''
  1917. category: 'Kernel'!
  1918. !ClassBuilder methodsFor: 'class creation'!
  1919. superclass: aClass subclass: aString
  1920. ^self superclass: aClass subclass: aString instanceVariableNames: '' package: nil
  1921. !
  1922. class: aClass instanceVariableNames: aString
  1923. aClass isMetaclass ifFalse: [self error: aClass name, ' is not a metaclass'].
  1924. aClass basicAt: 'iVarNames' put: (self instanceVariableNamesFor: aString).
  1925. self setupClass: aClass
  1926. !
  1927. superclass: aClass subclass: aString instanceVariableNames: aString2 package: aString3
  1928. | newClass |
  1929. newClass := self addSubclassOf: aClass
  1930. named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2)
  1931. package: (aString3 ifNil: ['unclassified']).
  1932. self setupClass: newClass.
  1933. ^newClass
  1934. ! !
  1935. !ClassBuilder methodsFor: 'private'!
  1936. instanceVariableNamesFor: aString
  1937. ^(aString tokenize: ' ') reject: [:each | each isEmpty]
  1938. !
  1939. addSubclassOf: aClass named: aString instanceVariableNames: aCollection
  1940. <smalltalk.addClass(aString, aClass, aCollection);
  1941. return smalltalk[aString]>
  1942. !
  1943. setupClass: aClass
  1944. <smalltalk.init(aClass);>
  1945. !
  1946. addSubclassOf: aClass named: aString instanceVariableNames: aCollection package: packageName
  1947. <smalltalk.addClass(aString, aClass, aCollection, packageName);
  1948. return smalltalk[aString]>
  1949. ! !
  1950. Object subclass: #ClassCategoryReader
  1951. instanceVariableNames: 'class category chunkParser'
  1952. category: 'Kernel'!
  1953. !ClassCategoryReader methodsFor: 'accessing'!
  1954. class: aClass category: aString
  1955. class := aClass.
  1956. category := aString
  1957. ! !
  1958. !ClassCategoryReader methodsFor: 'fileIn'!
  1959. scanFrom: aChunkParser
  1960. | chunk |
  1961. [chunk := aChunkParser nextChunk.
  1962. chunk isEmpty] whileFalse: [
  1963. self compileMethod: chunk]
  1964. ! !
  1965. !ClassCategoryReader methodsFor: 'initialization'!
  1966. initialize
  1967. super initialize.
  1968. chunkParser := ChunkParser new.
  1969. ! !
  1970. !ClassCategoryReader methodsFor: 'private'!
  1971. compileMethod: aString
  1972. | method |
  1973. method := Compiler new load: aString forClass: class.
  1974. method category: category.
  1975. class addCompiledMethod: method
  1976. ! !
  1977. Object subclass: #Stream
  1978. instanceVariableNames: 'collection position streamSize'
  1979. category: 'Kernel'!
  1980. !Stream methodsFor: 'accessing'!
  1981. collection
  1982. ^collection
  1983. !
  1984. setCollection: aCollection
  1985. collection := aCollection
  1986. !
  1987. position
  1988. ^position ifNil: [position := 0]
  1989. !
  1990. position: anInteger
  1991. position := anInteger
  1992. !
  1993. streamSize
  1994. ^streamSize
  1995. !
  1996. setStreamSize: anInteger
  1997. streamSize := anInteger
  1998. !
  1999. contents
  2000. ^self collection
  2001. copyFrom: 1
  2002. to: self streamSize
  2003. !
  2004. size
  2005. ^self streamSize
  2006. ! !
  2007. !Stream methodsFor: 'actions'!
  2008. reset
  2009. self position: 0
  2010. !
  2011. close
  2012. !
  2013. flush
  2014. !
  2015. resetContents
  2016. self reset.
  2017. self setStreamSize: 0
  2018. ! !
  2019. !Stream methodsFor: 'enumerating'!
  2020. do: aBlock
  2021. [self atEnd] whileFalse: [aBlock value: self next]
  2022. ! !
  2023. !Stream methodsFor: 'positioning'!
  2024. setToEnd
  2025. self position: self size
  2026. !
  2027. skip: anInteger
  2028. self position: ((self position + anInteger) min: self size max: 0)
  2029. ! !
  2030. !Stream methodsFor: 'reading'!
  2031. next
  2032. self position: self position + 1.
  2033. ^collection at: self position
  2034. !
  2035. next: anInteger
  2036. | tempCollection |
  2037. tempCollection := self collection class new.
  2038. anInteger timesRepeat: [
  2039. self atEnd ifFalse: [
  2040. tempCollection add: self next]].
  2041. ^tempCollection
  2042. !
  2043. peek
  2044. ^self atEnd ifFalse: [
  2045. self collection at: self position + 1]
  2046. ! !
  2047. !Stream methodsFor: 'testing'!
  2048. atEnd
  2049. ^self position = self size
  2050. !
  2051. atStart
  2052. ^self position = 0
  2053. !
  2054. isEmpty
  2055. ^self size = 0
  2056. ! !
  2057. !Stream methodsFor: 'writing'!
  2058. nextPut: anObject
  2059. self position: self position + 1.
  2060. self collection at: self position put: anObject.
  2061. self setStreamSize: (self streamSize max: self position)
  2062. !
  2063. nextPutAll: aCollection
  2064. aCollection do: [:each |
  2065. self nextPut: each]
  2066. ! !
  2067. !Stream class methodsFor: 'instance creation'!
  2068. on: aCollection
  2069. ^self new
  2070. setCollection: aCollection;
  2071. setStreamSize: aCollection size;
  2072. yourself
  2073. ! !
  2074. Stream subclass: #StringStream
  2075. instanceVariableNames: ''
  2076. category: 'Kernel'!
  2077. !StringStream methodsFor: 'reading'!
  2078. next: anInteger
  2079. | tempCollection |
  2080. tempCollection := self collection class new.
  2081. anInteger timesRepeat: [
  2082. self atEnd ifFalse: [
  2083. tempCollection := tempCollection, self next]].
  2084. ^tempCollection
  2085. ! !
  2086. !StringStream methodsFor: 'writing'!
  2087. nextPut: aString
  2088. self nextPutAll: aString
  2089. !
  2090. nextPutAll: aString
  2091. self setCollection:
  2092. (self collection copyFrom: 1 to: self position),
  2093. aString,
  2094. (self collection copyFrom: (self position + 1 + aString size) to: self collection size).
  2095. self position: self position + aString size.
  2096. self setStreamSize: (self streamSize max: self position)
  2097. !
  2098. cr
  2099. ^self nextPutAll: String cr
  2100. !
  2101. crlf
  2102. ^self nextPutAll: String crlf
  2103. !
  2104. lf
  2105. ^self nextPutAll: String lf
  2106. !
  2107. space
  2108. self nextPut: ' '
  2109. ! !
  2110. Object subclass: #ClassCommentReader
  2111. instanceVariableNames: 'class chunkParser'
  2112. category: 'Kernel'!
  2113. !ClassCommentReader methodsFor: 'accessing'!
  2114. class: aClass
  2115. class := aClass
  2116. ! !
  2117. !ClassCommentReader methodsFor: 'fileIn'!
  2118. scanFrom: aChunkParser
  2119. | chunk |
  2120. chunk := aChunkParser nextChunk.
  2121. chunk isEmpty ifFalse: [
  2122. self setComment: chunk].
  2123. ! !
  2124. !ClassCommentReader methodsFor: 'initialization'!
  2125. initialize
  2126. super initialize.
  2127. chunkParser := ChunkParser new.
  2128. ! !
  2129. !ClassCommentReader methodsFor: 'private'!
  2130. setComment: aString
  2131. class comment: aString
  2132. ! !
  2133. Object subclass: #Random
  2134. instanceVariableNames: ''
  2135. category: 'Kernel'!
  2136. !Random methodsFor: 'accessing'!
  2137. next
  2138. <return Math.random()>
  2139. !
  2140. next: anInteger
  2141. ^(1 to: anInteger) collect: [:each | self next]
  2142. ! !
  2143. Object subclass: #Point
  2144. instanceVariableNames: 'x y'
  2145. category: 'Kernel'!
  2146. !Point methodsFor: 'accessing'!
  2147. x
  2148. ^x
  2149. !
  2150. y
  2151. ^y
  2152. !
  2153. y: aNumber
  2154. y := aNumber
  2155. !
  2156. x: aNumber
  2157. x := aNumber
  2158. ! !
  2159. !Point methodsFor: 'arithmetic'!
  2160. * aPoint
  2161. ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
  2162. !
  2163. + aPoint
  2164. ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
  2165. !
  2166. - aPoint
  2167. ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
  2168. !
  2169. / aPoint
  2170. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  2171. !
  2172. = aPoint
  2173. ^aPoint class = self class and: [
  2174. (aPoint x = self x) & (aPoint y = self y)]
  2175. ! !
  2176. !Point methodsFor: 'converting'!
  2177. asPoint
  2178. ^self
  2179. ! !
  2180. !Point class methodsFor: 'instance creation'!
  2181. x: aNumber y: anotherNumber
  2182. ^self new
  2183. x: aNumber;
  2184. y: anotherNumber;
  2185. yourself
  2186. ! !
  2187. Object subclass: #Message
  2188. instanceVariableNames: 'selector arguments'
  2189. category: 'Kernel'!
  2190. !Message methodsFor: 'accessing'!
  2191. selector
  2192. ^selector
  2193. !
  2194. selector: aString
  2195. selector := aString
  2196. !
  2197. arguments: anArray
  2198. arguments := anArray
  2199. !
  2200. arguments
  2201. ^arguments
  2202. ! !
  2203. !Message methodsFor: 'printing'!
  2204. printString
  2205. ^ String streamContents: [:aStream|
  2206. aStream
  2207. nextPutAll: super printString;
  2208. nextPutAll: '(';
  2209. nextPutAll: selector;
  2210. nextPutAll: ')' ]
  2211. ! !
  2212. !Message class methodsFor: 'instance creation'!
  2213. selector: aString arguments: anArray
  2214. ^self new
  2215. selector: aString;
  2216. arguments: anArray;
  2217. yourself
  2218. ! !
  2219. Error subclass: #MessageNotUnderstood
  2220. instanceVariableNames: 'message receiver'
  2221. category: 'Kernel'!
  2222. !MessageNotUnderstood methodsFor: 'accessing'!
  2223. message
  2224. ^message
  2225. !
  2226. message: aMessage
  2227. message := aMessage
  2228. !
  2229. receiver
  2230. ^receiver
  2231. !
  2232. receiver: anObject
  2233. receiver := anObject
  2234. !
  2235. messageText
  2236. ^self receiver asString, ' does not understand #', self message selector
  2237. ! !
  2238. Object subclass: #ErrorHandler
  2239. instanceVariableNames: ''
  2240. category: 'Kernel'!
  2241. !ErrorHandler methodsFor: 'error handling'!
  2242. handleError: anError
  2243. anError context ifNotNil: [self logErrorContext: anError context].
  2244. self logError: anError
  2245. ! !
  2246. !ErrorHandler methodsFor: 'private'!
  2247. logContext: aContext
  2248. aContext home ifNotNil: [
  2249. self logContext: aContext home].
  2250. self log: aContext receiver asString, '>>', aContext selector
  2251. !
  2252. logErrorContext: aContext
  2253. aContext ifNotNil: [
  2254. aContext home ifNotNil: [
  2255. self logContext: aContext home]]
  2256. !
  2257. logError: anError
  2258. self log: anError messageText
  2259. !
  2260. log: aString
  2261. console log: aString
  2262. ! !
  2263. ErrorHandler class instanceVariableNames: 'current'!
  2264. !ErrorHandler class methodsFor: 'accessing'!
  2265. current
  2266. ^current ifNil: [current := self new]
  2267. !
  2268. setCurrent: anHandler
  2269. current := anHandler
  2270. ! !
  2271. !ErrorHandler class methodsFor: 'initialization'!
  2272. initialize
  2273. self register
  2274. !
  2275. register
  2276. ErrorHandler setCurrent: self new
  2277. ! !
  2278. Object subclass: #JSObjectProxy
  2279. instanceVariableNames: 'jsObject'
  2280. category: 'Kernel'!
  2281. !JSObjectProxy methodsFor: 'accessing'!
  2282. jsObject: aJSObject
  2283. jsObject := aJSObject
  2284. !
  2285. jsObject
  2286. ^jsObject
  2287. !
  2288. at: aString
  2289. <return self['@jsObject'][aString]>
  2290. !
  2291. at: aString put: anObject
  2292. <self['@jsObject'][aString] = anObject>
  2293. ! !
  2294. !JSObjectProxy methodsFor: 'proxy'!
  2295. printString
  2296. ^self jsObject toString
  2297. !
  2298. inspectOn: anInspector
  2299. | variables |
  2300. variables := Dictionary new.
  2301. variables at: '#self' put: self jsObject.
  2302. anInspector setLabel: self printString.
  2303. <for(var i in self['@jsObject']) {
  2304. variables._at_put_(i, self['@jsObject'][i]);
  2305. }>.
  2306. anInspector setVariables: variables
  2307. !
  2308. doesNotUnderstand: aMessage
  2309. | obj selector jsSelector arguments |
  2310. obj := self jsObject.
  2311. selector := aMessage selector.
  2312. jsSelector := selector asJavaScriptSelector.
  2313. arguments := aMessage arguments.
  2314. <if(obj[jsSelector] !!= undefined) {return smalltalk.send(obj, jsSelector, arguments)}>.
  2315. super doesNotUnderstand: aMessage
  2316. ! !
  2317. !JSObjectProxy class methodsFor: 'instance creation'!
  2318. on: aJSObject
  2319. ^self new
  2320. jsObject: aJSObject;
  2321. yourself
  2322. ! !
  2323. Collection subclass: #Set
  2324. instanceVariableNames: 'elements'
  2325. category: 'Kernel'!
  2326. !Set methodsFor: 'accessing'!
  2327. size
  2328. ^elements size
  2329. ! !
  2330. !Set methodsFor: 'adding/removing'!
  2331. add: anObject
  2332. <
  2333. var found;
  2334. for(var i in self['@elements']) {
  2335. if(anObject == self['@elements'][i]) {
  2336. found = true;
  2337. break;
  2338. }
  2339. }
  2340. if(!!found) {self['@elements'].push(anObject)}
  2341. >
  2342. !
  2343. remove: anObject
  2344. elements remove: anObject
  2345. ! !
  2346. !Set methodsFor: 'comparing'!
  2347. = aCollection
  2348. ^self class = aCollection class and: [
  2349. elements = aCollection asArray]
  2350. ! !
  2351. !Set methodsFor: 'converting'!
  2352. asArray
  2353. ^elements copy
  2354. ! !
  2355. !Set methodsFor: 'enumerating'!
  2356. detect: aBlock ifNone: anotherBlock
  2357. ^elements detect: aBlock ifNone: anotherBlock
  2358. !
  2359. do: aBlock
  2360. elements do: aBlock
  2361. ! !
  2362. !Set methodsFor: 'initialization'!
  2363. initialize
  2364. super initialize.
  2365. elements := #()
  2366. ! !
  2367. !Set methodsFor: 'testing'!
  2368. includes: anObject
  2369. ^elements includes: anObject
  2370. ! !
  2371. Object subclass: #Transcript
  2372. instanceVariableNames: 'textarea'
  2373. category: 'Kernel'!
  2374. Transcript class instanceVariableNames: 'current'!
  2375. !Transcript class methodsFor: 'instance creation'!
  2376. open
  2377. self current open
  2378. !
  2379. new
  2380. self shouldNotImplement
  2381. !
  2382. current
  2383. ^current
  2384. !
  2385. register: aTranscript
  2386. current := aTranscript
  2387. ! !
  2388. !Transcript class methodsFor: 'printing'!
  2389. show: anObject
  2390. self current show: anObject
  2391. !
  2392. cr
  2393. self current show: String cr
  2394. !
  2395. clear
  2396. self current clear
  2397. ! !
  2398. Object subclass: #ConsoleTranscript
  2399. instanceVariableNames: 'textarea'
  2400. category: 'Kernel'!
  2401. !ConsoleTranscript methodsFor: 'actions'!
  2402. open
  2403. ! !
  2404. !ConsoleTranscript methodsFor: 'printing'!
  2405. clear
  2406. "no op"
  2407. !
  2408. cr
  2409. "no op"
  2410. !
  2411. show: anObject
  2412. <console.log(String(anObject._asString()))>
  2413. ! !
  2414. !ConsoleTranscript class methodsFor: 'initialization'!
  2415. initialize
  2416. Transcript register: self new
  2417. ! !