Compiler-Core.js 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034
  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.addMethod(
  650. smalltalk.method({
  651. selector: "foo",
  652. protocol: 'tests',
  653. fn: function (){
  654. var self=this;
  655. function $Array(){return globals.Array||(typeof Array=="undefined"?nil:Array)}
  656. return smalltalk.withContext(function($ctx1) {
  657. var $2,$3,$1;
  658. $2=_st($Array())._new();
  659. _st($2)._add_((3));
  660. $ctx1.sendIdx["add:"]=1;
  661. _st($2)._add_((4));
  662. $3=_st($2)._yourself();
  663. $1=$3;
  664. return $1;
  665. }, function($ctx1) {$ctx1.fill(self,"foo",{},globals.DoIt)})},
  666. args: [],
  667. source: "foo ^ Array new add: 3; add: 4; yourself",
  668. messageSends: ["add:", "new", "yourself"],
  669. referencedClasses: ["Array"]
  670. }),
  671. globals.DoIt);
  672. smalltalk.addClass('NodeVisitor', globals.Object, [], 'Compiler-Core');
  673. globals.NodeVisitor.comment="I am the abstract super class of all AST node visitors.";
  674. smalltalk.addMethod(
  675. smalltalk.method({
  676. selector: "visit:",
  677. protocol: 'visiting',
  678. fn: function (aNode){
  679. var self=this;
  680. return smalltalk.withContext(function($ctx1) {
  681. var $1;
  682. $1=_st(aNode)._accept_(self);
  683. return $1;
  684. }, function($ctx1) {$ctx1.fill(self,"visit:",{aNode:aNode},globals.NodeVisitor)})},
  685. args: ["aNode"],
  686. source: "visit: aNode\x0a\x09^ aNode accept: self",
  687. messageSends: ["accept:"],
  688. referencedClasses: []
  689. }),
  690. globals.NodeVisitor);
  691. smalltalk.addMethod(
  692. smalltalk.method({
  693. selector: "visitAll:",
  694. protocol: 'visiting',
  695. fn: function (aCollection){
  696. var self=this;
  697. return smalltalk.withContext(function($ctx1) {
  698. var $1;
  699. $1=_st(aCollection)._collect_((function(each){
  700. return smalltalk.withContext(function($ctx2) {
  701. return self._visit_(each);
  702. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  703. return $1;
  704. }, function($ctx1) {$ctx1.fill(self,"visitAll:",{aCollection:aCollection},globals.NodeVisitor)})},
  705. args: ["aCollection"],
  706. source: "visitAll: aCollection\x0a\x09^ aCollection collect: [ :each | self visit: each ]",
  707. messageSends: ["collect:", "visit:"],
  708. referencedClasses: []
  709. }),
  710. globals.NodeVisitor);
  711. smalltalk.addMethod(
  712. smalltalk.method({
  713. selector: "visitAssignmentNode:",
  714. protocol: 'visiting',
  715. fn: function (aNode){
  716. var self=this;
  717. return smalltalk.withContext(function($ctx1) {
  718. var $1;
  719. $1=self._visitNode_(aNode);
  720. return $1;
  721. }, function($ctx1) {$ctx1.fill(self,"visitAssignmentNode:",{aNode:aNode},globals.NodeVisitor)})},
  722. args: ["aNode"],
  723. source: "visitAssignmentNode: aNode\x0a\x09^ self visitNode: aNode",
  724. messageSends: ["visitNode:"],
  725. referencedClasses: []
  726. }),
  727. globals.NodeVisitor);
  728. smalltalk.addMethod(
  729. smalltalk.method({
  730. selector: "visitBlockNode:",
  731. protocol: 'visiting',
  732. fn: function (aNode){
  733. var self=this;
  734. return smalltalk.withContext(function($ctx1) {
  735. var $1;
  736. $1=self._visitNode_(aNode);
  737. return $1;
  738. }, function($ctx1) {$ctx1.fill(self,"visitBlockNode:",{aNode:aNode},globals.NodeVisitor)})},
  739. args: ["aNode"],
  740. source: "visitBlockNode: aNode\x0a\x09^ self visitNode: aNode",
  741. messageSends: ["visitNode:"],
  742. referencedClasses: []
  743. }),
  744. globals.NodeVisitor);
  745. smalltalk.addMethod(
  746. smalltalk.method({
  747. selector: "visitBlockSequenceNode:",
  748. protocol: 'visiting',
  749. fn: function (aNode){
  750. var self=this;
  751. return smalltalk.withContext(function($ctx1) {
  752. var $1;
  753. $1=self._visitSequenceNode_(aNode);
  754. return $1;
  755. }, function($ctx1) {$ctx1.fill(self,"visitBlockSequenceNode:",{aNode:aNode},globals.NodeVisitor)})},
  756. args: ["aNode"],
  757. source: "visitBlockSequenceNode: aNode\x0a\x09^ self visitSequenceNode: aNode",
  758. messageSends: ["visitSequenceNode:"],
  759. referencedClasses: []
  760. }),
  761. globals.NodeVisitor);
  762. smalltalk.addMethod(
  763. smalltalk.method({
  764. selector: "visitCascadeNode:",
  765. protocol: 'visiting',
  766. fn: function (aNode){
  767. var self=this;
  768. return smalltalk.withContext(function($ctx1) {
  769. var $1;
  770. $1=self._visitNode_(aNode);
  771. return $1;
  772. }, function($ctx1) {$ctx1.fill(self,"visitCascadeNode:",{aNode:aNode},globals.NodeVisitor)})},
  773. args: ["aNode"],
  774. source: "visitCascadeNode: aNode\x0a\x09^ self visitNode: aNode",
  775. messageSends: ["visitNode:"],
  776. referencedClasses: []
  777. }),
  778. globals.NodeVisitor);
  779. smalltalk.addMethod(
  780. smalltalk.method({
  781. selector: "visitDynamicArrayNode:",
  782. protocol: 'visiting',
  783. fn: function (aNode){
  784. var self=this;
  785. return smalltalk.withContext(function($ctx1) {
  786. var $1;
  787. $1=self._visitNode_(aNode);
  788. return $1;
  789. }, function($ctx1) {$ctx1.fill(self,"visitDynamicArrayNode:",{aNode:aNode},globals.NodeVisitor)})},
  790. args: ["aNode"],
  791. source: "visitDynamicArrayNode: aNode\x0a\x09^ self visitNode: aNode",
  792. messageSends: ["visitNode:"],
  793. referencedClasses: []
  794. }),
  795. globals.NodeVisitor);
  796. smalltalk.addMethod(
  797. smalltalk.method({
  798. selector: "visitDynamicDictionaryNode:",
  799. protocol: 'visiting',
  800. fn: function (aNode){
  801. var self=this;
  802. return smalltalk.withContext(function($ctx1) {
  803. var $1;
  804. $1=self._visitNode_(aNode);
  805. return $1;
  806. }, function($ctx1) {$ctx1.fill(self,"visitDynamicDictionaryNode:",{aNode:aNode},globals.NodeVisitor)})},
  807. args: ["aNode"],
  808. source: "visitDynamicDictionaryNode: aNode\x0a\x09^ self visitNode: aNode",
  809. messageSends: ["visitNode:"],
  810. referencedClasses: []
  811. }),
  812. globals.NodeVisitor);
  813. smalltalk.addMethod(
  814. smalltalk.method({
  815. selector: "visitJSStatementNode:",
  816. protocol: 'visiting',
  817. fn: function (aNode){
  818. var self=this;
  819. return smalltalk.withContext(function($ctx1) {
  820. var $1;
  821. $1=self._visitNode_(aNode);
  822. return $1;
  823. }, function($ctx1) {$ctx1.fill(self,"visitJSStatementNode:",{aNode:aNode},globals.NodeVisitor)})},
  824. args: ["aNode"],
  825. source: "visitJSStatementNode: aNode\x0a\x09^ self visitNode: aNode",
  826. messageSends: ["visitNode:"],
  827. referencedClasses: []
  828. }),
  829. globals.NodeVisitor);
  830. smalltalk.addMethod(
  831. smalltalk.method({
  832. selector: "visitMethodNode:",
  833. protocol: 'visiting',
  834. fn: function (aNode){
  835. var self=this;
  836. return smalltalk.withContext(function($ctx1) {
  837. var $1;
  838. $1=self._visitNode_(aNode);
  839. return $1;
  840. }, function($ctx1) {$ctx1.fill(self,"visitMethodNode:",{aNode:aNode},globals.NodeVisitor)})},
  841. args: ["aNode"],
  842. source: "visitMethodNode: aNode\x0a\x09^ self visitNode: aNode",
  843. messageSends: ["visitNode:"],
  844. referencedClasses: []
  845. }),
  846. globals.NodeVisitor);
  847. smalltalk.addMethod(
  848. smalltalk.method({
  849. selector: "visitNode:",
  850. protocol: 'visiting',
  851. fn: function (aNode){
  852. var self=this;
  853. return smalltalk.withContext(function($ctx1) {
  854. var $1;
  855. $1=self._visitAll_(_st(aNode)._nodes());
  856. return $1;
  857. }, function($ctx1) {$ctx1.fill(self,"visitNode:",{aNode:aNode},globals.NodeVisitor)})},
  858. args: ["aNode"],
  859. source: "visitNode: aNode\x0a\x09^ self visitAll: aNode nodes",
  860. messageSends: ["visitAll:", "nodes"],
  861. referencedClasses: []
  862. }),
  863. globals.NodeVisitor);
  864. smalltalk.addMethod(
  865. smalltalk.method({
  866. selector: "visitReturnNode:",
  867. protocol: 'visiting',
  868. fn: function (aNode){
  869. var self=this;
  870. return smalltalk.withContext(function($ctx1) {
  871. var $1;
  872. $1=self._visitNode_(aNode);
  873. return $1;
  874. }, function($ctx1) {$ctx1.fill(self,"visitReturnNode:",{aNode:aNode},globals.NodeVisitor)})},
  875. args: ["aNode"],
  876. source: "visitReturnNode: aNode\x0a\x09^ self visitNode: aNode",
  877. messageSends: ["visitNode:"],
  878. referencedClasses: []
  879. }),
  880. globals.NodeVisitor);
  881. smalltalk.addMethod(
  882. smalltalk.method({
  883. selector: "visitSendNode:",
  884. protocol: 'visiting',
  885. fn: function (aNode){
  886. var self=this;
  887. return smalltalk.withContext(function($ctx1) {
  888. var $1;
  889. $1=self._visitNode_(aNode);
  890. return $1;
  891. }, function($ctx1) {$ctx1.fill(self,"visitSendNode:",{aNode:aNode},globals.NodeVisitor)})},
  892. args: ["aNode"],
  893. source: "visitSendNode: aNode\x0a\x09^ self visitNode: aNode",
  894. messageSends: ["visitNode:"],
  895. referencedClasses: []
  896. }),
  897. globals.NodeVisitor);
  898. smalltalk.addMethod(
  899. smalltalk.method({
  900. selector: "visitSequenceNode:",
  901. protocol: 'visiting',
  902. fn: function (aNode){
  903. var self=this;
  904. return smalltalk.withContext(function($ctx1) {
  905. var $1;
  906. $1=self._visitNode_(aNode);
  907. return $1;
  908. }, function($ctx1) {$ctx1.fill(self,"visitSequenceNode:",{aNode:aNode},globals.NodeVisitor)})},
  909. args: ["aNode"],
  910. source: "visitSequenceNode: aNode\x0a\x09^ self visitNode: aNode",
  911. messageSends: ["visitNode:"],
  912. referencedClasses: []
  913. }),
  914. globals.NodeVisitor);
  915. smalltalk.addMethod(
  916. smalltalk.method({
  917. selector: "visitValueNode:",
  918. protocol: 'visiting',
  919. fn: function (aNode){
  920. var self=this;
  921. return smalltalk.withContext(function($ctx1) {
  922. var $1;
  923. $1=self._visitNode_(aNode);
  924. return $1;
  925. }, function($ctx1) {$ctx1.fill(self,"visitValueNode:",{aNode:aNode},globals.NodeVisitor)})},
  926. args: ["aNode"],
  927. source: "visitValueNode: aNode\x0a\x09^ self visitNode: aNode",
  928. messageSends: ["visitNode:"],
  929. referencedClasses: []
  930. }),
  931. globals.NodeVisitor);
  932. smalltalk.addMethod(
  933. smalltalk.method({
  934. selector: "visitVariableNode:",
  935. protocol: 'visiting',
  936. fn: function (aNode){
  937. var self=this;
  938. return smalltalk.withContext(function($ctx1) {
  939. var $1;
  940. $1=self._visitNode_(aNode);
  941. return $1;
  942. }, function($ctx1) {$ctx1.fill(self,"visitVariableNode:",{aNode:aNode},globals.NodeVisitor)})},
  943. args: ["aNode"],
  944. source: "visitVariableNode: aNode\x0a\x09^ self visitNode: aNode",
  945. messageSends: ["visitNode:"],
  946. referencedClasses: []
  947. }),
  948. globals.NodeVisitor);
  949. smalltalk.addMethod(
  950. smalltalk.method({
  951. selector: "asVariableName",
  952. protocol: '*Compiler-Core',
  953. fn: function (){
  954. var self=this;
  955. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  956. return smalltalk.withContext(function($ctx1) {
  957. var $2,$1;
  958. $2=_st(_st($Smalltalk())._reservedWords())._includes_(self);
  959. if(smalltalk.assert($2)){
  960. $1=self.__comma("_");
  961. } else {
  962. $1=self;
  963. };
  964. return $1;
  965. }, function($ctx1) {$ctx1.fill(self,"asVariableName",{},globals.String)})},
  966. args: [],
  967. source: "asVariableName\x0a\x09^ (Smalltalk reservedWords includes: self)\x0a\x09\x09ifTrue: [ self, '_' ]\x0a\x09\x09ifFalse: [ self ]",
  968. messageSends: ["ifTrue:ifFalse:", "includes:", "reservedWords", ","],
  969. referencedClasses: ["Smalltalk"]
  970. }),
  971. globals.String);
  972. });