123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811 |
- define(["amber/boot", "amber_core/Compiler-AST", "amber_core/Compiler-Core", "amber_core/Kernel-Objects"], function($boot){"use strict";
- if(!$boot.nilAsReceiver)$boot.nilAsReceiver=$boot.nil;
- var $core=$boot.api,nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
- if(!$boot.nilAsClass)$boot.nilAsClass=$boot.dnu;
- $core.addPackage('Compiler-Semantic');
- $core.packages["Compiler-Semantic"].innerEval = function (expr) { return eval(expr); };
- $core.packages["Compiler-Semantic"].transport = {"type":"amd","amdNamespace":"amber_core"};
- $core.addClass('LexicalScope', $globals.Object, ['node', 'instruction', 'temps', 'args', 'outerScope', 'blockIndex'], 'Compiler-Semantic');
- $globals.LexicalScope.comment="I represent a lexical scope where variable names are associated with ScopeVars\x0aInstances are used for block scopes. Method scopes are instances of MethodLexicalScope.\x0a\x0aI am attached to a ScopeVar and method/block nodes.\x0aEach context (method/closure) get a fresh scope that inherits from its outer scope.";
- $core.addMethod(
- $core.method({
- selector: "addArg:",
- protocol: 'adding',
- fn: function (aString){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1;
- $1=self._args();
- $ctx1.sendIdx["args"]=1;
- $recv($1)._at_put_(aString,$recv($globals.ArgVar)._on_(aString));
- $recv($recv(self._args())._at_(aString))._scope_(self);
- return self;
- }, function($ctx1) {$ctx1.fill(self,"addArg:",{aString:aString},$globals.LexicalScope)});
- },
- args: ["aString"],
- source: "addArg: aString\x0a\x09self args at: aString put: (ArgVar on: aString).\x0a\x09(self args at: aString) scope: self",
- referencedClasses: ["ArgVar"],
- messageSends: ["at:put:", "args", "on:", "scope:", "at:"]
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "addTemp:",
- protocol: 'adding',
- fn: function (aString){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1;
- $1=self._temps();
- $ctx1.sendIdx["temps"]=1;
- $recv($1)._at_put_(aString,$recv($globals.TempVar)._on_(aString));
- $recv($recv(self._temps())._at_(aString))._scope_(self);
- return self;
- }, function($ctx1) {$ctx1.fill(self,"addTemp:",{aString:aString},$globals.LexicalScope)});
- },
- args: ["aString"],
- source: "addTemp: aString\x0a\x09self temps at: aString put: (TempVar on: aString).\x0a\x09(self temps at: aString) scope: self",
- referencedClasses: ["TempVar"],
- messageSends: ["at:put:", "temps", "on:", "scope:", "at:"]
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "alias",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- return "$ctx".__comma($recv(self._scopeLevel())._asString());
- }, function($ctx1) {$ctx1.fill(self,"alias",{},$globals.LexicalScope)});
- },
- args: [],
- source: "alias\x0a\x09^ '$ctx', self scopeLevel asString",
- referencedClasses: [],
- messageSends: [",", "asString", "scopeLevel"]
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "allVariableNames",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1;
- $1=$recv(self._args())._keys();
- $ctx1.sendIdx["keys"]=1;
- return $recv($1).__comma($recv(self._temps())._keys());
- }, function($ctx1) {$ctx1.fill(self,"allVariableNames",{},$globals.LexicalScope)});
- },
- args: [],
- source: "allVariableNames\x0a\x09^ self args keys, self temps keys",
- referencedClasses: [],
- messageSends: [",", "keys", "args", "temps"]
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "args",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$receiver;
- $1=self["@args"];
- if(($receiver = $1) == null || $receiver.isNil){
- self["@args"]=$recv($globals.Dictionary)._new();
- return self["@args"];
- } else {
- return $1;
- };
- }, function($ctx1) {$ctx1.fill(self,"args",{},$globals.LexicalScope)});
- },
- args: [],
- source: "args\x0a\x09^ args ifNil: [ args := Dictionary new ]",
- referencedClasses: ["Dictionary"],
- messageSends: ["ifNil:", "new"]
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "bindingFor:",
- protocol: 'accessing',
- fn: function (aStringOrNode){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $2,$3,$4,$5,$1;
- $2=self._pseudoVars();
- $3=$recv(aStringOrNode)._value();
- $ctx1.sendIdx["value"]=1;
- $1=$recv($2)._at_ifAbsent_($3,(function(){
- return $core.withContext(function($ctx2) {
- $4=self._args();
- $5=$recv(aStringOrNode)._value();
- $ctx2.sendIdx["value"]=2;
- return $recv($4)._at_ifAbsent_($5,(function(){
- return $core.withContext(function($ctx3) {
- return $recv(self._temps())._at_ifAbsent_($recv(aStringOrNode)._value(),(function(){
- return nil;
- }));
- }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)});
- }));
- $ctx2.sendIdx["at:ifAbsent:"]=2;
- }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
- }));
- $ctx1.sendIdx["at:ifAbsent:"]=1;
- return $1;
- }, function($ctx1) {$ctx1.fill(self,"bindingFor:",{aStringOrNode:aStringOrNode},$globals.LexicalScope)});
- },
- args: ["aStringOrNode"],
- source: "bindingFor: aStringOrNode\x0a\x09^ self pseudoVars at: aStringOrNode value ifAbsent: [\x0a\x09\x09self args at: aStringOrNode value ifAbsent: [\x0a\x09\x09\x09self temps at: aStringOrNode value ifAbsent: [ nil ]]]",
- referencedClasses: [],
- messageSends: ["at:ifAbsent:", "pseudoVars", "value", "args", "temps"]
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "blockIndex",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$receiver;
- $1=self["@blockIndex"];
- if(($receiver = $1) == null || $receiver.isNil){
- return (0);
- } else {
- return $1;
- };
- }, function($ctx1) {$ctx1.fill(self,"blockIndex",{},$globals.LexicalScope)});
- },
- args: [],
- source: "blockIndex\x0a\x09^ blockIndex ifNil: [ 0 ]",
- referencedClasses: [],
- messageSends: ["ifNil:"]
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "blockIndex:",
- protocol: 'accessing',
- fn: function (anInteger){
- var self=this;
- self["@blockIndex"]=anInteger;
- return self;
- },
- args: ["anInteger"],
- source: "blockIndex: anInteger \x0a\x09blockIndex := anInteger",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "canInlineNonLocalReturns",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- return $recv(self._isInlined())._and_((function(){
- return $core.withContext(function($ctx2) {
- return $recv(self._outerScope())._canInlineNonLocalReturns();
- }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
- }));
- }, function($ctx1) {$ctx1.fill(self,"canInlineNonLocalReturns",{},$globals.LexicalScope)});
- },
- args: [],
- source: "canInlineNonLocalReturns\x0a\x09^ self isInlined and: [ self outerScope canInlineNonLocalReturns ]",
- referencedClasses: [],
- messageSends: ["and:", "isInlined", "canInlineNonLocalReturns", "outerScope"]
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "instruction",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return self["@instruction"];
- },
- args: [],
- source: "instruction\x0a\x09^ instruction",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "instruction:",
- protocol: 'accessing',
- fn: function (anIRInstruction){
- var self=this;
- self["@instruction"]=anIRInstruction;
- return self;
- },
- args: ["anIRInstruction"],
- source: "instruction: anIRInstruction\x0a\x09instruction := anIRInstruction",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "isBlockScope",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- return $recv(self._isMethodScope())._not();
- }, function($ctx1) {$ctx1.fill(self,"isBlockScope",{},$globals.LexicalScope)});
- },
- args: [],
- source: "isBlockScope\x0a\x09^ self isMethodScope not",
- referencedClasses: [],
- messageSends: ["not", "isMethodScope"]
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "isInlined",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $2,$1;
- $2=self._instruction();
- $ctx1.sendIdx["instruction"]=1;
- $1=$recv($2)._notNil();
- return $recv($1)._and_((function(){
- return $core.withContext(function($ctx2) {
- return $recv(self._instruction())._isInlined();
- }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
- }));
- }, function($ctx1) {$ctx1.fill(self,"isInlined",{},$globals.LexicalScope)});
- },
- args: [],
- source: "isInlined\x0a\x09^ self instruction notNil and: [\x0a\x09\x09self instruction isInlined ]",
- referencedClasses: [],
- messageSends: ["and:", "notNil", "instruction", "isInlined"]
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "isMethodScope",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return false;
- },
- args: [],
- source: "isMethodScope\x0a\x09^ false",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "lookupVariable:",
- protocol: 'accessing',
- fn: function (aNode){
- var self=this;
- var lookup;
- return $core.withContext(function($ctx1) {
- var $1,$2,$receiver;
- lookup=self._bindingFor_(aNode);
- $1=lookup;
- if(($receiver = $1) == null || $receiver.isNil){
- $2=self._outerScope();
- $ctx1.sendIdx["outerScope"]=1;
- if(($receiver = $2) == null || $receiver.isNil){
- lookup=$2;
- } else {
- lookup=$recv(self._outerScope())._lookupVariable_(aNode);
- };
- lookup;
- } else {
- $1;
- };
- return lookup;
- }, function($ctx1) {$ctx1.fill(self,"lookupVariable:",{aNode:aNode,lookup:lookup},$globals.LexicalScope)});
- },
- args: ["aNode"],
- source: "lookupVariable: aNode\x0a\x09| lookup |\x0a\x09lookup := (self bindingFor: aNode).\x0a\x09lookup ifNil: [\x0a\x09\x09lookup := self outerScope ifNotNil: [\x0a\x09\x09\x09(self outerScope lookupVariable: aNode) ]].\x0a\x09^ lookup",
- referencedClasses: [],
- messageSends: ["bindingFor:", "ifNil:", "ifNotNil:", "outerScope", "lookupVariable:"]
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "methodScope",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$receiver;
- $1=self._outerScope();
- $ctx1.sendIdx["outerScope"]=1;
- if(($receiver = $1) == null || $receiver.isNil){
- return $1;
- } else {
- return $recv(self._outerScope())._methodScope();
- };
- }, function($ctx1) {$ctx1.fill(self,"methodScope",{},$globals.LexicalScope)});
- },
- args: [],
- source: "methodScope\x0a\x09^ self outerScope ifNotNil: [\x0a\x09\x09self outerScope methodScope ]",
- referencedClasses: [],
- messageSends: ["ifNotNil:", "outerScope", "methodScope"]
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "node",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return self["@node"];
- },
- args: [],
- source: "node\x0a\x09\x22Answer the node in which I am defined\x22\x0a\x09\x0a\x09^ node",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "node:",
- protocol: 'accessing',
- fn: function (aNode){
- var self=this;
- self["@node"]=aNode;
- return self;
- },
- args: ["aNode"],
- source: "node: aNode\x0a\x09node := aNode",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "outerScope",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return self["@outerScope"];
- },
- args: [],
- source: "outerScope\x0a\x09^ outerScope",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "outerScope:",
- protocol: 'accessing',
- fn: function (aLexicalScope){
- var self=this;
- self["@outerScope"]=aLexicalScope;
- return self;
- },
- args: ["aLexicalScope"],
- source: "outerScope: aLexicalScope\x0a\x09outerScope := aLexicalScope",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "pseudoVars",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- return $recv(self._methodScope())._pseudoVars();
- }, function($ctx1) {$ctx1.fill(self,"pseudoVars",{},$globals.LexicalScope)});
- },
- args: [],
- source: "pseudoVars\x0a\x09^ self methodScope pseudoVars",
- referencedClasses: [],
- messageSends: ["pseudoVars", "methodScope"]
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "scopeLevel",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$2,$4,$3,$receiver;
- $1=self._outerScope();
- $ctx1.sendIdx["outerScope"]=1;
- if(($receiver = $1) == null || $receiver.isNil){
- return (1);
- } else {
- $1;
- };
- $2=self._isInlined();
- if($core.assert($2)){
- $4=self._outerScope();
- $ctx1.sendIdx["outerScope"]=2;
- $3=$recv($4)._scopeLevel();
- $ctx1.sendIdx["scopeLevel"]=1;
- return $3;
- };
- return $recv($recv(self._outerScope())._scopeLevel()).__plus((1));
- }, function($ctx1) {$ctx1.fill(self,"scopeLevel",{},$globals.LexicalScope)});
- },
- args: [],
- source: "scopeLevel\x0a\x09self outerScope ifNil: [ ^ 1 ].\x0a\x09self isInlined ifTrue: [ ^ self outerScope scopeLevel ].\x0a\x09\x0a\x09^ self outerScope scopeLevel + 1",
- referencedClasses: [],
- messageSends: ["ifNil:", "outerScope", "ifTrue:", "isInlined", "scopeLevel", "+"]
- }),
- $globals.LexicalScope);
- $core.addMethod(
- $core.method({
- selector: "temps",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$receiver;
- $1=self["@temps"];
- if(($receiver = $1) == null || $receiver.isNil){
- self["@temps"]=$recv($globals.Dictionary)._new();
- return self["@temps"];
- } else {
- return $1;
- };
- }, function($ctx1) {$ctx1.fill(self,"temps",{},$globals.LexicalScope)});
- },
- args: [],
- source: "temps\x0a\x09^ temps ifNil: [ temps := Dictionary new ]",
- referencedClasses: ["Dictionary"],
- messageSends: ["ifNil:", "new"]
- }),
- $globals.LexicalScope);
- $core.addClass('MethodLexicalScope', $globals.LexicalScope, ['iVars', 'pseudoVars', 'unknownVariables', 'localReturn', 'nonLocalReturns'], 'Compiler-Semantic');
- $globals.MethodLexicalScope.comment="I represent a method scope.";
- $core.addMethod(
- $core.method({
- selector: "addIVar:",
- protocol: 'adding',
- fn: function (aString){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1;
- $1=self._iVars();
- $ctx1.sendIdx["iVars"]=1;
- $recv($1)._at_put_(aString,$recv($globals.InstanceVar)._on_(aString));
- $recv($recv(self._iVars())._at_(aString))._scope_(self);
- return self;
- }, function($ctx1) {$ctx1.fill(self,"addIVar:",{aString:aString},$globals.MethodLexicalScope)});
- },
- args: ["aString"],
- source: "addIVar: aString\x0a\x09self iVars at: aString put: (InstanceVar on: aString).\x0a\x09(self iVars at: aString) scope: self",
- referencedClasses: ["InstanceVar"],
- messageSends: ["at:put:", "iVars", "on:", "scope:", "at:"]
- }),
- $globals.MethodLexicalScope);
- $core.addMethod(
- $core.method({
- selector: "addNonLocalReturn:",
- protocol: 'adding',
- fn: function (aScope){
- var self=this;
- return $core.withContext(function($ctx1) {
- $recv(self._nonLocalReturns())._add_(aScope);
- return self;
- }, function($ctx1) {$ctx1.fill(self,"addNonLocalReturn:",{aScope:aScope},$globals.MethodLexicalScope)});
- },
- args: ["aScope"],
- source: "addNonLocalReturn: aScope\x0a\x09self nonLocalReturns add: aScope",
- referencedClasses: [],
- messageSends: ["add:", "nonLocalReturns"]
- }),
- $globals.MethodLexicalScope);
- $core.addMethod(
- $core.method({
- selector: "allVariableNames",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1;
- $1=(
- $ctx1.supercall = true,
- ($globals.MethodLexicalScope.superclass||$boot.nilAsClass).fn.prototype._allVariableNames.apply($recv(self), []));
- $ctx1.supercall = false;
- return $recv($1).__comma($recv(self._iVars())._keys());
- }, function($ctx1) {$ctx1.fill(self,"allVariableNames",{},$globals.MethodLexicalScope)});
- },
- args: [],
- source: "allVariableNames\x0a\x09^ super allVariableNames, self iVars keys",
- referencedClasses: [],
- messageSends: [",", "allVariableNames", "keys", "iVars"]
- }),
- $globals.MethodLexicalScope);
- $core.addMethod(
- $core.method({
- selector: "bindingFor:",
- protocol: 'accessing',
- fn: function (aNode){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$receiver;
- $1=(
- $ctx1.supercall = true,
- ($globals.MethodLexicalScope.superclass||$boot.nilAsClass).fn.prototype._bindingFor_.apply($recv(self), [aNode]));
- $ctx1.supercall = false;
- if(($receiver = $1) == null || $receiver.isNil){
- return $recv(self._iVars())._at_ifAbsent_($recv(aNode)._value(),(function(){
- return nil;
- }));
- } else {
- return $1;
- };
- }, function($ctx1) {$ctx1.fill(self,"bindingFor:",{aNode:aNode},$globals.MethodLexicalScope)});
- },
- args: ["aNode"],
- source: "bindingFor: aNode\x0a\x09^ (super bindingFor: aNode) ifNil: [\x0a\x09\x09self iVars at: aNode value ifAbsent: [ nil ]]",
- referencedClasses: [],
- messageSends: ["ifNil:", "bindingFor:", "at:ifAbsent:", "iVars", "value"]
- }),
- $globals.MethodLexicalScope);
- $core.addMethod(
- $core.method({
- selector: "canInlineNonLocalReturns",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return true;
- },
- args: [],
- source: "canInlineNonLocalReturns\x0a\x09^ true",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.MethodLexicalScope);
- $core.addMethod(
- $core.method({
- selector: "hasLocalReturn",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- return self._localReturn();
- }, function($ctx1) {$ctx1.fill(self,"hasLocalReturn",{},$globals.MethodLexicalScope)});
- },
- args: [],
- source: "hasLocalReturn\x0a\x09^ self localReturn",
- referencedClasses: [],
- messageSends: ["localReturn"]
- }),
- $globals.MethodLexicalScope);
- $core.addMethod(
- $core.method({
- selector: "hasNonLocalReturn",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- return $recv(self._nonLocalReturns())._notEmpty();
- }, function($ctx1) {$ctx1.fill(self,"hasNonLocalReturn",{},$globals.MethodLexicalScope)});
- },
- args: [],
- source: "hasNonLocalReturn\x0a\x09^ self nonLocalReturns notEmpty",
- referencedClasses: [],
- messageSends: ["notEmpty", "nonLocalReturns"]
- }),
- $globals.MethodLexicalScope);
- $core.addMethod(
- $core.method({
- selector: "iVars",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$receiver;
- $1=self["@iVars"];
- if(($receiver = $1) == null || $receiver.isNil){
- self["@iVars"]=$recv($globals.Dictionary)._new();
- return self["@iVars"];
- } else {
- return $1;
- };
- }, function($ctx1) {$ctx1.fill(self,"iVars",{},$globals.MethodLexicalScope)});
- },
- args: [],
- source: "iVars\x0a\x09^ iVars ifNil: [ iVars := Dictionary new ]",
- referencedClasses: ["Dictionary"],
- messageSends: ["ifNil:", "new"]
- }),
- $globals.MethodLexicalScope);
- $core.addMethod(
- $core.method({
- selector: "isMethodScope",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return true;
- },
- args: [],
- source: "isMethodScope\x0a\x09^ true",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.MethodLexicalScope);
- $core.addMethod(
- $core.method({
- selector: "localReturn",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$receiver;
- $1=self["@localReturn"];
- if(($receiver = $1) == null || $receiver.isNil){
- return false;
- } else {
- return $1;
- };
- }, function($ctx1) {$ctx1.fill(self,"localReturn",{},$globals.MethodLexicalScope)});
- },
- args: [],
- source: "localReturn\x0a\x09^ localReturn ifNil: [ false ]",
- referencedClasses: [],
- messageSends: ["ifNil:"]
- }),
- $globals.MethodLexicalScope);
- $core.addMethod(
- $core.method({
- selector: "localReturn:",
- protocol: 'accessing',
- fn: function (aBoolean){
- var self=this;
- self["@localReturn"]=aBoolean;
- return self;
- },
- args: ["aBoolean"],
- source: "localReturn: aBoolean\x0a\x09localReturn := aBoolean",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.MethodLexicalScope);
- $core.addMethod(
- $core.method({
- selector: "methodScope",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return self;
- },
- args: [],
- source: "methodScope\x0a\x09^ self",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.MethodLexicalScope);
- $core.addMethod(
- $core.method({
- selector: "nonLocalReturns",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$receiver;
- $1=self["@nonLocalReturns"];
- if(($receiver = $1) == null || $receiver.isNil){
- self["@nonLocalReturns"]=$recv($globals.OrderedCollection)._new();
- return self["@nonLocalReturns"];
- } else {
- return $1;
- };
- }, function($ctx1) {$ctx1.fill(self,"nonLocalReturns",{},$globals.MethodLexicalScope)});
- },
- args: [],
- source: "nonLocalReturns\x0a\x09^ nonLocalReturns ifNil: [ nonLocalReturns := OrderedCollection new ]",
- referencedClasses: ["OrderedCollection"],
- messageSends: ["ifNil:", "new"]
- }),
- $globals.MethodLexicalScope);
- $core.addMethod(
- $core.method({
- selector: "pseudoVars",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$2,$4,$3,$receiver;
- $1=self["@pseudoVars"];
- if(($receiver = $1) == null || $receiver.isNil){
- self["@pseudoVars"]=$recv($globals.Dictionary)._new();
- self["@pseudoVars"];
- $recv($recv($globals.Smalltalk)._pseudoVariableNames())._do_((function(each){
- return $core.withContext(function($ctx2) {
- $2=self["@pseudoVars"];
- $4=$recv($globals.PseudoVar)._on_(each);
- $recv($4)._scope_(self._methodScope());
- $3=$recv($4)._yourself();
- return $recv($2)._at_put_(each,$3);
- }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)});
- }));
- } else {
- $1;
- };
- return self["@pseudoVars"];
- }, function($ctx1) {$ctx1.fill(self,"pseudoVars",{},$globals.MethodLexicalScope)});
- },
- args: [],
- source: "pseudoVars\x0a\x09pseudoVars ifNil: [\x0a\x09\x09pseudoVars := Dictionary new.\x0a\x09\x09Smalltalk pseudoVariableNames do: [ :each |\x0a\x09\x09\x09pseudoVars at: each put: ((PseudoVar on: each)\x0a\x09\x09\x09\x09scope: self methodScope;\x0a\x09\x09\x09\x09yourself) ]].\x0a\x09^ pseudoVars",
- referencedClasses: ["Dictionary", "Smalltalk", "PseudoVar"],
- messageSends: ["ifNil:", "new", "do:", "pseudoVariableNames", "at:put:", "scope:", "on:", "methodScope", "yourself"]
- }),
- $globals.MethodLexicalScope);
- $core.addMethod(
- $core.method({
- selector: "removeNonLocalReturn:",
- protocol: 'adding',
- fn: function (aScope){
- var self=this;
- return $core.withContext(function($ctx1) {
- $recv(self._nonLocalReturns())._remove_ifAbsent_(aScope,(function(){
- }));
- return self;
- }, function($ctx1) {$ctx1.fill(self,"removeNonLocalReturn:",{aScope:aScope},$globals.MethodLexicalScope)});
- },
- args: ["aScope"],
- source: "removeNonLocalReturn: aScope\x0a\x09self nonLocalReturns remove: aScope ifAbsent: []",
- referencedClasses: [],
- messageSends: ["remove:ifAbsent:", "nonLocalReturns"]
- }),
- $globals.MethodLexicalScope);
- $core.addMethod(
- $core.method({
- selector: "unknownVariables",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$receiver;
- $1=self["@unknownVariables"];
- if(($receiver = $1) == null || $receiver.isNil){
- self["@unknownVariables"]=$recv($globals.OrderedCollection)._new();
- return self["@unknownVariables"];
- } else {
- return $1;
- };
- }, function($ctx1) {$ctx1.fill(self,"unknownVariables",{},$globals.MethodLexicalScope)});
- },
- args: [],
- source: "unknownVariables\x0a\x09^ unknownVariables ifNil: [ unknownVariables := OrderedCollection new ]",
- referencedClasses: ["OrderedCollection"],
- messageSends: ["ifNil:", "new"]
- }),
- $globals.MethodLexicalScope);
- $core.addClass('ScopeVar', $globals.Object, ['scope', 'name'], 'Compiler-Semantic');
- $globals.ScopeVar.comment="I am an entry in a LexicalScope that gets associated with variable nodes of the same name.\x0aThere are 4 different subclasses of vars: temp vars, local vars, args, and unknown/global vars.";
- $core.addMethod(
- $core.method({
- selector: "alias",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- return $recv(self._name())._asVariableName();
- }, function($ctx1) {$ctx1.fill(self,"alias",{},$globals.ScopeVar)});
- },
- args: [],
- source: "alias\x0a\x09^ self name asVariableName",
- referencedClasses: [],
- messageSends: ["asVariableName", "name"]
- }),
- $globals.ScopeVar);
- $core.addMethod(
- $core.method({
- selector: "isArgVar",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return false;
- },
- args: [],
- source: "isArgVar\x0a\x09^ false",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ScopeVar);
- $core.addMethod(
- $core.method({
- selector: "isClassRefVar",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return false;
- },
- args: [],
- source: "isClassRefVar\x0a\x09^ false",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ScopeVar);
- $core.addMethod(
- $core.method({
- selector: "isImmutable",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return false;
- },
- args: [],
- source: "isImmutable\x0a\x09^ false",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ScopeVar);
- $core.addMethod(
- $core.method({
- selector: "isInstanceVar",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return false;
- },
- args: [],
- source: "isInstanceVar\x0a\x09^ false",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ScopeVar);
- $core.addMethod(
- $core.method({
- selector: "isPseudoVar",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return false;
- },
- args: [],
- source: "isPseudoVar\x0a\x09^ false",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ScopeVar);
- $core.addMethod(
- $core.method({
- selector: "isTempVar",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return false;
- },
- args: [],
- source: "isTempVar\x0a\x09^ false",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ScopeVar);
- $core.addMethod(
- $core.method({
- selector: "isUnknownVar",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return false;
- },
- args: [],
- source: "isUnknownVar\x0a\x09^ false",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ScopeVar);
- $core.addMethod(
- $core.method({
- selector: "name",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return self["@name"];
- },
- args: [],
- source: "name\x0a\x09^ name",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ScopeVar);
- $core.addMethod(
- $core.method({
- selector: "name:",
- protocol: 'accessing',
- fn: function (aString){
- var self=this;
- self["@name"]=aString;
- return self;
- },
- args: ["aString"],
- source: "name: aString\x0a\x09name := aString",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ScopeVar);
- $core.addMethod(
- $core.method({
- selector: "scope",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return self["@scope"];
- },
- args: [],
- source: "scope\x0a\x09^ scope",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ScopeVar);
- $core.addMethod(
- $core.method({
- selector: "scope:",
- protocol: 'accessing',
- fn: function (aScope){
- var self=this;
- self["@scope"]=aScope;
- return self;
- },
- args: ["aScope"],
- source: "scope: aScope\x0a\x09scope := aScope",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ScopeVar);
- $core.addMethod(
- $core.method({
- selector: "validateAssignment",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$2;
- $1=$recv(self._isArgVar())._or_((function(){
- return $core.withContext(function($ctx2) {
- return self._isPseudoVar();
- }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
- }));
- if($core.assert($1)){
- $2=$recv($globals.InvalidAssignmentError)._new();
- $recv($2)._variableName_(self._name());
- $recv($2)._signal();
- };
- return self;
- }, function($ctx1) {$ctx1.fill(self,"validateAssignment",{},$globals.ScopeVar)});
- },
- args: [],
- source: "validateAssignment\x0a\x09(self isArgVar or: [ self isPseudoVar ]) ifTrue: [\x0a\x09\x09InvalidAssignmentError new\x0a\x09\x09\x09variableName: self name;\x0a\x09\x09\x09signal]",
- referencedClasses: ["InvalidAssignmentError"],
- messageSends: ["ifTrue:", "or:", "isArgVar", "isPseudoVar", "variableName:", "new", "name", "signal"]
- }),
- $globals.ScopeVar);
- $core.addMethod(
- $core.method({
- selector: "on:",
- protocol: 'instance creation',
- fn: function (aString){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1;
- $1=self._new();
- $recv($1)._name_(aString);
- return $recv($1)._yourself();
- }, function($ctx1) {$ctx1.fill(self,"on:",{aString:aString},$globals.ScopeVar.klass)});
- },
- args: ["aString"],
- source: "on: aString\x0a\x09^ self new\x0a\x09\x09name: aString;\x0a\x09\x09yourself",
- referencedClasses: [],
- messageSends: ["name:", "new", "yourself"]
- }),
- $globals.ScopeVar.klass);
- $core.addClass('AliasVar', $globals.ScopeVar, ['node'], 'Compiler-Semantic');
- $globals.AliasVar.comment="I am an internally defined variable by the compiler";
- $core.addMethod(
- $core.method({
- selector: "isImmutable",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return true;
- },
- args: [],
- source: "isImmutable\x0a\x09^ true",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.AliasVar);
- $core.addMethod(
- $core.method({
- selector: "node",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return self["@node"];
- },
- args: [],
- source: "node\x0a\x09^ node",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.AliasVar);
- $core.addMethod(
- $core.method({
- selector: "node:",
- protocol: 'accessing',
- fn: function (aNode){
- var self=this;
- self["@node"]=aNode;
- return self;
- },
- args: ["aNode"],
- source: "node: aNode\x0a\x09node := aNode",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.AliasVar);
- $core.addClass('ArgVar', $globals.ScopeVar, [], 'Compiler-Semantic');
- $globals.ArgVar.comment="I am an argument of a method or block.";
- $core.addMethod(
- $core.method({
- selector: "isArgVar",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return true;
- },
- args: [],
- source: "isArgVar\x0a\x09^ true",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ArgVar);
- $core.addMethod(
- $core.method({
- selector: "isImmutable",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return true;
- },
- args: [],
- source: "isImmutable\x0a\x09^ true",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ArgVar);
- $core.addClass('ClassRefVar', $globals.ScopeVar, [], 'Compiler-Semantic');
- $globals.ClassRefVar.comment="I am an class reference variable";
- $core.addMethod(
- $core.method({
- selector: "alias",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- return "$globals.".__comma(self._name());
- }, function($ctx1) {$ctx1.fill(self,"alias",{},$globals.ClassRefVar)});
- },
- args: [],
- source: "alias\x0a\x09\x22Fixes issue #190.\x0a\x09A function is created in the method definition, answering the class or nil.\x0a\x09See JSStream >> #nextPutClassRefFunction:\x22\x0a\x09\x0a\x09^ '$globals.', self name",
- referencedClasses: [],
- messageSends: [",", "name"]
- }),
- $globals.ClassRefVar);
- $core.addMethod(
- $core.method({
- selector: "isClassRefVar",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return true;
- },
- args: [],
- source: "isClassRefVar\x0a\x09^ true",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ClassRefVar);
- $core.addMethod(
- $core.method({
- selector: "isImmutable",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return true;
- },
- args: [],
- source: "isImmutable\x0a\x09^ true",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ClassRefVar);
- $core.addClass('InstanceVar', $globals.ScopeVar, [], 'Compiler-Semantic');
- $globals.InstanceVar.comment="I am an instance variable of a method or block.";
- $core.addMethod(
- $core.method({
- selector: "alias",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1;
- $1=$recv("self[\x22@".__comma(self._name())).__comma("\x22]");
- $ctx1.sendIdx[","]=1;
- return $1;
- }, function($ctx1) {$ctx1.fill(self,"alias",{},$globals.InstanceVar)});
- },
- args: [],
- source: "alias\x0a\x09^ 'self[\x22@', self name, '\x22]'",
- referencedClasses: [],
- messageSends: [",", "name"]
- }),
- $globals.InstanceVar);
- $core.addMethod(
- $core.method({
- selector: "isInstanceVar",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return true;
- },
- args: [],
- source: "isInstanceVar\x0a\x09^ true",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.InstanceVar);
- $core.addClass('PseudoVar', $globals.ScopeVar, [], 'Compiler-Semantic');
- $globals.PseudoVar.comment="I am an pseudo variable.\x0a\x0aThe five Smalltalk pseudo variables are: 'self', 'super', 'nil', 'true' and 'false'";
- $core.addMethod(
- $core.method({
- selector: "alias",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- return self._name();
- }, function($ctx1) {$ctx1.fill(self,"alias",{},$globals.PseudoVar)});
- },
- args: [],
- source: "alias\x0a\x09^ self name",
- referencedClasses: [],
- messageSends: ["name"]
- }),
- $globals.PseudoVar);
- $core.addMethod(
- $core.method({
- selector: "isImmutable",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return true;
- },
- args: [],
- source: "isImmutable\x0a\x09^ true",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.PseudoVar);
- $core.addMethod(
- $core.method({
- selector: "isPseudoVar",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return true;
- },
- args: [],
- source: "isPseudoVar\x0a\x09^ true",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.PseudoVar);
- $core.addClass('TempVar', $globals.ScopeVar, [], 'Compiler-Semantic');
- $globals.TempVar.comment="I am an temporary variable of a method or block.";
- $core.addMethod(
- $core.method({
- selector: "isTempVar",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return true;
- },
- args: [],
- source: "isTempVar\x0a\x09^ true",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.TempVar);
- $core.addClass('UnknownVar', $globals.ScopeVar, [], 'Compiler-Semantic');
- $globals.UnknownVar.comment="I am an unknown variable. Amber uses unknown variables as JavaScript globals";
- $core.addMethod(
- $core.method({
- selector: "isUnknownVar",
- protocol: 'testing',
- fn: function (){
- var self=this;
- return true;
- },
- args: [],
- source: "isUnknownVar\x0a\x09^ true",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.UnknownVar);
- $core.addClass('SemanticAnalyzer', $globals.NodeVisitor, ['currentScope', 'blockIndex', 'thePackage', 'theClass', 'classReferences', 'messageSends'], 'Compiler-Semantic');
- $globals.SemanticAnalyzer.comment="I semantically analyze the abstract syntax tree and annotate it with informations such as non local returns and variable scopes.";
- $core.addMethod(
- $core.method({
- selector: "classReferences",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$receiver;
- $1=self["@classReferences"];
- if(($receiver = $1) == null || $receiver.isNil){
- self["@classReferences"]=$recv($globals.Set)._new();
- return self["@classReferences"];
- } else {
- return $1;
- };
- }, function($ctx1) {$ctx1.fill(self,"classReferences",{},$globals.SemanticAnalyzer)});
- },
- args: [],
- source: "classReferences\x0a\x09^ classReferences ifNil: [ classReferences := Set new ]",
- referencedClasses: ["Set"],
- messageSends: ["ifNil:", "new"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "errorShadowingVariable:",
- protocol: 'error handling',
- fn: function (aString){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1;
- $1=$recv($globals.ShadowingVariableError)._new();
- $recv($1)._variableName_(aString);
- $recv($1)._signal();
- return self;
- }, function($ctx1) {$ctx1.fill(self,"errorShadowingVariable:",{aString:aString},$globals.SemanticAnalyzer)});
- },
- args: ["aString"],
- source: "errorShadowingVariable: aString\x0a\x09ShadowingVariableError new\x0a\x09\x09variableName: aString;\x0a\x09\x09signal",
- referencedClasses: ["ShadowingVariableError"],
- messageSends: ["variableName:", "new", "signal"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "errorUnknownVariable:",
- protocol: 'error handling',
- fn: function (aNode){
- var self=this;
- var identifier;
- return $core.withContext(function($ctx1) {
- var $1,$2,$3;
- identifier=$recv(aNode)._value();
- $ctx1.sendIdx["value"]=1;
- $1=$recv($recv($recv($recv($globals.Smalltalk)._globalJsVariables())._includes_(identifier))._not())._and_((function(){
- return $core.withContext(function($ctx2) {
- return self._isVariableUndefined_inPackage_(identifier,self._thePackage());
- }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
- }));
- if($core.assert($1)){
- $2=$recv($globals.UnknownVariableError)._new();
- $3=$recv(aNode)._value();
- $ctx1.sendIdx["value"]=2;
- $recv($2)._variableName_($3);
- $recv($2)._signal();
- } else {
- $recv($recv($recv(self["@currentScope"])._methodScope())._unknownVariables())._add_($recv(aNode)._value());
- };
- return self;
- }, function($ctx1) {$ctx1.fill(self,"errorUnknownVariable:",{aNode:aNode,identifier:identifier},$globals.SemanticAnalyzer)});
- },
- args: ["aNode"],
- source: "errorUnknownVariable: aNode\x0a\x09\x22Throw an error if the variable is undeclared in the global JS scope (i.e. window).\x0a\x09We allow all variables listed by Smalltalk>>#globalJsVariables.\x0a\x09This list includes: `window`, `document`, `process` and `global`\x0a\x09for nodejs and browser environments.\x0a\x09\x0a\x09This is only to make sure compilation works on both browser-based and nodejs environments.\x0a\x09The ideal solution would be to use a pragma instead\x22\x0a\x0a\x09| identifier |\x0a\x09identifier := aNode value.\x0a\x09\x0a\x09((Smalltalk globalJsVariables includes: identifier) not\x0a\x09\x09and: [ self isVariableUndefined: identifier inPackage: self thePackage ])\x0a\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09UnknownVariableError new\x0a\x09\x09\x09\x09\x09variableName: aNode value;\x0a\x09\x09\x09\x09\x09signal ]\x0a\x09\x09\x09ifFalse: [\x0a\x09\x09\x09\x09currentScope methodScope unknownVariables add: aNode value ]",
- referencedClasses: ["Smalltalk", "UnknownVariableError"],
- messageSends: ["value", "ifTrue:ifFalse:", "and:", "not", "includes:", "globalJsVariables", "isVariableUndefined:inPackage:", "thePackage", "variableName:", "new", "signal", "add:", "unknownVariables", "methodScope"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "isVariableUndefined:inPackage:",
- protocol: 'testing',
- fn: function (aString,aPackage){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$2,$3,$receiver;
- if(($receiver = aPackage) == null || $receiver.isNil){
- aPackage;
- } else {
- var packageKnownVars;
- packageKnownVars=$recv($recv($recv(aPackage)._imports())._reject_("isString"))._collect_("key");
- packageKnownVars;
- $1=$recv(packageKnownVars)._includes_(aString);
- if($core.assert($1)){
- return false;
- };
- };
- $2=$recv($globals.Compiler)._new();
- $3=$recv("typeof ".__comma(aString)).__comma(" == \x22undefined\x22");
- $ctx1.sendIdx[","]=1;
- return $recv($2)._eval_($3);
- }, function($ctx1) {$ctx1.fill(self,"isVariableUndefined:inPackage:",{aString:aString,aPackage:aPackage},$globals.SemanticAnalyzer)});
- },
- args: ["aString", "aPackage"],
- source: "isVariableUndefined: aString inPackage: aPackage\x0a\x09aPackage ifNotNil: [\x0a\x09\x09| packageKnownVars |\x0a\x09\x09packageKnownVars := (aPackage imports\x0a\x09\x09\x09reject: #isString)\x0a\x09\x09\x09collect: #key.\x0a\x09\x09(packageKnownVars includes: aString) ifTrue: [ ^ false ]].\x0a\x09^ Compiler new\x0a\x09\x09eval: 'typeof ', aString, ' == \x22undefined\x22'",
- referencedClasses: ["Compiler"],
- messageSends: ["ifNotNil:", "collect:", "reject:", "imports", "ifTrue:", "includes:", "eval:", "new", ","]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "messageSends",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$receiver;
- $1=self["@messageSends"];
- if(($receiver = $1) == null || $receiver.isNil){
- self["@messageSends"]=$recv($globals.Dictionary)._new();
- return self["@messageSends"];
- } else {
- return $1;
- };
- }, function($ctx1) {$ctx1.fill(self,"messageSends",{},$globals.SemanticAnalyzer)});
- },
- args: [],
- source: "messageSends\x0a\x09^ messageSends ifNil: [ messageSends := Dictionary new ]",
- referencedClasses: ["Dictionary"],
- messageSends: ["ifNil:", "new"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "newBlockScope",
- protocol: 'factory',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- return self._newScopeOfClass_($globals.LexicalScope);
- }, function($ctx1) {$ctx1.fill(self,"newBlockScope",{},$globals.SemanticAnalyzer)});
- },
- args: [],
- source: "newBlockScope\x0a\x09^ self newScopeOfClass: LexicalScope",
- referencedClasses: ["LexicalScope"],
- messageSends: ["newScopeOfClass:"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "newMethodScope",
- protocol: 'factory',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- return self._newScopeOfClass_($globals.MethodLexicalScope);
- }, function($ctx1) {$ctx1.fill(self,"newMethodScope",{},$globals.SemanticAnalyzer)});
- },
- args: [],
- source: "newMethodScope\x0a\x09^ self newScopeOfClass: MethodLexicalScope",
- referencedClasses: ["MethodLexicalScope"],
- messageSends: ["newScopeOfClass:"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "newScopeOfClass:",
- protocol: 'factory',
- fn: function (aLexicalScopeClass){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1;
- $1=$recv(aLexicalScopeClass)._new();
- $recv($1)._outerScope_(self["@currentScope"]);
- return $recv($1)._yourself();
- }, function($ctx1) {$ctx1.fill(self,"newScopeOfClass:",{aLexicalScopeClass:aLexicalScopeClass},$globals.SemanticAnalyzer)});
- },
- args: ["aLexicalScopeClass"],
- source: "newScopeOfClass: aLexicalScopeClass\x0a\x09^ aLexicalScopeClass new\x0a\x09\x09outerScope: currentScope;\x0a\x09\x09yourself",
- referencedClasses: [],
- messageSends: ["outerScope:", "new", "yourself"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "nextBlockIndex",
- protocol: 'private',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$receiver;
- $1=self["@blockIndex"];
- if(($receiver = $1) == null || $receiver.isNil){
- self["@blockIndex"]=(0);
- self["@blockIndex"];
- } else {
- $1;
- };
- self["@blockIndex"]=$recv(self["@blockIndex"]).__plus((1));
- return self["@blockIndex"];
- }, function($ctx1) {$ctx1.fill(self,"nextBlockIndex",{},$globals.SemanticAnalyzer)});
- },
- args: [],
- source: "nextBlockIndex\x0a\x09blockIndex ifNil: [ blockIndex := 0 ].\x0a\x09\x0a\x09blockIndex := blockIndex + 1.\x0a\x09^ blockIndex",
- referencedClasses: [],
- messageSends: ["ifNil:", "+"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "popScope",
- protocol: 'scope',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$receiver;
- $1=self["@currentScope"];
- if(($receiver = $1) == null || $receiver.isNil){
- $1;
- } else {
- self["@currentScope"]=$recv(self["@currentScope"])._outerScope();
- self["@currentScope"];
- };
- return self;
- }, function($ctx1) {$ctx1.fill(self,"popScope",{},$globals.SemanticAnalyzer)});
- },
- args: [],
- source: "popScope\x0a\x09currentScope ifNotNil: [\x0a\x09\x09currentScope := currentScope outerScope ]",
- referencedClasses: [],
- messageSends: ["ifNotNil:", "outerScope"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "pushScope:",
- protocol: 'scope',
- fn: function (aScope){
- var self=this;
- return $core.withContext(function($ctx1) {
- $recv(aScope)._outerScope_(self["@currentScope"]);
- self["@currentScope"]=aScope;
- return self;
- }, function($ctx1) {$ctx1.fill(self,"pushScope:",{aScope:aScope},$globals.SemanticAnalyzer)});
- },
- args: ["aScope"],
- source: "pushScope: aScope\x0a\x09aScope outerScope: currentScope.\x0a\x09currentScope := aScope",
- referencedClasses: [],
- messageSends: ["outerScope:"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "theClass",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return self["@theClass"];
- },
- args: [],
- source: "theClass\x0a\x09^ theClass",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "theClass:",
- protocol: 'accessing',
- fn: function (aClass){
- var self=this;
- self["@theClass"]=aClass;
- return self;
- },
- args: ["aClass"],
- source: "theClass: aClass\x0a\x09theClass := aClass",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "thePackage",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return self["@thePackage"];
- },
- args: [],
- source: "thePackage\x0a\x09^ thePackage",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "thePackage:",
- protocol: 'accessing',
- fn: function (aPackage){
- var self=this;
- self["@thePackage"]=aPackage;
- return self;
- },
- args: ["aPackage"],
- source: "thePackage: aPackage\x0a\x09thePackage := aPackage",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "validateVariableScope:",
- protocol: 'scope',
- fn: function (aString){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1,$receiver;
- $1=$recv(self["@currentScope"])._lookupVariable_(aString);
- if(($receiver = $1) == null || $receiver.isNil){
- $1;
- } else {
- self._errorShadowingVariable_(aString);
- };
- return self;
- }, function($ctx1) {$ctx1.fill(self,"validateVariableScope:",{aString:aString},$globals.SemanticAnalyzer)});
- },
- args: ["aString"],
- source: "validateVariableScope: aString\x0a\x09\x22Validate the variable scope in by doing a recursive lookup, up to the method scope\x22\x0a\x0a\x09(currentScope lookupVariable: aString) ifNotNil: [\x0a\x09\x09self errorShadowingVariable: aString ]",
- referencedClasses: [],
- messageSends: ["ifNotNil:", "lookupVariable:", "errorShadowingVariable:"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "visitAssignmentNode:",
- protocol: 'visiting',
- fn: function (aNode){
- var self=this;
- return $core.withContext(function($ctx1) {
- (
- $ctx1.supercall = true,
- ($globals.SemanticAnalyzer.superclass||$boot.nilAsClass).fn.prototype._visitAssignmentNode_.apply($recv(self), [aNode]));
- $ctx1.supercall = false;
- $recv($recv(aNode)._left())._beAssigned();
- return self;
- }, function($ctx1) {$ctx1.fill(self,"visitAssignmentNode:",{aNode:aNode},$globals.SemanticAnalyzer)});
- },
- args: ["aNode"],
- source: "visitAssignmentNode: aNode\x0a\x09super visitAssignmentNode: aNode.\x0a\x09aNode left beAssigned",
- referencedClasses: [],
- messageSends: ["visitAssignmentNode:", "beAssigned", "left"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "visitBlockNode:",
- protocol: 'visiting',
- fn: function (aNode){
- var self=this;
- return $core.withContext(function($ctx1) {
- self._pushScope_(self._newBlockScope());
- $recv(aNode)._scope_(self["@currentScope"]);
- $recv(self["@currentScope"])._node_(aNode);
- $recv(self["@currentScope"])._blockIndex_(self._nextBlockIndex());
- $recv($recv(aNode)._parameters())._do_((function(each){
- return $core.withContext(function($ctx2) {
- self._validateVariableScope_(each);
- return $recv(self["@currentScope"])._addArg_(each);
- }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
- }));
- (
- $ctx1.supercall = true,
- ($globals.SemanticAnalyzer.superclass||$boot.nilAsClass).fn.prototype._visitBlockNode_.apply($recv(self), [aNode]));
- $ctx1.supercall = false;
- self._popScope();
- return self;
- }, function($ctx1) {$ctx1.fill(self,"visitBlockNode:",{aNode:aNode},$globals.SemanticAnalyzer)});
- },
- args: ["aNode"],
- source: "visitBlockNode: aNode\x0a\x09self pushScope: self newBlockScope.\x0a\x09aNode scope: currentScope.\x0a\x09currentScope node: aNode.\x0a\x09currentScope blockIndex: self nextBlockIndex.\x0a\x0a\x09aNode parameters do: [ :each |\x0a\x09\x09self validateVariableScope: each.\x0a\x09\x09currentScope addArg: each ].\x0a\x0a\x09super visitBlockNode: aNode.\x0a\x09self popScope",
- referencedClasses: [],
- messageSends: ["pushScope:", "newBlockScope", "scope:", "node:", "blockIndex:", "nextBlockIndex", "do:", "parameters", "validateVariableScope:", "addArg:", "visitBlockNode:", "popScope"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "visitCascadeNode:",
- protocol: 'visiting',
- fn: function (aNode){
- var self=this;
- return $core.withContext(function($ctx1) {
- $recv(aNode)._receiver_($recv($recv($recv(aNode)._nodes())._first())._receiver());
- (
- $ctx1.supercall = true,
- ($globals.SemanticAnalyzer.superclass||$boot.nilAsClass).fn.prototype._visitCascadeNode_.apply($recv(self), [aNode]));
- $ctx1.supercall = false;
- return self;
- }, function($ctx1) {$ctx1.fill(self,"visitCascadeNode:",{aNode:aNode},$globals.SemanticAnalyzer)});
- },
- args: ["aNode"],
- source: "visitCascadeNode: aNode\x0a\x09aNode receiver: aNode nodes first receiver.\x0a\x09super visitCascadeNode: aNode",
- referencedClasses: [],
- messageSends: ["receiver:", "receiver", "first", "nodes", "visitCascadeNode:"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "visitMethodNode:",
- protocol: 'visiting',
- fn: function (aNode){
- var self=this;
- return $core.withContext(function($ctx1) {
- self._pushScope_(self._newMethodScope());
- $recv(aNode)._scope_(self["@currentScope"]);
- $recv(self["@currentScope"])._node_(aNode);
- $recv($recv(self._theClass())._allInstanceVariableNames())._do_((function(each){
- return $core.withContext(function($ctx2) {
- return $recv(self["@currentScope"])._addIVar_(each);
- }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
- }));
- $ctx1.sendIdx["do:"]=1;
- $recv($recv(aNode)._arguments())._do_((function(each){
- return $core.withContext(function($ctx2) {
- self._validateVariableScope_(each);
- return $recv(self["@currentScope"])._addArg_(each);
- }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)});
- }));
- (
- $ctx1.supercall = true,
- ($globals.SemanticAnalyzer.superclass||$boot.nilAsClass).fn.prototype._visitMethodNode_.apply($recv(self), [aNode]));
- $ctx1.supercall = false;
- $recv(aNode)._classReferences_(self._classReferences());
- $recv(aNode)._sendIndexes_(self._messageSends());
- self._popScope();
- return self;
- }, function($ctx1) {$ctx1.fill(self,"visitMethodNode:",{aNode:aNode},$globals.SemanticAnalyzer)});
- },
- args: ["aNode"],
- source: "visitMethodNode: aNode\x0a\x09self pushScope: self newMethodScope.\x0a\x09aNode scope: currentScope.\x0a\x09currentScope node: aNode.\x0a\x0a\x09self theClass allInstanceVariableNames do: [ :each |\x0a\x09\x09currentScope addIVar: each ].\x0a\x09aNode arguments do: [ :each |\x0a\x09\x09self validateVariableScope: each.\x0a\x09\x09currentScope addArg: each ].\x0a\x0a\x09super visitMethodNode: aNode.\x0a\x0a\x09aNode\x0a\x09\x09classReferences: self classReferences;\x0a\x09\x09sendIndexes: self messageSends.\x0a\x09self popScope",
- referencedClasses: [],
- messageSends: ["pushScope:", "newMethodScope", "scope:", "node:", "do:", "allInstanceVariableNames", "theClass", "addIVar:", "arguments", "validateVariableScope:", "addArg:", "visitMethodNode:", "classReferences:", "classReferences", "sendIndexes:", "messageSends", "popScope"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "visitReturnNode:",
- protocol: 'visiting',
- fn: function (aNode){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1;
- $recv(aNode)._scope_(self["@currentScope"]);
- $1=$recv(self["@currentScope"])._isMethodScope();
- if($core.assert($1)){
- $recv(self["@currentScope"])._localReturn_(true);
- } else {
- $recv($recv(self["@currentScope"])._methodScope())._addNonLocalReturn_(self["@currentScope"]);
- };
- (
- $ctx1.supercall = true,
- ($globals.SemanticAnalyzer.superclass||$boot.nilAsClass).fn.prototype._visitReturnNode_.apply($recv(self), [aNode]));
- $ctx1.supercall = false;
- return self;
- }, function($ctx1) {$ctx1.fill(self,"visitReturnNode:",{aNode:aNode},$globals.SemanticAnalyzer)});
- },
- args: ["aNode"],
- source: "visitReturnNode: aNode\x0a\x09aNode scope: currentScope.\x0a\x09currentScope isMethodScope\x0a\x09\x09ifTrue: [ currentScope localReturn: true ]\x0a\x09\x09ifFalse: [ currentScope methodScope addNonLocalReturn: currentScope ].\x0a\x09super visitReturnNode: aNode",
- referencedClasses: [],
- messageSends: ["scope:", "ifTrue:ifFalse:", "isMethodScope", "localReturn:", "addNonLocalReturn:", "methodScope", "visitReturnNode:"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "visitSendNode:",
- protocol: 'visiting',
- fn: function (aNode){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $3,$2,$1,$5,$6,$4,$7,$8,$9,$11,$12,$10,$receiver;
- $3=$recv(aNode)._receiver();
- $ctx1.sendIdx["receiver"]=1;
- $2=$recv($3)._value();
- $1=$recv($2).__eq("super");
- if(!$core.assert($1)){
- $5=$recv($globals.IRSendInliner)._inlinedSelectors();
- $6=$recv(aNode)._selector();
- $ctx1.sendIdx["selector"]=1;
- $4=$recv($5)._includes_($6);
- if($core.assert($4)){
- $recv(aNode)._shouldBeInlined_(true);
- $7=$recv(aNode)._receiver();
- if(($receiver = $7) == null || $receiver.isNil){
- $7;
- } else {
- var receiver;
- receiver=$receiver;
- $recv(receiver)._shouldBeAliased_(true);
- };
- };
- };
- $8=self._messageSends();
- $ctx1.sendIdx["messageSends"]=1;
- $9=$recv(aNode)._selector();
- $ctx1.sendIdx["selector"]=2;
- $recv($8)._at_ifAbsentPut_($9,(function(){
- return $core.withContext(function($ctx2) {
- return $recv($globals.Set)._new();
- }, function($ctx2) {$ctx2.fillBlock({},$ctx1,4)});
- }));
- $11=self._messageSends();
- $ctx1.sendIdx["messageSends"]=2;
- $12=$recv(aNode)._selector();
- $ctx1.sendIdx["selector"]=3;
- $10=$recv($11)._at_($12);
- $ctx1.sendIdx["at:"]=1;
- $recv($10)._add_(aNode);
- $recv(aNode)._index_($recv($recv(self._messageSends())._at_($recv(aNode)._selector()))._size());
- (
- $ctx1.supercall = true,
- ($globals.SemanticAnalyzer.superclass||$boot.nilAsClass).fn.prototype._visitSendNode_.apply($recv(self), [aNode]));
- $ctx1.supercall = false;
- return self;
- }, function($ctx1) {$ctx1.fill(self,"visitSendNode:",{aNode:aNode},$globals.SemanticAnalyzer)});
- },
- args: ["aNode"],
- source: "visitSendNode: aNode\x0a\x0a\x09aNode receiver value = 'super'\x0a\x09\x09ifFalse: [ (IRSendInliner inlinedSelectors includes: aNode selector) ifTrue: [\x0a\x09\x09\x09aNode shouldBeInlined: true.\x0a\x09\x09\x09aNode receiver ifNotNil: [ :receiver |\x0a\x09\x09\x09\x09receiver shouldBeAliased: true ] ] ].\x0a\x0a\x09self messageSends at: aNode selector ifAbsentPut: [ Set new ].\x0a\x09(self messageSends at: aNode selector) add: aNode.\x0a\x0a\x09aNode index: (self messageSends at: aNode selector) size.\x0a\x0a\x09super visitSendNode: aNode",
- referencedClasses: ["IRSendInliner", "Set"],
- messageSends: ["ifFalse:", "=", "value", "receiver", "ifTrue:", "includes:", "inlinedSelectors", "selector", "shouldBeInlined:", "ifNotNil:", "shouldBeAliased:", "at:ifAbsentPut:", "messageSends", "new", "add:", "at:", "index:", "size", "visitSendNode:"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "visitSequenceNode:",
- protocol: 'visiting',
- fn: function (aNode){
- var self=this;
- return $core.withContext(function($ctx1) {
- $recv($recv(aNode)._temps())._do_((function(each){
- return $core.withContext(function($ctx2) {
- self._validateVariableScope_(each);
- return $recv(self["@currentScope"])._addTemp_(each);
- }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
- }));
- (
- $ctx1.supercall = true,
- ($globals.SemanticAnalyzer.superclass||$boot.nilAsClass).fn.prototype._visitSequenceNode_.apply($recv(self), [aNode]));
- $ctx1.supercall = false;
- return self;
- }, function($ctx1) {$ctx1.fill(self,"visitSequenceNode:",{aNode:aNode},$globals.SemanticAnalyzer)});
- },
- args: ["aNode"],
- source: "visitSequenceNode: aNode\x0a\x09aNode temps do: [ :each |\x0a\x09\x09self validateVariableScope: each.\x0a\x09\x09currentScope addTemp: each ].\x0a\x0a\x09super visitSequenceNode: aNode",
- referencedClasses: [],
- messageSends: ["do:", "temps", "validateVariableScope:", "addTemp:", "visitSequenceNode:"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "visitVariableNode:",
- protocol: 'visiting',
- fn: function (aNode){
- var self=this;
- var binding;
- return $core.withContext(function($ctx1) {
- var $1,$3,$2,$4,$5,$6,$7,$8,$9,$receiver;
- binding=$recv(self["@currentScope"])._lookupVariable_(aNode);
- $1=binding;
- if(($receiver = $1) == null || $receiver.isNil){
- $3=$recv(aNode)._value();
- $ctx1.sendIdx["value"]=1;
- $2=$recv($3)._isCapitalized();
- if($core.assert($2)){
- $4=$recv($globals.ClassRefVar)._new();
- $ctx1.sendIdx["new"]=1;
- $5=$recv(aNode)._value();
- $ctx1.sendIdx["value"]=2;
- $recv($4)._name_($5);
- $ctx1.sendIdx["name:"]=1;
- $6=$recv($4)._yourself();
- $ctx1.sendIdx["yourself"]=1;
- binding=$6;
- binding;
- $7=self._classReferences();
- $8=$recv(aNode)._value();
- $ctx1.sendIdx["value"]=3;
- $recv($7)._add_($8);
- } else {
- self._errorUnknownVariable_(aNode);
- $9=$recv($globals.UnknownVar)._new();
- $recv($9)._name_($recv(aNode)._value());
- binding=$recv($9)._yourself();
- binding;
- };
- } else {
- $1;
- };
- $recv(aNode)._binding_(binding);
- return self;
- }, function($ctx1) {$ctx1.fill(self,"visitVariableNode:",{aNode:aNode,binding:binding},$globals.SemanticAnalyzer)});
- },
- args: ["aNode"],
- source: "visitVariableNode: aNode\x0a\x09\x22Bind a ScopeVar to aNode by doing a lookup in the current scope.\x0a\x09If no ScopeVar is found, bind a UnknowVar and throw an error.\x22\x0a\x0a\x09| binding |\x0a\x09binding := currentScope lookupVariable: aNode.\x0a\x09\x0a\x09binding ifNil: [\x0a\x09\x09aNode value isCapitalized\x0a\x09\x09\x09ifTrue: [ \x22Capital letter variables might be globals.\x22\x0a\x09\x09\x09\x09binding := ClassRefVar new name: aNode value; yourself.\x0a\x09\x09\x09\x09self classReferences add: aNode value]\x0a\x09\x09\x09ifFalse: [\x0a\x09\x09\x09\x09self errorUnknownVariable: aNode.\x0a\x09\x09\x09\x09binding := UnknownVar new name: aNode value; yourself ] ].\x0a\x09\x09\x0a\x09aNode binding: binding.",
- referencedClasses: ["ClassRefVar", "UnknownVar"],
- messageSends: ["lookupVariable:", "ifNil:", "ifTrue:ifFalse:", "isCapitalized", "value", "name:", "new", "yourself", "add:", "classReferences", "errorUnknownVariable:", "binding:"]
- }),
- $globals.SemanticAnalyzer);
- $core.addMethod(
- $core.method({
- selector: "on:",
- protocol: 'instance creation',
- fn: function (aClass){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1;
- $1=self._new();
- $recv($1)._theClass_(aClass);
- return $recv($1)._yourself();
- }, function($ctx1) {$ctx1.fill(self,"on:",{aClass:aClass},$globals.SemanticAnalyzer.klass)});
- },
- args: ["aClass"],
- source: "on: aClass\x0a\x09^ self new\x0a\x09\x09theClass: aClass;\x0a\x09\x09yourself",
- referencedClasses: [],
- messageSends: ["theClass:", "new", "yourself"]
- }),
- $globals.SemanticAnalyzer.klass);
- $core.addClass('SemanticError', $globals.CompilerError, [], 'Compiler-Semantic');
- $globals.SemanticError.comment="I represent an abstract semantic error thrown by the SemanticAnalyzer.\x0aSemantic errors can be unknown variable errors, etc.\x0aSee my subclasses for concrete errors.\x0a\x0aThe IDE should catch instances of Semantic error to deal with them when compiling";
- $core.addClass('InvalidAssignmentError', $globals.SemanticError, ['variableName'], 'Compiler-Semantic');
- $globals.InvalidAssignmentError.comment="I get signaled when a pseudo variable gets assigned.";
- $core.addMethod(
- $core.method({
- selector: "messageText",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- return " Invalid assignment to variable: ".__comma(self._variableName());
- }, function($ctx1) {$ctx1.fill(self,"messageText",{},$globals.InvalidAssignmentError)});
- },
- args: [],
- source: "messageText\x0a\x09^ ' Invalid assignment to variable: ', self variableName",
- referencedClasses: [],
- messageSends: [",", "variableName"]
- }),
- $globals.InvalidAssignmentError);
- $core.addMethod(
- $core.method({
- selector: "variableName",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return self["@variableName"];
- },
- args: [],
- source: "variableName\x0a\x09^ variableName",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.InvalidAssignmentError);
- $core.addMethod(
- $core.method({
- selector: "variableName:",
- protocol: 'accessing',
- fn: function (aString){
- var self=this;
- self["@variableName"]=aString;
- return self;
- },
- args: ["aString"],
- source: "variableName: aString\x0a\x09variableName := aString",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.InvalidAssignmentError);
- $core.addClass('ShadowingVariableError', $globals.SemanticError, ['variableName'], 'Compiler-Semantic');
- $globals.ShadowingVariableError.comment="I get signaled when a variable in a block or method scope shadows a variable of the same name in an outer scope.";
- $core.addMethod(
- $core.method({
- selector: "messageText",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1;
- $1=$recv("Variable shadowing error: ".__comma(self._variableName())).__comma(" is already defined");
- $ctx1.sendIdx[","]=1;
- return $1;
- }, function($ctx1) {$ctx1.fill(self,"messageText",{},$globals.ShadowingVariableError)});
- },
- args: [],
- source: "messageText\x0a\x09^ 'Variable shadowing error: ', self variableName, ' is already defined'",
- referencedClasses: [],
- messageSends: [",", "variableName"]
- }),
- $globals.ShadowingVariableError);
- $core.addMethod(
- $core.method({
- selector: "variableName",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return self["@variableName"];
- },
- args: [],
- source: "variableName\x0a\x09^ variableName",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ShadowingVariableError);
- $core.addMethod(
- $core.method({
- selector: "variableName:",
- protocol: 'accessing',
- fn: function (aString){
- var self=this;
- self["@variableName"]=aString;
- return self;
- },
- args: ["aString"],
- source: "variableName: aString\x0a\x09variableName := aString",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.ShadowingVariableError);
- $core.addClass('UnknownVariableError', $globals.SemanticError, ['variableName'], 'Compiler-Semantic');
- $globals.UnknownVariableError.comment="I get signaled when a variable is not defined.\x0aThe default behavior is to allow it, as this is how Amber currently is able to seamlessly send messages to JavaScript objects.";
- $core.addMethod(
- $core.method({
- selector: "messageText",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return $core.withContext(function($ctx1) {
- var $1;
- $1=$recv("Unknown Variable error: ".__comma(self._variableName())).__comma(" is not defined");
- $ctx1.sendIdx[","]=1;
- return $1;
- }, function($ctx1) {$ctx1.fill(self,"messageText",{},$globals.UnknownVariableError)});
- },
- args: [],
- source: "messageText\x0a\x09^ 'Unknown Variable error: ', self variableName, ' is not defined'",
- referencedClasses: [],
- messageSends: [",", "variableName"]
- }),
- $globals.UnknownVariableError);
- $core.addMethod(
- $core.method({
- selector: "variableName",
- protocol: 'accessing',
- fn: function (){
- var self=this;
- return self["@variableName"];
- },
- args: [],
- source: "variableName\x0a\x09^ variableName",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.UnknownVariableError);
- $core.addMethod(
- $core.method({
- selector: "variableName:",
- protocol: 'accessing',
- fn: function (aString){
- var self=this;
- self["@variableName"]=aString;
- return self;
- },
- args: ["aString"],
- source: "variableName: aString\x0a\x09variableName := aString",
- referencedClasses: [],
- messageSends: []
- }),
- $globals.UnknownVariableError);
- });
|