1
0

Compiler-Core.js 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  1. define(["amber/boot", "require", "amber/core/Kernel-Collections", "amber/core/Kernel-Objects"], function($boot,requirejs){"use strict";
  2. var $core=$boot.api,nil=$boot.nilAsValue,$nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
  3. var $pkg = $core.addPackage("Compiler-Core");
  4. $pkg.innerEval = function (expr) { return eval(expr); };
  5. $pkg.transport = {"type":"amd","amdNamespace":"amber/core"};
  6. $core.addClass("AbstractCodeGenerator", $globals.Object, ["currentClass", "currentPackage", "source"], "Compiler-Core");
  7. //>>excludeStart("ide", pragmas.excludeIdeData);
  8. $globals.AbstractCodeGenerator.comment="I am the abstract super class of all code generators and provide their common API.";
  9. //>>excludeEnd("ide");
  10. $core.addMethod(
  11. $core.method({
  12. selector: "compileNode:",
  13. protocol: "compiling",
  14. fn: function (aNode){
  15. var self=this,$self=this;
  16. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  17. return $core.withContext(function($ctx1) {
  18. //>>excludeEnd("ctx");
  19. return $recv($self._transformers())._inject_into_(aNode,(function(input,transformer){
  20. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  21. return $core.withContext(function($ctx2) {
  22. //>>excludeEnd("ctx");
  23. return $recv(transformer)._value_(input);
  24. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  25. }, function($ctx2) {$ctx2.fillBlock({input:input,transformer:transformer},$ctx1,1)});
  26. //>>excludeEnd("ctx");
  27. }));
  28. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  29. }, function($ctx1) {$ctx1.fill(self,"compileNode:",{aNode:aNode},$globals.AbstractCodeGenerator)});
  30. //>>excludeEnd("ctx");
  31. },
  32. //>>excludeStart("ide", pragmas.excludeIdeData);
  33. args: ["aNode"],
  34. source: "compileNode: aNode\x0a\x09^ self transformers\x0a\x09\x09inject: aNode\x0a\x09\x09into: [ :input :transformer | transformer value: input ]",
  35. referencedClasses: [],
  36. //>>excludeEnd("ide");
  37. messageSends: ["inject:into:", "transformers", "value:"]
  38. }),
  39. $globals.AbstractCodeGenerator);
  40. $core.addMethod(
  41. $core.method({
  42. selector: "currentClass",
  43. protocol: "accessing",
  44. fn: function (){
  45. var self=this,$self=this;
  46. return $self.currentClass;
  47. },
  48. //>>excludeStart("ide", pragmas.excludeIdeData);
  49. args: [],
  50. source: "currentClass\x0a\x09^ currentClass",
  51. referencedClasses: [],
  52. //>>excludeEnd("ide");
  53. messageSends: []
  54. }),
  55. $globals.AbstractCodeGenerator);
  56. $core.addMethod(
  57. $core.method({
  58. selector: "currentClass:",
  59. protocol: "accessing",
  60. fn: function (aClass){
  61. var self=this,$self=this;
  62. $self.currentClass=aClass;
  63. return self;
  64. },
  65. //>>excludeStart("ide", pragmas.excludeIdeData);
  66. args: ["aClass"],
  67. source: "currentClass: aClass\x0a\x09currentClass := aClass",
  68. referencedClasses: [],
  69. //>>excludeEnd("ide");
  70. messageSends: []
  71. }),
  72. $globals.AbstractCodeGenerator);
  73. $core.addMethod(
  74. $core.method({
  75. selector: "currentPackage",
  76. protocol: "accessing",
  77. fn: function (){
  78. var self=this,$self=this;
  79. return $self.currentPackage;
  80. },
  81. //>>excludeStart("ide", pragmas.excludeIdeData);
  82. args: [],
  83. source: "currentPackage\x0a\x09^ currentPackage",
  84. referencedClasses: [],
  85. //>>excludeEnd("ide");
  86. messageSends: []
  87. }),
  88. $globals.AbstractCodeGenerator);
  89. $core.addMethod(
  90. $core.method({
  91. selector: "currentPackage:",
  92. protocol: "accessing",
  93. fn: function (anObject){
  94. var self=this,$self=this;
  95. $self.currentPackage=anObject;
  96. return self;
  97. },
  98. //>>excludeStart("ide", pragmas.excludeIdeData);
  99. args: ["anObject"],
  100. source: "currentPackage: anObject\x0a\x09currentPackage := anObject",
  101. referencedClasses: [],
  102. //>>excludeEnd("ide");
  103. messageSends: []
  104. }),
  105. $globals.AbstractCodeGenerator);
  106. $core.addMethod(
  107. $core.method({
  108. selector: "pseudoVariables",
  109. protocol: "accessing",
  110. fn: function (){
  111. var self=this,$self=this;
  112. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  113. return $core.withContext(function($ctx1) {
  114. //>>excludeEnd("ctx");
  115. return $recv($globals.Smalltalk)._pseudoVariableNames();
  116. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  117. }, function($ctx1) {$ctx1.fill(self,"pseudoVariables",{},$globals.AbstractCodeGenerator)});
  118. //>>excludeEnd("ctx");
  119. },
  120. //>>excludeStart("ide", pragmas.excludeIdeData);
  121. args: [],
  122. source: "pseudoVariables\x0a\x09^ Smalltalk pseudoVariableNames",
  123. referencedClasses: ["Smalltalk"],
  124. //>>excludeEnd("ide");
  125. messageSends: ["pseudoVariableNames"]
  126. }),
  127. $globals.AbstractCodeGenerator);
  128. $core.addMethod(
  129. $core.method({
  130. selector: "source",
  131. protocol: "accessing",
  132. fn: function (){
  133. var self=this,$self=this;
  134. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  135. return $core.withContext(function($ctx1) {
  136. //>>excludeEnd("ctx");
  137. var $1,$receiver;
  138. $1=$self.source;
  139. if(($receiver = $1) == null || $receiver.a$nil){
  140. return "";
  141. } else {
  142. return $1;
  143. }
  144. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  145. }, function($ctx1) {$ctx1.fill(self,"source",{},$globals.AbstractCodeGenerator)});
  146. //>>excludeEnd("ctx");
  147. },
  148. //>>excludeStart("ide", pragmas.excludeIdeData);
  149. args: [],
  150. source: "source\x0a\x09^ source ifNil: [ '' ]",
  151. referencedClasses: [],
  152. //>>excludeEnd("ide");
  153. messageSends: ["ifNil:"]
  154. }),
  155. $globals.AbstractCodeGenerator);
  156. $core.addMethod(
  157. $core.method({
  158. selector: "source:",
  159. protocol: "accessing",
  160. fn: function (aString){
  161. var self=this,$self=this;
  162. $self.source=aString;
  163. return self;
  164. },
  165. //>>excludeStart("ide", pragmas.excludeIdeData);
  166. args: ["aString"],
  167. source: "source: aString\x0a\x09source := aString",
  168. referencedClasses: [],
  169. //>>excludeEnd("ide");
  170. messageSends: []
  171. }),
  172. $globals.AbstractCodeGenerator);
  173. $core.addMethod(
  174. $core.method({
  175. selector: "transformers",
  176. protocol: "compiling",
  177. fn: function (){
  178. var self=this,$self=this;
  179. var dict;
  180. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  181. return $core.withContext(function($ctx1) {
  182. //>>excludeEnd("ctx");
  183. dict=$self._transformersDictionary();
  184. return $recv($recv($recv($recv(dict)._keys())._asArray())._sort())._collect_((function(each){
  185. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  186. return $core.withContext(function($ctx2) {
  187. //>>excludeEnd("ctx");
  188. return $recv(dict)._at_(each);
  189. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  190. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  191. //>>excludeEnd("ctx");
  192. }));
  193. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  194. }, function($ctx1) {$ctx1.fill(self,"transformers",{dict:dict},$globals.AbstractCodeGenerator)});
  195. //>>excludeEnd("ctx");
  196. },
  197. //>>excludeStart("ide", pragmas.excludeIdeData);
  198. args: [],
  199. source: "transformers\x0a\x09| dict |\x0a\x09dict := self transformersDictionary.\x0a\x09^ dict keys asArray sort collect: [ :each | dict at: each ]",
  200. referencedClasses: [],
  201. //>>excludeEnd("ide");
  202. messageSends: ["transformersDictionary", "collect:", "sort", "asArray", "keys", "at:"]
  203. }),
  204. $globals.AbstractCodeGenerator);
  205. $core.addMethod(
  206. $core.method({
  207. selector: "transformersDictionary",
  208. protocol: "compiling",
  209. fn: function (){
  210. var self=this,$self=this;
  211. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  212. return $core.withContext(function($ctx1) {
  213. //>>excludeEnd("ctx");
  214. $self._subclassResponsibility();
  215. return self;
  216. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  217. }, function($ctx1) {$ctx1.fill(self,"transformersDictionary",{},$globals.AbstractCodeGenerator)});
  218. //>>excludeEnd("ctx");
  219. },
  220. //>>excludeStart("ide", pragmas.excludeIdeData);
  221. args: [],
  222. source: "transformersDictionary\x0a\x09self subclassResponsibility",
  223. referencedClasses: [],
  224. //>>excludeEnd("ide");
  225. messageSends: ["subclassResponsibility"]
  226. }),
  227. $globals.AbstractCodeGenerator);
  228. $core.addClass("CodeGenerator", $globals.AbstractCodeGenerator, ["transformersDictionary"], "Compiler-Core");
  229. //>>excludeStart("ide", pragmas.excludeIdeData);
  230. $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.";
  231. //>>excludeEnd("ide");
  232. $core.addMethod(
  233. $core.method({
  234. selector: "earlyAstPragmator",
  235. protocol: "compiling",
  236. fn: function (){
  237. var self=this,$self=this;
  238. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  239. return $core.withContext(function($ctx1) {
  240. //>>excludeEnd("ctx");
  241. return $recv($globals.AstEarlyPragmator)._new();
  242. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  243. }, function($ctx1) {$ctx1.fill(self,"earlyAstPragmator",{},$globals.CodeGenerator)});
  244. //>>excludeEnd("ctx");
  245. },
  246. //>>excludeStart("ide", pragmas.excludeIdeData);
  247. args: [],
  248. source: "earlyAstPragmator\x0a\x09^ AstEarlyPragmator new",
  249. referencedClasses: ["AstEarlyPragmator"],
  250. //>>excludeEnd("ide");
  251. messageSends: ["new"]
  252. }),
  253. $globals.CodeGenerator);
  254. $core.addMethod(
  255. $core.method({
  256. selector: "irTranslator",
  257. protocol: "compiling",
  258. fn: function (){
  259. var self=this,$self=this;
  260. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  261. return $core.withContext(function($ctx1) {
  262. //>>excludeEnd("ctx");
  263. var $1;
  264. $1=$recv($self._irTranslatorClass())._new();
  265. $recv($1)._currentClass_($self._currentClass());
  266. return $recv($1)._yourself();
  267. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  268. }, function($ctx1) {$ctx1.fill(self,"irTranslator",{},$globals.CodeGenerator)});
  269. //>>excludeEnd("ctx");
  270. },
  271. //>>excludeStart("ide", pragmas.excludeIdeData);
  272. args: [],
  273. source: "irTranslator\x0a\x09^ self irTranslatorClass new\x0a\x09\x09currentClass: self currentClass;\x0a\x09\x09yourself",
  274. referencedClasses: [],
  275. //>>excludeEnd("ide");
  276. messageSends: ["currentClass:", "new", "irTranslatorClass", "currentClass", "yourself"]
  277. }),
  278. $globals.CodeGenerator);
  279. $core.addMethod(
  280. $core.method({
  281. selector: "irTranslatorClass",
  282. protocol: "compiling",
  283. fn: function (){
  284. var self=this,$self=this;
  285. return $globals.IRJSTranslator;
  286. },
  287. //>>excludeStart("ide", pragmas.excludeIdeData);
  288. args: [],
  289. source: "irTranslatorClass\x0a\x09^ IRJSTranslator",
  290. referencedClasses: ["IRJSTranslator"],
  291. //>>excludeEnd("ide");
  292. messageSends: []
  293. }),
  294. $globals.CodeGenerator);
  295. $core.addMethod(
  296. $core.method({
  297. selector: "semanticAnalyzer",
  298. protocol: "compiling",
  299. fn: function (){
  300. var self=this,$self=this;
  301. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  302. return $core.withContext(function($ctx1) {
  303. //>>excludeEnd("ctx");
  304. var $1;
  305. $1=$recv($globals.SemanticAnalyzer)._on_($self._currentClass());
  306. $recv($1)._thePackage_($self._currentPackage());
  307. return $recv($1)._yourself();
  308. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  309. }, function($ctx1) {$ctx1.fill(self,"semanticAnalyzer",{},$globals.CodeGenerator)});
  310. //>>excludeEnd("ctx");
  311. },
  312. //>>excludeStart("ide", pragmas.excludeIdeData);
  313. args: [],
  314. source: "semanticAnalyzer\x0a\x09^ (SemanticAnalyzer on: self currentClass)\x0a\x09\x09thePackage: self currentPackage;\x0a\x09\x09yourself",
  315. referencedClasses: ["SemanticAnalyzer"],
  316. //>>excludeEnd("ide");
  317. messageSends: ["thePackage:", "on:", "currentClass", "currentPackage", "yourself"]
  318. }),
  319. $globals.CodeGenerator);
  320. $core.addMethod(
  321. $core.method({
  322. selector: "transformersDictionary",
  323. protocol: "compiling",
  324. fn: function (){
  325. var self=this,$self=this;
  326. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  327. return $core.withContext(function($ctx1) {
  328. //>>excludeEnd("ctx");
  329. var $1,$2,$receiver;
  330. $1=$self.transformersDictionary;
  331. if(($receiver = $1) == null || $receiver.a$nil){
  332. $2=$recv($globals.Dictionary)._new();
  333. $recv($2)._at_put_("1000-earlyPragmas",$self._earlyAstPragmator());
  334. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  335. $ctx1.sendIdx["at:put:"]=1;
  336. //>>excludeEnd("ctx");
  337. $recv($2)._at_put_("2000-semantic",$self._semanticAnalyzer());
  338. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  339. $ctx1.sendIdx["at:put:"]=2;
  340. //>>excludeEnd("ctx");
  341. $recv($2)._at_put_("5000-astToIr",$self._translator());
  342. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  343. $ctx1.sendIdx["at:put:"]=3;
  344. //>>excludeEnd("ctx");
  345. $recv($2)._at_put_("8000-irToJs",$self._irTranslator());
  346. $self.transformersDictionary=$recv($2)._yourself();
  347. return $self.transformersDictionary;
  348. } else {
  349. return $1;
  350. }
  351. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  352. }, function($ctx1) {$ctx1.fill(self,"transformersDictionary",{},$globals.CodeGenerator)});
  353. //>>excludeEnd("ctx");
  354. },
  355. //>>excludeStart("ide", pragmas.excludeIdeData);
  356. args: [],
  357. source: "transformersDictionary\x0a\x09^ transformersDictionary ifNil: [ transformersDictionary := Dictionary new\x0a\x09\x09at: '1000-earlyPragmas' put: self earlyAstPragmator;\x0a\x09\x09at: '2000-semantic' put: self semanticAnalyzer;\x0a\x09\x09at: '5000-astToIr' put: self translator;\x0a\x09\x09at: '8000-irToJs' put: self irTranslator;\x0a\x09\x09yourself ]",
  358. referencedClasses: ["Dictionary"],
  359. //>>excludeEnd("ide");
  360. messageSends: ["ifNil:", "at:put:", "new", "earlyAstPragmator", "semanticAnalyzer", "translator", "irTranslator", "yourself"]
  361. }),
  362. $globals.CodeGenerator);
  363. $core.addMethod(
  364. $core.method({
  365. selector: "translator",
  366. protocol: "compiling",
  367. fn: function (){
  368. var self=this,$self=this;
  369. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  370. return $core.withContext(function($ctx1) {
  371. //>>excludeEnd("ctx");
  372. var $1;
  373. $1=$recv($globals.IRASTTranslator)._new();
  374. $recv($1)._source_($self._source());
  375. $recv($1)._theClass_($self._currentClass());
  376. return $recv($1)._yourself();
  377. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  378. }, function($ctx1) {$ctx1.fill(self,"translator",{},$globals.CodeGenerator)});
  379. //>>excludeEnd("ctx");
  380. },
  381. //>>excludeStart("ide", pragmas.excludeIdeData);
  382. args: [],
  383. source: "translator\x0a\x09^ IRASTTranslator new\x0a\x09\x09source: self source;\x0a\x09\x09theClass: self currentClass;\x0a\x09\x09yourself",
  384. referencedClasses: ["IRASTTranslator"],
  385. //>>excludeEnd("ide");
  386. messageSends: ["source:", "new", "source", "theClass:", "currentClass", "yourself"]
  387. }),
  388. $globals.CodeGenerator);
  389. $core.addClass("Compiler", $globals.Object, ["currentClass", "currentPackage", "source", "codeGeneratorClass", "codeGenerator"], "Compiler-Core");
  390. //>>excludeStart("ide", pragmas.excludeIdeData);
  391. $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`";
  392. //>>excludeEnd("ide");
  393. $core.addMethod(
  394. $core.method({
  395. selector: "ast:forClass:protocol:",
  396. protocol: "compiling",
  397. fn: function (aString,aClass,anotherString){
  398. var self=this,$self=this;
  399. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  400. return $core.withContext(function($ctx1) {
  401. //>>excludeEnd("ctx");
  402. var $early={};
  403. try {
  404. $self._source_(aString);
  405. $self._forClass_protocol_(aClass,anotherString);
  406. $recv($recv($self._codeGenerator())._transformersDictionary())._at_put_("2500-astCheckpoint",(function(x){
  407. throw $early=[x];
  408. }));
  409. $self._compileNode_($self._parse_(aString));
  410. $recv($globals.CompilerError)._signal_("AST transformation failed.");
  411. return self;
  412. }
  413. catch(e) {if(e===$early)return e[0]; throw e}
  414. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  415. }, function($ctx1) {$ctx1.fill(self,"ast:forClass:protocol:",{aString:aString,aClass:aClass,anotherString:anotherString},$globals.Compiler)});
  416. //>>excludeEnd("ctx");
  417. },
  418. //>>excludeStart("ide", pragmas.excludeIdeData);
  419. args: ["aString", "aClass", "anotherString"],
  420. source: "ast: aString forClass: aClass protocol: anotherString\x0a\x09self\x0a\x09\x09source: aString;\x0a\x09\x09forClass: aClass protocol: anotherString.\x0a\x0a\x09self codeGenerator transformersDictionary at: '2500-astCheckpoint' put: [ :x | ^x ].\x0a\x09\x0a\x09self compileNode: (self parse: aString).\x0a\x0a\x09CompilerError signal: 'AST transformation failed.'",
  421. referencedClasses: ["CompilerError"],
  422. //>>excludeEnd("ide");
  423. messageSends: ["source:", "forClass:protocol:", "at:put:", "transformersDictionary", "codeGenerator", "compileNode:", "parse:", "signal:"]
  424. }),
  425. $globals.Compiler);
  426. $core.addMethod(
  427. $core.method({
  428. selector: "cleanCodeGenerator",
  429. protocol: "accessing",
  430. fn: function (){
  431. var self=this,$self=this;
  432. $self.codeGenerator=nil;
  433. return self;
  434. },
  435. //>>excludeStart("ide", pragmas.excludeIdeData);
  436. args: [],
  437. source: "cleanCodeGenerator\x0a\x09codeGenerator := nil",
  438. referencedClasses: [],
  439. //>>excludeEnd("ide");
  440. messageSends: []
  441. }),
  442. $globals.Compiler);
  443. $core.addMethod(
  444. $core.method({
  445. selector: "codeGenerator",
  446. protocol: "accessing",
  447. fn: function (){
  448. var self=this,$self=this;
  449. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  450. return $core.withContext(function($ctx1) {
  451. //>>excludeEnd("ctx");
  452. var $1,$2,$receiver;
  453. $1=$self.codeGenerator;
  454. if(($receiver = $1) == null || $receiver.a$nil){
  455. $2=$recv($self._codeGeneratorClass())._new();
  456. $recv($2)._source_($self._source());
  457. $recv($2)._currentClass_($self._currentClass());
  458. $recv($2)._currentPackage_($self._currentPackage());
  459. $self.codeGenerator=$recv($2)._yourself();
  460. return $self.codeGenerator;
  461. } else {
  462. return $1;
  463. }
  464. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  465. }, function($ctx1) {$ctx1.fill(self,"codeGenerator",{},$globals.Compiler)});
  466. //>>excludeEnd("ctx");
  467. },
  468. //>>excludeStart("ide", pragmas.excludeIdeData);
  469. args: [],
  470. source: "codeGenerator\x0a\x09^ codeGenerator ifNil: [ codeGenerator := self codeGeneratorClass new\x0a\x09\x09\x09source: self source;\x0a\x09\x09\x09currentClass: self currentClass;\x0a\x09\x09\x09currentPackage: self currentPackage;\x0a\x09\x09\x09yourself ]",
  471. referencedClasses: [],
  472. //>>excludeEnd("ide");
  473. messageSends: ["ifNil:", "source:", "new", "codeGeneratorClass", "source", "currentClass:", "currentClass", "currentPackage:", "currentPackage", "yourself"]
  474. }),
  475. $globals.Compiler);
  476. $core.addMethod(
  477. $core.method({
  478. selector: "codeGeneratorClass",
  479. protocol: "accessing",
  480. fn: function (){
  481. var self=this,$self=this;
  482. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  483. return $core.withContext(function($ctx1) {
  484. //>>excludeEnd("ctx");
  485. var $1,$receiver;
  486. $1=$self.codeGeneratorClass;
  487. if(($receiver = $1) == null || $receiver.a$nil){
  488. return $globals.InliningCodeGenerator;
  489. } else {
  490. return $1;
  491. }
  492. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  493. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},$globals.Compiler)});
  494. //>>excludeEnd("ctx");
  495. },
  496. //>>excludeStart("ide", pragmas.excludeIdeData);
  497. args: [],
  498. source: "codeGeneratorClass\x0a\x09^ codeGeneratorClass ifNil: [ InliningCodeGenerator ]",
  499. referencedClasses: ["InliningCodeGenerator"],
  500. //>>excludeEnd("ide");
  501. messageSends: ["ifNil:"]
  502. }),
  503. $globals.Compiler);
  504. $core.addMethod(
  505. $core.method({
  506. selector: "codeGeneratorClass:",
  507. protocol: "accessing",
  508. fn: function (aClass){
  509. var self=this,$self=this;
  510. $self.codeGeneratorClass=aClass;
  511. return self;
  512. },
  513. //>>excludeStart("ide", pragmas.excludeIdeData);
  514. args: ["aClass"],
  515. source: "codeGeneratorClass: aClass\x0a\x09codeGeneratorClass := aClass",
  516. referencedClasses: [],
  517. //>>excludeEnd("ide");
  518. messageSends: []
  519. }),
  520. $globals.Compiler);
  521. $core.addMethod(
  522. $core.method({
  523. selector: "compile:forClass:protocol:",
  524. protocol: "compiling",
  525. fn: function (aString,aClass,anotherString){
  526. var self=this,$self=this;
  527. var compilationResult,result;
  528. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  529. return $core.withContext(function($ctx1) {
  530. //>>excludeEnd("ctx");
  531. var $1,$3,$2;
  532. compilationResult=$self._compileSource_forClass_protocol_(aString,aClass,anotherString);
  533. $1=compilationResult;
  534. $3=$recv(compilationResult)._at_("fn");
  535. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  536. $ctx1.sendIdx["at:"]=1;
  537. //>>excludeEnd("ctx");
  538. $2=$self._eval_forPackage_($3,$self._currentPackage());
  539. $recv($1)._at_put_("fn",$2);
  540. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  541. $ctx1.sendIdx["at:put:"]=1;
  542. //>>excludeEnd("ctx");
  543. $recv($1)._at_put_("pragmas",$recv($recv(compilationResult)._at_("pragmas"))._collect_((function(each){
  544. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  545. return $core.withContext(function($ctx2) {
  546. //>>excludeEnd("ctx");
  547. return [$recv(each)._selector(),$recv(each)._arguments()];
  548. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  549. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  550. //>>excludeEnd("ctx");
  551. })));
  552. result=$recv($recv($globals.Smalltalk)._core())._method_(compilationResult);
  553. $recv(result)._protocol_(anotherString);
  554. return result;
  555. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  556. }, function($ctx1) {$ctx1.fill(self,"compile:forClass:protocol:",{aString:aString,aClass:aClass,anotherString:anotherString,compilationResult:compilationResult,result:result},$globals.Compiler)});
  557. //>>excludeEnd("ctx");
  558. },
  559. //>>excludeStart("ide", pragmas.excludeIdeData);
  560. args: ["aString", "aClass", "anotherString"],
  561. source: "compile: aString forClass: aClass protocol: anotherString\x0a\x09| compilationResult result |\x0a\x09compilationResult :=\x0a\x09\x09self compileSource: aString forClass: aClass protocol: anotherString.\x0a\x09compilationResult\x0a\x09\x09at: #fn\x0a\x09\x09put: (self eval: (compilationResult at: #fn) forPackage: self currentPackage);\x0a\x09\x09at: #pragmas\x0a\x09\x09put: ((compilationResult at: #pragmas) collect: [ :each | { each selector. each arguments } ]).\x0a\x09result := Smalltalk core method: compilationResult.\x0a\x09result protocol: anotherString.\x0a\x09^ result",
  562. referencedClasses: ["Smalltalk"],
  563. //>>excludeEnd("ide");
  564. messageSends: ["compileSource:forClass:protocol:", "at:put:", "eval:forPackage:", "at:", "currentPackage", "collect:", "selector", "arguments", "method:", "core", "protocol:"]
  565. }),
  566. $globals.Compiler);
  567. $core.addMethod(
  568. $core.method({
  569. selector: "compileExpression:on:",
  570. protocol: "compiling",
  571. fn: function (aString,anObject){
  572. var self=this,$self=this;
  573. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  574. return $core.withContext(function($ctx1) {
  575. //>>excludeEnd("ctx");
  576. var $1;
  577. $1=$recv("xxxDoIt ^ [ ".__comma(aString)).__comma(" ] value");
  578. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  579. $ctx1.sendIdx[","]=1;
  580. //>>excludeEnd("ctx");
  581. return $self._compile_forClass_protocol_($1,$recv(anObject)._class(),"**xxxDoIt");
  582. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  583. }, function($ctx1) {$ctx1.fill(self,"compileExpression:on:",{aString:aString,anObject:anObject},$globals.Compiler)});
  584. //>>excludeEnd("ctx");
  585. },
  586. //>>excludeStart("ide", pragmas.excludeIdeData);
  587. args: ["aString", "anObject"],
  588. source: "compileExpression: aString on: anObject\x0a\x09^ self\x0a\x09\x09compile: 'xxxDoIt ^ [ ', aString, ' ] value'\x0a\x09\x09forClass: anObject class\x0a\x09\x09protocol: '**xxxDoIt'",
  589. referencedClasses: [],
  590. //>>excludeEnd("ide");
  591. messageSends: ["compile:forClass:protocol:", ",", "class"]
  592. }),
  593. $globals.Compiler);
  594. $core.addMethod(
  595. $core.method({
  596. selector: "compileNode:",
  597. protocol: "compiling",
  598. fn: function (aNode){
  599. var self=this,$self=this;
  600. var result;
  601. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  602. return $core.withContext(function($ctx1) {
  603. //>>excludeEnd("ctx");
  604. result=$recv($self._codeGenerator())._compileNode_(aNode);
  605. $self._cleanCodeGenerator();
  606. return result;
  607. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  608. }, function($ctx1) {$ctx1.fill(self,"compileNode:",{aNode:aNode,result:result},$globals.Compiler)});
  609. //>>excludeEnd("ctx");
  610. },
  611. //>>excludeStart("ide", pragmas.excludeIdeData);
  612. args: ["aNode"],
  613. source: "compileNode: aNode\x0a | result |\x0a\x09result := self codeGenerator compileNode: aNode.\x0a\x09self cleanCodeGenerator.\x0a\x09^ result",
  614. referencedClasses: [],
  615. //>>excludeEnd("ide");
  616. messageSends: ["compileNode:", "codeGenerator", "cleanCodeGenerator"]
  617. }),
  618. $globals.Compiler);
  619. $core.addMethod(
  620. $core.method({
  621. selector: "compileSource:forClass:protocol:",
  622. protocol: "compiling",
  623. fn: function (aString,aClass,anotherString){
  624. var self=this,$self=this;
  625. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  626. return $core.withContext(function($ctx1) {
  627. //>>excludeEnd("ctx");
  628. $self._source_(aString);
  629. $self._forClass_protocol_(aClass,anotherString);
  630. return $self._compileNode_($self._parse_(aString));
  631. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  632. }, function($ctx1) {$ctx1.fill(self,"compileSource:forClass:protocol:",{aString:aString,aClass:aClass,anotherString:anotherString},$globals.Compiler)});
  633. //>>excludeEnd("ctx");
  634. },
  635. //>>excludeStart("ide", pragmas.excludeIdeData);
  636. args: ["aString", "aClass", "anotherString"],
  637. source: "compileSource: aString forClass: aClass protocol: anotherString\x0a\x09^ self\x0a\x09\x09source: aString;\x0a\x09\x09forClass: aClass protocol: anotherString;\x0a\x09\x09compileNode: (self parse: aString)",
  638. referencedClasses: [],
  639. //>>excludeEnd("ide");
  640. messageSends: ["source:", "forClass:protocol:", "compileNode:", "parse:"]
  641. }),
  642. $globals.Compiler);
  643. $core.addMethod(
  644. $core.method({
  645. selector: "currentClass",
  646. protocol: "accessing",
  647. fn: function (){
  648. var self=this,$self=this;
  649. return $self.currentClass;
  650. },
  651. //>>excludeStart("ide", pragmas.excludeIdeData);
  652. args: [],
  653. source: "currentClass\x0a\x09^ currentClass",
  654. referencedClasses: [],
  655. //>>excludeEnd("ide");
  656. messageSends: []
  657. }),
  658. $globals.Compiler);
  659. $core.addMethod(
  660. $core.method({
  661. selector: "currentClass:",
  662. protocol: "accessing",
  663. fn: function (aClass){
  664. var self=this,$self=this;
  665. $self.currentClass=aClass;
  666. return self;
  667. },
  668. //>>excludeStart("ide", pragmas.excludeIdeData);
  669. args: ["aClass"],
  670. source: "currentClass: aClass\x0a\x09currentClass := aClass",
  671. referencedClasses: [],
  672. //>>excludeEnd("ide");
  673. messageSends: []
  674. }),
  675. $globals.Compiler);
  676. $core.addMethod(
  677. $core.method({
  678. selector: "currentPackage",
  679. protocol: "accessing",
  680. fn: function (){
  681. var self=this,$self=this;
  682. return $self.currentPackage;
  683. },
  684. //>>excludeStart("ide", pragmas.excludeIdeData);
  685. args: [],
  686. source: "currentPackage\x0a\x09^ currentPackage",
  687. referencedClasses: [],
  688. //>>excludeEnd("ide");
  689. messageSends: []
  690. }),
  691. $globals.Compiler);
  692. $core.addMethod(
  693. $core.method({
  694. selector: "currentPackage:",
  695. protocol: "accessing",
  696. fn: function (anObject){
  697. var self=this,$self=this;
  698. $self.currentPackage=anObject;
  699. return self;
  700. },
  701. //>>excludeStart("ide", pragmas.excludeIdeData);
  702. args: ["anObject"],
  703. source: "currentPackage: anObject\x0a\x09currentPackage := anObject",
  704. referencedClasses: [],
  705. //>>excludeEnd("ide");
  706. messageSends: []
  707. }),
  708. $globals.Compiler);
  709. $core.addMethod(
  710. $core.method({
  711. selector: "eval:",
  712. protocol: "compiling",
  713. fn: function (aString){
  714. var self=this,$self=this;
  715. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  716. return $core.withContext(function($ctx1) {
  717. //>>excludeEnd("ctx");
  718. return eval(aString);
  719. return self;
  720. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  721. }, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString},$globals.Compiler)});
  722. //>>excludeEnd("ctx");
  723. },
  724. //>>excludeStart("ide", pragmas.excludeIdeData);
  725. args: ["aString"],
  726. source: "eval: aString\x0a\x09<inlineJS: 'return eval(aString)'>",
  727. referencedClasses: [],
  728. //>>excludeEnd("ide");
  729. messageSends: []
  730. }),
  731. $globals.Compiler);
  732. $core.addMethod(
  733. $core.method({
  734. selector: "eval:forPackage:",
  735. protocol: "compiling",
  736. fn: function (aString,aPackage){
  737. var self=this,$self=this;
  738. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  739. return $core.withContext(function($ctx1) {
  740. //>>excludeEnd("ctx");
  741. var $receiver;
  742. if(($receiver = aPackage) == null || $receiver.a$nil){
  743. return $self._eval_(aString);
  744. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  745. $ctx1.sendIdx["eval:"]=1;
  746. //>>excludeEnd("ctx");
  747. } else {
  748. return $recv(aPackage)._eval_(aString);
  749. }
  750. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  751. }, function($ctx1) {$ctx1.fill(self,"eval:forPackage:",{aString:aString,aPackage:aPackage},$globals.Compiler)});
  752. //>>excludeEnd("ctx");
  753. },
  754. //>>excludeStart("ide", pragmas.excludeIdeData);
  755. args: ["aString", "aPackage"],
  756. source: "eval: aString forPackage: aPackage\x0a\x09^ aPackage\x0a\x09\x09ifNil: [ self eval: aString ]\x0a\x09\x09ifNotNil: [ aPackage eval: aString ]",
  757. referencedClasses: [],
  758. //>>excludeEnd("ide");
  759. messageSends: ["ifNil:ifNotNil:", "eval:"]
  760. }),
  761. $globals.Compiler);
  762. $core.addMethod(
  763. $core.method({
  764. selector: "evaluateExpression:",
  765. protocol: "compiling",
  766. fn: function (aString){
  767. var self=this,$self=this;
  768. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  769. return $core.withContext(function($ctx1) {
  770. //>>excludeEnd("ctx");
  771. return $self._evaluateExpression_on_(aString,$recv($globals.DoIt)._new());
  772. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  773. }, function($ctx1) {$ctx1.fill(self,"evaluateExpression:",{aString:aString},$globals.Compiler)});
  774. //>>excludeEnd("ctx");
  775. },
  776. //>>excludeStart("ide", pragmas.excludeIdeData);
  777. args: ["aString"],
  778. 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",
  779. referencedClasses: ["DoIt"],
  780. //>>excludeEnd("ide");
  781. messageSends: ["evaluateExpression:on:", "new"]
  782. }),
  783. $globals.Compiler);
  784. $core.addMethod(
  785. $core.method({
  786. selector: "evaluateExpression:on:",
  787. protocol: "compiling",
  788. fn: function (aString,anObject){
  789. var self=this,$self=this;
  790. var result,method;
  791. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  792. return $core.withContext(function($ctx1) {
  793. //>>excludeEnd("ctx");
  794. var $1;
  795. method=$self._compileExpression_on_(aString,anObject);
  796. $1=$recv(anObject)._class();
  797. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  798. $ctx1.sendIdx["class"]=1;
  799. //>>excludeEnd("ctx");
  800. $recv($1)._addCompiledMethod_(method);
  801. result=$recv(anObject)._xxxDoIt();
  802. $recv($recv(anObject)._class())._removeCompiledMethod_(method);
  803. return result;
  804. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  805. }, function($ctx1) {$ctx1.fill(self,"evaluateExpression:on:",{aString:aString,anObject:anObject,result:result,method:method},$globals.Compiler)});
  806. //>>excludeEnd("ctx");
  807. },
  808. //>>excludeStart("ide", pragmas.excludeIdeData);
  809. args: ["aString", "anObject"],
  810. 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 compileExpression: aString on: anObject.\x0a\x09anObject class addCompiledMethod: method.\x0a\x09result := anObject xxxDoIt.\x0a\x09anObject class removeCompiledMethod: method.\x0a\x09^ result",
  811. referencedClasses: [],
  812. //>>excludeEnd("ide");
  813. messageSends: ["compileExpression:on:", "addCompiledMethod:", "class", "xxxDoIt", "removeCompiledMethod:"]
  814. }),
  815. $globals.Compiler);
  816. $core.addMethod(
  817. $core.method({
  818. selector: "forClass:protocol:",
  819. protocol: "compiling",
  820. fn: function (aClass,anotherString){
  821. var self=this,$self=this;
  822. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  823. return $core.withContext(function($ctx1) {
  824. //>>excludeEnd("ctx");
  825. $self._currentPackage_($recv(aClass)._packageOfProtocol_(anotherString));
  826. $self._currentClass_(aClass);
  827. return self;
  828. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  829. }, function($ctx1) {$ctx1.fill(self,"forClass:protocol:",{aClass:aClass,anotherString:anotherString},$globals.Compiler)});
  830. //>>excludeEnd("ctx");
  831. },
  832. //>>excludeStart("ide", pragmas.excludeIdeData);
  833. args: ["aClass", "anotherString"],
  834. source: "forClass: aClass protocol: anotherString\x0a\x09self\x0a\x09\x09currentPackage: (aClass packageOfProtocol: anotherString);\x0a\x09\x09currentClass: aClass",
  835. referencedClasses: [],
  836. //>>excludeEnd("ide");
  837. messageSends: ["currentPackage:", "packageOfProtocol:", "currentClass:"]
  838. }),
  839. $globals.Compiler);
  840. $core.addMethod(
  841. $core.method({
  842. selector: "install:forClass:protocol:",
  843. protocol: "compiling",
  844. fn: function (aString,aBehavior,anotherString){
  845. var self=this,$self=this;
  846. var compiledMethod;
  847. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  848. return $core.withContext(function($ctx1) {
  849. //>>excludeEnd("ctx");
  850. compiledMethod=$self._compile_forClass_protocol_(aString,aBehavior,anotherString);
  851. $recv(aBehavior)._addCompiledMethod_(compiledMethod);
  852. return compiledMethod;
  853. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  854. }, function($ctx1) {$ctx1.fill(self,"install:forClass:protocol:",{aString:aString,aBehavior:aBehavior,anotherString:anotherString,compiledMethod:compiledMethod},$globals.Compiler)});
  855. //>>excludeEnd("ctx");
  856. },
  857. //>>excludeStart("ide", pragmas.excludeIdeData);
  858. args: ["aString", "aBehavior", "anotherString"],
  859. source: "install: aString forClass: aBehavior protocol: anotherString\x0a\x09| compiledMethod |\x0a\x09compiledMethod := self compile: aString forClass: aBehavior protocol: anotherString.\x0a\x09aBehavior addCompiledMethod: compiledMethod.\x0a\x09^ compiledMethod",
  860. referencedClasses: [],
  861. //>>excludeEnd("ide");
  862. messageSends: ["compile:forClass:protocol:", "addCompiledMethod:"]
  863. }),
  864. $globals.Compiler);
  865. $core.addMethod(
  866. $core.method({
  867. selector: "parse:",
  868. protocol: "compiling",
  869. fn: function (aString){
  870. var self=this,$self=this;
  871. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  872. return $core.withContext(function($ctx1) {
  873. //>>excludeEnd("ctx");
  874. return $recv($globals.Smalltalk)._parse_(aString);
  875. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  876. }, function($ctx1) {$ctx1.fill(self,"parse:",{aString:aString},$globals.Compiler)});
  877. //>>excludeEnd("ctx");
  878. },
  879. //>>excludeStart("ide", pragmas.excludeIdeData);
  880. args: ["aString"],
  881. source: "parse: aString\x0a\x09^ Smalltalk parse: aString",
  882. referencedClasses: ["Smalltalk"],
  883. //>>excludeEnd("ide");
  884. messageSends: ["parse:"]
  885. }),
  886. $globals.Compiler);
  887. $core.addMethod(
  888. $core.method({
  889. selector: "parseExpression:",
  890. protocol: "compiling",
  891. fn: function (aString){
  892. var self=this,$self=this;
  893. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  894. return $core.withContext(function($ctx1) {
  895. //>>excludeEnd("ctx");
  896. var $1;
  897. $1=$recv("doIt ^ [ ".__comma(aString)).__comma(" ] value");
  898. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  899. $ctx1.sendIdx[","]=1;
  900. //>>excludeEnd("ctx");
  901. return $self._parse_($1);
  902. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  903. }, function($ctx1) {$ctx1.fill(self,"parseExpression:",{aString:aString},$globals.Compiler)});
  904. //>>excludeEnd("ctx");
  905. },
  906. //>>excludeStart("ide", pragmas.excludeIdeData);
  907. args: ["aString"],
  908. source: "parseExpression: aString\x0a\x09^ self parse: 'doIt ^ [ ', aString, ' ] value'",
  909. referencedClasses: [],
  910. //>>excludeEnd("ide");
  911. messageSends: ["parse:", ","]
  912. }),
  913. $globals.Compiler);
  914. $core.addMethod(
  915. $core.method({
  916. selector: "recompile:",
  917. protocol: "compiling",
  918. fn: function (aClass){
  919. var self=this,$self=this;
  920. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  921. return $core.withContext(function($ctx1) {
  922. //>>excludeEnd("ctx");
  923. var $1,$2,$3,$receiver;
  924. $recv($recv($recv(aClass)._methodDictionary())._values())._do_displayingProgress_((function(each){
  925. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  926. return $core.withContext(function($ctx2) {
  927. //>>excludeEnd("ctx");
  928. $1=$recv($recv(each)._methodClass()).__eq(aClass);
  929. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  930. $ctx2.sendIdx["="]=1;
  931. //>>excludeEnd("ctx");
  932. if($core.assert($1)){
  933. return $self._install_forClass_protocol_($recv(each)._source(),aClass,$recv(each)._protocol());
  934. }
  935. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  936. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  937. //>>excludeEnd("ctx");
  938. }),"Recompiling ".__comma($recv(aClass)._name()));
  939. $2=$recv(aClass)._theMetaClass();
  940. if(($receiver = $2) == null || $receiver.a$nil){
  941. $2;
  942. } else {
  943. var meta;
  944. meta=$receiver;
  945. $3=$recv(meta).__eq(aClass);
  946. if(!$core.assert($3)){
  947. $self._recompile_(meta);
  948. }
  949. }
  950. return self;
  951. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  952. }, function($ctx1) {$ctx1.fill(self,"recompile:",{aClass:aClass},$globals.Compiler)});
  953. //>>excludeEnd("ctx");
  954. },
  955. //>>excludeStart("ide", pragmas.excludeIdeData);
  956. args: ["aClass"],
  957. source: "recompile: aClass\x0a\x09aClass methodDictionary values\x0a\x09\x09do: [ :each | each methodClass = aClass ifTrue: [ \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 theMetaClass ifNotNil: [ :meta |\x0a\x09\x09meta = aClass ifFalse: [ self recompile: meta ] ]",
  958. referencedClasses: [],
  959. //>>excludeEnd("ide");
  960. messageSends: ["do:displayingProgress:", "values", "methodDictionary", "ifTrue:", "=", "methodClass", "install:forClass:protocol:", "source", "protocol", ",", "name", "ifNotNil:", "theMetaClass", "ifFalse:", "recompile:"]
  961. }),
  962. $globals.Compiler);
  963. $core.addMethod(
  964. $core.method({
  965. selector: "recompileAll",
  966. protocol: "compiling",
  967. fn: function (){
  968. var self=this,$self=this;
  969. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  970. return $core.withContext(function($ctx1) {
  971. //>>excludeEnd("ctx");
  972. $recv($recv($globals.Smalltalk)._classes())._do_displayingProgress_((function(each){
  973. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  974. return $core.withContext(function($ctx2) {
  975. //>>excludeEnd("ctx");
  976. return $self._recompile_(each);
  977. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  978. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  979. //>>excludeEnd("ctx");
  980. }),"Compiling all classes...");
  981. return self;
  982. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  983. }, function($ctx1) {$ctx1.fill(self,"recompileAll",{},$globals.Compiler)});
  984. //>>excludeEnd("ctx");
  985. },
  986. //>>excludeStart("ide", pragmas.excludeIdeData);
  987. args: [],
  988. source: "recompileAll\x0a\x09Smalltalk classes \x0a\x09\x09do: [ :each | self recompile: each ]\x0a\x09\x09displayingProgress: 'Compiling all classes...'",
  989. referencedClasses: ["Smalltalk"],
  990. //>>excludeEnd("ide");
  991. messageSends: ["do:displayingProgress:", "classes", "recompile:"]
  992. }),
  993. $globals.Compiler);
  994. $core.addMethod(
  995. $core.method({
  996. selector: "source",
  997. protocol: "accessing",
  998. fn: function (){
  999. var self=this,$self=this;
  1000. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1001. return $core.withContext(function($ctx1) {
  1002. //>>excludeEnd("ctx");
  1003. var $1,$receiver;
  1004. $1=$self.source;
  1005. if(($receiver = $1) == null || $receiver.a$nil){
  1006. return "";
  1007. } else {
  1008. return $1;
  1009. }
  1010. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1011. }, function($ctx1) {$ctx1.fill(self,"source",{},$globals.Compiler)});
  1012. //>>excludeEnd("ctx");
  1013. },
  1014. //>>excludeStart("ide", pragmas.excludeIdeData);
  1015. args: [],
  1016. source: "source\x0a\x09^ source ifNil: [ '' ]",
  1017. referencedClasses: [],
  1018. //>>excludeEnd("ide");
  1019. messageSends: ["ifNil:"]
  1020. }),
  1021. $globals.Compiler);
  1022. $core.addMethod(
  1023. $core.method({
  1024. selector: "source:",
  1025. protocol: "accessing",
  1026. fn: function (aString){
  1027. var self=this,$self=this;
  1028. $self.source=aString;
  1029. return self;
  1030. },
  1031. //>>excludeStart("ide", pragmas.excludeIdeData);
  1032. args: ["aString"],
  1033. source: "source: aString\x0a\x09source := aString",
  1034. referencedClasses: [],
  1035. //>>excludeEnd("ide");
  1036. messageSends: []
  1037. }),
  1038. $globals.Compiler);
  1039. $core.addMethod(
  1040. $core.method({
  1041. selector: "eval:",
  1042. protocol: "evaluating",
  1043. fn: function (aString){
  1044. var self=this,$self=this;
  1045. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1046. return $core.withContext(function($ctx1) {
  1047. //>>excludeEnd("ctx");
  1048. return $recv($self._new())._eval_(aString);
  1049. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1050. }, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString},$globals.Compiler.a$cls)});
  1051. //>>excludeEnd("ctx");
  1052. },
  1053. //>>excludeStart("ide", pragmas.excludeIdeData);
  1054. args: ["aString"],
  1055. source: "eval: aString\x0a\x09^ self new eval: aString",
  1056. referencedClasses: [],
  1057. //>>excludeEnd("ide");
  1058. messageSends: ["eval:", "new"]
  1059. }),
  1060. $globals.Compiler.a$cls);
  1061. $core.addMethod(
  1062. $core.method({
  1063. selector: "recompile:",
  1064. protocol: "compiling",
  1065. fn: function (aClass){
  1066. var self=this,$self=this;
  1067. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1068. return $core.withContext(function($ctx1) {
  1069. //>>excludeEnd("ctx");
  1070. $recv($self._new())._recompile_(aClass);
  1071. return self;
  1072. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1073. }, function($ctx1) {$ctx1.fill(self,"recompile:",{aClass:aClass},$globals.Compiler.a$cls)});
  1074. //>>excludeEnd("ctx");
  1075. },
  1076. //>>excludeStart("ide", pragmas.excludeIdeData);
  1077. args: ["aClass"],
  1078. source: "recompile: aClass\x0a\x09self new recompile: aClass",
  1079. referencedClasses: [],
  1080. //>>excludeEnd("ide");
  1081. messageSends: ["recompile:", "new"]
  1082. }),
  1083. $globals.Compiler.a$cls);
  1084. $core.addMethod(
  1085. $core.method({
  1086. selector: "recompileAll",
  1087. protocol: "compiling",
  1088. fn: function (){
  1089. var self=this,$self=this;
  1090. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1091. return $core.withContext(function($ctx1) {
  1092. //>>excludeEnd("ctx");
  1093. $recv($recv($globals.Smalltalk)._classes())._do_((function(each){
  1094. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1095. return $core.withContext(function($ctx2) {
  1096. //>>excludeEnd("ctx");
  1097. return $self._recompile_(each);
  1098. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1099. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  1100. //>>excludeEnd("ctx");
  1101. }));
  1102. return self;
  1103. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1104. }, function($ctx1) {$ctx1.fill(self,"recompileAll",{},$globals.Compiler.a$cls)});
  1105. //>>excludeEnd("ctx");
  1106. },
  1107. //>>excludeStart("ide", pragmas.excludeIdeData);
  1108. args: [],
  1109. source: "recompileAll\x0a\x09Smalltalk classes do: [ :each |\x0a\x09\x09self recompile: each ]",
  1110. referencedClasses: ["Smalltalk"],
  1111. //>>excludeEnd("ide");
  1112. messageSends: ["do:", "classes", "recompile:"]
  1113. }),
  1114. $globals.Compiler.a$cls);
  1115. $core.addClass("DoIt", $globals.Object, [], "Compiler-Core");
  1116. //>>excludeStart("ide", pragmas.excludeIdeData);
  1117. $globals.DoIt.comment="`DoIt` is the class used to compile and evaluate expressions. See `Compiler >> evaluateExpression:`.";
  1118. //>>excludeEnd("ide");
  1119. $core.addClass("Evaluator", $globals.Object, [], "Compiler-Core");
  1120. //>>excludeStart("ide", pragmas.excludeIdeData);
  1121. $globals.Evaluator.comment="I evaluate code against a receiver, dispatching #evaluate:on: to the receiver.";
  1122. //>>excludeEnd("ide");
  1123. $core.addMethod(
  1124. $core.method({
  1125. selector: "evaluate:context:",
  1126. protocol: "evaluating",
  1127. fn: function (aString,aContext){
  1128. var self=this,$self=this;
  1129. var compiler,ast;
  1130. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1131. return $core.withContext(function($ctx1) {
  1132. //>>excludeEnd("ctx");
  1133. var $1;
  1134. var $early={};
  1135. try {
  1136. compiler=$recv($globals.Compiler)._new();
  1137. $recv((function(){
  1138. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1139. return $core.withContext(function($ctx2) {
  1140. //>>excludeEnd("ctx");
  1141. ast=$recv(compiler)._parseExpression_(aString);
  1142. return ast;
  1143. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1144. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  1145. //>>excludeEnd("ctx");
  1146. }))._on_do_($globals.Error,(function(ex){
  1147. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1148. return $core.withContext(function($ctx2) {
  1149. //>>excludeEnd("ctx");
  1150. throw $early=[$recv($globals.Terminal)._alert_($recv(ex)._messageText())];
  1151. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1152. }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1,2)});
  1153. //>>excludeEnd("ctx");
  1154. }));
  1155. $1=$recv($globals.AISemanticAnalyzer)._on_($recv($recv(aContext)._receiver())._class());
  1156. $recv($1)._context_(aContext);
  1157. $recv($1)._visit_(ast);
  1158. return $recv(aContext)._evaluateNode_(ast);
  1159. }
  1160. catch(e) {if(e===$early)return e[0]; throw e}
  1161. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1162. }, function($ctx1) {$ctx1.fill(self,"evaluate:context:",{aString:aString,aContext:aContext,compiler:compiler,ast:ast},$globals.Evaluator)});
  1163. //>>excludeEnd("ctx");
  1164. },
  1165. //>>excludeStart("ide", pragmas.excludeIdeData);
  1166. args: ["aString", "aContext"],
  1167. source: "evaluate: aString context: aContext\x0a\x09\x22Similar to #evaluate:for:, with the following differences:\x0a\x09- instead of compiling and running `aString`, `aString` is interpreted using an `ASTInterpreter`\x0a\x09- instead of evaluating against a receiver, evaluate in the context of `aContext`\x22\x0a\x0a\x09| compiler ast |\x0a\x09\x0a\x09compiler := Compiler new.\x0a\x09[ ast := compiler parseExpression: aString ] \x0a\x09\x09on: Error \x0a\x09\x09do: [ :ex | ^ Terminal alert: ex messageText ].\x0a\x09\x09\x0a\x09(AISemanticAnalyzer on: aContext receiver class)\x0a\x09\x09context: aContext;\x0a\x09\x09visit: ast.\x0a\x0a\x09^ aContext evaluateNode: ast",
  1168. referencedClasses: ["Compiler", "Error", "Terminal", "AISemanticAnalyzer"],
  1169. //>>excludeEnd("ide");
  1170. messageSends: ["new", "on:do:", "parseExpression:", "alert:", "messageText", "context:", "on:", "class", "receiver", "visit:", "evaluateNode:"]
  1171. }),
  1172. $globals.Evaluator);
  1173. $core.addMethod(
  1174. $core.method({
  1175. selector: "evaluate:for:",
  1176. protocol: "evaluating",
  1177. fn: function (aString,anObject){
  1178. var self=this,$self=this;
  1179. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1180. return $core.withContext(function($ctx1) {
  1181. //>>excludeEnd("ctx");
  1182. return $recv(anObject)._evaluate_on_(aString,self);
  1183. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1184. }, function($ctx1) {$ctx1.fill(self,"evaluate:for:",{aString:aString,anObject:anObject},$globals.Evaluator)});
  1185. //>>excludeEnd("ctx");
  1186. },
  1187. //>>excludeStart("ide", pragmas.excludeIdeData);
  1188. args: ["aString", "anObject"],
  1189. source: "evaluate: aString for: anObject\x0a\x09^ anObject evaluate: aString on: self",
  1190. referencedClasses: [],
  1191. //>>excludeEnd("ide");
  1192. messageSends: ["evaluate:on:"]
  1193. }),
  1194. $globals.Evaluator);
  1195. $core.addMethod(
  1196. $core.method({
  1197. selector: "evaluate:receiver:",
  1198. protocol: "evaluating",
  1199. fn: function (aString,anObject){
  1200. var self=this,$self=this;
  1201. var compiler;
  1202. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1203. return $core.withContext(function($ctx1) {
  1204. //>>excludeEnd("ctx");
  1205. var $early={};
  1206. try {
  1207. compiler=$recv($globals.Compiler)._new();
  1208. $recv((function(){
  1209. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1210. return $core.withContext(function($ctx2) {
  1211. //>>excludeEnd("ctx");
  1212. return $recv(compiler)._parseExpression_(aString);
  1213. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1214. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  1215. //>>excludeEnd("ctx");
  1216. }))._on_do_($globals.Error,(function(ex){
  1217. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1218. return $core.withContext(function($ctx2) {
  1219. //>>excludeEnd("ctx");
  1220. throw $early=[$recv($globals.Terminal)._alert_($recv(ex)._messageText())];
  1221. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1222. }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1,2)});
  1223. //>>excludeEnd("ctx");
  1224. }));
  1225. return $recv(compiler)._evaluateExpression_on_(aString,anObject);
  1226. }
  1227. catch(e) {if(e===$early)return e[0]; throw e}
  1228. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1229. }, function($ctx1) {$ctx1.fill(self,"evaluate:receiver:",{aString:aString,anObject:anObject,compiler:compiler},$globals.Evaluator)});
  1230. //>>excludeEnd("ctx");
  1231. },
  1232. //>>excludeStart("ide", pragmas.excludeIdeData);
  1233. args: ["aString", "anObject"],
  1234. source: "evaluate: aString receiver: anObject\x0a\x09| compiler |\x0a\x09\x0a\x09compiler := Compiler new.\x0a\x09[ compiler parseExpression: aString ] \x0a\x09\x09on: Error \x0a\x09\x09do: [ :ex | ^ Terminal alert: ex messageText ].\x0a\x0a\x09^ compiler evaluateExpression: aString on: anObject",
  1235. referencedClasses: ["Compiler", "Error", "Terminal"],
  1236. //>>excludeEnd("ide");
  1237. messageSends: ["new", "on:do:", "parseExpression:", "alert:", "messageText", "evaluateExpression:on:"]
  1238. }),
  1239. $globals.Evaluator);
  1240. $core.addMethod(
  1241. $core.method({
  1242. selector: "evaluate:for:",
  1243. protocol: "instance creation",
  1244. fn: function (aString,anObject){
  1245. var self=this,$self=this;
  1246. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1247. return $core.withContext(function($ctx1) {
  1248. //>>excludeEnd("ctx");
  1249. return $recv($self._new())._evaluate_for_(aString,anObject);
  1250. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1251. }, function($ctx1) {$ctx1.fill(self,"evaluate:for:",{aString:aString,anObject:anObject},$globals.Evaluator.a$cls)});
  1252. //>>excludeEnd("ctx");
  1253. },
  1254. //>>excludeStart("ide", pragmas.excludeIdeData);
  1255. args: ["aString", "anObject"],
  1256. source: "evaluate: aString for: anObject\x0a\x09^ self new evaluate: aString for: anObject",
  1257. referencedClasses: [],
  1258. //>>excludeEnd("ide");
  1259. messageSends: ["evaluate:for:", "new"]
  1260. }),
  1261. $globals.Evaluator.a$cls);
  1262. $core.addMethod(
  1263. $core.method({
  1264. selector: "asVariableName",
  1265. protocol: "*Compiler-Core",
  1266. fn: function (){
  1267. var self=this,$self=this;
  1268. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1269. return $core.withContext(function($ctx1) {
  1270. //>>excludeEnd("ctx");
  1271. var $1;
  1272. $1=$recv($recv($globals.Smalltalk)._reservedWords())._includes_(self);
  1273. if($core.assert($1)){
  1274. return $self.__comma("_");
  1275. } else {
  1276. return self;
  1277. }
  1278. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1279. }, function($ctx1) {$ctx1.fill(self,"asVariableName",{},$globals.String)});
  1280. //>>excludeEnd("ctx");
  1281. },
  1282. //>>excludeStart("ide", pragmas.excludeIdeData);
  1283. args: [],
  1284. source: "asVariableName\x0a\x09^ (Smalltalk reservedWords includes: self)\x0a\x09\x09ifTrue: [ self, '_' ]\x0a\x09\x09ifFalse: [ self ]",
  1285. referencedClasses: ["Smalltalk"],
  1286. //>>excludeEnd("ide");
  1287. messageSends: ["ifTrue:ifFalse:", "includes:", "reservedWords", ","]
  1288. }),
  1289. $globals.String);
  1290. });