Kernel.st 55 KB

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