Compiler-Interpreter.js 75 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300
  1. define("amber_core/Compiler-Interpreter", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_vm/globals", "amber_core/Kernel-Methods", "amber_core/Kernel-Objects", "amber_core/Compiler-Core", "amber_core/Kernel-Exceptions", "amber_core/Compiler-AST"], function(smalltalk,nil,_st, globals){
  2. smalltalk.addPackage('Compiler-Interpreter');
  3. smalltalk.packages["Compiler-Interpreter"].transport = {"type":"amd","amdNamespace":"amber_core"};
  4. smalltalk.addClass('AIBlockClosure', globals.BlockClosure, ['node', 'outerContext'], 'Compiler-Interpreter');
  5. globals.AIBlockClosure.comment="I am a special `BlockClosure` subclass used by an interpreter to interpret a block node.\x0a\x0aWhile I am polymorphic with `BlockClosure`, some methods such as `#new` will raise interpretation errors. Unlike a `BlockClosure`, my instance are not JavaScript functions.\x0a\x0aEvaluating an instance will result in interpreting the `node` instance variable (instance of `BlockNode`).";
  6. smalltalk.addMethod(
  7. smalltalk.method({
  8. selector: "applyTo:arguments:",
  9. protocol: 'evaluating',
  10. fn: function (anObject,aCollection){
  11. var self=this;
  12. return smalltalk.withContext(function($ctx1) {
  13. self._interpreterError();
  14. return self}, function($ctx1) {$ctx1.fill(self,"applyTo:arguments:",{anObject:anObject,aCollection:aCollection},globals.AIBlockClosure)})},
  15. args: ["anObject", "aCollection"],
  16. source: "applyTo: anObject arguments: aCollection\x0a\x09self interpreterError",
  17. messageSends: ["interpreterError"],
  18. referencedClasses: []
  19. }),
  20. globals.AIBlockClosure);
  21. smalltalk.addMethod(
  22. smalltalk.method({
  23. selector: "compiledSource",
  24. protocol: 'accessing',
  25. fn: function (){
  26. var self=this;
  27. return "[ AST Block closure ]";
  28. },
  29. args: [],
  30. source: "compiledSource\x0a\x09\x22Unlike blocks, the receiver doesn't represent a JS function\x22\x0a\x09\x0a\x09^ '[ AST Block closure ]'",
  31. messageSends: [],
  32. referencedClasses: []
  33. }),
  34. globals.AIBlockClosure);
  35. smalltalk.addMethod(
  36. smalltalk.method({
  37. selector: "currySelf",
  38. protocol: 'converting',
  39. fn: function (){
  40. var self=this;
  41. return smalltalk.withContext(function($ctx1) {
  42. self._interpreterError();
  43. return self}, function($ctx1) {$ctx1.fill(self,"currySelf",{},globals.AIBlockClosure)})},
  44. args: [],
  45. source: "currySelf\x0a\x09self interpreterError",
  46. messageSends: ["interpreterError"],
  47. referencedClasses: []
  48. }),
  49. globals.AIBlockClosure);
  50. smalltalk.addMethod(
  51. smalltalk.method({
  52. selector: "initializeWithContext:node:",
  53. protocol: 'initialization',
  54. fn: function (aContext,aNode){
  55. var self=this;
  56. self["@node"]=aNode;
  57. self["@outerContext"]=aContext;
  58. return self},
  59. args: ["aContext", "aNode"],
  60. source: "initializeWithContext: aContext node: aNode\x0a\x09node := aNode.\x0a\x09outerContext := aContext",
  61. messageSends: [],
  62. referencedClasses: []
  63. }),
  64. globals.AIBlockClosure);
  65. smalltalk.addMethod(
  66. smalltalk.method({
  67. selector: "interpreterError",
  68. protocol: 'error handling',
  69. fn: function (){
  70. var self=this;
  71. function $ASTInterpreterError(){return globals.ASTInterpreterError||(typeof ASTInterpreterError=="undefined"?nil:ASTInterpreterError)}
  72. return smalltalk.withContext(function($ctx1) {
  73. _st($ASTInterpreterError())._signal_("Method cannot be interpreted by the interpreter.");
  74. return self}, function($ctx1) {$ctx1.fill(self,"interpreterError",{},globals.AIBlockClosure)})},
  75. args: [],
  76. source: "interpreterError\x0a\x09ASTInterpreterError signal: 'Method cannot be interpreted by the interpreter.'",
  77. messageSends: ["signal:"],
  78. referencedClasses: ["ASTInterpreterError"]
  79. }),
  80. globals.AIBlockClosure);
  81. smalltalk.addMethod(
  82. smalltalk.method({
  83. selector: "numArgs",
  84. protocol: 'accessing',
  85. fn: function (){
  86. var self=this;
  87. return smalltalk.withContext(function($ctx1) {
  88. var $1;
  89. $1=_st(_st(self["@node"])._temps())._size();
  90. return $1;
  91. }, function($ctx1) {$ctx1.fill(self,"numArgs",{},globals.AIBlockClosure)})},
  92. args: [],
  93. source: "numArgs\x0a\x09^ node temps size",
  94. messageSends: ["size", "temps"],
  95. referencedClasses: []
  96. }),
  97. globals.AIBlockClosure);
  98. smalltalk.addMethod(
  99. smalltalk.method({
  100. selector: "value",
  101. protocol: 'evaluating',
  102. fn: function (){
  103. var self=this;
  104. return smalltalk.withContext(function($ctx1) {
  105. var $1;
  106. $1=self._valueWithPossibleArguments_([]);
  107. return $1;
  108. }, function($ctx1) {$ctx1.fill(self,"value",{},globals.AIBlockClosure)})},
  109. args: [],
  110. source: "value\x0a\x09^ self valueWithPossibleArguments: #()",
  111. messageSends: ["valueWithPossibleArguments:"],
  112. referencedClasses: []
  113. }),
  114. globals.AIBlockClosure);
  115. smalltalk.addMethod(
  116. smalltalk.method({
  117. selector: "value:",
  118. protocol: 'evaluating',
  119. fn: function (anArgument){
  120. var self=this;
  121. return smalltalk.withContext(function($ctx1) {
  122. var $1;
  123. $1=self._valueWithPossibleArguments_([anArgument]);
  124. return $1;
  125. }, function($ctx1) {$ctx1.fill(self,"value:",{anArgument:anArgument},globals.AIBlockClosure)})},
  126. args: ["anArgument"],
  127. source: "value: anArgument\x0a\x09^ self valueWithPossibleArguments: {anArgument}",
  128. messageSends: ["valueWithPossibleArguments:"],
  129. referencedClasses: []
  130. }),
  131. globals.AIBlockClosure);
  132. smalltalk.addMethod(
  133. smalltalk.method({
  134. selector: "value:value:",
  135. protocol: 'evaluating',
  136. fn: function (firstArgument,secondArgument){
  137. var self=this;
  138. return smalltalk.withContext(function($ctx1) {
  139. var $1;
  140. $1=self._valueWithPossibleArguments_([firstArgument,secondArgument]);
  141. return $1;
  142. }, function($ctx1) {$ctx1.fill(self,"value:value:",{firstArgument:firstArgument,secondArgument:secondArgument},globals.AIBlockClosure)})},
  143. args: ["firstArgument", "secondArgument"],
  144. source: "value: firstArgument value: secondArgument\x0a\x09^ self valueWithPossibleArguments: {firstArgument . secondArgument}",
  145. messageSends: ["valueWithPossibleArguments:"],
  146. referencedClasses: []
  147. }),
  148. globals.AIBlockClosure);
  149. smalltalk.addMethod(
  150. smalltalk.method({
  151. selector: "value:value:value:",
  152. protocol: 'evaluating',
  153. fn: function (firstArgument,secondArgument,thirdArgument){
  154. var self=this;
  155. return smalltalk.withContext(function($ctx1) {
  156. var $1;
  157. $1=self._valueWithPossibleArguments_([firstArgument,secondArgument,thirdArgument]);
  158. return $1;
  159. }, function($ctx1) {$ctx1.fill(self,"value:value:value:",{firstArgument:firstArgument,secondArgument:secondArgument,thirdArgument:thirdArgument},globals.AIBlockClosure)})},
  160. args: ["firstArgument", "secondArgument", "thirdArgument"],
  161. source: "value: firstArgument value: secondArgument value: thirdArgument\x0a\x09^ self valueWithPossibleArguments: {firstArgument . secondArgument . thirdArgument}",
  162. messageSends: ["valueWithPossibleArguments:"],
  163. referencedClasses: []
  164. }),
  165. globals.AIBlockClosure);
  166. smalltalk.addMethod(
  167. smalltalk.method({
  168. selector: "valueWithPossibleArguments:",
  169. protocol: 'evaluating',
  170. fn: function (aCollection){
  171. var self=this;
  172. var context,sequenceNode;
  173. return smalltalk.withContext(function($ctx1) {
  174. var $1,$2,$3,$4,$5,$6;
  175. context=_st(self["@outerContext"])._newBlockContext();
  176. $1=_st(_st(_st(self["@node"])._nodes())._first())._copy();
  177. _st($1)._parent_(nil);
  178. $2=_st($1)._yourself();
  179. sequenceNode=$2;
  180. _st(_st(self["@node"])._parameters())._withIndexDo_((function(each,index){
  181. return smalltalk.withContext(function($ctx2) {
  182. return _st(context)._localAt_put_(each,_st(aCollection)._at_ifAbsent_(index,(function(){
  183. return nil;
  184. })));
  185. }, function($ctx2) {$ctx2.fillBlock({each:each,index:index},$ctx1,1)})}));
  186. $3=_st(context)._interpreter();
  187. $ctx1.sendIdx["interpreter"]=1;
  188. _st($3)._node_(_st(sequenceNode)._nextChild());
  189. $4=_st($3)._proceed();
  190. $5=_st(self["@outerContext"])._interpreter();
  191. $ctx1.sendIdx["interpreter"]=2;
  192. _st($5)._setNonLocalReturnFromContext_(context);
  193. $6=_st(_st(context)._interpreter())._pop();
  194. return $6;
  195. }, function($ctx1) {$ctx1.fill(self,"valueWithPossibleArguments:",{aCollection:aCollection,context:context,sequenceNode:sequenceNode},globals.AIBlockClosure)})},
  196. args: ["aCollection"],
  197. source: "valueWithPossibleArguments: aCollection\x0a\x09| context sequenceNode |\x0a\x09context := outerContext newBlockContext.\x0a\x0a\x09\x22Interpret a copy of the sequence node to avoid creating a new AIBlockClosure\x22\x0a\x09sequenceNode := node nodes first copy\x0a\x09\x09parent: nil;\x0a\x09\x09yourself.\x0a\x0a\x09\x22Populate the arguments into the context locals\x22\x09\x0a\x09node parameters withIndexDo: [ :each :index |\x0a\x09\x09context localAt: each put: (aCollection at: index ifAbsent: [ nil ]) ].\x0a\x0a\x09\x22Interpret the first node of the BlockSequenceNode\x22\x0a\x09context interpreter\x0a\x09\x09node: sequenceNode nextChild;\x0a\x09\x09proceed.\x0a\x09\x09\x0a\x09outerContext interpreter\x0a\x09\x09setNonLocalReturnFromContext: context.\x0a\x09\x09\x0a\x09^ context interpreter pop",
  198. messageSends: ["newBlockContext", "parent:", "copy", "first", "nodes", "yourself", "withIndexDo:", "parameters", "localAt:put:", "at:ifAbsent:", "node:", "interpreter", "nextChild", "proceed", "setNonLocalReturnFromContext:", "pop"],
  199. referencedClasses: []
  200. }),
  201. globals.AIBlockClosure);
  202. smalltalk.addMethod(
  203. smalltalk.method({
  204. selector: "forContext:node:",
  205. protocol: 'instance creation',
  206. fn: function (aContext,aNode){
  207. var self=this;
  208. return smalltalk.withContext(function($ctx1) {
  209. var $2,$3,$1;
  210. $2=self._new();
  211. _st($2)._initializeWithContext_node_(aContext,aNode);
  212. $3=_st($2)._yourself();
  213. $1=$3;
  214. return $1;
  215. }, function($ctx1) {$ctx1.fill(self,"forContext:node:",{aContext:aContext,aNode:aNode},globals.AIBlockClosure.klass)})},
  216. args: ["aContext", "aNode"],
  217. source: "forContext: aContext node: aNode\x0a\x09^ self new\x0a\x09\x09initializeWithContext: aContext node: aNode;\x0a\x09\x09yourself",
  218. messageSends: ["initializeWithContext:node:", "new", "yourself"],
  219. referencedClasses: []
  220. }),
  221. globals.AIBlockClosure.klass);
  222. smalltalk.addClass('AIContext', globals.MethodContext, ['outerContext', 'innerContext', 'pc', 'locals', 'selector', 'index', 'sendIndexes', 'evaluatedSelector', 'ast', 'interpreter'], 'Compiler-Interpreter');
  223. globals.AIContext.comment="I am like a `MethodContext`, used by the `ASTInterpreter`.\x0aUnlike a `MethodContext`, my instances are not read-only.\x0a\x0aWhen debugging, my instances are created by copying the current `MethodContext` (thisContext)";
  224. smalltalk.addMethod(
  225. smalltalk.method({
  226. selector: "arguments",
  227. protocol: 'interpreting',
  228. fn: function (){
  229. var self=this;
  230. return smalltalk.withContext(function($ctx1) {
  231. var $1;
  232. $1=_st(_st(self._ast())._arguments())._collect_((function(each){
  233. return smalltalk.withContext(function($ctx2) {
  234. return self._localAt_(each);
  235. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  236. return $1;
  237. }, function($ctx1) {$ctx1.fill(self,"arguments",{},globals.AIContext)})},
  238. args: [],
  239. source: "arguments\x0a\x09^ self ast arguments collect: [ :each |\x0a\x09\x09self localAt: each ]",
  240. messageSends: ["collect:", "arguments", "ast", "localAt:"],
  241. referencedClasses: []
  242. }),
  243. globals.AIContext);
  244. smalltalk.addMethod(
  245. smalltalk.method({
  246. selector: "ast",
  247. protocol: 'interpreting',
  248. fn: function (){
  249. var self=this;
  250. return smalltalk.withContext(function($ctx1) {
  251. var $1,$3,$2,$4,$5;
  252. $1=self._isBlockContext();
  253. if(smalltalk.assert($1)){
  254. $3=self._outerContext();
  255. if(($receiver = $3) == nil || $receiver == null){
  256. $2=$3;
  257. } else {
  258. var context;
  259. context=$receiver;
  260. $2=_st(context)._ast();
  261. };
  262. return $2;
  263. };
  264. $4=self["@ast"];
  265. if(($receiver = $4) == nil || $receiver == null){
  266. self._initializeAST();
  267. } else {
  268. $4;
  269. };
  270. $5=self["@ast"];
  271. return $5;
  272. }, function($ctx1) {$ctx1.fill(self,"ast",{},globals.AIContext)})},
  273. args: [],
  274. source: "ast\x0a\x09self isBlockContext ifTrue: [ \x0a\x09\x09^ self outerContext ifNotNil: [ :context | context ast ] ].\x0a\x0a\x09ast ifNil: [ self initializeAST ].\x0a\x09^ ast",
  275. messageSends: ["ifTrue:", "isBlockContext", "ifNotNil:", "outerContext", "ast", "ifNil:", "initializeAST"],
  276. referencedClasses: []
  277. }),
  278. globals.AIContext);
  279. smalltalk.addMethod(
  280. smalltalk.method({
  281. selector: "evaluateNode:",
  282. protocol: 'evaluating',
  283. fn: function (aNode){
  284. var self=this;
  285. function $ASTInterpreter(){return globals.ASTInterpreter||(typeof ASTInterpreter=="undefined"?nil:ASTInterpreter)}
  286. return smalltalk.withContext(function($ctx1) {
  287. var $2,$3,$1;
  288. $2=_st($ASTInterpreter())._new();
  289. _st($2)._context_(self);
  290. _st($2)._node_(_st(aNode)._nextChild());
  291. _st($2)._proceed();
  292. $3=_st($2)._result();
  293. $1=$3;
  294. return $1;
  295. }, function($ctx1) {$ctx1.fill(self,"evaluateNode:",{aNode:aNode},globals.AIContext)})},
  296. args: ["aNode"],
  297. source: "evaluateNode: aNode\x0a\x09^ ASTInterpreter new\x0a\x09\x09context: self;\x0a\x09\x09node: aNode nextChild;\x0a\x09\x09proceed;\x0a\x09\x09result",
  298. messageSends: ["context:", "new", "node:", "nextChild", "proceed", "result"],
  299. referencedClasses: ["ASTInterpreter"]
  300. }),
  301. globals.AIContext);
  302. smalltalk.addMethod(
  303. smalltalk.method({
  304. selector: "evaluatedSelector",
  305. protocol: 'accessing',
  306. fn: function (){
  307. var self=this;
  308. var $1;
  309. $1=self["@evaluatedSelector"];
  310. return $1;
  311. },
  312. args: [],
  313. source: "evaluatedSelector\x0a\x09^ evaluatedSelector",
  314. messageSends: [],
  315. referencedClasses: []
  316. }),
  317. globals.AIContext);
  318. smalltalk.addMethod(
  319. smalltalk.method({
  320. selector: "evaluatedSelector:",
  321. protocol: 'accessing',
  322. fn: function (aString){
  323. var self=this;
  324. self["@evaluatedSelector"]=aString;
  325. return self},
  326. args: ["aString"],
  327. source: "evaluatedSelector: aString\x0a\x09evaluatedSelector := aString",
  328. messageSends: [],
  329. referencedClasses: []
  330. }),
  331. globals.AIContext);
  332. smalltalk.addMethod(
  333. smalltalk.method({
  334. selector: "index",
  335. protocol: 'accessing',
  336. fn: function (){
  337. var self=this;
  338. return smalltalk.withContext(function($ctx1) {
  339. var $2,$1;
  340. $2=self["@index"];
  341. if(($receiver = $2) == nil || $receiver == null){
  342. $1=(0);
  343. } else {
  344. $1=$2;
  345. };
  346. return $1;
  347. }, function($ctx1) {$ctx1.fill(self,"index",{},globals.AIContext)})},
  348. args: [],
  349. source: "index\x0a\x09^ index ifNil: [ 0 ]",
  350. messageSends: ["ifNil:"],
  351. referencedClasses: []
  352. }),
  353. globals.AIContext);
  354. smalltalk.addMethod(
  355. smalltalk.method({
  356. selector: "index:",
  357. protocol: 'accessing',
  358. fn: function (anInteger){
  359. var self=this;
  360. self["@index"]=anInteger;
  361. return self},
  362. args: ["anInteger"],
  363. source: "index: anInteger\x0a\x09index := anInteger",
  364. messageSends: [],
  365. referencedClasses: []
  366. }),
  367. globals.AIContext);
  368. smalltalk.addMethod(
  369. smalltalk.method({
  370. selector: "initializeAST",
  371. protocol: 'initialization',
  372. fn: function (){
  373. var self=this;
  374. function $SemanticAnalyzer(){return globals.SemanticAnalyzer||(typeof SemanticAnalyzer=="undefined"?nil:SemanticAnalyzer)}
  375. return smalltalk.withContext(function($ctx1) {
  376. var $1;
  377. $1=self._method();
  378. $ctx1.sendIdx["method"]=1;
  379. self["@ast"]=_st($1)._ast();
  380. _st(_st($SemanticAnalyzer())._on_(_st(self._method())._methodClass()))._visit_(self["@ast"]);
  381. return self}, function($ctx1) {$ctx1.fill(self,"initializeAST",{},globals.AIContext)})},
  382. args: [],
  383. source: "initializeAST\x0a\x09ast := self method ast.\x0a\x09(SemanticAnalyzer on: self method methodClass)\x0a\x09\x09visit: ast",
  384. messageSends: ["ast", "method", "visit:", "on:", "methodClass"],
  385. referencedClasses: ["SemanticAnalyzer"]
  386. }),
  387. globals.AIContext);
  388. smalltalk.addMethod(
  389. smalltalk.method({
  390. selector: "initializeFromMethodContext:",
  391. protocol: 'initialization',
  392. fn: function (aMethodContext){
  393. var self=this;
  394. return smalltalk.withContext(function($ctx1) {
  395. var $1,$2,$3,$4;
  396. self._evaluatedSelector_(_st(aMethodContext)._evaluatedSelector());
  397. self._index_(_st(aMethodContext)._index());
  398. self._sendIndexes_(_st(aMethodContext)._sendIndexes());
  399. self._receiver_(_st(aMethodContext)._receiver());
  400. $1=self._selector_(_st(aMethodContext)._selector());
  401. $2=_st(aMethodContext)._outerContext();
  402. $ctx1.sendIdx["outerContext"]=1;
  403. if(($receiver = $2) == nil || $receiver == null){
  404. $2;
  405. } else {
  406. var outer;
  407. outer=$receiver;
  408. $3=_st(outer)._methodContext();
  409. if(($receiver = $3) == nil || $receiver == null){
  410. $3;
  411. } else {
  412. self._outerContext_(_st(self._class())._fromMethodContext_(_st(aMethodContext)._outerContext()));
  413. };
  414. $4=_st(aMethodContext)._locals();
  415. $ctx1.sendIdx["locals"]=1;
  416. _st($4)._keysAndValuesDo_((function(key,value){
  417. return smalltalk.withContext(function($ctx2) {
  418. return _st(self._locals())._at_put_(key,value);
  419. }, function($ctx2) {$ctx2.fillBlock({key:key,value:value},$ctx1,3)})}));
  420. };
  421. return self}, function($ctx1) {$ctx1.fill(self,"initializeFromMethodContext:",{aMethodContext:aMethodContext},globals.AIContext)})},
  422. args: ["aMethodContext"],
  423. source: "initializeFromMethodContext: aMethodContext\x0a\x0a\x09self\x0a\x09\x09evaluatedSelector: aMethodContext evaluatedSelector;\x0a\x09\x09index: aMethodContext index;\x0a\x09\x09sendIndexes: aMethodContext sendIndexes;\x0a\x09\x09receiver: aMethodContext receiver;\x0a\x09\x09selector: aMethodContext selector.\x0a\x09\x09\x0a\x09aMethodContext outerContext ifNotNil: [ :outer |\x0a\x09\x09\x22If the method context is nil, the block was defined in JS, so ignore it\x22\x0a\x09\x09outer methodContext ifNotNil: [\x0a\x09\x09\x09self outerContext: (self class fromMethodContext: aMethodContext outerContext) ].\x0a\x09\x09\x09aMethodContext locals keysAndValuesDo: [ :key :value |\x0a\x09\x09\x09\x09self locals at: key put: value ] ]",
  424. messageSends: ["evaluatedSelector:", "evaluatedSelector", "index:", "index", "sendIndexes:", "sendIndexes", "receiver:", "receiver", "selector:", "selector", "ifNotNil:", "outerContext", "methodContext", "outerContext:", "fromMethodContext:", "class", "keysAndValuesDo:", "locals", "at:put:"],
  425. referencedClasses: []
  426. }),
  427. globals.AIContext);
  428. smalltalk.addMethod(
  429. smalltalk.method({
  430. selector: "initializeInterpreter",
  431. protocol: 'initialization',
  432. fn: function (){
  433. var self=this;
  434. function $ASTInterpreter(){return globals.ASTInterpreter||(typeof ASTInterpreter=="undefined"?nil:ASTInterpreter)}
  435. return smalltalk.withContext(function($ctx1) {
  436. var $1,$2,$3;
  437. $1=_st($ASTInterpreter())._new();
  438. _st($1)._context_(self);
  439. $2=_st($1)._yourself();
  440. self["@interpreter"]=$2;
  441. $3=self._innerContext();
  442. if(($receiver = $3) == nil || $receiver == null){
  443. $3;
  444. } else {
  445. self._setupInterpreter_(self["@interpreter"]);
  446. };
  447. return self}, function($ctx1) {$ctx1.fill(self,"initializeInterpreter",{},globals.AIContext)})},
  448. args: [],
  449. source: "initializeInterpreter\x0a\x09interpreter := ASTInterpreter new\x0a\x09\x09context: self;\x0a\x09\x09yourself.\x0a\x09\x0a\x09self innerContext ifNotNil: [\x0a\x09\x09self setupInterpreter: interpreter ]",
  450. messageSends: ["context:", "new", "yourself", "ifNotNil:", "innerContext", "setupInterpreter:"],
  451. referencedClasses: ["ASTInterpreter"]
  452. }),
  453. globals.AIContext);
  454. smalltalk.addMethod(
  455. smalltalk.method({
  456. selector: "initializeLocals",
  457. protocol: 'initialization',
  458. fn: function (){
  459. var self=this;
  460. function $Dictionary(){return globals.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  461. return smalltalk.withContext(function($ctx1) {
  462. self["@locals"]=_st($Dictionary())._new();
  463. _st(self["@locals"])._at_put_("thisContext",self);
  464. return self}, function($ctx1) {$ctx1.fill(self,"initializeLocals",{},globals.AIContext)})},
  465. args: [],
  466. source: "initializeLocals\x0a\x09locals := Dictionary new.\x0a\x09locals at: 'thisContext' put: self.",
  467. messageSends: ["new", "at:put:"],
  468. referencedClasses: ["Dictionary"]
  469. }),
  470. globals.AIContext);
  471. smalltalk.addMethod(
  472. smalltalk.method({
  473. selector: "innerContext",
  474. protocol: 'accessing',
  475. fn: function (){
  476. var self=this;
  477. var $1;
  478. $1=self["@innerContext"];
  479. return $1;
  480. },
  481. args: [],
  482. source: "innerContext\x0a\x09^ innerContext",
  483. messageSends: [],
  484. referencedClasses: []
  485. }),
  486. globals.AIContext);
  487. smalltalk.addMethod(
  488. smalltalk.method({
  489. selector: "innerContext:",
  490. protocol: 'accessing',
  491. fn: function (anAIContext){
  492. var self=this;
  493. self["@innerContext"]=anAIContext;
  494. return self},
  495. args: ["anAIContext"],
  496. source: "innerContext: anAIContext\x0a\x09innerContext := anAIContext",
  497. messageSends: [],
  498. referencedClasses: []
  499. }),
  500. globals.AIContext);
  501. smalltalk.addMethod(
  502. smalltalk.method({
  503. selector: "interpreter",
  504. protocol: 'interpreting',
  505. fn: function (){
  506. var self=this;
  507. return smalltalk.withContext(function($ctx1) {
  508. var $1,$2;
  509. $1=self["@interpreter"];
  510. if(($receiver = $1) == nil || $receiver == null){
  511. self._initializeInterpreter();
  512. } else {
  513. $1;
  514. };
  515. $2=self["@interpreter"];
  516. return $2;
  517. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},globals.AIContext)})},
  518. args: [],
  519. source: "interpreter\x0a\x09interpreter ifNil: [ self initializeInterpreter ].\x0a\x09^ interpreter",
  520. messageSends: ["ifNil:", "initializeInterpreter"],
  521. referencedClasses: []
  522. }),
  523. globals.AIContext);
  524. smalltalk.addMethod(
  525. smalltalk.method({
  526. selector: "interpreter:",
  527. protocol: 'interpreting',
  528. fn: function (anInterpreter){
  529. var self=this;
  530. self["@interpreter"]=anInterpreter;
  531. return self},
  532. args: ["anInterpreter"],
  533. source: "interpreter: anInterpreter\x0a\x09interpreter := anInterpreter",
  534. messageSends: [],
  535. referencedClasses: []
  536. }),
  537. globals.AIContext);
  538. smalltalk.addMethod(
  539. smalltalk.method({
  540. selector: "localAt:",
  541. protocol: 'accessing',
  542. fn: function (aString){
  543. var self=this;
  544. return smalltalk.withContext(function($ctx1) {
  545. var $2,$1;
  546. $1=_st(self._locals())._at_ifAbsent_(aString,(function(){
  547. return smalltalk.withContext(function($ctx2) {
  548. $2=self._outerContext();
  549. if(($receiver = $2) == nil || $receiver == null){
  550. return $2;
  551. } else {
  552. var context;
  553. context=$receiver;
  554. return _st(context)._localAt_(aString);
  555. };
  556. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  557. return $1;
  558. }, function($ctx1) {$ctx1.fill(self,"localAt:",{aString:aString},globals.AIContext)})},
  559. args: ["aString"],
  560. source: "localAt: aString\x0a\x09\x22Lookup the local value up to the method context\x22\x0a\x0a\x09^ self locals at: aString ifAbsent: [ \x0a\x09\x09self outerContext ifNotNil: [ :context | \x0a\x09\x09\x09context localAt: aString ] ]",
  561. messageSends: ["at:ifAbsent:", "locals", "ifNotNil:", "outerContext", "localAt:"],
  562. referencedClasses: []
  563. }),
  564. globals.AIContext);
  565. smalltalk.addMethod(
  566. smalltalk.method({
  567. selector: "localAt:ifAbsent:",
  568. protocol: 'accessing',
  569. fn: function (aString,aBlock){
  570. var self=this;
  571. return smalltalk.withContext(function($ctx1) {
  572. var $2,$1;
  573. $1=_st(self._locals())._at_ifAbsent_(aString,(function(){
  574. return smalltalk.withContext(function($ctx2) {
  575. $2=self._outerContext();
  576. if(($receiver = $2) == nil || $receiver == null){
  577. return _st(aBlock)._value();
  578. } else {
  579. var context;
  580. context=$receiver;
  581. return _st(context)._localAt_ifAbsent_(aString,aBlock);
  582. };
  583. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  584. return $1;
  585. }, function($ctx1) {$ctx1.fill(self,"localAt:ifAbsent:",{aString:aString,aBlock:aBlock},globals.AIContext)})},
  586. args: ["aString", "aBlock"],
  587. source: "localAt: aString ifAbsent: aBlock\x0a\x09\x22Lookup the local value up to the method context\x22\x0a\x0a\x09^ self locals at: aString ifAbsent: [ \x0a\x09\x09self outerContext \x0a\x09\x09\x09ifNotNil: [ :context | context localAt: aString ifAbsent: aBlock ]\x0a\x09\x09\x09ifNil: [ aBlock value ] ]",
  588. messageSends: ["at:ifAbsent:", "locals", "ifNotNil:ifNil:", "outerContext", "localAt:ifAbsent:", "value"],
  589. referencedClasses: []
  590. }),
  591. globals.AIContext);
  592. smalltalk.addMethod(
  593. smalltalk.method({
  594. selector: "localAt:put:",
  595. protocol: 'accessing',
  596. fn: function (aString,anObject){
  597. var self=this;
  598. return smalltalk.withContext(function($ctx1) {
  599. _st(self._locals())._at_put_(aString,anObject);
  600. return self}, function($ctx1) {$ctx1.fill(self,"localAt:put:",{aString:aString,anObject:anObject},globals.AIContext)})},
  601. args: ["aString", "anObject"],
  602. source: "localAt: aString put: anObject\x0a\x09self locals at: aString put: anObject",
  603. messageSends: ["at:put:", "locals"],
  604. referencedClasses: []
  605. }),
  606. globals.AIContext);
  607. smalltalk.addMethod(
  608. smalltalk.method({
  609. selector: "locals",
  610. protocol: 'accessing',
  611. fn: function (){
  612. var self=this;
  613. return smalltalk.withContext(function($ctx1) {
  614. var $1,$2;
  615. $1=self["@locals"];
  616. if(($receiver = $1) == nil || $receiver == null){
  617. self._initializeLocals();
  618. } else {
  619. $1;
  620. };
  621. $2=self["@locals"];
  622. return $2;
  623. }, function($ctx1) {$ctx1.fill(self,"locals",{},globals.AIContext)})},
  624. args: [],
  625. source: "locals\x0a\x09locals ifNil: [ self initializeLocals ].\x0a\x09\x0a\x09^ locals",
  626. messageSends: ["ifNil:", "initializeLocals"],
  627. referencedClasses: []
  628. }),
  629. globals.AIContext);
  630. smalltalk.addMethod(
  631. smalltalk.method({
  632. selector: "method",
  633. protocol: 'accessing',
  634. fn: function (){
  635. var self=this;
  636. return smalltalk.withContext(function($ctx1) {
  637. var $2,$5,$4,$3,$1;
  638. $2=self._methodContext();
  639. $ctx1.sendIdx["methodContext"]=1;
  640. if(($receiver = $2) == nil || $receiver == null){
  641. $1=$2;
  642. } else {
  643. $5=self._methodContext();
  644. $ctx1.sendIdx["methodContext"]=2;
  645. $4=_st($5)._receiver();
  646. $3=_st($4)._class();
  647. $1=_st($3)._lookupSelector_(_st(self._methodContext())._selector());
  648. };
  649. return $1;
  650. }, function($ctx1) {$ctx1.fill(self,"method",{},globals.AIContext)})},
  651. args: [],
  652. source: "method\x0a\x09^ self methodContext ifNotNil: [\x0a\x09\x09self methodContext receiver class lookupSelector: self methodContext selector ]",
  653. messageSends: ["ifNotNil:", "methodContext", "lookupSelector:", "class", "receiver", "selector"],
  654. referencedClasses: []
  655. }),
  656. globals.AIContext);
  657. smalltalk.addMethod(
  658. smalltalk.method({
  659. selector: "newBlockContext",
  660. protocol: 'factory',
  661. fn: function (){
  662. var self=this;
  663. return smalltalk.withContext(function($ctx1) {
  664. var $2,$3,$1;
  665. $2=_st(self._class())._new();
  666. _st($2)._outerContext_(self);
  667. $3=_st($2)._yourself();
  668. $1=$3;
  669. return $1;
  670. }, function($ctx1) {$ctx1.fill(self,"newBlockContext",{},globals.AIContext)})},
  671. args: [],
  672. source: "newBlockContext\x0a\x09^ self class new\x0a\x09\x09outerContext: self;\x0a\x09\x09yourself",
  673. messageSends: ["outerContext:", "new", "class", "yourself"],
  674. referencedClasses: []
  675. }),
  676. globals.AIContext);
  677. smalltalk.addMethod(
  678. smalltalk.method({
  679. selector: "outerContext",
  680. protocol: 'accessing',
  681. fn: function (){
  682. var self=this;
  683. var $1;
  684. $1=self["@outerContext"];
  685. return $1;
  686. },
  687. args: [],
  688. source: "outerContext\x0a\x09^ outerContext",
  689. messageSends: [],
  690. referencedClasses: []
  691. }),
  692. globals.AIContext);
  693. smalltalk.addMethod(
  694. smalltalk.method({
  695. selector: "outerContext:",
  696. protocol: 'accessing',
  697. fn: function (anAIContext){
  698. var self=this;
  699. return smalltalk.withContext(function($ctx1) {
  700. var $1;
  701. self["@outerContext"]=anAIContext;
  702. $1=self["@outerContext"];
  703. if(($receiver = $1) == nil || $receiver == null){
  704. $1;
  705. } else {
  706. var context;
  707. context=$receiver;
  708. _st(context)._innerContext_(self);
  709. };
  710. return self}, function($ctx1) {$ctx1.fill(self,"outerContext:",{anAIContext:anAIContext},globals.AIContext)})},
  711. args: ["anAIContext"],
  712. source: "outerContext: anAIContext\x0a\x09outerContext := anAIContext.\x0a\x09outerContext ifNotNil: [ :context | \x0a\x09\x09context innerContext: self ]",
  713. messageSends: ["ifNotNil:", "innerContext:"],
  714. referencedClasses: []
  715. }),
  716. globals.AIContext);
  717. smalltalk.addMethod(
  718. smalltalk.method({
  719. selector: "receiver",
  720. protocol: 'interpreting',
  721. fn: function (){
  722. var self=this;
  723. return smalltalk.withContext(function($ctx1) {
  724. var $1;
  725. $1=self._localAt_("self");
  726. return $1;
  727. }, function($ctx1) {$ctx1.fill(self,"receiver",{},globals.AIContext)})},
  728. args: [],
  729. source: "receiver\x0a\x09^ self localAt: 'self'",
  730. messageSends: ["localAt:"],
  731. referencedClasses: []
  732. }),
  733. globals.AIContext);
  734. smalltalk.addMethod(
  735. smalltalk.method({
  736. selector: "receiver:",
  737. protocol: 'interpreting',
  738. fn: function (anObject){
  739. var self=this;
  740. return smalltalk.withContext(function($ctx1) {
  741. self._localAt_put_("self",anObject);
  742. return self}, function($ctx1) {$ctx1.fill(self,"receiver:",{anObject:anObject},globals.AIContext)})},
  743. args: ["anObject"],
  744. source: "receiver: anObject\x0a\x09self localAt: 'self' put: anObject",
  745. messageSends: ["localAt:put:"],
  746. referencedClasses: []
  747. }),
  748. globals.AIContext);
  749. smalltalk.addMethod(
  750. smalltalk.method({
  751. selector: "selector",
  752. protocol: 'accessing',
  753. fn: function (){
  754. var self=this;
  755. var $1;
  756. $1=self["@selector"];
  757. return $1;
  758. },
  759. args: [],
  760. source: "selector\x0a\x09^ selector",
  761. messageSends: [],
  762. referencedClasses: []
  763. }),
  764. globals.AIContext);
  765. smalltalk.addMethod(
  766. smalltalk.method({
  767. selector: "selector:",
  768. protocol: 'accessing',
  769. fn: function (aString){
  770. var self=this;
  771. self["@selector"]=aString;
  772. return self},
  773. args: ["aString"],
  774. source: "selector: aString\x0a\x09selector := aString",
  775. messageSends: [],
  776. referencedClasses: []
  777. }),
  778. globals.AIContext);
  779. smalltalk.addMethod(
  780. smalltalk.method({
  781. selector: "sendIndexAt:",
  782. protocol: 'accessing',
  783. fn: function (aString){
  784. var self=this;
  785. return smalltalk.withContext(function($ctx1) {
  786. var $1;
  787. $1=_st(self._sendIndexes())._at_ifAbsent_(aString,(function(){
  788. return (0);
  789. }));
  790. return $1;
  791. }, function($ctx1) {$ctx1.fill(self,"sendIndexAt:",{aString:aString},globals.AIContext)})},
  792. args: ["aString"],
  793. source: "sendIndexAt: aString\x0a\x09^ self sendIndexes at: aString ifAbsent: [ 0 ]",
  794. messageSends: ["at:ifAbsent:", "sendIndexes"],
  795. referencedClasses: []
  796. }),
  797. globals.AIContext);
  798. smalltalk.addMethod(
  799. smalltalk.method({
  800. selector: "sendIndexes",
  801. protocol: 'accessing',
  802. fn: function (){
  803. var self=this;
  804. function $Dictionary(){return globals.Dictionary||(typeof Dictionary=="undefined"?nil:Dictionary)}
  805. return smalltalk.withContext(function($ctx1) {
  806. var $2,$1;
  807. $2=self["@sendIndexes"];
  808. if(($receiver = $2) == nil || $receiver == null){
  809. $1=_st($Dictionary())._new();
  810. } else {
  811. $1=$2;
  812. };
  813. return $1;
  814. }, function($ctx1) {$ctx1.fill(self,"sendIndexes",{},globals.AIContext)})},
  815. args: [],
  816. source: "sendIndexes\x0a\x09^ sendIndexes ifNil: [ Dictionary new ]",
  817. messageSends: ["ifNil:", "new"],
  818. referencedClasses: ["Dictionary"]
  819. }),
  820. globals.AIContext);
  821. smalltalk.addMethod(
  822. smalltalk.method({
  823. selector: "sendIndexes:",
  824. protocol: 'accessing',
  825. fn: function (aDictionary){
  826. var self=this;
  827. self["@sendIndexes"]=aDictionary;
  828. return self},
  829. args: ["aDictionary"],
  830. source: "sendIndexes: aDictionary\x0a\x09sendIndexes := aDictionary",
  831. messageSends: [],
  832. referencedClasses: []
  833. }),
  834. globals.AIContext);
  835. smalltalk.addMethod(
  836. smalltalk.method({
  837. selector: "setupInterpreter:",
  838. protocol: 'interpreting',
  839. fn: function (anInterpreter){
  840. var self=this;
  841. var currentNode;
  842. function $ASTPCNodeVisitor(){return globals.ASTPCNodeVisitor||(typeof ASTPCNodeVisitor=="undefined"?nil:ASTPCNodeVisitor)}
  843. return smalltalk.withContext(function($ctx1) {
  844. var $1,$2,$5,$4,$3;
  845. $1=_st($ASTPCNodeVisitor())._new();
  846. _st($1)._selector_(self._evaluatedSelector());
  847. _st($1)._context_(self);
  848. _st($1)._visit_(self._ast());
  849. $2=_st($1)._currentNode();
  850. currentNode=$2;
  851. _st(anInterpreter)._node_(currentNode);
  852. $5=self._innerContext();
  853. $ctx1.sendIdx["innerContext"]=1;
  854. $4=_st($5)._arguments();
  855. $3=_st($4)._reversed();
  856. _st($3)._do_((function(each){
  857. return smalltalk.withContext(function($ctx2) {
  858. return _st(anInterpreter)._push_(each);
  859. $ctx2.sendIdx["push:"]=1;
  860. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  861. _st(anInterpreter)._push_(_st(self._innerContext())._receiver());
  862. return self}, function($ctx1) {$ctx1.fill(self,"setupInterpreter:",{anInterpreter:anInterpreter,currentNode:currentNode},globals.AIContext)})},
  863. args: ["anInterpreter"],
  864. source: "setupInterpreter: anInterpreter\x0a\x09| currentNode |\x0a\x09\x0a\x09\x22Retrieve the current node\x22\x0a\x09currentNode := ASTPCNodeVisitor new\x0a\x09\x09\x09selector: self evaluatedSelector;\x0a\x09\x09\x09context: self;\x0a\x09\x09\x09visit: self ast;\x0a\x09\x09\x09currentNode.\x0a\x09\x0a\x09anInterpreter node: currentNode.\x0a\x0a\x09\x22Push the send args and receiver to the interpreter stack\x22\x09\x0a\x09self innerContext arguments reversed do: [ :each | \x0a\x09\x09anInterpreter push: each ].\x0a\x09\x09\x0a\x09anInterpreter push: (self innerContext receiver)",
  865. messageSends: ["selector:", "new", "evaluatedSelector", "context:", "visit:", "ast", "currentNode", "node:", "do:", "reversed", "arguments", "innerContext", "push:", "receiver"],
  866. referencedClasses: ["ASTPCNodeVisitor"]
  867. }),
  868. globals.AIContext);
  869. smalltalk.addMethod(
  870. smalltalk.method({
  871. selector: "fromMethodContext:",
  872. protocol: 'instance creation',
  873. fn: function (aMethodContext){
  874. var self=this;
  875. return smalltalk.withContext(function($ctx1) {
  876. var $2,$3,$1;
  877. $2=self._new();
  878. _st($2)._initializeFromMethodContext_(aMethodContext);
  879. $3=_st($2)._yourself();
  880. $1=$3;
  881. return $1;
  882. }, function($ctx1) {$ctx1.fill(self,"fromMethodContext:",{aMethodContext:aMethodContext},globals.AIContext.klass)})},
  883. args: ["aMethodContext"],
  884. source: "fromMethodContext: aMethodContext\x0a\x09^ self new\x0a\x09\x09initializeFromMethodContext: aMethodContext;\x0a\x09\x09yourself",
  885. messageSends: ["initializeFromMethodContext:", "new", "yourself"],
  886. referencedClasses: []
  887. }),
  888. globals.AIContext.klass);
  889. smalltalk.addClass('ASTDebugger', globals.Object, ['interpreter', 'context'], 'Compiler-Interpreter');
  890. globals.ASTDebugger.comment="I am a stepping debugger interface for Amber code.\x0aI internally use an instance of `ASTInterpreter` to actually step through node and interpret them.\x0a\x0aMy instances are created from an `AIContext` with `ASTDebugger class >> context:`.\x0aThey hold an `AIContext` instance internally, recursive copy of the `MethodContext`.\x0a\x0a## API\x0a\x0aUse the methods of the `'stepping'` protocol to do stepping.";
  891. smalltalk.addMethod(
  892. smalltalk.method({
  893. selector: "atEnd",
  894. protocol: 'testing',
  895. fn: function (){
  896. var self=this;
  897. return smalltalk.withContext(function($ctx1) {
  898. var $1;
  899. $1=_st(self._interpreter())._atEnd();
  900. return $1;
  901. }, function($ctx1) {$ctx1.fill(self,"atEnd",{},globals.ASTDebugger)})},
  902. args: [],
  903. source: "atEnd\x0a\x09^ self interpreter atEnd",
  904. messageSends: ["atEnd", "interpreter"],
  905. referencedClasses: []
  906. }),
  907. globals.ASTDebugger);
  908. smalltalk.addMethod(
  909. smalltalk.method({
  910. selector: "context",
  911. protocol: 'accessing',
  912. fn: function (){
  913. var self=this;
  914. var $1;
  915. $1=self["@context"];
  916. return $1;
  917. },
  918. args: [],
  919. source: "context\x0a\x09^ context",
  920. messageSends: [],
  921. referencedClasses: []
  922. }),
  923. globals.ASTDebugger);
  924. smalltalk.addMethod(
  925. smalltalk.method({
  926. selector: "context:",
  927. protocol: 'accessing',
  928. fn: function (aContext){
  929. var self=this;
  930. self["@context"]=aContext;
  931. return self},
  932. args: ["aContext"],
  933. source: "context: aContext\x0a\x09context := aContext",
  934. messageSends: [],
  935. referencedClasses: []
  936. }),
  937. globals.ASTDebugger);
  938. smalltalk.addMethod(
  939. smalltalk.method({
  940. selector: "interpreter",
  941. protocol: 'accessing',
  942. fn: function (){
  943. var self=this;
  944. return smalltalk.withContext(function($ctx1) {
  945. var $1;
  946. $1=_st(self._context())._interpreter();
  947. return $1;
  948. }, function($ctx1) {$ctx1.fill(self,"interpreter",{},globals.ASTDebugger)})},
  949. args: [],
  950. source: "interpreter\x0a\x09^ self context interpreter",
  951. messageSends: ["interpreter", "context"],
  952. referencedClasses: []
  953. }),
  954. globals.ASTDebugger);
  955. smalltalk.addMethod(
  956. smalltalk.method({
  957. selector: "method",
  958. protocol: 'accessing',
  959. fn: function (){
  960. var self=this;
  961. return smalltalk.withContext(function($ctx1) {
  962. var $1;
  963. $1=_st(self._context())._method();
  964. return $1;
  965. }, function($ctx1) {$ctx1.fill(self,"method",{},globals.ASTDebugger)})},
  966. args: [],
  967. source: "method\x0a\x09^ self context method",
  968. messageSends: ["method", "context"],
  969. referencedClasses: []
  970. }),
  971. globals.ASTDebugger);
  972. smalltalk.addMethod(
  973. smalltalk.method({
  974. selector: "nextNode",
  975. protocol: 'accessing',
  976. fn: function (){
  977. var self=this;
  978. return smalltalk.withContext(function($ctx1) {
  979. var $1;
  980. $1=_st(self._interpreter())._nextNode();
  981. return $1;
  982. }, function($ctx1) {$ctx1.fill(self,"nextNode",{},globals.ASTDebugger)})},
  983. args: [],
  984. source: "nextNode\x0a\x09^ self interpreter nextNode",
  985. messageSends: ["nextNode", "interpreter"],
  986. referencedClasses: []
  987. }),
  988. globals.ASTDebugger);
  989. smalltalk.addMethod(
  990. smalltalk.method({
  991. selector: "proceed",
  992. protocol: 'stepping',
  993. fn: function (){
  994. var self=this;
  995. return smalltalk.withContext(function($ctx1) {
  996. self._shouldBeImplemented();
  997. return self}, function($ctx1) {$ctx1.fill(self,"proceed",{},globals.ASTDebugger)})},
  998. args: [],
  999. source: "proceed\x0a\x09self shouldBeImplemented",
  1000. messageSends: ["shouldBeImplemented"],
  1001. referencedClasses: []
  1002. }),
  1003. globals.ASTDebugger);
  1004. smalltalk.addMethod(
  1005. smalltalk.method({
  1006. selector: "restart",
  1007. protocol: 'stepping',
  1008. fn: function (){
  1009. var self=this;
  1010. return smalltalk.withContext(function($ctx1) {
  1011. _st(self._interpreter())._restart();
  1012. return self}, function($ctx1) {$ctx1.fill(self,"restart",{},globals.ASTDebugger)})},
  1013. args: [],
  1014. source: "restart\x0a\x09self interpreter restart",
  1015. messageSends: ["restart", "interpreter"],
  1016. referencedClasses: []
  1017. }),
  1018. globals.ASTDebugger);
  1019. smalltalk.addMethod(
  1020. smalltalk.method({
  1021. selector: "skip",
  1022. protocol: 'stepping',
  1023. fn: function (){
  1024. var self=this;
  1025. return smalltalk.withContext(function($ctx1) {
  1026. _st(self._interpreter())._skip();
  1027. return self}, function($ctx1) {$ctx1.fill(self,"skip",{},globals.ASTDebugger)})},
  1028. args: [],
  1029. source: "skip\x0a\x09self interpreter skip",
  1030. messageSends: ["skip", "interpreter"],
  1031. referencedClasses: []
  1032. }),
  1033. globals.ASTDebugger);
  1034. smalltalk.addMethod(
  1035. smalltalk.method({
  1036. selector: "stepInto",
  1037. protocol: 'stepping',
  1038. fn: function (){
  1039. var self=this;
  1040. return smalltalk.withContext(function($ctx1) {
  1041. self._shouldBeImplemented();
  1042. return self}, function($ctx1) {$ctx1.fill(self,"stepInto",{},globals.ASTDebugger)})},
  1043. args: [],
  1044. source: "stepInto\x0a\x09self shouldBeImplemented",
  1045. messageSends: ["shouldBeImplemented"],
  1046. referencedClasses: []
  1047. }),
  1048. globals.ASTDebugger);
  1049. smalltalk.addMethod(
  1050. smalltalk.method({
  1051. selector: "stepOver",
  1052. protocol: 'stepping',
  1053. fn: function (){
  1054. var self=this;
  1055. return smalltalk.withContext(function($ctx1) {
  1056. self._flushOuterContexts();
  1057. _st(self._interpreter())._stepOver();
  1058. return self}, function($ctx1) {$ctx1.fill(self,"stepOver",{},globals.ASTDebugger)})},
  1059. args: [],
  1060. source: "stepOver\x0a\x09self flushOuterContexts.\x0a\x09self interpreter stepOver",
  1061. messageSends: ["flushOuterContexts", "stepOver", "interpreter"],
  1062. referencedClasses: []
  1063. }),
  1064. globals.ASTDebugger);
  1065. smalltalk.addMethod(
  1066. smalltalk.method({
  1067. selector: "context:",
  1068. protocol: 'instance creation',
  1069. fn: function (aContext){
  1070. var self=this;
  1071. return smalltalk.withContext(function($ctx1) {
  1072. var $2,$3,$1;
  1073. $2=self._new();
  1074. _st($2)._context_(aContext);
  1075. $3=_st($2)._yourself();
  1076. $1=$3;
  1077. return $1;
  1078. }, function($ctx1) {$ctx1.fill(self,"context:",{aContext:aContext},globals.ASTDebugger.klass)})},
  1079. args: ["aContext"],
  1080. source: "context: aContext\x0a\x09^ self new\x0a\x09\x09context: aContext;\x0a\x09\x09yourself",
  1081. messageSends: ["context:", "new", "yourself"],
  1082. referencedClasses: []
  1083. }),
  1084. globals.ASTDebugger.klass);
  1085. smalltalk.addClass('ASTInterpreter', globals.NodeVisitor, ['node', 'context', 'stack', 'returnValue', 'returned'], 'Compiler-Interpreter');
  1086. globals.ASTInterpreter.comment="I visit an AST, interpreting (evaluating) nodes one after the other, using a small stack machine.\x0a\x0a## API\x0a\x0aWhile my instances should be used from within an `ASTDebugger`, which provides a more high level interface,\x0ayou can use methods from the `interpreting` protocol:\x0a\x0a- `#step` evaluates the current `node` only\x0a- `#stepOver` evaluates the AST from the current `node` up to the next stepping node (most likely the next send node)\x0a- `#proceed` evaluates eagerly the AST\x0a- `#restart` select the first node of the AST\x0a- `#skip` skips the current node, moving to the next one if any";
  1087. smalltalk.addMethod(
  1088. smalltalk.method({
  1089. selector: "assign:to:",
  1090. protocol: 'private',
  1091. fn: function (aNode,anObject){
  1092. var self=this;
  1093. return smalltalk.withContext(function($ctx1) {
  1094. var $1,$3,$2,$4;
  1095. $1=_st(_st(aNode)._binding())._isInstanceVar();
  1096. if(smalltalk.assert($1)){
  1097. $3=self._context();
  1098. $ctx1.sendIdx["context"]=1;
  1099. $2=_st($3)._receiver();
  1100. $4=_st(aNode)._value();
  1101. $ctx1.sendIdx["value"]=1;
  1102. _st($2)._instVarAt_put_($4,anObject);
  1103. } else {
  1104. _st(self._context())._localAt_put_(_st(aNode)._value(),anObject);
  1105. };
  1106. return self}, function($ctx1) {$ctx1.fill(self,"assign:to:",{aNode:aNode,anObject:anObject},globals.ASTInterpreter)})},
  1107. args: ["aNode", "anObject"],
  1108. source: "assign: aNode to: anObject\x0a\x09aNode binding isInstanceVar\x0a\x09\x09ifTrue: [ self context receiver instVarAt: aNode value put: anObject ]\x0a\x09\x09ifFalse: [ self context localAt: aNode value put: anObject ]",
  1109. messageSends: ["ifTrue:ifFalse:", "isInstanceVar", "binding", "instVarAt:put:", "receiver", "context", "value", "localAt:put:"],
  1110. referencedClasses: []
  1111. }),
  1112. globals.ASTInterpreter);
  1113. smalltalk.addMethod(
  1114. smalltalk.method({
  1115. selector: "atEnd",
  1116. protocol: 'testing',
  1117. fn: function (){
  1118. var self=this;
  1119. return smalltalk.withContext(function($ctx1) {
  1120. var $1;
  1121. $1=_st(self._hasReturned())._or_((function(){
  1122. return smalltalk.withContext(function($ctx2) {
  1123. return _st(self._node())._isNil();
  1124. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
  1125. return $1;
  1126. }, function($ctx1) {$ctx1.fill(self,"atEnd",{},globals.ASTInterpreter)})},
  1127. args: [],
  1128. source: "atEnd\x0a\x09^ self hasReturned or: [ self node isNil ]",
  1129. messageSends: ["or:", "hasReturned", "isNil", "node"],
  1130. referencedClasses: []
  1131. }),
  1132. globals.ASTInterpreter);
  1133. smalltalk.addMethod(
  1134. smalltalk.method({
  1135. selector: "context",
  1136. protocol: 'accessing',
  1137. fn: function (){
  1138. var self=this;
  1139. var $1;
  1140. $1=self["@context"];
  1141. return $1;
  1142. },
  1143. args: [],
  1144. source: "context\x0a\x09^ context",
  1145. messageSends: [],
  1146. referencedClasses: []
  1147. }),
  1148. globals.ASTInterpreter);
  1149. smalltalk.addMethod(
  1150. smalltalk.method({
  1151. selector: "context:",
  1152. protocol: 'accessing',
  1153. fn: function (aContext){
  1154. var self=this;
  1155. self["@context"]=aContext;
  1156. return self},
  1157. args: ["aContext"],
  1158. source: "context: aContext\x0a\x09context := aContext",
  1159. messageSends: [],
  1160. referencedClasses: []
  1161. }),
  1162. globals.ASTInterpreter);
  1163. smalltalk.addMethod(
  1164. smalltalk.method({
  1165. selector: "eval:",
  1166. protocol: 'private',
  1167. fn: function (aString){
  1168. var self=this;
  1169. var source,function_;
  1170. function $String(){return globals.String||(typeof String=="undefined"?nil:String)}
  1171. function $Compiler(){return globals.Compiler||(typeof Compiler=="undefined"?nil:Compiler)}
  1172. return smalltalk.withContext(function($ctx1) {
  1173. var $3,$2,$1,$4,$5;
  1174. source=_st($String())._streamContents_((function(str){
  1175. return smalltalk.withContext(function($ctx2) {
  1176. _st(str)._nextPutAll_("(function(");
  1177. $ctx2.sendIdx["nextPutAll:"]=1;
  1178. $3=self._context();
  1179. $ctx2.sendIdx["context"]=1;
  1180. $2=_st($3)._locals();
  1181. $ctx2.sendIdx["locals"]=1;
  1182. $1=_st($2)._keys();
  1183. _st($1)._do_separatedBy_((function(each){
  1184. return smalltalk.withContext(function($ctx3) {
  1185. return _st(str)._nextPutAll_(each);
  1186. $ctx3.sendIdx["nextPutAll:"]=2;
  1187. }, function($ctx3) {$ctx3.fillBlock({each:each},$ctx2,2)})}),(function(){
  1188. return smalltalk.withContext(function($ctx3) {
  1189. return _st(str)._nextPutAll_(",");
  1190. $ctx3.sendIdx["nextPutAll:"]=3;
  1191. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,3)})}));
  1192. _st(str)._nextPutAll_("){ return (function() {");
  1193. $ctx2.sendIdx["nextPutAll:"]=4;
  1194. _st(str)._nextPutAll_(aString);
  1195. $ctx2.sendIdx["nextPutAll:"]=5;
  1196. $4=_st(str)._nextPutAll_("})() })");
  1197. return $4;
  1198. }, function($ctx2) {$ctx2.fillBlock({str:str},$ctx1,1)})}));
  1199. function_=_st(_st($Compiler())._new())._eval_(source);
  1200. $5=_st(function_)._valueWithPossibleArguments_(_st(_st(self._context())._locals())._values());
  1201. return $5;
  1202. }, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString,source:source,function_:function_},globals.ASTInterpreter)})},
  1203. args: ["aString"],
  1204. source: "eval: aString\x0a\x09\x22Evaluate aString as JS source inside an JS function.\x0a\x09aString is not sandboxed.\x22\x0a\x09\x0a\x09| source function |\x0a\x09\x0a\x09source := String streamContents: [ :str |\x0a\x09\x09str nextPutAll: '(function('.\x0a\x09\x09self context locals keys\x0a\x09\x09\x09do: [ :each | str nextPutAll: each ]\x0a\x09\x09\x09separatedBy: [ str nextPutAll: ',' ].\x0a\x09\x09str\x0a\x09\x09\x09nextPutAll: '){ return (function() {';\x0a\x09\x09\x09nextPutAll: aString;\x0a\x09\x09\x09nextPutAll: '})() })' ].\x0a\x09\x09\x09\x0a\x09function := Compiler new eval: source.\x0a\x09\x0a\x09^ function valueWithPossibleArguments: self context locals values",
  1205. messageSends: ["streamContents:", "nextPutAll:", "do:separatedBy:", "keys", "locals", "context", "eval:", "new", "valueWithPossibleArguments:", "values"],
  1206. referencedClasses: ["String", "Compiler"]
  1207. }),
  1208. globals.ASTInterpreter);
  1209. smalltalk.addMethod(
  1210. smalltalk.method({
  1211. selector: "hasReturned",
  1212. protocol: 'testing',
  1213. fn: function (){
  1214. var self=this;
  1215. return smalltalk.withContext(function($ctx1) {
  1216. var $2,$1;
  1217. $2=self["@returned"];
  1218. if(($receiver = $2) == nil || $receiver == null){
  1219. $1=false;
  1220. } else {
  1221. $1=$2;
  1222. };
  1223. return $1;
  1224. }, function($ctx1) {$ctx1.fill(self,"hasReturned",{},globals.ASTInterpreter)})},
  1225. args: [],
  1226. source: "hasReturned\x0a\x09^ returned ifNil: [ false ]",
  1227. messageSends: ["ifNil:"],
  1228. referencedClasses: []
  1229. }),
  1230. globals.ASTInterpreter);
  1231. smalltalk.addMethod(
  1232. smalltalk.method({
  1233. selector: "interpret",
  1234. protocol: 'interpreting',
  1235. fn: function (){
  1236. var self=this;
  1237. return smalltalk.withContext(function($ctx1) {
  1238. self._visit_(self._node());
  1239. return self}, function($ctx1) {$ctx1.fill(self,"interpret",{},globals.ASTInterpreter)})},
  1240. args: [],
  1241. source: "interpret\x0a\x09\x22Interpret the next node to be evaluated\x22\x0a\x09\x0a\x09self visit: self node",
  1242. messageSends: ["visit:", "node"],
  1243. referencedClasses: []
  1244. }),
  1245. globals.ASTInterpreter);
  1246. smalltalk.addMethod(
  1247. smalltalk.method({
  1248. selector: "interpret:",
  1249. protocol: 'interpreting',
  1250. fn: function (aNode){
  1251. var self=this;
  1252. return smalltalk.withContext(function($ctx1) {
  1253. self._node_(aNode);
  1254. self._interpret();
  1255. return self}, function($ctx1) {$ctx1.fill(self,"interpret:",{aNode:aNode},globals.ASTInterpreter)})},
  1256. args: ["aNode"],
  1257. source: "interpret: aNode\x0a\x09self node: aNode.\x0a\x09self interpret",
  1258. messageSends: ["node:", "interpret"],
  1259. referencedClasses: []
  1260. }),
  1261. globals.ASTInterpreter);
  1262. smalltalk.addMethod(
  1263. smalltalk.method({
  1264. selector: "messageFromSendNode:arguments:",
  1265. protocol: 'private',
  1266. fn: function (aSendNode,aCollection){
  1267. var self=this;
  1268. function $Message(){return globals.Message||(typeof Message=="undefined"?nil:Message)}
  1269. return smalltalk.withContext(function($ctx1) {
  1270. var $2,$3,$1;
  1271. $2=_st($Message())._new();
  1272. _st($2)._selector_(_st(aSendNode)._selector());
  1273. _st($2)._arguments_(aCollection);
  1274. $3=_st($2)._yourself();
  1275. $1=$3;
  1276. return $1;
  1277. }, function($ctx1) {$ctx1.fill(self,"messageFromSendNode:arguments:",{aSendNode:aSendNode,aCollection:aCollection},globals.ASTInterpreter)})},
  1278. args: ["aSendNode", "aCollection"],
  1279. source: "messageFromSendNode: aSendNode arguments: aCollection\x0a\x09^ Message new\x0a\x09\x09selector: aSendNode selector;\x0a\x09\x09arguments: aCollection;\x0a\x09\x09yourself",
  1280. messageSends: ["selector:", "new", "selector", "arguments:", "yourself"],
  1281. referencedClasses: ["Message"]
  1282. }),
  1283. globals.ASTInterpreter);
  1284. smalltalk.addMethod(
  1285. smalltalk.method({
  1286. selector: "messageNotUnderstood:receiver:",
  1287. protocol: 'private',
  1288. fn: function (aMessage,anObject){
  1289. var self=this;
  1290. function $MessageNotUnderstood(){return globals.MessageNotUnderstood||(typeof MessageNotUnderstood=="undefined"?nil:MessageNotUnderstood)}
  1291. return smalltalk.withContext(function($ctx1) {
  1292. var $1,$2;
  1293. $1=_st($MessageNotUnderstood())._new();
  1294. _st($1)._meesage_(aMessage);
  1295. _st($1)._receiver_(anObject);
  1296. $2=_st($1)._signal();
  1297. return self}, function($ctx1) {$ctx1.fill(self,"messageNotUnderstood:receiver:",{aMessage:aMessage,anObject:anObject},globals.ASTInterpreter)})},
  1298. args: ["aMessage", "anObject"],
  1299. source: "messageNotUnderstood: aMessage receiver: anObject\x0a\x09MessageNotUnderstood new\x0a\x09\x09meesage: aMessage;\x0a\x09\x09receiver: anObject;\x0a\x09\x09signal",
  1300. messageSends: ["meesage:", "new", "receiver:", "signal"],
  1301. referencedClasses: ["MessageNotUnderstood"]
  1302. }),
  1303. globals.ASTInterpreter);
  1304. smalltalk.addMethod(
  1305. smalltalk.method({
  1306. selector: "next",
  1307. protocol: 'interpreting',
  1308. fn: function (){
  1309. var self=this;
  1310. return smalltalk.withContext(function($ctx1) {
  1311. self._node_(_st(self._node())._nextNode());
  1312. return self}, function($ctx1) {$ctx1.fill(self,"next",{},globals.ASTInterpreter)})},
  1313. args: [],
  1314. source: "next\x0a\x09self node: self node nextNode",
  1315. messageSends: ["node:", "nextNode", "node"],
  1316. referencedClasses: []
  1317. }),
  1318. globals.ASTInterpreter);
  1319. smalltalk.addMethod(
  1320. smalltalk.method({
  1321. selector: "node",
  1322. protocol: 'accessing',
  1323. fn: function (){
  1324. var self=this;
  1325. var $1;
  1326. $1=self["@node"];
  1327. return $1;
  1328. },
  1329. args: [],
  1330. source: "node\x0a\x09\x22Answer the next node, ie the node to be evaluated in the next step\x22\x0a\x09\x0a\x09^ node",
  1331. messageSends: [],
  1332. referencedClasses: []
  1333. }),
  1334. globals.ASTInterpreter);
  1335. smalltalk.addMethod(
  1336. smalltalk.method({
  1337. selector: "node:",
  1338. protocol: 'accessing',
  1339. fn: function (aNode){
  1340. var self=this;
  1341. self["@node"]=aNode;
  1342. return self},
  1343. args: ["aNode"],
  1344. source: "node: aNode\x0a\x09node := aNode",
  1345. messageSends: [],
  1346. referencedClasses: []
  1347. }),
  1348. globals.ASTInterpreter);
  1349. smalltalk.addMethod(
  1350. smalltalk.method({
  1351. selector: "peek",
  1352. protocol: 'stack',
  1353. fn: function (){
  1354. var self=this;
  1355. return smalltalk.withContext(function($ctx1) {
  1356. var $1,$2;
  1357. var $early={};
  1358. try {
  1359. $1=self._stack();
  1360. $ctx1.sendIdx["stack"]=1;
  1361. _st($1)._ifEmpty_((function(){
  1362. throw $early=[nil];
  1363. }));
  1364. $2=_st(self._stack())._last();
  1365. return $2;
  1366. }
  1367. catch(e) {if(e===$early)return e[0]; throw e}
  1368. }, function($ctx1) {$ctx1.fill(self,"peek",{},globals.ASTInterpreter)})},
  1369. args: [],
  1370. source: "peek\x0a\x09\x22Peek the top object of the context stack\x22\x0a\x09\x0a\x09self stack ifEmpty: [ ^ nil ].\x0a\x09\x0a\x09^ self stack last",
  1371. messageSends: ["ifEmpty:", "stack", "last"],
  1372. referencedClasses: []
  1373. }),
  1374. globals.ASTInterpreter);
  1375. smalltalk.addMethod(
  1376. smalltalk.method({
  1377. selector: "pop",
  1378. protocol: 'stack',
  1379. fn: function (){
  1380. var self=this;
  1381. var peekedValue;
  1382. return smalltalk.withContext(function($ctx1) {
  1383. var $1;
  1384. peekedValue=self._peek();
  1385. _st(self._stack())._removeLast();
  1386. $1=peekedValue;
  1387. return $1;
  1388. }, function($ctx1) {$ctx1.fill(self,"pop",{peekedValue:peekedValue},globals.ASTInterpreter)})},
  1389. args: [],
  1390. source: "pop\x0a\x09\x22Pop an object from the context stack\x22\x0a\x09\x0a\x09| peekedValue |\x0a\x09\x0a\x09peekedValue := self peek.\x0a\x09self stack removeLast.\x0a\x09^ peekedValue",
  1391. messageSends: ["peek", "removeLast", "stack"],
  1392. referencedClasses: []
  1393. }),
  1394. globals.ASTInterpreter);
  1395. smalltalk.addMethod(
  1396. smalltalk.method({
  1397. selector: "proceed",
  1398. protocol: 'interpreting',
  1399. fn: function (){
  1400. var self=this;
  1401. return smalltalk.withContext(function($ctx1) {
  1402. _st((function(){
  1403. return smalltalk.withContext(function($ctx2) {
  1404. return self._atEnd();
  1405. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}))._whileFalse_((function(){
  1406. return smalltalk.withContext(function($ctx2) {
  1407. return self._step();
  1408. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  1409. return self}, function($ctx1) {$ctx1.fill(self,"proceed",{},globals.ASTInterpreter)})},
  1410. args: [],
  1411. source: "proceed\x0a\x09\x22Eagerly evaluate the ast\x22\x0a\x09\x0a\x09[ self atEnd ] \x0a\x09\x09whileFalse: [ self step ]",
  1412. messageSends: ["whileFalse:", "atEnd", "step"],
  1413. referencedClasses: []
  1414. }),
  1415. globals.ASTInterpreter);
  1416. smalltalk.addMethod(
  1417. smalltalk.method({
  1418. selector: "push:",
  1419. protocol: 'stack',
  1420. fn: function (anObject){
  1421. var self=this;
  1422. return smalltalk.withContext(function($ctx1) {
  1423. var $1;
  1424. $1=_st(self._stack())._add_(anObject);
  1425. return $1;
  1426. }, function($ctx1) {$ctx1.fill(self,"push:",{anObject:anObject},globals.ASTInterpreter)})},
  1427. args: ["anObject"],
  1428. source: "push: anObject\x0a\x09\x22Push an object to the context stack\x22\x0a\x09\x0a\x09^ self stack add: anObject",
  1429. messageSends: ["add:", "stack"],
  1430. referencedClasses: []
  1431. }),
  1432. globals.ASTInterpreter);
  1433. smalltalk.addMethod(
  1434. smalltalk.method({
  1435. selector: "restart",
  1436. protocol: 'interpreting',
  1437. fn: function (){
  1438. var self=this;
  1439. return smalltalk.withContext(function($ctx1) {
  1440. self._node_(_st(_st(self._context())._ast())._nextChild());
  1441. return self}, function($ctx1) {$ctx1.fill(self,"restart",{},globals.ASTInterpreter)})},
  1442. args: [],
  1443. source: "restart\x0a\x09self node: self context ast nextChild",
  1444. messageSends: ["node:", "nextChild", "ast", "context"],
  1445. referencedClasses: []
  1446. }),
  1447. globals.ASTInterpreter);
  1448. smalltalk.addMethod(
  1449. smalltalk.method({
  1450. selector: "result",
  1451. protocol: 'accessing',
  1452. fn: function (){
  1453. var self=this;
  1454. return smalltalk.withContext(function($ctx1) {
  1455. var $2,$1;
  1456. $2=self._hasReturned();
  1457. if(smalltalk.assert($2)){
  1458. $1=self._returnValue();
  1459. } else {
  1460. $1=_st(self._context())._receiver();
  1461. };
  1462. return $1;
  1463. }, function($ctx1) {$ctx1.fill(self,"result",{},globals.ASTInterpreter)})},
  1464. args: [],
  1465. source: "result\x0a\x09^ self hasReturned \x0a\x09\x09ifTrue: [ self returnValue ] \x0a\x09\x09ifFalse: [ self context receiver ]",
  1466. messageSends: ["ifTrue:ifFalse:", "hasReturned", "returnValue", "receiver", "context"],
  1467. referencedClasses: []
  1468. }),
  1469. globals.ASTInterpreter);
  1470. smalltalk.addMethod(
  1471. smalltalk.method({
  1472. selector: "returnValue",
  1473. protocol: 'accessing',
  1474. fn: function (){
  1475. var self=this;
  1476. var $1;
  1477. $1=self["@returnValue"];
  1478. return $1;
  1479. },
  1480. args: [],
  1481. source: "returnValue\x0a\x09^ returnValue",
  1482. messageSends: [],
  1483. referencedClasses: []
  1484. }),
  1485. globals.ASTInterpreter);
  1486. smalltalk.addMethod(
  1487. smalltalk.method({
  1488. selector: "returnValue:",
  1489. protocol: 'accessing',
  1490. fn: function (anObject){
  1491. var self=this;
  1492. self["@returnValue"]=anObject;
  1493. return self},
  1494. args: ["anObject"],
  1495. source: "returnValue: anObject\x0a\x09returnValue := anObject",
  1496. messageSends: [],
  1497. referencedClasses: []
  1498. }),
  1499. globals.ASTInterpreter);
  1500. smalltalk.addMethod(
  1501. smalltalk.method({
  1502. selector: "sendMessage:to:superSend:",
  1503. protocol: 'private',
  1504. fn: function (aMessage,anObject,aBoolean){
  1505. var self=this;
  1506. var method;
  1507. return smalltalk.withContext(function($ctx1) {
  1508. var $1,$3,$2,$4,$5,$6;
  1509. var $early={};
  1510. try {
  1511. if(! smalltalk.assert(aBoolean)){
  1512. $1=_st(aMessage)._sendTo_(anObject);
  1513. return $1;
  1514. };
  1515. $3=_st(anObject)._class();
  1516. $ctx1.sendIdx["class"]=1;
  1517. $2=_st($3)._superclass();
  1518. $ctx1.sendIdx["superclass"]=1;
  1519. if(($receiver = $2) == nil || $receiver == null){
  1520. $4=self._messageNotUnderstood_receiver_(aMessage,anObject);
  1521. $ctx1.sendIdx["messageNotUnderstood:receiver:"]=1;
  1522. return $4;
  1523. } else {
  1524. $2;
  1525. };
  1526. method=_st(_st(_st(_st(anObject)._class())._superclass())._methodDictionary())._at_ifAbsent_(_st(aMessage)._selector(),(function(){
  1527. return smalltalk.withContext(function($ctx2) {
  1528. $5=self._messageNotUnderstood_receiver_(aMessage,anObject);
  1529. throw $early=[$5];
  1530. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,3)})}));
  1531. $6=_st(method)._sendTo_arguments_(anObject,_st(aMessage)._arguments());
  1532. return $6;
  1533. }
  1534. catch(e) {if(e===$early)return e[0]; throw e}
  1535. }, function($ctx1) {$ctx1.fill(self,"sendMessage:to:superSend:",{aMessage:aMessage,anObject:anObject,aBoolean:aBoolean,method:method},globals.ASTInterpreter)})},
  1536. args: ["aMessage", "anObject", "aBoolean"],
  1537. source: "sendMessage: aMessage to: anObject superSend: aBoolean\x0a\x09| method |\x0a\x09\x0a\x09aBoolean ifFalse: [ ^ aMessage sendTo: anObject ].\x0a\x09anObject class superclass ifNil: [ ^ self messageNotUnderstood: aMessage receiver: anObject ].\x0a\x09\x0a\x09method := anObject class superclass methodDictionary\x0a\x09\x09at: aMessage selector\x0a\x09\x09ifAbsent: [ ^ self messageNotUnderstood: aMessage receiver: anObject ].\x0a\x09\x09\x0a\x09^ method sendTo: anObject arguments: aMessage arguments",
  1538. messageSends: ["ifFalse:", "sendTo:", "ifNil:", "superclass", "class", "messageNotUnderstood:receiver:", "at:ifAbsent:", "methodDictionary", "selector", "sendTo:arguments:", "arguments"],
  1539. referencedClasses: []
  1540. }),
  1541. globals.ASTInterpreter);
  1542. smalltalk.addMethod(
  1543. smalltalk.method({
  1544. selector: "setNonLocalReturnFromContext:",
  1545. protocol: 'interpreting',
  1546. fn: function (aContext){
  1547. var self=this;
  1548. return smalltalk.withContext(function($ctx1) {
  1549. var $2,$1;
  1550. $2=_st(aContext)._interpreter();
  1551. $ctx1.sendIdx["interpreter"]=1;
  1552. $1=_st($2)._hasReturned();
  1553. if(smalltalk.assert($1)){
  1554. self["@returned"]=true;
  1555. self["@returned"];
  1556. self._returnValue_(_st(_st(aContext)._interpreter())._returnValue());
  1557. };
  1558. return self}, function($ctx1) {$ctx1.fill(self,"setNonLocalReturnFromContext:",{aContext:aContext},globals.ASTInterpreter)})},
  1559. args: ["aContext"],
  1560. source: "setNonLocalReturnFromContext: aContext\x0a\x09aContext interpreter hasReturned ifTrue: [\x0a\x09\x09returned := true.\x0a\x09\x09self returnValue: aContext interpreter returnValue ]",
  1561. messageSends: ["ifTrue:", "hasReturned", "interpreter", "returnValue:", "returnValue"],
  1562. referencedClasses: []
  1563. }),
  1564. globals.ASTInterpreter);
  1565. smalltalk.addMethod(
  1566. smalltalk.method({
  1567. selector: "skip",
  1568. protocol: 'interpreting',
  1569. fn: function (){
  1570. var self=this;
  1571. return smalltalk.withContext(function($ctx1) {
  1572. self._next();
  1573. return self}, function($ctx1) {$ctx1.fill(self,"skip",{},globals.ASTInterpreter)})},
  1574. args: [],
  1575. source: "skip\x0a\x09self next",
  1576. messageSends: ["next"],
  1577. referencedClasses: []
  1578. }),
  1579. globals.ASTInterpreter);
  1580. smalltalk.addMethod(
  1581. smalltalk.method({
  1582. selector: "stack",
  1583. protocol: 'accessing',
  1584. fn: function (){
  1585. var self=this;
  1586. function $OrderedCollection(){return globals.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  1587. return smalltalk.withContext(function($ctx1) {
  1588. var $2,$1;
  1589. $2=self["@stack"];
  1590. if(($receiver = $2) == nil || $receiver == null){
  1591. self["@stack"]=_st($OrderedCollection())._new();
  1592. $1=self["@stack"];
  1593. } else {
  1594. $1=$2;
  1595. };
  1596. return $1;
  1597. }, function($ctx1) {$ctx1.fill(self,"stack",{},globals.ASTInterpreter)})},
  1598. args: [],
  1599. source: "stack\x0a\x09^ stack ifNil: [ stack := OrderedCollection new ]",
  1600. messageSends: ["ifNil:", "new"],
  1601. referencedClasses: ["OrderedCollection"]
  1602. }),
  1603. globals.ASTInterpreter);
  1604. smalltalk.addMethod(
  1605. smalltalk.method({
  1606. selector: "step",
  1607. protocol: 'interpreting',
  1608. fn: function (){
  1609. var self=this;
  1610. return smalltalk.withContext(function($ctx1) {
  1611. var $1;
  1612. self._interpret();
  1613. $1=self._next();
  1614. return self}, function($ctx1) {$ctx1.fill(self,"step",{},globals.ASTInterpreter)})},
  1615. args: [],
  1616. source: "step\x0a\x09self \x0a\x09\x09interpret; \x0a\x09\x09next",
  1617. messageSends: ["interpret", "next"],
  1618. referencedClasses: []
  1619. }),
  1620. globals.ASTInterpreter);
  1621. smalltalk.addMethod(
  1622. smalltalk.method({
  1623. selector: "stepOver",
  1624. protocol: 'interpreting',
  1625. fn: function (){
  1626. var self=this;
  1627. return smalltalk.withContext(function($ctx1) {
  1628. self._step();
  1629. $ctx1.sendIdx["step"]=1;
  1630. _st((function(){
  1631. return smalltalk.withContext(function($ctx2) {
  1632. return _st(self._node())._isSteppingNode();
  1633. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}))._whileFalse_((function(){
  1634. return smalltalk.withContext(function($ctx2) {
  1635. return self._step();
  1636. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  1637. return self}, function($ctx1) {$ctx1.fill(self,"stepOver",{},globals.ASTInterpreter)})},
  1638. args: [],
  1639. source: "stepOver\x0a\x09self step.\x0a\x09\x0a\x09[ self node isSteppingNode ] whileFalse: [ \x0a\x09\x09self step ]",
  1640. messageSends: ["step", "whileFalse:", "isSteppingNode", "node"],
  1641. referencedClasses: []
  1642. }),
  1643. globals.ASTInterpreter);
  1644. smalltalk.addMethod(
  1645. smalltalk.method({
  1646. selector: "visit:",
  1647. protocol: 'visiting',
  1648. fn: function (aNode){
  1649. var self=this;
  1650. return smalltalk.withContext(function($ctx1) {
  1651. var $1;
  1652. $1=self._hasReturned();
  1653. if(! smalltalk.assert($1)){
  1654. globals.ASTInterpreter.superclass.fn.prototype._visit_.apply(_st(self), [aNode]);
  1655. };
  1656. return self}, function($ctx1) {$ctx1.fill(self,"visit:",{aNode:aNode},globals.ASTInterpreter)})},
  1657. args: ["aNode"],
  1658. source: "visit: aNode\x0a\x09self hasReturned ifFalse: [ super visit: aNode ]",
  1659. messageSends: ["ifFalse:", "hasReturned", "visit:"],
  1660. referencedClasses: []
  1661. }),
  1662. globals.ASTInterpreter);
  1663. smalltalk.addMethod(
  1664. smalltalk.method({
  1665. selector: "visitAssignmentNode:",
  1666. protocol: 'visiting',
  1667. fn: function (aNode){
  1668. var self=this;
  1669. var poppedValue;
  1670. return smalltalk.withContext(function($ctx1) {
  1671. poppedValue=self._pop();
  1672. $ctx1.sendIdx["pop"]=1;
  1673. self._pop();
  1674. self._push_(poppedValue);
  1675. self._assign_to_(_st(aNode)._left(),poppedValue);
  1676. return self}, function($ctx1) {$ctx1.fill(self,"visitAssignmentNode:",{aNode:aNode,poppedValue:poppedValue},globals.ASTInterpreter)})},
  1677. args: ["aNode"],
  1678. source: "visitAssignmentNode: aNode\x0a\x09| poppedValue |\x0a\x09\x0a\x09poppedValue := self pop.\x0a\x09\x0a\x09\x22Pop the left side of the assignment.\x0a\x09It already has been visited, and we don't need its value.\x22\x0a\x09self pop.\x0a\x09\x0a\x09self push: poppedValue.\x0a\x09self assign: aNode left to: poppedValue",
  1679. messageSends: ["pop", "push:", "assign:to:", "left"],
  1680. referencedClasses: []
  1681. }),
  1682. globals.ASTInterpreter);
  1683. smalltalk.addMethod(
  1684. smalltalk.method({
  1685. selector: "visitBlockNode:",
  1686. protocol: 'visiting',
  1687. fn: function (aNode){
  1688. var self=this;
  1689. var block;
  1690. function $AIBlockClosure(){return globals.AIBlockClosure||(typeof AIBlockClosure=="undefined"?nil:AIBlockClosure)}
  1691. return smalltalk.withContext(function($ctx1) {
  1692. block=_st($AIBlockClosure())._forContext_node_(self._context(),aNode);
  1693. self._push_(block);
  1694. return self}, function($ctx1) {$ctx1.fill(self,"visitBlockNode:",{aNode:aNode,block:block},globals.ASTInterpreter)})},
  1695. args: ["aNode"],
  1696. source: "visitBlockNode: aNode\x0a\x09\x22Do not evaluate the block node.\x0a\x09Instead, put all instructions into a block that we push to the stack for later evaluation\x22\x0a\x09\x0a\x09| block |\x0a\x09\x0a\x09block := AIBlockClosure forContext: self context node: aNode.\x0a\x09\x0a\x09self push: block",
  1697. messageSends: ["forContext:node:", "context", "push:"],
  1698. referencedClasses: ["AIBlockClosure"]
  1699. }),
  1700. globals.ASTInterpreter);
  1701. smalltalk.addMethod(
  1702. smalltalk.method({
  1703. selector: "visitDynamicArrayNode:",
  1704. protocol: 'visiting',
  1705. fn: function (aNode){
  1706. var self=this;
  1707. var array;
  1708. return smalltalk.withContext(function($ctx1) {
  1709. array=[];
  1710. _st(_st(aNode)._nodes())._do_((function(each){
  1711. return smalltalk.withContext(function($ctx2) {
  1712. return _st(array)._addFirst_(self._pop());
  1713. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1714. self._push_(array);
  1715. return self}, function($ctx1) {$ctx1.fill(self,"visitDynamicArrayNode:",{aNode:aNode,array:array},globals.ASTInterpreter)})},
  1716. args: ["aNode"],
  1717. source: "visitDynamicArrayNode: aNode\x0a\x09| array |\x0a\x09\x0a\x09array := #().\x0a\x09aNode nodes do: [ :each |\x0a\x09\x09array addFirst: self pop ].\x0a\x09\x0a\x09self push: array",
  1718. messageSends: ["do:", "nodes", "addFirst:", "pop", "push:"],
  1719. referencedClasses: []
  1720. }),
  1721. globals.ASTInterpreter);
  1722. smalltalk.addMethod(
  1723. smalltalk.method({
  1724. selector: "visitDynamicDictionaryNode:",
  1725. protocol: 'visiting',
  1726. fn: function (aNode){
  1727. var self=this;
  1728. var associations,hashedCollection;
  1729. function $OrderedCollection(){return globals.OrderedCollection||(typeof OrderedCollection=="undefined"?nil:OrderedCollection)}
  1730. function $HashedCollection(){return globals.HashedCollection||(typeof HashedCollection=="undefined"?nil:HashedCollection)}
  1731. return smalltalk.withContext(function($ctx1) {
  1732. associations=_st($OrderedCollection())._new();
  1733. $ctx1.sendIdx["new"]=1;
  1734. hashedCollection=_st($HashedCollection())._new();
  1735. _st(_st(aNode)._nodes())._do_((function(each){
  1736. return smalltalk.withContext(function($ctx2) {
  1737. return _st(associations)._add_(self._pop());
  1738. $ctx2.sendIdx["add:"]=1;
  1739. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1740. $ctx1.sendIdx["do:"]=1;
  1741. _st(_st(associations)._reversed())._do_((function(each){
  1742. return smalltalk.withContext(function($ctx2) {
  1743. return _st(hashedCollection)._add_(each);
  1744. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)})}));
  1745. self._push_(hashedCollection);
  1746. return self}, function($ctx1) {$ctx1.fill(self,"visitDynamicDictionaryNode:",{aNode:aNode,associations:associations,hashedCollection:hashedCollection},globals.ASTInterpreter)})},
  1747. args: ["aNode"],
  1748. source: "visitDynamicDictionaryNode: aNode\x0a\x09| associations hashedCollection |\x0a\x09\x0a\x09associations := OrderedCollection new.\x0a\x09hashedCollection := HashedCollection new.\x0a\x09\x0a\x09aNode nodes do: [ :each | \x0a\x09\x09associations add: self pop ].\x0a\x09\x0a\x09associations reversed do: [ :each |\x0a\x09\x09hashedCollection add: each ].\x0a\x09\x0a\x09self push: hashedCollection",
  1749. messageSends: ["new", "do:", "nodes", "add:", "pop", "reversed", "push:"],
  1750. referencedClasses: ["OrderedCollection", "HashedCollection"]
  1751. }),
  1752. globals.ASTInterpreter);
  1753. smalltalk.addMethod(
  1754. smalltalk.method({
  1755. selector: "visitJSStatementNode:",
  1756. protocol: 'visiting',
  1757. fn: function (aNode){
  1758. var self=this;
  1759. return smalltalk.withContext(function($ctx1) {
  1760. self["@returned"]=true;
  1761. self._returnValue_(self._eval_(_st(aNode)._source()));
  1762. return self}, function($ctx1) {$ctx1.fill(self,"visitJSStatementNode:",{aNode:aNode},globals.ASTInterpreter)})},
  1763. args: ["aNode"],
  1764. source: "visitJSStatementNode: aNode\x0a\x09returned := true.\x0a\x09self returnValue: (self eval: aNode source)",
  1765. messageSends: ["returnValue:", "eval:", "source"],
  1766. referencedClasses: []
  1767. }),
  1768. globals.ASTInterpreter);
  1769. smalltalk.addMethod(
  1770. smalltalk.method({
  1771. selector: "visitNode:",
  1772. protocol: 'visiting',
  1773. fn: function (aNode){
  1774. var self=this;
  1775. return self},
  1776. args: ["aNode"],
  1777. source: "visitNode: aNode\x0a\x09\x22Do nothing by default. Especially, do not visit children recursively.\x22",
  1778. messageSends: [],
  1779. referencedClasses: []
  1780. }),
  1781. globals.ASTInterpreter);
  1782. smalltalk.addMethod(
  1783. smalltalk.method({
  1784. selector: "visitReturnNode:",
  1785. protocol: 'visiting',
  1786. fn: function (aNode){
  1787. var self=this;
  1788. return smalltalk.withContext(function($ctx1) {
  1789. self["@returned"]=true;
  1790. self._returnValue_(self._pop());
  1791. return self}, function($ctx1) {$ctx1.fill(self,"visitReturnNode:",{aNode:aNode},globals.ASTInterpreter)})},
  1792. args: ["aNode"],
  1793. source: "visitReturnNode: aNode\x0a\x09returned := true.\x0a\x09self returnValue: self pop",
  1794. messageSends: ["returnValue:", "pop"],
  1795. referencedClasses: []
  1796. }),
  1797. globals.ASTInterpreter);
  1798. smalltalk.addMethod(
  1799. smalltalk.method({
  1800. selector: "visitSendNode:",
  1801. protocol: 'visiting',
  1802. fn: function (aNode){
  1803. var self=this;
  1804. var receiver,args,message,result;
  1805. return smalltalk.withContext(function($ctx1) {
  1806. var $1;
  1807. args=_st(_st(aNode)._arguments())._collect_((function(each){
  1808. return smalltalk.withContext(function($ctx2) {
  1809. return self._pop();
  1810. $ctx2.sendIdx["pop"]=1;
  1811. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  1812. receiver=self._pop();
  1813. message=self._messageFromSendNode_arguments_(aNode,_st(args)._reversed());
  1814. result=self._sendMessage_to_superSend_(message,receiver,_st(aNode)._superSend());
  1815. $1=_st(_st(aNode)._isCascadeSendNode())._and_((function(){
  1816. return smalltalk.withContext(function($ctx2) {
  1817. return _st(_st(aNode)._isLastChild())._not();
  1818. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  1819. if(smalltalk.assert($1)){
  1820. self._push_(receiver);
  1821. $ctx1.sendIdx["push:"]=1;
  1822. } else {
  1823. self._push_(result);
  1824. };
  1825. return self}, function($ctx1) {$ctx1.fill(self,"visitSendNode:",{aNode:aNode,receiver:receiver,args:args,message:message,result:result},globals.ASTInterpreter)})},
  1826. args: ["aNode"],
  1827. source: "visitSendNode: aNode\x0a\x09| receiver args message result |\x0a\x09\x0a\x09args := aNode arguments collect: [ :each | self pop ].\x0a\x09receiver := self pop.\x0a\x09\x0a\x09message := self\x0a\x09\x09messageFromSendNode: aNode\x0a\x09\x09arguments: args reversed.\x0a\x09\x0a\x09result := self sendMessage: message to: receiver superSend: aNode superSend.\x0a\x09\x0a\x09\x22For cascade sends, push the reciever if the send is not the last one\x22\x0a\x09(aNode isCascadeSendNode and: [ aNode isLastChild not ])\x0a\x09\x09ifTrue: [ self push: receiver ]\x0a\x09\x09ifFalse: [ self push: result ]",
  1828. messageSends: ["collect:", "arguments", "pop", "messageFromSendNode:arguments:", "reversed", "sendMessage:to:superSend:", "superSend", "ifTrue:ifFalse:", "and:", "isCascadeSendNode", "not", "isLastChild", "push:"],
  1829. referencedClasses: []
  1830. }),
  1831. globals.ASTInterpreter);
  1832. smalltalk.addMethod(
  1833. smalltalk.method({
  1834. selector: "visitValueNode:",
  1835. protocol: 'visiting',
  1836. fn: function (aNode){
  1837. var self=this;
  1838. return smalltalk.withContext(function($ctx1) {
  1839. self._push_(_st(aNode)._value());
  1840. return self}, function($ctx1) {$ctx1.fill(self,"visitValueNode:",{aNode:aNode},globals.ASTInterpreter)})},
  1841. args: ["aNode"],
  1842. source: "visitValueNode: aNode\x0a\x09self push: aNode value",
  1843. messageSends: ["push:", "value"],
  1844. referencedClasses: []
  1845. }),
  1846. globals.ASTInterpreter);
  1847. smalltalk.addMethod(
  1848. smalltalk.method({
  1849. selector: "visitVariableNode:",
  1850. protocol: 'visiting',
  1851. fn: function (aNode){
  1852. var self=this;
  1853. function $PlatformInterface(){return globals.PlatformInterface||(typeof PlatformInterface=="undefined"?nil:PlatformInterface)}
  1854. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  1855. return smalltalk.withContext(function($ctx1) {
  1856. var $2,$1,$5,$6,$4,$3,$8,$10,$9,$11,$12,$13,$15,$14,$16,$17,$7;
  1857. $2=_st(aNode)._binding();
  1858. $ctx1.sendIdx["binding"]=1;
  1859. $1=_st($2)._isUnknownVar();
  1860. if(smalltalk.assert($1)){
  1861. $5=_st($PlatformInterface())._globals();
  1862. $ctx1.sendIdx["globals"]=1;
  1863. $6=_st(aNode)._value();
  1864. $ctx1.sendIdx["value"]=1;
  1865. $4=_st($5)._at_ifAbsent_($6,(function(){
  1866. return smalltalk.withContext(function($ctx2) {
  1867. return self._error_("Unknown variable");
  1868. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,2)})}));
  1869. $ctx1.sendIdx["at:ifAbsent:"]=1;
  1870. $3=self._push_($4);
  1871. $ctx1.sendIdx["push:"]=1;
  1872. return $3;
  1873. };
  1874. $8=_st(_st(aNode)._binding())._isInstanceVar();
  1875. if(smalltalk.assert($8)){
  1876. $10=self._context();
  1877. $ctx1.sendIdx["context"]=1;
  1878. $9=_st($10)._receiver();
  1879. $11=_st(aNode)._value();
  1880. $ctx1.sendIdx["value"]=2;
  1881. $7=_st($9)._instVarAt_($11);
  1882. } else {
  1883. $12=self._context();
  1884. $13=_st(aNode)._value();
  1885. $ctx1.sendIdx["value"]=3;
  1886. $7=_st($12)._localAt_ifAbsent_($13,(function(){
  1887. return smalltalk.withContext(function($ctx2) {
  1888. $15=_st(aNode)._value();
  1889. $ctx2.sendIdx["value"]=4;
  1890. $14=_st($15)._isCapitalized();
  1891. if(smalltalk.assert($14)){
  1892. $16=_st($Smalltalk())._globals();
  1893. $ctx2.sendIdx["globals"]=2;
  1894. $17=_st(aNode)._value();
  1895. $ctx2.sendIdx["value"]=5;
  1896. return _st($16)._at_ifAbsent_($17,(function(){
  1897. return smalltalk.withContext(function($ctx3) {
  1898. return _st(_st($PlatformInterface())._globals())._at_(_st(aNode)._value());
  1899. }, function($ctx3) {$ctx3.fillBlock({},$ctx2,7)})}));
  1900. };
  1901. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,5)})}));
  1902. };
  1903. self._push_($7);
  1904. return self}, function($ctx1) {$ctx1.fill(self,"visitVariableNode:",{aNode:aNode},globals.ASTInterpreter)})},
  1905. args: ["aNode"],
  1906. source: "visitVariableNode: aNode\x0a\x09aNode binding isUnknownVar ifTrue: [\x0a\x09\x09^ self push: (PlatformInterface globals at: aNode value ifAbsent: [ self error: 'Unknown variable' ]) ].\x0a\x09\x09\x0a\x09self push: (aNode binding isInstanceVar\x0a\x09\x09ifTrue: [ self context receiver instVarAt: aNode value ]\x0a\x09\x09ifFalse: [ self context \x0a\x09\x09\x09localAt: aNode value\x0a\x09\x09\x09ifAbsent: [\x0a\x09\x09\x09\x09aNode value isCapitalized\x0a\x09\x09\x09\x09\x09ifTrue: [\x0a\x09\x09\x09\x09\x09\x09Smalltalk globals \x0a\x09\x09\x09\x09\x09\x09\x09at: aNode value \x0a\x09\x09\x09\x09\x09\x09\x09ifAbsent: [ PlatformInterface globals at: aNode value ] ] ] ])",
  1907. messageSends: ["ifTrue:", "isUnknownVar", "binding", "push:", "at:ifAbsent:", "globals", "value", "error:", "ifTrue:ifFalse:", "isInstanceVar", "instVarAt:", "receiver", "context", "localAt:ifAbsent:", "isCapitalized", "at:"],
  1908. referencedClasses: ["PlatformInterface", "Smalltalk"]
  1909. }),
  1910. globals.ASTInterpreter);
  1911. smalltalk.addClass('ASTInterpreterError', globals.Error, [], 'Compiler-Interpreter');
  1912. globals.ASTInterpreterError.comment="I get signaled when an AST interpreter is unable to interpret a node.";
  1913. smalltalk.addClass('ASTPCNodeVisitor', globals.NodeVisitor, ['context', 'index', 'selector', 'currentNode'], 'Compiler-Interpreter');
  1914. globals.ASTPCNodeVisitor.comment="I visit an AST until I get to the current node for the `context` and answer it.\x0a\x0a## API\x0a\x0aMy instances must be filled with a context object using `#context:`.\x0a\x0aAfter visiting the AST the current node is answered by `#currentNode`";
  1915. smalltalk.addMethod(
  1916. smalltalk.method({
  1917. selector: "context",
  1918. protocol: 'accessing',
  1919. fn: function (){
  1920. var self=this;
  1921. var $1;
  1922. $1=self["@context"];
  1923. return $1;
  1924. },
  1925. args: [],
  1926. source: "context\x0a\x09^ context",
  1927. messageSends: [],
  1928. referencedClasses: []
  1929. }),
  1930. globals.ASTPCNodeVisitor);
  1931. smalltalk.addMethod(
  1932. smalltalk.method({
  1933. selector: "context:",
  1934. protocol: 'accessing',
  1935. fn: function (aContext){
  1936. var self=this;
  1937. self["@context"]=aContext;
  1938. return self},
  1939. args: ["aContext"],
  1940. source: "context: aContext\x0a\x09context := aContext",
  1941. messageSends: [],
  1942. referencedClasses: []
  1943. }),
  1944. globals.ASTPCNodeVisitor);
  1945. smalltalk.addMethod(
  1946. smalltalk.method({
  1947. selector: "currentNode",
  1948. protocol: 'accessing',
  1949. fn: function (){
  1950. var self=this;
  1951. var $1;
  1952. $1=self["@currentNode"];
  1953. return $1;
  1954. },
  1955. args: [],
  1956. source: "currentNode\x0a\x09^ currentNode",
  1957. messageSends: [],
  1958. referencedClasses: []
  1959. }),
  1960. globals.ASTPCNodeVisitor);
  1961. smalltalk.addMethod(
  1962. smalltalk.method({
  1963. selector: "increaseIndex",
  1964. protocol: 'accessing',
  1965. fn: function (){
  1966. var self=this;
  1967. return smalltalk.withContext(function($ctx1) {
  1968. self["@index"]=_st(self._index()).__plus((1));
  1969. return self}, function($ctx1) {$ctx1.fill(self,"increaseIndex",{},globals.ASTPCNodeVisitor)})},
  1970. args: [],
  1971. source: "increaseIndex\x0a\x09index := self index + 1",
  1972. messageSends: ["+", "index"],
  1973. referencedClasses: []
  1974. }),
  1975. globals.ASTPCNodeVisitor);
  1976. smalltalk.addMethod(
  1977. smalltalk.method({
  1978. selector: "index",
  1979. protocol: 'accessing',
  1980. fn: function (){
  1981. var self=this;
  1982. return smalltalk.withContext(function($ctx1) {
  1983. var $2,$1;
  1984. $2=self["@index"];
  1985. if(($receiver = $2) == nil || $receiver == null){
  1986. self["@index"]=(0);
  1987. $1=self["@index"];
  1988. } else {
  1989. $1=$2;
  1990. };
  1991. return $1;
  1992. }, function($ctx1) {$ctx1.fill(self,"index",{},globals.ASTPCNodeVisitor)})},
  1993. args: [],
  1994. source: "index\x0a\x09^ index ifNil: [ index := 0 ]",
  1995. messageSends: ["ifNil:"],
  1996. referencedClasses: []
  1997. }),
  1998. globals.ASTPCNodeVisitor);
  1999. smalltalk.addMethod(
  2000. smalltalk.method({
  2001. selector: "selector",
  2002. protocol: 'accessing',
  2003. fn: function (){
  2004. var self=this;
  2005. var $1;
  2006. $1=self["@selector"];
  2007. return $1;
  2008. },
  2009. args: [],
  2010. source: "selector\x0a\x09^ selector",
  2011. messageSends: [],
  2012. referencedClasses: []
  2013. }),
  2014. globals.ASTPCNodeVisitor);
  2015. smalltalk.addMethod(
  2016. smalltalk.method({
  2017. selector: "selector:",
  2018. protocol: 'accessing',
  2019. fn: function (aString){
  2020. var self=this;
  2021. self["@selector"]=aString;
  2022. return self},
  2023. args: ["aString"],
  2024. source: "selector: aString\x0a\x09selector := aString",
  2025. messageSends: [],
  2026. referencedClasses: []
  2027. }),
  2028. globals.ASTPCNodeVisitor);
  2029. smalltalk.addMethod(
  2030. smalltalk.method({
  2031. selector: "visitJSStatementNode:",
  2032. protocol: 'visiting',
  2033. fn: function (aNode){
  2034. var self=this;
  2035. self["@currentNode"]=aNode;
  2036. return self},
  2037. args: ["aNode"],
  2038. source: "visitJSStatementNode: aNode\x0a\x09\x22If a JSStatementNode is encountered, it always is the current node.\x0a\x09Stop visiting the AST there\x22\x0a\x09\x0a\x09currentNode := aNode",
  2039. messageSends: [],
  2040. referencedClasses: []
  2041. }),
  2042. globals.ASTPCNodeVisitor);
  2043. smalltalk.addMethod(
  2044. smalltalk.method({
  2045. selector: "visitSendNode:",
  2046. protocol: 'visiting',
  2047. fn: function (aNode){
  2048. var self=this;
  2049. var sendIndex;
  2050. return smalltalk.withContext(function($ctx1) {
  2051. var $1,$2,$4,$3,$6,$5,$7;
  2052. $1=self._context();
  2053. $2=self._selector();
  2054. $ctx1.sendIdx["selector"]=1;
  2055. sendIndex=_st($1)._sendIndexAt_($2);
  2056. globals.ASTPCNodeVisitor.superclass.fn.prototype._visitSendNode_.apply(_st(self), [aNode]);
  2057. $4=self._selector();
  2058. $ctx1.sendIdx["selector"]=2;
  2059. $3=_st($4).__eq(_st(aNode)._selector());
  2060. if(smalltalk.assert($3)){
  2061. $6=self._index();
  2062. $ctx1.sendIdx["index"]=1;
  2063. $5=_st($6).__lt(sendIndex);
  2064. if(! smalltalk.assert($5)){
  2065. $7=_st(self._index()).__gt(sendIndex);
  2066. if(! smalltalk.assert($7)){
  2067. self["@currentNode"]=aNode;
  2068. self["@currentNode"];
  2069. };
  2070. };
  2071. self._increaseIndex();
  2072. };
  2073. return self}, function($ctx1) {$ctx1.fill(self,"visitSendNode:",{aNode:aNode,sendIndex:sendIndex},globals.ASTPCNodeVisitor)})},
  2074. args: ["aNode"],
  2075. source: "visitSendNode: aNode\x0a\x09| sendIndex |\x0a\x09sendIndex := self context sendIndexAt: self selector.\x0a\x09\x0a\x09super visitSendNode: aNode.\x0a\x09\x0a\x09self selector = aNode selector ifTrue: [\x0a\x09\x09self index < sendIndex ifFalse: [ \x0a\x09\x09\x09self index > sendIndex ifFalse: [ currentNode := aNode ] ].\x0a\x09\x09self increaseIndex ]",
  2076. messageSends: ["sendIndexAt:", "context", "selector", "visitSendNode:", "ifTrue:", "=", "ifFalse:", "<", "index", ">", "increaseIndex"],
  2077. referencedClasses: []
  2078. }),
  2079. globals.ASTPCNodeVisitor);
  2080. smalltalk.addMethod(
  2081. smalltalk.method({
  2082. selector: "isSteppingNode",
  2083. protocol: '*Compiler-Interpreter',
  2084. fn: function (){
  2085. var self=this;
  2086. return true;
  2087. },
  2088. args: [],
  2089. source: "isSteppingNode\x0a\x09^ true",
  2090. messageSends: [],
  2091. referencedClasses: []
  2092. }),
  2093. globals.AssignmentNode);
  2094. smalltalk.addMethod(
  2095. smalltalk.method({
  2096. selector: "isSteppingNode",
  2097. protocol: '*Compiler-Interpreter',
  2098. fn: function (){
  2099. var self=this;
  2100. return true;
  2101. },
  2102. args: [],
  2103. source: "isSteppingNode\x0a\x09^ true",
  2104. messageSends: [],
  2105. referencedClasses: []
  2106. }),
  2107. globals.BlockNode);
  2108. smalltalk.addMethod(
  2109. smalltalk.method({
  2110. selector: "isSteppingNode",
  2111. protocol: '*Compiler-Interpreter',
  2112. fn: function (){
  2113. var self=this;
  2114. return true;
  2115. },
  2116. args: [],
  2117. source: "isSteppingNode\x0a\x09^ true",
  2118. messageSends: [],
  2119. referencedClasses: []
  2120. }),
  2121. globals.DynamicArrayNode);
  2122. smalltalk.addMethod(
  2123. smalltalk.method({
  2124. selector: "isSteppingNode",
  2125. protocol: '*Compiler-Interpreter',
  2126. fn: function (){
  2127. var self=this;
  2128. return true;
  2129. },
  2130. args: [],
  2131. source: "isSteppingNode\x0a\x09^ true",
  2132. messageSends: [],
  2133. referencedClasses: []
  2134. }),
  2135. globals.DynamicDictionaryNode);
  2136. smalltalk.addMethod(
  2137. smalltalk.method({
  2138. selector: "isSteppingNode",
  2139. protocol: '*Compiler-Interpreter',
  2140. fn: function (){
  2141. var self=this;
  2142. return true;
  2143. },
  2144. args: [],
  2145. source: "isSteppingNode\x0a\x09^ true",
  2146. messageSends: [],
  2147. referencedClasses: []
  2148. }),
  2149. globals.JSStatementNode);
  2150. smalltalk.addMethod(
  2151. smalltalk.method({
  2152. selector: "isSteppingNode",
  2153. protocol: '*Compiler-Interpreter',
  2154. fn: function (){
  2155. var self=this;
  2156. return false;
  2157. },
  2158. args: [],
  2159. source: "isSteppingNode\x0a\x09^ false",
  2160. messageSends: [],
  2161. referencedClasses: []
  2162. }),
  2163. globals.Node);
  2164. smalltalk.addMethod(
  2165. smalltalk.method({
  2166. selector: "isSteppingNode",
  2167. protocol: '*Compiler-Interpreter',
  2168. fn: function (){
  2169. var self=this;
  2170. return true;
  2171. },
  2172. args: [],
  2173. source: "isSteppingNode\x0a\x09^ true",
  2174. messageSends: [],
  2175. referencedClasses: []
  2176. }),
  2177. globals.SendNode);
  2178. });