2
0

Compiler-Core.js 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009
  1. define("amber_core/Compiler-Core", ["amber_vm/smalltalk", "amber_vm/nil", "amber_vm/_st", "amber_core/Kernel-Objects", "amber_core/Kernel-Collections"], function(smalltalk,nil,_st){
  2. smalltalk.addPackage('Compiler-Core');
  3. smalltalk.packages["Compiler-Core"].transport = {"type":"amd","amdNamespace":"amber_core"};
  4. smalltalk.addClass('AbstractCodeGenerator', smalltalk.Object, ['currentClass', 'source'], 'Compiler-Core');
  5. smalltalk.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},smalltalk.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. smalltalk.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},smalltalk.AbstractCodeGenerator)})},
  44. args: ["aNode"],
  45. source: "compileNode: aNode\x0a\x09self subclassResponsibility",
  46. messageSends: ["subclassResponsibility"],
  47. referencedClasses: []
  48. }),
  49. smalltalk.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. smalltalk.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. smalltalk.AbstractCodeGenerator);
  80. smalltalk.addMethod(
  81. smalltalk.method({
  82. selector: "pseudoVariables",
  83. protocol: 'accessing',
  84. fn: function (){
  85. var self=this;
  86. function $Smalltalk(){return smalltalk.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",{},smalltalk.AbstractCodeGenerator)})},
  92. args: [],
  93. source: "pseudoVariables\x0a\x09^ Smalltalk pseudoVariableNames",
  94. messageSends: ["pseudoVariableNames"],
  95. referencedClasses: ["Smalltalk"]
  96. }),
  97. smalltalk.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",{},smalltalk.AbstractCodeGenerator)})},
  114. args: [],
  115. source: "source\x0a\x09^ source ifNil: [ '' ]",
  116. messageSends: ["ifNil:"],
  117. referencedClasses: []
  118. }),
  119. smalltalk.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. smalltalk.AbstractCodeGenerator);
  134. smalltalk.addClass('CodeGenerator', smalltalk.AbstractCodeGenerator, [], 'Compiler-Core');
  135. smalltalk.CodeGenerator.comment="I am a basic code generator. I generate a valid JavaScript output, but no not perform any inlining.\x0aSee `InliningCodeGenerator` for an optimized JavaScript code generation.";
  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},smalltalk.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. smalltalk.CodeGenerator);
  162. smalltalk.addMethod(
  163. smalltalk.method({
  164. selector: "irTranslator",
  165. protocol: 'compiling',
  166. fn: function (){
  167. var self=this;
  168. function $IRJSTranslator(){return smalltalk.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",{},smalltalk.CodeGenerator)})},
  174. args: [],
  175. source: "irTranslator\x0a\x09^ IRJSTranslator new",
  176. messageSends: ["new"],
  177. referencedClasses: ["IRJSTranslator"]
  178. }),
  179. smalltalk.CodeGenerator);
  180. smalltalk.addMethod(
  181. smalltalk.method({
  182. selector: "semanticAnalyzer",
  183. protocol: 'compiling',
  184. fn: function (){
  185. var self=this;
  186. function $SemanticAnalyzer(){return smalltalk.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",{},smalltalk.CodeGenerator)})},
  192. args: [],
  193. source: "semanticAnalyzer\x0a\x09^ SemanticAnalyzer on: self currentClass",
  194. messageSends: ["on:", "currentClass"],
  195. referencedClasses: ["SemanticAnalyzer"]
  196. }),
  197. smalltalk.CodeGenerator);
  198. smalltalk.addMethod(
  199. smalltalk.method({
  200. selector: "translator",
  201. protocol: 'compiling',
  202. fn: function (){
  203. var self=this;
  204. function $IRASTTranslator(){return smalltalk.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",{},smalltalk.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. smalltalk.CodeGenerator);
  220. smalltalk.addClass('Compiler', smalltalk.Object, ['currentClass', 'source', 'unknownVariables', 'codeGeneratorClass'], 'Compiler-Core');
  221. smalltalk.Compiler.comment="I provide the public interface for compiling Amber source code into JavaScript.\x0a\x0aThe code generator used to produce JavaScript can be plugged with `#codeGeneratorClass`.\x0aThe default code generator is an instance of `InlinedCodeGenerator`";
  222. smalltalk.addMethod(
  223. smalltalk.method({
  224. selector: "codeGeneratorClass",
  225. protocol: 'accessing',
  226. fn: function (){
  227. var self=this;
  228. function $InliningCodeGenerator(){return smalltalk.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",{},smalltalk.Compiler)})},
  239. args: [],
  240. source: "codeGeneratorClass\x0a\x09^ codeGeneratorClass ifNil: [ InliningCodeGenerator ]",
  241. messageSends: ["ifNil:"],
  242. referencedClasses: ["InliningCodeGenerator"]
  243. }),
  244. smalltalk.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. smalltalk.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},smalltalk.Compiler)})},
  270. args: ["aString"],
  271. source: "compile: aString\x0a\x09^ self compileNode: (self parse: aString)",
  272. messageSends: ["compileNode:", "parse:"],
  273. referencedClasses: []
  274. }),
  275. smalltalk.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},smalltalk.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. smalltalk.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 smalltalk.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},smalltalk.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. smalltalk.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},smalltalk.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. smalltalk.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},smalltalk.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. smalltalk.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. smalltalk.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. smalltalk.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. smalltalk.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 smalltalk.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},smalltalk.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. smalltalk.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},smalltalk.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. smalltalk.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 smalltalk.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},smalltalk.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. smalltalk.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 smalltalk.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},smalltalk.Compiler)})},
  479. args: ["aString"],
  480. source: "parse: aString\x0a\x09^ Smalltalk parse: aString",
  481. messageSends: ["parse:"],
  482. referencedClasses: ["Smalltalk"]
  483. }),
  484. smalltalk.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},smalltalk.Compiler)})},
  498. args: ["aString"],
  499. source: "parseExpression: aString\x0a\x09^ self parse: 'doIt ^ [ ', aString, ' ] value'",
  500. messageSends: ["parse:", ","],
  501. referencedClasses: []
  502. }),
  503. smalltalk.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},smalltalk.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. smalltalk.Compiler);
  527. smalltalk.addMethod(
  528. smalltalk.method({
  529. selector: "recompileAll",
  530. protocol: 'compiling',
  531. fn: function (){
  532. var self=this;
  533. function $Smalltalk(){return smalltalk.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",{},smalltalk.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. smalltalk.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",{},smalltalk.Compiler)})},
  562. args: [],
  563. source: "source\x0a\x09^ source ifNil: [ '' ]",
  564. messageSends: ["ifNil:"],
  565. referencedClasses: []
  566. }),
  567. smalltalk.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. smalltalk.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. smalltalk.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. smalltalk.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},smalltalk.Compiler.klass)})},
  621. args: ["aClass"],
  622. source: "recompile: aClass\x0a\x09self new recompile: aClass",
  623. messageSends: ["recompile:", "new"],
  624. referencedClasses: []
  625. }),
  626. smalltalk.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 smalltalk.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",{},smalltalk.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. smalltalk.Compiler.klass);
  646. smalltalk.addClass('DoIt', smalltalk.Object, [], 'Compiler-Core');
  647. smalltalk.DoIt.comment="`DoIt` is the class used to compile and evaluate expressions. See `Compiler >> evaluateExpression:`.";
  648. smalltalk.addClass('NodeVisitor', smalltalk.Object, [], 'Compiler-Core');
  649. smalltalk.NodeVisitor.comment="I am the abstract super class of all AST node visitors.";
  650. smalltalk.addMethod(
  651. smalltalk.method({
  652. selector: "visit:",
  653. protocol: 'visiting',
  654. fn: function (aNode){
  655. var self=this;
  656. return smalltalk.withContext(function($ctx1) {
  657. var $1;
  658. $1=_st(aNode)._accept_(self);
  659. return $1;
  660. }, function($ctx1) {$ctx1.fill(self,"visit:",{aNode:aNode},smalltalk.NodeVisitor)})},
  661. args: ["aNode"],
  662. source: "visit: aNode\x0a\x09^ aNode accept: self",
  663. messageSends: ["accept:"],
  664. referencedClasses: []
  665. }),
  666. smalltalk.NodeVisitor);
  667. smalltalk.addMethod(
  668. smalltalk.method({
  669. selector: "visitAll:",
  670. protocol: 'visiting',
  671. fn: function (aCollection){
  672. var self=this;
  673. return smalltalk.withContext(function($ctx1) {
  674. var $1;
  675. $1=_st(aCollection)._collect_((function(each){
  676. return smalltalk.withContext(function($ctx2) {
  677. return self._visit_(each);
  678. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)})}));
  679. return $1;
  680. }, function($ctx1) {$ctx1.fill(self,"visitAll:",{aCollection:aCollection},smalltalk.NodeVisitor)})},
  681. args: ["aCollection"],
  682. source: "visitAll: aCollection\x0a\x09^ aCollection collect: [ :each | self visit: each ]",
  683. messageSends: ["collect:", "visit:"],
  684. referencedClasses: []
  685. }),
  686. smalltalk.NodeVisitor);
  687. smalltalk.addMethod(
  688. smalltalk.method({
  689. selector: "visitAssignmentNode:",
  690. protocol: 'visiting',
  691. fn: function (aNode){
  692. var self=this;
  693. return smalltalk.withContext(function($ctx1) {
  694. var $1;
  695. $1=self._visitNode_(aNode);
  696. return $1;
  697. }, function($ctx1) {$ctx1.fill(self,"visitAssignmentNode:",{aNode:aNode},smalltalk.NodeVisitor)})},
  698. args: ["aNode"],
  699. source: "visitAssignmentNode: aNode\x0a\x09^ self visitNode: aNode",
  700. messageSends: ["visitNode:"],
  701. referencedClasses: []
  702. }),
  703. smalltalk.NodeVisitor);
  704. smalltalk.addMethod(
  705. smalltalk.method({
  706. selector: "visitBlockNode:",
  707. protocol: 'visiting',
  708. fn: function (aNode){
  709. var self=this;
  710. return smalltalk.withContext(function($ctx1) {
  711. var $1;
  712. $1=self._visitNode_(aNode);
  713. return $1;
  714. }, function($ctx1) {$ctx1.fill(self,"visitBlockNode:",{aNode:aNode},smalltalk.NodeVisitor)})},
  715. args: ["aNode"],
  716. source: "visitBlockNode: aNode\x0a\x09^ self visitNode: aNode",
  717. messageSends: ["visitNode:"],
  718. referencedClasses: []
  719. }),
  720. smalltalk.NodeVisitor);
  721. smalltalk.addMethod(
  722. smalltalk.method({
  723. selector: "visitBlockSequenceNode:",
  724. protocol: 'visiting',
  725. fn: function (aNode){
  726. var self=this;
  727. return smalltalk.withContext(function($ctx1) {
  728. var $1;
  729. $1=self._visitSequenceNode_(aNode);
  730. return $1;
  731. }, function($ctx1) {$ctx1.fill(self,"visitBlockSequenceNode:",{aNode:aNode},smalltalk.NodeVisitor)})},
  732. args: ["aNode"],
  733. source: "visitBlockSequenceNode: aNode\x0a\x09^ self visitSequenceNode: aNode",
  734. messageSends: ["visitSequenceNode:"],
  735. referencedClasses: []
  736. }),
  737. smalltalk.NodeVisitor);
  738. smalltalk.addMethod(
  739. smalltalk.method({
  740. selector: "visitCascadeNode:",
  741. protocol: 'visiting',
  742. fn: function (aNode){
  743. var self=this;
  744. return smalltalk.withContext(function($ctx1) {
  745. var $1;
  746. $1=self._visitNode_(aNode);
  747. return $1;
  748. }, function($ctx1) {$ctx1.fill(self,"visitCascadeNode:",{aNode:aNode},smalltalk.NodeVisitor)})},
  749. args: ["aNode"],
  750. source: "visitCascadeNode: aNode\x0a\x09^ self visitNode: aNode",
  751. messageSends: ["visitNode:"],
  752. referencedClasses: []
  753. }),
  754. smalltalk.NodeVisitor);
  755. smalltalk.addMethod(
  756. smalltalk.method({
  757. selector: "visitDynamicArrayNode:",
  758. protocol: 'visiting',
  759. fn: function (aNode){
  760. var self=this;
  761. return smalltalk.withContext(function($ctx1) {
  762. var $1;
  763. $1=self._visitNode_(aNode);
  764. return $1;
  765. }, function($ctx1) {$ctx1.fill(self,"visitDynamicArrayNode:",{aNode:aNode},smalltalk.NodeVisitor)})},
  766. args: ["aNode"],
  767. source: "visitDynamicArrayNode: aNode\x0a\x09^ self visitNode: aNode",
  768. messageSends: ["visitNode:"],
  769. referencedClasses: []
  770. }),
  771. smalltalk.NodeVisitor);
  772. smalltalk.addMethod(
  773. smalltalk.method({
  774. selector: "visitDynamicDictionaryNode:",
  775. protocol: 'visiting',
  776. fn: function (aNode){
  777. var self=this;
  778. return smalltalk.withContext(function($ctx1) {
  779. var $1;
  780. $1=self._visitNode_(aNode);
  781. return $1;
  782. }, function($ctx1) {$ctx1.fill(self,"visitDynamicDictionaryNode:",{aNode:aNode},smalltalk.NodeVisitor)})},
  783. args: ["aNode"],
  784. source: "visitDynamicDictionaryNode: aNode\x0a\x09^ self visitNode: aNode",
  785. messageSends: ["visitNode:"],
  786. referencedClasses: []
  787. }),
  788. smalltalk.NodeVisitor);
  789. smalltalk.addMethod(
  790. smalltalk.method({
  791. selector: "visitJSStatementNode:",
  792. protocol: 'visiting',
  793. fn: function (aNode){
  794. var self=this;
  795. return smalltalk.withContext(function($ctx1) {
  796. var $1;
  797. $1=self._visitNode_(aNode);
  798. return $1;
  799. }, function($ctx1) {$ctx1.fill(self,"visitJSStatementNode:",{aNode:aNode},smalltalk.NodeVisitor)})},
  800. args: ["aNode"],
  801. source: "visitJSStatementNode: aNode\x0a\x09^ self visitNode: aNode",
  802. messageSends: ["visitNode:"],
  803. referencedClasses: []
  804. }),
  805. smalltalk.NodeVisitor);
  806. smalltalk.addMethod(
  807. smalltalk.method({
  808. selector: "visitMethodNode:",
  809. protocol: 'visiting',
  810. fn: function (aNode){
  811. var self=this;
  812. return smalltalk.withContext(function($ctx1) {
  813. var $1;
  814. $1=self._visitNode_(aNode);
  815. return $1;
  816. }, function($ctx1) {$ctx1.fill(self,"visitMethodNode:",{aNode:aNode},smalltalk.NodeVisitor)})},
  817. args: ["aNode"],
  818. source: "visitMethodNode: aNode\x0a\x09^ self visitNode: aNode",
  819. messageSends: ["visitNode:"],
  820. referencedClasses: []
  821. }),
  822. smalltalk.NodeVisitor);
  823. smalltalk.addMethod(
  824. smalltalk.method({
  825. selector: "visitNode:",
  826. protocol: 'visiting',
  827. fn: function (aNode){
  828. var self=this;
  829. return smalltalk.withContext(function($ctx1) {
  830. var $1;
  831. $1=self._visitAll_(_st(aNode)._nodes());
  832. return $1;
  833. }, function($ctx1) {$ctx1.fill(self,"visitNode:",{aNode:aNode},smalltalk.NodeVisitor)})},
  834. args: ["aNode"],
  835. source: "visitNode: aNode\x0a\x09^ self visitAll: aNode nodes",
  836. messageSends: ["visitAll:", "nodes"],
  837. referencedClasses: []
  838. }),
  839. smalltalk.NodeVisitor);
  840. smalltalk.addMethod(
  841. smalltalk.method({
  842. selector: "visitReturnNode:",
  843. protocol: 'visiting',
  844. fn: function (aNode){
  845. var self=this;
  846. return smalltalk.withContext(function($ctx1) {
  847. var $1;
  848. $1=self._visitNode_(aNode);
  849. return $1;
  850. }, function($ctx1) {$ctx1.fill(self,"visitReturnNode:",{aNode:aNode},smalltalk.NodeVisitor)})},
  851. args: ["aNode"],
  852. source: "visitReturnNode: aNode\x0a\x09^ self visitNode: aNode",
  853. messageSends: ["visitNode:"],
  854. referencedClasses: []
  855. }),
  856. smalltalk.NodeVisitor);
  857. smalltalk.addMethod(
  858. smalltalk.method({
  859. selector: "visitSendNode:",
  860. protocol: 'visiting',
  861. fn: function (aNode){
  862. var self=this;
  863. return smalltalk.withContext(function($ctx1) {
  864. var $1;
  865. $1=self._visitNode_(aNode);
  866. return $1;
  867. }, function($ctx1) {$ctx1.fill(self,"visitSendNode:",{aNode:aNode},smalltalk.NodeVisitor)})},
  868. args: ["aNode"],
  869. source: "visitSendNode: aNode\x0a\x09^ self visitNode: aNode",
  870. messageSends: ["visitNode:"],
  871. referencedClasses: []
  872. }),
  873. smalltalk.NodeVisitor);
  874. smalltalk.addMethod(
  875. smalltalk.method({
  876. selector: "visitSequenceNode:",
  877. protocol: 'visiting',
  878. fn: function (aNode){
  879. var self=this;
  880. return smalltalk.withContext(function($ctx1) {
  881. var $1;
  882. $1=self._visitNode_(aNode);
  883. return $1;
  884. }, function($ctx1) {$ctx1.fill(self,"visitSequenceNode:",{aNode:aNode},smalltalk.NodeVisitor)})},
  885. args: ["aNode"],
  886. source: "visitSequenceNode: aNode\x0a\x09^ self visitNode: aNode",
  887. messageSends: ["visitNode:"],
  888. referencedClasses: []
  889. }),
  890. smalltalk.NodeVisitor);
  891. smalltalk.addMethod(
  892. smalltalk.method({
  893. selector: "visitValueNode:",
  894. protocol: 'visiting',
  895. fn: function (aNode){
  896. var self=this;
  897. return smalltalk.withContext(function($ctx1) {
  898. var $1;
  899. $1=self._visitNode_(aNode);
  900. return $1;
  901. }, function($ctx1) {$ctx1.fill(self,"visitValueNode:",{aNode:aNode},smalltalk.NodeVisitor)})},
  902. args: ["aNode"],
  903. source: "visitValueNode: aNode\x0a\x09^ self visitNode: aNode",
  904. messageSends: ["visitNode:"],
  905. referencedClasses: []
  906. }),
  907. smalltalk.NodeVisitor);
  908. smalltalk.addMethod(
  909. smalltalk.method({
  910. selector: "visitVariableNode:",
  911. protocol: 'visiting',
  912. fn: function (aNode){
  913. var self=this;
  914. return smalltalk.withContext(function($ctx1) {
  915. var $1;
  916. $1=self._visitNode_(aNode);
  917. return $1;
  918. }, function($ctx1) {$ctx1.fill(self,"visitVariableNode:",{aNode:aNode},smalltalk.NodeVisitor)})},
  919. args: ["aNode"],
  920. source: "visitVariableNode: aNode\x0a\x09^ self visitNode: aNode",
  921. messageSends: ["visitNode:"],
  922. referencedClasses: []
  923. }),
  924. smalltalk.NodeVisitor);
  925. smalltalk.addMethod(
  926. smalltalk.method({
  927. selector: "asVariableName",
  928. protocol: '*Compiler-Core',
  929. fn: function (){
  930. var self=this;
  931. function $Smalltalk(){return smalltalk.Smalltalk||(typeof Smalltalk=="undefined"?nil:Smalltalk)}
  932. return smalltalk.withContext(function($ctx1) {
  933. var $2,$1;
  934. $2=_st(_st($Smalltalk())._reservedWords())._includes_(self);
  935. if(smalltalk.assert($2)){
  936. $1=self.__comma("_");
  937. } else {
  938. $1=self;
  939. };
  940. return $1;
  941. }, function($ctx1) {$ctx1.fill(self,"asVariableName",{},smalltalk.String)})},
  942. args: [],
  943. source: "asVariableName\x0a\x09^ (Smalltalk reservedWords includes: self)\x0a\x09\x09ifTrue: [ self, '_' ]\x0a\x09\x09ifFalse: [ self ]",
  944. messageSends: ["ifTrue:ifFalse:", "includes:", "reservedWords", ","],
  945. referencedClasses: ["Smalltalk"]
  946. }),
  947. smalltalk.String);
  948. });