Compiler-Core.js 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. smalltalk.addPackage('Compiler-Core');
  2. smalltalk.addClass('Compiler', smalltalk.Object, ['currentClass', 'source', 'unknownVariables', 'codeGeneratorClass'], 'Compiler-Core');
  3. smalltalk.Compiler.comment="I provide the public interface for compiling Amber source code into JavaScript.\x0a\x0aThe code generator used to produce JavaScript can be plugged with `#codeGeneratorClass`. \x0aThe default code generator is an instance of `InlinedCodeGenerator`"
  4. smalltalk.addMethod(
  5. "_codeGeneratorClass",
  6. smalltalk.method({
  7. selector: "codeGeneratorClass",
  8. category: 'accessing',
  9. fn: function (){
  10. var self=this;
  11. return smalltalk.withContext(function($ctx1) { var $2,$1;
  12. $2=self["@codeGeneratorClass"];
  13. if(($receiver = $2) == nil || $receiver == undefined){
  14. $1=(smalltalk.InliningCodeGenerator || InliningCodeGenerator);
  15. } else {
  16. $1=$2;
  17. };
  18. return $1;
  19. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{}, smalltalk.Compiler)})},
  20. args: [],
  21. source: "codeGeneratorClass\x0a\x09^codeGeneratorClass ifNil: [InliningCodeGenerator]",
  22. messageSends: ["ifNil:"],
  23. referencedClasses: ["InliningCodeGenerator"]
  24. }),
  25. smalltalk.Compiler);
  26. smalltalk.addMethod(
  27. "_codeGeneratorClass_",
  28. smalltalk.method({
  29. selector: "codeGeneratorClass:",
  30. category: 'accessing',
  31. fn: function (aClass){
  32. var self=this;
  33. return smalltalk.withContext(function($ctx1) { self["@codeGeneratorClass"]=aClass;
  34. return self}, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass:",{aClass:aClass}, smalltalk.Compiler)})},
  35. args: ["aClass"],
  36. source: "codeGeneratorClass: aClass\x0a\x09codeGeneratorClass := aClass",
  37. messageSends: [],
  38. referencedClasses: []
  39. }),
  40. smalltalk.Compiler);
  41. smalltalk.addMethod(
  42. "_compile_",
  43. smalltalk.method({
  44. selector: "compile:",
  45. category: 'compiling',
  46. fn: function (aString){
  47. var self=this;
  48. return smalltalk.withContext(function($ctx1) { var $1;
  49. $1=_st(self)._compileNode_(_st(self)._parse_(aString));
  50. return $1;
  51. }, function($ctx1) {$ctx1.fill(self,"compile:",{aString:aString}, smalltalk.Compiler)})},
  52. args: ["aString"],
  53. source: "compile: aString\x0a\x09^self compileNode: (self parse: aString)",
  54. messageSends: ["compileNode:", "parse:"],
  55. referencedClasses: []
  56. }),
  57. smalltalk.Compiler);
  58. smalltalk.addMethod(
  59. "_compile_forClass_",
  60. smalltalk.method({
  61. selector: "compile:forClass:",
  62. category: 'compiling',
  63. fn: function (aString,aClass){
  64. var self=this;
  65. return smalltalk.withContext(function($ctx1) { var $1;
  66. _st(self)._currentClass_(aClass);
  67. _st(self)._source_(aString);
  68. $1=_st(self)._compile_(aString);
  69. return $1;
  70. }, function($ctx1) {$ctx1.fill(self,"compile:forClass:",{aString:aString,aClass:aClass}, smalltalk.Compiler)})},
  71. args: ["aString", "aClass"],
  72. source: "compile: aString forClass: aClass\x0a\x09self currentClass: aClass.\x0a\x09self source: aString.\x0a\x09^self compile: aString",
  73. messageSends: ["currentClass:", "source:", "compile:"],
  74. referencedClasses: []
  75. }),
  76. smalltalk.Compiler);
  77. smalltalk.addMethod(
  78. "_compileExpression_",
  79. smalltalk.method({
  80. selector: "compileExpression:",
  81. category: 'compiling',
  82. fn: function (aString){
  83. var self=this;
  84. return smalltalk.withContext(function($ctx1) { var $1;
  85. _st(self)._currentClass_((smalltalk.DoIt || DoIt));
  86. _st(self)._source_(_st(_st("doIt ^[").__comma(aString)).__comma("] value"));
  87. $1=_st(self)._compileNode_(_st(self)._parse_(_st(self)._source()));
  88. return $1;
  89. }, function($ctx1) {$ctx1.fill(self,"compileExpression:",{aString:aString}, smalltalk.Compiler)})},
  90. args: ["aString"],
  91. source: "compileExpression: aString\x0a\x09self currentClass: DoIt.\x0a\x09self source: 'doIt ^[', aString, '] value'.\x0a\x09^self compileNode: (self parse: self source)",
  92. messageSends: ["currentClass:", "source:", ",", "compileNode:", "parse:", "source"],
  93. referencedClasses: ["DoIt"]
  94. }),
  95. smalltalk.Compiler);
  96. smalltalk.addMethod(
  97. "_compileNode_",
  98. smalltalk.method({
  99. selector: "compileNode:",
  100. category: 'compiling',
  101. fn: function (aNode){
  102. var self=this;
  103. var generator,result;
  104. return smalltalk.withContext(function($ctx1) { var $1,$2,$3;
  105. generator=_st(_st(self)._codeGeneratorClass())._new();
  106. $1=generator;
  107. _st($1)._source_(_st(self)._source());
  108. $2=_st($1)._currentClass_(_st(self)._currentClass());
  109. result=_st(generator)._compileNode_(aNode);
  110. _st(self)._unknownVariables_([]);
  111. $3=result;
  112. return $3;
  113. }, function($ctx1) {$ctx1.fill(self,"compileNode:",{aNode:aNode,generator:generator,result:result}, smalltalk.Compiler)})},
  114. args: ["aNode"],
  115. source: "compileNode: aNode\x0a\x09| generator result |\x0a\x09generator := self codeGeneratorClass new.\x0a\x09generator\x0a\x09\x09source: self source;\x0a\x09\x09currentClass: self currentClass.\x0a\x09result := generator compileNode: aNode.\x0a\x09self unknownVariables: #().\x0a\x09^result",
  116. messageSends: ["new", "codeGeneratorClass", "source:", "source", "currentClass:", "currentClass", "compileNode:", "unknownVariables:"],
  117. referencedClasses: []
  118. }),
  119. smalltalk.Compiler);
  120. smalltalk.addMethod(
  121. "_currentClass",
  122. smalltalk.method({
  123. selector: "currentClass",
  124. category: 'accessing',
  125. fn: function (){
  126. var self=this;
  127. return smalltalk.withContext(function($ctx1) { var $1;
  128. $1=self["@currentClass"];
  129. return $1;
  130. }, function($ctx1) {$ctx1.fill(self,"currentClass",{}, smalltalk.Compiler)})},
  131. args: [],
  132. source: "currentClass\x0a\x09^currentClass",
  133. messageSends: [],
  134. referencedClasses: []
  135. }),
  136. smalltalk.Compiler);
  137. smalltalk.addMethod(
  138. "_currentClass_",
  139. smalltalk.method({
  140. selector: "currentClass:",
  141. category: 'accessing',
  142. fn: function (aClass){
  143. var self=this;
  144. return smalltalk.withContext(function($ctx1) { self["@currentClass"]=aClass;
  145. return self}, function($ctx1) {$ctx1.fill(self,"currentClass:",{aClass:aClass}, smalltalk.Compiler)})},
  146. args: ["aClass"],
  147. source: "currentClass: aClass\x0a\x09currentClass := aClass",
  148. messageSends: [],
  149. referencedClasses: []
  150. }),
  151. smalltalk.Compiler);
  152. smalltalk.addMethod(
  153. "_eval_",
  154. smalltalk.method({
  155. selector: "eval:",
  156. category: 'compiling',
  157. fn: function (aString){
  158. var self=this;
  159. return smalltalk.withContext(function($ctx1) { return eval(aString);
  160. return self}, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString}, smalltalk.Compiler)})},
  161. args: ["aString"],
  162. source: "eval: aString\x0a\x09<return eval(aString)>",
  163. messageSends: [],
  164. referencedClasses: []
  165. }),
  166. smalltalk.Compiler);
  167. smalltalk.addMethod(
  168. "_evaluateExpression_",
  169. smalltalk.method({
  170. selector: "evaluateExpression:",
  171. category: 'compiling',
  172. fn: function (aString){
  173. var self=this;
  174. var result,method;
  175. return smalltalk.withContext(function($ctx1) { var $1;
  176. method=_st(self)._eval_(_st(self)._compileExpression_(aString));
  177. _st(method)._category_("doIt");
  178. _st((smalltalk.DoIt || DoIt))._addCompiledMethod_(method);
  179. result=_st(_st((smalltalk.DoIt || DoIt))._new())._doIt();
  180. _st((smalltalk.DoIt || DoIt))._removeCompiledMethod_(method);
  181. $1=result;
  182. return $1;
  183. }, function($ctx1) {$ctx1.fill(self,"evaluateExpression:",{aString:aString,result:result,method:method}, smalltalk.Compiler)})},
  184. args: ["aString"],
  185. source: "evaluateExpression: aString\x0a\x09\x22Unlike #eval: evaluate a Smalltalk expression and answer the returned object\x22\x0a\x09| result method |\x0a method := self eval: (self compileExpression: aString).\x0a method category: 'doIt'.\x0a\x09DoIt addCompiledMethod: method.\x0a\x09result := DoIt new doIt.\x0a\x09DoIt removeCompiledMethod: method.\x0a\x09^result",
  186. messageSends: ["eval:", "compileExpression:", "category:", "addCompiledMethod:", "doIt", "new", "removeCompiledMethod:"],
  187. referencedClasses: ["DoIt"]
  188. }),
  189. smalltalk.Compiler);
  190. smalltalk.addMethod(
  191. "_install_forClass_category_",
  192. smalltalk.method({
  193. selector: "install:forClass:category:",
  194. category: 'compiling',
  195. fn: function (aString,aBehavior,anotherString){
  196. var self=this;
  197. return smalltalk.withContext(function($ctx1) { var $1;
  198. $1=_st(_st((smalltalk.ClassBuilder || ClassBuilder))._new())._installMethod_forClass_category_(_st(self)._eval_(_st(self)._compile_forClass_(aString,aBehavior)),aBehavior,anotherString);
  199. return $1;
  200. }, function($ctx1) {$ctx1.fill(self,"install:forClass:category:",{aString:aString,aBehavior:aBehavior,anotherString:anotherString}, smalltalk.Compiler)})},
  201. args: ["aString", "aBehavior", "anotherString"],
  202. source: "install: aString forClass: aBehavior category: anotherString\x0a \x09^ ClassBuilder new\x0a \x09installMethod: (self eval: (self compile: aString forClass: aBehavior))\x0a forClass: aBehavior\x0a category: anotherString",
  203. messageSends: ["installMethod:forClass:category:", "eval:", "compile:forClass:", "new"],
  204. referencedClasses: ["ClassBuilder"]
  205. }),
  206. smalltalk.Compiler);
  207. smalltalk.addMethod(
  208. "_parse_",
  209. smalltalk.method({
  210. selector: "parse:",
  211. category: 'compiling',
  212. fn: function (aString){
  213. var self=this;
  214. return smalltalk.withContext(function($ctx1) { var $1;
  215. $1=_st(_st((smalltalk.Smalltalk || Smalltalk))._current())._parse_(aString);
  216. return $1;
  217. }, function($ctx1) {$ctx1.fill(self,"parse:",{aString:aString}, smalltalk.Compiler)})},
  218. args: ["aString"],
  219. source: "parse: aString\x0a ^Smalltalk current parse: aString",
  220. messageSends: ["parse:", "current"],
  221. referencedClasses: ["Smalltalk"]
  222. }),
  223. smalltalk.Compiler);
  224. smalltalk.addMethod(
  225. "_parseExpression_",
  226. smalltalk.method({
  227. selector: "parseExpression:",
  228. category: 'compiling',
  229. fn: function (aString){
  230. var self=this;
  231. return smalltalk.withContext(function($ctx1) { var $1;
  232. $1=_st(self)._parse_(_st(_st("doIt ^[").__comma(aString)).__comma("] value"));
  233. return $1;
  234. }, function($ctx1) {$ctx1.fill(self,"parseExpression:",{aString:aString}, smalltalk.Compiler)})},
  235. args: ["aString"],
  236. source: "parseExpression: aString\x0a ^self parse: 'doIt ^[', aString, '] value'",
  237. messageSends: ["parse:", ","],
  238. referencedClasses: []
  239. }),
  240. smalltalk.Compiler);
  241. smalltalk.addMethod(
  242. "_recompile_",
  243. smalltalk.method({
  244. selector: "recompile:",
  245. category: 'compiling',
  246. fn: function (aClass){
  247. var self=this;
  248. return smalltalk.withContext(function($ctx1) { var $1;
  249. _st(_st(aClass)._methodDictionary())._do_((function(each){
  250. return smalltalk.withContext(function($ctx2) { _st(console)._log_(_st(_st(_st(aClass)._name()).__comma(" >> ")).__comma(_st(each)._selector()));
  251. return _st(self)._install_forClass_category_(_st(each)._source(),aClass,_st(each)._category());
  252. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  253. $1=_st(aClass)._isMetaclass();
  254. if(! smalltalk.assert($1)){
  255. _st(self)._recompile_(_st(aClass)._class());
  256. };
  257. return self}, function($ctx1) {$ctx1.fill(self,"recompile:",{aClass:aClass}, smalltalk.Compiler)})},
  258. args: ["aClass"],
  259. source: "recompile: aClass\x0a\x09aClass methodDictionary do: [:each |\x0a\x09\x09console log: aClass name, ' >> ', each selector.\x0a\x09\x09self install: each source forClass: aClass category: each category].\x0a\x09\x22self setupClass: aClass.\x22\x0a\x09aClass isMetaclass ifFalse: [self recompile: aClass class]",
  260. messageSends: ["do:", "log:", ",", "selector", "name", "install:forClass:category:", "source", "category", "methodDictionary", "ifFalse:", "recompile:", "class", "isMetaclass"],
  261. referencedClasses: []
  262. }),
  263. smalltalk.Compiler);
  264. smalltalk.addMethod(
  265. "_recompileAll",
  266. smalltalk.method({
  267. selector: "recompileAll",
  268. category: 'compiling',
  269. fn: function (){
  270. var self=this;
  271. return smalltalk.withContext(function($ctx1) { var $1,$2;
  272. _st(_st(_st((smalltalk.Smalltalk || Smalltalk))._current())._classes())._do_((function(each){
  273. return smalltalk.withContext(function($ctx2) { $1=(smalltalk.Transcript || Transcript);
  274. _st($1)._show_(each);
  275. $2=_st($1)._cr();
  276. $2;
  277. return _st((function(){
  278. return smalltalk.withContext(function($ctx3) { return _st(self)._recompile_(each);
  279. }, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}))._valueWithTimeout_((100));
  280. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  281. return self}, function($ctx1) {$ctx1.fill(self,"recompileAll",{}, smalltalk.Compiler)})},
  282. args: [],
  283. source: "recompileAll\x0a\x09Smalltalk current classes do: [:each |\x0a\x09\x09Transcript show: each; cr.\x0a\x09\x09[self recompile: each] valueWithTimeout: 100]",
  284. messageSends: ["do:", "show:", "cr", "valueWithTimeout:", "recompile:", "classes", "current"],
  285. referencedClasses: ["Transcript", "Smalltalk"]
  286. }),
  287. smalltalk.Compiler);
  288. smalltalk.addMethod(
  289. "_source",
  290. smalltalk.method({
  291. selector: "source",
  292. category: 'accessing',
  293. fn: function (){
  294. var self=this;
  295. return smalltalk.withContext(function($ctx1) { var $2,$1;
  296. $2=self["@source"];
  297. if(($receiver = $2) == nil || $receiver == undefined){
  298. $1="";
  299. } else {
  300. $1=$2;
  301. };
  302. return $1;
  303. }, function($ctx1) {$ctx1.fill(self,"source",{}, smalltalk.Compiler)})},
  304. args: [],
  305. source: "source\x0a\x09^source ifNil: ['']",
  306. messageSends: ["ifNil:"],
  307. referencedClasses: []
  308. }),
  309. smalltalk.Compiler);
  310. smalltalk.addMethod(
  311. "_source_",
  312. smalltalk.method({
  313. selector: "source:",
  314. category: 'accessing',
  315. fn: function (aString){
  316. var self=this;
  317. return smalltalk.withContext(function($ctx1) { self["@source"]=aString;
  318. return self}, function($ctx1) {$ctx1.fill(self,"source:",{aString:aString}, smalltalk.Compiler)})},
  319. args: ["aString"],
  320. source: "source: aString\x0a\x09source := aString",
  321. messageSends: [],
  322. referencedClasses: []
  323. }),
  324. smalltalk.Compiler);
  325. smalltalk.addMethod(
  326. "_unknownVariables",
  327. smalltalk.method({
  328. selector: "unknownVariables",
  329. category: 'accessing',
  330. fn: function (){
  331. var self=this;
  332. return smalltalk.withContext(function($ctx1) { var $1;
  333. $1=self["@unknownVariables"];
  334. return $1;
  335. }, function($ctx1) {$ctx1.fill(self,"unknownVariables",{}, smalltalk.Compiler)})},
  336. args: [],
  337. source: "unknownVariables\x0a\x09^unknownVariables",
  338. messageSends: [],
  339. referencedClasses: []
  340. }),
  341. smalltalk.Compiler);
  342. smalltalk.addMethod(
  343. "_unknownVariables_",
  344. smalltalk.method({
  345. selector: "unknownVariables:",
  346. category: 'accessing',
  347. fn: function (aCollection){
  348. var self=this;
  349. return smalltalk.withContext(function($ctx1) { self["@unknownVariables"]=aCollection;
  350. return self}, function($ctx1) {$ctx1.fill(self,"unknownVariables:",{aCollection:aCollection}, smalltalk.Compiler)})},
  351. args: ["aCollection"],
  352. source: "unknownVariables: aCollection\x0a\x09unknownVariables := aCollection",
  353. messageSends: [],
  354. referencedClasses: []
  355. }),
  356. smalltalk.Compiler);
  357. smalltalk.addMethod(
  358. "_recompile_",
  359. smalltalk.method({
  360. selector: "recompile:",
  361. category: 'compiling',
  362. fn: function (aClass){
  363. var self=this;
  364. return smalltalk.withContext(function($ctx1) { _st(_st(self)._new())._recompile_(aClass);
  365. return self}, function($ctx1) {$ctx1.fill(self,"recompile:",{aClass:aClass}, smalltalk.Compiler.klass)})},
  366. args: ["aClass"],
  367. source: "recompile: aClass\x0a\x09self new recompile: aClass",
  368. messageSends: ["recompile:", "new"],
  369. referencedClasses: []
  370. }),
  371. smalltalk.Compiler.klass);
  372. smalltalk.addMethod(
  373. "_recompileAll",
  374. smalltalk.method({
  375. selector: "recompileAll",
  376. category: 'compiling',
  377. fn: function (){
  378. var self=this;
  379. return smalltalk.withContext(function($ctx1) { _st(_st(_st((smalltalk.Smalltalk || Smalltalk))._current())._classes())._do_((function(each){
  380. return smalltalk.withContext(function($ctx2) { return _st(self)._recompile_(each);
  381. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  382. return self}, function($ctx1) {$ctx1.fill(self,"recompileAll",{}, smalltalk.Compiler.klass)})},
  383. args: [],
  384. source: "recompileAll\x0a\x09Smalltalk current classes do: [:each |\x0a\x09\x09self recompile: each]",
  385. messageSends: ["do:", "recompile:", "classes", "current"],
  386. referencedClasses: ["Smalltalk"]
  387. }),
  388. smalltalk.Compiler.klass);
  389. smalltalk.addClass('DoIt', smalltalk.Object, [], 'Compiler-Core');
  390. smalltalk.DoIt.comment="`DoIt` is the class used to compile and evaluate expressions. See `Compiler >> evaluateExpression:`."
  391. smalltalk.addClass('NodeVisitor', smalltalk.Object, [], 'Compiler-Core');
  392. smalltalk.NodeVisitor.comment="I am the abstract super class of all AST node visitors."
  393. smalltalk.addMethod(
  394. "_visit_",
  395. smalltalk.method({
  396. selector: "visit:",
  397. category: 'visiting',
  398. fn: function (aNode){
  399. var self=this;
  400. return smalltalk.withContext(function($ctx1) { var $1;
  401. $1=_st(aNode)._accept_(self);
  402. return $1;
  403. }, function($ctx1) {$ctx1.fill(self,"visit:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  404. args: ["aNode"],
  405. source: "visit: aNode\x0a\x09^ aNode accept: self",
  406. messageSends: ["accept:"],
  407. referencedClasses: []
  408. }),
  409. smalltalk.NodeVisitor);
  410. smalltalk.addMethod(
  411. "_visitAll_",
  412. smalltalk.method({
  413. selector: "visitAll:",
  414. category: 'visiting',
  415. fn: function (aCollection){
  416. var self=this;
  417. return smalltalk.withContext(function($ctx1) { var $1;
  418. $1=_st(aCollection)._collect_((function(each){
  419. return smalltalk.withContext(function($ctx2) { return _st(self)._visit_(each);
  420. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
  421. return $1;
  422. }, function($ctx1) {$ctx1.fill(self,"visitAll:",{aCollection:aCollection}, smalltalk.NodeVisitor)})},
  423. args: ["aCollection"],
  424. source: "visitAll: aCollection\x0a\x09^ aCollection collect: [ :each | self visit: each ]",
  425. messageSends: ["collect:", "visit:"],
  426. referencedClasses: []
  427. }),
  428. smalltalk.NodeVisitor);
  429. smalltalk.addMethod(
  430. "_visitAssignmentNode_",
  431. smalltalk.method({
  432. selector: "visitAssignmentNode:",
  433. category: 'visiting',
  434. fn: function (aNode){
  435. var self=this;
  436. return smalltalk.withContext(function($ctx1) { var $1;
  437. $1=_st(self)._visitNode_(aNode);
  438. return $1;
  439. }, function($ctx1) {$ctx1.fill(self,"visitAssignmentNode:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  440. args: ["aNode"],
  441. source: "visitAssignmentNode: aNode\x0a\x09^ self visitNode: aNode",
  442. messageSends: ["visitNode:"],
  443. referencedClasses: []
  444. }),
  445. smalltalk.NodeVisitor);
  446. smalltalk.addMethod(
  447. "_visitBlockNode_",
  448. smalltalk.method({
  449. selector: "visitBlockNode:",
  450. category: 'visiting',
  451. fn: function (aNode){
  452. var self=this;
  453. return smalltalk.withContext(function($ctx1) { var $1;
  454. $1=_st(self)._visitNode_(aNode);
  455. return $1;
  456. }, function($ctx1) {$ctx1.fill(self,"visitBlockNode:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  457. args: ["aNode"],
  458. source: "visitBlockNode: aNode\x0a\x09^ self visitNode: aNode",
  459. messageSends: ["visitNode:"],
  460. referencedClasses: []
  461. }),
  462. smalltalk.NodeVisitor);
  463. smalltalk.addMethod(
  464. "_visitBlockSequenceNode_",
  465. smalltalk.method({
  466. selector: "visitBlockSequenceNode:",
  467. category: 'visiting',
  468. fn: function (aNode){
  469. var self=this;
  470. return smalltalk.withContext(function($ctx1) { var $1;
  471. $1=_st(self)._visitSequenceNode_(aNode);
  472. return $1;
  473. }, function($ctx1) {$ctx1.fill(self,"visitBlockSequenceNode:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  474. args: ["aNode"],
  475. source: "visitBlockSequenceNode: aNode\x0a\x09^ self visitSequenceNode: aNode",
  476. messageSends: ["visitSequenceNode:"],
  477. referencedClasses: []
  478. }),
  479. smalltalk.NodeVisitor);
  480. smalltalk.addMethod(
  481. "_visitCascadeNode_",
  482. smalltalk.method({
  483. selector: "visitCascadeNode:",
  484. category: 'visiting',
  485. fn: function (aNode){
  486. var self=this;
  487. return smalltalk.withContext(function($ctx1) { var $1;
  488. $1=_st(self)._visitNode_(aNode);
  489. return $1;
  490. }, function($ctx1) {$ctx1.fill(self,"visitCascadeNode:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  491. args: ["aNode"],
  492. source: "visitCascadeNode: aNode\x0a\x09^ self visitNode: aNode",
  493. messageSends: ["visitNode:"],
  494. referencedClasses: []
  495. }),
  496. smalltalk.NodeVisitor);
  497. smalltalk.addMethod(
  498. "_visitClassReferenceNode_",
  499. smalltalk.method({
  500. selector: "visitClassReferenceNode:",
  501. category: 'visiting',
  502. fn: function (aNode){
  503. var self=this;
  504. return smalltalk.withContext(function($ctx1) { var $1;
  505. $1=_st(self)._visitVariableNode_(aNode);
  506. return $1;
  507. }, function($ctx1) {$ctx1.fill(self,"visitClassReferenceNode:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  508. args: ["aNode"],
  509. source: "visitClassReferenceNode: aNode\x0a\x09^ self visitVariableNode: aNode",
  510. messageSends: ["visitVariableNode:"],
  511. referencedClasses: []
  512. }),
  513. smalltalk.NodeVisitor);
  514. smalltalk.addMethod(
  515. "_visitDynamicArrayNode_",
  516. smalltalk.method({
  517. selector: "visitDynamicArrayNode:",
  518. category: 'visiting',
  519. fn: function (aNode){
  520. var self=this;
  521. return smalltalk.withContext(function($ctx1) { var $1;
  522. $1=_st(self)._visitNode_(aNode);
  523. return $1;
  524. }, function($ctx1) {$ctx1.fill(self,"visitDynamicArrayNode:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  525. args: ["aNode"],
  526. source: "visitDynamicArrayNode: aNode\x0a\x09^ self visitNode: aNode",
  527. messageSends: ["visitNode:"],
  528. referencedClasses: []
  529. }),
  530. smalltalk.NodeVisitor);
  531. smalltalk.addMethod(
  532. "_visitDynamicDictionaryNode_",
  533. smalltalk.method({
  534. selector: "visitDynamicDictionaryNode:",
  535. category: 'visiting',
  536. fn: function (aNode){
  537. var self=this;
  538. return smalltalk.withContext(function($ctx1) { var $1;
  539. $1=_st(self)._visitNode_(aNode);
  540. return $1;
  541. }, function($ctx1) {$ctx1.fill(self,"visitDynamicDictionaryNode:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  542. args: ["aNode"],
  543. source: "visitDynamicDictionaryNode: aNode\x0a\x09^ self visitNode: aNode",
  544. messageSends: ["visitNode:"],
  545. referencedClasses: []
  546. }),
  547. smalltalk.NodeVisitor);
  548. smalltalk.addMethod(
  549. "_visitJSStatementNode_",
  550. smalltalk.method({
  551. selector: "visitJSStatementNode:",
  552. category: 'visiting',
  553. fn: function (aNode){
  554. var self=this;
  555. return smalltalk.withContext(function($ctx1) { var $1;
  556. $1=_st(self)._visitNode_(aNode);
  557. return $1;
  558. }, function($ctx1) {$ctx1.fill(self,"visitJSStatementNode:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  559. args: ["aNode"],
  560. source: "visitJSStatementNode: aNode\x0a\x09^ self visitNode: aNode",
  561. messageSends: ["visitNode:"],
  562. referencedClasses: []
  563. }),
  564. smalltalk.NodeVisitor);
  565. smalltalk.addMethod(
  566. "_visitMethodNode_",
  567. smalltalk.method({
  568. selector: "visitMethodNode:",
  569. category: 'visiting',
  570. fn: function (aNode){
  571. var self=this;
  572. return smalltalk.withContext(function($ctx1) { var $1;
  573. $1=_st(self)._visitNode_(aNode);
  574. return $1;
  575. }, function($ctx1) {$ctx1.fill(self,"visitMethodNode:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  576. args: ["aNode"],
  577. source: "visitMethodNode: aNode\x0a\x09^ self visitNode: aNode",
  578. messageSends: ["visitNode:"],
  579. referencedClasses: []
  580. }),
  581. smalltalk.NodeVisitor);
  582. smalltalk.addMethod(
  583. "_visitNode_",
  584. smalltalk.method({
  585. selector: "visitNode:",
  586. category: 'visiting',
  587. fn: function (aNode){
  588. var self=this;
  589. return smalltalk.withContext(function($ctx1) { var $1;
  590. $1=_st(self)._visitAll_(_st(aNode)._nodes());
  591. return $1;
  592. }, function($ctx1) {$ctx1.fill(self,"visitNode:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  593. args: ["aNode"],
  594. source: "visitNode: aNode\x0a\x09^ self visitAll: aNode nodes",
  595. messageSends: ["visitAll:", "nodes"],
  596. referencedClasses: []
  597. }),
  598. smalltalk.NodeVisitor);
  599. smalltalk.addMethod(
  600. "_visitReturnNode_",
  601. smalltalk.method({
  602. selector: "visitReturnNode:",
  603. category: 'visiting',
  604. fn: function (aNode){
  605. var self=this;
  606. return smalltalk.withContext(function($ctx1) { var $1;
  607. $1=_st(self)._visitNode_(aNode);
  608. return $1;
  609. }, function($ctx1) {$ctx1.fill(self,"visitReturnNode:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  610. args: ["aNode"],
  611. source: "visitReturnNode: aNode\x0a\x09^ self visitNode: aNode",
  612. messageSends: ["visitNode:"],
  613. referencedClasses: []
  614. }),
  615. smalltalk.NodeVisitor);
  616. smalltalk.addMethod(
  617. "_visitSendNode_",
  618. smalltalk.method({
  619. selector: "visitSendNode:",
  620. category: 'visiting',
  621. fn: function (aNode){
  622. var self=this;
  623. return smalltalk.withContext(function($ctx1) { var $1;
  624. $1=_st(self)._visitNode_(aNode);
  625. return $1;
  626. }, function($ctx1) {$ctx1.fill(self,"visitSendNode:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  627. args: ["aNode"],
  628. source: "visitSendNode: aNode\x0a\x09^ self visitNode: aNode",
  629. messageSends: ["visitNode:"],
  630. referencedClasses: []
  631. }),
  632. smalltalk.NodeVisitor);
  633. smalltalk.addMethod(
  634. "_visitSequenceNode_",
  635. smalltalk.method({
  636. selector: "visitSequenceNode:",
  637. category: 'visiting',
  638. fn: function (aNode){
  639. var self=this;
  640. return smalltalk.withContext(function($ctx1) { var $1;
  641. $1=_st(self)._visitNode_(aNode);
  642. return $1;
  643. }, function($ctx1) {$ctx1.fill(self,"visitSequenceNode:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  644. args: ["aNode"],
  645. source: "visitSequenceNode: aNode\x0a\x09^ self visitNode: aNode",
  646. messageSends: ["visitNode:"],
  647. referencedClasses: []
  648. }),
  649. smalltalk.NodeVisitor);
  650. smalltalk.addMethod(
  651. "_visitValueNode_",
  652. smalltalk.method({
  653. selector: "visitValueNode:",
  654. category: 'visiting',
  655. fn: function (aNode){
  656. var self=this;
  657. return smalltalk.withContext(function($ctx1) { var $1;
  658. $1=_st(self)._visitNode_(aNode);
  659. return $1;
  660. }, function($ctx1) {$ctx1.fill(self,"visitValueNode:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  661. args: ["aNode"],
  662. source: "visitValueNode: aNode\x0a\x09^ self visitNode: aNode",
  663. messageSends: ["visitNode:"],
  664. referencedClasses: []
  665. }),
  666. smalltalk.NodeVisitor);
  667. smalltalk.addMethod(
  668. "_visitVariableNode_",
  669. smalltalk.method({
  670. selector: "visitVariableNode:",
  671. category: 'visiting',
  672. fn: function (aNode){
  673. var self=this;
  674. return smalltalk.withContext(function($ctx1) { var $1;
  675. $1=_st(self)._visitNode_(aNode);
  676. return $1;
  677. }, function($ctx1) {$ctx1.fill(self,"visitVariableNode:",{aNode:aNode}, smalltalk.NodeVisitor)})},
  678. args: ["aNode"],
  679. source: "visitVariableNode: aNode\x0a\x09^ self visitNode: aNode",
  680. messageSends: ["visitNode:"],
  681. referencedClasses: []
  682. }),
  683. smalltalk.NodeVisitor);
  684. smalltalk.addClass('AbstractCodeGenerator', smalltalk.NodeVisitor, ['currentClass', 'source'], 'Compiler-Core');
  685. smalltalk.AbstractCodeGenerator.comment="I am the abstract super class of all code generators and provide their common API."
  686. smalltalk.addMethod(
  687. "_classNameFor_",
  688. smalltalk.method({
  689. selector: "classNameFor:",
  690. category: 'accessing',
  691. fn: function (aClass){
  692. var self=this;
  693. return smalltalk.withContext(function($ctx1) { var $2,$3,$1;
  694. $2=_st(aClass)._isMetaclass();
  695. if(smalltalk.assert($2)){
  696. $1=_st(_st(_st(aClass)._instanceClass())._name()).__comma(".klass");
  697. } else {
  698. $3=_st(aClass)._isNil();
  699. if(smalltalk.assert($3)){
  700. $1="nil";
  701. } else {
  702. $1=_st(aClass)._name();
  703. };
  704. };
  705. return $1;
  706. }, function($ctx1) {$ctx1.fill(self,"classNameFor:",{aClass:aClass}, smalltalk.AbstractCodeGenerator)})},
  707. args: ["aClass"],
  708. source: "classNameFor: aClass\x0a\x09^aClass isMetaclass\x0a\x09 ifTrue: [aClass instanceClass name, '.klass']\x0a\x09 ifFalse: [\x0a\x09\x09aClass isNil\x0a\x09\x09 ifTrue: ['nil']\x0a\x09\x09 ifFalse: [aClass name]]",
  709. messageSends: ["ifTrue:ifFalse:", ",", "name", "instanceClass", "isNil", "isMetaclass"],
  710. referencedClasses: []
  711. }),
  712. smalltalk.AbstractCodeGenerator);
  713. smalltalk.addMethod(
  714. "_compileNode_",
  715. smalltalk.method({
  716. selector: "compileNode:",
  717. category: 'compiling',
  718. fn: function (aNode){
  719. var self=this;
  720. return smalltalk.withContext(function($ctx1) { _st(self)._subclassResponsibility();
  721. return self}, function($ctx1) {$ctx1.fill(self,"compileNode:",{aNode:aNode}, smalltalk.AbstractCodeGenerator)})},
  722. args: ["aNode"],
  723. source: "compileNode: aNode\x0a\x09self subclassResponsibility",
  724. messageSends: ["subclassResponsibility"],
  725. referencedClasses: []
  726. }),
  727. smalltalk.AbstractCodeGenerator);
  728. smalltalk.addMethod(
  729. "_currentClass",
  730. smalltalk.method({
  731. selector: "currentClass",
  732. category: 'accessing',
  733. fn: function (){
  734. var self=this;
  735. return smalltalk.withContext(function($ctx1) { var $1;
  736. $1=self["@currentClass"];
  737. return $1;
  738. }, function($ctx1) {$ctx1.fill(self,"currentClass",{}, smalltalk.AbstractCodeGenerator)})},
  739. args: [],
  740. source: "currentClass\x0a\x09^currentClass",
  741. messageSends: [],
  742. referencedClasses: []
  743. }),
  744. smalltalk.AbstractCodeGenerator);
  745. smalltalk.addMethod(
  746. "_currentClass_",
  747. smalltalk.method({
  748. selector: "currentClass:",
  749. category: 'accessing',
  750. fn: function (aClass){
  751. var self=this;
  752. return smalltalk.withContext(function($ctx1) { self["@currentClass"]=aClass;
  753. return self}, function($ctx1) {$ctx1.fill(self,"currentClass:",{aClass:aClass}, smalltalk.AbstractCodeGenerator)})},
  754. args: ["aClass"],
  755. source: "currentClass: aClass\x0a\x09currentClass := aClass",
  756. messageSends: [],
  757. referencedClasses: []
  758. }),
  759. smalltalk.AbstractCodeGenerator);
  760. smalltalk.addMethod(
  761. "_pseudoVariables",
  762. smalltalk.method({
  763. selector: "pseudoVariables",
  764. category: 'accessing',
  765. fn: function (){
  766. var self=this;
  767. return smalltalk.withContext(function($ctx1) { return ["self", "super", "true", "false", "nil", "thisContext"];
  768. }, function($ctx1) {$ctx1.fill(self,"pseudoVariables",{}, smalltalk.AbstractCodeGenerator)})},
  769. args: [],
  770. source: "pseudoVariables\x0a\x09^#('self' 'super' 'true' 'false' 'nil' 'thisContext')",
  771. messageSends: [],
  772. referencedClasses: []
  773. }),
  774. smalltalk.AbstractCodeGenerator);
  775. smalltalk.addMethod(
  776. "_safeVariableNameFor_",
  777. smalltalk.method({
  778. selector: "safeVariableNameFor:",
  779. category: 'accessing',
  780. fn: function (aString){
  781. var self=this;
  782. return smalltalk.withContext(function($ctx1) { var $2,$1;
  783. $2=_st(_st(_st((smalltalk.Smalltalk || Smalltalk))._current())._reservedWords())._includes_(aString);
  784. if(smalltalk.assert($2)){
  785. $1=_st(aString).__comma("_");
  786. } else {
  787. $1=aString;
  788. };
  789. return $1;
  790. }, function($ctx1) {$ctx1.fill(self,"safeVariableNameFor:",{aString:aString}, smalltalk.AbstractCodeGenerator)})},
  791. args: ["aString"],
  792. source: "safeVariableNameFor: aString\x0a\x09^(Smalltalk current reservedWords includes: aString)\x0a\x09\x09ifTrue: [aString, '_']\x0a\x09\x09ifFalse: [aString]",
  793. messageSends: ["ifTrue:ifFalse:", ",", "includes:", "reservedWords", "current"],
  794. referencedClasses: ["Smalltalk"]
  795. }),
  796. smalltalk.AbstractCodeGenerator);
  797. smalltalk.addMethod(
  798. "_source",
  799. smalltalk.method({
  800. selector: "source",
  801. category: 'accessing',
  802. fn: function (){
  803. var self=this;
  804. return smalltalk.withContext(function($ctx1) { var $2,$1;
  805. $2=self["@source"];
  806. if(($receiver = $2) == nil || $receiver == undefined){
  807. $1="";
  808. } else {
  809. $1=$2;
  810. };
  811. return $1;
  812. }, function($ctx1) {$ctx1.fill(self,"source",{}, smalltalk.AbstractCodeGenerator)})},
  813. args: [],
  814. source: "source\x0a\x09^source ifNil: ['']",
  815. messageSends: ["ifNil:"],
  816. referencedClasses: []
  817. }),
  818. smalltalk.AbstractCodeGenerator);
  819. smalltalk.addMethod(
  820. "_source_",
  821. smalltalk.method({
  822. selector: "source:",
  823. category: 'accessing',
  824. fn: function (aString){
  825. var self=this;
  826. return smalltalk.withContext(function($ctx1) { self["@source"]=aString;
  827. return self}, function($ctx1) {$ctx1.fill(self,"source:",{aString:aString}, smalltalk.AbstractCodeGenerator)})},
  828. args: ["aString"],
  829. source: "source: aString\x0a\x09source := aString",
  830. messageSends: [],
  831. referencedClasses: []
  832. }),
  833. smalltalk.AbstractCodeGenerator);
  834. smalltalk.addClass('CodeGenerator', smalltalk.AbstractCodeGenerator, [], 'Compiler-Core');
  835. smalltalk.CodeGenerator.comment="I am a basic code generator. I generate a valid JavaScript output, but no not perform any inlining.\x0aSee `InliningCodeGenerator` for an optimized JavaScript code generation."
  836. smalltalk.addMethod(
  837. "_compileNode_",
  838. smalltalk.method({
  839. selector: "compileNode:",
  840. category: 'compiling',
  841. fn: function (aNode){
  842. var self=this;
  843. var ir,stream;
  844. return smalltalk.withContext(function($ctx1) { var $2,$3,$1;
  845. _st(_st(self)._semanticAnalyzer())._visit_(aNode);
  846. ir=_st(_st(self)._translator())._visit_(aNode);
  847. $2=_st(self)._irTranslator();
  848. _st($2)._visit_(ir);
  849. $3=_st($2)._contents();
  850. $1=$3;
  851. return $1;
  852. }, function($ctx1) {$ctx1.fill(self,"compileNode:",{aNode:aNode,ir:ir,stream:stream}, smalltalk.CodeGenerator)})},
  853. args: ["aNode"],
  854. source: "compileNode: aNode\x0a\x09| ir stream |\x0a\x09self semanticAnalyzer visit: aNode.\x0a\x09ir := self translator visit: aNode.\x0a\x09^ self irTranslator\x0a\x09\x09visit: ir;\x0a\x09\x09contents",
  855. messageSends: ["visit:", "semanticAnalyzer", "translator", "irTranslator", "contents"],
  856. referencedClasses: []
  857. }),
  858. smalltalk.CodeGenerator);
  859. smalltalk.addMethod(
  860. "_irTranslator",
  861. smalltalk.method({
  862. selector: "irTranslator",
  863. category: 'compiling',
  864. fn: function (){
  865. var self=this;
  866. return smalltalk.withContext(function($ctx1) { var $1;
  867. $1=_st((smalltalk.IRJSTranslator || IRJSTranslator))._new();
  868. return $1;
  869. }, function($ctx1) {$ctx1.fill(self,"irTranslator",{}, smalltalk.CodeGenerator)})},
  870. args: [],
  871. source: "irTranslator\x0a\x09^ IRJSTranslator new",
  872. messageSends: ["new"],
  873. referencedClasses: ["IRJSTranslator"]
  874. }),
  875. smalltalk.CodeGenerator);
  876. smalltalk.addMethod(
  877. "_semanticAnalyzer",
  878. smalltalk.method({
  879. selector: "semanticAnalyzer",
  880. category: 'compiling',
  881. fn: function (){
  882. var self=this;
  883. return smalltalk.withContext(function($ctx1) { var $1;
  884. $1=_st((smalltalk.SemanticAnalyzer || SemanticAnalyzer))._on_(_st(self)._currentClass());
  885. return $1;
  886. }, function($ctx1) {$ctx1.fill(self,"semanticAnalyzer",{}, smalltalk.CodeGenerator)})},
  887. args: [],
  888. source: "semanticAnalyzer\x0a\x09^ SemanticAnalyzer on: self currentClass",
  889. messageSends: ["on:", "currentClass"],
  890. referencedClasses: ["SemanticAnalyzer"]
  891. }),
  892. smalltalk.CodeGenerator);
  893. smalltalk.addMethod(
  894. "_translator",
  895. smalltalk.method({
  896. selector: "translator",
  897. category: 'compiling',
  898. fn: function (){
  899. var self=this;
  900. return smalltalk.withContext(function($ctx1) { var $2,$3,$1;
  901. $2=_st((smalltalk.IRASTTranslator || IRASTTranslator))._new();
  902. _st($2)._source_(_st(self)._source());
  903. _st($2)._theClass_(_st(self)._currentClass());
  904. $3=_st($2)._yourself();
  905. $1=$3;
  906. return $1;
  907. }, function($ctx1) {$ctx1.fill(self,"translator",{}, smalltalk.CodeGenerator)})},
  908. args: [],
  909. source: "translator\x0a\x09^ IRASTTranslator new\x0a\x09\x09source: self source;\x0a\x09\x09theClass: self currentClass;\x0a\x09\x09yourself",
  910. messageSends: ["source:", "source", "new", "theClass:", "currentClass", "yourself"],
  911. referencedClasses: ["IRASTTranslator"]
  912. }),
  913. smalltalk.CodeGenerator);