Kernel.st 56 KB

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