Compiler-Semantic.js 60 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953
  1. define("amber_core/Compiler-Semantic", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_vm/globals", "amber_core/Kernel-Objects", "amber_core/Compiler-Core"], function(smalltalk,nil,_st, globals){
  2. smalltalk.addPackage('Compiler-Semantic');
  3. smalltalk.packages["Compiler-Semantic"].transport = {"type":"amd","amdNamespace":"amber_core"};
  4. smalltalk.addClass('LexicalScope', globals.Object, ['node', 'instruction', 'temps', 'args', 'outerScope', 'blockIndex'], 'Compiler-Semantic');
  5. 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.";
  6. smalltalk.addMethod(
  7. smalltalk.method({
  8. selector: "addArg:",
  9. protocol: 'adding',
  10. fn: function (aString){
  11. var self=this;
  12. function $ArgVar(){return globals.ArgVar||(typeof ArgVar=="undefined"?nil:ArgVar)}
  13. return smalltalk.withContext(function($ctx1) {
  14. var $1;
  15. $1=self._args();
  16. $ctx1.sendIdx["args"]=1;
  17. _st($1)._at_put_(aString,_st($ArgVar())._on_(aString));
  18. _st(_st(self._args())._at_(aString))._scope_(self);
  19. return self}, function($ctx1) {$ctx1.fill(self,"addArg:",{aString:aString},globals.LexicalScope)})},
  20. args: ["aString"],
  21. source: "addArg: aString\x0a\x09self args at: aString put: (ArgVar on: aString).\x0a\x09(self args at: aString) scope: self",
  22. messageSends: ["at:put:", "args", "on:", "scope:", "at:"],
  23. referencedClasses: ["ArgVar"]
  24. }),
  25. globals.LexicalScope);
  26. smalltalk.addMethod(
  27. smalltalk.method({
  28. selector: "addTemp:",
  29. protocol: 'adding',
  30. fn: function (aString){
  31. var self=this;
  32. function $TempVar(){return globals.TempVar||(typeof TempVar=="undefined"?nil:TempVar)}
  33. return smalltalk.withContext(function($ctx1) {
  34. var $1;
  35. $1=self._temps();
  36. $ctx1.sendIdx["temps"]=1;
  37. _st($1)._at_put_(aString,_st($TempVar())._on_(aString));
  38. _st(_st(self._temps())._at_(aString))._scope_(self);
  39. return self}, function($ctx1) {$ctx1.fill(self,"addTemp:",{aString:aString},globals.LexicalScope)})},
  40. args: ["aString"],
  41. source: "addTemp: aString\x0a\x09self temps at: aString put: (TempVar on: aString).\x0a\x09(self temps at: aString) scope: self",
  42. messageSends: ["at:put:", "temps", "on:", "scope:", "at:"],
  43. referencedClasses: ["TempVar"]
  44. }),
  45. globals.LexicalScope);
  46. smalltalk.addMethod(
  47. smalltalk.method({
  48. selector: "alias",
  49. protocol: 'accessing',
  50. fn: function (){
  51. var self=this;
  52. return smalltalk.withContext(function($ctx1) {
  53. var $1;
  54. $1="$ctx".__comma(_st(self._scopeLevel())._asString());
  55. return $1;
  56. }, function($ctx1) {$ctx1.fill(self,"alias",{},globals.LexicalScope)})},
  57. args: [],
  58. source: "alias\x0a\x09^ '$ctx', self scopeLevel asString",
  59. messageSends: [",", "asString", "scopeLevel"],
  60. referencedClasses: []
  61. }),
  62. globals.LexicalScope);
  63. smalltalk.addMethod(
  64. smalltalk.method({
  65. selector: "allVariableNames",
  66. protocol: 'accessing',
  67. fn: function (){
  68. var self=this;
  69. return smalltalk.withContext(function($ctx1) {
  70. var $2,$1;
  71. $2=_st(self._args())._keys();
  72. $ctx1.sendIdx["keys"]=1;
  73. $1=_st($2).__comma(_st(self._temps())._keys());
  74. return $1;
  75. }, function($ctx1) {$ctx1.fill(self,"allVariableNames",{},globals.LexicalScope)})},
  76. args: [],
  77. source: "allVariableNames\x0a\x09^ self args keys, self temps keys",
  78. messageSends: [",", "keys", "args", "temps"],
  79. referencedClasses: []
  80. }),
  81. globals.LexicalScope);
  82. smalltalk.addMethod(
  83. smalltalk.method({
  84. selector: "args",
  85. protocol: 'accessing',
  86. fn: function (){
  87. var self=this;
  88. function $Dictionary(){return globals.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  89. return smalltalk.withContext(function($ctx1) {
  90. var $2,$1,$receiver;
  91. $2=self["@args"];
  92. if(($receiver = $2) == null || $receiver.isNil){
  93. self["@args"]=_st($Dictionary())._new();
  94. $1=self["@args"];
  95. } else {
  96. $1=$2;
  97. };
  98. return $1;
  99. }, function($ctx1) {$ctx1.fill(self,"args",{},globals.LexicalScope)})},
  100. args: [],
  101. source: "args\x0a\x09^ args ifNil: [ args := Dictionary new ]",
  102. messageSends: ["ifNil:", "new"],
  103. referencedClasses: ["Dictionary"]
  104. }),
  105. globals.LexicalScope);
  106. smalltalk.addMethod(
  107. smalltalk.method({
  108. selector: "bindingFor:",
  109. protocol: 'accessing',
  110. fn: function (aStringOrNode){
  111. var self=this;
  112. return smalltalk.withContext(function($ctx1) {
  113. var $2,$3,$4,$5,$1;
  114. $2=self._pseudoVars();
  115. $3=_st(aStringOrNode)._value();
  116. $ctx1.sendIdx["value"]=1;
  117. $1=_st($2)._at_ifAbsent_($3,(function(){
  118. return smalltalk.withContext(function($ctx2) {
  119. $4=self._args();
  120. $5=_st(aStringOrNode)._value();
  121. $ctx2.sendIdx["value"]=2;
  122. return _st($4)._at_ifAbsent_($5,(function(){
  123. return smalltalk.withContext(function($ctx3) {
  124. return _st(self._temps())._at_ifAbsent_(_st(aStringOrNode)._value(),(function(){
  125. return nil;
  126. }));
  127. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)})}));
  128. $ctx2.sendIdx["at:ifAbsent:"]=2;
  129. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  130. $ctx1.sendIdx["at:ifAbsent:"]=1;
  131. return $1;
  132. }, function($ctx1) {$ctx1.fill(self,"bindingFor:",{aStringOrNode:aStringOrNode},globals.LexicalScope)})},
  133. args: ["aStringOrNode"],
  134. 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 ]]]",
  135. messageSends: ["at:ifAbsent:", "pseudoVars", "value", "args", "temps"],
  136. referencedClasses: []
  137. }),
  138. globals.LexicalScope);
  139. smalltalk.addMethod(
  140. smalltalk.method({
  141. selector: "blockIndex",
  142. protocol: 'accessing',
  143. fn: function (){
  144. var self=this;
  145. return smalltalk.withContext(function($ctx1) {
  146. var $2,$1,$receiver;
  147. $2=self["@blockIndex"];
  148. if(($receiver = $2) == null || $receiver.isNil){
  149. $1=(0);
  150. } else {
  151. $1=$2;
  152. };
  153. return $1;
  154. }, function($ctx1) {$ctx1.fill(self,"blockIndex",{},globals.LexicalScope)})},
  155. args: [],
  156. source: "blockIndex\x0a\x09^ blockIndex ifNil: [ 0 ]",
  157. messageSends: ["ifNil:"],
  158. referencedClasses: []
  159. }),
  160. globals.LexicalScope);
  161. smalltalk.addMethod(
  162. smalltalk.method({
  163. selector: "blockIndex:",
  164. protocol: 'accessing',
  165. fn: function (anInteger){
  166. var self=this;
  167. self["@blockIndex"]=anInteger;
  168. return self},
  169. args: ["anInteger"],
  170. source: "blockIndex: anInteger \x0a\x09blockIndex := anInteger",
  171. messageSends: [],
  172. referencedClasses: []
  173. }),
  174. globals.LexicalScope);
  175. smalltalk.addMethod(
  176. smalltalk.method({
  177. selector: "canInlineNonLocalReturns",
  178. protocol: 'testing',
  179. fn: function (){
  180. var self=this;
  181. return smalltalk.withContext(function($ctx1) {
  182. var $1;
  183. $1=_st(self._isInlined())._and_((function(){
  184. return smalltalk.withContext(function($ctx2) {
  185. return _st(self._outerScope())._canInlineNonLocalReturns();
  186. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  187. return $1;
  188. }, function($ctx1) {$ctx1.fill(self,"canInlineNonLocalReturns",{},globals.LexicalScope)})},
  189. args: [],
  190. source: "canInlineNonLocalReturns\x0a\x09^ self isInlined and: [ self outerScope canInlineNonLocalReturns ]",
  191. messageSends: ["and:", "isInlined", "canInlineNonLocalReturns", "outerScope"],
  192. referencedClasses: []
  193. }),
  194. globals.LexicalScope);
  195. smalltalk.addMethod(
  196. smalltalk.method({
  197. selector: "instruction",
  198. protocol: 'accessing',
  199. fn: function (){
  200. var self=this;
  201. var $1;
  202. $1=self["@instruction"];
  203. return $1;
  204. },
  205. args: [],
  206. source: "instruction\x0a\x09^ instruction",
  207. messageSends: [],
  208. referencedClasses: []
  209. }),
  210. globals.LexicalScope);
  211. smalltalk.addMethod(
  212. smalltalk.method({
  213. selector: "instruction:",
  214. protocol: 'accessing',
  215. fn: function (anIRInstruction){
  216. var self=this;
  217. self["@instruction"]=anIRInstruction;
  218. return self},
  219. args: ["anIRInstruction"],
  220. source: "instruction: anIRInstruction\x0a\x09instruction := anIRInstruction",
  221. messageSends: [],
  222. referencedClasses: []
  223. }),
  224. globals.LexicalScope);
  225. smalltalk.addMethod(
  226. smalltalk.method({
  227. selector: "isBlockScope",
  228. protocol: 'testing',
  229. fn: function (){
  230. var self=this;
  231. return smalltalk.withContext(function($ctx1) {
  232. var $1;
  233. $1=_st(self._isMethodScope())._not();
  234. return $1;
  235. }, function($ctx1) {$ctx1.fill(self,"isBlockScope",{},globals.LexicalScope)})},
  236. args: [],
  237. source: "isBlockScope\x0a\x09^ self isMethodScope not",
  238. messageSends: ["not", "isMethodScope"],
  239. referencedClasses: []
  240. }),
  241. globals.LexicalScope);
  242. smalltalk.addMethod(
  243. smalltalk.method({
  244. selector: "isInlined",
  245. protocol: 'testing',
  246. fn: function (){
  247. var self=this;
  248. return smalltalk.withContext(function($ctx1) {
  249. var $3,$2,$1;
  250. $3=self._instruction();
  251. $ctx1.sendIdx["instruction"]=1;
  252. $2=_st($3)._notNil();
  253. $1=_st($2)._and_((function(){
  254. return smalltalk.withContext(function($ctx2) {
  255. return _st(self._instruction())._isInlined();
  256. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  257. return $1;
  258. }, function($ctx1) {$ctx1.fill(self,"isInlined",{},globals.LexicalScope)})},
  259. args: [],
  260. source: "isInlined\x0a\x09^ self instruction notNil and: [\x0a\x09\x09self instruction isInlined ]",
  261. messageSends: ["and:", "notNil", "instruction", "isInlined"],
  262. referencedClasses: []
  263. }),
  264. globals.LexicalScope);
  265. smalltalk.addMethod(
  266. smalltalk.method({
  267. selector: "isMethodScope",
  268. protocol: 'testing',
  269. fn: function (){
  270. var self=this;
  271. return false;
  272. },
  273. args: [],
  274. source: "isMethodScope\x0a\x09^ false",
  275. messageSends: [],
  276. referencedClasses: []
  277. }),
  278. globals.LexicalScope);
  279. smalltalk.addMethod(
  280. smalltalk.method({
  281. selector: "lookupVariable:",
  282. protocol: 'accessing',
  283. fn: function (aNode){
  284. var self=this;
  285. var lookup;
  286. return smalltalk.withContext(function($ctx1) {
  287. var $1,$2,$3,$receiver;
  288. lookup=self._bindingFor_(aNode);
  289. $1=lookup;
  290. if(($receiver = $1) == null || $receiver.isNil){
  291. $2=self._outerScope();
  292. $ctx1.sendIdx["outerScope"]=1;
  293. if(($receiver = $2) == null || $receiver.isNil){
  294. lookup=$2;
  295. } else {
  296. lookup=_st(self._outerScope())._lookupVariable_(aNode);
  297. };
  298. lookup;
  299. } else {
  300. $1;
  301. };
  302. $3=lookup;
  303. return $3;
  304. }, function($ctx1) {$ctx1.fill(self,"lookupVariable:",{aNode:aNode,lookup:lookup},globals.LexicalScope)})},
  305. args: ["aNode"],
  306. 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",
  307. messageSends: ["bindingFor:", "ifNil:", "ifNotNil:", "outerScope", "lookupVariable:"],
  308. referencedClasses: []
  309. }),
  310. globals.LexicalScope);
  311. smalltalk.addMethod(
  312. smalltalk.method({
  313. selector: "methodScope",
  314. protocol: 'accessing',
  315. fn: function (){
  316. var self=this;
  317. return smalltalk.withContext(function($ctx1) {
  318. var $2,$1,$receiver;
  319. $2=self._outerScope();
  320. $ctx1.sendIdx["outerScope"]=1;
  321. if(($receiver = $2) == null || $receiver.isNil){
  322. $1=$2;
  323. } else {
  324. $1=_st(self._outerScope())._methodScope();
  325. };
  326. return $1;
  327. }, function($ctx1) {$ctx1.fill(self,"methodScope",{},globals.LexicalScope)})},
  328. args: [],
  329. source: "methodScope\x0a\x09^ self outerScope ifNotNil: [\x0a\x09\x09self outerScope methodScope ]",
  330. messageSends: ["ifNotNil:", "outerScope", "methodScope"],
  331. referencedClasses: []
  332. }),
  333. globals.LexicalScope);
  334. smalltalk.addMethod(
  335. smalltalk.method({
  336. selector: "node",
  337. protocol: 'accessing',
  338. fn: function (){
  339. var self=this;
  340. var $1;
  341. $1=self["@node"];
  342. return $1;
  343. },
  344. args: [],
  345. source: "node\x0a\x09\x22Answer the node in which I am defined\x22\x0a\x09\x0a\x09^ node",
  346. messageSends: [],
  347. referencedClasses: []
  348. }),
  349. globals.LexicalScope);
  350. smalltalk.addMethod(
  351. smalltalk.method({
  352. selector: "node:",
  353. protocol: 'accessing',
  354. fn: function (aNode){
  355. var self=this;
  356. self["@node"]=aNode;
  357. return self},
  358. args: ["aNode"],
  359. source: "node: aNode\x0a\x09node := aNode",
  360. messageSends: [],
  361. referencedClasses: []
  362. }),
  363. globals.LexicalScope);
  364. smalltalk.addMethod(
  365. smalltalk.method({
  366. selector: "outerScope",
  367. protocol: 'accessing',
  368. fn: function (){
  369. var self=this;
  370. var $1;
  371. $1=self["@outerScope"];
  372. return $1;
  373. },
  374. args: [],
  375. source: "outerScope\x0a\x09^ outerScope",
  376. messageSends: [],
  377. referencedClasses: []
  378. }),
  379. globals.LexicalScope);
  380. smalltalk.addMethod(
  381. smalltalk.method({
  382. selector: "outerScope:",
  383. protocol: 'accessing',
  384. fn: function (aLexicalScope){
  385. var self=this;
  386. self["@outerScope"]=aLexicalScope;
  387. return self},
  388. args: ["aLexicalScope"],
  389. source: "outerScope: aLexicalScope\x0a\x09outerScope := aLexicalScope",
  390. messageSends: [],
  391. referencedClasses: []
  392. }),
  393. globals.LexicalScope);
  394. smalltalk.addMethod(
  395. smalltalk.method({
  396. selector: "pseudoVars",
  397. protocol: 'accessing',
  398. fn: function (){
  399. var self=this;
  400. return smalltalk.withContext(function($ctx1) {
  401. var $1;
  402. $1=_st(self._methodScope())._pseudoVars();
  403. return $1;
  404. }, function($ctx1) {$ctx1.fill(self,"pseudoVars",{},globals.LexicalScope)})},
  405. args: [],
  406. source: "pseudoVars\x0a\x09^ self methodScope pseudoVars",
  407. messageSends: ["pseudoVars", "methodScope"],
  408. referencedClasses: []
  409. }),
  410. globals.LexicalScope);
  411. smalltalk.addMethod(
  412. smalltalk.method({
  413. selector: "scopeLevel",
  414. protocol: 'accessing',
  415. fn: function (){
  416. var self=this;
  417. return smalltalk.withContext(function($ctx1) {
  418. var $1,$2,$4,$3,$5,$receiver;
  419. $1=self._outerScope();
  420. $ctx1.sendIdx["outerScope"]=1;
  421. if(($receiver = $1) == null || $receiver.isNil){
  422. return (1);
  423. } else {
  424. $1;
  425. };
  426. $2=self._isInlined();
  427. if(smalltalk.assert($2)){
  428. $4=self._outerScope();
  429. $ctx1.sendIdx["outerScope"]=2;
  430. $3=_st($4)._scopeLevel();
  431. $ctx1.sendIdx["scopeLevel"]=1;
  432. return $3;
  433. };
  434. $5=_st(_st(self._outerScope())._scopeLevel()).__plus((1));
  435. return $5;
  436. }, function($ctx1) {$ctx1.fill(self,"scopeLevel",{},globals.LexicalScope)})},
  437. args: [],
  438. source: "scopeLevel\x0a\x09self outerScope ifNil: [ ^ 1 ].\x0a\x09self isInlined ifTrue: [ ^ self outerScope scopeLevel ].\x0a\x09\x0a\x09^ self outerScope scopeLevel + 1",
  439. messageSends: ["ifNil:", "outerScope", "ifTrue:", "isInlined", "scopeLevel", "+"],
  440. referencedClasses: []
  441. }),
  442. globals.LexicalScope);
  443. smalltalk.addMethod(
  444. smalltalk.method({
  445. selector: "temps",
  446. protocol: 'accessing',
  447. fn: function (){
  448. var self=this;
  449. function $Dictionary(){return globals.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  450. return smalltalk.withContext(function($ctx1) {
  451. var $2,$1,$receiver;
  452. $2=self["@temps"];
  453. if(($receiver = $2) == null || $receiver.isNil){
  454. self["@temps"]=_st($Dictionary())._new();
  455. $1=self["@temps"];
  456. } else {
  457. $1=$2;
  458. };
  459. return $1;
  460. }, function($ctx1) {$ctx1.fill(self,"temps",{},globals.LexicalScope)})},
  461. args: [],
  462. source: "temps\x0a\x09^ temps ifNil: [ temps := Dictionary new ]",
  463. messageSends: ["ifNil:", "new"],
  464. referencedClasses: ["Dictionary"]
  465. }),
  466. globals.LexicalScope);
  467. smalltalk.addClass('MethodLexicalScope', globals.LexicalScope, ['iVars', 'pseudoVars', 'unknownVariables', 'localReturn', 'nonLocalReturns'], 'Compiler-Semantic');
  468. globals.MethodLexicalScope.comment="I represent a method scope.";
  469. smalltalk.addMethod(
  470. smalltalk.method({
  471. selector: "addIVar:",
  472. protocol: 'adding',
  473. fn: function (aString){
  474. var self=this;
  475. function $InstanceVar(){return globals.InstanceVar||(typeof InstanceVar=="undefined"?nil:InstanceVar)}
  476. return smalltalk.withContext(function($ctx1) {
  477. var $1;
  478. $1=self._iVars();
  479. $ctx1.sendIdx["iVars"]=1;
  480. _st($1)._at_put_(aString,_st($InstanceVar())._on_(aString));
  481. _st(_st(self._iVars())._at_(aString))._scope_(self);
  482. return self}, function($ctx1) {$ctx1.fill(self,"addIVar:",{aString:aString},globals.MethodLexicalScope)})},
  483. args: ["aString"],
  484. source: "addIVar: aString\x0a\x09self iVars at: aString put: (InstanceVar on: aString).\x0a\x09(self iVars at: aString) scope: self",
  485. messageSends: ["at:put:", "iVars", "on:", "scope:", "at:"],
  486. referencedClasses: ["InstanceVar"]
  487. }),
  488. globals.MethodLexicalScope);
  489. smalltalk.addMethod(
  490. smalltalk.method({
  491. selector: "addNonLocalReturn:",
  492. protocol: 'adding',
  493. fn: function (aScope){
  494. var self=this;
  495. return smalltalk.withContext(function($ctx1) {
  496. _st(self._nonLocalReturns())._add_(aScope);
  497. return self}, function($ctx1) {$ctx1.fill(self,"addNonLocalReturn:",{aScope:aScope},globals.MethodLexicalScope)})},
  498. args: ["aScope"],
  499. source: "addNonLocalReturn: aScope\x0a\x09self nonLocalReturns add: aScope",
  500. messageSends: ["add:", "nonLocalReturns"],
  501. referencedClasses: []
  502. }),
  503. globals.MethodLexicalScope);
  504. smalltalk.addMethod(
  505. smalltalk.method({
  506. selector: "allVariableNames",
  507. protocol: 'accessing',
  508. fn: function (){
  509. var self=this;
  510. return smalltalk.withContext(function($ctx1) {
  511. var $2,$1;
  512. $2=($ctx1.supercall = true, globals.MethodLexicalScope.superclass.fn.prototype._allVariableNames.apply(_st(self), []));
  513. $ctx1.supercall = false;
  514. $1=_st($2).__comma(_st(self._iVars())._keys());
  515. return $1;
  516. }, function($ctx1) {$ctx1.fill(self,"allVariableNames",{},globals.MethodLexicalScope)})},
  517. args: [],
  518. source: "allVariableNames\x0a\x09^ super allVariableNames, self iVars keys",
  519. messageSends: [",", "allVariableNames", "keys", "iVars"],
  520. referencedClasses: []
  521. }),
  522. globals.MethodLexicalScope);
  523. smalltalk.addMethod(
  524. smalltalk.method({
  525. selector: "bindingFor:",
  526. protocol: 'accessing',
  527. fn: function (aNode){
  528. var self=this;
  529. return smalltalk.withContext(function($ctx1) {
  530. var $2,$1,$receiver;
  531. $2=($ctx1.supercall = true, globals.MethodLexicalScope.superclass.fn.prototype._bindingFor_.apply(_st(self), [aNode]));
  532. $ctx1.supercall = false;
  533. if(($receiver = $2) == null || $receiver.isNil){
  534. $1=_st(self._iVars())._at_ifAbsent_(_st(aNode)._value(),(function(){
  535. return nil;
  536. }));
  537. } else {
  538. $1=$2;
  539. };
  540. return $1;
  541. }, function($ctx1) {$ctx1.fill(self,"bindingFor:",{aNode:aNode},globals.MethodLexicalScope)})},
  542. args: ["aNode"],
  543. source: "bindingFor: aNode\x0a\x09^ (super bindingFor: aNode) ifNil: [\x0a\x09\x09self iVars at: aNode value ifAbsent: [ nil ]]",
  544. messageSends: ["ifNil:", "bindingFor:", "at:ifAbsent:", "iVars", "value"],
  545. referencedClasses: []
  546. }),
  547. globals.MethodLexicalScope);
  548. smalltalk.addMethod(
  549. smalltalk.method({
  550. selector: "canInlineNonLocalReturns",
  551. protocol: 'testing',
  552. fn: function (){
  553. var self=this;
  554. return true;
  555. },
  556. args: [],
  557. source: "canInlineNonLocalReturns\x0a\x09^ true",
  558. messageSends: [],
  559. referencedClasses: []
  560. }),
  561. globals.MethodLexicalScope);
  562. smalltalk.addMethod(
  563. smalltalk.method({
  564. selector: "hasLocalReturn",
  565. protocol: 'testing',
  566. fn: function (){
  567. var self=this;
  568. return smalltalk.withContext(function($ctx1) {
  569. var $1;
  570. $1=self._localReturn();
  571. return $1;
  572. }, function($ctx1) {$ctx1.fill(self,"hasLocalReturn",{},globals.MethodLexicalScope)})},
  573. args: [],
  574. source: "hasLocalReturn\x0a\x09^ self localReturn",
  575. messageSends: ["localReturn"],
  576. referencedClasses: []
  577. }),
  578. globals.MethodLexicalScope);
  579. smalltalk.addMethod(
  580. smalltalk.method({
  581. selector: "hasNonLocalReturn",
  582. protocol: 'testing',
  583. fn: function (){
  584. var self=this;
  585. return smalltalk.withContext(function($ctx1) {
  586. var $1;
  587. $1=_st(self._nonLocalReturns())._notEmpty();
  588. return $1;
  589. }, function($ctx1) {$ctx1.fill(self,"hasNonLocalReturn",{},globals.MethodLexicalScope)})},
  590. args: [],
  591. source: "hasNonLocalReturn\x0a\x09^ self nonLocalReturns notEmpty",
  592. messageSends: ["notEmpty", "nonLocalReturns"],
  593. referencedClasses: []
  594. }),
  595. globals.MethodLexicalScope);
  596. smalltalk.addMethod(
  597. smalltalk.method({
  598. selector: "iVars",
  599. protocol: 'accessing',
  600. fn: function (){
  601. var self=this;
  602. function $Dictionary(){return globals.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  603. return smalltalk.withContext(function($ctx1) {
  604. var $2,$1,$receiver;
  605. $2=self["@iVars"];
  606. if(($receiver = $2) == null || $receiver.isNil){
  607. self["@iVars"]=_st($Dictionary())._new();
  608. $1=self["@iVars"];
  609. } else {
  610. $1=$2;
  611. };
  612. return $1;
  613. }, function($ctx1) {$ctx1.fill(self,"iVars",{},globals.MethodLexicalScope)})},
  614. args: [],
  615. source: "iVars\x0a\x09^ iVars ifNil: [ iVars := Dictionary new ]",
  616. messageSends: ["ifNil:", "new"],
  617. referencedClasses: ["Dictionary"]
  618. }),
  619. globals.MethodLexicalScope);
  620. smalltalk.addMethod(
  621. smalltalk.method({
  622. selector: "isMethodScope",
  623. protocol: 'testing',
  624. fn: function (){
  625. var self=this;
  626. return true;
  627. },
  628. args: [],
  629. source: "isMethodScope\x0a\x09^ true",
  630. messageSends: [],
  631. referencedClasses: []
  632. }),
  633. globals.MethodLexicalScope);
  634. smalltalk.addMethod(
  635. smalltalk.method({
  636. selector: "localReturn",
  637. protocol: 'accessing',
  638. fn: function (){
  639. var self=this;
  640. return smalltalk.withContext(function($ctx1) {
  641. var $2,$1,$receiver;
  642. $2=self["@localReturn"];
  643. if(($receiver = $2) == null || $receiver.isNil){
  644. $1=false;
  645. } else {
  646. $1=$2;
  647. };
  648. return $1;
  649. }, function($ctx1) {$ctx1.fill(self,"localReturn",{},globals.MethodLexicalScope)})},
  650. args: [],
  651. source: "localReturn\x0a\x09^ localReturn ifNil: [ false ]",
  652. messageSends: ["ifNil:"],
  653. referencedClasses: []
  654. }),
  655. globals.MethodLexicalScope);
  656. smalltalk.addMethod(
  657. smalltalk.method({
  658. selector: "localReturn:",
  659. protocol: 'accessing',
  660. fn: function (aBoolean){
  661. var self=this;
  662. self["@localReturn"]=aBoolean;
  663. return self},
  664. args: ["aBoolean"],
  665. source: "localReturn: aBoolean\x0a\x09localReturn := aBoolean",
  666. messageSends: [],
  667. referencedClasses: []
  668. }),
  669. globals.MethodLexicalScope);
  670. smalltalk.addMethod(
  671. smalltalk.method({
  672. selector: "methodScope",
  673. protocol: 'accessing',
  674. fn: function (){
  675. var self=this;
  676. return self;
  677. },
  678. args: [],
  679. source: "methodScope\x0a\x09^ self",
  680. messageSends: [],
  681. referencedClasses: []
  682. }),
  683. globals.MethodLexicalScope);
  684. smalltalk.addMethod(
  685. smalltalk.method({
  686. selector: "nonLocalReturns",
  687. protocol: 'accessing',
  688. fn: function (){
  689. var self=this;
  690. function $OrderedCollection(){return globals.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  691. return smalltalk.withContext(function($ctx1) {
  692. var $2,$1,$receiver;
  693. $2=self["@nonLocalReturns"];
  694. if(($receiver = $2) == null || $receiver.isNil){
  695. self["@nonLocalReturns"]=_st($OrderedCollection())._new();
  696. $1=self["@nonLocalReturns"];
  697. } else {
  698. $1=$2;
  699. };
  700. return $1;
  701. }, function($ctx1) {$ctx1.fill(self,"nonLocalReturns",{},globals.MethodLexicalScope)})},
  702. args: [],
  703. source: "nonLocalReturns\x0a\x09^ nonLocalReturns ifNil: [ nonLocalReturns := OrderedCollection new ]",
  704. messageSends: ["ifNil:", "new"],
  705. referencedClasses: ["OrderedCollection"]
  706. }),
  707. globals.MethodLexicalScope);
  708. smalltalk.addMethod(
  709. smalltalk.method({
  710. selector: "pseudoVars",
  711. protocol: 'accessing',
  712. fn: function (){
  713. var self=this;
  714. function $Dictionary(){return globals.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  715. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  716. function $PseudoVar(){return globals.PseudoVar||(typeof PseudoVar=="undefined"?nil:PseudoVar)}
  717. return smalltalk.withContext(function($ctx1) {
  718. var $1,$2,$3,$4,$receiver;
  719. $1=self["@pseudoVars"];
  720. if(($receiver = $1) == null || $receiver.isNil){
  721. self["@pseudoVars"]=_st($Dictionary())._new();
  722. self["@pseudoVars"];
  723. _st(_st($Smalltalk())._pseudoVariableNames())._do_((function(each){
  724. return smalltalk.withContext(function($ctx2) {
  725. $2=_st($PseudoVar())._on_(each);
  726. _st($2)._scope_(self._methodScope());
  727. $3=_st($2)._yourself();
  728. return _st(self["@pseudoVars"])._at_put_(each,$3);
  729. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})}));
  730. } else {
  731. $1;
  732. };
  733. $4=self["@pseudoVars"];
  734. return $4;
  735. }, function($ctx1) {$ctx1.fill(self,"pseudoVars",{},globals.MethodLexicalScope)})},
  736. args: [],
  737. 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",
  738. messageSends: ["ifNil:", "new", "do:", "pseudoVariableNames", "at:put:", "scope:", "on:", "methodScope", "yourself"],
  739. referencedClasses: ["Dictionary", "Smalltalk", "PseudoVar"]
  740. }),
  741. globals.MethodLexicalScope);
  742. smalltalk.addMethod(
  743. smalltalk.method({
  744. selector: "removeNonLocalReturn:",
  745. protocol: 'adding',
  746. fn: function (aScope){
  747. var self=this;
  748. return smalltalk.withContext(function($ctx1) {
  749. _st(self._nonLocalReturns())._remove_ifAbsent_(aScope,(function(){
  750. }));
  751. return self}, function($ctx1) {$ctx1.fill(self,"removeNonLocalReturn:",{aScope:aScope},globals.MethodLexicalScope)})},
  752. args: ["aScope"],
  753. source: "removeNonLocalReturn: aScope\x0a\x09self nonLocalReturns remove: aScope ifAbsent: []",
  754. messageSends: ["remove:ifAbsent:", "nonLocalReturns"],
  755. referencedClasses: []
  756. }),
  757. globals.MethodLexicalScope);
  758. smalltalk.addMethod(
  759. smalltalk.method({
  760. selector: "unknownVariables",
  761. protocol: 'accessing',
  762. fn: function (){
  763. var self=this;
  764. function $OrderedCollection(){return globals.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  765. return smalltalk.withContext(function($ctx1) {
  766. var $2,$1,$receiver;
  767. $2=self["@unknownVariables"];
  768. if(($receiver = $2) == null || $receiver.isNil){
  769. self["@unknownVariables"]=_st($OrderedCollection())._new();
  770. $1=self["@unknownVariables"];
  771. } else {
  772. $1=$2;
  773. };
  774. return $1;
  775. }, function($ctx1) {$ctx1.fill(self,"unknownVariables",{},globals.MethodLexicalScope)})},
  776. args: [],
  777. source: "unknownVariables\x0a\x09^ unknownVariables ifNil: [ unknownVariables := OrderedCollection new ]",
  778. messageSends: ["ifNil:", "new"],
  779. referencedClasses: ["OrderedCollection"]
  780. }),
  781. globals.MethodLexicalScope);
  782. smalltalk.addClass('ScopeVar', globals.Object, ['scope', 'name'], 'Compiler-Semantic');
  783. 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.";
  784. smalltalk.addMethod(
  785. smalltalk.method({
  786. selector: "alias",
  787. protocol: 'accessing',
  788. fn: function (){
  789. var self=this;
  790. return smalltalk.withContext(function($ctx1) {
  791. var $1;
  792. $1=_st(self._name())._asVariableName();
  793. return $1;
  794. }, function($ctx1) {$ctx1.fill(self,"alias",{},globals.ScopeVar)})},
  795. args: [],
  796. source: "alias\x0a\x09^ self name asVariableName",
  797. messageSends: ["asVariableName", "name"],
  798. referencedClasses: []
  799. }),
  800. globals.ScopeVar);
  801. smalltalk.addMethod(
  802. smalltalk.method({
  803. selector: "isArgVar",
  804. protocol: 'testing',
  805. fn: function (){
  806. var self=this;
  807. return false;
  808. },
  809. args: [],
  810. source: "isArgVar\x0a\x09^ false",
  811. messageSends: [],
  812. referencedClasses: []
  813. }),
  814. globals.ScopeVar);
  815. smalltalk.addMethod(
  816. smalltalk.method({
  817. selector: "isClassRefVar",
  818. protocol: 'testing',
  819. fn: function (){
  820. var self=this;
  821. return false;
  822. },
  823. args: [],
  824. source: "isClassRefVar\x0a\x09^ false",
  825. messageSends: [],
  826. referencedClasses: []
  827. }),
  828. globals.ScopeVar);
  829. smalltalk.addMethod(
  830. smalltalk.method({
  831. selector: "isImmutable",
  832. protocol: 'testing',
  833. fn: function (){
  834. var self=this;
  835. return false;
  836. },
  837. args: [],
  838. source: "isImmutable\x0a\x09^ false",
  839. messageSends: [],
  840. referencedClasses: []
  841. }),
  842. globals.ScopeVar);
  843. smalltalk.addMethod(
  844. smalltalk.method({
  845. selector: "isInstanceVar",
  846. protocol: 'testing',
  847. fn: function (){
  848. var self=this;
  849. return false;
  850. },
  851. args: [],
  852. source: "isInstanceVar\x0a\x09^ false",
  853. messageSends: [],
  854. referencedClasses: []
  855. }),
  856. globals.ScopeVar);
  857. smalltalk.addMethod(
  858. smalltalk.method({
  859. selector: "isPseudoVar",
  860. protocol: 'testing',
  861. fn: function (){
  862. var self=this;
  863. return false;
  864. },
  865. args: [],
  866. source: "isPseudoVar\x0a\x09^ false",
  867. messageSends: [],
  868. referencedClasses: []
  869. }),
  870. globals.ScopeVar);
  871. smalltalk.addMethod(
  872. smalltalk.method({
  873. selector: "isTempVar",
  874. protocol: 'testing',
  875. fn: function (){
  876. var self=this;
  877. return false;
  878. },
  879. args: [],
  880. source: "isTempVar\x0a\x09^ false",
  881. messageSends: [],
  882. referencedClasses: []
  883. }),
  884. globals.ScopeVar);
  885. smalltalk.addMethod(
  886. smalltalk.method({
  887. selector: "isUnknownVar",
  888. protocol: 'testing',
  889. fn: function (){
  890. var self=this;
  891. return false;
  892. },
  893. args: [],
  894. source: "isUnknownVar\x0a\x09^ false",
  895. messageSends: [],
  896. referencedClasses: []
  897. }),
  898. globals.ScopeVar);
  899. smalltalk.addMethod(
  900. smalltalk.method({
  901. selector: "name",
  902. protocol: 'accessing',
  903. fn: function (){
  904. var self=this;
  905. var $1;
  906. $1=self["@name"];
  907. return $1;
  908. },
  909. args: [],
  910. source: "name\x0a\x09^ name",
  911. messageSends: [],
  912. referencedClasses: []
  913. }),
  914. globals.ScopeVar);
  915. smalltalk.addMethod(
  916. smalltalk.method({
  917. selector: "name:",
  918. protocol: 'accessing',
  919. fn: function (aString){
  920. var self=this;
  921. self["@name"]=aString;
  922. return self},
  923. args: ["aString"],
  924. source: "name: aString\x0a\x09name := aString",
  925. messageSends: [],
  926. referencedClasses: []
  927. }),
  928. globals.ScopeVar);
  929. smalltalk.addMethod(
  930. smalltalk.method({
  931. selector: "scope",
  932. protocol: 'accessing',
  933. fn: function (){
  934. var self=this;
  935. var $1;
  936. $1=self["@scope"];
  937. return $1;
  938. },
  939. args: [],
  940. source: "scope\x0a\x09^ scope",
  941. messageSends: [],
  942. referencedClasses: []
  943. }),
  944. globals.ScopeVar);
  945. smalltalk.addMethod(
  946. smalltalk.method({
  947. selector: "scope:",
  948. protocol: 'accessing',
  949. fn: function (aScope){
  950. var self=this;
  951. self["@scope"]=aScope;
  952. return self},
  953. args: ["aScope"],
  954. source: "scope: aScope\x0a\x09scope := aScope",
  955. messageSends: [],
  956. referencedClasses: []
  957. }),
  958. globals.ScopeVar);
  959. smalltalk.addMethod(
  960. smalltalk.method({
  961. selector: "validateAssignment",
  962. protocol: 'testing',
  963. fn: function (){
  964. var self=this;
  965. function $InvalidAssignmentError(){return globals.InvalidAssignmentError||(typeof InvalidAssignmentError=="undefined"?nil:InvalidAssignmentError)}
  966. return smalltalk.withContext(function($ctx1) {
  967. var $1,$2,$3;
  968. $1=_st(self._isArgVar())._or_((function(){
  969. return smalltalk.withContext(function($ctx2) {
  970. return self._isPseudoVar();
  971. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  972. if(smalltalk.assert($1)){
  973. $2=_st($InvalidAssignmentError())._new();
  974. _st($2)._variableName_(self._name());
  975. $3=_st($2)._signal();
  976. $3;
  977. };
  978. return self}, function($ctx1) {$ctx1.fill(self,"validateAssignment",{},globals.ScopeVar)})},
  979. args: [],
  980. source: "validateAssignment\x0a\x09(self isArgVar or: [ self isPseudoVar ]) ifTrue: [\x0a\x09\x09InvalidAssignmentError new\x0a\x09\x09\x09variableName: self name;\x0a\x09\x09\x09signal]",
  981. messageSends: ["ifTrue:", "or:", "isArgVar", "isPseudoVar", "variableName:", "new", "name", "signal"],
  982. referencedClasses: ["InvalidAssignmentError"]
  983. }),
  984. globals.ScopeVar);
  985. smalltalk.addMethod(
  986. smalltalk.method({
  987. selector: "on:",
  988. protocol: 'instance creation',
  989. fn: function (aString){
  990. var self=this;
  991. return smalltalk.withContext(function($ctx1) {
  992. var $2,$3,$1;
  993. $2=self._new();
  994. _st($2)._name_(aString);
  995. $3=_st($2)._yourself();
  996. $1=$3;
  997. return $1;
  998. }, function($ctx1) {$ctx1.fill(self,"on:",{aString:aString},globals.ScopeVar.klass)})},
  999. args: ["aString"],
  1000. source: "on: aString\x0a\x09^ self new\x0a\x09\x09name: aString;\x0a\x09\x09yourself",
  1001. messageSends: ["name:", "new", "yourself"],
  1002. referencedClasses: []
  1003. }),
  1004. globals.ScopeVar.klass);
  1005. smalltalk.addClass('AliasVar', globals.ScopeVar, ['node'], 'Compiler-Semantic');
  1006. globals.AliasVar.comment="I am an internally defined variable by the compiler";
  1007. smalltalk.addMethod(
  1008. smalltalk.method({
  1009. selector: "node",
  1010. protocol: 'accessing',
  1011. fn: function (){
  1012. var self=this;
  1013. var $1;
  1014. $1=self["@node"];
  1015. return $1;
  1016. },
  1017. args: [],
  1018. source: "node\x0a\x09^ node",
  1019. messageSends: [],
  1020. referencedClasses: []
  1021. }),
  1022. globals.AliasVar);
  1023. smalltalk.addMethod(
  1024. smalltalk.method({
  1025. selector: "node:",
  1026. protocol: 'accessing',
  1027. fn: function (aNode){
  1028. var self=this;
  1029. self["@node"]=aNode;
  1030. return self},
  1031. args: ["aNode"],
  1032. source: "node: aNode\x0a\x09node := aNode",
  1033. messageSends: [],
  1034. referencedClasses: []
  1035. }),
  1036. globals.AliasVar);
  1037. smalltalk.addClass('ArgVar', globals.ScopeVar, [], 'Compiler-Semantic');
  1038. globals.ArgVar.comment="I am an argument of a method or block.";
  1039. smalltalk.addMethod(
  1040. smalltalk.method({
  1041. selector: "isArgVar",
  1042. protocol: 'testing',
  1043. fn: function (){
  1044. var self=this;
  1045. return true;
  1046. },
  1047. args: [],
  1048. source: "isArgVar\x0a\x09^ true",
  1049. messageSends: [],
  1050. referencedClasses: []
  1051. }),
  1052. globals.ArgVar);
  1053. smalltalk.addMethod(
  1054. smalltalk.method({
  1055. selector: "isImmutable",
  1056. protocol: 'testing',
  1057. fn: function (){
  1058. var self=this;
  1059. return true;
  1060. },
  1061. args: [],
  1062. source: "isImmutable\x0a\x09^ true",
  1063. messageSends: [],
  1064. referencedClasses: []
  1065. }),
  1066. globals.ArgVar);
  1067. smalltalk.addClass('ClassRefVar', globals.ScopeVar, [], 'Compiler-Semantic');
  1068. globals.ClassRefVar.comment="I am an class reference variable";
  1069. smalltalk.addMethod(
  1070. smalltalk.method({
  1071. selector: "alias",
  1072. protocol: 'accessing',
  1073. fn: function (){
  1074. var self=this;
  1075. return smalltalk.withContext(function($ctx1) {
  1076. var $1;
  1077. $1=_st("$".__comma(self._name())).__comma("()");
  1078. $ctx1.sendIdx[","]=1;
  1079. return $1;
  1080. }, function($ctx1) {$ctx1.fill(self,"alias",{},globals.ClassRefVar)})},
  1081. args: [],
  1082. 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^ '$', self name, '()'",
  1083. messageSends: [",", "name"],
  1084. referencedClasses: []
  1085. }),
  1086. globals.ClassRefVar);
  1087. smalltalk.addMethod(
  1088. smalltalk.method({
  1089. selector: "isClassRefVar",
  1090. protocol: 'testing',
  1091. fn: function (){
  1092. var self=this;
  1093. return true;
  1094. },
  1095. args: [],
  1096. source: "isClassRefVar\x0a\x09^ true",
  1097. messageSends: [],
  1098. referencedClasses: []
  1099. }),
  1100. globals.ClassRefVar);
  1101. smalltalk.addMethod(
  1102. smalltalk.method({
  1103. selector: "isImmutable",
  1104. protocol: 'testing',
  1105. fn: function (){
  1106. var self=this;
  1107. return true;
  1108. },
  1109. args: [],
  1110. source: "isImmutable\x0a\x09^ true",
  1111. messageSends: [],
  1112. referencedClasses: []
  1113. }),
  1114. globals.ClassRefVar);
  1115. smalltalk.addClass('InstanceVar', globals.ScopeVar, [], 'Compiler-Semantic');
  1116. globals.InstanceVar.comment="I am an instance variable of a method or block.";
  1117. smalltalk.addMethod(
  1118. smalltalk.method({
  1119. selector: "alias",
  1120. protocol: 'testing',
  1121. fn: function (){
  1122. var self=this;
  1123. return smalltalk.withContext(function($ctx1) {
  1124. var $1;
  1125. $1=_st("self[\x22@".__comma(self._name())).__comma("\x22]");
  1126. $ctx1.sendIdx[","]=1;
  1127. return $1;
  1128. }, function($ctx1) {$ctx1.fill(self,"alias",{},globals.InstanceVar)})},
  1129. args: [],
  1130. source: "alias\x0a\x09^ 'self[\x22@', self name, '\x22]'",
  1131. messageSends: [",", "name"],
  1132. referencedClasses: []
  1133. }),
  1134. globals.InstanceVar);
  1135. smalltalk.addMethod(
  1136. smalltalk.method({
  1137. selector: "isInstanceVar",
  1138. protocol: 'testing',
  1139. fn: function (){
  1140. var self=this;
  1141. return true;
  1142. },
  1143. args: [],
  1144. source: "isInstanceVar\x0a\x09^ true",
  1145. messageSends: [],
  1146. referencedClasses: []
  1147. }),
  1148. globals.InstanceVar);
  1149. smalltalk.addClass('PseudoVar', globals.ScopeVar, [], 'Compiler-Semantic');
  1150. globals.PseudoVar.comment="I am an pseudo variable.\x0a\x0aThe five Smalltalk pseudo variables are: 'self', 'super', 'nil', 'true' and 'false'";
  1151. smalltalk.addMethod(
  1152. smalltalk.method({
  1153. selector: "alias",
  1154. protocol: 'accessing',
  1155. fn: function (){
  1156. var self=this;
  1157. return smalltalk.withContext(function($ctx1) {
  1158. var $1;
  1159. $1=self._name();
  1160. return $1;
  1161. }, function($ctx1) {$ctx1.fill(self,"alias",{},globals.PseudoVar)})},
  1162. args: [],
  1163. source: "alias\x0a\x09^ self name",
  1164. messageSends: ["name"],
  1165. referencedClasses: []
  1166. }),
  1167. globals.PseudoVar);
  1168. smalltalk.addMethod(
  1169. smalltalk.method({
  1170. selector: "isImmutable",
  1171. protocol: 'testing',
  1172. fn: function (){
  1173. var self=this;
  1174. return true;
  1175. },
  1176. args: [],
  1177. source: "isImmutable\x0a\x09^ true",
  1178. messageSends: [],
  1179. referencedClasses: []
  1180. }),
  1181. globals.PseudoVar);
  1182. smalltalk.addMethod(
  1183. smalltalk.method({
  1184. selector: "isPseudoVar",
  1185. protocol: 'testing',
  1186. fn: function (){
  1187. var self=this;
  1188. return true;
  1189. },
  1190. args: [],
  1191. source: "isPseudoVar\x0a\x09^ true",
  1192. messageSends: [],
  1193. referencedClasses: []
  1194. }),
  1195. globals.PseudoVar);
  1196. smalltalk.addClass('TempVar', globals.ScopeVar, [], 'Compiler-Semantic');
  1197. globals.TempVar.comment="I am an temporary variable of a method or block.";
  1198. smalltalk.addMethod(
  1199. smalltalk.method({
  1200. selector: "isTempVar",
  1201. protocol: 'testing',
  1202. fn: function (){
  1203. var self=this;
  1204. return true;
  1205. },
  1206. args: [],
  1207. source: "isTempVar\x0a\x09^ true",
  1208. messageSends: [],
  1209. referencedClasses: []
  1210. }),
  1211. globals.TempVar);
  1212. smalltalk.addClass('UnknownVar', globals.ScopeVar, [], 'Compiler-Semantic');
  1213. globals.UnknownVar.comment="I am an unknown variable. Amber uses unknown variables as JavaScript globals";
  1214. smalltalk.addMethod(
  1215. smalltalk.method({
  1216. selector: "isUnknownVar",
  1217. protocol: 'testing',
  1218. fn: function (){
  1219. var self=this;
  1220. return true;
  1221. },
  1222. args: [],
  1223. source: "isUnknownVar\x0a\x09^ true",
  1224. messageSends: [],
  1225. referencedClasses: []
  1226. }),
  1227. globals.UnknownVar);
  1228. smalltalk.addClass('SemanticAnalyzer', globals.NodeVisitor, ['currentScope', 'blockIndex', 'theClass', 'classReferences', 'messageSends', 'superSends'], 'Compiler-Semantic');
  1229. globals.SemanticAnalyzer.comment="I semantically analyze the abstract syntax tree and annotate it with informations such as non local returns and variable scopes.";
  1230. smalltalk.addMethod(
  1231. smalltalk.method({
  1232. selector: "classReferences",
  1233. protocol: 'accessing',
  1234. fn: function (){
  1235. var self=this;
  1236. function $Set(){return globals.Set||(typeof Set=="undefined"?nil:Set)}
  1237. return smalltalk.withContext(function($ctx1) {
  1238. var $2,$1,$receiver;
  1239. $2=self["@classReferences"];
  1240. if(($receiver = $2) == null || $receiver.isNil){
  1241. self["@classReferences"]=_st($Set())._new();
  1242. $1=self["@classReferences"];
  1243. } else {
  1244. $1=$2;
  1245. };
  1246. return $1;
  1247. }, function($ctx1) {$ctx1.fill(self,"classReferences",{},globals.SemanticAnalyzer)})},
  1248. args: [],
  1249. source: "classReferences\x0a\x09^ classReferences ifNil: [ classReferences := Set new ]",
  1250. messageSends: ["ifNil:", "new"],
  1251. referencedClasses: ["Set"]
  1252. }),
  1253. globals.SemanticAnalyzer);
  1254. smalltalk.addMethod(
  1255. smalltalk.method({
  1256. selector: "errorShadowingVariable:",
  1257. protocol: 'error handling',
  1258. fn: function (aString){
  1259. var self=this;
  1260. function $ShadowingVariableError(){return globals.ShadowingVariableError||(typeof ShadowingVariableError=="undefined"?nil:ShadowingVariableError)}
  1261. return smalltalk.withContext(function($ctx1) {
  1262. var $1,$2;
  1263. $1=_st($ShadowingVariableError())._new();
  1264. _st($1)._variableName_(aString);
  1265. $2=_st($1)._signal();
  1266. return self}, function($ctx1) {$ctx1.fill(self,"errorShadowingVariable:",{aString:aString},globals.SemanticAnalyzer)})},
  1267. args: ["aString"],
  1268. source: "errorShadowingVariable: aString\x0a\x09ShadowingVariableError new\x0a\x09\x09variableName: aString;\x0a\x09\x09signal",
  1269. messageSends: ["variableName:", "new", "signal"],
  1270. referencedClasses: ["ShadowingVariableError"]
  1271. }),
  1272. globals.SemanticAnalyzer);
  1273. smalltalk.addMethod(
  1274. smalltalk.method({
  1275. selector: "errorUnknownVariable:",
  1276. protocol: 'error handling',
  1277. fn: function (aNode){
  1278. var self=this;
  1279. var identifier;
  1280. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1281. function $UnknownVariableError(){return globals.UnknownVariableError||(typeof UnknownVariableError=="undefined"?nil:UnknownVariableError)}
  1282. return smalltalk.withContext(function($ctx1) {
  1283. var $1,$2,$3,$4,$5;
  1284. identifier=_st(aNode)._value();
  1285. $ctx1.sendIdx["value"]=1;
  1286. $1=_st(_st(_st(_st($Smalltalk())._globalJsVariables())._includes_(identifier))._not())._and_((function(){
  1287. return smalltalk.withContext(function($ctx2) {
  1288. return self._isVariableGloballyUndefined_(identifier);
  1289. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  1290. if(smalltalk.assert($1)){
  1291. $2=_st($UnknownVariableError())._new();
  1292. $3=$2;
  1293. $4=_st(aNode)._value();
  1294. $ctx1.sendIdx["value"]=2;
  1295. _st($3)._variableName_($4);
  1296. $5=_st($2)._signal();
  1297. $5;
  1298. } else {
  1299. _st(_st(_st(self["@currentScope"])._methodScope())._unknownVariables())._add_(_st(aNode)._value());
  1300. };
  1301. return self}, function($ctx1) {$ctx1.fill(self,"errorUnknownVariable:",{aNode:aNode,identifier:identifier},globals.SemanticAnalyzer)})},
  1302. args: ["aNode"],
  1303. 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: `jQuery`, `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 isVariableGloballyUndefined: identifier ])\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 ]",
  1304. messageSends: ["value", "ifTrue:ifFalse:", "and:", "not", "includes:", "globalJsVariables", "isVariableGloballyUndefined:", "variableName:", "new", "signal", "add:", "unknownVariables", "methodScope"],
  1305. referencedClasses: ["Smalltalk", "UnknownVariableError"]
  1306. }),
  1307. globals.SemanticAnalyzer);
  1308. smalltalk.addMethod(
  1309. smalltalk.method({
  1310. selector: "isVariableGloballyUndefined:",
  1311. protocol: 'testing',
  1312. fn: function (aString){
  1313. var self=this;
  1314. return smalltalk.withContext(function($ctx1) {
  1315. return eval('typeof ' + aString + ' == "undefined"');
  1316. return self}, function($ctx1) {$ctx1.fill(self,"isVariableGloballyUndefined:",{aString:aString},globals.SemanticAnalyzer)})},
  1317. args: ["aString"],
  1318. source: "isVariableGloballyUndefined: aString\x0a\x09<return eval('typeof ' + aString + ' == \x22undefined\x22')>",
  1319. messageSends: [],
  1320. referencedClasses: []
  1321. }),
  1322. globals.SemanticAnalyzer);
  1323. smalltalk.addMethod(
  1324. smalltalk.method({
  1325. selector: "messageSends",
  1326. protocol: 'accessing',
  1327. fn: function (){
  1328. var self=this;
  1329. function $Dictionary(){return globals.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  1330. return smalltalk.withContext(function($ctx1) {
  1331. var $2,$1,$receiver;
  1332. $2=self["@messageSends"];
  1333. if(($receiver = $2) == null || $receiver.isNil){
  1334. self["@messageSends"]=_st($Dictionary())._new();
  1335. $1=self["@messageSends"];
  1336. } else {
  1337. $1=$2;
  1338. };
  1339. return $1;
  1340. }, function($ctx1) {$ctx1.fill(self,"messageSends",{},globals.SemanticAnalyzer)})},
  1341. args: [],
  1342. source: "messageSends\x0a\x09^ messageSends ifNil: [ messageSends := Dictionary new ]",
  1343. messageSends: ["ifNil:", "new"],
  1344. referencedClasses: ["Dictionary"]
  1345. }),
  1346. globals.SemanticAnalyzer);
  1347. smalltalk.addMethod(
  1348. smalltalk.method({
  1349. selector: "newBlockScope",
  1350. protocol: 'factory',
  1351. fn: function (){
  1352. var self=this;
  1353. function $LexicalScope(){return globals.LexicalScope||(typeof LexicalScope=="undefined"?nil:LexicalScope)}
  1354. return smalltalk.withContext(function($ctx1) {
  1355. var $1;
  1356. $1=self._newScopeOfClass_($LexicalScope());
  1357. return $1;
  1358. }, function($ctx1) {$ctx1.fill(self,"newBlockScope",{},globals.SemanticAnalyzer)})},
  1359. args: [],
  1360. source: "newBlockScope\x0a\x09^ self newScopeOfClass: LexicalScope",
  1361. messageSends: ["newScopeOfClass:"],
  1362. referencedClasses: ["LexicalScope"]
  1363. }),
  1364. globals.SemanticAnalyzer);
  1365. smalltalk.addMethod(
  1366. smalltalk.method({
  1367. selector: "newMethodScope",
  1368. protocol: 'factory',
  1369. fn: function (){
  1370. var self=this;
  1371. function $MethodLexicalScope(){return globals.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1372. return smalltalk.withContext(function($ctx1) {
  1373. var $1;
  1374. $1=self._newScopeOfClass_($MethodLexicalScope());
  1375. return $1;
  1376. }, function($ctx1) {$ctx1.fill(self,"newMethodScope",{},globals.SemanticAnalyzer)})},
  1377. args: [],
  1378. source: "newMethodScope\x0a\x09^ self newScopeOfClass: MethodLexicalScope",
  1379. messageSends: ["newScopeOfClass:"],
  1380. referencedClasses: ["MethodLexicalScope"]
  1381. }),
  1382. globals.SemanticAnalyzer);
  1383. smalltalk.addMethod(
  1384. smalltalk.method({
  1385. selector: "newScopeOfClass:",
  1386. protocol: 'factory',
  1387. fn: function (aLexicalScopeClass){
  1388. var self=this;
  1389. return smalltalk.withContext(function($ctx1) {
  1390. var $2,$3,$1;
  1391. $2=_st(aLexicalScopeClass)._new();
  1392. _st($2)._outerScope_(self["@currentScope"]);
  1393. $3=_st($2)._yourself();
  1394. $1=$3;
  1395. return $1;
  1396. }, function($ctx1) {$ctx1.fill(self,"newScopeOfClass:",{aLexicalScopeClass:aLexicalScopeClass},globals.SemanticAnalyzer)})},
  1397. args: ["aLexicalScopeClass"],
  1398. source: "newScopeOfClass: aLexicalScopeClass\x0a\x09^ aLexicalScopeClass new\x0a\x09\x09outerScope: currentScope;\x0a\x09\x09yourself",
  1399. messageSends: ["outerScope:", "new", "yourself"],
  1400. referencedClasses: []
  1401. }),
  1402. globals.SemanticAnalyzer);
  1403. smalltalk.addMethod(
  1404. smalltalk.method({
  1405. selector: "nextBlockIndex",
  1406. protocol: 'private',
  1407. fn: function (){
  1408. var self=this;
  1409. return smalltalk.withContext(function($ctx1) {
  1410. var $1,$2,$receiver;
  1411. $1=self["@blockIndex"];
  1412. if(($receiver = $1) == null || $receiver.isNil){
  1413. self["@blockIndex"]=(0);
  1414. self["@blockIndex"];
  1415. } else {
  1416. $1;
  1417. };
  1418. self["@blockIndex"]=_st(self["@blockIndex"]).__plus((1));
  1419. $2=self["@blockIndex"];
  1420. return $2;
  1421. }, function($ctx1) {$ctx1.fill(self,"nextBlockIndex",{},globals.SemanticAnalyzer)})},
  1422. args: [],
  1423. source: "nextBlockIndex\x0a\x09blockIndex ifNil: [ blockIndex := 0 ].\x0a\x09\x0a\x09blockIndex := blockIndex + 1.\x0a\x09^ blockIndex",
  1424. messageSends: ["ifNil:", "+"],
  1425. referencedClasses: []
  1426. }),
  1427. globals.SemanticAnalyzer);
  1428. smalltalk.addMethod(
  1429. smalltalk.method({
  1430. selector: "popScope",
  1431. protocol: 'scope',
  1432. fn: function (){
  1433. var self=this;
  1434. return smalltalk.withContext(function($ctx1) {
  1435. var $1,$receiver;
  1436. $1=self["@currentScope"];
  1437. if(($receiver = $1) == null || $receiver.isNil){
  1438. $1;
  1439. } else {
  1440. self["@currentScope"]=_st(self["@currentScope"])._outerScope();
  1441. self["@currentScope"];
  1442. };
  1443. return self}, function($ctx1) {$ctx1.fill(self,"popScope",{},globals.SemanticAnalyzer)})},
  1444. args: [],
  1445. source: "popScope\x0a\x09currentScope ifNotNil: [\x0a\x09\x09currentScope := currentScope outerScope ]",
  1446. messageSends: ["ifNotNil:", "outerScope"],
  1447. referencedClasses: []
  1448. }),
  1449. globals.SemanticAnalyzer);
  1450. smalltalk.addMethod(
  1451. smalltalk.method({
  1452. selector: "pushScope:",
  1453. protocol: 'scope',
  1454. fn: function (aScope){
  1455. var self=this;
  1456. return smalltalk.withContext(function($ctx1) {
  1457. _st(aScope)._outerScope_(self["@currentScope"]);
  1458. self["@currentScope"]=aScope;
  1459. return self}, function($ctx1) {$ctx1.fill(self,"pushScope:",{aScope:aScope},globals.SemanticAnalyzer)})},
  1460. args: ["aScope"],
  1461. source: "pushScope: aScope\x0a\x09aScope outerScope: currentScope.\x0a\x09currentScope := aScope",
  1462. messageSends: ["outerScope:"],
  1463. referencedClasses: []
  1464. }),
  1465. globals.SemanticAnalyzer);
  1466. smalltalk.addMethod(
  1467. smalltalk.method({
  1468. selector: "superSends",
  1469. protocol: 'accessing',
  1470. fn: function (){
  1471. var self=this;
  1472. function $Dictionary(){return globals.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  1473. return smalltalk.withContext(function($ctx1) {
  1474. var $2,$1,$receiver;
  1475. $2=self["@superSends"];
  1476. if(($receiver = $2) == null || $receiver.isNil){
  1477. self["@superSends"]=_st($Dictionary())._new();
  1478. $1=self["@superSends"];
  1479. } else {
  1480. $1=$2;
  1481. };
  1482. return $1;
  1483. }, function($ctx1) {$ctx1.fill(self,"superSends",{},globals.SemanticAnalyzer)})},
  1484. args: [],
  1485. source: "superSends\x0a\x09^ superSends ifNil: [ superSends := Dictionary new ]",
  1486. messageSends: ["ifNil:", "new"],
  1487. referencedClasses: ["Dictionary"]
  1488. }),
  1489. globals.SemanticAnalyzer);
  1490. smalltalk.addMethod(
  1491. smalltalk.method({
  1492. selector: "theClass",
  1493. protocol: 'accessing',
  1494. fn: function (){
  1495. var self=this;
  1496. var $1;
  1497. $1=self["@theClass"];
  1498. return $1;
  1499. },
  1500. args: [],
  1501. source: "theClass\x0a\x09^ theClass",
  1502. messageSends: [],
  1503. referencedClasses: []
  1504. }),
  1505. globals.SemanticAnalyzer);
  1506. smalltalk.addMethod(
  1507. smalltalk.method({
  1508. selector: "theClass:",
  1509. protocol: 'accessing',
  1510. fn: function (aClass){
  1511. var self=this;
  1512. self["@theClass"]=aClass;
  1513. return self},
  1514. args: ["aClass"],
  1515. source: "theClass: aClass\x0a\x09theClass := aClass",
  1516. messageSends: [],
  1517. referencedClasses: []
  1518. }),
  1519. globals.SemanticAnalyzer);
  1520. smalltalk.addMethod(
  1521. smalltalk.method({
  1522. selector: "validateVariableScope:",
  1523. protocol: 'scope',
  1524. fn: function (aString){
  1525. var self=this;
  1526. return smalltalk.withContext(function($ctx1) {
  1527. var $1,$receiver;
  1528. $1=_st(self["@currentScope"])._lookupVariable_(aString);
  1529. if(($receiver = $1) == null || $receiver.isNil){
  1530. $1;
  1531. } else {
  1532. self._errorShadowingVariable_(aString);
  1533. };
  1534. return self}, function($ctx1) {$ctx1.fill(self,"validateVariableScope:",{aString:aString},globals.SemanticAnalyzer)})},
  1535. args: ["aString"],
  1536. 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 ]",
  1537. messageSends: ["ifNotNil:", "lookupVariable:", "errorShadowingVariable:"],
  1538. referencedClasses: []
  1539. }),
  1540. globals.SemanticAnalyzer);
  1541. smalltalk.addMethod(
  1542. smalltalk.method({
  1543. selector: "visitAssignmentNode:",
  1544. protocol: 'visiting',
  1545. fn: function (aNode){
  1546. var self=this;
  1547. return smalltalk.withContext(function($ctx1) {
  1548. ($ctx1.supercall = true, globals.SemanticAnalyzer.superclass.fn.prototype._visitAssignmentNode_.apply(_st(self), [aNode]));
  1549. $ctx1.supercall = false;
  1550. _st(_st(aNode)._left())._beAssigned();
  1551. return self}, function($ctx1) {$ctx1.fill(self,"visitAssignmentNode:",{aNode:aNode},globals.SemanticAnalyzer)})},
  1552. args: ["aNode"],
  1553. source: "visitAssignmentNode: aNode\x0a\x09super visitAssignmentNode: aNode.\x0a\x09aNode left beAssigned",
  1554. messageSends: ["visitAssignmentNode:", "beAssigned", "left"],
  1555. referencedClasses: []
  1556. }),
  1557. globals.SemanticAnalyzer);
  1558. smalltalk.addMethod(
  1559. smalltalk.method({
  1560. selector: "visitBlockNode:",
  1561. protocol: 'visiting',
  1562. fn: function (aNode){
  1563. var self=this;
  1564. return smalltalk.withContext(function($ctx1) {
  1565. self._pushScope_(self._newBlockScope());
  1566. _st(aNode)._scope_(self["@currentScope"]);
  1567. _st(self["@currentScope"])._node_(aNode);
  1568. _st(self["@currentScope"])._blockIndex_(self._nextBlockIndex());
  1569. _st(_st(aNode)._parameters())._do_((function(each){
  1570. return smalltalk.withContext(function($ctx2) {
  1571. self._validateVariableScope_(each);
  1572. return _st(self["@currentScope"])._addArg_(each);
  1573. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1574. ($ctx1.supercall = true, globals.SemanticAnalyzer.superclass.fn.prototype._visitBlockNode_.apply(_st(self), [aNode]));
  1575. $ctx1.supercall = false;
  1576. self._popScope();
  1577. return self}, function($ctx1) {$ctx1.fill(self,"visitBlockNode:",{aNode:aNode},globals.SemanticAnalyzer)})},
  1578. args: ["aNode"],
  1579. 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",
  1580. messageSends: ["pushScope:", "newBlockScope", "scope:", "node:", "blockIndex:", "nextBlockIndex", "do:", "parameters", "validateVariableScope:", "addArg:", "visitBlockNode:", "popScope"],
  1581. referencedClasses: []
  1582. }),
  1583. globals.SemanticAnalyzer);
  1584. smalltalk.addMethod(
  1585. smalltalk.method({
  1586. selector: "visitCascadeNode:",
  1587. protocol: 'visiting',
  1588. fn: function (aNode){
  1589. var self=this;
  1590. return smalltalk.withContext(function($ctx1) {
  1591. var $3,$2,$1;
  1592. ($ctx1.supercall = true, globals.SemanticAnalyzer.superclass.fn.prototype._visitCascadeNode_.apply(_st(self), [aNode]));
  1593. $ctx1.supercall = false;
  1594. $3=_st(aNode)._nodes();
  1595. $ctx1.sendIdx["nodes"]=1;
  1596. $2=_st($3)._first();
  1597. $1=_st($2)._superSend();
  1598. if(smalltalk.assert($1)){
  1599. _st(_st(aNode)._nodes())._do_((function(each){
  1600. return smalltalk.withContext(function($ctx2) {
  1601. return _st(each)._superSend_(true);
  1602. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})}));
  1603. };
  1604. return self}, function($ctx1) {$ctx1.fill(self,"visitCascadeNode:",{aNode:aNode},globals.SemanticAnalyzer)})},
  1605. args: ["aNode"],
  1606. source: "visitCascadeNode: aNode\x0a\x09super visitCascadeNode: aNode.\x0a\x09aNode nodes first superSend ifTrue: [\x0a\x09\x09aNode nodes do: [ :each | each superSend: true ] ]",
  1607. messageSends: ["visitCascadeNode:", "ifTrue:", "superSend", "first", "nodes", "do:", "superSend:"],
  1608. referencedClasses: []
  1609. }),
  1610. globals.SemanticAnalyzer);
  1611. smalltalk.addMethod(
  1612. smalltalk.method({
  1613. selector: "visitMethodNode:",
  1614. protocol: 'visiting',
  1615. fn: function (aNode){
  1616. var self=this;
  1617. return smalltalk.withContext(function($ctx1) {
  1618. var $1;
  1619. self._pushScope_(self._newMethodScope());
  1620. _st(aNode)._scope_(self["@currentScope"]);
  1621. _st(self["@currentScope"])._node_(aNode);
  1622. _st(_st(self._theClass())._allInstanceVariableNames())._do_((function(each){
  1623. return smalltalk.withContext(function($ctx2) {
  1624. return _st(self["@currentScope"])._addIVar_(each);
  1625. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1626. $ctx1.sendIdx["do:"]=1;
  1627. _st(_st(aNode)._arguments())._do_((function(each){
  1628. return smalltalk.withContext(function($ctx2) {
  1629. self._validateVariableScope_(each);
  1630. return _st(self["@currentScope"])._addArg_(each);
  1631. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})}));
  1632. ($ctx1.supercall = true, globals.SemanticAnalyzer.superclass.fn.prototype._visitMethodNode_.apply(_st(self), [aNode]));
  1633. $ctx1.supercall = false;
  1634. _st(aNode)._classReferences_(self._classReferences());
  1635. _st(aNode)._sendIndexes_(self._messageSends());
  1636. $1=_st(aNode)._superSends_(_st(self._superSends())._keys());
  1637. self._popScope();
  1638. return self}, function($ctx1) {$ctx1.fill(self,"visitMethodNode:",{aNode:aNode},globals.SemanticAnalyzer)})},
  1639. args: ["aNode"],
  1640. 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\x09\x09superSends: self superSends keys.\x0a\x09self popScope",
  1641. messageSends: ["pushScope:", "newMethodScope", "scope:", "node:", "do:", "allInstanceVariableNames", "theClass", "addIVar:", "arguments", "validateVariableScope:", "addArg:", "visitMethodNode:", "classReferences:", "classReferences", "sendIndexes:", "messageSends", "superSends:", "keys", "superSends", "popScope"],
  1642. referencedClasses: []
  1643. }),
  1644. globals.SemanticAnalyzer);
  1645. smalltalk.addMethod(
  1646. smalltalk.method({
  1647. selector: "visitReturnNode:",
  1648. protocol: 'visiting',
  1649. fn: function (aNode){
  1650. var self=this;
  1651. return smalltalk.withContext(function($ctx1) {
  1652. var $1;
  1653. _st(aNode)._scope_(self["@currentScope"]);
  1654. $1=_st(self["@currentScope"])._isMethodScope();
  1655. if(smalltalk.assert($1)){
  1656. _st(self["@currentScope"])._localReturn_(true);
  1657. } else {
  1658. _st(_st(self["@currentScope"])._methodScope())._addNonLocalReturn_(self["@currentScope"]);
  1659. };
  1660. ($ctx1.supercall = true, globals.SemanticAnalyzer.superclass.fn.prototype._visitReturnNode_.apply(_st(self), [aNode]));
  1661. $ctx1.supercall = false;
  1662. return self}, function($ctx1) {$ctx1.fill(self,"visitReturnNode:",{aNode:aNode},globals.SemanticAnalyzer)})},
  1663. args: ["aNode"],
  1664. 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",
  1665. messageSends: ["scope:", "ifTrue:ifFalse:", "isMethodScope", "localReturn:", "addNonLocalReturn:", "methodScope", "visitReturnNode:"],
  1666. referencedClasses: []
  1667. }),
  1668. globals.SemanticAnalyzer);
  1669. smalltalk.addMethod(
  1670. smalltalk.method({
  1671. selector: "visitSendNode:",
  1672. protocol: 'visiting',
  1673. fn: function (aNode){
  1674. var self=this;
  1675. function $Set(){return globals.Set||(typeof Set=="undefined"?nil:Set)}
  1676. function $IRSendInliner(){return globals.IRSendInliner||(typeof IRSendInliner=="undefined"?nil:IRSendInliner)}
  1677. return smalltalk.withContext(function($ctx1) {
  1678. var $3,$2,$1,$4,$5,$6,$8,$9,$7,$11,$12,$10,$13,$14,$15,$17,$18,$16,$receiver;
  1679. $3=_st(aNode)._receiver();
  1680. $ctx1.sendIdx["receiver"]=1;
  1681. $2=_st($3)._value();
  1682. $1=_st($2).__eq("super");
  1683. if(smalltalk.assert($1)){
  1684. _st(aNode)._superSend_(true);
  1685. $4=_st(aNode)._receiver();
  1686. $ctx1.sendIdx["receiver"]=2;
  1687. _st($4)._value_("self");
  1688. $5=self._superSends();
  1689. $ctx1.sendIdx["superSends"]=1;
  1690. $6=_st(aNode)._selector();
  1691. $ctx1.sendIdx["selector"]=1;
  1692. _st($5)._at_ifAbsentPut_($6,(function(){
  1693. return smalltalk.withContext(function($ctx2) {
  1694. return _st($Set())._new();
  1695. $ctx2.sendIdx["new"]=1;
  1696. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  1697. $ctx1.sendIdx["at:ifAbsentPut:"]=1;
  1698. $8=self._superSends();
  1699. $9=_st(aNode)._selector();
  1700. $ctx1.sendIdx["selector"]=2;
  1701. $7=_st($8)._at_($9);
  1702. $ctx1.sendIdx["at:"]=1;
  1703. _st($7)._add_(aNode);
  1704. $ctx1.sendIdx["add:"]=1;
  1705. } else {
  1706. $11=_st($IRSendInliner())._inlinedSelectors();
  1707. $12=_st(aNode)._selector();
  1708. $ctx1.sendIdx["selector"]=3;
  1709. $10=_st($11)._includes_($12);
  1710. if(smalltalk.assert($10)){
  1711. _st(aNode)._shouldBeInlined_(true);
  1712. $13=_st(aNode)._receiver();
  1713. if(($receiver = $13) == null || $receiver.isNil){
  1714. $13;
  1715. } else {
  1716. var receiver;
  1717. receiver=$receiver;
  1718. _st(receiver)._shouldBeAliased_(true);
  1719. };
  1720. };
  1721. };
  1722. $14=self._messageSends();
  1723. $ctx1.sendIdx["messageSends"]=1;
  1724. $15=_st(aNode)._selector();
  1725. $ctx1.sendIdx["selector"]=4;
  1726. _st($14)._at_ifAbsentPut_($15,(function(){
  1727. return smalltalk.withContext(function($ctx2) {
  1728. return _st($Set())._new();
  1729. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,6)})}));
  1730. $17=self._messageSends();
  1731. $ctx1.sendIdx["messageSends"]=2;
  1732. $18=_st(aNode)._selector();
  1733. $ctx1.sendIdx["selector"]=5;
  1734. $16=_st($17)._at_($18);
  1735. $ctx1.sendIdx["at:"]=2;
  1736. _st($16)._add_(aNode);
  1737. _st(aNode)._index_(_st(_st(self._messageSends())._at_(_st(aNode)._selector()))._size());
  1738. ($ctx1.supercall = true, globals.SemanticAnalyzer.superclass.fn.prototype._visitSendNode_.apply(_st(self), [aNode]));
  1739. $ctx1.supercall = false;
  1740. return self}, function($ctx1) {$ctx1.fill(self,"visitSendNode:",{aNode:aNode},globals.SemanticAnalyzer)})},
  1741. args: ["aNode"],
  1742. source: "visitSendNode: aNode\x0a\x0a\x09aNode receiver value = 'super'\x0a\x09\x09ifTrue: [\x0a\x09\x09\x09aNode superSend: true.\x0a\x09\x09\x09aNode receiver value: 'self'.\x0a\x09\x09\x09self superSends at: aNode selector ifAbsentPut: [ Set new ].\x0a\x09\x09\x09(self superSends at: aNode selector) add: aNode ]\x0a\x09\x09\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",
  1743. messageSends: ["ifTrue:ifFalse:", "=", "value", "receiver", "superSend:", "value:", "at:ifAbsentPut:", "superSends", "selector", "new", "add:", "at:", "ifTrue:", "includes:", "inlinedSelectors", "shouldBeInlined:", "ifNotNil:", "shouldBeAliased:", "messageSends", "index:", "size", "visitSendNode:"],
  1744. referencedClasses: ["Set", "IRSendInliner"]
  1745. }),
  1746. globals.SemanticAnalyzer);
  1747. smalltalk.addMethod(
  1748. smalltalk.method({
  1749. selector: "visitSequenceNode:",
  1750. protocol: 'visiting',
  1751. fn: function (aNode){
  1752. var self=this;
  1753. return smalltalk.withContext(function($ctx1) {
  1754. _st(_st(aNode)._temps())._do_((function(each){
  1755. return smalltalk.withContext(function($ctx2) {
  1756. self._validateVariableScope_(each);
  1757. return _st(self["@currentScope"])._addTemp_(each);
  1758. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1759. ($ctx1.supercall = true, globals.SemanticAnalyzer.superclass.fn.prototype._visitSequenceNode_.apply(_st(self), [aNode]));
  1760. $ctx1.supercall = false;
  1761. return self}, function($ctx1) {$ctx1.fill(self,"visitSequenceNode:",{aNode:aNode},globals.SemanticAnalyzer)})},
  1762. args: ["aNode"],
  1763. source: "visitSequenceNode: aNode\x0a\x09aNode temps do: [ :each |\x0a\x09\x09self validateVariableScope: each.\x0a\x09\x09currentScope addTemp: each ].\x0a\x0a\x09super visitSequenceNode: aNode",
  1764. messageSends: ["do:", "temps", "validateVariableScope:", "addTemp:", "visitSequenceNode:"],
  1765. referencedClasses: []
  1766. }),
  1767. globals.SemanticAnalyzer);
  1768. smalltalk.addMethod(
  1769. smalltalk.method({
  1770. selector: "visitVariableNode:",
  1771. protocol: 'visiting',
  1772. fn: function (aNode){
  1773. var self=this;
  1774. var binding;
  1775. function $ClassRefVar(){return globals.ClassRefVar||(typeof ClassRefVar=="undefined"?nil:ClassRefVar)}
  1776. function $UnknownVar(){return globals.UnknownVar||(typeof UnknownVar=="undefined"?nil:UnknownVar)}
  1777. return smalltalk.withContext(function($ctx1) {
  1778. var $1,$3,$2,$4,$5,$6,$7,$8,$9,$10,$11,$receiver;
  1779. binding=_st(self["@currentScope"])._lookupVariable_(aNode);
  1780. $1=binding;
  1781. if(($receiver = $1) == null || $receiver.isNil){
  1782. $3=_st(aNode)._value();
  1783. $ctx1.sendIdx["value"]=1;
  1784. $2=_st($3)._isCapitalized();
  1785. if(smalltalk.assert($2)){
  1786. $4=_st($ClassRefVar())._new();
  1787. $ctx1.sendIdx["new"]=1;
  1788. $5=$4;
  1789. $6=_st(aNode)._value();
  1790. $ctx1.sendIdx["value"]=2;
  1791. _st($5)._name_($6);
  1792. $ctx1.sendIdx["name:"]=1;
  1793. $7=_st($4)._yourself();
  1794. $ctx1.sendIdx["yourself"]=1;
  1795. binding=$7;
  1796. binding;
  1797. $8=self._classReferences();
  1798. $9=_st(aNode)._value();
  1799. $ctx1.sendIdx["value"]=3;
  1800. _st($8)._add_($9);
  1801. } else {
  1802. self._errorUnknownVariable_(aNode);
  1803. $10=_st($UnknownVar())._new();
  1804. _st($10)._name_(_st(aNode)._value());
  1805. $11=_st($10)._yourself();
  1806. binding=$11;
  1807. binding;
  1808. };
  1809. } else {
  1810. $1;
  1811. };
  1812. _st(aNode)._binding_(binding);
  1813. return self}, function($ctx1) {$ctx1.fill(self,"visitVariableNode:",{aNode:aNode,binding:binding},globals.SemanticAnalyzer)})},
  1814. args: ["aNode"],
  1815. 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.",
  1816. messageSends: ["lookupVariable:", "ifNil:", "ifTrue:ifFalse:", "isCapitalized", "value", "name:", "new", "yourself", "add:", "classReferences", "errorUnknownVariable:", "binding:"],
  1817. referencedClasses: ["ClassRefVar", "UnknownVar"]
  1818. }),
  1819. globals.SemanticAnalyzer);
  1820. smalltalk.addMethod(
  1821. smalltalk.method({
  1822. selector: "on:",
  1823. protocol: 'instance creation',
  1824. fn: function (aClass){
  1825. var self=this;
  1826. return smalltalk.withContext(function($ctx1) {
  1827. var $2,$3,$1;
  1828. $2=self._new();
  1829. _st($2)._theClass_(aClass);
  1830. $3=_st($2)._yourself();
  1831. $1=$3;
  1832. return $1;
  1833. }, function($ctx1) {$ctx1.fill(self,"on:",{aClass:aClass},globals.SemanticAnalyzer.klass)})},
  1834. args: ["aClass"],
  1835. source: "on: aClass\x0a\x09^ self new\x0a\x09\x09theClass: aClass;\x0a\x09\x09yourself",
  1836. messageSends: ["theClass:", "new", "yourself"],
  1837. referencedClasses: []
  1838. }),
  1839. globals.SemanticAnalyzer.klass);
  1840. });