Compiler-Interpreter.js 75 KB

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