1
0

Compiler-Interpreter.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787
  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', 'currentValue'], '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. "_continue_",
  304. smalltalk.method({
  305. selector: "continue:",
  306. category: 'interpreting',
  307. fn: function (anObject){
  308. var self=this;
  309. return smalltalk.withContext(function($ctx1) { self["@currentValue"]=anObject;
  310. return self}, function($ctx1) {$ctx1.fill(self,"continue:",{anObject:anObject}, smalltalk.ASTInterpreter)})},
  311. args: ["anObject"],
  312. source: "continue: anObject\x0a\x09currentValue := anObject",
  313. messageSends: [],
  314. referencedClasses: []
  315. }),
  316. smalltalk.ASTInterpreter);
  317. smalltalk.addMethod(
  318. "_currentValue",
  319. smalltalk.method({
  320. selector: "currentValue",
  321. category: 'accessing',
  322. fn: function (){
  323. var self=this;
  324. return smalltalk.withContext(function($ctx1) { var $1;
  325. $1=self["@currentValue"];
  326. return $1;
  327. }, function($ctx1) {$ctx1.fill(self,"currentValue",{}, smalltalk.ASTInterpreter)})},
  328. args: [],
  329. source: "currentValue\x0a\x09^ currentValue",
  330. messageSends: [],
  331. referencedClasses: []
  332. }),
  333. smalltalk.ASTInterpreter);
  334. smalltalk.addMethod(
  335. "_eval_",
  336. smalltalk.method({
  337. selector: "eval:",
  338. category: 'interpreting',
  339. fn: function (aString){
  340. var self=this;
  341. var source,function_;
  342. return smalltalk.withContext(function($ctx1) { var $1,$2,$3;
  343. source=_st((smalltalk.String || String))._streamContents_((function(str){
  344. return smalltalk.withContext(function($ctx2) { _st(str)._nextPutAll_("(function(");
  345. _st(_st(_st(_st(self)._context())._locals())._keys())._do_separatedBy_((function(each){
  346. return smalltalk.withContext(function($ctx3) { return _st(str)._nextPutAll_(each);
  347. }, function($ctx3) {$ctx3.fillBlock({each:each},$ctx1)})}),(function(){
  348. return smalltalk.withContext(function($ctx3) { return _st(str)._nextPutAll_(",");
  349. }, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}));
  350. $1=str;
  351. _st($1)._nextPutAll_("){ return (function() {");
  352. _st($1)._nextPutAll_(aString);
  353. $2=_st($1)._nextPutAll_("})() })");
  354. return $2;
  355. }, function($ctx2) {$ctx2.fillBlock({str:str},$ctx1)})}));
  356. function_=_st(_st((smalltalk.Compiler || Compiler))._new())._eval_(source);
  357. $3=_st(function_)._valueWithPossibleArguments_(_st(_st(_st(self)._context())._locals())._values());
  358. return $3;
  359. }, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString,source:source,function_:function_}, smalltalk.ASTInterpreter)})},
  360. args: ["aString"],
  361. 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",
  362. messageSends: ["streamContents:", "nextPutAll:", "do:separatedBy:", "keys", "locals", "context", "eval:", "new", "valueWithPossibleArguments:", "values"],
  363. referencedClasses: ["String", "Compiler"]
  364. }),
  365. smalltalk.ASTInterpreter);
  366. smalltalk.addMethod(
  367. "_initialize",
  368. smalltalk.method({
  369. selector: "initialize",
  370. category: 'initialization',
  371. fn: function (){
  372. var self=this;
  373. return smalltalk.withContext(function($ctx1) { smalltalk.NodeVisitor.fn.prototype._initialize.apply(_st(self), []);
  374. self["@shouldReturn"]=false;
  375. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{}, smalltalk.ASTInterpreter)})},
  376. args: [],
  377. source: "initialize\x0a\x09super initialize.\x0a shouldReturn := false",
  378. messageSends: ["initialize"],
  379. referencedClasses: []
  380. }),
  381. smalltalk.ASTInterpreter);
  382. smalltalk.addMethod(
  383. "_interpret_",
  384. smalltalk.method({
  385. selector: "interpret:",
  386. category: 'interpreting',
  387. fn: function (aNode){
  388. var self=this;
  389. return smalltalk.withContext(function($ctx1) { self["@shouldReturn"]=false;
  390. _st(self)._interpret_continue_(aNode,(function(value){
  391. return smalltalk.withContext(function($ctx2) { self["@currentValue"]=value;
  392. return self["@currentValue"];
  393. }, function($ctx2) {$ctx2.fillBlock({value:value},$ctx1)})}));
  394. return self}, function($ctx1) {$ctx1.fill(self,"interpret:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  395. args: ["aNode"],
  396. source: "interpret: aNode\x0a\x09shouldReturn := false.\x0a self interpret: aNode continue: [ :value |\x0a \x09currentValue := value ]",
  397. messageSends: ["interpret:continue:"],
  398. referencedClasses: []
  399. }),
  400. smalltalk.ASTInterpreter);
  401. smalltalk.addMethod(
  402. "_interpret_continue_",
  403. smalltalk.method({
  404. selector: "interpret:continue:",
  405. category: 'interpreting',
  406. fn: function (aNode,aBlock){
  407. var self=this;
  408. return smalltalk.withContext(function($ctx1) { var $1,$2,$3;
  409. $1=self["@shouldReturn"];
  410. if(smalltalk.assert($1)){
  411. $2=self;
  412. return $2;
  413. };
  414. $3=_st(aNode)._isNode();
  415. if(smalltalk.assert($3)){
  416. _st(self)._visit_(aNode);
  417. } else {
  418. self["@currentValue"]=aNode;
  419. self["@currentValue"];
  420. };
  421. _st(aBlock)._value_(_st(self)._currentValue());
  422. return self}, function($ctx1) {$ctx1.fill(self,"interpret:continue:",{aNode:aNode,aBlock:aBlock}, smalltalk.ASTInterpreter)})},
  423. args: ["aNode", "aBlock"],
  424. source: "interpret: aNode continue: aBlock\x0a\x0a\x09shouldReturn ifTrue: [ ^ self ].\x0a\x0a\x09aNode isNode \x0a \x09ifTrue: [ self visit: aNode ]\x0a ifFalse: [ currentValue := aNode ].\x0a\x09aBlock value: self currentValue",
  425. messageSends: ["ifTrue:", "ifTrue:ifFalse:", "visit:", "isNode", "value:", "currentValue"],
  426. referencedClasses: []
  427. }),
  428. smalltalk.ASTInterpreter);
  429. smalltalk.addMethod(
  430. "_interpretAll_continue_",
  431. smalltalk.method({
  432. selector: "interpretAll:continue:",
  433. category: 'interpreting',
  434. fn: function (aCollection,aBlock){
  435. var self=this;
  436. return smalltalk.withContext(function($ctx1) { _st(self)._interpretAll_continue_result_(aCollection,aBlock,_st((smalltalk.OrderedCollection || OrderedCollection))._new());
  437. return self}, function($ctx1) {$ctx1.fill(self,"interpretAll:continue:",{aCollection:aCollection,aBlock:aBlock}, smalltalk.ASTInterpreter)})},
  438. args: ["aCollection", "aBlock"],
  439. source: "interpretAll: aCollection continue: aBlock\x0a\x09self \x0a \x09interpretAll: aCollection \x0a continue: aBlock \x0a result: OrderedCollection new",
  440. messageSends: ["interpretAll:continue:result:", "new"],
  441. referencedClasses: ["OrderedCollection"]
  442. }),
  443. smalltalk.ASTInterpreter);
  444. smalltalk.addMethod(
  445. "_interpretAll_continue_result_",
  446. smalltalk.method({
  447. selector: "interpretAll:continue:result:",
  448. category: 'interpreting',
  449. fn: function (nodes,aBlock,aCollection){
  450. var self=this;
  451. return smalltalk.withContext(function($ctx1) { var $1;
  452. $1=_st(nodes)._isEmpty();
  453. if(smalltalk.assert($1)){
  454. _st(aBlock)._value_(aCollection);
  455. } else {
  456. _st(self)._interpret_continue_(_st(nodes)._first(),(function(value){
  457. return smalltalk.withContext(function($ctx2) { return _st(self)._interpretAll_continue_result_(_st(nodes)._allButFirst(),aBlock,_st(aCollection).__comma([value]));
  458. }, function($ctx2) {$ctx2.fillBlock({value:value},$ctx1)})}));
  459. };
  460. return self}, function($ctx1) {$ctx1.fill(self,"interpretAll:continue:result:",{nodes:nodes,aBlock:aBlock,aCollection:aCollection}, smalltalk.ASTInterpreter)})},
  461. args: ["nodes", "aBlock", "aCollection"],
  462. source: "interpretAll: nodes continue: aBlock result: aCollection\x0a\x09nodes isEmpty \x0a \x09ifTrue: [ aBlock value: aCollection ]\x0a \x09ifFalse: [\x0a \x09\x09self interpret: nodes first continue: [:value |\x0a \x09\x09\x09self \x0a \x09interpretAll: nodes allButFirst \x0a continue: aBlock\x0a \x09\x09\x09\x09\x09result: aCollection, { value } ] ]",
  463. messageSends: ["ifTrue:ifFalse:", "value:", "interpret:continue:", "first", "interpretAll:continue:result:", "allButFirst", ",", "isEmpty"],
  464. referencedClasses: []
  465. }),
  466. smalltalk.ASTInterpreter);
  467. smalltalk.addMethod(
  468. "_messageFromSendNode_do_",
  469. smalltalk.method({
  470. selector: "messageFromSendNode:do:",
  471. category: 'interpreting',
  472. fn: function (aSendNode,aBlock){
  473. var self=this;
  474. return smalltalk.withContext(function($ctx1) { var $1,$2;
  475. _st(self)._interpretAll_continue_(_st(aSendNode)._arguments(),(function(args){
  476. return smalltalk.withContext(function($ctx2) { $1=_st((smalltalk.Message || Message))._new();
  477. _st($1)._selector_(_st(aSendNode)._selector());
  478. _st($1)._arguments_(args);
  479. $2=_st($1)._yourself();
  480. return _st(aBlock)._value_($2);
  481. }, function($ctx2) {$ctx2.fillBlock({args:args},$ctx1)})}));
  482. return self}, function($ctx1) {$ctx1.fill(self,"messageFromSendNode:do:",{aSendNode:aSendNode,aBlock:aBlock}, smalltalk.ASTInterpreter)})},
  483. args: ["aSendNode", "aBlock"],
  484. source: "messageFromSendNode: aSendNode do: aBlock\x0a\x09self interpretAll: aSendNode arguments continue: [ :args |\x0a \x09aBlock value: (Message new\x0a \x09\x09selector: aSendNode selector;\x0a \x09arguments: args;\x0a \x09yourself) ]",
  485. messageSends: ["interpretAll:continue:", "arguments", "value:", "selector:", "selector", "new", "arguments:", "yourself"],
  486. referencedClasses: ["Message"]
  487. }),
  488. smalltalk.ASTInterpreter);
  489. smalltalk.addMethod(
  490. "_visitAssignmentNode_",
  491. smalltalk.method({
  492. selector: "visitAssignmentNode:",
  493. category: 'visiting',
  494. fn: function (aNode){
  495. var self=this;
  496. return smalltalk.withContext(function($ctx1) { _st(self)._interpret_continue_(_st(aNode)._right(),(function(value){
  497. return smalltalk.withContext(function($ctx2) { return _st(self)._continue_(_st(self)._assign_to_(_st(aNode)._left(),value));
  498. }, function($ctx2) {$ctx2.fillBlock({value:value},$ctx1)})}));
  499. return self}, function($ctx1) {$ctx1.fill(self,"visitAssignmentNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  500. args: ["aNode"],
  501. source: "visitAssignmentNode: aNode\x0a\x09self interpret: aNode right continue: [ :value |\x0a \x09self continue: (self assign: aNode left to: value) ]",
  502. messageSends: ["interpret:continue:", "right", "continue:", "assign:to:", "left"],
  503. referencedClasses: []
  504. }),
  505. smalltalk.ASTInterpreter);
  506. smalltalk.addMethod(
  507. "_visitBlockNode_",
  508. smalltalk.method({
  509. selector: "visitBlockNode:",
  510. category: 'visiting',
  511. fn: function (aNode){
  512. var self=this;
  513. return smalltalk.withContext(function($ctx1) { var $1,$2;
  514. _st(self)._continue_((function(){
  515. return smalltalk.withContext(function($ctx2) { $1=self;
  516. _st($1)._interpret_(_st(_st(aNode)._nodes())._first());
  517. $2=_st($1)._currentValue();
  518. return $2;
  519. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  520. return self}, function($ctx1) {$ctx1.fill(self,"visitBlockNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  521. args: ["aNode"],
  522. source: "visitBlockNode: aNode\x0a\x09\x22TODO: Context should be set\x22\x0a self continue: [ self interpret: aNode nodes first; currentValue ]",
  523. messageSends: ["continue:", "interpret:", "first", "nodes", "currentValue"],
  524. referencedClasses: []
  525. }),
  526. smalltalk.ASTInterpreter);
  527. smalltalk.addMethod(
  528. "_visitCascadeNode_",
  529. smalltalk.method({
  530. selector: "visitCascadeNode:",
  531. category: 'visiting',
  532. fn: function (aNode){
  533. var self=this;
  534. return smalltalk.withContext(function($ctx1) { _st(self)._interpret_continue_(_st(aNode)._receiver(),(function(receiver){
  535. return smalltalk.withContext(function($ctx2) { _st(_st(aNode)._nodes())._do_((function(each){
  536. return smalltalk.withContext(function($ctx3) { return _st(each)._receiver_(receiver);
  537. }, function($ctx3) {$ctx3.fillBlock({each:each},$ctx1)})}));
  538. return _st(self)._interpretAll_continue_(_st(_st(aNode)._nodes())._allButLast(),(function(){
  539. return smalltalk.withContext(function($ctx3) { return _st(self)._interpret_continue_(_st(_st(aNode)._nodes())._last(),(function(val){
  540. return smalltalk.withContext(function($ctx4) { return _st(self)._continue_(val);
  541. }, function($ctx4) {$ctx4.fillBlock({val:val},$ctx1)})}));
  542. }, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}));
  543. }, function($ctx2) {$ctx2.fillBlock({receiver:receiver},$ctx1)})}));
  544. return self}, function($ctx1) {$ctx1.fill(self,"visitCascadeNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  545. args: ["aNode"],
  546. source: "visitCascadeNode: aNode\x0a\x09\x22TODO: Handle super sends\x22\x0a\x09\x0a self interpret: aNode receiver continue: [ :receiver |\x0a\x09\x09\x22Only interpret the receiver once\x22\x0a aNode nodes do: [ :each | each receiver: receiver ].\x0a \x0a \x09self \x0a \x09interpretAll: aNode nodes allButLast\x0a \x09\x09continue: [\x0a \x09self \x0a \x09interpret: aNode nodes last\x0a \x09continue: [ :val | self continue: val ] ] ]",
  547. messageSends: ["interpret:continue:", "receiver", "do:", "receiver:", "nodes", "interpretAll:continue:", "allButLast", "last", "continue:"],
  548. referencedClasses: []
  549. }),
  550. smalltalk.ASTInterpreter);
  551. smalltalk.addMethod(
  552. "_visitClassReferenceNode_",
  553. smalltalk.method({
  554. selector: "visitClassReferenceNode:",
  555. category: 'visiting',
  556. fn: function (aNode){
  557. var self=this;
  558. return smalltalk.withContext(function($ctx1) { _st(self)._continue_(_st(_st((smalltalk.Smalltalk || Smalltalk))._current())._at_(_st(aNode)._value()));
  559. return self}, function($ctx1) {$ctx1.fill(self,"visitClassReferenceNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  560. args: ["aNode"],
  561. source: "visitClassReferenceNode: aNode\x0a\x09self continue: (Smalltalk current at: aNode value)",
  562. messageSends: ["continue:", "at:", "value", "current"],
  563. referencedClasses: ["Smalltalk"]
  564. }),
  565. smalltalk.ASTInterpreter);
  566. smalltalk.addMethod(
  567. "_visitDynamicArrayNode_",
  568. smalltalk.method({
  569. selector: "visitDynamicArrayNode:",
  570. category: 'visiting',
  571. fn: function (aNode){
  572. var self=this;
  573. return smalltalk.withContext(function($ctx1) { _st(self)._interpretAll_continue_(_st(aNode)._nodes(),(function(array){
  574. return smalltalk.withContext(function($ctx2) { return _st(self)._continue_(array);
  575. }, function($ctx2) {$ctx2.fillBlock({array:array},$ctx1)})}));
  576. return self}, function($ctx1) {$ctx1.fill(self,"visitDynamicArrayNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  577. args: ["aNode"],
  578. source: "visitDynamicArrayNode: aNode\x0a\x0a\x09self interpretAll: aNode nodes continue: [ :array |\x0a \x09self continue: array ]",
  579. messageSends: ["interpretAll:continue:", "nodes", "continue:"],
  580. referencedClasses: []
  581. }),
  582. smalltalk.ASTInterpreter);
  583. smalltalk.addMethod(
  584. "_visitDynamicDictionaryNode_",
  585. smalltalk.method({
  586. selector: "visitDynamicDictionaryNode:",
  587. category: 'visiting',
  588. fn: function (aNode){
  589. var self=this;
  590. return smalltalk.withContext(function($ctx1) { _st(self)._interpretAll_continue_(_st(aNode)._nodes(),(function(array){
  591. var hashedCollection;
  592. return smalltalk.withContext(function($ctx2) { hashedCollection=_st((smalltalk.HashedCollection || HashedCollection))._new();
  593. hashedCollection;
  594. _st(array)._do_((function(each){
  595. return smalltalk.withContext(function($ctx3) { return _st(hashedCollection)._add_(each);
  596. }, function($ctx3) {$ctx3.fillBlock({each:each},$ctx1)})}));
  597. return _st(self)._continue_(hashedCollection);
  598. }, function($ctx2) {$ctx2.fillBlock({array:array,hashedCollection:hashedCollection},$ctx1)})}));
  599. return self}, function($ctx1) {$ctx1.fill(self,"visitDynamicDictionaryNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  600. args: ["aNode"],
  601. source: "visitDynamicDictionaryNode: aNode\x0a\x09\x0a self interpretAll: aNode nodes continue: [ :array | | hashedCollection |\x0a \x09hashedCollection := HashedCollection new.\x0a array do: [ :each | hashedCollection add: each ].\x0a self continue: hashedCollection ]",
  602. messageSends: ["interpretAll:continue:", "nodes", "new", "do:", "add:", "continue:"],
  603. referencedClasses: ["HashedCollection"]
  604. }),
  605. smalltalk.ASTInterpreter);
  606. smalltalk.addMethod(
  607. "_visitJSStatementNode_",
  608. smalltalk.method({
  609. selector: "visitJSStatementNode:",
  610. category: 'visiting',
  611. fn: function (aNode){
  612. var self=this;
  613. return smalltalk.withContext(function($ctx1) { self["@shouldReturn"]=true;
  614. _st(self)._continue_(_st(self)._eval_(_st(aNode)._source()));
  615. return self}, function($ctx1) {$ctx1.fill(self,"visitJSStatementNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  616. args: ["aNode"],
  617. source: "visitJSStatementNode: aNode\x0a\x09shouldReturn := true.\x0a\x09self continue: (self eval: aNode source)",
  618. messageSends: ["continue:", "eval:", "source"],
  619. referencedClasses: []
  620. }),
  621. smalltalk.ASTInterpreter);
  622. smalltalk.addMethod(
  623. "_visitReturnNode_",
  624. smalltalk.method({
  625. selector: "visitReturnNode:",
  626. category: 'visiting',
  627. fn: function (aNode){
  628. var self=this;
  629. return smalltalk.withContext(function($ctx1) { _st(self)._interpret_continue_(_st(_st(aNode)._nodes())._first(),(function(value){
  630. return smalltalk.withContext(function($ctx2) { self["@shouldReturn"]=true;
  631. self["@shouldReturn"];
  632. return _st(self)._continue_(value);
  633. }, function($ctx2) {$ctx2.fillBlock({value:value},$ctx1)})}));
  634. return self}, function($ctx1) {$ctx1.fill(self,"visitReturnNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  635. args: ["aNode"],
  636. source: "visitReturnNode: aNode\x0a self interpret: aNode nodes first continue: [ :value |\x0a \x09shouldReturn := true.\x0a\x09\x09self continue: value ]",
  637. messageSends: ["interpret:continue:", "first", "nodes", "continue:"],
  638. referencedClasses: []
  639. }),
  640. smalltalk.ASTInterpreter);
  641. smalltalk.addMethod(
  642. "_visitSendNode_",
  643. smalltalk.method({
  644. selector: "visitSendNode:",
  645. category: 'visiting',
  646. fn: function (aNode){
  647. var self=this;
  648. return smalltalk.withContext(function($ctx1) { _st(self)._interpret_continue_(_st(aNode)._receiver(),(function(receiver){
  649. return smalltalk.withContext(function($ctx2) { return _st(self)._messageFromSendNode_do_(aNode,(function(message){
  650. return smalltalk.withContext(function($ctx3) { _st(_st(self)._context())._pc_(_st(_st(_st(self)._context())._pc()).__plus((1)));
  651. return _st(self)._continue_(_st(message)._sendTo_(receiver));
  652. }, function($ctx3) {$ctx3.fillBlock({message:message},$ctx1)})}));
  653. }, function($ctx2) {$ctx2.fillBlock({receiver:receiver},$ctx1)})}));
  654. return self}, function($ctx1) {$ctx1.fill(self,"visitSendNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  655. args: ["aNode"],
  656. source: "visitSendNode: aNode\x0a\x09\x22TODO: Handle super sends\x22\x0a \x0a self interpret: aNode receiver continue: [ :receiver |\x0a \x09self messageFromSendNode: aNode do: [ :message |\x0a \x09self context pc: self context pc + 1.\x0a \x09self continue: (message sendTo: receiver) ] ]",
  657. messageSends: ["interpret:continue:", "receiver", "messageFromSendNode:do:", "pc:", "+", "pc", "context", "continue:", "sendTo:"],
  658. referencedClasses: []
  659. }),
  660. smalltalk.ASTInterpreter);
  661. smalltalk.addMethod(
  662. "_visitSequenceNode_",
  663. smalltalk.method({
  664. selector: "visitSequenceNode:",
  665. category: 'visiting',
  666. fn: function (aNode){
  667. var self=this;
  668. return smalltalk.withContext(function($ctx1) { _st(self)._interpretAll_continue_(_st(aNode)._nodes(),(function(array){
  669. return smalltalk.withContext(function($ctx2) { return _st(self)._continue_(_st(array)._last());
  670. }, function($ctx2) {$ctx2.fillBlock({array:array},$ctx1)})}));
  671. return self}, function($ctx1) {$ctx1.fill(self,"visitSequenceNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  672. args: ["aNode"],
  673. source: "visitSequenceNode: aNode\x0a\x09self interpretAll: aNode nodes continue: [ :array |\x0a \x09self continue: array last ]",
  674. messageSends: ["interpretAll:continue:", "nodes", "continue:", "last"],
  675. referencedClasses: []
  676. }),
  677. smalltalk.ASTInterpreter);
  678. smalltalk.addMethod(
  679. "_visitValueNode_",
  680. smalltalk.method({
  681. selector: "visitValueNode:",
  682. category: 'visiting',
  683. fn: function (aNode){
  684. var self=this;
  685. return smalltalk.withContext(function($ctx1) { _st(self)._continue_(_st(aNode)._value());
  686. return self}, function($ctx1) {$ctx1.fill(self,"visitValueNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})},
  687. args: ["aNode"],
  688. source: "visitValueNode: aNode\x0a\x09self continue: aNode value",
  689. messageSends: ["continue:", "value"],
  690. referencedClasses: []
  691. }),
  692. smalltalk.ASTInterpreter);
  693. smalltalk.addClass('ASTDebugger', smalltalk.ASTInterpreter, ['continuation'], 'Compiler-Interpreter');
  694. smalltalk.addMethod(
  695. "_initialize",
  696. smalltalk.method({
  697. selector: "initialize",
  698. category: 'initialization',
  699. fn: function (){
  700. var self=this;
  701. return smalltalk.withContext(function($ctx1) { smalltalk.ASTInterpreter.fn.prototype._initialize.apply(_st(self), []);
  702. self["@continuation"]=(function(){
  703. return smalltalk.withContext(function($ctx2) { }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})});
  704. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{}, smalltalk.ASTDebugger)})},
  705. args: [],
  706. source: "initialize\x0a\x09super initialize.\x0a continuation := [ ]",
  707. messageSends: ["initialize"],
  708. referencedClasses: []
  709. }),
  710. smalltalk.ASTDebugger);
  711. smalltalk.addMethod(
  712. "_interpret_continue_",
  713. smalltalk.method({
  714. selector: "interpret:continue:",
  715. category: 'interpreting',
  716. fn: function (aNode,aBlock){
  717. var self=this;
  718. return smalltalk.withContext(function($ctx1) { self["@continuation"]=(function(){
  719. return smalltalk.withContext(function($ctx2) { return smalltalk.ASTInterpreter.fn.prototype._interpret_continue_.apply(_st(self), [aNode,aBlock]);
  720. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})});
  721. return self}, function($ctx1) {$ctx1.fill(self,"interpret:continue:",{aNode:aNode,aBlock:aBlock}, smalltalk.ASTDebugger)})},
  722. args: ["aNode", "aBlock"],
  723. source: "interpret: aNode continue: aBlock\x0a\x09continuation := [ super interpret: aNode continue: aBlock ]",
  724. messageSends: ["interpret:continue:"],
  725. referencedClasses: []
  726. }),
  727. smalltalk.ASTDebugger);
  728. smalltalk.addMethod(
  729. "_stepOver",
  730. smalltalk.method({
  731. selector: "stepOver",
  732. category: 'stepping',
  733. fn: function (){
  734. var self=this;
  735. return smalltalk.withContext(function($ctx1) { _st(self["@continuation"])._value();
  736. return self}, function($ctx1) {$ctx1.fill(self,"stepOver",{}, smalltalk.ASTDebugger)})},
  737. args: [],
  738. source: "stepOver\x0a\x09continuation value",
  739. messageSends: ["value"],
  740. referencedClasses: []
  741. }),
  742. smalltalk.ASTDebugger);