Compiler-Interpreter.deploy.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. smalltalk.addPackage('Compiler-Interpreter', {});
  2. smalltalk.addClass('ASTBlockClosure', smalltalk.BlockClosure, ['astNode'], 'Compiler-Interpreter');
  3. smalltalk.addMethod(
  4. "_astNode",
  5. smalltalk.method({
  6. selector: "astNode",
  7. fn: function (){
  8. var self=this;
  9. return self["@astNode"];
  10. }
  11. }),
  12. smalltalk.ASTBlockClosure);
  13. smalltalk.addMethod(
  14. "_astNode_",
  15. smalltalk.method({
  16. selector: "astNode:",
  17. fn: function (aNode){
  18. var self=this;
  19. self["@astNode"]=aNode;
  20. return self}
  21. }),
  22. smalltalk.ASTBlockClosure);
  23. smalltalk.addMethod(
  24. "_value",
  25. smalltalk.method({
  26. selector: "value",
  27. fn: function (){
  28. var self=this;
  29. var $1;
  30. $1=smalltalk.send(smalltalk.send((smalltalk.ASTInterpreter || ASTInterpreter),"_current",[]),"_blockValue_",[self]);
  31. return $1;
  32. }
  33. }),
  34. smalltalk.ASTBlockClosure);
  35. smalltalk.addClass('ASTInterpreter', smalltalk.NodeVisitor, ['currentNode', 'context', 'shouldReturn'], 'Compiler-Interpreter');
  36. smalltalk.addMethod(
  37. "_blockValue_",
  38. smalltalk.method({
  39. selector: "blockValue:",
  40. fn: function (anASTBlockClosure){
  41. var self=this;
  42. var $1;
  43. $1=smalltalk.send(self,"_interpret_",[smalltalk.send(smalltalk.send(smalltalk.send(anASTBlockClosure,"_astNode",[]),"_nodes",[]),"_first",[])]);
  44. return $1;
  45. }
  46. }),
  47. smalltalk.ASTInterpreter);
  48. smalltalk.addMethod(
  49. "_context",
  50. smalltalk.method({
  51. selector: "context",
  52. fn: function (){
  53. var self=this;
  54. return self["@context"];
  55. }
  56. }),
  57. smalltalk.ASTInterpreter);
  58. smalltalk.addMethod(
  59. "_context_",
  60. smalltalk.method({
  61. selector: "context:",
  62. fn: function (aMethodContext){
  63. var self=this;
  64. self["@context"]=aMethodContext;
  65. return self}
  66. }),
  67. smalltalk.ASTInterpreter);
  68. smalltalk.addMethod(
  69. "_initialize",
  70. smalltalk.method({
  71. selector: "initialize",
  72. fn: function (){
  73. var self=this;
  74. smalltalk.send(self,"_initialize",[],smalltalk.NodeVisitor);
  75. self["@shouldReturn"]=false;
  76. return self}
  77. }),
  78. smalltalk.ASTInterpreter);
  79. smalltalk.addMethod(
  80. "_interpret_",
  81. smalltalk.method({
  82. selector: "interpret:",
  83. fn: function (aNode){
  84. var self=this;
  85. var $1;
  86. self["@shouldReturn"]=false;
  87. $1=smalltalk.send(self,"_interpretNode_",[aNode]);
  88. return $1;
  89. }
  90. }),
  91. smalltalk.ASTInterpreter);
  92. smalltalk.addMethod(
  93. "_interpretNode_",
  94. smalltalk.method({
  95. selector: "interpretNode:",
  96. fn: function (aNode){
  97. var self=this;
  98. var $1;
  99. self["@currentNode"]=aNode;
  100. $1=smalltalk.send(self,"_visit_",[aNode]);
  101. return $1;
  102. }
  103. }),
  104. smalltalk.ASTInterpreter);
  105. smalltalk.addMethod(
  106. "_send_to_arguments_",
  107. smalltalk.method({
  108. selector: "send:to:arguments:",
  109. fn: function (aSelector,anObject,aCollection){
  110. var self=this;
  111. var $1;
  112. $1=smalltalk.send(anObject,"_perform_withArguments_",[aSelector,aCollection]);
  113. return $1;
  114. }
  115. }),
  116. smalltalk.ASTInterpreter);
  117. smalltalk.addMethod(
  118. "_visitBlockNode_",
  119. smalltalk.method({
  120. selector: "visitBlockNode:",
  121. fn: function (aNode){
  122. var self=this;
  123. var $2,$3,$1;
  124. $2=smalltalk.send((smalltalk.ASTBlockClosure || ASTBlockClosure),"_new",[]);
  125. smalltalk.send($2,"_astNode_",[aNode]);
  126. $3=smalltalk.send($2,"_yourself",[]);
  127. $1=$3;
  128. return $1;
  129. }
  130. }),
  131. smalltalk.ASTInterpreter);
  132. smalltalk.addMethod(
  133. "_visitReturnNode_",
  134. smalltalk.method({
  135. selector: "visitReturnNode:",
  136. fn: function (aNode){
  137. var self=this;
  138. var $1;
  139. self["@shouldReturn"]=true;
  140. $1=smalltalk.send(self,"_interpret_",[smalltalk.send(smalltalk.send(aNode,"_nodes",[]),"_first",[])]);
  141. return $1;
  142. }
  143. }),
  144. smalltalk.ASTInterpreter);
  145. smalltalk.addMethod(
  146. "_visitSendNode_",
  147. smalltalk.method({
  148. selector: "visitSendNode:",
  149. fn: function (aNode){
  150. var self=this;
  151. var $1;
  152. var receiver;
  153. var arguments;
  154. receiver=smalltalk.send(self,"_interpret_",[smalltalk.send(aNode,"_receiver",[])]);
  155. arguments=smalltalk.send(smalltalk.send(aNode,"_arguments",[]),"_collect_",[(function(each){
  156. return smalltalk.send(self,"_interpret_",[each]);
  157. })]);
  158. $1=smalltalk.send(self,"_send_to_arguments_",[smalltalk.send(aNode,"_selector",[]),receiver,arguments]);
  159. return $1;
  160. }
  161. }),
  162. smalltalk.ASTInterpreter);
  163. smalltalk.addMethod(
  164. "_visitSequenceNode_",
  165. smalltalk.method({
  166. selector: "visitSequenceNode:",
  167. fn: function (aNode){
  168. var self=this;
  169. var $1;
  170. var $early={};
  171. try {
  172. smalltalk.send(smalltalk.send(smalltalk.send(aNode,"_nodes",[]),"_allButLast",[]),"_do_",[(function(each){
  173. var value;
  174. value=smalltalk.send(self,"_interpret_",[each]);
  175. value;
  176. if(smalltalk.assert(self["@shouldReturn"])){
  177. throw $early=[value];
  178. };
  179. })]);
  180. $1=smalltalk.send(self,"_interpret_",[smalltalk.send(smalltalk.send(aNode,"_nodes",[]),"_last",[])]);
  181. return $1;
  182. }
  183. catch(e) {if(e===$early)return e[0]; throw e}
  184. }
  185. }),
  186. smalltalk.ASTInterpreter);
  187. smalltalk.addMethod(
  188. "_visitValueNode_",
  189. smalltalk.method({
  190. selector: "visitValueNode:",
  191. fn: function (aNode){
  192. var self=this;
  193. var $1;
  194. $1=smalltalk.send(aNode,"_value",[]);
  195. return $1;
  196. }
  197. }),
  198. smalltalk.ASTInterpreter);
  199. smalltalk.ASTInterpreter.klass.iVarNames = ['current'];
  200. smalltalk.addMethod(
  201. "_current",
  202. smalltalk.method({
  203. selector: "current",
  204. fn: function (){
  205. var self=this;
  206. var $1;
  207. if(($receiver = self["@current"]) == nil || $receiver == undefined){
  208. self["@current"]=smalltalk.send(self,"_new",[],smalltalk.NodeVisitor.klass);
  209. $1=self["@current"];
  210. } else {
  211. $1=self["@current"];
  212. };
  213. return $1;
  214. }
  215. }),
  216. smalltalk.ASTInterpreter.klass);
  217. smalltalk.addMethod(
  218. "_new",
  219. smalltalk.method({
  220. selector: "new",
  221. fn: function (){
  222. var self=this;
  223. smalltalk.send(self,"_shouldNotImplement",[]);
  224. return self}
  225. }),
  226. smalltalk.ASTInterpreter.klass);