2
0

Compiler-Core.js 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033
  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 eval(aString);
  399. return self},
  400. args: ["aString"],
  401. source: "eval: aString\x0a\x09<return eval(aString)>",
  402. messageSends: [],
  403. referencedClasses: []
  404. }),
  405. globals.Compiler);
  406. smalltalk.addMethod(
  407. smalltalk.method({
  408. selector: "evaluateExpression:",
  409. protocol: 'compiling',
  410. fn: function (aString){
  411. var self=this;
  412. function $DoIt(){return globals.DoIt||(typeof DoIt=="undefined"?nil:DoIt)}
  413. return smalltalk.withContext(function($ctx1) {
  414. var $1;
  415. $1=self._evaluateExpression_on_(aString,_st($DoIt())._new());
  416. return $1;
  417. }, function($ctx1) {$ctx1.fill(self,"evaluateExpression:",{aString:aString},globals.Compiler)})},
  418. args: ["aString"],
  419. 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",
  420. messageSends: ["evaluateExpression:on:", "new"],
  421. referencedClasses: ["DoIt"]
  422. }),
  423. globals.Compiler);
  424. smalltalk.addMethod(
  425. smalltalk.method({
  426. selector: "evaluateExpression:on:",
  427. protocol: 'compiling',
  428. fn: function (aString,anObject){
  429. var self=this;
  430. var result,method;
  431. return smalltalk.withContext(function($ctx1) {
  432. var $1,$2;
  433. method=self._eval_(self._compileExpression_on_(aString,anObject));
  434. _st(method)._protocol_("xxxDoIt");
  435. $1=_st(anObject)._class();
  436. $ctx1.sendIdx["class"]=1;
  437. _st($1)._addCompiledMethod_(method);
  438. result=_st(anObject)._xxxDoIt();
  439. _st(_st(anObject)._class())._removeCompiledMethod_(method);
  440. $2=result;
  441. return $2;
  442. }, function($ctx1) {$ctx1.fill(self,"evaluateExpression:on:",{aString:aString,anObject:anObject,result:result,method:method},globals.Compiler)})},
  443. args: ["aString", "anObject"],
  444. 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",
  445. messageSends: ["eval:", "compileExpression:on:", "protocol:", "addCompiledMethod:", "class", "xxxDoIt", "removeCompiledMethod:"],
  446. referencedClasses: []
  447. }),
  448. globals.Compiler);
  449. smalltalk.addMethod(
  450. smalltalk.method({
  451. selector: "install:forClass:protocol:",
  452. protocol: 'compiling',
  453. fn: function (aString,aBehavior,anotherString){
  454. var self=this;
  455. function $ClassBuilder(){return globals.ClassBuilder||(typeof ClassBuilder=="undefined"?nil:ClassBuilder)}
  456. return smalltalk.withContext(function($ctx1) {
  457. var $1;
  458. $1=_st(_st($ClassBuilder())._new())._installMethod_forClass_protocol_(self._eval_(self._compile_forClass_(aString,aBehavior)),aBehavior,anotherString);
  459. return $1;
  460. }, function($ctx1) {$ctx1.fill(self,"install:forClass:protocol:",{aString:aString,aBehavior:aBehavior,anotherString:anotherString},globals.Compiler)})},
  461. args: ["aString", "aBehavior", "anotherString"],
  462. 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",
  463. messageSends: ["installMethod:forClass:protocol:", "new", "eval:", "compile:forClass:"],
  464. referencedClasses: ["ClassBuilder"]
  465. }),
  466. globals.Compiler);
  467. smalltalk.addMethod(
  468. smalltalk.method({
  469. selector: "parse:",
  470. protocol: 'compiling',
  471. fn: function (aString){
  472. var self=this;
  473. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  474. return smalltalk.withContext(function($ctx1) {
  475. var $1;
  476. $1=_st($Smalltalk())._parse_(aString);
  477. return $1;
  478. }, function($ctx1) {$ctx1.fill(self,"parse:",{aString:aString},globals.Compiler)})},
  479. args: ["aString"],
  480. source: "parse: aString\x0a\x09^ Smalltalk parse: aString",
  481. messageSends: ["parse:"],
  482. referencedClasses: ["Smalltalk"]
  483. }),
  484. globals.Compiler);
  485. smalltalk.addMethod(
  486. smalltalk.method({
  487. selector: "parseExpression:",
  488. protocol: 'compiling',
  489. fn: function (aString){
  490. var self=this;
  491. return smalltalk.withContext(function($ctx1) {
  492. var $2,$1;
  493. $2=_st("doIt ^ [ ".__comma(aString)).__comma(" ] value");
  494. $ctx1.sendIdx[","]=1;
  495. $1=self._parse_($2);
  496. return $1;
  497. }, function($ctx1) {$ctx1.fill(self,"parseExpression:",{aString:aString},globals.Compiler)})},
  498. args: ["aString"],
  499. source: "parseExpression: aString\x0a\x09^ self parse: 'doIt ^ [ ', aString, ' ] value'",
  500. messageSends: ["parse:", ","],
  501. referencedClasses: []
  502. }),
  503. globals.Compiler);
  504. smalltalk.addMethod(
  505. smalltalk.method({
  506. selector: "recompile:",
  507. protocol: 'compiling',
  508. fn: function (aClass){
  509. var self=this;
  510. return smalltalk.withContext(function($ctx1) {
  511. var $1;
  512. _st(_st(_st(aClass)._methodDictionary())._values())._do_displayingProgress_((function(each){
  513. return smalltalk.withContext(function($ctx2) {
  514. return self._install_forClass_protocol_(_st(each)._source(),aClass,_st(each)._protocol());
  515. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}),"Recompiling ".__comma(_st(aClass)._name()));
  516. $1=_st(aClass)._isMetaclass();
  517. if(! smalltalk.assert($1)){
  518. self._recompile_(_st(aClass)._class());
  519. };
  520. return self}, function($ctx1) {$ctx1.fill(self,"recompile:",{aClass:aClass},globals.Compiler)})},
  521. args: ["aClass"],
  522. 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 ]",
  523. messageSends: ["do:displayingProgress:", "values", "methodDictionary", "install:forClass:protocol:", "source", "protocol", ",", "name", "ifFalse:", "isMetaclass", "recompile:", "class"],
  524. referencedClasses: []
  525. }),
  526. globals.Compiler);
  527. smalltalk.addMethod(
  528. smalltalk.method({
  529. selector: "recompileAll",
  530. protocol: 'compiling',
  531. fn: function (){
  532. var self=this;
  533. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  534. return smalltalk.withContext(function($ctx1) {
  535. _st(_st($Smalltalk())._classes())._do_displayingProgress_((function(each){
  536. return smalltalk.withContext(function($ctx2) {
  537. return self._recompile_(each);
  538. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}),"Compiling all classes...");
  539. return self}, function($ctx1) {$ctx1.fill(self,"recompileAll",{},globals.Compiler)})},
  540. args: [],
  541. source: "recompileAll\x0a\x09Smalltalk classes \x0a\x09\x09do: [ :each | self recompile: each ]\x0a\x09\x09displayingProgress: 'Compiling all classes...'",
  542. messageSends: ["do:displayingProgress:", "classes", "recompile:"],
  543. referencedClasses: ["Smalltalk"]
  544. }),
  545. globals.Compiler);
  546. smalltalk.addMethod(
  547. smalltalk.method({
  548. selector: "source",
  549. protocol: 'accessing',
  550. fn: function (){
  551. var self=this;
  552. return smalltalk.withContext(function($ctx1) {
  553. var $2,$1;
  554. $2=self["@source"];
  555. if(($receiver = $2) == nil || $receiver == null){
  556. $1="";
  557. } else {
  558. $1=$2;
  559. };
  560. return $1;
  561. }, function($ctx1) {$ctx1.fill(self,"source",{},globals.Compiler)})},
  562. args: [],
  563. source: "source\x0a\x09^ source ifNil: [ '' ]",
  564. messageSends: ["ifNil:"],
  565. referencedClasses: []
  566. }),
  567. globals.Compiler);
  568. smalltalk.addMethod(
  569. smalltalk.method({
  570. selector: "source:",
  571. protocol: 'accessing',
  572. fn: function (aString){
  573. var self=this;
  574. self["@source"]=aString;
  575. return self},
  576. args: ["aString"],
  577. source: "source: aString\x0a\x09source := aString",
  578. messageSends: [],
  579. referencedClasses: []
  580. }),
  581. globals.Compiler);
  582. smalltalk.addMethod(
  583. smalltalk.method({
  584. selector: "unknownVariables",
  585. protocol: 'accessing',
  586. fn: function (){
  587. var self=this;
  588. var $1;
  589. $1=self["@unknownVariables"];
  590. return $1;
  591. },
  592. args: [],
  593. source: "unknownVariables\x0a\x09^ unknownVariables",
  594. messageSends: [],
  595. referencedClasses: []
  596. }),
  597. globals.Compiler);
  598. smalltalk.addMethod(
  599. smalltalk.method({
  600. selector: "unknownVariables:",
  601. protocol: 'accessing',
  602. fn: function (aCollection){
  603. var self=this;
  604. self["@unknownVariables"]=aCollection;
  605. return self},
  606. args: ["aCollection"],
  607. source: "unknownVariables: aCollection\x0a\x09unknownVariables := aCollection",
  608. messageSends: [],
  609. referencedClasses: []
  610. }),
  611. globals.Compiler);
  612. smalltalk.addMethod(
  613. smalltalk.method({
  614. selector: "recompile:",
  615. protocol: 'compiling',
  616. fn: function (aClass){
  617. var self=this;
  618. return smalltalk.withContext(function($ctx1) {
  619. _st(self._new())._recompile_(aClass);
  620. return self}, function($ctx1) {$ctx1.fill(self,"recompile:",{aClass:aClass},globals.Compiler.klass)})},
  621. args: ["aClass"],
  622. source: "recompile: aClass\x0a\x09self new recompile: aClass",
  623. messageSends: ["recompile:", "new"],
  624. referencedClasses: []
  625. }),
  626. globals.Compiler.klass);
  627. smalltalk.addMethod(
  628. smalltalk.method({
  629. selector: "recompileAll",
  630. protocol: 'compiling',
  631. fn: function (){
  632. var self=this;
  633. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  634. return smalltalk.withContext(function($ctx1) {
  635. _st(_st($Smalltalk())._classes())._do_((function(each){
  636. return smalltalk.withContext(function($ctx2) {
  637. return self._recompile_(each);
  638. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  639. return self}, function($ctx1) {$ctx1.fill(self,"recompileAll",{},globals.Compiler.klass)})},
  640. args: [],
  641. source: "recompileAll\x0a\x09Smalltalk classes do: [ :each |\x0a\x09\x09self recompile: each ]",
  642. messageSends: ["do:", "classes", "recompile:"],
  643. referencedClasses: ["Smalltalk"]
  644. }),
  645. globals.Compiler.klass);
  646. smalltalk.addClass('DoIt', globals.Object, [], 'Compiler-Core');
  647. globals.DoIt.comment="`DoIt` is the class used to compile and evaluate expressions. See `Compiler >> evaluateExpression:`.";
  648. smalltalk.addMethod(
  649. smalltalk.method({
  650. selector: "foo",
  651. protocol: 'tests',
  652. fn: function (){
  653. var self=this;
  654. function $Array(){return globals.Array||(typeof Array=="undefined"?nil:Array)}
  655. return smalltalk.withContext(function($ctx1) {
  656. var $2,$3,$1;
  657. $2=_st($Array())._new();
  658. _st($2)._add_((3));
  659. $ctx1.sendIdx["add:"]=1;
  660. _st($2)._add_((4));
  661. $3=_st($2)._yourself();
  662. $1=$3;
  663. return $1;
  664. }, function($ctx1) {$ctx1.fill(self,"foo",{},globals.DoIt)})},
  665. args: [],
  666. source: "foo ^ Array new add: 3; add: 4; yourself",
  667. messageSends: ["add:", "new", "yourself"],
  668. referencedClasses: ["Array"]
  669. }),
  670. globals.DoIt);
  671. smalltalk.addClass('NodeVisitor', globals.Object, [], 'Compiler-Core');
  672. globals.NodeVisitor.comment="I am the abstract super class of all AST node visitors.";
  673. smalltalk.addMethod(
  674. smalltalk.method({
  675. selector: "visit:",
  676. protocol: 'visiting',
  677. fn: function (aNode){
  678. var self=this;
  679. return smalltalk.withContext(function($ctx1) {
  680. var $1;
  681. $1=_st(aNode)._accept_(self);
  682. return $1;
  683. }, function($ctx1) {$ctx1.fill(self,"visit:",{aNode:aNode},globals.NodeVisitor)})},
  684. args: ["aNode"],
  685. source: "visit: aNode\x0a\x09^ aNode accept: self",
  686. messageSends: ["accept:"],
  687. referencedClasses: []
  688. }),
  689. globals.NodeVisitor);
  690. smalltalk.addMethod(
  691. smalltalk.method({
  692. selector: "visitAll:",
  693. protocol: 'visiting',
  694. fn: function (aCollection){
  695. var self=this;
  696. return smalltalk.withContext(function($ctx1) {
  697. var $1;
  698. $1=_st(aCollection)._collect_((function(each){
  699. return smalltalk.withContext(function($ctx2) {
  700. return self._visit_(each);
  701. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  702. return $1;
  703. }, function($ctx1) {$ctx1.fill(self,"visitAll:",{aCollection:aCollection},globals.NodeVisitor)})},
  704. args: ["aCollection"],
  705. source: "visitAll: aCollection\x0a\x09^ aCollection collect: [ :each | self visit: each ]",
  706. messageSends: ["collect:", "visit:"],
  707. referencedClasses: []
  708. }),
  709. globals.NodeVisitor);
  710. smalltalk.addMethod(
  711. smalltalk.method({
  712. selector: "visitAssignmentNode:",
  713. protocol: 'visiting',
  714. fn: function (aNode){
  715. var self=this;
  716. return smalltalk.withContext(function($ctx1) {
  717. var $1;
  718. $1=self._visitNode_(aNode);
  719. return $1;
  720. }, function($ctx1) {$ctx1.fill(self,"visitAssignmentNode:",{aNode:aNode},globals.NodeVisitor)})},
  721. args: ["aNode"],
  722. source: "visitAssignmentNode: aNode\x0a\x09^ self visitNode: aNode",
  723. messageSends: ["visitNode:"],
  724. referencedClasses: []
  725. }),
  726. globals.NodeVisitor);
  727. smalltalk.addMethod(
  728. smalltalk.method({
  729. selector: "visitBlockNode:",
  730. protocol: 'visiting',
  731. fn: function (aNode){
  732. var self=this;
  733. return smalltalk.withContext(function($ctx1) {
  734. var $1;
  735. $1=self._visitNode_(aNode);
  736. return $1;
  737. }, function($ctx1) {$ctx1.fill(self,"visitBlockNode:",{aNode:aNode},globals.NodeVisitor)})},
  738. args: ["aNode"],
  739. source: "visitBlockNode: aNode\x0a\x09^ self visitNode: aNode",
  740. messageSends: ["visitNode:"],
  741. referencedClasses: []
  742. }),
  743. globals.NodeVisitor);
  744. smalltalk.addMethod(
  745. smalltalk.method({
  746. selector: "visitBlockSequenceNode:",
  747. protocol: 'visiting',
  748. fn: function (aNode){
  749. var self=this;
  750. return smalltalk.withContext(function($ctx1) {
  751. var $1;
  752. $1=self._visitSequenceNode_(aNode);
  753. return $1;
  754. }, function($ctx1) {$ctx1.fill(self,"visitBlockSequenceNode:",{aNode:aNode},globals.NodeVisitor)})},
  755. args: ["aNode"],
  756. source: "visitBlockSequenceNode: aNode\x0a\x09^ self visitSequenceNode: aNode",
  757. messageSends: ["visitSequenceNode:"],
  758. referencedClasses: []
  759. }),
  760. globals.NodeVisitor);
  761. smalltalk.addMethod(
  762. smalltalk.method({
  763. selector: "visitCascadeNode:",
  764. protocol: 'visiting',
  765. fn: function (aNode){
  766. var self=this;
  767. return smalltalk.withContext(function($ctx1) {
  768. var $1;
  769. $1=self._visitNode_(aNode);
  770. return $1;
  771. }, function($ctx1) {$ctx1.fill(self,"visitCascadeNode:",{aNode:aNode},globals.NodeVisitor)})},
  772. args: ["aNode"],
  773. source: "visitCascadeNode: aNode\x0a\x09^ self visitNode: aNode",
  774. messageSends: ["visitNode:"],
  775. referencedClasses: []
  776. }),
  777. globals.NodeVisitor);
  778. smalltalk.addMethod(
  779. smalltalk.method({
  780. selector: "visitDynamicArrayNode:",
  781. protocol: 'visiting',
  782. fn: function (aNode){
  783. var self=this;
  784. return smalltalk.withContext(function($ctx1) {
  785. var $1;
  786. $1=self._visitNode_(aNode);
  787. return $1;
  788. }, function($ctx1) {$ctx1.fill(self,"visitDynamicArrayNode:",{aNode:aNode},globals.NodeVisitor)})},
  789. args: ["aNode"],
  790. source: "visitDynamicArrayNode: aNode\x0a\x09^ self visitNode: aNode",
  791. messageSends: ["visitNode:"],
  792. referencedClasses: []
  793. }),
  794. globals.NodeVisitor);
  795. smalltalk.addMethod(
  796. smalltalk.method({
  797. selector: "visitDynamicDictionaryNode:",
  798. protocol: 'visiting',
  799. fn: function (aNode){
  800. var self=this;
  801. return smalltalk.withContext(function($ctx1) {
  802. var $1;
  803. $1=self._visitNode_(aNode);
  804. return $1;
  805. }, function($ctx1) {$ctx1.fill(self,"visitDynamicDictionaryNode:",{aNode:aNode},globals.NodeVisitor)})},
  806. args: ["aNode"],
  807. source: "visitDynamicDictionaryNode: aNode\x0a\x09^ self visitNode: aNode",
  808. messageSends: ["visitNode:"],
  809. referencedClasses: []
  810. }),
  811. globals.NodeVisitor);
  812. smalltalk.addMethod(
  813. smalltalk.method({
  814. selector: "visitJSStatementNode:",
  815. protocol: 'visiting',
  816. fn: function (aNode){
  817. var self=this;
  818. return smalltalk.withContext(function($ctx1) {
  819. var $1;
  820. $1=self._visitNode_(aNode);
  821. return $1;
  822. }, function($ctx1) {$ctx1.fill(self,"visitJSStatementNode:",{aNode:aNode},globals.NodeVisitor)})},
  823. args: ["aNode"],
  824. source: "visitJSStatementNode: aNode\x0a\x09^ self visitNode: aNode",
  825. messageSends: ["visitNode:"],
  826. referencedClasses: []
  827. }),
  828. globals.NodeVisitor);
  829. smalltalk.addMethod(
  830. smalltalk.method({
  831. selector: "visitMethodNode:",
  832. protocol: 'visiting',
  833. fn: function (aNode){
  834. var self=this;
  835. return smalltalk.withContext(function($ctx1) {
  836. var $1;
  837. $1=self._visitNode_(aNode);
  838. return $1;
  839. }, function($ctx1) {$ctx1.fill(self,"visitMethodNode:",{aNode:aNode},globals.NodeVisitor)})},
  840. args: ["aNode"],
  841. source: "visitMethodNode: aNode\x0a\x09^ self visitNode: aNode",
  842. messageSends: ["visitNode:"],
  843. referencedClasses: []
  844. }),
  845. globals.NodeVisitor);
  846. smalltalk.addMethod(
  847. smalltalk.method({
  848. selector: "visitNode:",
  849. protocol: 'visiting',
  850. fn: function (aNode){
  851. var self=this;
  852. return smalltalk.withContext(function($ctx1) {
  853. var $1;
  854. $1=self._visitAll_(_st(aNode)._nodes());
  855. return $1;
  856. }, function($ctx1) {$ctx1.fill(self,"visitNode:",{aNode:aNode},globals.NodeVisitor)})},
  857. args: ["aNode"],
  858. source: "visitNode: aNode\x0a\x09^ self visitAll: aNode nodes",
  859. messageSends: ["visitAll:", "nodes"],
  860. referencedClasses: []
  861. }),
  862. globals.NodeVisitor);
  863. smalltalk.addMethod(
  864. smalltalk.method({
  865. selector: "visitReturnNode:",
  866. protocol: 'visiting',
  867. fn: function (aNode){
  868. var self=this;
  869. return smalltalk.withContext(function($ctx1) {
  870. var $1;
  871. $1=self._visitNode_(aNode);
  872. return $1;
  873. }, function($ctx1) {$ctx1.fill(self,"visitReturnNode:",{aNode:aNode},globals.NodeVisitor)})},
  874. args: ["aNode"],
  875. source: "visitReturnNode: aNode\x0a\x09^ self visitNode: aNode",
  876. messageSends: ["visitNode:"],
  877. referencedClasses: []
  878. }),
  879. globals.NodeVisitor);
  880. smalltalk.addMethod(
  881. smalltalk.method({
  882. selector: "visitSendNode:",
  883. protocol: 'visiting',
  884. fn: function (aNode){
  885. var self=this;
  886. return smalltalk.withContext(function($ctx1) {
  887. var $1;
  888. $1=self._visitNode_(aNode);
  889. return $1;
  890. }, function($ctx1) {$ctx1.fill(self,"visitSendNode:",{aNode:aNode},globals.NodeVisitor)})},
  891. args: ["aNode"],
  892. source: "visitSendNode: aNode\x0a\x09^ self visitNode: aNode",
  893. messageSends: ["visitNode:"],
  894. referencedClasses: []
  895. }),
  896. globals.NodeVisitor);
  897. smalltalk.addMethod(
  898. smalltalk.method({
  899. selector: "visitSequenceNode:",
  900. protocol: 'visiting',
  901. fn: function (aNode){
  902. var self=this;
  903. return smalltalk.withContext(function($ctx1) {
  904. var $1;
  905. $1=self._visitNode_(aNode);
  906. return $1;
  907. }, function($ctx1) {$ctx1.fill(self,"visitSequenceNode:",{aNode:aNode},globals.NodeVisitor)})},
  908. args: ["aNode"],
  909. source: "visitSequenceNode: aNode\x0a\x09^ self visitNode: aNode",
  910. messageSends: ["visitNode:"],
  911. referencedClasses: []
  912. }),
  913. globals.NodeVisitor);
  914. smalltalk.addMethod(
  915. smalltalk.method({
  916. selector: "visitValueNode:",
  917. protocol: 'visiting',
  918. fn: function (aNode){
  919. var self=this;
  920. return smalltalk.withContext(function($ctx1) {
  921. var $1;
  922. $1=self._visitNode_(aNode);
  923. return $1;
  924. }, function($ctx1) {$ctx1.fill(self,"visitValueNode:",{aNode:aNode},globals.NodeVisitor)})},
  925. args: ["aNode"],
  926. source: "visitValueNode: aNode\x0a\x09^ self visitNode: aNode",
  927. messageSends: ["visitNode:"],
  928. referencedClasses: []
  929. }),
  930. globals.NodeVisitor);
  931. smalltalk.addMethod(
  932. smalltalk.method({
  933. selector: "visitVariableNode:",
  934. protocol: 'visiting',
  935. fn: function (aNode){
  936. var self=this;
  937. return smalltalk.withContext(function($ctx1) {
  938. var $1;
  939. $1=self._visitNode_(aNode);
  940. return $1;
  941. }, function($ctx1) {$ctx1.fill(self,"visitVariableNode:",{aNode:aNode},globals.NodeVisitor)})},
  942. args: ["aNode"],
  943. source: "visitVariableNode: aNode\x0a\x09^ self visitNode: aNode",
  944. messageSends: ["visitNode:"],
  945. referencedClasses: []
  946. }),
  947. globals.NodeVisitor);
  948. smalltalk.addMethod(
  949. smalltalk.method({
  950. selector: "asVariableName",
  951. protocol: '*Compiler-Core',
  952. fn: function (){
  953. var self=this;
  954. function $Smalltalk(){return globals.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  955. return smalltalk.withContext(function($ctx1) {
  956. var $2,$1;
  957. $2=_st(_st($Smalltalk())._reservedWords())._includes_(self);
  958. if(smalltalk.assert($2)){
  959. $1=self.__comma("_");
  960. } else {
  961. $1=self;
  962. };
  963. return $1;
  964. }, function($ctx1) {$ctx1.fill(self,"asVariableName",{},globals.String)})},
  965. args: [],
  966. source: "asVariableName\x0a\x09^ (Smalltalk reservedWords includes: self)\x0a\x09\x09ifTrue: [ self, '_' ]\x0a\x09\x09ifFalse: [ self ]",
  967. messageSends: ["ifTrue:ifFalse:", "includes:", "reservedWords", ","],
  968. referencedClasses: ["Smalltalk"]
  969. }),
  970. globals.String);
  971. });