Compiler-Semantic.js 60 KB

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