Compiler-Semantic.js 60 KB

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