Kernel.st 54 KB

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