Compiler-Core.js 30 KB

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