1
0

Compiler-Interpreter.deploy.js 13 KB

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