Compiler-Core.js 33 KB

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