Compiler-Core.js 47 KB

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