2
0

Compiler-Semantic.js 59 KB

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