Compiler-Semantic.js 60 KB

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