Kernel.st 55 KB

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