Compiler-Interpreter.js 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. smalltalk.addPackage('Compiler-Interpreter', {});
  2. smalltalk.addClass('AIContext', smalltalk.NodeVisitor, ['outerContext', 'pc', 'locals', 'receiver', 'selector'], 'Compiler-Interpreter');
  3. smalltalk.addMethod(
  4. "_initializeFromMethodContext_",
  5. smalltalk.method({
  6. selector: "initializeFromMethodContext:",
  7. category: 'accessing',
  8. fn: function (aMethodContext){
  9. var self=this;
  10. return smalltalk.withContext(function($ctx1) { var $1;
  11. _st(self)._pc_(_st(aMethodContext)._pc());
  12. _st(self)._receiver_(_st(aMethodContext)._receiver());
  13. _st(self)._selector_(_st(aMethodContext)._selector());
  14. $1=_st(aMethodContext)._outerContext();
  15. if(($receiver = $1) == nil || $receiver == undefined){
  16. $1;
  17. } else {
  18. _st(self)._outerContext_(_st(_st(self)._class())._fromMethodContext_(_st(aMethodContext)._outerContext()));
  19. };
  20. _st(_st(aMethodContext)._locals())._keysAndValuesDo_((function(key,value){
  21. return smalltalk.withContext(function($ctx2) { return _st(_st(self)._locals())._at_put_(key,value);
  22. }, function($ctx2) {$ctx2.fillBlock({key:key,value:value},$ctx1)})}));
  23. return self}, function($ctx1) {$ctx1.fill(self,"initializeFromMethodContext:",{aMethodContext:aMethodContext}, smalltalk.AIContext)})},
  24. args: ["aMethodContext"],
  25. source: "initializeFromMethodContext: aMethodContext\x0a\x09self pc: aMethodContext pc.\x0a self receiver: aMethodContext receiver.\x0a self selector: aMethodContext selector.\x0a aMethodContext outerContext ifNotNil: [\x0a\x09\x09self outerContext: (self class fromMethodContext: aMethodContext outerContext) ].\x0a aMethodContext locals keysAndValuesDo: [ :key :value |\x0a \x09self locals at: key put: value ]\x0a ",
  26. messageSends: ["pc:", "pc", "receiver:", "receiver", "selector:", "selector", "ifNotNil:", "outerContext:", "fromMethodContext:", "outerContext", "class", "keysAndValuesDo:", "at:put:", "locals"],
  27. referencedClasses: []
  28. }),
  29. smalltalk.AIContext);
  30. smalltalk.addMethod(
  31. "_localAt_",
  32. smalltalk.method({
  33. selector: "localAt:",
  34. category: 'accessing',
  35. fn: function (aString){
  36. var self=this;
  37. return smalltalk.withContext(function($ctx1) { var $1;
  38. $1=_st(_st(self)._locals())._at_ifAbsent_(aString,(function(){
  39. return smalltalk.withContext(function($ctx2) { return nil;
  40. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  41. return $1;
  42. }, function($ctx1) {$ctx1.fill(self,"localAt:",{aString:aString}, smalltalk.AIContext)})},
  43. args: ["aString"],
  44. source: "localAt: aString\x0a\x09^ self locals at: aString ifAbsent: [ nil ]",
  45. messageSends: ["at:ifAbsent:", "locals"],
  46. referencedClasses: []
  47. }),
  48. smalltalk.AIContext);
  49. smalltalk.addMethod(
  50. "_localAt_put_",
  51. smalltalk.method({
  52. selector: "localAt:put:",
  53. category: 'accessing',
  54. fn: function (aString,anObject){
  55. var self=this;
  56. return smalltalk.withContext(function($ctx1) { _st(_st(self)._locals())._at_put_(aString,anObject);
  57. return self}, function($ctx1) {$ctx1.fill(self,"localAt:put:",{aString:aString,anObject:anObject}, smalltalk.AIContext)})},
  58. args: ["aString", "anObject"],
  59. source: "localAt: aString put: anObject\x0a\x09self locals at: aString put: anObject",
  60. messageSends: ["at:put:", "locals"],
  61. referencedClasses: []
  62. }),
  63. smalltalk.AIContext);
  64. smalltalk.addMethod(
  65. "_locals",
  66. smalltalk.method({
  67. selector: "locals",
  68. category: 'accessing',
  69. fn: function (){
  70. var self=this;
  71. return smalltalk.withContext(function($ctx1) { var $2,$1;
  72. $2=self["@locals"];
  73. if(($receiver = $2) == nil || $receiver == undefined){
  74. self["@locals"]=_st((smalltalk.Dictionary || Dictionary))._new();
  75. $1=self["@locals"];
  76. } else {
  77. $1=$2;
  78. };
  79. return $1;
  80. }, function($ctx1) {$ctx1.fill(self,"locals",{}, smalltalk.AIContext)})},
  81. args: [],
  82. source: "locals\x0a\x09^ locals ifNil: [ locals := Dictionary new ]",
  83. messageSends: ["ifNil:", "new"],
  84. referencedClasses: ["Dictionary"]
  85. }),
  86. smalltalk.AIContext);
  87. smalltalk.addMethod(
  88. "_outerContext",
  89. smalltalk.method({
  90. selector: "outerContext",
  91. category: 'accessing',
  92. fn: function (){
  93. var self=this;
  94. return smalltalk.withContext(function($ctx1) { var $1;
  95. $1=self["@outerContext"];
  96. return $1;
  97. }, function($ctx1) {$ctx1.fill(self,"outerContext",{}, smalltalk.AIContext)})},
  98. args: [],
  99. source: "outerContext\x0a\x09^ outerContext",
  100. messageSends: [],
  101. referencedClasses: []
  102. }),
  103. smalltalk.AIContext);
  104. smalltalk.addMethod(
  105. "_outerContext_",
  106. smalltalk.method({
  107. selector: "outerContext:",
  108. category: 'accessing',
  109. fn: function (anAIContext){
  110. var self=this;
  111. return smalltalk.withContext(function($ctx1) { self["@outerContext"]=anAIContext;
  112. return self}, function($ctx1) {$ctx1.fill(self,"outerContext:",{anAIContext:anAIContext}, smalltalk.AIContext)})},
  113. args: ["anAIContext"],
  114. source: "outerContext: anAIContext\x0a\x09outerContext := anAIContext",
  115. messageSends: [],
  116. referencedClasses: []
  117. }),
  118. smalltalk.AIContext);
  119. smalltalk.addMethod(
  120. "_pc",
  121. smalltalk.method({
  122. selector: "pc",
  123. category: 'accessing',
  124. fn: function (){
  125. var self=this;
  126. return smalltalk.withContext(function($ctx1) { var $2,$1;
  127. $2=self["@pc"];
  128. if(($receiver = $2) == nil || $receiver == undefined){
  129. self["@pc"]=(0);
  130. $1=self["@pc"];
  131. } else {
  132. $1=$2;
  133. };
  134. return $1;
  135. }, function($ctx1) {$ctx1.fill(self,"pc",{}, smalltalk.AIContext)})},
  136. args: [],
  137. source: "pc\x0a\x09^ pc ifNil: [ pc := 0 ]",
  138. messageSends: ["ifNil:"],
  139. referencedClasses: []
  140. }),
  141. smalltalk.AIContext);
  142. smalltalk.addMethod(
  143. "_pc_",
  144. smalltalk.method({
  145. selector: "pc:",
  146. category: 'accessing',
  147. fn: function (anInteger){
  148. var self=this;
  149. return smalltalk.withContext(function($ctx1) { self["@pc"]=anInteger;
  150. return self}, function($ctx1) {$ctx1.fill(self,"pc:",{anInteger:anInteger}, smalltalk.AIContext)})},
  151. args: ["anInteger"],
  152. source: "pc: anInteger\x0a\x09pc := anInteger",
  153. messageSends: [],
  154. referencedClasses: []
  155. }),
  156. smalltalk.AIContext);
  157. smalltalk.addMethod(
  158. "_receiver",
  159. smalltalk.method({
  160. selector: "receiver",
  161. category: 'accessing',
  162. fn: function (){
  163. var self=this;
  164. return smalltalk.withContext(function($ctx1) { var $1;
  165. $1=self["@receiver"];
  166. return $1;
  167. }, function($ctx1) {$ctx1.fill(self,"receiver",{}, smalltalk.AIContext)})},
  168. args: [],
  169. source: "receiver\x0a\x09^ receiver",
  170. messageSends: [],
  171. referencedClasses: []
  172. }),
  173. smalltalk.AIContext);
  174. smalltalk.addMethod(
  175. "_receiver_",
  176. smalltalk.method({
  177. selector: "receiver:",
  178. category: 'accessing',
  179. fn: function (anObject){
  180. var self=this;
  181. return smalltalk.withContext(function($ctx1) { self["@receiver"]=anObject;
  182. return self}, function($ctx1) {$ctx1.fill(self,"receiver:",{anObject:anObject}, smalltalk.AIContext)})},
  183. args: ["anObject"],
  184. source: "receiver: anObject\x0a\x09receiver := anObject",
  185. messageSends: [],
  186. referencedClasses: []
  187. }),
  188. smalltalk.AIContext);
  189. smalltalk.addMethod(
  190. "_selector",
  191. smalltalk.method({
  192. selector: "selector",
  193. category: 'accessing',
  194. fn: function (){
  195. var self=this;
  196. return smalltalk.withContext(function($ctx1) { var $1;
  197. $1=self["@selector"];
  198. return $1;
  199. }, function($ctx1) {$ctx1.fill(self,"selector",{}, smalltalk.AIContext)})},
  200. args: [],
  201. source: "selector\x0a\x09^ selector",
  202. messageSends: [],
  203. referencedClasses: []
  204. }),
  205. smalltalk.AIContext);
  206. smalltalk.addMethod(
  207. "_selector_",
  208. smalltalk.method({
  209. selector: "selector:",
  210. category: 'accessing',
  211. fn: function (aString){
  212. var self=this;
  213. return smalltalk.withContext(function($ctx1) { self["@selector"]=aString;
  214. return self}, function($ctx1) {$ctx1.fill(self,"selector:",{aString:aString}, smalltalk.AIContext)})},
  215. args: ["aString"],
  216. source: "selector: aString\x0a\x09selector := aString",
  217. messageSends: [],
  218. referencedClasses: []
  219. }),
  220. smalltalk.AIContext);
  221. smalltalk.addMethod(
  222. "_fromMethodContext_",
  223. smalltalk.method({
  224. selector: "fromMethodContext:",
  225. category: 'instance creation',
  226. fn: function (aMethodContext){
  227. var self=this;
  228. return smalltalk.withContext(function($ctx1) { var $2,$3,$1;
  229. $2=_st(self)._new();
  230. _st($2)._initializeFromMethodContext_(aMethodContext);
  231. $3=_st($2)._yourself();
  232. $1=$3;
  233. return $1;
  234. }, function($ctx1) {$ctx1.fill(self,"fromMethodContext:",{aMethodContext:aMethodContext}, smalltalk.AIContext.klass)})},
  235. args: ["aMethodContext"],
  236. source: "fromMethodContext: aMethodContext\x0a\x09^ self new \x0a \x09initializeFromMethodContext: aMethodContext;\x0a yourself",
  237. messageSends: ["initializeFromMethodContext:", "new", "yourself"],
  238. referencedClasses: []
  239. }),
  240. smalltalk.AIContext.klass);
  241. smalltalk.addClass('ASTInterpreter', smalltalk.NodeVisitor, ['currentNode', 'context', 'shouldReturn'], 'Compiler-Interpreter');
  242. smalltalk.addMethod(
  243. "_assign_to_",
  244. smalltalk.method({
  245. selector: "assign:to:",
  246. category: 'interpreting',
  247. fn: function (aNode,anObject){
  248. var self=this;
  249. return smalltalk.withContext(function($ctx1) { var $2,$1;
  250. $2=_st(_st(aNode)._binding())._isInstanceVar();
  251. if(smalltalk.assert($2)){
  252. $1=_st(_st(_st(self)._context())._receiver())._instVarAt_put_(_st(aNode)._value(),anObject);
  253. } else {
  254. $1=_st(_st(self)._context())._localAt_put_(_st(aNode)._value(),anObject);
  255. };
  256. return $1;
  257. }, function($ctx1) {$ctx1.fill(self,"assign:to:",{aNode:aNode,anObject:anObject}, smalltalk.ASTInterpreter)})},
  258. args: ["aNode", "anObject"],
  259. source: "assign: aNode to: anObject\x0a\x09^ aNode binding isInstanceVar \x0a \x09ifTrue: [ self context receiver instVarAt: aNode value put: anObject ]\x0a \x09ifFalse: [ self context localAt: aNode value put: anObject ]",
  260. messageSends: ["ifTrue:ifFalse:", "instVarAt:put:", "value", "receiver", "context", "localAt:put:", "isInstanceVar", "binding"],
  261. referencedClasses: []
  262. }),
  263. smalltalk.ASTInterpreter);
  264. smalltalk.addMethod(
  265. "_context",
  266. smalltalk.method({
  267. selector: "context",
  268. category: 'accessing',
  269. fn: function (){
  270. var self=this;
  271. return smalltalk.withContext(function($ctx1) { var $2,$1;
  272. $2=self["@context"];
  273. if(($receiver = $2) == nil || $receiver == undefined){
  274. self["@context"]=_st((smalltalk.AIContext || AIContext))._new();
  275. $1=self["@context"];
  276. } else {
  277. $1=$2;
  278. };
  279. return $1;
  280. }, function($ctx1) {$ctx1.fill(self,"context",{}, smalltalk.ASTInterpreter)})},
  281. args: [],
  282. source: "context\x0a\x09^ context ifNil: [ context := AIContext new ]",
  283. messageSends: ["ifNil:", "new"],
  284. referencedClasses: ["AIContext"]
  285. }),
  286. smalltalk.ASTInterpreter);
  287. smalltalk.addMethod(
  288. "_context_",
  289. smalltalk.method({
  290. selector: "context:",
  291. category: 'accessing',
  292. fn: function (anAIContext){
  293. var self=this;
  294. return smalltalk.withContext(function($ctx1) { self["@context"]=anAIContext;
  295. return self}, function($ctx1) {$ctx1.fill(self,"context:",{anAIContext:anAIContext}, smalltalk.ASTInterpreter)})},
  296. args: ["anAIContext"],
  297. source: "context: anAIContext\x0a\x09context := anAIContext",
  298. messageSends: [],
  299. referencedClasses: []
  300. }),
  301. smalltalk.ASTInterpreter);
  302. smalltalk.addMethod(
  303. "_eval_",
  304. smalltalk.method({
  305. selector: "eval:",
  306. category: 'interpreting',
  307. fn: function (aString){
  308. var self=this;
  309. var source,function_;
  310. return smalltalk.withContext(function($ctx1) { var $1,$2,$3;
  311. source=_st((smalltalk.String || String))._streamContents_((function(str){
  312. return smalltalk.withContext(function($ctx2) { _st(str)._nextPutAll_("(function(");
  313. _st(_st(_st(_st(self)._context())._locals())._keys())._do_separatedBy_((function(each){
  314. return smalltalk.withContext(function($ctx3) { return _st(str)._nextPutAll_(each);
  315. }, function($ctx3) {$ctx3.fillBlock({each:each},$ctx1)})}),(function(){
  316. return smalltalk.withContext(function($ctx3) { return _st(str)._nextPutAll_(",");
  317. }, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}));
  318. $1=str;
  319. _st($1)._nextPutAll_("){ return (function() {");
  320. _st($1)._nextPutAll_(aString);
  321. $2=_st($1)._nextPutAll_("})() })");
  322. return $2;
  323. }, function($ctx2) {$ctx2.fillBlock({str:str},$ctx1)})}));
  324. function_=_st(_st((smalltalk.Compiler || Compiler))._new())._eval_(source);
  325. $3=_st(function_)._valueWithPossibleArguments_(_st(_st(_st(self)._context())._locals())._values());
  326. return $3;
  327. }, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString,source:source,function_:function_}, smalltalk.ASTInterpreter)})},
  328. args: ["aString"],
  329. source: "eval: aString\x0a\x09\x22Evaluate aString as JS source inside an JS function. \x0a aString is not sandboxed.\x22\x0a \x0a | source function |\x0a \x0a source := String streamContents: [ :str |\x0a \x09str nextPutAll: '(function('.\x0a self context locals keys \x0a \x09do: [ :each | str nextPutAll: each ]\x0a \x09separatedBy: [ str nextPutAll: ',' ].\x0a str \x0a \x09nextPutAll: '){ return (function() {';\x0a \x09nextPutAll: aString;\x0a nextPutAll: '})() })' ].\x0a \x0a\x09function := Compiler new eval: source.\x0a \x0a\x09^ function valueWithPossibleArguments: self context locals values",
  330. messageSends: ["streamContents:", "nextPutAll:", "do:separatedBy:", "keys", "locals", "context", "eval:", "new", "valueWithPossibleArguments:", "values"],
  331. referencedClasses: ["String", "Compiler"]
  332. }),
  333. smalltalk.ASTInterpreter);
  334. smalltalk.addMethod(
  335. "_initialize",
  336. smalltalk.method({
  337. selector: "initialize",
  338. category: 'initialization',
  339. fn: function (){
  340. var self=this;
  341. return smalltalk.withContext(function($ctx1) { smalltalk.NodeVisitor.fn.prototype._initialize.apply(_st(self), []);
  342. self["@shouldReturn"]=false;
  343. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{}, smalltalk.ASTInterpreter)})},
  344. args: [],
  345. source: "initialize\x0a\x09super initialize.\x0a shouldReturn := false",
  346. messageSends: ["initialize"],
  347. referencedClasses: []
  348. }),
  349. smalltalk.ASTInterpreter);
  350. smalltalk.addMethod(
  351. "_interpret_",
  352. smalltalk.method({
  353. selector: "interpret:",
  354. category: 'interpreting',
  355. fn: function (aNode){
  356. var self=this;
  357. return smalltalk.withContext(function($ctx1) { var $1;
  358. self["@shouldReturn"]=false;
  359. $1=_st(self)._interpretNode_(aNode);
  360. return $1;
  361. }, function($ctx1) {$ctx1.fill(self,"interpret:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  362. args: ["aNode"],
  363. source: "interpret: aNode\x0a\x09shouldReturn := false.\x0a ^ self interpretNode: aNode",
  364. messageSends: ["interpretNode:"],
  365. referencedClasses: []
  366. }),
  367. smalltalk.ASTInterpreter);
  368. smalltalk.addMethod(
  369. "_interpretNode_",
  370. smalltalk.method({
  371. selector: "interpretNode:",
  372. category: 'interpreting',
  373. fn: function (aNode){
  374. var self=this;
  375. return smalltalk.withContext(function($ctx1) { var $1;
  376. self["@currentNode"]=aNode;
  377. $1=_st(self)._visit_(aNode);
  378. return $1;
  379. }, function($ctx1) {$ctx1.fill(self,"interpretNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  380. args: ["aNode"],
  381. source: "interpretNode: aNode\x0a\x09currentNode := aNode.\x0a ^ self visit: aNode",
  382. messageSends: ["visit:"],
  383. referencedClasses: []
  384. }),
  385. smalltalk.ASTInterpreter);
  386. smalltalk.addMethod(
  387. "_messageFromSendNode_",
  388. smalltalk.method({
  389. selector: "messageFromSendNode:",
  390. category: 'interpreting',
  391. fn: function (aSendNode){
  392. var self=this;
  393. return smalltalk.withContext(function($ctx1) { var $2,$3,$1;
  394. $2=_st((smalltalk.Message || Message))._new();
  395. _st($2)._selector_(_st(aSendNode)._selector());
  396. _st($2)._arguments_(_st(_st(aSendNode)._arguments())._collect_((function(each){
  397. return smalltalk.withContext(function($ctx2) { return _st(self)._interpretNode_(each);
  398. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})})));
  399. $3=_st($2)._yourself();
  400. $1=$3;
  401. return $1;
  402. }, function($ctx1) {$ctx1.fill(self,"messageFromSendNode:",{aSendNode:aSendNode}, smalltalk.ASTInterpreter)})},
  403. args: ["aSendNode"],
  404. source: "messageFromSendNode: aSendNode\x0a\x09^ Message new\x0a \x09selector: aSendNode selector;\x0a arguments: (aSendNode arguments collect: [ :each |\x0a \x09self interpretNode: each ]);\x0a yourself",
  405. messageSends: ["selector:", "selector", "new", "arguments:", "collect:", "interpretNode:", "arguments", "yourself"],
  406. referencedClasses: ["Message"]
  407. }),
  408. smalltalk.ASTInterpreter);
  409. smalltalk.addMethod(
  410. "_visitAssignmentNode_",
  411. smalltalk.method({
  412. selector: "visitAssignmentNode:",
  413. category: 'visiting',
  414. fn: function (aNode){
  415. var self=this;
  416. return smalltalk.withContext(function($ctx1) { var $1;
  417. $1=_st(self)._assign_to_(_st(aNode)._left(),_st(self)._interpretNode_(_st(aNode)._right()));
  418. return $1;
  419. }, function($ctx1) {$ctx1.fill(self,"visitAssignmentNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  420. args: ["aNode"],
  421. source: "visitAssignmentNode: aNode\x0a\x09^ self assign: aNode left to: (self interpretNode: aNode right)",
  422. messageSends: ["assign:to:", "left", "interpretNode:", "right"],
  423. referencedClasses: []
  424. }),
  425. smalltalk.ASTInterpreter);
  426. smalltalk.addMethod(
  427. "_visitBlockNode_",
  428. smalltalk.method({
  429. selector: "visitBlockNode:",
  430. category: 'visiting',
  431. fn: function (aNode){
  432. var self=this;
  433. return smalltalk.withContext(function($ctx1) { var $1;
  434. $1=(function(){
  435. return smalltalk.withContext(function($ctx2) { return _st(self)._interpretNode_(_st(_st(aNode)._nodes())._first());
  436. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})});
  437. return $1;
  438. }, function($ctx1) {$ctx1.fill(self,"visitBlockNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  439. args: ["aNode"],
  440. source: "visitBlockNode: aNode\x0a ^ [ self interpretNode: aNode nodes first ]",
  441. messageSends: ["interpretNode:", "first", "nodes"],
  442. referencedClasses: []
  443. }),
  444. smalltalk.ASTInterpreter);
  445. smalltalk.addMethod(
  446. "_visitCascadeNode_",
  447. smalltalk.method({
  448. selector: "visitCascadeNode:",
  449. category: 'visiting',
  450. fn: function (aNode){
  451. var self=this;
  452. var receiver;
  453. return smalltalk.withContext(function($ctx1) { var $1;
  454. receiver=_st(self)._interpretNode_(_st(aNode)._receiver());
  455. _st(_st(_st(aNode)._nodes())._allButLast())._do_((function(each){
  456. return smalltalk.withContext(function($ctx2) { return _st(_st(self)._messageFromSendNode_(each))._sendTo_(receiver);
  457. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  458. $1=_st(_st(self)._messageFromSendNode_(_st(_st(aNode)._nodes())._last()))._sendTo_(receiver);
  459. return $1;
  460. }, function($ctx1) {$ctx1.fill(self,"visitCascadeNode:",{aNode:aNode,receiver:receiver}, smalltalk.ASTInterpreter)})},
  461. args: ["aNode"],
  462. source: "visitCascadeNode: aNode\x0a\x09\x22TODO: Handle super sends\x22\x0a\x09| receiver |\x0a \x0a receiver := self interpretNode: aNode receiver.\x0a\x0a aNode nodes allButLast\x0a \x09do: [ :each | \x0a \x09(self messageFromSendNode: each)\x0a \x09sendTo: receiver ].\x0a\x0a ^ (self messageFromSendNode: aNode nodes last)\x0a \x09sendTo: receiver",
  463. messageSends: ["interpretNode:", "receiver", "do:", "sendTo:", "messageFromSendNode:", "allButLast", "nodes", "last"],
  464. referencedClasses: []
  465. }),
  466. smalltalk.ASTInterpreter);
  467. smalltalk.addMethod(
  468. "_visitClassReferenceNode_",
  469. smalltalk.method({
  470. selector: "visitClassReferenceNode:",
  471. category: 'visiting',
  472. fn: function (aNode){
  473. var self=this;
  474. return smalltalk.withContext(function($ctx1) { var $1;
  475. $1=_st(_st((smalltalk.Smalltalk || Smalltalk))._current())._at_(_st(aNode)._value());
  476. return $1;
  477. }, function($ctx1) {$ctx1.fill(self,"visitClassReferenceNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  478. args: ["aNode"],
  479. source: "visitClassReferenceNode: aNode\x0a\x09^ Smalltalk current at: aNode value",
  480. messageSends: ["at:", "value", "current"],
  481. referencedClasses: ["Smalltalk"]
  482. }),
  483. smalltalk.ASTInterpreter);
  484. smalltalk.addMethod(
  485. "_visitJSStatementNode_",
  486. smalltalk.method({
  487. selector: "visitJSStatementNode:",
  488. category: 'visiting',
  489. fn: function (aNode){
  490. var self=this;
  491. return smalltalk.withContext(function($ctx1) { var $1;
  492. self["@shouldReturn"]=true;
  493. $1=_st(self)._eval_(_st(aNode)._source());
  494. return $1;
  495. }, function($ctx1) {$ctx1.fill(self,"visitJSStatementNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  496. args: ["aNode"],
  497. source: "visitJSStatementNode: aNode\x0a\x09shouldReturn := true.\x0a\x09^ self eval: aNode source",
  498. messageSends: ["eval:", "source"],
  499. referencedClasses: []
  500. }),
  501. smalltalk.ASTInterpreter);
  502. smalltalk.addMethod(
  503. "_visitReturnNode_",
  504. smalltalk.method({
  505. selector: "visitReturnNode:",
  506. category: 'visiting',
  507. fn: function (aNode){
  508. var self=this;
  509. return smalltalk.withContext(function($ctx1) { var $1;
  510. self["@shouldReturn"]=true;
  511. $1=_st(self)._interpretNode_(_st(_st(aNode)._nodes())._first());
  512. return $1;
  513. }, function($ctx1) {$ctx1.fill(self,"visitReturnNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  514. args: ["aNode"],
  515. source: "visitReturnNode: aNode\x0a\x09shouldReturn := true.\x0a ^ self interpretNode: aNode nodes first",
  516. messageSends: ["interpretNode:", "first", "nodes"],
  517. referencedClasses: []
  518. }),
  519. smalltalk.ASTInterpreter);
  520. smalltalk.addMethod(
  521. "_visitSendNode_",
  522. smalltalk.method({
  523. selector: "visitSendNode:",
  524. category: 'visiting',
  525. fn: function (aNode){
  526. var self=this;
  527. return smalltalk.withContext(function($ctx1) { var $1;
  528. $1=_st(_st(self)._messageFromSendNode_(aNode))._sendTo_(_st(self)._interpretNode_(_st(aNode)._receiver()));
  529. return $1;
  530. }, function($ctx1) {$ctx1.fill(self,"visitSendNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  531. args: ["aNode"],
  532. source: "visitSendNode: aNode\x0a\x09\x22TODO: Handle super sends\x22\x0a \x0a ^ (self messageFromSendNode: aNode)\x0a \x09sendTo: (self interpretNode: aNode receiver)",
  533. messageSends: ["sendTo:", "interpretNode:", "receiver", "messageFromSendNode:"],
  534. referencedClasses: []
  535. }),
  536. smalltalk.ASTInterpreter);
  537. smalltalk.addMethod(
  538. "_visitSequenceNode_",
  539. smalltalk.method({
  540. selector: "visitSequenceNode:",
  541. category: 'visiting',
  542. fn: function (aNode){
  543. var self=this;
  544. return smalltalk.withContext(function($ctx1) { var $1,$3,$4,$2,$5;
  545. var $early={};
  546. try {
  547. $1=_st(_st(aNode)._nodes())._allButLast();
  548. $2=(function(each){
  549. var value;
  550. return smalltalk.withContext(function($ctx2) { value=_st(self)._interpretNode_(each);
  551. value;
  552. $3=self["@shouldReturn"];
  553. if(smalltalk.assert($3)){
  554. $4=value;
  555. throw $early=[$4];
  556. };
  557. }, function($ctx2) {$ctx2.fillBlock({each:each,value:value},$ctx1)})});
  558. _st($1)._do_($2);
  559. $5=_st(self)._interpretNode_(_st(_st(aNode)._nodes())._last());
  560. return $5;
  561. }
  562. catch(e) {if(e===$early)return e[0]; throw e}
  563. }, function($ctx1) {$ctx1.fill(self,"visitSequenceNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  564. args: ["aNode"],
  565. source: "visitSequenceNode: aNode\x0a\x0a\x09aNode nodes allButLast do: [ :each | | value |\x0a value := self interpretNode: each.\x0a\x09\x09shouldReturn ifTrue: [ ^ value ] ].\x0a \x0a ^ self interpretNode: aNode nodes last",
  566. messageSends: ["do:", "interpretNode:", "ifTrue:", "allButLast", "nodes", "last"],
  567. referencedClasses: []
  568. }),
  569. smalltalk.ASTInterpreter);
  570. smalltalk.addMethod(
  571. "_visitValueNode_",
  572. smalltalk.method({
  573. selector: "visitValueNode:",
  574. category: 'visiting',
  575. fn: function (aNode){
  576. var self=this;
  577. return smalltalk.withContext(function($ctx1) { var $1;
  578. $1=_st(aNode)._value();
  579. return $1;
  580. }, function($ctx1) {$ctx1.fill(self,"visitValueNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  581. args: ["aNode"],
  582. source: "visitValueNode: aNode\x0a\x09^ aNode value",
  583. messageSends: ["value"],
  584. referencedClasses: []
  585. }),
  586. smalltalk.ASTInterpreter);
  587. smalltalk.addMethod(
  588. "_visitVariableNode_",
  589. smalltalk.method({
  590. selector: "visitVariableNode:",
  591. category: 'visiting',
  592. fn: function (aNode){
  593. var self=this;
  594. return smalltalk.withContext(function($ctx1) { var $2,$1;
  595. $2=_st(_st(aNode)._binding())._isInstanceVar();
  596. if(smalltalk.assert($2)){
  597. $1=_st(_st(_st(self)._context())._receiver())._instVarAt_(_st(aNode)._value());
  598. } else {
  599. $1=_st(_st(self)._context())._localAt_(_st(aNode)._value());
  600. };
  601. return $1;
  602. }, function($ctx1) {$ctx1.fill(self,"visitVariableNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  603. args: ["aNode"],
  604. source: "visitVariableNode: aNode\x0a\x09^ aNode binding isInstanceVar\x0a \x09ifTrue: [ self context receiver instVarAt: aNode value ]\x0a \x09ifFalse: [ self context localAt: aNode value ]",
  605. messageSends: ["ifTrue:ifFalse:", "instVarAt:", "value", "receiver", "context", "localAt:", "isInstanceVar", "binding"],
  606. referencedClasses: []
  607. }),
  608. smalltalk.ASTInterpreter);