Kernel.st 55 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281
  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: 'arithmetic'!
  612. + aNumber
  613. "Inlined in the Compiler"
  614. <return self + aNumber>
  615. !
  616. - aNumber
  617. "Inlined in the Compiler"
  618. <return self - aNumber>
  619. !
  620. * aNumber
  621. "Inlined in the Compiler"
  622. <return self * aNumber>
  623. !
  624. / aNumber
  625. "Inlined in the Compiler"
  626. <return self / aNumber>
  627. !
  628. max: aNumber
  629. <return Math.max(self, aNumber);>
  630. !
  631. min: aNumber
  632. <return Math.min(self, aNumber);>
  633. !
  634. negated
  635. ^0 - self
  636. !
  637. \\ aNumber
  638. <return self % aNumber>
  639. !
  640. sqrt
  641. <return Math.sqrt(self)>
  642. !
  643. squared
  644. ^self * self
  645. ! !
  646. !Number methodsFor: 'comparing'!
  647. = aNumber
  648. aNumber class = self class ifFalse: [^false].
  649. <return Number(self) == aNumber>
  650. !
  651. > aNumber
  652. "Inlined in the Compiler"
  653. <return self >> aNumber>
  654. !
  655. < aNumber
  656. "Inlined in the Compiler"
  657. <return self < aNumber>
  658. !
  659. >= aNumber
  660. "Inlined in the Compiler"
  661. <return self >>= aNumber>
  662. !
  663. <= aNumber
  664. "Inlined in the Compiler"
  665. <return self <= aNumber>
  666. !
  667. == aNumber
  668. aNumber class = self class ifFalse: [^false].
  669. <return Number(self) === Number(aNumber)>
  670. ! !
  671. !Number methodsFor: 'converting'!
  672. rounded
  673. <return Math.round(self);>
  674. !
  675. truncated
  676. |result|
  677. self >= 0
  678. ifTrue: [<result = Math.floor(self);>]
  679. ifFalse: [<result = (Math.floor(self * (-1)) * (-1));>].
  680. ^ result
  681. !
  682. to: aNumber
  683. | array first last count |
  684. first := self truncated.
  685. last := aNumber truncated + 1.
  686. count := 1.
  687. array := Array new.
  688. (last - first) timesRepeat: [
  689. array at: count put: first.
  690. count := count + 1.
  691. first := first + 1].
  692. ^array
  693. !
  694. asString
  695. ^self printString
  696. !
  697. asJavascript
  698. ^'(', self printString, ')'
  699. !
  700. atRandom
  701. ^(Random new next * self) truncated + 1
  702. !
  703. @ aNumber
  704. ^Point x: self y: aNumber
  705. !
  706. asPoint
  707. ^Point x: self y: self
  708. !
  709. asJSONObject
  710. ^self
  711. !
  712. to: stop by: step
  713. | array value pos |
  714. value := self.
  715. array := Array new.
  716. pos := 1.
  717. step = 0 ifTrue: [self error: 'step must be non-zero'].
  718. step < 0
  719. ifTrue: [[ value >= stop ] whileTrue: [
  720. array at: pos put: value.
  721. pos := pos + 1.
  722. value := value + step]]
  723. ifFalse: [[ value <= stop ] whileTrue: [
  724. array at: pos put: value.
  725. pos := pos + 1.
  726. value := value + step]].
  727. ^array
  728. ! !
  729. !Number methodsFor: 'copying'!
  730. deepCopy
  731. ^self copy
  732. !
  733. copy
  734. ^self
  735. ! !
  736. !Number methodsFor: 'enumerating'!
  737. timesRepeat: aBlock
  738. | integer count |
  739. integer := self truncated.
  740. count := 1.
  741. [count > self] whileFalse: [
  742. aBlock value.
  743. count := count + 1]
  744. !
  745. to: stop do: aBlock
  746. "Evaluate aBlock for each number from self to aNumber."
  747. | nextValue |
  748. nextValue := self.
  749. [nextValue <= stop]
  750. whileTrue:
  751. [aBlock value: nextValue.
  752. nextValue := nextValue + 1]
  753. !
  754. to: stop by: step do: aBlock
  755. | value |
  756. value := self.
  757. step = 0 ifTrue: [self error: 'step must be non-zero'].
  758. step < 0
  759. ifTrue: [[ value >= stop ] whileTrue: [
  760. aBlock value: value.
  761. value := value + step]]
  762. ifFalse: [[ value <= stop ] whileTrue: [
  763. aBlock value: value.
  764. value := value + step]]
  765. ! !
  766. !Number methodsFor: 'printing'!
  767. printString
  768. <return String(self)>
  769. !
  770. printShowingDecimalPlaces: placesDesired
  771. <return self.toFixed(placesDesired)>
  772. ! !
  773. !Number methodsFor: 'testing'!
  774. isNumber
  775. ^true
  776. !
  777. even
  778. ^ 0 = (self \\ 2)
  779. !
  780. odd
  781. ^ self even not
  782. ! !
  783. !Number methodsFor: 'timeouts/intervals'!
  784. clearInterval
  785. <clearInterval(Number(self))>
  786. !
  787. clearTimeout
  788. <clearTimeout(Number(self))>
  789. ! !
  790. !Number class methodsFor: 'instance creation'!
  791. pi
  792. <return Math.PI>
  793. ! !
  794. Object subclass: #BlockClosure
  795. instanceVariableNames: ''
  796. category: 'Kernel'!
  797. !BlockClosure methodsFor: 'accessing'!
  798. compiledSource
  799. <return self.toString()>
  800. ! !
  801. !BlockClosure methodsFor: 'controlling'!
  802. whileTrue: aBlock
  803. "inlined in the Compiler"
  804. <while(self()) {aBlock()}>
  805. !
  806. whileFalse: aBlock
  807. "inlined in the Compiler"
  808. <while(!!self()) {aBlock()}>
  809. !
  810. whileFalse
  811. "inlined in the Compiler"
  812. self whileFalse: []
  813. !
  814. whileTrue
  815. "inlined in the Compiler"
  816. self whileTrue: []
  817. ! !
  818. !BlockClosure methodsFor: 'error handling'!
  819. on: anErrorClass do: aBlock
  820. self try: self catch: [:error |
  821. (error isKindOf: anErrorClass)
  822. ifTrue: [aBlock value: error]
  823. ifFalse: [error signal]]
  824. ! !
  825. !BlockClosure methodsFor: 'evaluating'!
  826. value
  827. "inlined in the Compiler"
  828. <return self();>
  829. !
  830. value: anArg
  831. "inlined in the Compiler"
  832. <return self(anArg);>
  833. !
  834. value: firstArg value: secondArg
  835. "inlined in the Compiler"
  836. <return self(firstArg, secondArg);>
  837. !
  838. value: firstArg value: secondArg value: thirdArg
  839. "inlined in the Compiler"
  840. <return self(firstArg, secondArg, thirdArg);>
  841. !
  842. valueWithPossibleArguments: aCollection
  843. <return self.apply(null, aCollection);>
  844. !
  845. new
  846. "Use the receiver as a JS constructor.
  847. *Do not* use this method to instanciate Smalltalk objects!!"
  848. <return new self()>
  849. !
  850. applyTo: anObject arguments: aCollection
  851. <return self.apply(anObject, aCollection)>
  852. !
  853. timeToRun
  854. "Answer the number of milliseconds taken to execute this block."
  855. ^ Date millisecondsToRun: self
  856. ! !
  857. !BlockClosure methodsFor: 'timeout/interval'!
  858. valueWithTimeout: aNumber
  859. <return setTimeout(self, aNumber)>
  860. !
  861. valueWithInterval: aNumber
  862. <return setInterval(self, aNumber)>
  863. ! !
  864. Object subclass: #Boolean
  865. instanceVariableNames: ''
  866. category: 'Kernel'!
  867. !Boolean methodsFor: 'comparing'!
  868. = aBoolean
  869. aBoolean class = self class ifFalse: [^false].
  870. <return Boolean(self == true) == aBoolean>
  871. !
  872. == aBoolean
  873. aBoolean class = self class ifFalse: [^false].
  874. <return Boolean(self == true) === Boolean(aBoolean == true)>
  875. ! !
  876. !Boolean methodsFor: 'controlling'!
  877. ifTrue: aBlock
  878. "inlined in the Compiler"
  879. ^self ifTrue: aBlock ifFalse: []
  880. !
  881. ifFalse: aBlock
  882. "inlined in the Compiler"
  883. ^self ifTrue: [] ifFalse: aBlock
  884. !
  885. ifFalse: aBlock ifTrue: anotherBlock
  886. "inlined in the Compiler"
  887. ^self ifTrue: anotherBlock ifFalse: aBlock
  888. !
  889. ifTrue: aBlock ifFalse: anotherBlock
  890. "inlined in the Compiler"
  891. <
  892. if(self == true) {
  893. return aBlock();
  894. } else {
  895. return anotherBlock();
  896. }
  897. >
  898. !
  899. and: aBlock
  900. ^self = true
  901. ifTrue: aBlock
  902. ifFalse: [false]
  903. !
  904. or: aBlock
  905. ^self = true
  906. ifTrue: [true]
  907. ifFalse: aBlock
  908. !
  909. not
  910. ^self = false
  911. !
  912. & aBoolean
  913. <
  914. if(self == true) {
  915. return aBoolean;
  916. } else {
  917. return false;
  918. }
  919. >
  920. !
  921. | aBoolean
  922. <
  923. if(self == true) {
  924. return true;
  925. } else {
  926. return aBoolean;
  927. }
  928. >
  929. ! !
  930. !Boolean methodsFor: 'converting'!
  931. asJSONObject
  932. ^self
  933. ! !
  934. !Boolean methodsFor: 'copying'!
  935. shallowCopy
  936. ^self
  937. !
  938. deepCopy
  939. ^self
  940. ! !
  941. !Boolean methodsFor: 'printing'!
  942. printString
  943. <return self.toString()>
  944. ! !
  945. Object subclass: #Date
  946. instanceVariableNames: ''
  947. category: 'Kernel'!
  948. !Date commentStamp!
  949. The Date class is used to work with dates and times.!
  950. !Date methodsFor: 'accessing'!
  951. year
  952. <return self.getFullYear()>
  953. !
  954. month
  955. <return self.getMonth() + 1>
  956. !
  957. month: aNumber
  958. <self.setMonth(aNumber - 1)>
  959. !
  960. day
  961. ^self dayOfWeek
  962. !
  963. dayOfWeek
  964. <return self.getDay() + 1>
  965. !
  966. dayOfWeek: aNumber
  967. <return self.setDay(aNumber - 1)>
  968. !
  969. day: aNumber
  970. self day: aNumber
  971. !
  972. year: aNumber
  973. <self.setFullYear(aNumber)>
  974. !
  975. dayOfMonth
  976. <return self.getDate()>
  977. !
  978. dayOfMonth: aNumber
  979. <self.setDate(aNumber)>
  980. !
  981. time
  982. <return self.getTime()>
  983. !
  984. time: aNumber
  985. <self.setTime(aNumber)>
  986. !
  987. hours: aNumber
  988. <self.setHours(aNumber)>
  989. !
  990. minutes: aNumber
  991. <self.setMinutes(aNumber)>
  992. !
  993. seconds: aNumber
  994. <self.setSeconds(aNumber)>
  995. !
  996. milliseconds: aNumber
  997. <self.setMilliseconds(aNumber)>
  998. !
  999. hours
  1000. <return self.getHours()>
  1001. !
  1002. minutes
  1003. <return self.getMinutes()>
  1004. !
  1005. seconds
  1006. <return self.getSeconds()>
  1007. !
  1008. milliseconds
  1009. <return self.getMilliseconds()>
  1010. ! !
  1011. !Date methodsFor: 'arithmetic'!
  1012. - aDate
  1013. <return self - aDate>
  1014. !
  1015. + aDate
  1016. <return self + aDate>
  1017. ! !
  1018. !Date methodsFor: 'comparing'!
  1019. < aDate
  1020. <return self < aDate>
  1021. !
  1022. > aDate
  1023. <return self >> aDate>
  1024. !
  1025. <= aDate
  1026. <return self <= aDate>
  1027. !
  1028. >= aDate
  1029. <return self >>= aDate>
  1030. ! !
  1031. !Date methodsFor: 'converting'!
  1032. asString
  1033. <return self.toString()>
  1034. !
  1035. asMilliseconds
  1036. ^self time
  1037. !
  1038. asDateString
  1039. <return self.toDateString()>
  1040. !
  1041. asTimeString
  1042. <return self.toTimeString()>
  1043. !
  1044. asLocaleString
  1045. <return self.toLocaleString()>
  1046. !
  1047. asNumber
  1048. ^self asMilliseconds
  1049. !
  1050. asJSONObject
  1051. ^self
  1052. ! !
  1053. !Date methodsFor: 'printing'!
  1054. printString
  1055. ^self asString
  1056. ! !
  1057. !Date class methodsFor: 'instance creation'!
  1058. new: anObject
  1059. <return new Date(anObject)>
  1060. !
  1061. fromString: aString
  1062. "Example: Date fromString('2011/04/15 00:00:00')"
  1063. ^self new: aString
  1064. !
  1065. fromSeconds: aNumber
  1066. ^self fromMilliseconds: aNumber * 1000
  1067. !
  1068. fromMilliseconds: aNumber
  1069. ^self new: aNumber
  1070. !
  1071. today
  1072. ^self new
  1073. !
  1074. now
  1075. ^self today
  1076. !
  1077. millisecondsToRun: aBlock
  1078. | t |
  1079. t := Date now.
  1080. aBlock value.
  1081. ^Date now - t
  1082. ! !
  1083. Object subclass: #UndefinedObject
  1084. instanceVariableNames: ''
  1085. category: 'Kernel'!
  1086. !UndefinedObject methodsFor: 'class creation'!
  1087. subclass: aString instanceVariableNames: anotherString
  1088. ^self subclass: aString instanceVariableNames: anotherString package: nil
  1089. !
  1090. subclass: aString instanceVariableNames: aString2 category: aString3
  1091. "Kept for compatibility."
  1092. ^self subclass: aString instanceVariableNames: aString2 package: aString3
  1093. !
  1094. subclass: aString instanceVariableNames: aString2 package: aString3
  1095. ^ClassBuilder new
  1096. superclass: self subclass: aString instanceVariableNames: aString2 package: aString3
  1097. ! !
  1098. !UndefinedObject methodsFor: 'copying'!
  1099. shallowCopy
  1100. ^self
  1101. !
  1102. deepCopy
  1103. ^self
  1104. ! !
  1105. !UndefinedObject methodsFor: 'printing'!
  1106. printString
  1107. ^'nil'
  1108. ! !
  1109. !UndefinedObject methodsFor: 'testing'!
  1110. ifNil: aBlock
  1111. "inlined in the Compiler"
  1112. ^self ifNil: aBlock ifNotNil: []
  1113. !
  1114. ifNotNil: aBlock
  1115. "inlined in the Compiler"
  1116. ^self
  1117. !
  1118. ifNil: aBlock ifNotNil: anotherBlock
  1119. "inlined in the Compiler"
  1120. ^aBlock value
  1121. !
  1122. ifNotNil: aBlock ifNil: anotherBlock
  1123. "inlined in the Compiler"
  1124. ^anotherBlock value
  1125. !
  1126. isNil
  1127. ^true
  1128. !
  1129. notNil
  1130. ^false
  1131. ! !
  1132. !UndefinedObject class methodsFor: 'instance creation'!
  1133. new
  1134. self error: 'You cannot create new instances of UndefinedObject. Use nil'
  1135. ! !
  1136. Object subclass: #Collection
  1137. instanceVariableNames: ''
  1138. category: 'Kernel'!
  1139. !Collection methodsFor: 'accessing'!
  1140. size
  1141. self subclassResponsibility
  1142. !
  1143. readStream
  1144. ^self stream
  1145. !
  1146. writeStream
  1147. ^self stream
  1148. !
  1149. stream
  1150. ^self streamClass on: self
  1151. !
  1152. streamClass
  1153. ^self class streamClass
  1154. ! !
  1155. !Collection methodsFor: 'adding/removing'!
  1156. add: anObject
  1157. self subclassResponsibility
  1158. !
  1159. addAll: aCollection
  1160. aCollection do: [:each |
  1161. self add: each].
  1162. ^aCollection
  1163. !
  1164. remove: anObject
  1165. self subclassResponsibility
  1166. ! !
  1167. !Collection methodsFor: 'converting'!
  1168. asArray
  1169. | array index |
  1170. array := Array new.
  1171. index := 0.
  1172. self do: [:each |
  1173. index := index + 1.
  1174. array at: index put: each].
  1175. ^array
  1176. !
  1177. asSet
  1178. ^Set withAll: self
  1179. ! !
  1180. !Collection methodsFor: 'copying'!
  1181. , aCollection
  1182. ^self copy
  1183. addAll: aCollection;
  1184. yourself
  1185. !
  1186. copyWith: anObject
  1187. ^self copy add: anObject; yourself
  1188. !
  1189. copyWithAll: aCollection
  1190. ^self copy addAll: aCollection; yourself
  1191. !
  1192. copyWithoutAll: aCollection
  1193. "Answer a copy of the receiver that does not contain any elements
  1194. equal to those in aCollection."
  1195. ^ self reject: [:each | aCollection includes: each]
  1196. ! !
  1197. !Collection methodsFor: 'enumerating'!
  1198. do: aBlock
  1199. <for(var i=0;i<self.length;i++){aBlock(self[i]);}>
  1200. !
  1201. collect: aBlock
  1202. | newCollection |
  1203. newCollection := self class new.
  1204. self do: [:each |
  1205. newCollection add: (aBlock value: each)].
  1206. ^newCollection
  1207. !
  1208. detect: aBlock
  1209. ^self detect: aBlock ifNone: [self errorNotFound]
  1210. !
  1211. detect: aBlock ifNone: anotherBlock
  1212. <
  1213. for(var i = 0; i < self.length; i++)
  1214. if(aBlock(self[i]))
  1215. return self[i];
  1216. return anotherBlock();
  1217. >
  1218. !
  1219. do: aBlock separatedBy: anotherBlock
  1220. | first |
  1221. first := true.
  1222. self do: [:each |
  1223. first
  1224. ifTrue: [first := false]
  1225. ifFalse: [anotherBlock value].
  1226. aBlock value: each]
  1227. !
  1228. inject: anObject into: aBlock
  1229. | result |
  1230. result := anObject.
  1231. self do: [:each |
  1232. result := aBlock value: result value: each].
  1233. ^result
  1234. !
  1235. reject: aBlock
  1236. ^self select: [:each | (aBlock value: each) = false]
  1237. !
  1238. select: aBlock
  1239. | stream |
  1240. stream := self class new writeStream.
  1241. self do: [:each |
  1242. (aBlock value: each) ifTrue: [
  1243. stream nextPut: each]].
  1244. ^stream contents
  1245. ! !
  1246. !Collection methodsFor: 'error handling'!
  1247. errorNotFound
  1248. self error: 'Object is not in the collection'
  1249. ! !
  1250. !Collection methodsFor: 'testing'!
  1251. includes: anObject
  1252. <
  1253. var i = self.length;
  1254. while (i--) {
  1255. if (smalltalk.send(self[i], "__eq", [anObject])) {return true;}
  1256. }
  1257. return false
  1258. >
  1259. !
  1260. notEmpty
  1261. ^self isEmpty not
  1262. !
  1263. isEmpty
  1264. ^self size = 0
  1265. !
  1266. ifNotEmpty: aBlock
  1267. self notEmpty ifTrue: aBlock.
  1268. !
  1269. ifEmpty: aBlock
  1270. self isEmpty ifTrue: aBlock.
  1271. ! !
  1272. !Collection class methodsFor: 'accessing'!
  1273. streamClass
  1274. ^Stream
  1275. ! !
  1276. !Collection class methodsFor: 'instance creation'!
  1277. with: anObject
  1278. ^self new
  1279. add: anObject;
  1280. yourself
  1281. !
  1282. with: anObject with: anotherObject
  1283. ^self new
  1284. add: anObject;
  1285. add: anotherObject;
  1286. yourself
  1287. !
  1288. with: firstObject with: secondObject with: thirdObject
  1289. ^self new
  1290. add: firstObject;
  1291. add: secondObject;
  1292. add: thirdObject;
  1293. yourself
  1294. !
  1295. withAll: aCollection
  1296. ^self new
  1297. addAll: aCollection;
  1298. yourself
  1299. ! !
  1300. Collection subclass: #SequenceableCollection
  1301. instanceVariableNames: ''
  1302. category: 'Kernel'!
  1303. !SequenceableCollection methodsFor: 'accessing'!
  1304. at: anIndex
  1305. ^self at: anIndex ifAbsent: [
  1306. self errorNotFound]
  1307. !
  1308. at: anIndex ifAbsent: aBlock
  1309. self subclassResponsibility
  1310. !
  1311. at: anIndex put: anObject
  1312. self subclassResponsibility
  1313. !
  1314. first
  1315. ^self at: 1
  1316. !
  1317. fourth
  1318. ^self at: 4
  1319. !
  1320. last
  1321. ^self at: self size
  1322. !
  1323. second
  1324. ^self at: 2
  1325. !
  1326. third
  1327. ^self at: 3
  1328. !
  1329. allButFirst
  1330. ^self copyFrom: 2 to: self size
  1331. !
  1332. allButLast
  1333. ^self copyFrom: 1 to: self size - 1
  1334. !
  1335. indexOf: anObject
  1336. ^self indexOf: anObject ifAbsent: [self errorNotFound]
  1337. !
  1338. indexOf: anObject ifAbsent: aBlock
  1339. <
  1340. for(var i=0;i<self.length;i++){
  1341. if(self[i].__eq(anObject)) {return i+1}
  1342. }
  1343. return aBlock();
  1344. >
  1345. !
  1346. indexOf: anObject startingAt: start ifAbsent: aBlock
  1347. <
  1348. for(var i=start-1;i<self.length;i++){
  1349. if(self[i].__eq(anObject)) {return i+1}
  1350. }
  1351. return aBlock();
  1352. >
  1353. !
  1354. indexOf: anObject startingAt: start
  1355. "Answer the index of the first occurence of anElement after start
  1356. within the receiver. If the receiver does not contain anElement,
  1357. answer 0."
  1358. ^self indexOf: anObject startingAt: start ifAbsent: [0]
  1359. !
  1360. atRandom
  1361. ^ self at: self size atRandom
  1362. ! !
  1363. !SequenceableCollection methodsFor: 'adding'!
  1364. removeLast
  1365. self remove: self last
  1366. !
  1367. addLast: anObject
  1368. self add: anObject
  1369. ! !
  1370. !SequenceableCollection methodsFor: 'converting'!
  1371. reversed
  1372. self subclassResponsibility
  1373. ! !
  1374. !SequenceableCollection methodsFor: 'copying'!
  1375. copyFrom: anIndex to: anotherIndex
  1376. self subclassResponsibility
  1377. ! !
  1378. !SequenceableCollection methodsFor: 'enumerating'!
  1379. withIndexDo: aBlock
  1380. <for(var i=0;i<self.length;i++){aBlock(self[i], i+1);}>
  1381. ! !
  1382. SequenceableCollection subclass: #String
  1383. instanceVariableNames: ''
  1384. category: 'Kernel'!
  1385. !String methodsFor: 'accessing'!
  1386. size
  1387. <return self.length>
  1388. !
  1389. at: anIndex
  1390. <return self[anIndex - 1]>
  1391. !
  1392. at: anIndex put: anObject
  1393. self errorReadOnly
  1394. !
  1395. at: anIndex ifAbsent: aBlock
  1396. (self at: anIndex) ifNil: [aBlock]
  1397. !
  1398. escaped
  1399. <return escape(self)>
  1400. !
  1401. unescaped
  1402. <return unescape(self)>
  1403. !
  1404. asciiValue
  1405. <return self.charCodeAt(0);>
  1406. ! !
  1407. !String methodsFor: 'adding'!
  1408. add: anObject
  1409. self errorReadOnly
  1410. !
  1411. remove: anObject
  1412. self errorReadOnly
  1413. ! !
  1414. !String methodsFor: 'comparing'!
  1415. = aString
  1416. aString class = self class ifFalse: [^false].
  1417. <return String(self) == aString>
  1418. !
  1419. > aString
  1420. <return String(self) >> aString>
  1421. !
  1422. < aString
  1423. <return String(self) < aString>
  1424. !
  1425. >= aString
  1426. <return String(self) >>= aString>
  1427. !
  1428. <= aString
  1429. <return String(self) <= aString>
  1430. !
  1431. == aString
  1432. aString class = self class ifFalse: [^false].
  1433. <return String(self) === String(aString)>
  1434. ! !
  1435. !String methodsFor: 'converting'!
  1436. asSelector
  1437. "If you change this method, change smalltalk.convertSelector too (see js/boot.js file)"
  1438. | selector |
  1439. selector := '_', self.
  1440. selector := selector replace: ':' with: '_'.
  1441. selector := selector replace: '[+]' with: '_plus'.
  1442. selector := selector replace: '-' with: '_minus'.
  1443. selector := selector replace: '[*]' with: '_star'.
  1444. selector := selector replace: '[/]' with: '_slash'.
  1445. selector := selector replace: '>' with: '_gt'.
  1446. selector := selector replace: '<' with: '_lt'.
  1447. selector := selector replace: '=' with: '_eq'.
  1448. selector := selector replace: ',' with: '_comma'.
  1449. selector := selector replace: '[@]' with: '_at'.
  1450. ^selector
  1451. !
  1452. asJavascript
  1453. <
  1454. if(self.search(/^[a-zA-Z0-9_:.$ ]*$/) == -1)
  1455. return "unescape(\"" + escape(self) + "\")";
  1456. else
  1457. return "\"" + self + "\"";
  1458. >
  1459. !
  1460. tokenize: aString
  1461. <return self.split(aString)>
  1462. !
  1463. asString
  1464. ^self
  1465. !
  1466. asNumber
  1467. <return Number(self)>
  1468. !
  1469. asJSONObject
  1470. ^self
  1471. !
  1472. asLowercase
  1473. <return self.toLowerCase()>
  1474. !
  1475. asUppercase
  1476. <return self.toUpperCase()>
  1477. !
  1478. reversed
  1479. <return self.split("").reverse().join("")>
  1480. !
  1481. asJavaScriptSelector
  1482. ^(self asSelector replace: '^_' with: '') replace: '_.*' with: ''.
  1483. ! !
  1484. !String methodsFor: 'copying'!
  1485. , aString
  1486. <return self + aString>
  1487. !
  1488. copyFrom: anIndex to: anotherIndex
  1489. <return self.substring(anIndex - 1, anotherIndex)>
  1490. !
  1491. shallowCopy
  1492. ^self class fromString: self
  1493. !
  1494. deepCopy
  1495. ^self shallowCopy
  1496. ! !
  1497. !String methodsFor: 'error handling'!
  1498. errorReadOnly
  1499. self error: 'Object is read-only'
  1500. ! !
  1501. !String methodsFor: 'printing'!
  1502. printString
  1503. ^'''', self, ''''
  1504. !
  1505. printNl
  1506. <console.log(self)>
  1507. ! !
  1508. !String methodsFor: 'regular expressions'!
  1509. replace: aString with: anotherString
  1510. ^self replaceRegexp: (RegularExpression fromString: aString flag: 'g') with: anotherString
  1511. !
  1512. replaceRegexp: aRegexp with: aString
  1513. <return self.replace(aRegexp, aString)>
  1514. !
  1515. match: aRegexp
  1516. <return self.search(aRegexp) !!= -1>
  1517. !
  1518. trimLeft: separators
  1519. ^self replaceRegexp: (RegularExpression fromString: '^[', separators, ']+' flag: 'g') with: ''
  1520. !
  1521. trimRight: separators
  1522. ^self replaceRegexp: (RegularExpression fromString: '[', separators, ']+$' flag: 'g') with: ''
  1523. !
  1524. trimLeft
  1525. ^self trimLeft: '\s'
  1526. !
  1527. trimRight
  1528. ^self trimRight: '\s'
  1529. !
  1530. trimBoth
  1531. ^self trimBoth: '\s'
  1532. !
  1533. trimBoth: separators
  1534. ^(self trimLeft: separators) trimRight: separators
  1535. ! !
  1536. !String methodsFor: 'split join'!
  1537. join: aCollection
  1538. ^ String
  1539. streamContents: [:stream | aCollection
  1540. do: [:each | stream nextPutAll: each asString]
  1541. separatedBy: [stream nextPutAll: self]]
  1542. !
  1543. lineIndicesDo: aBlock
  1544. "execute aBlock with 3 arguments for each line:
  1545. - start index of line
  1546. - end index of line without line delimiter
  1547. - end index of line including line delimiter(s) CR, LF or CRLF"
  1548. | cr lf start sz nextLF nextCR |
  1549. start := 1.
  1550. sz := self size.
  1551. cr := String cr.
  1552. nextCR := self indexOf: cr startingAt: 1.
  1553. lf := String lf.
  1554. nextLF := self indexOf: lf startingAt: 1.
  1555. [ start <= sz ] whileTrue: [
  1556. (nextLF = 0 and: [ nextCR = 0 ])
  1557. ifTrue: [ "No more CR, nor LF, the string is over"
  1558. aBlock value: start value: sz value: sz.
  1559. ^self ].
  1560. (nextCR = 0 or: [ 0 < nextLF and: [ nextLF < nextCR ] ])
  1561. ifTrue: [ "Found a LF"
  1562. aBlock value: start value: nextLF - 1 value: nextLF.
  1563. start := 1 + nextLF.
  1564. nextLF := self indexOf: lf startingAt: start ]
  1565. ifFalse: [ 1 + nextCR = nextLF
  1566. ifTrue: [ "Found a CR-LF pair"
  1567. aBlock value: start value: nextCR - 1 value: nextLF.
  1568. start := 1 + nextLF.
  1569. nextCR := self indexOf: cr startingAt: start.
  1570. nextLF := self indexOf: lf startingAt: start ]
  1571. ifFalse: [ "Found a CR"
  1572. aBlock value: start value: nextCR - 1 value: nextCR.
  1573. start := 1 + nextCR.
  1574. nextCR := self indexOf: cr startingAt: start ]]]
  1575. !
  1576. linesDo: aBlock
  1577. "Execute aBlock with each line in this string. The terminating line
  1578. delimiters CR, LF or CRLF pairs are not included in what is passed to aBlock"
  1579. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1580. aBlock value: (self copyFrom: start to: endWithoutDelimiters)]
  1581. !
  1582. lines
  1583. "Answer an array of lines composing this receiver without the line ending delimiters."
  1584. | lines |
  1585. lines := Array new.
  1586. self linesDo: [:aLine | lines add: aLine].
  1587. ^lines
  1588. !
  1589. lineNumber: anIndex
  1590. "Answer a string containing the characters in the given line number."
  1591. | lineCount |
  1592. lineCount := 0.
  1593. self lineIndicesDo: [:start :endWithoutDelimiters :end |
  1594. (lineCount := lineCount + 1) = anIndex ifTrue: [^self copyFrom: start to: endWithoutDelimiters]].
  1595. ^nil
  1596. ! !
  1597. !String methodsFor: 'testing'!
  1598. isString
  1599. ^true
  1600. !
  1601. includesSubString: subString
  1602. < return self.indexOf(subString) !!= -1 >
  1603. ! !
  1604. !String class methodsFor: 'accessing'!
  1605. streamClass
  1606. ^StringStream
  1607. !
  1608. cr
  1609. <return '\r'>
  1610. !
  1611. lf
  1612. <return '\n'>
  1613. !
  1614. space
  1615. <return ' '>
  1616. !
  1617. tab
  1618. <return '\t'>
  1619. !
  1620. crlf
  1621. <return '\r\n'>
  1622. ! !
  1623. !String class methodsFor: 'instance creation'!
  1624. fromString: aString
  1625. <return new self.fn(aString)>
  1626. !
  1627. streamContents: blockWithArg
  1628. |stream|
  1629. stream := (self streamClass on: String new).
  1630. blockWithArg value: stream.
  1631. ^ stream contents
  1632. !
  1633. value: aUTFCharCode
  1634. <return String.fromCharCode(aUTFCharCode);>
  1635. ! !
  1636. SequenceableCollection subclass: #Array
  1637. instanceVariableNames: ''
  1638. category: 'Kernel'!
  1639. !Array methodsFor: 'accessing'!
  1640. size
  1641. <return self.length>
  1642. !
  1643. at: anIndex put: anObject
  1644. <return self[anIndex - 1] = anObject>
  1645. !
  1646. at: anIndex ifAbsent: aBlock
  1647. <
  1648. var value = self[anIndex - 1];
  1649. if(value === undefined) {
  1650. return aBlock();
  1651. } else {
  1652. return value;
  1653. }
  1654. >
  1655. ! !
  1656. !Array methodsFor: 'adding/removing'!
  1657. add: anObject
  1658. <self.push(anObject); return anObject;>
  1659. !
  1660. remove: anObject
  1661. <
  1662. for(var i=0;i<self.length;i++) {
  1663. if(self[i] == anObject) {
  1664. self.splice(i,1);
  1665. break;
  1666. }
  1667. }
  1668. >
  1669. !
  1670. removeFrom: aNumber to: anotherNumber
  1671. <self.splice(aNumber - 1,anotherNumber - 1)>
  1672. ! !
  1673. !Array methodsFor: 'comparing'!
  1674. = aCollection
  1675. (self class = aCollection class and: [
  1676. self size = aCollection size]) ifFalse: [^false].
  1677. self withIndexDo: [:each :i |
  1678. (aCollection at: i) = each ifFalse: [^false]].
  1679. ^true
  1680. ! !
  1681. !Array methodsFor: 'converting'!
  1682. asJavascript
  1683. ^'[', ((self collect: [:each | each asJavascript]) join: ', '), ']'
  1684. !
  1685. asJSONObject
  1686. ^self collect: [:each | each asJSONObject]
  1687. !
  1688. reversed
  1689. <return self._copy().reverse()>
  1690. ! !
  1691. !Array methodsFor: 'copying'!
  1692. shallowCopy
  1693. | newCollection |
  1694. newCollection := self class new.
  1695. self do: [:each | newCollection add: each].
  1696. ^newCollection
  1697. !
  1698. deepCopy
  1699. | newCollection |
  1700. newCollection := self class new.
  1701. self do: [:each | newCollection add: each deepCopy].
  1702. ^newCollection
  1703. !
  1704. copyFrom: anIndex to: anotherIndex
  1705. | array |
  1706. array := self class new.
  1707. anIndex to: anotherIndex do: [:each |
  1708. array add: (self at: each)].
  1709. ^array
  1710. ! !
  1711. !Array methodsFor: 'enumerating'!
  1712. join: aString
  1713. <return self.join(aString)>
  1714. !
  1715. sort
  1716. ^self basicPerform: 'sort'
  1717. !
  1718. sort: aBlock
  1719. <
  1720. return self.sort(function(a, b) {
  1721. if(aBlock(a,b)) {return -1} else {return 1}
  1722. })
  1723. >
  1724. !
  1725. sorted
  1726. ^self copy sort
  1727. !
  1728. sorted: aBlock
  1729. ^self copy sort: aBlock
  1730. !
  1731. printString
  1732. | str |
  1733. str := '' writeStream.
  1734. str nextPutAll: super printString, ' ('.
  1735. self
  1736. do: [:each | str nextPutAll: each printString]
  1737. separatedBy: [str nextPutAll: ' '].
  1738. str nextPutAll: ')'.
  1739. ^str contents
  1740. ! !
  1741. Object subclass: #RegularExpression
  1742. instanceVariableNames: ''
  1743. category: 'Kernel'!
  1744. !RegularExpression methodsFor: 'evaluating'!
  1745. compile: aString
  1746. <return self.compile(aString)>
  1747. !
  1748. exec: aString
  1749. <return self.exec(aString) || nil>
  1750. !
  1751. test: aString
  1752. <return self.test(aString)>
  1753. ! !
  1754. !RegularExpression class methodsFor: 'instance creation'!
  1755. fromString: aString flag: anotherString
  1756. <return new RegExp(aString, anotherString)>
  1757. !
  1758. fromString: aString
  1759. ^self fromString: aString flag: ''
  1760. ! !
  1761. Object subclass: #Error
  1762. instanceVariableNames: 'messageText'
  1763. category: 'Kernel'!
  1764. !Error methodsFor: 'accessing'!
  1765. messageText
  1766. ^messageText
  1767. !
  1768. messageText: aString
  1769. messageText := aString
  1770. !
  1771. context
  1772. <return self.context>
  1773. ! !
  1774. !Error methodsFor: 'signaling'!
  1775. signal
  1776. <self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
  1777. ! !
  1778. !Error class methodsFor: 'instance creation'!
  1779. signal: aString
  1780. ^self new
  1781. messageText: aString;
  1782. signal
  1783. ! !
  1784. Object subclass: #MethodContext
  1785. instanceVariableNames: ''
  1786. category: 'Kernel'!
  1787. !MethodContext methodsFor: 'accessing'!
  1788. receiver
  1789. <return self.receiver>
  1790. !
  1791. selector
  1792. <return smalltalk.convertSelector(self.selector)>
  1793. !
  1794. home
  1795. <return self.homeContext>
  1796. !
  1797. temps
  1798. <return self.temps>
  1799. !
  1800. printString
  1801. ^super printString, '(', self asString, ')'
  1802. !
  1803. asString
  1804. ^self receiver class printString, ' >> ', self selector
  1805. ! !
  1806. Object subclass: #Association
  1807. instanceVariableNames: 'key value'
  1808. category: 'Kernel'!
  1809. !Association methodsFor: 'accessing'!
  1810. key: aKey
  1811. key := aKey
  1812. !
  1813. key
  1814. ^key
  1815. !
  1816. value: aValue
  1817. value := aValue
  1818. !
  1819. value
  1820. ^value
  1821. ! !
  1822. !Association methodsFor: 'comparing'!
  1823. = anAssociation
  1824. ^self class = anAssociation class and: [
  1825. self key = anAssociation key and: [
  1826. self value = anAssociation value]]
  1827. !
  1828. storeOn: aStream
  1829. "Store in the format (key->value)"
  1830. "aStream nextPutAll: '('."
  1831. key storeOn: aStream.
  1832. aStream nextPutAll: '->'.
  1833. value storeOn: aStream.
  1834. "aStream nextPutAll: ')'"
  1835. ! !
  1836. !Association class methodsFor: 'instance creation'!
  1837. key: aKey value: aValue
  1838. ^self new
  1839. key: aKey;
  1840. value: aValue;
  1841. yourself
  1842. ! !
  1843. Collection subclass: #Dictionary
  1844. instanceVariableNames: 'keys'
  1845. category: 'Kernel'!
  1846. !Dictionary methodsFor: 'accessing'!
  1847. size
  1848. ^keys size
  1849. !
  1850. associations
  1851. | associations |
  1852. associations := #().
  1853. keys do: [:each |
  1854. associations add: (Association key: each value: (self at: each))].
  1855. ^associations
  1856. !
  1857. keys
  1858. ^keys copy
  1859. !
  1860. values
  1861. ^keys collect: [:each | self at: each]
  1862. !
  1863. at: aKey put: aValue
  1864. (keys includes: aKey) ifFalse: [keys add: aKey].
  1865. ^self basicAt: aKey put: aValue
  1866. !
  1867. at: aKey ifAbsent: aBlock
  1868. ^(self keys includes: aKey)
  1869. ifTrue: [self basicAt: aKey]
  1870. ifFalse: aBlock
  1871. !
  1872. at: aKey ifAbsentPut: aBlock
  1873. ^self at: aKey ifAbsent: [
  1874. self at: aKey put: aBlock value]
  1875. !
  1876. at: aKey ifPresent: aBlock
  1877. ^(self basicAt: aKey) ifNotNil: [aBlock value: (self at: aKey)]
  1878. !
  1879. at: aKey ifPresent: aBlock ifAbsent: anotherBlock
  1880. ^(self basicAt: aKey)
  1881. ifNil: anotherBlock
  1882. ifNotNil: [aBlock value: (self at: aKey)]
  1883. !
  1884. at: aKey
  1885. ^self at: aKey ifAbsent: [self errorNotFound]
  1886. ! !
  1887. !Dictionary methodsFor: 'adding/removing'!
  1888. add: anAssociation
  1889. self at: anAssociation key put: anAssociation value
  1890. !
  1891. addAll: aDictionary
  1892. super addAll: aDictionary associations.
  1893. ^aDictionary
  1894. !
  1895. remove: aKey
  1896. self removeKey: aKey
  1897. !
  1898. removeKey: aKey
  1899. keys remove: aKey
  1900. ! !
  1901. !Dictionary methodsFor: 'comparing'!
  1902. = aDictionary
  1903. self class = aDictionary class ifFalse: [^false].
  1904. self size = aDictionary size ifFalse: [^false].
  1905. ^self associations = aDictionary associations
  1906. ! !
  1907. !Dictionary methodsFor: 'converting'!
  1908. asJSONObject
  1909. | object |
  1910. object := Object new.
  1911. self keysAndValuesDo: [:key :value |
  1912. object basicAt: key put: value asJSONObject].
  1913. ^object
  1914. ! !
  1915. !Dictionary methodsFor: 'copying'!
  1916. shallowCopy
  1917. | copy |
  1918. copy := self class new.
  1919. self associationsDo: [:each |
  1920. copy at: each key put: each value].
  1921. ^copy
  1922. !
  1923. , aCollection
  1924. self shouldNotImplement
  1925. !
  1926. copyFrom: anIndex to: anotherIndex
  1927. self shouldNotImplement
  1928. ! !
  1929. !Dictionary methodsFor: 'enumerating'!
  1930. associationsDo: aBlock
  1931. self associations do: aBlock
  1932. !
  1933. keysAndValuesDo: aBlock
  1934. self associationsDo: [:each |
  1935. aBlock value: each key value: each value]
  1936. !
  1937. do: aBlock
  1938. self values do: aBlock
  1939. !
  1940. select: aBlock
  1941. | newDict |
  1942. newDict := self class new.
  1943. self keysAndValuesDo: [:key :value |
  1944. (aBlock value: value) ifTrue: [newDict at: key put: value]].
  1945. ^newDict
  1946. !
  1947. collect: aBlock
  1948. | newDict |
  1949. newDict := self class new.
  1950. self keysAndValuesDo: [:key :value |
  1951. newDict at: key put: (aBlock value: value)].
  1952. ^newDict
  1953. !
  1954. detect: aBlock ifNone: anotherBlock
  1955. ^self values detect: aBlock ifNone: anotherBlock
  1956. !
  1957. includes: anObject
  1958. ^self values includes: anObject
  1959. ! !
  1960. !Dictionary methodsFor: 'initialization'!
  1961. initialize
  1962. super initialize.
  1963. keys := #()
  1964. ! !
  1965. !Dictionary methodsFor: 'printing'!
  1966. printString
  1967. ^ String streamContents: [:aStream|
  1968. aStream
  1969. nextPutAll: super printString;
  1970. nextPutAll: '('.
  1971. self associations
  1972. do: [:anAssociation|
  1973. aStream
  1974. nextPutAll: anAssociation key printString;
  1975. nextPutAll: ' -> ';
  1976. nextPutAll: anAssociation value printString]
  1977. separatedBy: [aStream nextPutAll: ' , '].
  1978. aStream nextPutAll: ')'.
  1979. ]
  1980. !
  1981. storeOn: aStream
  1982. aStream nextPutAll: '#{'.
  1983. self associations
  1984. do: [:each | each storeOn: aStream]
  1985. separatedBy: [ aStream nextPutAll: '. '].
  1986. aStream nextPutAll: '}'
  1987. ! !
  1988. !Dictionary class methodsFor: 'instance creation'!
  1989. fromPairs: aCollection
  1990. | dict |
  1991. dict := self new.
  1992. aCollection do: [:each | dict add: each].
  1993. ^dict
  1994. ! !
  1995. Object subclass: #ClassBuilder
  1996. instanceVariableNames: ''
  1997. category: 'Kernel'!
  1998. !ClassBuilder methodsFor: 'class creation'!
  1999. superclass: aClass subclass: aString
  2000. ^self superclass: aClass subclass: aString instanceVariableNames: '' package: nil
  2001. !
  2002. class: aClass instanceVariableNames: aString
  2003. aClass isMetaclass ifFalse: [self error: aClass name, ' is not a metaclass'].
  2004. aClass basicAt: 'iVarNames' put: (self instanceVariableNamesFor: aString).
  2005. self setupClass: aClass
  2006. !
  2007. superclass: aClass subclass: aString instanceVariableNames: aString2 package: aString3
  2008. | newClass |
  2009. newClass := self addSubclassOf: aClass
  2010. named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2)
  2011. package: (aString3 ifNil: ['unclassified']).
  2012. self setupClass: newClass.
  2013. ^newClass
  2014. ! !
  2015. !ClassBuilder methodsFor: 'private'!
  2016. instanceVariableNamesFor: aString
  2017. ^(aString tokenize: ' ') reject: [:each | each isEmpty]
  2018. !
  2019. addSubclassOf: aClass named: aString instanceVariableNames: aCollection
  2020. <smalltalk.addClass(aString, aClass, aCollection);
  2021. return smalltalk[aString]>
  2022. !
  2023. setupClass: aClass
  2024. <smalltalk.init(aClass);>
  2025. !
  2026. addSubclassOf: aClass named: aString instanceVariableNames: aCollection package: packageName
  2027. <smalltalk.addClass(aString, aClass, aCollection, packageName);
  2028. return smalltalk[aString]>
  2029. ! !
  2030. Object subclass: #ClassCategoryReader
  2031. instanceVariableNames: 'class category chunkParser'
  2032. category: 'Kernel'!
  2033. !ClassCategoryReader methodsFor: 'accessing'!
  2034. class: aClass category: aString
  2035. class := aClass.
  2036. category := aString
  2037. ! !
  2038. !ClassCategoryReader methodsFor: 'fileIn'!
  2039. scanFrom: aChunkParser
  2040. | chunk |
  2041. [chunk := aChunkParser nextChunk.
  2042. chunk isEmpty] whileFalse: [
  2043. self compileMethod: chunk]
  2044. ! !
  2045. !ClassCategoryReader methodsFor: 'initialization'!
  2046. initialize
  2047. super initialize.
  2048. chunkParser := ChunkParser new.
  2049. ! !
  2050. !ClassCategoryReader methodsFor: 'private'!
  2051. compileMethod: aString
  2052. | method |
  2053. method := Compiler new load: aString forClass: class.
  2054. method category: category.
  2055. class addCompiledMethod: method
  2056. ! !
  2057. Object subclass: #Stream
  2058. instanceVariableNames: 'collection position streamSize'
  2059. category: 'Kernel'!
  2060. !Stream methodsFor: 'accessing'!
  2061. collection
  2062. ^collection
  2063. !
  2064. setCollection: aCollection
  2065. collection := aCollection
  2066. !
  2067. position
  2068. ^position ifNil: [position := 0]
  2069. !
  2070. position: anInteger
  2071. position := anInteger
  2072. !
  2073. streamSize
  2074. ^streamSize
  2075. !
  2076. setStreamSize: anInteger
  2077. streamSize := anInteger
  2078. !
  2079. contents
  2080. ^self collection
  2081. copyFrom: 1
  2082. to: self streamSize
  2083. !
  2084. size
  2085. ^self streamSize
  2086. ! !
  2087. !Stream methodsFor: 'actions'!
  2088. reset
  2089. self position: 0
  2090. !
  2091. close
  2092. !
  2093. flush
  2094. !
  2095. resetContents
  2096. self reset.
  2097. self setStreamSize: 0
  2098. ! !
  2099. !Stream methodsFor: 'enumerating'!
  2100. do: aBlock
  2101. [self atEnd] whileFalse: [aBlock value: self next]
  2102. ! !
  2103. !Stream methodsFor: 'positioning'!
  2104. setToEnd
  2105. self position: self size
  2106. !
  2107. skip: anInteger
  2108. self position: ((self position + anInteger) min: self size max: 0)
  2109. ! !
  2110. !Stream methodsFor: 'reading'!
  2111. next
  2112. self position: self position + 1.
  2113. ^collection at: self position
  2114. !
  2115. next: anInteger
  2116. | tempCollection |
  2117. tempCollection := self collection class new.
  2118. anInteger timesRepeat: [
  2119. self atEnd ifFalse: [
  2120. tempCollection add: self next]].
  2121. ^tempCollection
  2122. !
  2123. peek
  2124. ^self atEnd ifFalse: [
  2125. self collection at: self position + 1]
  2126. ! !
  2127. !Stream methodsFor: 'testing'!
  2128. atEnd
  2129. ^self position = self size
  2130. !
  2131. atStart
  2132. ^self position = 0
  2133. !
  2134. isEmpty
  2135. ^self size = 0
  2136. ! !
  2137. !Stream methodsFor: 'writing'!
  2138. nextPut: anObject
  2139. self position: self position + 1.
  2140. self collection at: self position put: anObject.
  2141. self setStreamSize: (self streamSize max: self position)
  2142. !
  2143. nextPutAll: aCollection
  2144. aCollection do: [:each |
  2145. self nextPut: each]
  2146. ! !
  2147. !Stream class methodsFor: 'instance creation'!
  2148. on: aCollection
  2149. ^self new
  2150. setCollection: aCollection;
  2151. setStreamSize: aCollection size;
  2152. yourself
  2153. ! !
  2154. Stream subclass: #StringStream
  2155. instanceVariableNames: ''
  2156. category: 'Kernel'!
  2157. !StringStream methodsFor: 'reading'!
  2158. next: anInteger
  2159. | tempCollection |
  2160. tempCollection := self collection class new.
  2161. anInteger timesRepeat: [
  2162. self atEnd ifFalse: [
  2163. tempCollection := tempCollection, self next]].
  2164. ^tempCollection
  2165. ! !
  2166. !StringStream methodsFor: 'writing'!
  2167. nextPut: aString
  2168. self nextPutAll: aString
  2169. !
  2170. nextPutAll: aString
  2171. self setCollection:
  2172. (self collection copyFrom: 1 to: self position),
  2173. aString,
  2174. (self collection copyFrom: (self position + 1 + aString size) to: self collection size).
  2175. self position: self position + aString size.
  2176. self setStreamSize: (self streamSize max: self position)
  2177. !
  2178. cr
  2179. ^self nextPutAll: String cr
  2180. !
  2181. crlf
  2182. ^self nextPutAll: String crlf
  2183. !
  2184. lf
  2185. ^self nextPutAll: String lf
  2186. !
  2187. space
  2188. self nextPut: ' '
  2189. ! !
  2190. Object subclass: #ClassCommentReader
  2191. instanceVariableNames: 'class chunkParser'
  2192. category: 'Kernel'!
  2193. !ClassCommentReader methodsFor: 'accessing'!
  2194. class: aClass
  2195. class := aClass
  2196. ! !
  2197. !ClassCommentReader methodsFor: 'fileIn'!
  2198. scanFrom: aChunkParser
  2199. | chunk |
  2200. chunk := aChunkParser nextChunk.
  2201. chunk isEmpty ifFalse: [
  2202. self setComment: chunk].
  2203. ! !
  2204. !ClassCommentReader methodsFor: 'initialization'!
  2205. initialize
  2206. super initialize.
  2207. chunkParser := ChunkParser new.
  2208. ! !
  2209. !ClassCommentReader methodsFor: 'private'!
  2210. setComment: aString
  2211. class comment: aString
  2212. ! !
  2213. Object subclass: #Random
  2214. instanceVariableNames: ''
  2215. category: 'Kernel'!
  2216. !Random methodsFor: 'accessing'!
  2217. next
  2218. <return Math.random()>
  2219. !
  2220. next: anInteger
  2221. ^(1 to: anInteger) collect: [:each | self next]
  2222. ! !
  2223. Object subclass: #Point
  2224. instanceVariableNames: 'x y'
  2225. category: 'Kernel'!
  2226. !Point methodsFor: 'accessing'!
  2227. x
  2228. ^x
  2229. !
  2230. y
  2231. ^y
  2232. !
  2233. y: aNumber
  2234. y := aNumber
  2235. !
  2236. x: aNumber
  2237. x := aNumber
  2238. ! !
  2239. !Point methodsFor: 'arithmetic'!
  2240. * aPoint
  2241. ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
  2242. !
  2243. + aPoint
  2244. ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
  2245. !
  2246. - aPoint
  2247. ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
  2248. !
  2249. / aPoint
  2250. ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
  2251. !
  2252. = aPoint
  2253. ^aPoint class = self class and: [
  2254. (aPoint x = self x) & (aPoint y = self y)]
  2255. ! !
  2256. !Point methodsFor: 'converting'!
  2257. asPoint
  2258. ^self
  2259. ! !
  2260. !Point class methodsFor: 'instance creation'!
  2261. x: aNumber y: anotherNumber
  2262. ^self new
  2263. x: aNumber;
  2264. y: anotherNumber;
  2265. yourself
  2266. ! !
  2267. Object subclass: #Message
  2268. instanceVariableNames: 'selector arguments'
  2269. category: 'Kernel'!
  2270. !Message methodsFor: 'accessing'!
  2271. selector
  2272. ^selector
  2273. !
  2274. selector: aString
  2275. selector := aString
  2276. !
  2277. arguments: anArray
  2278. arguments := anArray
  2279. !
  2280. arguments
  2281. ^arguments
  2282. ! !
  2283. !Message methodsFor: 'printing'!
  2284. printString
  2285. ^ String streamContents: [:aStream|
  2286. aStream
  2287. nextPutAll: super printString;
  2288. nextPutAll: '(';
  2289. nextPutAll: selector;
  2290. nextPutAll: ')' ]
  2291. ! !
  2292. !Message class methodsFor: 'instance creation'!
  2293. selector: aString arguments: anArray
  2294. ^self new
  2295. selector: aString;
  2296. arguments: anArray;
  2297. yourself
  2298. ! !
  2299. Error subclass: #MessageNotUnderstood
  2300. instanceVariableNames: 'message receiver'
  2301. category: 'Kernel'!
  2302. !MessageNotUnderstood methodsFor: 'accessing'!
  2303. message
  2304. ^message
  2305. !
  2306. message: aMessage
  2307. message := aMessage
  2308. !
  2309. receiver
  2310. ^receiver
  2311. !
  2312. receiver: anObject
  2313. receiver := anObject
  2314. !
  2315. messageText
  2316. ^self receiver asString, ' does not understand #', self message selector
  2317. ! !
  2318. Object subclass: #ErrorHandler
  2319. instanceVariableNames: ''
  2320. category: 'Kernel'!
  2321. !ErrorHandler methodsFor: 'error handling'!
  2322. handleError: anError
  2323. anError context ifNotNil: [self logErrorContext: anError context].
  2324. self logError: anError
  2325. ! !
  2326. !ErrorHandler methodsFor: 'private'!
  2327. logContext: aContext
  2328. aContext home ifNotNil: [
  2329. self logContext: aContext home].
  2330. self log: aContext receiver asString, '>>', aContext selector
  2331. !
  2332. logErrorContext: aContext
  2333. aContext ifNotNil: [
  2334. aContext home ifNotNil: [
  2335. self logContext: aContext home]]
  2336. !
  2337. logError: anError
  2338. self log: anError messageText
  2339. !
  2340. log: aString
  2341. console log: aString
  2342. ! !
  2343. ErrorHandler class instanceVariableNames: 'current'!
  2344. !ErrorHandler class methodsFor: 'accessing'!
  2345. current
  2346. ^current ifNil: [current := self new]
  2347. !
  2348. setCurrent: anHandler
  2349. current := anHandler
  2350. ! !
  2351. !ErrorHandler class methodsFor: 'initialization'!
  2352. initialize
  2353. self register
  2354. !
  2355. register
  2356. ErrorHandler setCurrent: self new
  2357. ! !
  2358. Object subclass: #JSObjectProxy
  2359. instanceVariableNames: 'jsObject'
  2360. category: 'Kernel'!
  2361. !JSObjectProxy methodsFor: 'accessing'!
  2362. jsObject: aJSObject
  2363. jsObject := aJSObject
  2364. !
  2365. jsObject
  2366. ^jsObject
  2367. !
  2368. at: aString
  2369. <return self['@jsObject'][aString]>
  2370. !
  2371. at: aString put: anObject
  2372. <self['@jsObject'][aString] = anObject>
  2373. ! !
  2374. !JSObjectProxy methodsFor: 'proxy'!
  2375. printString
  2376. ^self jsObject toString
  2377. !
  2378. inspectOn: anInspector
  2379. | variables |
  2380. variables := Dictionary new.
  2381. variables at: '#self' put: self jsObject.
  2382. anInspector setLabel: self printString.
  2383. <for(var i in self['@jsObject']) {
  2384. variables._at_put_(i, self['@jsObject'][i]);
  2385. }>.
  2386. anInspector setVariables: variables
  2387. !
  2388. doesNotUnderstand: aMessage
  2389. | obj selector jsSelector arguments |
  2390. obj := self jsObject.
  2391. selector := aMessage selector.
  2392. jsSelector := selector asJavaScriptSelector.
  2393. arguments := aMessage arguments.
  2394. <if(obj[jsSelector] !!= undefined) {return smalltalk.send(obj, jsSelector, arguments)}>.
  2395. super doesNotUnderstand: aMessage
  2396. ! !
  2397. !JSObjectProxy class methodsFor: 'instance creation'!
  2398. on: aJSObject
  2399. ^self new
  2400. jsObject: aJSObject;
  2401. yourself
  2402. ! !
  2403. Collection subclass: #Set
  2404. instanceVariableNames: 'elements'
  2405. category: 'Kernel'!
  2406. !Set methodsFor: 'accessing'!
  2407. size
  2408. ^elements size
  2409. ! !
  2410. !Set methodsFor: 'adding/removing'!
  2411. add: anObject
  2412. <
  2413. var found;
  2414. for(var i in self['@elements']) {
  2415. if(anObject == self['@elements'][i]) {
  2416. found = true;
  2417. break;
  2418. }
  2419. }
  2420. if(!!found) {self['@elements'].push(anObject)}
  2421. >
  2422. !
  2423. remove: anObject
  2424. elements remove: anObject
  2425. ! !
  2426. !Set methodsFor: 'comparing'!
  2427. = aCollection
  2428. ^self class = aCollection class and: [
  2429. elements = aCollection asArray]
  2430. ! !
  2431. !Set methodsFor: 'converting'!
  2432. asArray
  2433. ^elements copy
  2434. ! !
  2435. !Set methodsFor: 'enumerating'!
  2436. detect: aBlock ifNone: anotherBlock
  2437. ^elements detect: aBlock ifNone: anotherBlock
  2438. !
  2439. do: aBlock
  2440. elements do: aBlock
  2441. ! !
  2442. !Set methodsFor: 'initialization'!
  2443. initialize
  2444. super initialize.
  2445. elements := #()
  2446. ! !
  2447. !Set methodsFor: 'testing'!
  2448. includes: anObject
  2449. ^elements includes: anObject
  2450. ! !
  2451. Object subclass: #Transcript
  2452. instanceVariableNames: 'textarea'
  2453. category: 'Kernel'!
  2454. Transcript class instanceVariableNames: 'current'!
  2455. !Transcript class methodsFor: 'instance creation'!
  2456. open
  2457. self current open
  2458. !
  2459. new
  2460. self shouldNotImplement
  2461. !
  2462. current
  2463. ^current
  2464. !
  2465. register: aTranscript
  2466. current := aTranscript
  2467. ! !
  2468. !Transcript class methodsFor: 'printing'!
  2469. show: anObject
  2470. self current show: anObject
  2471. !
  2472. cr
  2473. self current show: String cr
  2474. !
  2475. clear
  2476. self current clear
  2477. ! !
  2478. Object subclass: #ConsoleTranscript
  2479. instanceVariableNames: 'textarea'
  2480. category: 'Kernel'!
  2481. !ConsoleTranscript methodsFor: 'actions'!
  2482. open
  2483. ! !
  2484. !ConsoleTranscript methodsFor: 'printing'!
  2485. clear
  2486. "no op"
  2487. !
  2488. cr
  2489. "no op"
  2490. !
  2491. show: anObject
  2492. <console.log(String(anObject._asString()))>
  2493. ! !
  2494. !ConsoleTranscript class methodsFor: 'initialization'!
  2495. initialize
  2496. Transcript register: self new
  2497. ! !