Compiler-Core.js 32 KB

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