2
0

Compiler-Interpreter.js 78 KB

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