Compiler-Semantic.js 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945
  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;
  91. $2=self["@args"];
  92. if(($receiver = $2) == nil || $receiver == null){
  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 smalltalk.withContext(function($ctx4) {
  126. return nil;
  127. }, function($ctx4) {$ctx4.fillBlock({},$ctx3,3)})}));
  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;
  148. $2=self["@blockIndex"];
  149. if(($receiver = $2) == nil || $receiver == null){
  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;
  289. lookup=self._bindingFor_(aNode);
  290. $1=lookup;
  291. if(($receiver = $1) == nil || $receiver == null){
  292. $2=self._outerScope();
  293. $ctx1.sendIdx["outerScope"]=1;
  294. if(($receiver = $2) == nil || $receiver == null){
  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;
  320. $2=self._outerScope();
  321. $ctx1.sendIdx["outerScope"]=1;
  322. if(($receiver = $2) == nil || $receiver == null){
  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;
  420. $1=self._outerScope();
  421. $ctx1.sendIdx["outerScope"]=1;
  422. if(($receiver = $1) == nil || $receiver == null){
  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;
  453. $2=self["@temps"];
  454. if(($receiver = $2) == nil || $receiver == null){
  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 $1;
  513. $1=_st(globals.MethodLexicalScope.superclass.fn.prototype._allVariableNames.apply(_st(self), [])).__comma(_st(self._iVars())._keys());
  514. return $1;
  515. }, function($ctx1) {$ctx1.fill(self,"allVariableNames",{},globals.MethodLexicalScope)})},
  516. args: [],
  517. source: "allVariableNames\x0a\x09^ super allVariableNames, self iVars keys",
  518. messageSends: [",", "allVariableNames", "keys", "iVars"],
  519. referencedClasses: []
  520. }),
  521. globals.MethodLexicalScope);
  522. smalltalk.addMethod(
  523. smalltalk.method({
  524. selector: "bindingFor:",
  525. protocol: 'accessing',
  526. fn: function (aNode){
  527. var self=this;
  528. return smalltalk.withContext(function($ctx1) {
  529. var $2,$1;
  530. $2=globals.MethodLexicalScope.superclass.fn.prototype._bindingFor_.apply(_st(self), [aNode]);
  531. if(($receiver = $2) == nil || $receiver == null){
  532. $1=_st(self._iVars())._at_ifAbsent_(_st(aNode)._value(),(function(){
  533. return smalltalk.withContext(function($ctx2) {
  534. return nil;
  535. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  536. } else {
  537. $1=$2;
  538. };
  539. return $1;
  540. }, function($ctx1) {$ctx1.fill(self,"bindingFor:",{aNode:aNode},globals.MethodLexicalScope)})},
  541. args: ["aNode"],
  542. source: "bindingFor: aNode\x0a\x09^ (super bindingFor: aNode) ifNil: [\x0a\x09\x09self iVars at: aNode value ifAbsent: [ nil ]]",
  543. messageSends: ["ifNil:", "bindingFor:", "at:ifAbsent:", "iVars", "value"],
  544. referencedClasses: []
  545. }),
  546. globals.MethodLexicalScope);
  547. smalltalk.addMethod(
  548. smalltalk.method({
  549. selector: "canInlineNonLocalReturns",
  550. protocol: 'testing',
  551. fn: function (){
  552. var self=this;
  553. return true;
  554. },
  555. args: [],
  556. source: "canInlineNonLocalReturns\x0a\x09^ true",
  557. messageSends: [],
  558. referencedClasses: []
  559. }),
  560. globals.MethodLexicalScope);
  561. smalltalk.addMethod(
  562. smalltalk.method({
  563. selector: "hasLocalReturn",
  564. protocol: 'testing',
  565. fn: function (){
  566. var self=this;
  567. return smalltalk.withContext(function($ctx1) {
  568. var $1;
  569. $1=self._localReturn();
  570. return $1;
  571. }, function($ctx1) {$ctx1.fill(self,"hasLocalReturn",{},globals.MethodLexicalScope)})},
  572. args: [],
  573. source: "hasLocalReturn\x0a\x09^ self localReturn",
  574. messageSends: ["localReturn"],
  575. referencedClasses: []
  576. }),
  577. globals.MethodLexicalScope);
  578. smalltalk.addMethod(
  579. smalltalk.method({
  580. selector: "hasNonLocalReturn",
  581. protocol: 'testing',
  582. fn: function (){
  583. var self=this;
  584. return smalltalk.withContext(function($ctx1) {
  585. var $1;
  586. $1=_st(self._nonLocalReturns())._notEmpty();
  587. return $1;
  588. }, function($ctx1) {$ctx1.fill(self,"hasNonLocalReturn",{},globals.MethodLexicalScope)})},
  589. args: [],
  590. source: "hasNonLocalReturn\x0a\x09^ self nonLocalReturns notEmpty",
  591. messageSends: ["notEmpty", "nonLocalReturns"],
  592. referencedClasses: []
  593. }),
  594. globals.MethodLexicalScope);
  595. smalltalk.addMethod(
  596. smalltalk.method({
  597. selector: "iVars",
  598. protocol: 'accessing',
  599. fn: function (){
  600. var self=this;
  601. function $Dictionary(){return globals.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  602. return smalltalk.withContext(function($ctx1) {
  603. var $2,$1;
  604. $2=self["@iVars"];
  605. if(($receiver = $2) == nil || $receiver == null){
  606. self["@iVars"]=_st($Dictionary())._new();
  607. $1=self["@iVars"];
  608. } else {
  609. $1=$2;
  610. };
  611. return $1;
  612. }, function($ctx1) {$ctx1.fill(self,"iVars",{},globals.MethodLexicalScope)})},
  613. args: [],
  614. source: "iVars\x0a\x09^ iVars ifNil: [ iVars := Dictionary new ]",
  615. messageSends: ["ifNil:", "new"],
  616. referencedClasses: ["Dictionary"]
  617. }),
  618. globals.MethodLexicalScope);
  619. smalltalk.addMethod(
  620. smalltalk.method({
  621. selector: "isMethodScope",
  622. protocol: 'testing',
  623. fn: function (){
  624. var self=this;
  625. return true;
  626. },
  627. args: [],
  628. source: "isMethodScope\x0a\x09^ true",
  629. messageSends: [],
  630. referencedClasses: []
  631. }),
  632. globals.MethodLexicalScope);
  633. smalltalk.addMethod(
  634. smalltalk.method({
  635. selector: "localReturn",
  636. protocol: 'accessing',
  637. fn: function (){
  638. var self=this;
  639. return smalltalk.withContext(function($ctx1) {
  640. var $2,$1;
  641. $2=self["@localReturn"];
  642. if(($receiver = $2) == nil || $receiver == null){
  643. $1=false;
  644. } else {
  645. $1=$2;
  646. };
  647. return $1;
  648. }, function($ctx1) {$ctx1.fill(self,"localReturn",{},globals.MethodLexicalScope)})},
  649. args: [],
  650. source: "localReturn\x0a\x09^ localReturn ifNil: [ false ]",
  651. messageSends: ["ifNil:"],
  652. referencedClasses: []
  653. }),
  654. globals.MethodLexicalScope);
  655. smalltalk.addMethod(
  656. smalltalk.method({
  657. selector: "localReturn:",
  658. protocol: 'accessing',
  659. fn: function (aBoolean){
  660. var self=this;
  661. self["@localReturn"]=aBoolean;
  662. return self},
  663. args: ["aBoolean"],
  664. source: "localReturn: aBoolean\x0a\x09localReturn := aBoolean",
  665. messageSends: [],
  666. referencedClasses: []
  667. }),
  668. globals.MethodLexicalScope);
  669. smalltalk.addMethod(
  670. smalltalk.method({
  671. selector: "methodScope",
  672. protocol: 'accessing',
  673. fn: function (){
  674. var self=this;
  675. return self;
  676. },
  677. args: [],
  678. source: "methodScope\x0a\x09^ self",
  679. messageSends: [],
  680. referencedClasses: []
  681. }),
  682. globals.MethodLexicalScope);
  683. smalltalk.addMethod(
  684. smalltalk.method({
  685. selector: "nonLocalReturns",
  686. protocol: 'accessing',
  687. fn: function (){
  688. var self=this;
  689. function $OrderedCollection(){return globals.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  690. return smalltalk.withContext(function($ctx1) {
  691. var $2,$1;
  692. $2=self["@nonLocalReturns"];
  693. if(($receiver = $2) == nil || $receiver == null){
  694. self["@nonLocalReturns"]=_st($OrderedCollection())._new();
  695. $1=self["@nonLocalReturns"];
  696. } else {
  697. $1=$2;
  698. };
  699. return $1;
  700. }, function($ctx1) {$ctx1.fill(self,"nonLocalReturns",{},globals.MethodLexicalScope)})},
  701. args: [],
  702. source: "nonLocalReturns\x0a\x09^ nonLocalReturns ifNil: [ nonLocalReturns := OrderedCollection new ]",
  703. messageSends: ["ifNil:", "new"],
  704. referencedClasses: ["OrderedCollection"]
  705. }),
  706. globals.MethodLexicalScope);
  707. smalltalk.addMethod(
  708. smalltalk.method({
  709. selector: "pseudoVars",
  710. protocol: 'accessing',
  711. fn: function (){
  712. var self=this;
  713. function $Dictionary(){return globals.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  714. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  715. function $PseudoVar(){return globals.PseudoVar||(typeof PseudoVar=="undefined"?nil:PseudoVar)}
  716. return smalltalk.withContext(function($ctx1) {
  717. var $1,$2,$3,$4;
  718. $1=self["@pseudoVars"];
  719. if(($receiver = $1) == nil || $receiver == null){
  720. self["@pseudoVars"]=_st($Dictionary())._new();
  721. self["@pseudoVars"];
  722. _st(_st($Smalltalk())._pseudoVariableNames())._do_((function(each){
  723. return smalltalk.withContext(function($ctx2) {
  724. $2=_st($PseudoVar())._on_(each);
  725. _st($2)._scope_(self._methodScope());
  726. $3=_st($2)._yourself();
  727. return _st(self["@pseudoVars"])._at_put_(each,$3);
  728. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})}));
  729. } else {
  730. $1;
  731. };
  732. $4=self["@pseudoVars"];
  733. return $4;
  734. }, function($ctx1) {$ctx1.fill(self,"pseudoVars",{},globals.MethodLexicalScope)})},
  735. args: [],
  736. 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",
  737. messageSends: ["ifNil:", "new", "do:", "pseudoVariableNames", "at:put:", "scope:", "on:", "methodScope", "yourself"],
  738. referencedClasses: ["Dictionary", "Smalltalk", "PseudoVar"]
  739. }),
  740. globals.MethodLexicalScope);
  741. smalltalk.addMethod(
  742. smalltalk.method({
  743. selector: "removeNonLocalReturn:",
  744. protocol: 'adding',
  745. fn: function (aScope){
  746. var self=this;
  747. return smalltalk.withContext(function($ctx1) {
  748. _st(self._nonLocalReturns())._remove_ifAbsent_(aScope,(function(){
  749. return smalltalk.withContext(function($ctx2) {
  750. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  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;
  767. $2=self["@unknownVariables"];
  768. if(($receiver = $2) == nil || $receiver == null){
  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;
  1239. $2=self["@classReferences"];
  1240. if(($receiver = $2) == nil || $receiver == null){
  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 eval('typeof ' + aString + ' == "undefined"');
  1315. return self},
  1316. args: ["aString"],
  1317. source: "isVariableGloballyUndefined: aString\x0a\x09<return eval('typeof ' + aString + ' == \x22undefined\x22')>",
  1318. messageSends: [],
  1319. referencedClasses: []
  1320. }),
  1321. globals.SemanticAnalyzer);
  1322. smalltalk.addMethod(
  1323. smalltalk.method({
  1324. selector: "messageSends",
  1325. protocol: 'accessing',
  1326. fn: function (){
  1327. var self=this;
  1328. function $Dictionary(){return globals.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  1329. return smalltalk.withContext(function($ctx1) {
  1330. var $2,$1;
  1331. $2=self["@messageSends"];
  1332. if(($receiver = $2) == nil || $receiver == null){
  1333. self["@messageSends"]=_st($Dictionary())._new();
  1334. $1=self["@messageSends"];
  1335. } else {
  1336. $1=$2;
  1337. };
  1338. return $1;
  1339. }, function($ctx1) {$ctx1.fill(self,"messageSends",{},globals.SemanticAnalyzer)})},
  1340. args: [],
  1341. source: "messageSends\x0a\x09^ messageSends ifNil: [ messageSends := Dictionary new ]",
  1342. messageSends: ["ifNil:", "new"],
  1343. referencedClasses: ["Dictionary"]
  1344. }),
  1345. globals.SemanticAnalyzer);
  1346. smalltalk.addMethod(
  1347. smalltalk.method({
  1348. selector: "newBlockScope",
  1349. protocol: 'factory',
  1350. fn: function (){
  1351. var self=this;
  1352. function $LexicalScope(){return globals.LexicalScope||(typeof LexicalScope=="undefined"?nil:LexicalScope)}
  1353. return smalltalk.withContext(function($ctx1) {
  1354. var $1;
  1355. $1=self._newScopeOfClass_($LexicalScope());
  1356. return $1;
  1357. }, function($ctx1) {$ctx1.fill(self,"newBlockScope",{},globals.SemanticAnalyzer)})},
  1358. args: [],
  1359. source: "newBlockScope\x0a\x09^ self newScopeOfClass: LexicalScope",
  1360. messageSends: ["newScopeOfClass:"],
  1361. referencedClasses: ["LexicalScope"]
  1362. }),
  1363. globals.SemanticAnalyzer);
  1364. smalltalk.addMethod(
  1365. smalltalk.method({
  1366. selector: "newMethodScope",
  1367. protocol: 'factory',
  1368. fn: function (){
  1369. var self=this;
  1370. function $MethodLexicalScope(){return globals.MethodLexicalScope||(typeof MethodLexicalScope=="undefined"?nil:MethodLexicalScope)}
  1371. return smalltalk.withContext(function($ctx1) {
  1372. var $1;
  1373. $1=self._newScopeOfClass_($MethodLexicalScope());
  1374. return $1;
  1375. }, function($ctx1) {$ctx1.fill(self,"newMethodScope",{},globals.SemanticAnalyzer)})},
  1376. args: [],
  1377. source: "newMethodScope\x0a\x09^ self newScopeOfClass: MethodLexicalScope",
  1378. messageSends: ["newScopeOfClass:"],
  1379. referencedClasses: ["MethodLexicalScope"]
  1380. }),
  1381. globals.SemanticAnalyzer);
  1382. smalltalk.addMethod(
  1383. smalltalk.method({
  1384. selector: "newScopeOfClass:",
  1385. protocol: 'factory',
  1386. fn: function (aLexicalScopeClass){
  1387. var self=this;
  1388. return smalltalk.withContext(function($ctx1) {
  1389. var $2,$3,$1;
  1390. $2=_st(aLexicalScopeClass)._new();
  1391. _st($2)._outerScope_(self["@currentScope"]);
  1392. $3=_st($2)._yourself();
  1393. $1=$3;
  1394. return $1;
  1395. }, function($ctx1) {$ctx1.fill(self,"newScopeOfClass:",{aLexicalScopeClass:aLexicalScopeClass},globals.SemanticAnalyzer)})},
  1396. args: ["aLexicalScopeClass"],
  1397. source: "newScopeOfClass: aLexicalScopeClass\x0a\x09^ aLexicalScopeClass new\x0a\x09\x09outerScope: currentScope;\x0a\x09\x09yourself",
  1398. messageSends: ["outerScope:", "new", "yourself"],
  1399. referencedClasses: []
  1400. }),
  1401. globals.SemanticAnalyzer);
  1402. smalltalk.addMethod(
  1403. smalltalk.method({
  1404. selector: "nextBlockIndex",
  1405. protocol: 'private',
  1406. fn: function (){
  1407. var self=this;
  1408. return smalltalk.withContext(function($ctx1) {
  1409. var $1,$2;
  1410. $1=self["@blockIndex"];
  1411. if(($receiver = $1) == nil || $receiver == null){
  1412. self["@blockIndex"]=(0);
  1413. self["@blockIndex"];
  1414. } else {
  1415. $1;
  1416. };
  1417. self["@blockIndex"]=_st(self["@blockIndex"]).__plus((1));
  1418. $2=self["@blockIndex"];
  1419. return $2;
  1420. }, function($ctx1) {$ctx1.fill(self,"nextBlockIndex",{},globals.SemanticAnalyzer)})},
  1421. args: [],
  1422. source: "nextBlockIndex\x0a\x09blockIndex ifNil: [ blockIndex := 0 ].\x0a\x09\x0a\x09blockIndex := blockIndex + 1.\x0a\x09^ blockIndex",
  1423. messageSends: ["ifNil:", "+"],
  1424. referencedClasses: []
  1425. }),
  1426. globals.SemanticAnalyzer);
  1427. smalltalk.addMethod(
  1428. smalltalk.method({
  1429. selector: "popScope",
  1430. protocol: 'scope',
  1431. fn: function (){
  1432. var self=this;
  1433. return smalltalk.withContext(function($ctx1) {
  1434. var $1;
  1435. $1=self["@currentScope"];
  1436. if(($receiver = $1) == nil || $receiver == null){
  1437. $1;
  1438. } else {
  1439. self["@currentScope"]=_st(self["@currentScope"])._outerScope();
  1440. self["@currentScope"];
  1441. };
  1442. return self}, function($ctx1) {$ctx1.fill(self,"popScope",{},globals.SemanticAnalyzer)})},
  1443. args: [],
  1444. source: "popScope\x0a\x09currentScope ifNotNil: [\x0a\x09\x09currentScope := currentScope outerScope ]",
  1445. messageSends: ["ifNotNil:", "outerScope"],
  1446. referencedClasses: []
  1447. }),
  1448. globals.SemanticAnalyzer);
  1449. smalltalk.addMethod(
  1450. smalltalk.method({
  1451. selector: "pushScope:",
  1452. protocol: 'scope',
  1453. fn: function (aScope){
  1454. var self=this;
  1455. return smalltalk.withContext(function($ctx1) {
  1456. _st(aScope)._outerScope_(self["@currentScope"]);
  1457. self["@currentScope"]=aScope;
  1458. return self}, function($ctx1) {$ctx1.fill(self,"pushScope:",{aScope:aScope},globals.SemanticAnalyzer)})},
  1459. args: ["aScope"],
  1460. source: "pushScope: aScope\x0a\x09aScope outerScope: currentScope.\x0a\x09currentScope := aScope",
  1461. messageSends: ["outerScope:"],
  1462. referencedClasses: []
  1463. }),
  1464. globals.SemanticAnalyzer);
  1465. smalltalk.addMethod(
  1466. smalltalk.method({
  1467. selector: "superSends",
  1468. protocol: 'accessing',
  1469. fn: function (){
  1470. var self=this;
  1471. function $Dictionary(){return globals.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  1472. return smalltalk.withContext(function($ctx1) {
  1473. var $2,$1;
  1474. $2=self["@superSends"];
  1475. if(($receiver = $2) == nil || $receiver == null){
  1476. self["@superSends"]=_st($Dictionary())._new();
  1477. $1=self["@superSends"];
  1478. } else {
  1479. $1=$2;
  1480. };
  1481. return $1;
  1482. }, function($ctx1) {$ctx1.fill(self,"superSends",{},globals.SemanticAnalyzer)})},
  1483. args: [],
  1484. source: "superSends\x0a\x09^ superSends ifNil: [ superSends := Dictionary new ]",
  1485. messageSends: ["ifNil:", "new"],
  1486. referencedClasses: ["Dictionary"]
  1487. }),
  1488. globals.SemanticAnalyzer);
  1489. smalltalk.addMethod(
  1490. smalltalk.method({
  1491. selector: "theClass",
  1492. protocol: 'accessing',
  1493. fn: function (){
  1494. var self=this;
  1495. var $1;
  1496. $1=self["@theClass"];
  1497. return $1;
  1498. },
  1499. args: [],
  1500. source: "theClass\x0a\x09^ theClass",
  1501. messageSends: [],
  1502. referencedClasses: []
  1503. }),
  1504. globals.SemanticAnalyzer);
  1505. smalltalk.addMethod(
  1506. smalltalk.method({
  1507. selector: "theClass:",
  1508. protocol: 'accessing',
  1509. fn: function (aClass){
  1510. var self=this;
  1511. self["@theClass"]=aClass;
  1512. return self},
  1513. args: ["aClass"],
  1514. source: "theClass: aClass\x0a\x09theClass := aClass",
  1515. messageSends: [],
  1516. referencedClasses: []
  1517. }),
  1518. globals.SemanticAnalyzer);
  1519. smalltalk.addMethod(
  1520. smalltalk.method({
  1521. selector: "validateVariableScope:",
  1522. protocol: 'scope',
  1523. fn: function (aString){
  1524. var self=this;
  1525. return smalltalk.withContext(function($ctx1) {
  1526. var $1;
  1527. $1=_st(self["@currentScope"])._lookupVariable_(aString);
  1528. if(($receiver = $1) == nil || $receiver == null){
  1529. $1;
  1530. } else {
  1531. self._errorShadowingVariable_(aString);
  1532. };
  1533. return self}, function($ctx1) {$ctx1.fill(self,"validateVariableScope:",{aString:aString},globals.SemanticAnalyzer)})},
  1534. args: ["aString"],
  1535. 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 ]",
  1536. messageSends: ["ifNotNil:", "lookupVariable:", "errorShadowingVariable:"],
  1537. referencedClasses: []
  1538. }),
  1539. globals.SemanticAnalyzer);
  1540. smalltalk.addMethod(
  1541. smalltalk.method({
  1542. selector: "visitAssignmentNode:",
  1543. protocol: 'visiting',
  1544. fn: function (aNode){
  1545. var self=this;
  1546. return smalltalk.withContext(function($ctx1) {
  1547. globals.SemanticAnalyzer.superclass.fn.prototype._visitAssignmentNode_.apply(_st(self), [aNode]);
  1548. _st(_st(aNode)._left())._beAssigned();
  1549. return self}, function($ctx1) {$ctx1.fill(self,"visitAssignmentNode:",{aNode:aNode},globals.SemanticAnalyzer)})},
  1550. args: ["aNode"],
  1551. source: "visitAssignmentNode: aNode\x0a\x09super visitAssignmentNode: aNode.\x0a\x09aNode left beAssigned",
  1552. messageSends: ["visitAssignmentNode:", "beAssigned", "left"],
  1553. referencedClasses: []
  1554. }),
  1555. globals.SemanticAnalyzer);
  1556. smalltalk.addMethod(
  1557. smalltalk.method({
  1558. selector: "visitBlockNode:",
  1559. protocol: 'visiting',
  1560. fn: function (aNode){
  1561. var self=this;
  1562. return smalltalk.withContext(function($ctx1) {
  1563. self._pushScope_(self._newBlockScope());
  1564. _st(aNode)._scope_(self["@currentScope"]);
  1565. _st(self["@currentScope"])._node_(aNode);
  1566. _st(self["@currentScope"])._blockIndex_(self._nextBlockIndex());
  1567. _st(_st(aNode)._parameters())._do_((function(each){
  1568. return smalltalk.withContext(function($ctx2) {
  1569. self._validateVariableScope_(each);
  1570. return _st(self["@currentScope"])._addArg_(each);
  1571. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1572. globals.SemanticAnalyzer.superclass.fn.prototype._visitBlockNode_.apply(_st(self), [aNode]);
  1573. self._popScope();
  1574. return self}, function($ctx1) {$ctx1.fill(self,"visitBlockNode:",{aNode:aNode},globals.SemanticAnalyzer)})},
  1575. args: ["aNode"],
  1576. 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",
  1577. messageSends: ["pushScope:", "newBlockScope", "scope:", "node:", "blockIndex:", "nextBlockIndex", "do:", "parameters", "validateVariableScope:", "addArg:", "visitBlockNode:", "popScope"],
  1578. referencedClasses: []
  1579. }),
  1580. globals.SemanticAnalyzer);
  1581. smalltalk.addMethod(
  1582. smalltalk.method({
  1583. selector: "visitCascadeNode:",
  1584. protocol: 'visiting',
  1585. fn: function (aNode){
  1586. var self=this;
  1587. return smalltalk.withContext(function($ctx1) {
  1588. var $3,$2,$1;
  1589. globals.SemanticAnalyzer.superclass.fn.prototype._visitCascadeNode_.apply(_st(self), [aNode]);
  1590. $3=_st(aNode)._nodes();
  1591. $ctx1.sendIdx["nodes"]=1;
  1592. $2=_st($3)._first();
  1593. $1=_st($2)._superSend();
  1594. if(smalltalk.assert($1)){
  1595. _st(_st(aNode)._nodes())._do_((function(each){
  1596. return smalltalk.withContext(function($ctx2) {
  1597. return _st(each)._superSend_(true);
  1598. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})}));
  1599. };
  1600. return self}, function($ctx1) {$ctx1.fill(self,"visitCascadeNode:",{aNode:aNode},globals.SemanticAnalyzer)})},
  1601. args: ["aNode"],
  1602. source: "visitCascadeNode: aNode\x0a\x09super visitCascadeNode: aNode.\x0a\x09aNode nodes first superSend ifTrue: [\x0a\x09\x09aNode nodes do: [ :each | each superSend: true ] ]",
  1603. messageSends: ["visitCascadeNode:", "ifTrue:", "superSend", "first", "nodes", "do:", "superSend:"],
  1604. referencedClasses: []
  1605. }),
  1606. globals.SemanticAnalyzer);
  1607. smalltalk.addMethod(
  1608. smalltalk.method({
  1609. selector: "visitMethodNode:",
  1610. protocol: 'visiting',
  1611. fn: function (aNode){
  1612. var self=this;
  1613. return smalltalk.withContext(function($ctx1) {
  1614. var $1;
  1615. self._pushScope_(self._newMethodScope());
  1616. _st(aNode)._scope_(self["@currentScope"]);
  1617. _st(self["@currentScope"])._node_(aNode);
  1618. _st(_st(self._theClass())._allInstanceVariableNames())._do_((function(each){
  1619. return smalltalk.withContext(function($ctx2) {
  1620. return _st(self["@currentScope"])._addIVar_(each);
  1621. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1622. $ctx1.sendIdx["do:"]=1;
  1623. _st(_st(aNode)._arguments())._do_((function(each){
  1624. return smalltalk.withContext(function($ctx2) {
  1625. self._validateVariableScope_(each);
  1626. return _st(self["@currentScope"])._addArg_(each);
  1627. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})}));
  1628. globals.SemanticAnalyzer.superclass.fn.prototype._visitMethodNode_.apply(_st(self), [aNode]);
  1629. _st(aNode)._classReferences_(self._classReferences());
  1630. _st(aNode)._sendIndexes_(self._messageSends());
  1631. $1=_st(aNode)._superSends_(_st(self._superSends())._keys());
  1632. self._popScope();
  1633. return self}, function($ctx1) {$ctx1.fill(self,"visitMethodNode:",{aNode:aNode},globals.SemanticAnalyzer)})},
  1634. args: ["aNode"],
  1635. 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",
  1636. messageSends: ["pushScope:", "newMethodScope", "scope:", "node:", "do:", "allInstanceVariableNames", "theClass", "addIVar:", "arguments", "validateVariableScope:", "addArg:", "visitMethodNode:", "classReferences:", "classReferences", "sendIndexes:", "messageSends", "superSends:", "keys", "superSends", "popScope"],
  1637. referencedClasses: []
  1638. }),
  1639. globals.SemanticAnalyzer);
  1640. smalltalk.addMethod(
  1641. smalltalk.method({
  1642. selector: "visitReturnNode:",
  1643. protocol: 'visiting',
  1644. fn: function (aNode){
  1645. var self=this;
  1646. return smalltalk.withContext(function($ctx1) {
  1647. var $1;
  1648. _st(aNode)._scope_(self["@currentScope"]);
  1649. $1=_st(self["@currentScope"])._isMethodScope();
  1650. if(smalltalk.assert($1)){
  1651. _st(self["@currentScope"])._localReturn_(true);
  1652. } else {
  1653. _st(_st(self["@currentScope"])._methodScope())._addNonLocalReturn_(self["@currentScope"]);
  1654. };
  1655. globals.SemanticAnalyzer.superclass.fn.prototype._visitReturnNode_.apply(_st(self), [aNode]);
  1656. return self}, function($ctx1) {$ctx1.fill(self,"visitReturnNode:",{aNode:aNode},globals.SemanticAnalyzer)})},
  1657. args: ["aNode"],
  1658. 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",
  1659. messageSends: ["scope:", "ifTrue:ifFalse:", "isMethodScope", "localReturn:", "addNonLocalReturn:", "methodScope", "visitReturnNode:"],
  1660. referencedClasses: []
  1661. }),
  1662. globals.SemanticAnalyzer);
  1663. smalltalk.addMethod(
  1664. smalltalk.method({
  1665. selector: "visitSendNode:",
  1666. protocol: 'visiting',
  1667. fn: function (aNode){
  1668. var self=this;
  1669. function $Set(){return globals.Set||(typeof Set=="undefined"?nil:Set)}
  1670. function $IRSendInliner(){return globals.IRSendInliner||(typeof IRSendInliner=="undefined"?nil:IRSendInliner)}
  1671. return smalltalk.withContext(function($ctx1) {
  1672. var $3,$2,$1,$4,$5,$6,$8,$9,$7,$11,$12,$10,$13,$14,$15,$17,$18,$16;
  1673. $3=_st(aNode)._receiver();
  1674. $ctx1.sendIdx["receiver"]=1;
  1675. $2=_st($3)._value();
  1676. $1=_st($2).__eq("super");
  1677. if(smalltalk.assert($1)){
  1678. _st(aNode)._superSend_(true);
  1679. $4=_st(aNode)._receiver();
  1680. $ctx1.sendIdx["receiver"]=2;
  1681. _st($4)._value_("self");
  1682. $5=self._superSends();
  1683. $ctx1.sendIdx["superSends"]=1;
  1684. $6=_st(aNode)._selector();
  1685. $ctx1.sendIdx["selector"]=1;
  1686. _st($5)._at_ifAbsentPut_($6,(function(){
  1687. return smalltalk.withContext(function($ctx2) {
  1688. return _st($Set())._new();
  1689. $ctx2.sendIdx["new"]=1;
  1690. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  1691. $ctx1.sendIdx["at:ifAbsentPut:"]=1;
  1692. $8=self._superSends();
  1693. $9=_st(aNode)._selector();
  1694. $ctx1.sendIdx["selector"]=2;
  1695. $7=_st($8)._at_($9);
  1696. $ctx1.sendIdx["at:"]=1;
  1697. _st($7)._add_(aNode);
  1698. $ctx1.sendIdx["add:"]=1;
  1699. } else {
  1700. $11=_st($IRSendInliner())._inlinedSelectors();
  1701. $12=_st(aNode)._selector();
  1702. $ctx1.sendIdx["selector"]=3;
  1703. $10=_st($11)._includes_($12);
  1704. if(smalltalk.assert($10)){
  1705. _st(aNode)._shouldBeInlined_(true);
  1706. $13=_st(aNode)._receiver();
  1707. if(($receiver = $13) == nil || $receiver == null){
  1708. $13;
  1709. } else {
  1710. var receiver;
  1711. receiver=$receiver;
  1712. _st(receiver)._shouldBeAliased_(true);
  1713. };
  1714. };
  1715. };
  1716. $14=self._messageSends();
  1717. $ctx1.sendIdx["messageSends"]=1;
  1718. $15=_st(aNode)._selector();
  1719. $ctx1.sendIdx["selector"]=4;
  1720. _st($14)._at_ifAbsentPut_($15,(function(){
  1721. return smalltalk.withContext(function($ctx2) {
  1722. return _st($Set())._new();
  1723. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,6)})}));
  1724. $17=self._messageSends();
  1725. $ctx1.sendIdx["messageSends"]=2;
  1726. $18=_st(aNode)._selector();
  1727. $ctx1.sendIdx["selector"]=5;
  1728. $16=_st($17)._at_($18);
  1729. $ctx1.sendIdx["at:"]=2;
  1730. _st($16)._add_(aNode);
  1731. _st(aNode)._index_(_st(_st(self._messageSends())._at_(_st(aNode)._selector()))._size());
  1732. globals.SemanticAnalyzer.superclass.fn.prototype._visitSendNode_.apply(_st(self), [aNode]);
  1733. return self}, function($ctx1) {$ctx1.fill(self,"visitSendNode:",{aNode:aNode},globals.SemanticAnalyzer)})},
  1734. args: ["aNode"],
  1735. 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",
  1736. messageSends: ["ifTrue:ifFalse:", "=", "value", "receiver", "superSend:", "value:", "at:ifAbsentPut:", "superSends", "selector", "new", "add:", "at:", "ifTrue:", "includes:", "inlinedSelectors", "shouldBeInlined:", "ifNotNil:", "shouldBeAliased:", "messageSends", "index:", "size", "visitSendNode:"],
  1737. referencedClasses: ["Set", "IRSendInliner"]
  1738. }),
  1739. globals.SemanticAnalyzer);
  1740. smalltalk.addMethod(
  1741. smalltalk.method({
  1742. selector: "visitSequenceNode:",
  1743. protocol: 'visiting',
  1744. fn: function (aNode){
  1745. var self=this;
  1746. return smalltalk.withContext(function($ctx1) {
  1747. _st(_st(aNode)._temps())._do_((function(each){
  1748. return smalltalk.withContext(function($ctx2) {
  1749. self._validateVariableScope_(each);
  1750. return _st(self["@currentScope"])._addTemp_(each);
  1751. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1752. globals.SemanticAnalyzer.superclass.fn.prototype._visitSequenceNode_.apply(_st(self), [aNode]);
  1753. return self}, function($ctx1) {$ctx1.fill(self,"visitSequenceNode:",{aNode:aNode},globals.SemanticAnalyzer)})},
  1754. args: ["aNode"],
  1755. source: "visitSequenceNode: aNode\x0a\x09aNode temps do: [ :each |\x0a\x09\x09self validateVariableScope: each.\x0a\x09\x09currentScope addTemp: each ].\x0a\x0a\x09super visitSequenceNode: aNode",
  1756. messageSends: ["do:", "temps", "validateVariableScope:", "addTemp:", "visitSequenceNode:"],
  1757. referencedClasses: []
  1758. }),
  1759. globals.SemanticAnalyzer);
  1760. smalltalk.addMethod(
  1761. smalltalk.method({
  1762. selector: "visitVariableNode:",
  1763. protocol: 'visiting',
  1764. fn: function (aNode){
  1765. var self=this;
  1766. var binding;
  1767. function $ClassRefVar(){return globals.ClassRefVar||(typeof ClassRefVar=="undefined"?nil:ClassRefVar)}
  1768. function $UnknownVar(){return globals.UnknownVar||(typeof UnknownVar=="undefined"?nil:UnknownVar)}
  1769. return smalltalk.withContext(function($ctx1) {
  1770. var $1,$3,$2,$4,$5,$6,$7,$8,$9,$10,$11;
  1771. binding=_st(self["@currentScope"])._lookupVariable_(aNode);
  1772. $1=binding;
  1773. if(($receiver = $1) == nil || $receiver == null){
  1774. $3=_st(aNode)._value();
  1775. $ctx1.sendIdx["value"]=1;
  1776. $2=_st($3)._isCapitalized();
  1777. if(smalltalk.assert($2)){
  1778. $4=_st($ClassRefVar())._new();
  1779. $ctx1.sendIdx["new"]=1;
  1780. $5=$4;
  1781. $6=_st(aNode)._value();
  1782. $ctx1.sendIdx["value"]=2;
  1783. _st($5)._name_($6);
  1784. $ctx1.sendIdx["name:"]=1;
  1785. $7=_st($4)._yourself();
  1786. $ctx1.sendIdx["yourself"]=1;
  1787. binding=$7;
  1788. binding;
  1789. $8=self._classReferences();
  1790. $9=_st(aNode)._value();
  1791. $ctx1.sendIdx["value"]=3;
  1792. _st($8)._add_($9);
  1793. } else {
  1794. self._errorUnknownVariable_(aNode);
  1795. $10=_st($UnknownVar())._new();
  1796. _st($10)._name_(_st(aNode)._value());
  1797. $11=_st($10)._yourself();
  1798. binding=$11;
  1799. binding;
  1800. };
  1801. } else {
  1802. $1;
  1803. };
  1804. _st(aNode)._binding_(binding);
  1805. return self}, function($ctx1) {$ctx1.fill(self,"visitVariableNode:",{aNode:aNode,binding:binding},globals.SemanticAnalyzer)})},
  1806. args: ["aNode"],
  1807. 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.",
  1808. messageSends: ["lookupVariable:", "ifNil:", "ifTrue:ifFalse:", "isCapitalized", "value", "name:", "new", "yourself", "add:", "classReferences", "errorUnknownVariable:", "binding:"],
  1809. referencedClasses: ["ClassRefVar", "UnknownVar"]
  1810. }),
  1811. globals.SemanticAnalyzer);
  1812. smalltalk.addMethod(
  1813. smalltalk.method({
  1814. selector: "on:",
  1815. protocol: 'instance creation',
  1816. fn: function (aClass){
  1817. var self=this;
  1818. return smalltalk.withContext(function($ctx1) {
  1819. var $2,$3,$1;
  1820. $2=self._new();
  1821. _st($2)._theClass_(aClass);
  1822. $3=_st($2)._yourself();
  1823. $1=$3;
  1824. return $1;
  1825. }, function($ctx1) {$ctx1.fill(self,"on:",{aClass:aClass},globals.SemanticAnalyzer.klass)})},
  1826. args: ["aClass"],
  1827. source: "on: aClass\x0a\x09^ self new\x0a\x09\x09theClass: aClass;\x0a\x09\x09yourself",
  1828. messageSends: ["theClass:", "new", "yourself"],
  1829. referencedClasses: []
  1830. }),
  1831. globals.SemanticAnalyzer.klass);
  1832. });