Compiler-Interpreter.js 78 KB

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