Kernel.st 55 KB

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