1
0

Compiler-Interpreter.js 20 KB

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