Kernel.st 54 KB

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