Compiler-Interpreter.js 91 KB

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