Compiler-Interpreter.deploy.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  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. fn: function (aMethodContext){
  8. var self=this;
  9. return smalltalk.withContext(function($ctx1) { var $1;
  10. _st(self)._pc_(_st(aMethodContext)._pc());
  11. _st(self)._receiver_(_st(aMethodContext)._receiver());
  12. _st(self)._selector_(_st(aMethodContext)._selector());
  13. $1=_st(aMethodContext)._outerContext();
  14. if(($receiver = $1) == nil || $receiver == undefined){
  15. $1;
  16. } else {
  17. _st(self)._outerContext_(_st(_st(self)._class())._fromMethodContext_(_st(aMethodContext)._outerContext()));
  18. };
  19. _st(_st(aMethodContext)._locals())._keysAndValuesDo_((function(key,value){
  20. return smalltalk.withContext(function($ctx2) { return _st(_st(self)._locals())._at_put_(key,value);
  21. }, function($ctx2) {$ctx2.fillBlock({key:key,value:value},$ctx1)})}));
  22. return self}, function($ctx1) {$ctx1.fill(self,"initializeFromMethodContext:",{aMethodContext:aMethodContext}, smalltalk.AIContext)})}
  23. }),
  24. smalltalk.AIContext);
  25. smalltalk.addMethod(
  26. "_localAt_",
  27. smalltalk.method({
  28. selector: "localAt:",
  29. fn: function (aString){
  30. var self=this;
  31. return smalltalk.withContext(function($ctx1) { var $1;
  32. $1=_st(_st(self)._locals())._at_ifAbsent_(aString,(function(){
  33. return smalltalk.withContext(function($ctx2) { return nil;
  34. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
  35. return $1;
  36. }, function($ctx1) {$ctx1.fill(self,"localAt:",{aString:aString}, smalltalk.AIContext)})}
  37. }),
  38. smalltalk.AIContext);
  39. smalltalk.addMethod(
  40. "_localAt_put_",
  41. smalltalk.method({
  42. selector: "localAt:put:",
  43. fn: function (aString,anObject){
  44. var self=this;
  45. return smalltalk.withContext(function($ctx1) { _st(_st(self)._locals())._at_put_(aString,anObject);
  46. return self}, function($ctx1) {$ctx1.fill(self,"localAt:put:",{aString:aString,anObject:anObject}, smalltalk.AIContext)})}
  47. }),
  48. smalltalk.AIContext);
  49. smalltalk.addMethod(
  50. "_locals",
  51. smalltalk.method({
  52. selector: "locals",
  53. fn: function (){
  54. var self=this;
  55. return smalltalk.withContext(function($ctx1) { var $2,$1;
  56. $2=self["@locals"];
  57. if(($receiver = $2) == nil || $receiver == undefined){
  58. self["@locals"]=_st((smalltalk.Dictionary || Dictionary))._new();
  59. $1=self["@locals"];
  60. } else {
  61. $1=$2;
  62. };
  63. return $1;
  64. }, function($ctx1) {$ctx1.fill(self,"locals",{}, smalltalk.AIContext)})}
  65. }),
  66. smalltalk.AIContext);
  67. smalltalk.addMethod(
  68. "_outerContext",
  69. smalltalk.method({
  70. selector: "outerContext",
  71. fn: function (){
  72. var self=this;
  73. return smalltalk.withContext(function($ctx1) { var $1;
  74. $1=self["@outerContext"];
  75. return $1;
  76. }, function($ctx1) {$ctx1.fill(self,"outerContext",{}, smalltalk.AIContext)})}
  77. }),
  78. smalltalk.AIContext);
  79. smalltalk.addMethod(
  80. "_outerContext_",
  81. smalltalk.method({
  82. selector: "outerContext:",
  83. fn: function (anAIContext){
  84. var self=this;
  85. return smalltalk.withContext(function($ctx1) { self["@outerContext"]=anAIContext;
  86. return self}, function($ctx1) {$ctx1.fill(self,"outerContext:",{anAIContext:anAIContext}, smalltalk.AIContext)})}
  87. }),
  88. smalltalk.AIContext);
  89. smalltalk.addMethod(
  90. "_pc",
  91. smalltalk.method({
  92. selector: "pc",
  93. fn: function (){
  94. var self=this;
  95. return smalltalk.withContext(function($ctx1) { var $2,$1;
  96. $2=self["@pc"];
  97. if(($receiver = $2) == nil || $receiver == undefined){
  98. self["@pc"]=(0);
  99. $1=self["@pc"];
  100. } else {
  101. $1=$2;
  102. };
  103. return $1;
  104. }, function($ctx1) {$ctx1.fill(self,"pc",{}, smalltalk.AIContext)})}
  105. }),
  106. smalltalk.AIContext);
  107. smalltalk.addMethod(
  108. "_pc_",
  109. smalltalk.method({
  110. selector: "pc:",
  111. fn: function (anInteger){
  112. var self=this;
  113. return smalltalk.withContext(function($ctx1) { self["@pc"]=anInteger;
  114. return self}, function($ctx1) {$ctx1.fill(self,"pc:",{anInteger:anInteger}, smalltalk.AIContext)})}
  115. }),
  116. smalltalk.AIContext);
  117. smalltalk.addMethod(
  118. "_receiver",
  119. smalltalk.method({
  120. selector: "receiver",
  121. fn: function (){
  122. var self=this;
  123. return smalltalk.withContext(function($ctx1) { var $1;
  124. $1=self["@receiver"];
  125. return $1;
  126. }, function($ctx1) {$ctx1.fill(self,"receiver",{}, smalltalk.AIContext)})}
  127. }),
  128. smalltalk.AIContext);
  129. smalltalk.addMethod(
  130. "_receiver_",
  131. smalltalk.method({
  132. selector: "receiver:",
  133. fn: function (anObject){
  134. var self=this;
  135. return smalltalk.withContext(function($ctx1) { self["@receiver"]=anObject;
  136. return self}, function($ctx1) {$ctx1.fill(self,"receiver:",{anObject:anObject}, smalltalk.AIContext)})}
  137. }),
  138. smalltalk.AIContext);
  139. smalltalk.addMethod(
  140. "_selector",
  141. smalltalk.method({
  142. selector: "selector",
  143. fn: function (){
  144. var self=this;
  145. return smalltalk.withContext(function($ctx1) { var $1;
  146. $1=self["@selector"];
  147. return $1;
  148. }, function($ctx1) {$ctx1.fill(self,"selector",{}, smalltalk.AIContext)})}
  149. }),
  150. smalltalk.AIContext);
  151. smalltalk.addMethod(
  152. "_selector_",
  153. smalltalk.method({
  154. selector: "selector:",
  155. fn: function (aString){
  156. var self=this;
  157. return smalltalk.withContext(function($ctx1) { self["@selector"]=aString;
  158. return self}, function($ctx1) {$ctx1.fill(self,"selector:",{aString:aString}, smalltalk.AIContext)})}
  159. }),
  160. smalltalk.AIContext);
  161. smalltalk.addMethod(
  162. "_fromMethodContext_",
  163. smalltalk.method({
  164. selector: "fromMethodContext:",
  165. fn: function (aMethodContext){
  166. var self=this;
  167. return smalltalk.withContext(function($ctx1) { var $2,$3,$1;
  168. $2=_st(self)._new();
  169. _st($2)._initializeFromMethodContext_(aMethodContext);
  170. $3=_st($2)._yourself();
  171. $1=$3;
  172. return $1;
  173. }, function($ctx1) {$ctx1.fill(self,"fromMethodContext:",{aMethodContext:aMethodContext}, smalltalk.AIContext.klass)})}
  174. }),
  175. smalltalk.AIContext.klass);
  176. smalltalk.addClass('ASTInterpreter', smalltalk.NodeVisitor, ['currentNode', 'context', 'shouldReturn'], 'Compiler-Interpreter');
  177. smalltalk.addMethod(
  178. "_assign_to_",
  179. smalltalk.method({
  180. selector: "assign:to:",
  181. fn: function (aNode,anObject){
  182. var self=this;
  183. return smalltalk.withContext(function($ctx1) { var $2,$1;
  184. $2=_st(_st(aNode)._binding())._isInstanceVar();
  185. if(smalltalk.assert($2)){
  186. $1=_st(_st(_st(self)._context())._receiver())._instVarAt_put_(_st(aNode)._value(),anObject);
  187. } else {
  188. $1=_st(_st(self)._context())._localAt_put_(_st(aNode)._value(),anObject);
  189. };
  190. return $1;
  191. }, function($ctx1) {$ctx1.fill(self,"assign:to:",{aNode:aNode,anObject:anObject}, smalltalk.ASTInterpreter)})}
  192. }),
  193. smalltalk.ASTInterpreter);
  194. smalltalk.addMethod(
  195. "_context",
  196. smalltalk.method({
  197. selector: "context",
  198. fn: function (){
  199. var self=this;
  200. return smalltalk.withContext(function($ctx1) { var $2,$1;
  201. $2=self["@context"];
  202. if(($receiver = $2) == nil || $receiver == undefined){
  203. self["@context"]=_st((smalltalk.AIContext || AIContext))._new();
  204. $1=self["@context"];
  205. } else {
  206. $1=$2;
  207. };
  208. return $1;
  209. }, function($ctx1) {$ctx1.fill(self,"context",{}, smalltalk.ASTInterpreter)})}
  210. }),
  211. smalltalk.ASTInterpreter);
  212. smalltalk.addMethod(
  213. "_context_",
  214. smalltalk.method({
  215. selector: "context:",
  216. fn: function (anAIContext){
  217. var self=this;
  218. return smalltalk.withContext(function($ctx1) { self["@context"]=anAIContext;
  219. return self}, function($ctx1) {$ctx1.fill(self,"context:",{anAIContext:anAIContext}, smalltalk.ASTInterpreter)})}
  220. }),
  221. smalltalk.ASTInterpreter);
  222. smalltalk.addMethod(
  223. "_eval_",
  224. smalltalk.method({
  225. selector: "eval:",
  226. fn: function (aString){
  227. var self=this;
  228. var source,function_;
  229. return smalltalk.withContext(function($ctx1) { var $1,$2,$3;
  230. source=_st((smalltalk.String || String))._streamContents_((function(str){
  231. return smalltalk.withContext(function($ctx2) { _st(str)._nextPutAll_("(function(");
  232. _st(_st(_st(_st(self)._context())._locals())._keys())._do_separatedBy_((function(each){
  233. return smalltalk.withContext(function($ctx3) { return _st(str)._nextPutAll_(each);
  234. }, function($ctx3) {$ctx3.fillBlock({each:each},$ctx1)})}),(function(){
  235. return smalltalk.withContext(function($ctx3) { return _st(str)._nextPutAll_(",");
  236. }, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}));
  237. $1=str;
  238. _st($1)._nextPutAll_("){ return (function() {");
  239. _st($1)._nextPutAll_(aString);
  240. $2=_st($1)._nextPutAll_("})() })");
  241. return $2;
  242. }, function($ctx2) {$ctx2.fillBlock({str:str},$ctx1)})}));
  243. function_=_st(_st((smalltalk.Compiler || Compiler))._new())._eval_(source);
  244. $3=_st(function_)._valueWithPossibleArguments_(_st(_st(_st(self)._context())._locals())._values());
  245. return $3;
  246. }, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString,source:source,function_:function_}, smalltalk.ASTInterpreter)})}
  247. }),
  248. smalltalk.ASTInterpreter);
  249. smalltalk.addMethod(
  250. "_initialize",
  251. smalltalk.method({
  252. selector: "initialize",
  253. fn: function (){
  254. var self=this;
  255. return smalltalk.withContext(function($ctx1) { smalltalk.NodeVisitor.fn.prototype._initialize.apply(_st(self), []);
  256. self["@shouldReturn"]=false;
  257. return self}, function($ctx1) {$ctx1.fill(self,"initialize",{}, smalltalk.ASTInterpreter)})}
  258. }),
  259. smalltalk.ASTInterpreter);
  260. smalltalk.addMethod(
  261. "_interpret_",
  262. smalltalk.method({
  263. selector: "interpret:",
  264. fn: function (aNode){
  265. var self=this;
  266. return smalltalk.withContext(function($ctx1) { var $1;
  267. self["@shouldReturn"]=false;
  268. $1=_st(self)._interpretNode_(aNode);
  269. return $1;
  270. }, function($ctx1) {$ctx1.fill(self,"interpret:",{aNode:aNode}, smalltalk.ASTInterpreter)})}
  271. }),
  272. smalltalk.ASTInterpreter);
  273. smalltalk.addMethod(
  274. "_interpretNode_",
  275. smalltalk.method({
  276. selector: "interpretNode:",
  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. }, function($ctx1) {$ctx1.fill(self,"interpretNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})}
  284. }),
  285. smalltalk.ASTInterpreter);
  286. smalltalk.addMethod(
  287. "_messageFromSendNode_",
  288. smalltalk.method({
  289. selector: "messageFromSendNode:",
  290. fn: function (aSendNode){
  291. var self=this;
  292. return smalltalk.withContext(function($ctx1) { var $2,$3,$1;
  293. $2=_st((smalltalk.Message || Message))._new();
  294. _st($2)._selector_(_st(aSendNode)._selector());
  295. _st($2)._arguments_(_st(_st(aSendNode)._arguments())._collect_((function(each){
  296. return smalltalk.withContext(function($ctx2) { return _st(self)._interpretNode_(each);
  297. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})})));
  298. $3=_st($2)._yourself();
  299. $1=$3;
  300. return $1;
  301. }, function($ctx1) {$ctx1.fill(self,"messageFromSendNode:",{aSendNode:aSendNode}, smalltalk.ASTInterpreter)})}
  302. }),
  303. smalltalk.ASTInterpreter);
  304. smalltalk.addMethod(
  305. "_visitAssignmentNode_",
  306. smalltalk.method({
  307. selector: "visitAssignmentNode:",
  308. fn: function (aNode){
  309. var self=this;
  310. return smalltalk.withContext(function($ctx1) { var $1;
  311. $1=_st(self)._assign_to_(_st(aNode)._left(),_st(self)._interpretNode_(_st(aNode)._right()));
  312. return $1;
  313. }, function($ctx1) {$ctx1.fill(self,"visitAssignmentNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})}
  314. }),
  315. smalltalk.ASTInterpreter);
  316. smalltalk.addMethod(
  317. "_visitBlockNode_",
  318. smalltalk.method({
  319. selector: "visitBlockNode:",
  320. fn: function (aNode){
  321. var self=this;
  322. return smalltalk.withContext(function($ctx1) { var $1;
  323. $1=(function(){
  324. return smalltalk.withContext(function($ctx2) { return _st(self)._interpretNode_(_st(_st(aNode)._nodes())._first());
  325. }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})});
  326. return $1;
  327. }, function($ctx1) {$ctx1.fill(self,"visitBlockNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})}
  328. }),
  329. smalltalk.ASTInterpreter);
  330. smalltalk.addMethod(
  331. "_visitCascadeNode_",
  332. smalltalk.method({
  333. selector: "visitCascadeNode:",
  334. fn: function (aNode){
  335. var self=this;
  336. var receiver;
  337. return smalltalk.withContext(function($ctx1) { var $1;
  338. receiver=_st(self)._interpretNode_(_st(aNode)._receiver());
  339. _st(_st(_st(aNode)._nodes())._allButLast())._do_((function(each){
  340. return smalltalk.withContext(function($ctx2) { return _st(_st(self)._messageFromSendNode_(each))._sendTo_(receiver);
  341. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  342. $1=_st(_st(self)._messageFromSendNode_(_st(_st(aNode)._nodes())._last()))._sendTo_(receiver);
  343. return $1;
  344. }, function($ctx1) {$ctx1.fill(self,"visitCascadeNode:",{aNode:aNode,receiver:receiver}, smalltalk.ASTInterpreter)})}
  345. }),
  346. smalltalk.ASTInterpreter);
  347. smalltalk.addMethod(
  348. "_visitClassReferenceNode_",
  349. smalltalk.method({
  350. selector: "visitClassReferenceNode:",
  351. fn: function (aNode){
  352. var self=this;
  353. return smalltalk.withContext(function($ctx1) { var $1;
  354. $1=_st(_st((smalltalk.Smalltalk || Smalltalk))._current())._at_(_st(aNode)._value());
  355. return $1;
  356. }, function($ctx1) {$ctx1.fill(self,"visitClassReferenceNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})}
  357. }),
  358. smalltalk.ASTInterpreter);
  359. smalltalk.addMethod(
  360. "_visitJSStatementNode_",
  361. smalltalk.method({
  362. selector: "visitJSStatementNode:",
  363. fn: function (aNode){
  364. var self=this;
  365. return smalltalk.withContext(function($ctx1) { var $1;
  366. self["@shouldReturn"]=true;
  367. $1=_st(self)._eval_(_st(aNode)._source());
  368. return $1;
  369. }, function($ctx1) {$ctx1.fill(self,"visitJSStatementNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})}
  370. }),
  371. smalltalk.ASTInterpreter);
  372. smalltalk.addMethod(
  373. "_visitReturnNode_",
  374. smalltalk.method({
  375. selector: "visitReturnNode:",
  376. fn: function (aNode){
  377. var self=this;
  378. return smalltalk.withContext(function($ctx1) { var $1;
  379. self["@shouldReturn"]=true;
  380. $1=_st(self)._interpretNode_(_st(_st(aNode)._nodes())._first());
  381. return $1;
  382. }, function($ctx1) {$ctx1.fill(self,"visitReturnNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})}
  383. }),
  384. smalltalk.ASTInterpreter);
  385. smalltalk.addMethod(
  386. "_visitSendNode_",
  387. smalltalk.method({
  388. selector: "visitSendNode:",
  389. fn: function (aNode){
  390. var self=this;
  391. return smalltalk.withContext(function($ctx1) { var $1;
  392. $1=_st(_st(self)._messageFromSendNode_(aNode))._sendTo_(_st(self)._interpretNode_(_st(aNode)._receiver()));
  393. return $1;
  394. }, function($ctx1) {$ctx1.fill(self,"visitSendNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})}
  395. }),
  396. smalltalk.ASTInterpreter);
  397. smalltalk.addMethod(
  398. "_visitSequenceNode_",
  399. smalltalk.method({
  400. selector: "visitSequenceNode:",
  401. fn: function (aNode){
  402. var self=this;
  403. return smalltalk.withContext(function($ctx1) { var $1,$3,$4,$2,$5;
  404. var $early={};
  405. try {
  406. $1=_st(_st(aNode)._nodes())._allButLast();
  407. $2=(function(each){
  408. var value;
  409. return smalltalk.withContext(function($ctx2) { value=_st(self)._interpretNode_(each);
  410. value;
  411. $3=self["@shouldReturn"];
  412. if(smalltalk.assert($3)){
  413. $4=value;
  414. throw $early=[$4];
  415. };
  416. }, function($ctx2) {$ctx2.fillBlock({each:each,value:value},$ctx1)})});
  417. _st($1)._do_($2);
  418. $5=_st(self)._interpretNode_(_st(_st(aNode)._nodes())._last());
  419. return $5;
  420. }
  421. catch(e) {if(e===$early)return e[0]; throw e}
  422. }, function($ctx1) {$ctx1.fill(self,"visitSequenceNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})}
  423. }),
  424. smalltalk.ASTInterpreter);
  425. smalltalk.addMethod(
  426. "_visitValueNode_",
  427. smalltalk.method({
  428. selector: "visitValueNode:",
  429. fn: function (aNode){
  430. var self=this;
  431. return smalltalk.withContext(function($ctx1) { var $1;
  432. $1=_st(aNode)._value();
  433. return $1;
  434. }, function($ctx1) {$ctx1.fill(self,"visitValueNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})}
  435. }),
  436. smalltalk.ASTInterpreter);
  437. smalltalk.addMethod(
  438. "_visitVariableNode_",
  439. smalltalk.method({
  440. selector: "visitVariableNode:",
  441. fn: function (aNode){
  442. var self=this;
  443. return smalltalk.withContext(function($ctx1) { var $2,$1;
  444. $2=_st(_st(aNode)._binding())._isInstanceVar();
  445. if(smalltalk.assert($2)){
  446. $1=_st(_st(_st(self)._context())._receiver())._instVarAt_(_st(aNode)._value());
  447. } else {
  448. $1=_st(_st(self)._context())._localAt_(_st(aNode)._value());
  449. };
  450. return $1;
  451. }, function($ctx1) {$ctx1.fill(self,"visitVariableNode:",{aNode:aNode}, smalltalk.ASTInterpreter)})}
  452. }),
  453. smalltalk.ASTInterpreter);