123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216 |
- nil subclass: #Object
- instanceVariableNames: ''
- category: 'Kernel'!
- !Object methodsFor: 'accessing'!
- yourself
- ^self
- !
- class
- <return self.klass>
- !
- size
- self error: 'Object not indexable'
- !
- instVarAt: aString
- <return self['@'+aString]>
- !
- instVarAt: aString put: anObject
- <self['@' + aString] = anObject>
- !
- basicAt: aString
- <return self[aString]>
- !
- basicAt: aString put: anObject
- <return self[aString] = anObject>
- !
- basicDelete: aString
- <delete self[aString]>
- ! !
- !Object methodsFor: 'comparing'!
- = anObject
- ^self == anObject
- !
- ~= anObject
- ^(self = anObject) = false
- !
- == anObject
- <return self === anObject>
- !
- ~~ anObject
- ^(self == anObject) = false
- ! !
- !Object methodsFor: 'converting'!
- -> anObject
- ^Association key: self value: anObject
- !
- asString
- ^self printString
- !
- asJavascript
- ^self asString
- !
- asJSON
- <return JSON.stringify(self._asJSONObject())>
- !
- asJSONObject
- | object |
- object := Object new.
- self class instanceVariableNames do: [:each |
- object basicAt: each put: (self instVarAt: each) asJSONObject].
- ^object
- ! !
- !Object methodsFor: 'copying'!
- copy
- ^self shallowCopy postCopy
- !
- shallowCopy
- <
- var copy = self.klass._new();
- for(var i in self) {
- if(/^@.+/.test(i)) {
- copy[i] = self[i];
- }
- }
- return copy;
- >
- !
- deepCopy
- <
- var copy = self.klass._new();
- for(var i in self) {
- if(/^@.+/.test(i)) {
- copy[i] = self[i]._deepCopy();
- }
- }
- return copy;
- >
- !
- postCopy
- ! !
- !Object methodsFor: 'error handling'!
- error: aString
- Error signal: aString
- !
- subclassResponsibility
- self error: 'This method is a responsibility of a subclass'
- !
- shouldNotImplement
- self error: 'This method should not be implemented in ', self class name
- !
- try: aBlock catch: anotherBlock
- <try{aBlock()} catch(e) {anotherBlock(e)}>
- !
- doesNotUnderstand: aMessage
- MessageNotUnderstood new
- receiver: self;
- message: aMessage;
- signal
- !
- halt
- self error: 'Halt encountered'
- !
- deprecatedAPI
- "Just a simple way to deprecate methods.
- #deprecatedAPI is in the 'error handling' protocol even if it doesn't throw an error,
- but it could in the future."
- console warn: thisContext home asString, ' is deprecated!!'
- ! !
- !Object methodsFor: 'initialization'!
- initialize
- ! !
- !Object methodsFor: 'message handling'!
- perform: aSymbol
- ^self perform: aSymbol withArguments: #()
- !
- perform: aSymbol withArguments: aCollection
- ^self basicPerform: aSymbol asSelector withArguments: aCollection
- !
- basicPerform: aSymbol
- ^self basicPerform: aSymbol withArguments: #()
- !
- basicPerform: aSymbol withArguments: aCollection
- <return self[aSymbol].apply(self, aCollection);>
- ! !
- !Object methodsFor: 'printing'!
- printString
- ^'a ', self class name
- !
- printNl
- <console.log(self)>
- !
- log: aString block: aBlock
- | result |
- console log: aString, ' time: ', (Date millisecondsToRun: [result := aBlock value]) printString.
- ^result
- ! !
- !Object methodsFor: 'testing'!
- isKindOf: aClass
- ^(self isMemberOf: aClass)
- ifTrue: [true]
- ifFalse: [self class inheritsFrom: aClass]
- !
- isMemberOf: aClass
- ^self class = aClass
- !
- ifNil: aBlock
- "inlined in the Compiler"
- ^self
- !
- ifNil: aBlock ifNotNil: anotherBlock
- "inlined in the Compiler"
- ^anotherBlock value
- !
- ifNotNil: aBlock
- "inlined in the Compiler"
- ^aBlock value
- !
- ifNotNil: aBlock ifNil: anotherBlock
- "inlined in the Compiler"
- ^aBlock value
- !
- isNil
- ^false
- !
- notNil
- ^self isNil not
- !
- isClass
- ^false
- !
- isMetaclass
- ^false
- !
- isNumber
- ^false
- !
- isString
- ^false
- !
- isParseFailure
- ^false
- ! !
- !Object class methodsFor: 'initialization'!
- initialize
- "no op"
- ! !
- Object subclass: #Smalltalk
- instanceVariableNames: ''
- category: 'Kernel'!
- !Smalltalk methodsFor: 'accessing'!
- classes
- <return self.classes()>
- !
- readJSON: anObject
- <return self.readJSObject(anObject)>
- !
- at: aString
- <return self[aString]>
- !
- basicParse: aString
- <return smalltalk.parser.parse(aString)>
- !
- parse: aString
- | result |
- self try: [result := self basicParse: aString] catch: [:ex | (self parseError: ex parsing: aString) signal].
- ^result
- !
- parseError: anException parsing: aString
- | row col message lines badLine code |
- <row = anException.line;
- col = anException.column;
- message = anException.message;>.
- lines := aString lines.
- badLine := lines at: row.
- badLine := (badLine copyFrom: 1 to: col - 1), ' ===>', (badLine copyFrom: col to: badLine size).
- lines at: row put: badLine.
- code := String streamContents: [:s |
- lines withIndexDo: [:l :i |
- s nextPutAll: i asString, ': ', l, String lf]].
- ^ Error new messageText: ('Parse error on line ' , row , ' column ' , col , ' : ' , message , ' Below is code with line numbers and ===> marker inserted:' , String lf, code)
- !
- reservedWords
- "JavaScript reserved words"
- <return self.reservedWords>
- ! !
- !Smalltalk methodsFor: 'classes'!
- removeClass: aClass
- aClass isMetaclass ifTrue: [self error: aClass asString, ' is a Metaclass and cannot be removed!!'].
- aClass methodDictionary values do: [:each |
- aClass removeCompiledMethod: each].
- aClass class methodDictionary values do: [:each |
- aClass class removeCompiledMethod: each].
- self basicDelete: aClass name
- ! !
- !Smalltalk methodsFor: 'packages'!
- packages
- "Return all Package instances in the system."
- <return self.packages.all()>
- !
- packageAt: packageName
- <return self.packages[packageName]>
- !
- packageAt: packageName ifAbsent: aBlock
- ^(self packageAt: packageName) ifNil: aBlock
- !
- removePackage: packageName
- "Removes a package and all its classes."
- | pkg |
- pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
- pkg classes do: [:each |
- self removeClass: each].
- self deletePackage: packageName
- !
- renamePackage: packageName to: newName
- "Rename a package."
- | pkg |
- pkg := self packageAt: packageName ifAbsent: [self error: 'Missing package: ', packageName].
- (self packageAt: newName) ifNotNil: [self error: 'Already exists a package called: ', newName].
- <smalltalk.packages[newName] = smalltalk.packages[packageName]>.
- pkg name: newName.
- self deletePackage: packageName.
- ! !
- !Smalltalk methodsFor: 'private'!
- createPackage: packageName
- "Create and bind a new package with given name and return it."
- <return smalltalk.addPackage(packageName)>
- !
- deletePackage: packageName
- "Deletes a package by deleting its binding, but does not check if it contains classes etc.
- To remove a package, use #removePackage instead."
- <delete smalltalk.packages[packageName]>
- ! !
- Smalltalk class instanceVariableNames: 'current'!
- !Smalltalk class methodsFor: 'accessing'!
- current
- <return smalltalk>
- ! !
- Object subclass: #Package
- instanceVariableNames: 'commitPathJs commitPathSt'
- category: 'Kernel'!
- !Package commentStamp!
- 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.
- 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.
- Packages are manipulated through "Smalltalk current", like for example finding one based on a name:
- Smalltalk current packageAt: 'Kernel'
- ...but you can also use:
- Package named: 'Kernel'
- 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
- 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
- String where the method category "*IDE" defines #inspectOn: which thus is a method belonging to the IDE package.!
- !Package methodsFor: 'accessing'!
- name
- <return self.pkgName || nil>
- !
- requires
- <return self.requires || nil>
- !
- name: aString
- <self.pkgName = aString>
- !
- commitPathJs
- ^ commitPathJs ifNil: [self class defaultCommitPathJs]
- !
- commitPathSt
- ^ commitPathSt ifNil: [self class defaultCommitPathSt]
- !
- commitPathJs: aString
- commitPathJs := aString
- !
- commitPathSt: aString
- commitPathSt := aString
- ! !
- !Package methodsFor: 'classes'!
- classes
- "We need to do a reverse scan."
- ^Smalltalk current classes select: [:c | c package == self]
- ! !
- !Package methodsFor: 'printing'!
- printString
- ^self name
- ! !
- Package class instanceVariableNames: 'defaultCommitPathJs defaultCommitPathSt'!
- !Package class methodsFor: 'accessing'!
- named: aPackageName
- ^Smalltalk current packageAt: aPackageName
- !
- named: aPackageName ifAbsent: aBlock
- ^Smalltalk current packageAt: aPackageName ifAbsent: aBlock
- !
- defaultCommitPathSt
- ^ defaultCommitPathSt ifNil: [ defaultCommitPathSt := 'st']
- !
- defaultCommitPathJs
- ^ defaultCommitPathJs ifNil: [ defaultCommitPathJs := 'js']
- !
- defaultCommitPathSt: aString
- defaultCommitPathSt := aString
- !
- defaultCommitPathJs: aString
- defaultCommitPathJs := aString
- ! !
- !Package class methodsFor: 'reset'!
- resetCommitPaths
- defaultCommitPathJs := nil.
- defaultCommitPathSt := nil.
- ! !
- Object subclass: #Behavior
- instanceVariableNames: ''
- category: 'Kernel'!
- !Behavior methodsFor: 'accessing'!
- name
- <return self.className || nil>
- !
- superclass
- <return self.superclass || nil>
- !
- subclasses
- <return smalltalk.subclasses(self)>
- !
- allSubclasses
- | result |
- result := self subclasses.
- self subclasses do: [:each |
- result addAll: each allSubclasses].
- ^result
- !
- withAllSubclasses
- ^(Array with: self) addAll: self allSubclasses; yourself
- !
- prototype
- <return self.fn.prototype>
- !
- methodDictionary
- <var dict = smalltalk.Dictionary._new();
- var methods = self.fn.prototype.methods;
- for(var i in methods) {
- if(methods[i].selector) {
- dict._at_put_(methods[i].selector, methods[i]);
- }
- };
- return dict>
- !
- methodsFor: aString
- ^ClassCategoryReader new
- class: self category: aString;
- yourself
- !
- addCompiledMethod: aMethod
- <smalltalk.addMethod(aMethod.selector._asSelector(), aMethod, self)>
- !
- instanceVariableNames
- <return self.iVarNames>
- !
- comment
- ^(self basicAt: 'comment') ifNil: ['']
- !
- comment: aString
- self basicAt: 'comment' put: aString
- !
- commentStamp
- ^ClassCommentReader new
- class: self;
- yourself
- !
- removeCompiledMethod: aMethod
- <delete self.fn.prototype[aMethod.selector._asSelector()];
- delete self.fn.prototype.methods[aMethod.selector];
- smalltalk.init(self);>
- !
- protocols
- | protocols |
- protocols := Array new.
- self methodDictionary do: [:each |
- (protocols includes: each category) ifFalse: [
- protocols add: each category]].
- ^protocols sort
- !
- protocolsDo: aBlock
- "Execute aBlock for each method category with
- its collection of methods in the sort order of category name."
- | methodsByCategory |
- methodsByCategory := Dictionary new.
- self methodDictionary values do: [:m |
- (methodsByCategory at: m category ifAbsentPut: [Array new])
- add: m].
- self protocols do: [:category |
- aBlock value: category value: (methodsByCategory at: category)]
- !
- allInstanceVariableNames
- | result |
- result := self instanceVariableNames copy.
- self superclass ifNotNil: [
- result addAll: self superclass allInstanceVariableNames].
- ^result
- !
- methodAt: aString
- <return smalltalk.methods(self)[aString]>
- !
- methodsFor: aString stamp: aStamp
- "Added for compatibility, right now ignores stamp."
- ^self methodsFor: aString
- !
- commentStamp: aStamp prior: prior
- ^self commentStamp
- ! !
- !Behavior methodsFor: 'compiling'!
- compile: aString
- self compile: aString category: ''
- !
- compile: aString category: anotherString
- | method |
- method := Compiler new load: aString forClass: self.
- method category: anotherString.
- self addCompiledMethod: method
- ! !
- !Behavior methodsFor: 'instance creation'!
- new
- ^self basicNew initialize
- !
- basicNew
- <return new self.fn()>
- !
- inheritsFrom: aClass
- ^aClass allSubclasses includes: self
- ! !
- Behavior subclass: #Class
- instanceVariableNames: ''
- category: 'Kernel'!
- !Class methodsFor: 'accessing'!
- category
- ^self package ifNil: ['Unclassified'] ifNotNil: [self package name]
- !
- rename: aString
- <
- smalltalk[aString] = self;
- delete smalltalk[self.className];
- self.className = aString;
- >
- !
- package
- <return self.pkg>
- !
- package: aPackage
- <self.pkg = aPackage>
- ! !
- !Class methodsFor: 'class creation'!
- subclass: aString instanceVariableNames: anotherString
- "Kept for compatibility."
- ^self subclass: aString instanceVariableNames: anotherString package: nil
- !
- subclass: aString instanceVariableNames: aString2 category: aString3
- "Kept for compatibility."
- ^self subclass: aString instanceVariableNames: aString2 package: aString3
- !
- subclass: aString instanceVariableNames: aString2 classVariableNames: classVars poolDictionaries: pools category: aString3
- "Just ignore class variables and pools. Added for compatibility."
- ^self subclass: aString instanceVariableNames: aString2 package: aString3
- !
- subclass: aString instanceVariableNames: aString2 package: aString3
- ^ClassBuilder new
- superclass: self subclass: aString instanceVariableNames: aString2 package: aString3
- ! !
- !Class methodsFor: 'printing'!
- printString
- ^self name
- ! !
- !Class methodsFor: 'testing'!
- isClass
- ^true
- ! !
- Behavior subclass: #Metaclass
- instanceVariableNames: ''
- category: 'Kernel'!
- !Metaclass methodsFor: 'accessing'!
- instanceClass
- <return self.instanceClass>
- !
- instanceVariableNames: aCollection
- ClassBuilder new
- class: self instanceVariableNames: aCollection
- ! !
- !Metaclass methodsFor: 'printing'!
- printString
- ^self instanceClass name, ' class'
- ! !
- !Metaclass methodsFor: 'testing'!
- isMetaclass
- ^true
- ! !
- Object subclass: #CompiledMethod
- instanceVariableNames: ''
- category: 'Kernel'!
- !CompiledMethod methodsFor: 'accessing'!
- source
- ^(self basicAt: 'source') ifNil: ['']
- !
- source: aString
- self basicAt: 'source' put: aString
- !
- category
- ^(self basicAt: 'category') ifNil: ['']
- !
- category: aString
- self basicAt: 'category' put: aString
- !
- selector
- ^self basicAt: 'selector'
- !
- selector: aString
- self basicAt: 'selector' put: aString
- !
- fn
- ^self basicAt: 'fn'
- !
- fn: aBlock
- self basicAt: 'fn' put: aBlock
- !
- messageSends
- ^self basicAt: 'messageSends'
- !
- methodClass
- ^self basicAt: 'methodClass'
- !
- referencedClasses
- ^self basicAt: 'referencedClasses'
- !
- arguments
- <return self.args || []>
- ! !
- Object subclass: #Number
- instanceVariableNames: ''
- category: 'Kernel'!
- !Number methodsFor: 'arithmetic'!
- + aNumber
- "Inlined in the Compiler"
- <return self + aNumber>
- !
- - aNumber
- "Inlined in the Compiler"
- <return self - aNumber>
- !
- * aNumber
- "Inlined in the Compiler"
- <return self * aNumber>
- !
- / aNumber
- "Inlined in the Compiler"
- <return self / aNumber>
- !
- max: aNumber
- <return Math.max(self, aNumber);>
- !
- min: aNumber
- <return Math.min(self, aNumber);>
- !
- negated
- ^0 - self
- !
- \\ aNumber
- <return self % aNumber>
- ! !
- !Number methodsFor: 'comparing'!
- = aNumber
- aNumber class = self class ifFalse: [^false].
- <return Number(self) == aNumber>
- !
- > aNumber
- "Inlined in the Compiler"
- <return self >> aNumber>
- !
- < aNumber
- "Inlined in the Compiler"
- <return self < aNumber>
- !
- >= aNumber
- "Inlined in the Compiler"
- <return self >>= aNumber>
- !
- <= aNumber
- "Inlined in the Compiler"
- <return self <= aNumber>
- !
- == aNumber
- aNumber class = self class ifFalse: [^false].
- <return Number(self) === Number(aNumber)>
- ! !
- !Number methodsFor: 'converting'!
- rounded
- <return Math.round(self);>
- !
- truncated
- |result|
- self >= 0
- ifTrue: [<result = Math.floor(self);>]
- ifFalse: [<result = (Math.floor(self * (-1)) * (-1));>].
- ^ result
- !
- to: aNumber
- | array first last count |
- first := self truncated.
- last := aNumber truncated + 1.
- count := 1.
- array := Array new.
- (last - first) timesRepeat: [
- array at: count put: first.
- count := count + 1.
- first := first + 1].
- ^array
- !
- asString
- ^self printString
- !
- asJavascript
- ^'(', self printString, ')'
- !
- atRandom
- ^(Random new next * self) truncated + 1
- !
- @ aNumber
- ^Point x: self y: aNumber
- !
- asPoint
- ^Point x: self y: self
- !
- asJSONObject
- ^self
- !
- to: stop by: step
- | array value pos |
- value := self.
- array := Array new.
- pos := 1.
- step = 0 ifTrue: [self error: 'step must be non-zero'].
- step < 0
- ifTrue: [[ value >= stop ] whileTrue: [
- array at: pos put: value.
- pos := pos + 1.
- value := value + step]]
- ifFalse: [[ value <= stop ] whileTrue: [
- array at: pos put: value.
- pos := pos + 1.
- value := value + step]].
- ^array
- !
- to: stop by: step do: aBlock
- | value |
- value := self.
- step = 0 ifTrue: [self error: 'step must be non-zero'].
- step < 0
- ifTrue: [[ value >= stop ] whileTrue: [
- aBlock value: value.
- value := value + step]]
- ifFalse: [[ value <= stop ] whileTrue: [
- aBlock value: value.
- value := value + step]]
- ! !
- !Number methodsFor: 'copying'!
- deepCopy
- ^self copy
- !
- copy
- ^self
- ! !
- !Number methodsFor: 'enumerating'!
- timesRepeat: aBlock
- | integer count |
- integer := self truncated.
- count := 1.
- [count > self] whileFalse: [
- aBlock value.
- count := count + 1]
- !
- to: stop do: aBlock
- "Evaluate aBlock for each number from self to aNumber."
- | nextValue |
- nextValue := self.
- [nextValue <= stop]
- whileTrue:
- [aBlock value: nextValue.
- nextValue := nextValue + 1]
- ! !
- !Number methodsFor: 'printing'!
- printString
- <return String(self)>
- !
- printShowingDecimalPlaces: placesDesired
- <return self.toFixed(placesDesired)>
- ! !
- !Number methodsFor: 'testing'!
- isNumber
- ^true
- !
- even
- ^ 0 = (self \\ 2)
- !
- odd
- ^ self even not
- ! !
- !Number methodsFor: 'timeouts/intervals'!
- clearInterval
- <clearInterval(Number(self))>
- !
- clearTimeout
- <clearTimeout(Number(self))>
- ! !
- !Number class methodsFor: 'instance creation'!
- pi
- <return Math.PI>
- ! !
- Object subclass: #BlockClosure
- instanceVariableNames: ''
- category: 'Kernel'!
- !BlockClosure methodsFor: 'accessing'!
- compiledSource
- <return self.toString()>
- ! !
- !BlockClosure methodsFor: 'controlling'!
- whileTrue: aBlock
- "inlined in the Compiler"
- <while(self()) {aBlock()}>
- !
- whileFalse: aBlock
- "inlined in the Compiler"
- <while(!!self()) {aBlock()}>
- !
- whileFalse
- "inlined in the Compiler"
- self whileFalse: []
- !
- whileTrue
- "inlined in the Compiler"
- self whileTrue: []
- ! !
- !BlockClosure methodsFor: 'error handling'!
- on: anErrorClass do: aBlock
- self try: self catch: [:error |
- (error isKindOf: anErrorClass)
- ifTrue: [aBlock value: error]
- ifFalse: [error signal]]
- ! !
- !BlockClosure methodsFor: 'evaluating'!
- value
- "inlined in the Compiler"
- <return self();>
- !
- value: anArg
- "inlined in the Compiler"
- <return self(anArg);>
- !
- value: firstArg value: secondArg
- "inlined in the Compiler"
- <return self(firstArg, secondArg);>
- !
- value: firstArg value: secondArg value: thirdArg
- "inlined in the Compiler"
- <return self(firstArg, secondArg, thirdArg);>
- !
- valueWithPossibleArguments: aCollection
- <return self.apply(null, aCollection);>
- !
- new
- "Use the receiver as a JS constructor.
- *Do not* use this method to instanciate Smalltalk objects!!"
- <return new self()>
- !
- applyTo: anObject arguments: aCollection
- <return self.apply(anObject, aCollection)>
- !
- timeToRun
- "Answer the number of milliseconds taken to execute this block."
- ^ Date millisecondsToRun: self
- ! !
- !BlockClosure methodsFor: 'timeout/interval'!
- valueWithTimeout: aNumber
- <return setTimeout(self, aNumber)>
- !
- valueWithInterval: aNumber
- <return setInterval(self, aNumber)>
- ! !
- Object subclass: #Boolean
- instanceVariableNames: ''
- category: 'Kernel'!
- !Boolean methodsFor: 'comparing'!
- = aBoolean
- aBoolean class = self class ifFalse: [^false].
- <return Boolean(self == true) == aBoolean>
- !
- == aBoolean
- aBoolean class = self class ifFalse: [^false].
- <return Boolean(self == true) === Boolean(aBoolean == true)>
- ! !
- !Boolean methodsFor: 'controlling'!
- ifTrue: aBlock
- "inlined in the Compiler"
- ^self ifTrue: aBlock ifFalse: []
- !
- ifFalse: aBlock
- "inlined in the Compiler"
- ^self ifTrue: [] ifFalse: aBlock
- !
- ifFalse: aBlock ifTrue: anotherBlock
- "inlined in the Compiler"
- ^self ifTrue: anotherBlock ifFalse: aBlock
- !
- ifTrue: aBlock ifFalse: anotherBlock
- "inlined in the Compiler"
- <
- if(self == true) {
- return aBlock();
- } else {
- return anotherBlock();
- }
- >
- !
- and: aBlock
- ^self = true
- ifTrue: aBlock
- ifFalse: [false]
- !
- or: aBlock
- ^self = true
- ifTrue: [true]
- ifFalse: aBlock
- !
- not
- ^self = false
- !
- & aBoolean
- <
- if(self == true) {
- return aBoolean;
- } else {
- return false;
- }
- >
- !
- | aBoolean
- <
- if(self == true) {
- return true;
- } else {
- return aBoolean;
- }
- >
- ! !
- !Boolean methodsFor: 'converting'!
- asJSONObject
- ^self
- ! !
- !Boolean methodsFor: 'copying'!
- shallowCopy
- ^self
- !
- deepCopy
- ^self
- ! !
- !Boolean methodsFor: 'printing'!
- printString
- <return self.toString()>
- ! !
- Object subclass: #Date
- instanceVariableNames: ''
- category: 'Kernel'!
- !Date commentStamp!
- The Date class is used to work with dates and times.!
- !Date methodsFor: 'accessing'!
- year
- <return self.getFullYear()>
- !
- month
- <return self.getMonth() + 1>
- !
- month: aNumber
- <self.setMonth(aNumber - 1)>
- !
- day
- ^self dayOfWeek
- !
- dayOfWeek
- <return self.getDay() + 1>
- !
- dayOfWeek: aNumber
- <return self.setDay(aNumber - 1)>
- !
- day: aNumber
- self day: aNumber
- !
- year: aNumber
- <self.setFullYear(aNumber)>
- !
- dayOfMonth
- <return self.getDate()>
- !
- dayOfMonth: aNumber
- <self.setDate(aNumber)>
- !
- time
- <return self.getTime()>
- !
- time: aNumber
- <self.setTime(aNumber)>
- !
- hours: aNumber
- <self.setHours(aNumber)>
- !
- minutes: aNumber
- <self.setMinutes(aNumber)>
- !
- seconds: aNumber
- <self.setSeconds(aNumber)>
- !
- milliseconds: aNumber
- <self.setMilliseconds(aNumber)>
- !
- hours
- <return self.getHours()>
- !
- minutes
- <return self.getMinutes()>
- !
- seconds
- <return self.getSeconds()>
- !
- milliseconds
- <return self.getMilliseconds()>
- ! !
- !Date methodsFor: 'arithmetic'!
- - aDate
- <return self - aDate>
- !
- + aDate
- <return self + aDate>
- ! !
- !Date methodsFor: 'comparing'!
- < aDate
- <return self < aDate>
- !
- > aDate
- <return self >> aDate>
- !
- <= aDate
- <return self <= aDate>
- !
- >= aDate
- <return self >>= aDate>
- ! !
- !Date methodsFor: 'converting'!
- asString
- <return self.toString()>
- !
- asMilliseconds
- ^self time
- !
- asDateString
- <return self.toDateString()>
- !
- asTimeString
- <return self.toTimeString()>
- !
- asLocaleString
- <return self.toLocaleString()>
- !
- asNumber
- ^self asMilliseconds
- !
- asJSONObject
- ^self
- ! !
- !Date methodsFor: 'printing'!
- printString
- ^self asString
- ! !
- !Date class methodsFor: 'instance creation'!
- new: anObject
- <return new Date(anObject)>
- !
- fromString: aString
- "Example: Date fromString('2011/04/15 00:00:00')"
- ^self new: aString
- !
- fromSeconds: aNumber
- ^self fromMilliseconds: aNumber * 1000
- !
- fromMilliseconds: aNumber
- ^self new: aNumber
- !
- today
- ^self new
- !
- now
- ^self today
- !
- millisecondsToRun: aBlock
- | t |
- t := Date now.
- aBlock value.
- ^Date now - t
- ! !
- Object subclass: #UndefinedObject
- instanceVariableNames: ''
- category: 'Kernel'!
- !UndefinedObject methodsFor: 'class creation'!
- subclass: aString instanceVariableNames: anotherString
- ^self subclass: aString instanceVariableNames: anotherString package: nil
- !
- subclass: aString instanceVariableNames: aString2 category: aString3
- "Kept for compatibility."
- ^self subclass: aString instanceVariableNames: aString2 package: aString3
- !
- subclass: aString instanceVariableNames: aString2 package: aString3
- ^ClassBuilder new
- superclass: self subclass: aString instanceVariableNames: aString2 package: aString3
- ! !
- !UndefinedObject methodsFor: 'copying'!
- shallowCopy
- ^self
- !
- deepCopy
- ^self
- ! !
- !UndefinedObject methodsFor: 'printing'!
- printString
- ^'nil'
- ! !
- !UndefinedObject methodsFor: 'testing'!
- ifNil: aBlock
- "inlined in the Compiler"
- ^self ifNil: aBlock ifNotNil: []
- !
- ifNotNil: aBlock
- "inlined in the Compiler"
- ^self
- !
- ifNil: aBlock ifNotNil: anotherBlock
- "inlined in the Compiler"
- ^aBlock value
- !
- ifNotNil: aBlock ifNil: anotherBlock
- "inlined in the Compiler"
- ^anotherBlock value
- !
- isNil
- ^true
- !
- notNil
- ^false
- ! !
- !UndefinedObject class methodsFor: 'instance creation'!
- new
- self error: 'You cannot create new instances of UndefinedObject. Use nil'
- ! !
- Object subclass: #Collection
- instanceVariableNames: ''
- category: 'Kernel'!
- !Collection methodsFor: 'accessing'!
- size
- self subclassResponsibility
- !
- readStream
- ^self stream
- !
- writeStream
- ^self stream
- !
- stream
- ^self streamClass on: self
- !
- streamClass
- ^self class streamClass
- ! !
- !Collection methodsFor: 'adding/removing'!
- add: anObject
- self subclassResponsibility
- !
- addAll: aCollection
- aCollection do: [:each |
- self add: each].
- ^aCollection
- !
- remove: anObject
- self subclassResponsibility
- ! !
- !Collection methodsFor: 'converting'!
- asArray
- | array index |
- array := Array new.
- index := 0.
- self do: [:each |
- index := index + 1.
- array at: index put: each].
- ^array
- !
- asSet
- ^Set withAll: self
- ! !
- !Collection methodsFor: 'copying'!
- , aCollection
- ^self copy
- addAll: aCollection;
- yourself
- !
- copyWith: anObject
- ^self copy add: anObject; yourself
- !
- copyWithAll: aCollection
- ^self copy addAll: aCollection; yourself
- !
- copyWithoutAll: aCollection
- "Answer a copy of the receiver that does not contain any elements
- equal to those in aCollection."
- ^ self reject: [:each | aCollection includes: each]
- ! !
- !Collection methodsFor: 'enumerating'!
- do: aBlock
- <for(var i=0;i<self.length;i++){aBlock(self[i]);}>
- !
- collect: aBlock
- | newCollection |
- newCollection := self class new.
- self do: [:each |
- newCollection add: (aBlock value: each)].
- ^newCollection
- !
- detect: aBlock
- ^self detect: aBlock ifNone: [self errorNotFound]
- !
- detect: aBlock ifNone: anotherBlock
- <
- for(var i = 0; i < self.length; i++)
- if(aBlock(self[i]))
- return self[i];
- return anotherBlock();
- >
- !
- do: aBlock separatedBy: anotherBlock
- | first |
- first := true.
- self do: [:each |
- first
- ifTrue: [first := false]
- ifFalse: [anotherBlock value].
- aBlock value: each]
- !
- inject: anObject into: aBlock
- | result |
- result := anObject.
- self do: [:each |
- result := aBlock value: result value: each].
- ^result
- !
- reject: aBlock
- ^self select: [:each | (aBlock value: each) = false]
- !
- select: aBlock
- | stream |
- stream := self class new writeStream.
- self do: [:each |
- (aBlock value: each) ifTrue: [
- stream nextPut: each]].
- ^stream contents
- ! !
- !Collection methodsFor: 'error handling'!
- errorNotFound
- self error: 'Object is not in the collection'
- ! !
- !Collection methodsFor: 'testing'!
- includes: anObject
- <
- var i = self.length;
- while (i--) {
- if (smalltalk.send(self[i], "__eq", [anObject])) {return true;}
- }
- return false
- >
- !
- notEmpty
- ^self isEmpty not
- !
- isEmpty
- ^self size = 0
- !
- ifNotEmpty: aBlock
- self notEmpty ifTrue: aBlock.
- !
- ifEmpty: aBlock
- self isEmpty ifTrue: aBlock.
- ! !
- !Collection class methodsFor: 'accessing'!
- streamClass
- ^Stream
- ! !
- !Collection class methodsFor: 'instance creation'!
- with: anObject
- ^self new
- add: anObject;
- yourself
- !
- with: anObject with: anotherObject
- ^self new
- add: anObject;
- add: anotherObject;
- yourself
- !
- with: firstObject with: secondObject with: thirdObject
- ^self new
- add: firstObject;
- add: secondObject;
- add: thirdObject;
- yourself
- !
- withAll: aCollection
- ^self new
- addAll: aCollection;
- yourself
- ! !
- Collection subclass: #SequenceableCollection
- instanceVariableNames: ''
- category: 'Kernel'!
- !SequenceableCollection methodsFor: 'accessing'!
- at: anIndex
- ^self at: anIndex ifAbsent: [
- self errorNotFound]
- !
- at: anIndex ifAbsent: aBlock
- self subclassResponsibility
- !
- at: anIndex put: anObject
- self subclassResponsibility
- !
- first
- ^self at: 1
- !
- fourth
- ^self at: 4
- !
- last
- ^self at: self size
- !
- second
- ^self at: 2
- !
- third
- ^self at: 3
- !
- allButFirst
- ^self copyFrom: 2 to: self size
- !
- allButLast
- ^self copyFrom: 1 to: self size - 1
- !
- indexOf: anObject
- ^self indexOf: anObject ifAbsent: [self errorNotFound]
- !
- indexOf: anObject ifAbsent: aBlock
- <
- for(var i=0;i<self.length;i++){
- if(self[i].__eq(anObject)) {return i+1}
- }
- return aBlock();
- >
- !
- indexOf: anObject startingAt: start ifAbsent: aBlock
- <
- for(var i=start-1;i<self.length;i++){
- if(self[i].__eq(anObject)) {return i+1}
- }
- return aBlock();
- >
- !
- indexOf: anObject startingAt: start
- "Answer the index of the first occurence of anElement after start
- within the receiver. If the receiver does not contain anElement,
- answer 0."
- ^self indexOf: anObject startingAt: start ifAbsent: [0]
- !
- atRandom
- ^ self at: self size atRandom
- ! !
- !SequenceableCollection methodsFor: 'adding'!
- removeLast
- self remove: self last
- !
- addLast: anObject
- self add: anObject
- ! !
- !SequenceableCollection methodsFor: 'converting'!
- reversed
- self subclassResponsibility
- ! !
- !SequenceableCollection methodsFor: 'copying'!
- copyFrom: anIndex to: anotherIndex
- self subclassResponsibility
- ! !
- !SequenceableCollection methodsFor: 'enumerating'!
- withIndexDo: aBlock
- <for(var i=0;i<self.length;i++){aBlock(self[i], i+1);}>
- ! !
- SequenceableCollection subclass: #String
- instanceVariableNames: ''
- category: 'Kernel'!
- !String methodsFor: 'accessing'!
- size
- <return self.length>
- !
- at: anIndex
- <return self[anIndex - 1]>
- !
- at: anIndex put: anObject
- self errorReadOnly
- !
- at: anIndex ifAbsent: aBlock
- (self at: anIndex) ifNil: [aBlock]
- !
- escaped
- <return escape(self)>
- !
- unescaped
- <return unescape(self)>
- !
- asciiValue
- <return self.charCodeAt(0);>
- ! !
- !String methodsFor: 'adding'!
- add: anObject
- self errorReadOnly
- !
- remove: anObject
- self errorReadOnly
- ! !
- !String methodsFor: 'comparing'!
- = aString
- aString class = self class ifFalse: [^false].
- <return String(self) == aString>
- !
- > aString
- <return String(self) >> aString>
- !
- < aString
- <return String(self) < aString>
- !
- >= aString
- <return String(self) >>= aString>
- !
- <= aString
- <return String(self) <= aString>
- !
- == aString
- aString class = self class ifFalse: [^false].
- <return String(self) === String(aString)>
- ! !
- !String methodsFor: 'converting'!
- asSelector
- "If you change this method, change smalltalk.convertSelector too (see js/boot.js file)"
- | selector |
- selector := '_', self.
- selector := selector replace: ':' with: '_'.
- selector := selector replace: '[+]' with: '_plus'.
- selector := selector replace: '-' with: '_minus'.
- selector := selector replace: '[*]' with: '_star'.
- selector := selector replace: '[/]' with: '_slash'.
- selector := selector replace: '>' with: '_gt'.
- selector := selector replace: '<' with: '_lt'.
- selector := selector replace: '=' with: '_eq'.
- selector := selector replace: ',' with: '_comma'.
- selector := selector replace: '[@]' with: '_at'.
- ^selector
- !
- asJavascript
- <
- if(self.search(/^[a-zA-Z0-9_:.$ ]*$/) == -1)
- return "unescape(\"" + escape(self) + "\")";
- else
- return "\"" + self + "\"";
- >
- !
- tokenize: aString
- <return self.split(aString)>
- !
- asString
- ^self
- !
- asNumber
- <return Number(self)>
- !
- asJSONObject
- ^self
- !
- asLowercase
- <return self.toLowerCase()>
- !
- asUppercase
- <return self.toUpperCase()>
- !
- reversed
- <return self.split("").reverse().join("")>
- !
- asJavaScriptSelector
- ^(self asSelector replace: '^_' with: '') replace: '_.*' with: ''.
- ! !
- !String methodsFor: 'copying'!
- , aString
- <return self + aString>
- !
- copyFrom: anIndex to: anotherIndex
- <return self.substring(anIndex - 1, anotherIndex)>
- !
- shallowCopy
- ^self class fromString: self
- !
- deepCopy
- ^self shallowCopy
- ! !
- !String methodsFor: 'error handling'!
- errorReadOnly
- self error: 'Object is read-only'
- ! !
- !String methodsFor: 'printing'!
- printString
- ^'''', self, ''''
- !
- printNl
- <console.log(self)>
- ! !
- !String methodsFor: 'regular expressions'!
- replace: aString with: anotherString
- ^self replaceRegexp: (RegularExpression fromString: aString flag: 'g') with: anotherString
- !
- replaceRegexp: aRegexp with: aString
- <return self.replace(aRegexp, aString)>
- !
- match: aRegexp
- <return self.search(aRegexp) !!= -1>
- !
- trimLeft: separators
- ^self replaceRegexp: (RegularExpression fromString: '^[', separators, ']+' flag: 'g') with: ''
- !
- trimRight: separators
- ^self replaceRegexp: (RegularExpression fromString: '[', separators, ']+$' flag: 'g') with: ''
- !
- trimLeft
- ^self trimLeft: '\s'
- !
- trimRight
- ^self trimRight: '\s'
- !
- trimBoth
- ^self trimBoth: '\s'
- !
- trimBoth: separators
- ^(self trimLeft: separators) trimRight: separators
- ! !
- !String methodsFor: 'split join'!
- join: aCollection
- ^ String
- streamContents: [:stream | aCollection
- do: [:each | stream nextPutAll: each asString]
- separatedBy: [stream nextPutAll: self]]
- !
- lineIndicesDo: aBlock
- "execute aBlock with 3 arguments for each line:
- - start index of line
- - end index of line without line delimiter
- - end index of line including line delimiter(s) CR, LF or CRLF"
-
- | cr lf start sz nextLF nextCR |
- start := 1.
- sz := self size.
- cr := String cr.
- nextCR := self indexOf: cr startingAt: 1.
- lf := String lf.
- nextLF := self indexOf: lf startingAt: 1.
- [ start <= sz ] whileTrue: [
- (nextLF = 0 and: [ nextCR = 0 ])
- ifTrue: [ "No more CR, nor LF, the string is over"
- aBlock value: start value: sz value: sz.
- ^self ].
- (nextCR = 0 or: [ 0 < nextLF and: [ nextLF < nextCR ] ])
- ifTrue: [ "Found a LF"
- aBlock value: start value: nextLF - 1 value: nextLF.
- start := 1 + nextLF.
- nextLF := self indexOf: lf startingAt: start ]
- ifFalse: [ 1 + nextCR = nextLF
- ifTrue: [ "Found a CR-LF pair"
- aBlock value: start value: nextCR - 1 value: nextLF.
- start := 1 + nextLF.
- nextCR := self indexOf: cr startingAt: start.
- nextLF := self indexOf: lf startingAt: start ]
- ifFalse: [ "Found a CR"
- aBlock value: start value: nextCR - 1 value: nextCR.
- start := 1 + nextCR.
- nextCR := self indexOf: cr startingAt: start ]]]
- !
- linesDo: aBlock
- "Execute aBlock with each line in this string. The terminating line
- delimiters CR, LF or CRLF pairs are not included in what is passed to aBlock"
- self lineIndicesDo: [:start :endWithoutDelimiters :end |
- aBlock value: (self copyFrom: start to: endWithoutDelimiters)]
- !
- lines
- "Answer an array of lines composing this receiver without the line ending delimiters."
- | lines |
- lines := Array new.
- self linesDo: [:aLine | lines add: aLine].
- ^lines
- !
- lineNumber: anIndex
- "Answer a string containing the characters in the given line number."
- | lineCount |
- lineCount := 0.
- self lineIndicesDo: [:start :endWithoutDelimiters :end |
- (lineCount := lineCount + 1) = anIndex ifTrue: [^self copyFrom: start to: endWithoutDelimiters]].
- ^nil
- ! !
- !String methodsFor: 'testing'!
- isString
- ^true
- !
- includesSubString: subString
- < return self.indexOf(subString) !!= -1 >
- ! !
- !String class methodsFor: 'accessing'!
- streamClass
- ^StringStream
- !
- cr
- <return '\r'>
- !
- lf
- <return '\n'>
- !
- space
- <return ' '>
- !
- tab
- <return '\t'>
- !
- crlf
- <return '\r\n'>
- ! !
- !String class methodsFor: 'instance creation'!
- fromString: aString
- <return new self.fn(aString)>
- !
- streamContents: blockWithArg
- |stream|
- stream := (self streamClass on: String new).
- blockWithArg value: stream.
- ^ stream contents
- !
- value: aUTFCharCode
- <return String.fromCharCode(aUTFCharCode);>
- ! !
- SequenceableCollection subclass: #Array
- instanceVariableNames: ''
- category: 'Kernel'!
- !Array methodsFor: 'accessing'!
- size
- <return self.length>
- !
- at: anIndex put: anObject
- <return self[anIndex - 1] = anObject>
- !
- at: anIndex ifAbsent: aBlock
- <
- var value = self[anIndex - 1];
- if(value === undefined) {
- return aBlock();
- } else {
- return value;
- }
- >
- ! !
- !Array methodsFor: 'adding/removing'!
- add: anObject
- <self.push(anObject); return anObject;>
- !
- remove: anObject
- <
- for(var i=0;i<self.length;i++) {
- if(self[i] == anObject) {
- self.splice(i,1);
- break;
- }
- }
- >
- !
- removeFrom: aNumber to: anotherNumber
- <self.splice(aNumber - 1,anotherNumber - 1)>
- ! !
- !Array methodsFor: 'comparing'!
- = aCollection
- (self class = aCollection class and: [
- self size = aCollection size]) ifFalse: [^false].
- self withIndexDo: [:each :i |
- (aCollection at: i) = each ifFalse: [^false]].
- ^true
- ! !
- !Array methodsFor: 'converting'!
- asJavascript
- ^'[', ((self collect: [:each | each asJavascript]) join: ', '), ']'
- !
- asJSONObject
- ^self collect: [:each | each asJSONObject]
- !
- reversed
- <return self._copy().reverse()>
- ! !
- !Array methodsFor: 'copying'!
- shallowCopy
- | newCollection |
- newCollection := self class new.
- self do: [:each | newCollection add: each].
- ^newCollection
- !
- deepCopy
- | newCollection |
- newCollection := self class new.
- self do: [:each | newCollection add: each deepCopy].
- ^newCollection
- !
- copyFrom: anIndex to: anotherIndex
- | array |
- array := self class new.
- anIndex to: anotherIndex do: [:each |
- array add: (self at: each)].
- ^array
- ! !
- !Array methodsFor: 'enumerating'!
- join: aString
- <return self.join(aString)>
- !
- sort
- ^self basicPerform: 'sort'
- !
- sort: aBlock
- <
- return self.sort(function(a, b) {
- if(aBlock(a,b)) {return -1} else {return 1}
- })
- >
- !
- sorted
- ^self copy sort
- !
- sorted: aBlock
- ^self copy sort: aBlock
- !
- printString
- | str |
- str := '' writeStream.
- str nextPutAll: super printString, ' ('.
- self
- do: [:each | str nextPutAll: each printString]
- separatedBy: [str nextPutAll: ' '].
- str nextPutAll: ')'.
- ^str contents
- ! !
- Object subclass: #RegularExpression
- instanceVariableNames: ''
- category: 'Kernel'!
- !RegularExpression methodsFor: 'evaluating'!
- compile: aString
- <return self.compile(aString)>
- !
- exec: aString
- <return self.exec(aString) || nil>
- !
- test: aString
- <return self.test(aString)>
- ! !
- !RegularExpression class methodsFor: 'instance creation'!
- fromString: aString flag: anotherString
- <return new RegExp(aString, anotherString)>
- !
- fromString: aString
- ^self fromString: aString flag: ''
- ! !
- Object subclass: #Error
- instanceVariableNames: 'messageText'
- category: 'Kernel'!
- !Error methodsFor: 'accessing'!
- messageText
- ^messageText
- !
- messageText: aString
- messageText := aString
- !
- context
- <return self.context>
- ! !
- !Error methodsFor: 'signaling'!
- signal
- <self.context = smalltalk.getThisContext(); self.smalltalkError = true; throw(self)>
- ! !
- !Error class methodsFor: 'instance creation'!
- signal: aString
- ^self new
- messageText: aString;
- signal
- ! !
- Object subclass: #MethodContext
- instanceVariableNames: ''
- category: 'Kernel'!
- !MethodContext methodsFor: 'accessing'!
- receiver
- <return self.receiver>
- !
- selector
- <return smalltalk.convertSelector(self.selector)>
- !
- home
- <return self.homeContext>
- !
- temps
- <return self.temps>
- !
- printString
- ^super printString, '(', self asString, ')'
- !
- asString
- ^self receiver class printString, ' >> ', self selector
- ! !
- Object subclass: #Association
- instanceVariableNames: 'key value'
- category: 'Kernel'!
- !Association methodsFor: 'accessing'!
- key: aKey
- key := aKey
- !
- key
- ^key
- !
- value: aValue
- value := aValue
- !
- value
- ^value
- ! !
- !Association methodsFor: 'comparing'!
- = anAssociation
- ^self class = anAssociation class and: [
- self key = anAssociation key and: [
- self value = anAssociation value]]
- ! !
- !Association class methodsFor: 'instance creation'!
- key: aKey value: aValue
- ^self new
- key: aKey;
- value: aValue;
- yourself
- ! !
- Collection subclass: #Dictionary
- instanceVariableNames: 'keys'
- category: 'Kernel'!
- !Dictionary methodsFor: 'accessing'!
- size
- ^keys size
- !
- associations
- | associations |
- associations := #().
- keys do: [:each |
- associations add: (Association key: each value: (self at: each))].
- ^associations
- !
- keys
- ^keys copy
- !
- values
- ^keys collect: [:each | self at: each]
- !
- at: aKey put: aValue
- (keys includes: aKey) ifFalse: [keys add: aKey].
- ^self basicAt: aKey put: aValue
- !
- at: aKey ifAbsent: aBlock
- ^(self keys includes: aKey)
- ifTrue: [self basicAt: aKey]
- ifFalse: aBlock
- !
- at: aKey ifAbsentPut: aBlock
- ^self at: aKey ifAbsent: [
- self at: aKey put: aBlock value]
- !
- at: aKey ifPresent: aBlock
- ^(self basicAt: aKey) ifNotNil: [aBlock value: (self at: aKey)]
- !
- at: aKey ifPresent: aBlock ifAbsent: anotherBlock
- ^(self basicAt: aKey)
- ifNil: anotherBlock
- ifNotNil: [aBlock value: (self at: aKey)]
- !
- at: aKey
- ^self at: aKey ifAbsent: [self errorNotFound]
- ! !
- !Dictionary methodsFor: 'adding/removing'!
- add: anAssociation
- self at: anAssociation key put: anAssociation value
- !
- addAll: aDictionary
- super addAll: aDictionary associations.
- ^aDictionary
- !
- remove: aKey
- self removeKey: aKey
- !
- removeKey: aKey
- keys remove: aKey
- ! !
- !Dictionary methodsFor: 'comparing'!
- = aDictionary
- self class = aDictionary class ifFalse: [^false].
- self size = aDictionary size ifFalse: [^false].
- ^self associations = aDictionary associations
- ! !
- !Dictionary methodsFor: 'converting'!
- asJSONObject
- | object |
- object := Object new.
- self keysAndValuesDo: [:key :value |
- object basicAt: key put: value asJSONObject].
- ^object
- ! !
- !Dictionary methodsFor: 'copying'!
- shallowCopy
- | copy |
- copy := self class new.
- self associationsDo: [:each |
- copy at: each key put: each value].
- ^copy
- !
- , aCollection
- self shouldNotImplement
- !
- copyFrom: anIndex to: anotherIndex
- self shouldNotImplement
- ! !
- !Dictionary methodsFor: 'enumerating'!
- associationsDo: aBlock
- self associations do: aBlock
- !
- keysAndValuesDo: aBlock
- self associationsDo: [:each |
- aBlock value: each key value: each value]
- !
- do: aBlock
- self values do: aBlock
- !
- select: aBlock
- | newDict |
- newDict := self class new.
- self keysAndValuesDo: [:key :value |
- (aBlock value: value) ifTrue: [newDict at: key put: value]].
- ^newDict
- !
- collect: aBlock
- | newDict |
- newDict := self class new.
- self keysAndValuesDo: [:key :value |
- newDict at: key put: (aBlock value: value)].
- ^newDict
- !
- detect: aBlock ifNone: anotherBlock
- ^self values detect: aBlock ifNone: anotherBlock
- !
- includes: anObject
- ^self values includes: anObject
- ! !
- !Dictionary methodsFor: 'initialization'!
- initialize
- super initialize.
- keys := #()
- ! !
- !Dictionary methodsFor: 'printing'!
- printString
- ^ String streamContents: [:aStream|
- aStream
- nextPutAll: super printString;
- nextPutAll: '('.
- self associations
- do: [:anAssociation|
- aStream
- nextPutAll: anAssociation key printString;
- nextPutAll: ' -> ';
- nextPutAll: anAssociation value printString]
-
- separatedBy: [aStream nextPutAll: ' , '].
- aStream nextPutAll: ')'.
- ]
- ! !
- !Dictionary class methodsFor: 'instance creation'!
- fromPairs: aCollection
- | dict |
- dict := self new.
- aCollection do: [:each | dict add: each].
- ^dict
- ! !
- Object subclass: #ClassBuilder
- instanceVariableNames: ''
- category: 'Kernel'!
- !ClassBuilder methodsFor: 'class creation'!
- superclass: aClass subclass: aString
- ^self superclass: aClass subclass: aString instanceVariableNames: '' package: nil
- !
- class: aClass instanceVariableNames: aString
- aClass isMetaclass ifFalse: [self error: aClass name, ' is not a metaclass'].
- aClass basicAt: 'iVarNames' put: (self instanceVariableNamesFor: aString).
- self setupClass: aClass
- !
- superclass: aClass subclass: aString instanceVariableNames: aString2 package: aString3
- | newClass |
- newClass := self addSubclassOf: aClass
- named: aString instanceVariableNames: (self instanceVariableNamesFor: aString2)
- package: (aString3 ifNil: ['unclassified']).
- self setupClass: newClass.
- ^newClass
- ! !
- !ClassBuilder methodsFor: 'private'!
- instanceVariableNamesFor: aString
- ^(aString tokenize: ' ') reject: [:each | each isEmpty]
- !
- addSubclassOf: aClass named: aString instanceVariableNames: aCollection
- <smalltalk.addClass(aString, aClass, aCollection);
- return smalltalk[aString]>
- !
- setupClass: aClass
- <smalltalk.init(aClass);>
- !
- addSubclassOf: aClass named: aString instanceVariableNames: aCollection package: packageName
- <smalltalk.addClass(aString, aClass, aCollection, packageName);
- return smalltalk[aString]>
- ! !
- Object subclass: #ClassCategoryReader
- instanceVariableNames: 'class category chunkParser'
- category: 'Kernel'!
- !ClassCategoryReader methodsFor: 'accessing'!
- class: aClass category: aString
- class := aClass.
- category := aString
- ! !
- !ClassCategoryReader methodsFor: 'fileIn'!
- scanFrom: aChunkParser
- | chunk |
- [chunk := aChunkParser nextChunk.
- chunk isEmpty] whileFalse: [
- self compileMethod: chunk]
- ! !
- !ClassCategoryReader methodsFor: 'initialization'!
- initialize
- super initialize.
- chunkParser := ChunkParser new.
- ! !
- !ClassCategoryReader methodsFor: 'private'!
- compileMethod: aString
- | method |
- method := Compiler new load: aString forClass: class.
- method category: category.
- class addCompiledMethod: method
- ! !
- Object subclass: #Stream
- instanceVariableNames: 'collection position streamSize'
- category: 'Kernel'!
- !Stream methodsFor: 'accessing'!
- collection
- ^collection
- !
- setCollection: aCollection
- collection := aCollection
- !
- position
- ^position ifNil: [position := 0]
- !
- position: anInteger
- position := anInteger
- !
- streamSize
- ^streamSize
- !
- setStreamSize: anInteger
- streamSize := anInteger
- !
- contents
- ^self collection
- copyFrom: 1
- to: self streamSize
- !
- size
- ^self streamSize
- ! !
- !Stream methodsFor: 'actions'!
- reset
- self position: 0
- !
- close
- !
- flush
- !
- resetContents
- self reset.
- self setStreamSize: 0
- ! !
- !Stream methodsFor: 'enumerating'!
- do: aBlock
- [self atEnd] whileFalse: [aBlock value: self next]
- ! !
- !Stream methodsFor: 'positioning'!
- setToEnd
- self position: self size
- !
- skip: anInteger
- self position: ((self position + anInteger) min: self size max: 0)
- ! !
- !Stream methodsFor: 'reading'!
- next
- self position: self position + 1.
- ^collection at: self position
- !
- next: anInteger
- | tempCollection |
- tempCollection := self collection class new.
- anInteger timesRepeat: [
- self atEnd ifFalse: [
- tempCollection add: self next]].
- ^tempCollection
- !
- peek
- ^self atEnd ifFalse: [
- self collection at: self position + 1]
- ! !
- !Stream methodsFor: 'testing'!
- atEnd
- ^self position = self size
- !
- atStart
- ^self position = 0
- !
- isEmpty
- ^self size = 0
- ! !
- !Stream methodsFor: 'writing'!
- nextPut: anObject
- self position: self position + 1.
- self collection at: self position put: anObject.
- self setStreamSize: (self streamSize max: self position)
- !
- nextPutAll: aCollection
- aCollection do: [:each |
- self nextPut: each]
- ! !
- !Stream class methodsFor: 'instance creation'!
- on: aCollection
- ^self new
- setCollection: aCollection;
- setStreamSize: aCollection size;
- yourself
- ! !
- Stream subclass: #StringStream
- instanceVariableNames: ''
- category: 'Kernel'!
- !StringStream methodsFor: 'reading'!
- next: anInteger
- | tempCollection |
- tempCollection := self collection class new.
- anInteger timesRepeat: [
- self atEnd ifFalse: [
- tempCollection := tempCollection, self next]].
- ^tempCollection
- ! !
- !StringStream methodsFor: 'writing'!
- nextPut: aString
- self nextPutAll: aString
- !
- nextPutAll: aString
- self setCollection:
- (self collection copyFrom: 1 to: self position),
- aString,
- (self collection copyFrom: (self position + 1 + aString size) to: self collection size).
- self position: self position + aString size.
- self setStreamSize: (self streamSize max: self position)
- !
- cr
- ^self nextPutAll: String cr
- !
- crlf
- ^self nextPutAll: String crlf
- !
- lf
- ^self nextPutAll: String lf
- !
- space
- self nextPut: ' '
- ! !
- Object subclass: #ClassCommentReader
- instanceVariableNames: 'class chunkParser'
- category: 'Kernel'!
- !ClassCommentReader methodsFor: 'accessing'!
- class: aClass
- class := aClass
- ! !
- !ClassCommentReader methodsFor: 'fileIn'!
- scanFrom: aChunkParser
- | chunk |
- chunk := aChunkParser nextChunk.
- chunk isEmpty ifFalse: [
- self setComment: chunk].
- ! !
- !ClassCommentReader methodsFor: 'initialization'!
- initialize
- super initialize.
- chunkParser := ChunkParser new.
- ! !
- !ClassCommentReader methodsFor: 'private'!
- setComment: aString
- class comment: aString
- ! !
- Object subclass: #Random
- instanceVariableNames: ''
- category: 'Kernel'!
- !Random methodsFor: 'accessing'!
- next
- <return Math.random()>
- !
- next: anInteger
- ^(1 to: anInteger) collect: [:each | self next]
- ! !
- Object subclass: #Point
- instanceVariableNames: 'x y'
- category: 'Kernel'!
- !Point methodsFor: 'accessing'!
- x
- ^x
- !
- y
- ^y
- !
- y: aNumber
- y := aNumber
- !
- x: aNumber
- x := aNumber
- ! !
- !Point methodsFor: 'arithmetic'!
- * aPoint
- ^Point x: self x * aPoint asPoint x y: self y * aPoint asPoint y
- !
- + aPoint
- ^Point x: self x + aPoint asPoint x y: self y + aPoint asPoint y
- !
- - aPoint
- ^Point x: self x - aPoint asPoint x y: self y - aPoint asPoint y
- !
- / aPoint
- ^Point x: self x / aPoint asPoint x y: self y / aPoint asPoint y
- !
- = aPoint
- ^aPoint class = self class and: [
- (aPoint x = self x) & (aPoint y = self y)]
- ! !
- !Point methodsFor: 'converting'!
- asPoint
- ^self
- ! !
- !Point class methodsFor: 'instance creation'!
- x: aNumber y: anotherNumber
- ^self new
- x: aNumber;
- y: anotherNumber;
- yourself
- ! !
- Object subclass: #Message
- instanceVariableNames: 'selector arguments'
- category: 'Kernel'!
- !Message methodsFor: 'accessing'!
- selector
- ^selector
- !
- selector: aString
- selector := aString
- !
- arguments: anArray
- arguments := anArray
- !
- arguments
- ^arguments
- ! !
- !Message methodsFor: 'printing'!
- printString
- ^ String streamContents: [:aStream|
- aStream
- nextPutAll: super printString;
- nextPutAll: '(';
- nextPutAll: selector;
- nextPutAll: ')' ]
- ! !
- !Message class methodsFor: 'instance creation'!
- selector: aString arguments: anArray
- ^self new
- selector: aString;
- arguments: anArray;
- yourself
- ! !
- Error subclass: #MessageNotUnderstood
- instanceVariableNames: 'message receiver'
- category: 'Kernel'!
- !MessageNotUnderstood methodsFor: 'accessing'!
- message
- ^message
- !
- message: aMessage
- message := aMessage
- !
- receiver
- ^receiver
- !
- receiver: anObject
- receiver := anObject
- !
- messageText
- ^self receiver asString, ' does not understand #', self message selector
- ! !
- Object subclass: #ErrorHandler
- instanceVariableNames: ''
- category: 'Kernel'!
- !ErrorHandler methodsFor: 'error handling'!
- handleError: anError
- anError context ifNotNil: [self logErrorContext: anError context].
- self logError: anError
- ! !
- !ErrorHandler methodsFor: 'private'!
- logContext: aContext
- aContext home ifNotNil: [
- self logContext: aContext home].
- self log: aContext receiver asString, '>>', aContext selector
- !
- logErrorContext: aContext
- aContext ifNotNil: [
- aContext home ifNotNil: [
- self logContext: aContext home]]
- !
- logError: anError
- self log: anError messageText
- !
- log: aString
- console log: aString
- ! !
- ErrorHandler class instanceVariableNames: 'current'!
- !ErrorHandler class methodsFor: 'accessing'!
- current
- ^current ifNil: [current := self new]
- !
- setCurrent: anHandler
- current := anHandler
- ! !
- !ErrorHandler class methodsFor: 'initialization'!
- initialize
- self register
- !
- register
- ErrorHandler setCurrent: self new
- ! !
- Object subclass: #JSObjectProxy
- instanceVariableNames: 'jsObject'
- category: 'Kernel'!
- !JSObjectProxy methodsFor: 'accessing'!
- jsObject: aJSObject
- jsObject := aJSObject
- !
- jsObject
- ^jsObject
- !
- at: aString
- <return self['@jsObject'][aString]>
- !
- at: aString put: anObject
- <self['@jsObject'][aString] = anObject>
- ! !
- !JSObjectProxy methodsFor: 'proxy'!
- printString
- ^self jsObject toString
- !
- inspectOn: anInspector
- | variables |
- variables := Dictionary new.
- variables at: '#self' put: self jsObject.
- anInspector setLabel: self printString.
- <for(var i in self['@jsObject']) {
- variables._at_put_(i, self['@jsObject'][i]);
- }>.
- anInspector setVariables: variables
- !
- doesNotUnderstand: aMessage
- | obj selector jsSelector arguments |
- obj := self jsObject.
- selector := aMessage selector.
- jsSelector := selector asJavaScriptSelector.
- arguments := aMessage arguments.
- <if(obj[jsSelector] !!= undefined) {return smalltalk.send(obj, jsSelector, arguments)}>.
- super doesNotUnderstand: aMessage
- ! !
- !JSObjectProxy class methodsFor: 'instance creation'!
- on: aJSObject
- ^self new
- jsObject: aJSObject;
- yourself
- ! !
- Collection subclass: #Set
- instanceVariableNames: 'elements'
- category: 'Kernel'!
- !Set methodsFor: 'accessing'!
- size
- ^elements size
- ! !
- !Set methodsFor: 'adding/removing'!
- add: anObject
- <
- var found;
- for(var i in self['@elements']) {
- if(anObject == self['@elements'][i]) {
- found = true;
- break;
- }
- }
- if(!!found) {self['@elements'].push(anObject)}
- >
- !
- remove: anObject
- elements remove: anObject
- ! !
- !Set methodsFor: 'comparing'!
- = aCollection
- ^self class = aCollection class and: [
- elements = aCollection asArray]
- ! !
- !Set methodsFor: 'converting'!
- asArray
- ^elements copy
- ! !
- !Set methodsFor: 'enumerating'!
- detect: aBlock ifNone: anotherBlock
- ^elements detect: aBlock ifNone: anotherBlock
- !
- do: aBlock
- elements do: aBlock
- ! !
- !Set methodsFor: 'initialization'!
- initialize
- super initialize.
- elements := #()
- ! !
- !Set methodsFor: 'testing'!
- includes: anObject
- ^elements includes: anObject
- ! !
- Object subclass: #Transcript
- instanceVariableNames: 'textarea'
- category: 'Kernel'!
- Transcript class instanceVariableNames: 'current'!
- !Transcript class methodsFor: 'instance creation'!
- open
- self current open
- !
- new
- self shouldNotImplement
- !
- current
- ^current
- !
- register: aTranscript
- current := aTranscript
- ! !
- !Transcript class methodsFor: 'printing'!
- show: anObject
- self current show: anObject
- !
- cr
- self current show: String cr
- !
- clear
- self current clear
- ! !
- Object subclass: #ConsoleTranscript
- instanceVariableNames: 'textarea'
- category: 'Kernel'!
- !ConsoleTranscript methodsFor: 'actions'!
- open
- ! !
- !ConsoleTranscript methodsFor: 'printing'!
- clear
- "no op"
- !
- cr
- "no op"
- !
- show: anObject
- <console.log(String(anObject._asString()))>
- ! !
- !ConsoleTranscript class methodsFor: 'initialization'!
- initialize
- Transcript register: self new
- ! !
|