Kernel.st 55 KB

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