Compiler-Interpreter.js 20 KB

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