Compiler-Core.js 32 KB

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