Compiler-Interpreter.deploy.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  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,value], {})})}));
  22. return self}, function($ctx1) {$ctx1.fill(self,"initializeFromMethodContext:", [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,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], {}, 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], {}, 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], {}, 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], {}, 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], {}, 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], {}, 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. return smalltalk.withContext(function($ctx1) { var $1;
  198. $1=_st(_st((smalltalk.Compiler || Compiler))._new())._eval_(_st(_st("(function() { ").__comma(aString)).__comma(" })()"));
  199. return $1;
  200. }, function($ctx1) {$ctx1.fill(self,"eval:", [aString], {}, smalltalk.ASTInterpreter)})}
  201. }),
  202. smalltalk.ASTInterpreter);
  203. smalltalk.addMethod(
  204. "_initialize",
  205. smalltalk.method({
  206. selector: "initialize",
  207. fn: function (){
  208. var self=this;
  209. return smalltalk.withContext(function($ctx1) { smalltalk.NodeVisitor.fn.prototype._initialize.apply(_st(self), []);
  210. self["@shouldReturn"]=false;
  211. return self}, function($ctx1) {$ctx1.fill(self,"initialize", [], {}, smalltalk.ASTInterpreter)})}
  212. }),
  213. smalltalk.ASTInterpreter);
  214. smalltalk.addMethod(
  215. "_interpret_",
  216. smalltalk.method({
  217. selector: "interpret:",
  218. fn: function (aNode){
  219. var self=this;
  220. return smalltalk.withContext(function($ctx1) { var $1;
  221. self["@shouldReturn"]=false;
  222. $1=_st(self)._interpretNode_(aNode);
  223. return $1;
  224. }, function($ctx1) {$ctx1.fill(self,"interpret:", [aNode], {}, smalltalk.ASTInterpreter)})}
  225. }),
  226. smalltalk.ASTInterpreter);
  227. smalltalk.addMethod(
  228. "_interpretNode_",
  229. smalltalk.method({
  230. selector: "interpretNode:",
  231. fn: function (aNode){
  232. var self=this;
  233. return smalltalk.withContext(function($ctx1) { var $1;
  234. self["@currentNode"]=aNode;
  235. $1=_st(self)._visit_(aNode);
  236. return $1;
  237. }, function($ctx1) {$ctx1.fill(self,"interpretNode:", [aNode], {}, smalltalk.ASTInterpreter)})}
  238. }),
  239. smalltalk.ASTInterpreter);
  240. smalltalk.addMethod(
  241. "_messageFromSendNode_",
  242. smalltalk.method({
  243. selector: "messageFromSendNode:",
  244. fn: function (aSendNode){
  245. var self=this;
  246. return smalltalk.withContext(function($ctx1) { var $2,$3,$1;
  247. $2=_st((smalltalk.Message || Message))._new();
  248. _st($2)._selector_(_st(aSendNode)._selector());
  249. _st($2)._arguments_(_st(_st(aSendNode)._arguments())._collect_((function(each){
  250. return smalltalk.withContext(function($ctx2) { return _st(self)._interpretNode_(each);
  251. }, function($ctx2) {$ctx2.fillBlock([each], {})})})));
  252. $3=_st($2)._yourself();
  253. $1=$3;
  254. return $1;
  255. }, function($ctx1) {$ctx1.fill(self,"messageFromSendNode:", [aSendNode], {}, smalltalk.ASTInterpreter)})}
  256. }),
  257. smalltalk.ASTInterpreter);
  258. smalltalk.addMethod(
  259. "_visitBlockNode_",
  260. smalltalk.method({
  261. selector: "visitBlockNode:",
  262. fn: function (aNode){
  263. var self=this;
  264. return smalltalk.withContext(function($ctx1) { var $1;
  265. $1=(function(){
  266. return smalltalk.withContext(function($ctx2) { return _st(self)._interpretNode_(_st(_st(aNode)._nodes())._first());
  267. }, function($ctx2) {$ctx2.fillBlock([], {})})});
  268. return $1;
  269. }, function($ctx1) {$ctx1.fill(self,"visitBlockNode:", [aNode], {}, smalltalk.ASTInterpreter)})}
  270. }),
  271. smalltalk.ASTInterpreter);
  272. smalltalk.addMethod(
  273. "_visitCascadeNode_",
  274. smalltalk.method({
  275. selector: "visitCascadeNode:",
  276. fn: function (aNode){
  277. var self=this;
  278. var receiver;
  279. return smalltalk.withContext(function($ctx1) { var $1;
  280. receiver=_st(self)._interpretNode_(_st(aNode)._receiver());
  281. _st(_st(_st(aNode)._nodes())._allButLast())._do_((function(each){
  282. return smalltalk.withContext(function($ctx2) { return _st(_st(self)._messageFromSendNode_(each))._sendTo_(receiver);
  283. }, function($ctx2) {$ctx2.fillBlock([each], {})})}));
  284. $1=_st(_st(self)._messageFromSendNode_(_st(_st(aNode)._nodes())._last()))._sendTo_(receiver);
  285. return $1;
  286. }, function($ctx1) {$ctx1.fill(self,"visitCascadeNode:", [aNode], {receiver:receiver}, smalltalk.ASTInterpreter)})}
  287. }),
  288. smalltalk.ASTInterpreter);
  289. smalltalk.addMethod(
  290. "_visitClassReferenceNode_",
  291. smalltalk.method({
  292. selector: "visitClassReferenceNode:",
  293. fn: function (aNode){
  294. var self=this;
  295. return smalltalk.withContext(function($ctx1) { var $1;
  296. $1=_st(_st((smalltalk.Smalltalk || Smalltalk))._current())._at_(_st(aNode)._value());
  297. return $1;
  298. }, function($ctx1) {$ctx1.fill(self,"visitClassReferenceNode:", [aNode], {}, smalltalk.ASTInterpreter)})}
  299. }),
  300. smalltalk.ASTInterpreter);
  301. smalltalk.addMethod(
  302. "_visitJSStatementNode_",
  303. smalltalk.method({
  304. selector: "visitJSStatementNode:",
  305. fn: function (aNode){
  306. var self=this;
  307. return smalltalk.withContext(function($ctx1) { var $1;
  308. self["@shouldReturn"]=true;
  309. $1=_st(self)._eval_(_st(aNode)._source());
  310. return $1;
  311. }, function($ctx1) {$ctx1.fill(self,"visitJSStatementNode:", [aNode], {}, smalltalk.ASTInterpreter)})}
  312. }),
  313. smalltalk.ASTInterpreter);
  314. smalltalk.addMethod(
  315. "_visitReturnNode_",
  316. smalltalk.method({
  317. selector: "visitReturnNode:",
  318. fn: function (aNode){
  319. var self=this;
  320. return smalltalk.withContext(function($ctx1) { var $1;
  321. self["@shouldReturn"]=true;
  322. $1=_st(self)._interpretNode_(_st(_st(aNode)._nodes())._first());
  323. return $1;
  324. }, function($ctx1) {$ctx1.fill(self,"visitReturnNode:", [aNode], {}, smalltalk.ASTInterpreter)})}
  325. }),
  326. smalltalk.ASTInterpreter);
  327. smalltalk.addMethod(
  328. "_visitSendNode_",
  329. smalltalk.method({
  330. selector: "visitSendNode:",
  331. fn: function (aNode){
  332. var self=this;
  333. return smalltalk.withContext(function($ctx1) { var $1;
  334. $1=_st(_st(self)._messageFromSendNode_(aNode))._sendTo_(_st(self)._interpretNode_(_st(aNode)._receiver()));
  335. return $1;
  336. }, function($ctx1) {$ctx1.fill(self,"visitSendNode:", [aNode], {}, smalltalk.ASTInterpreter)})}
  337. }),
  338. smalltalk.ASTInterpreter);
  339. smalltalk.addMethod(
  340. "_visitSequenceNode_",
  341. smalltalk.method({
  342. selector: "visitSequenceNode:",
  343. fn: function (aNode){
  344. var self=this;
  345. return smalltalk.withContext(function($ctx1) { var $1,$3,$4,$2,$5;
  346. var $early={};
  347. try {
  348. $1=_st(_st(aNode)._nodes())._allButLast();
  349. $2=(function(each){
  350. var value;
  351. return smalltalk.withContext(function($ctx2) { value=_st(self)._interpretNode_(each);
  352. value;
  353. $3=self["@shouldReturn"];
  354. if(smalltalk.assert($3)){
  355. $4=value;
  356. throw $early=[$4];
  357. };
  358. }, function($ctx2) {$ctx2.fillBlock([each], {value:value})})});
  359. _st($1)._do_($2);
  360. $5=_st(self)._interpretNode_(_st(_st(aNode)._nodes())._last());
  361. return $5;
  362. }
  363. catch(e) {if(e===$early)return e[0]; throw e}
  364. }, function($ctx1) {$ctx1.fill(self,"visitSequenceNode:", [aNode], {}, smalltalk.ASTInterpreter)})}
  365. }),
  366. smalltalk.ASTInterpreter);
  367. smalltalk.addMethod(
  368. "_visitValueNode_",
  369. smalltalk.method({
  370. selector: "visitValueNode:",
  371. fn: function (aNode){
  372. var self=this;
  373. return smalltalk.withContext(function($ctx1) { var $1;
  374. $1=_st(aNode)._value();
  375. return $1;
  376. }, function($ctx1) {$ctx1.fill(self,"visitValueNode:", [aNode], {}, smalltalk.ASTInterpreter)})}
  377. }),
  378. smalltalk.ASTInterpreter);