Compiler-Interpreter.js 75 KB

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