Compiler-Semantic.js 62 KB

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