Compiler-Core.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341
  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. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  528. return $core.withContext(function($ctx1) {
  529. //>>excludeEnd("ctx");
  530. $self._source_(aString);
  531. $self._forClass_protocol_(aClass,anotherString);
  532. return $self._compileNode_($self._parse_(aString));
  533. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  534. }, function($ctx1) {$ctx1.fill(self,"compile:forClass:protocol:",{aString:aString,aClass:aClass,anotherString:anotherString},$globals.Compiler)});
  535. //>>excludeEnd("ctx");
  536. },
  537. //>>excludeStart("ide", pragmas.excludeIdeData);
  538. args: ["aString", "aClass", "anotherString"],
  539. source: "compile: aString forClass: aClass protocol: anotherString\x0a\x09^ self\x0a\x09\x09source: aString;\x0a\x09\x09forClass: aClass protocol: anotherString;\x0a\x09\x09compileNode: (self parse: aString)",
  540. referencedClasses: [],
  541. //>>excludeEnd("ide");
  542. messageSends: ["source:", "forClass:protocol:", "compileNode:", "parse:"]
  543. }),
  544. $globals.Compiler);
  545. $core.addMethod(
  546. $core.method({
  547. selector: "compileExpression:on:",
  548. protocol: "compiling",
  549. fn: function (aString,anObject){
  550. var self=this,$self=this;
  551. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  552. return $core.withContext(function($ctx1) {
  553. //>>excludeEnd("ctx");
  554. var $1;
  555. $1=$recv("xxxDoIt ^ [ ".__comma(aString)).__comma(" ] value");
  556. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  557. $ctx1.sendIdx[","]=1;
  558. //>>excludeEnd("ctx");
  559. return $self._compile_forClass_protocol_($1,$recv(anObject)._class(),"**xxxDoIt");
  560. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  561. }, function($ctx1) {$ctx1.fill(self,"compileExpression:on:",{aString:aString,anObject:anObject},$globals.Compiler)});
  562. //>>excludeEnd("ctx");
  563. },
  564. //>>excludeStart("ide", pragmas.excludeIdeData);
  565. args: ["aString", "anObject"],
  566. source: "compileExpression: aString on: anObject\x0a\x09^ self\x0a\x09\x09compile: 'xxxDoIt ^ [ ', aString, ' ] value'\x0a\x09\x09forClass: anObject class\x0a\x09\x09protocol: '**xxxDoIt'",
  567. referencedClasses: [],
  568. //>>excludeEnd("ide");
  569. messageSends: ["compile:forClass:protocol:", ",", "class"]
  570. }),
  571. $globals.Compiler);
  572. $core.addMethod(
  573. $core.method({
  574. selector: "compileNode:",
  575. protocol: "compiling",
  576. fn: function (aNode){
  577. var self=this,$self=this;
  578. var result;
  579. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  580. return $core.withContext(function($ctx1) {
  581. //>>excludeEnd("ctx");
  582. result=$recv($self._codeGenerator())._compileNode_(aNode);
  583. $self._cleanCodeGenerator();
  584. return result;
  585. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  586. }, function($ctx1) {$ctx1.fill(self,"compileNode:",{aNode:aNode,result:result},$globals.Compiler)});
  587. //>>excludeEnd("ctx");
  588. },
  589. //>>excludeStart("ide", pragmas.excludeIdeData);
  590. args: ["aNode"],
  591. source: "compileNode: aNode\x0a | result |\x0a\x09result := self codeGenerator compileNode: aNode.\x0a\x09self cleanCodeGenerator.\x0a\x09^ result",
  592. referencedClasses: [],
  593. //>>excludeEnd("ide");
  594. messageSends: ["compileNode:", "codeGenerator", "cleanCodeGenerator"]
  595. }),
  596. $globals.Compiler);
  597. $core.addMethod(
  598. $core.method({
  599. selector: "compiledMethodFrom:forPackage:",
  600. protocol: "compiling",
  601. fn: function (aHashedCollection,aPackage){
  602. var self=this,$self=this;
  603. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  604. return $core.withContext(function($ctx1) {
  605. //>>excludeEnd("ctx");
  606. $recv(aHashedCollection)._at_put_("fn",$self._eval_forPackage_($recv(aHashedCollection)._at_("fn"),aPackage));
  607. return $recv($recv($globals.Smalltalk)._core())._method_(aHashedCollection);
  608. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  609. }, function($ctx1) {$ctx1.fill(self,"compiledMethodFrom:forPackage:",{aHashedCollection:aHashedCollection,aPackage:aPackage},$globals.Compiler)});
  610. //>>excludeEnd("ctx");
  611. },
  612. //>>excludeStart("ide", pragmas.excludeIdeData);
  613. args: ["aHashedCollection", "aPackage"],
  614. source: "compiledMethodFrom: aHashedCollection forPackage: aPackage\x0a\x09aHashedCollection\x0a\x09\x09at: #fn\x0a\x09\x09put: (self eval: (aHashedCollection at: #fn) forPackage: aPackage).\x0a\x09^ Smalltalk core method: aHashedCollection",
  615. referencedClasses: ["Smalltalk"],
  616. //>>excludeEnd("ide");
  617. messageSends: ["at:put:", "eval:forPackage:", "at:", "method:", "core"]
  618. }),
  619. $globals.Compiler);
  620. $core.addMethod(
  621. $core.method({
  622. selector: "currentClass",
  623. protocol: "accessing",
  624. fn: function (){
  625. var self=this,$self=this;
  626. return $self.currentClass;
  627. },
  628. //>>excludeStart("ide", pragmas.excludeIdeData);
  629. args: [],
  630. source: "currentClass\x0a\x09^ currentClass",
  631. referencedClasses: [],
  632. //>>excludeEnd("ide");
  633. messageSends: []
  634. }),
  635. $globals.Compiler);
  636. $core.addMethod(
  637. $core.method({
  638. selector: "currentClass:",
  639. protocol: "accessing",
  640. fn: function (aClass){
  641. var self=this,$self=this;
  642. $self.currentClass=aClass;
  643. return self;
  644. },
  645. //>>excludeStart("ide", pragmas.excludeIdeData);
  646. args: ["aClass"],
  647. source: "currentClass: aClass\x0a\x09currentClass := aClass",
  648. referencedClasses: [],
  649. //>>excludeEnd("ide");
  650. messageSends: []
  651. }),
  652. $globals.Compiler);
  653. $core.addMethod(
  654. $core.method({
  655. selector: "currentPackage",
  656. protocol: "accessing",
  657. fn: function (){
  658. var self=this,$self=this;
  659. return $self.currentPackage;
  660. },
  661. //>>excludeStart("ide", pragmas.excludeIdeData);
  662. args: [],
  663. source: "currentPackage\x0a\x09^ currentPackage",
  664. referencedClasses: [],
  665. //>>excludeEnd("ide");
  666. messageSends: []
  667. }),
  668. $globals.Compiler);
  669. $core.addMethod(
  670. $core.method({
  671. selector: "currentPackage:",
  672. protocol: "accessing",
  673. fn: function (anObject){
  674. var self=this,$self=this;
  675. $self.currentPackage=anObject;
  676. return self;
  677. },
  678. //>>excludeStart("ide", pragmas.excludeIdeData);
  679. args: ["anObject"],
  680. source: "currentPackage: anObject\x0a\x09currentPackage := anObject",
  681. referencedClasses: [],
  682. //>>excludeEnd("ide");
  683. messageSends: []
  684. }),
  685. $globals.Compiler);
  686. $core.addMethod(
  687. $core.method({
  688. selector: "eval:",
  689. protocol: "compiling",
  690. fn: function (aString){
  691. var self=this,$self=this;
  692. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  693. return $core.withContext(function($ctx1) {
  694. //>>excludeEnd("ctx");
  695. return eval(aString);
  696. return self;
  697. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  698. }, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString},$globals.Compiler)});
  699. //>>excludeEnd("ctx");
  700. },
  701. //>>excludeStart("ide", pragmas.excludeIdeData);
  702. args: ["aString"],
  703. source: "eval: aString\x0a\x09<inlineJS: 'return eval(aString)'>",
  704. referencedClasses: [],
  705. //>>excludeEnd("ide");
  706. messageSends: []
  707. }),
  708. $globals.Compiler);
  709. $core.addMethod(
  710. $core.method({
  711. selector: "eval:forPackage:",
  712. protocol: "compiling",
  713. fn: function (aString,aPackage){
  714. var self=this,$self=this;
  715. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  716. return $core.withContext(function($ctx1) {
  717. //>>excludeEnd("ctx");
  718. var $receiver;
  719. if(($receiver = aPackage) == null || $receiver.a$nil){
  720. return $self._eval_(aString);
  721. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  722. $ctx1.sendIdx["eval:"]=1;
  723. //>>excludeEnd("ctx");
  724. } else {
  725. return $recv(aPackage)._eval_(aString);
  726. }
  727. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  728. }, function($ctx1) {$ctx1.fill(self,"eval:forPackage:",{aString:aString,aPackage:aPackage},$globals.Compiler)});
  729. //>>excludeEnd("ctx");
  730. },
  731. //>>excludeStart("ide", pragmas.excludeIdeData);
  732. args: ["aString", "aPackage"],
  733. source: "eval: aString forPackage: aPackage\x0a\x09^ aPackage\x0a\x09\x09ifNil: [ self eval: aString ]\x0a\x09\x09ifNotNil: [ aPackage eval: aString ]",
  734. referencedClasses: [],
  735. //>>excludeEnd("ide");
  736. messageSends: ["ifNil:ifNotNil:", "eval:"]
  737. }),
  738. $globals.Compiler);
  739. $core.addMethod(
  740. $core.method({
  741. selector: "evaluateExpression:",
  742. protocol: "compiling",
  743. fn: function (aString){
  744. var self=this,$self=this;
  745. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  746. return $core.withContext(function($ctx1) {
  747. //>>excludeEnd("ctx");
  748. return $self._evaluateExpression_on_(aString,$recv($globals.DoIt)._new());
  749. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  750. }, function($ctx1) {$ctx1.fill(self,"evaluateExpression:",{aString:aString},$globals.Compiler)});
  751. //>>excludeEnd("ctx");
  752. },
  753. //>>excludeStart("ide", pragmas.excludeIdeData);
  754. args: ["aString"],
  755. 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",
  756. referencedClasses: ["DoIt"],
  757. //>>excludeEnd("ide");
  758. messageSends: ["evaluateExpression:on:", "new"]
  759. }),
  760. $globals.Compiler);
  761. $core.addMethod(
  762. $core.method({
  763. selector: "evaluateExpression:on:",
  764. protocol: "compiling",
  765. fn: function (aString,anObject){
  766. var self=this,$self=this;
  767. var result,method;
  768. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  769. return $core.withContext(function($ctx1) {
  770. //>>excludeEnd("ctx");
  771. var $1,$2,$3;
  772. method=$self._compiledMethodFrom_forPackage_($self._compileExpression_on_(aString,anObject),nil);
  773. $1=$recv($globals.ClassBuilder)._new();
  774. $2=method;
  775. $3=$recv(anObject)._class();
  776. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  777. $ctx1.sendIdx["class"]=1;
  778. //>>excludeEnd("ctx");
  779. $recv($1)._installMethod_forClass_protocol_($2,$3,"**xxxDoIt");
  780. result=$recv(anObject)._xxxDoIt();
  781. $recv($recv(anObject)._class())._removeCompiledMethod_(method);
  782. return result;
  783. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  784. }, function($ctx1) {$ctx1.fill(self,"evaluateExpression:on:",{aString:aString,anObject:anObject,result:result,method:method},$globals.Compiler)});
  785. //>>excludeEnd("ctx");
  786. },
  787. //>>excludeStart("ide", pragmas.excludeIdeData);
  788. args: ["aString", "anObject"],
  789. 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 compiledMethodFrom: (self compileExpression: aString on: anObject) forPackage: nil.\x0a\x09ClassBuilder new installMethod: method forClass: anObject class protocol: '**xxxDoIt'.\x0a\x09result := anObject xxxDoIt.\x0a\x09anObject class removeCompiledMethod: method.\x0a\x09^ result",
  790. referencedClasses: ["ClassBuilder"],
  791. //>>excludeEnd("ide");
  792. messageSends: ["compiledMethodFrom:forPackage:", "compileExpression:on:", "installMethod:forClass:protocol:", "new", "class", "xxxDoIt", "removeCompiledMethod:"]
  793. }),
  794. $globals.Compiler);
  795. $core.addMethod(
  796. $core.method({
  797. selector: "forClass:protocol:",
  798. protocol: "compiling",
  799. fn: function (aClass,anotherString){
  800. var self=this,$self=this;
  801. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  802. return $core.withContext(function($ctx1) {
  803. //>>excludeEnd("ctx");
  804. $self._currentPackage_($recv(aClass)._packageOfProtocol_(anotherString));
  805. $self._currentClass_(aClass);
  806. return self;
  807. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  808. }, function($ctx1) {$ctx1.fill(self,"forClass:protocol:",{aClass:aClass,anotherString:anotherString},$globals.Compiler)});
  809. //>>excludeEnd("ctx");
  810. },
  811. //>>excludeStart("ide", pragmas.excludeIdeData);
  812. args: ["aClass", "anotherString"],
  813. source: "forClass: aClass protocol: anotherString\x0a\x09self\x0a\x09\x09currentPackage: (aClass packageOfProtocol: anotherString);\x0a\x09\x09currentClass: aClass",
  814. referencedClasses: [],
  815. //>>excludeEnd("ide");
  816. messageSends: ["currentPackage:", "packageOfProtocol:", "currentClass:"]
  817. }),
  818. $globals.Compiler);
  819. $core.addMethod(
  820. $core.method({
  821. selector: "install:forClass:protocol:",
  822. protocol: "compiling",
  823. fn: function (aString,aBehavior,anotherString){
  824. var self=this,$self=this;
  825. var compiledMethod;
  826. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  827. return $core.withContext(function($ctx1) {
  828. //>>excludeEnd("ctx");
  829. compiledMethod=$self._compiledMethodFrom_forPackage_($self._compile_forClass_protocol_(aString,aBehavior,anotherString),$recv(aBehavior)._packageOfProtocol_(anotherString));
  830. return $recv($recv($globals.ClassBuilder)._new())._installMethod_forClass_protocol_(compiledMethod,aBehavior,anotherString);
  831. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  832. }, function($ctx1) {$ctx1.fill(self,"install:forClass:protocol:",{aString:aString,aBehavior:aBehavior,anotherString:anotherString,compiledMethod:compiledMethod},$globals.Compiler)});
  833. //>>excludeEnd("ctx");
  834. },
  835. //>>excludeStart("ide", pragmas.excludeIdeData);
  836. args: ["aString", "aBehavior", "anotherString"],
  837. source: "install: aString forClass: aBehavior protocol: anotherString\x0a\x09| compiledMethod |\x0a\x09compiledMethod := self\x0a\x09\x09compiledMethodFrom: (self compile: aString forClass: aBehavior protocol: anotherString)\x0a\x09\x09forPackage: (aBehavior packageOfProtocol: anotherString).\x0a\x09^ ClassBuilder new\x0a\x09\x09installMethod: compiledMethod\x0a\x09\x09forClass: aBehavior\x0a\x09\x09protocol: anotherString",
  838. referencedClasses: ["ClassBuilder"],
  839. //>>excludeEnd("ide");
  840. messageSends: ["compiledMethodFrom:forPackage:", "compile:forClass:protocol:", "packageOfProtocol:", "installMethod:forClass:protocol:", "new"]
  841. }),
  842. $globals.Compiler);
  843. $core.addMethod(
  844. $core.method({
  845. selector: "parse:",
  846. protocol: "compiling",
  847. fn: function (aString){
  848. var self=this,$self=this;
  849. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  850. return $core.withContext(function($ctx1) {
  851. //>>excludeEnd("ctx");
  852. return $recv($globals.Smalltalk)._parse_(aString);
  853. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  854. }, function($ctx1) {$ctx1.fill(self,"parse:",{aString:aString},$globals.Compiler)});
  855. //>>excludeEnd("ctx");
  856. },
  857. //>>excludeStart("ide", pragmas.excludeIdeData);
  858. args: ["aString"],
  859. source: "parse: aString\x0a\x09^ Smalltalk parse: aString",
  860. referencedClasses: ["Smalltalk"],
  861. //>>excludeEnd("ide");
  862. messageSends: ["parse:"]
  863. }),
  864. $globals.Compiler);
  865. $core.addMethod(
  866. $core.method({
  867. selector: "parseExpression:",
  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. var $1;
  875. $1=$recv("doIt ^ [ ".__comma(aString)).__comma(" ] value");
  876. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  877. $ctx1.sendIdx[","]=1;
  878. //>>excludeEnd("ctx");
  879. return $self._parse_($1);
  880. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  881. }, function($ctx1) {$ctx1.fill(self,"parseExpression:",{aString:aString},$globals.Compiler)});
  882. //>>excludeEnd("ctx");
  883. },
  884. //>>excludeStart("ide", pragmas.excludeIdeData);
  885. args: ["aString"],
  886. source: "parseExpression: aString\x0a\x09^ self parse: 'doIt ^ [ ', aString, ' ] value'",
  887. referencedClasses: [],
  888. //>>excludeEnd("ide");
  889. messageSends: ["parse:", ","]
  890. }),
  891. $globals.Compiler);
  892. $core.addMethod(
  893. $core.method({
  894. selector: "recompile:",
  895. protocol: "compiling",
  896. fn: function (aClass){
  897. var self=this,$self=this;
  898. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  899. return $core.withContext(function($ctx1) {
  900. //>>excludeEnd("ctx");
  901. var $1,$2,$3,$receiver;
  902. $recv($recv($recv(aClass)._methodDictionary())._values())._do_displayingProgress_((function(each){
  903. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  904. return $core.withContext(function($ctx2) {
  905. //>>excludeEnd("ctx");
  906. $1=$recv($recv(each)._methodClass()).__eq(aClass);
  907. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  908. $ctx2.sendIdx["="]=1;
  909. //>>excludeEnd("ctx");
  910. if($core.assert($1)){
  911. return $self._install_forClass_protocol_($recv(each)._source(),aClass,$recv(each)._protocol());
  912. }
  913. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  914. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  915. //>>excludeEnd("ctx");
  916. }),"Recompiling ".__comma($recv(aClass)._name()));
  917. $2=$recv(aClass)._theMetaClass();
  918. if(($receiver = $2) == null || $receiver.a$nil){
  919. $2;
  920. } else {
  921. var meta;
  922. meta=$receiver;
  923. $3=$recv(meta).__eq(aClass);
  924. if(!$core.assert($3)){
  925. $self._recompile_(meta);
  926. }
  927. }
  928. return self;
  929. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  930. }, function($ctx1) {$ctx1.fill(self,"recompile:",{aClass:aClass},$globals.Compiler)});
  931. //>>excludeEnd("ctx");
  932. },
  933. //>>excludeStart("ide", pragmas.excludeIdeData);
  934. args: ["aClass"],
  935. 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 ] ]",
  936. referencedClasses: [],
  937. //>>excludeEnd("ide");
  938. messageSends: ["do:displayingProgress:", "values", "methodDictionary", "ifTrue:", "=", "methodClass", "install:forClass:protocol:", "source", "protocol", ",", "name", "ifNotNil:", "theMetaClass", "ifFalse:", "recompile:"]
  939. }),
  940. $globals.Compiler);
  941. $core.addMethod(
  942. $core.method({
  943. selector: "recompileAll",
  944. protocol: "compiling",
  945. fn: function (){
  946. var self=this,$self=this;
  947. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  948. return $core.withContext(function($ctx1) {
  949. //>>excludeEnd("ctx");
  950. $recv($recv($globals.Smalltalk)._classes())._do_displayingProgress_((function(each){
  951. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  952. return $core.withContext(function($ctx2) {
  953. //>>excludeEnd("ctx");
  954. return $self._recompile_(each);
  955. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  956. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  957. //>>excludeEnd("ctx");
  958. }),"Compiling all classes...");
  959. return self;
  960. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  961. }, function($ctx1) {$ctx1.fill(self,"recompileAll",{},$globals.Compiler)});
  962. //>>excludeEnd("ctx");
  963. },
  964. //>>excludeStart("ide", pragmas.excludeIdeData);
  965. args: [],
  966. source: "recompileAll\x0a\x09Smalltalk classes \x0a\x09\x09do: [ :each | self recompile: each ]\x0a\x09\x09displayingProgress: 'Compiling all classes...'",
  967. referencedClasses: ["Smalltalk"],
  968. //>>excludeEnd("ide");
  969. messageSends: ["do:displayingProgress:", "classes", "recompile:"]
  970. }),
  971. $globals.Compiler);
  972. $core.addMethod(
  973. $core.method({
  974. selector: "source",
  975. protocol: "accessing",
  976. fn: function (){
  977. var self=this,$self=this;
  978. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  979. return $core.withContext(function($ctx1) {
  980. //>>excludeEnd("ctx");
  981. var $1,$receiver;
  982. $1=$self.source;
  983. if(($receiver = $1) == null || $receiver.a$nil){
  984. return "";
  985. } else {
  986. return $1;
  987. }
  988. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  989. }, function($ctx1) {$ctx1.fill(self,"source",{},$globals.Compiler)});
  990. //>>excludeEnd("ctx");
  991. },
  992. //>>excludeStart("ide", pragmas.excludeIdeData);
  993. args: [],
  994. source: "source\x0a\x09^ source ifNil: [ '' ]",
  995. referencedClasses: [],
  996. //>>excludeEnd("ide");
  997. messageSends: ["ifNil:"]
  998. }),
  999. $globals.Compiler);
  1000. $core.addMethod(
  1001. $core.method({
  1002. selector: "source:",
  1003. protocol: "accessing",
  1004. fn: function (aString){
  1005. var self=this,$self=this;
  1006. $self.source=aString;
  1007. return self;
  1008. },
  1009. //>>excludeStart("ide", pragmas.excludeIdeData);
  1010. args: ["aString"],
  1011. source: "source: aString\x0a\x09source := aString",
  1012. referencedClasses: [],
  1013. //>>excludeEnd("ide");
  1014. messageSends: []
  1015. }),
  1016. $globals.Compiler);
  1017. $core.addMethod(
  1018. $core.method({
  1019. selector: "eval:",
  1020. protocol: "evaluating",
  1021. fn: function (aString){
  1022. var self=this,$self=this;
  1023. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1024. return $core.withContext(function($ctx1) {
  1025. //>>excludeEnd("ctx");
  1026. return $recv($self._new())._eval_(aString);
  1027. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1028. }, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString},$globals.Compiler.a$cls)});
  1029. //>>excludeEnd("ctx");
  1030. },
  1031. //>>excludeStart("ide", pragmas.excludeIdeData);
  1032. args: ["aString"],
  1033. source: "eval: aString\x0a\x09^ self new eval: aString",
  1034. referencedClasses: [],
  1035. //>>excludeEnd("ide");
  1036. messageSends: ["eval:", "new"]
  1037. }),
  1038. $globals.Compiler.a$cls);
  1039. $core.addMethod(
  1040. $core.method({
  1041. selector: "recompile:",
  1042. protocol: "compiling",
  1043. fn: function (aClass){
  1044. var self=this,$self=this;
  1045. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1046. return $core.withContext(function($ctx1) {
  1047. //>>excludeEnd("ctx");
  1048. $recv($self._new())._recompile_(aClass);
  1049. return self;
  1050. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1051. }, function($ctx1) {$ctx1.fill(self,"recompile:",{aClass:aClass},$globals.Compiler.a$cls)});
  1052. //>>excludeEnd("ctx");
  1053. },
  1054. //>>excludeStart("ide", pragmas.excludeIdeData);
  1055. args: ["aClass"],
  1056. source: "recompile: aClass\x0a\x09self new recompile: aClass",
  1057. referencedClasses: [],
  1058. //>>excludeEnd("ide");
  1059. messageSends: ["recompile:", "new"]
  1060. }),
  1061. $globals.Compiler.a$cls);
  1062. $core.addMethod(
  1063. $core.method({
  1064. selector: "recompileAll",
  1065. protocol: "compiling",
  1066. fn: function (){
  1067. var self=this,$self=this;
  1068. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1069. return $core.withContext(function($ctx1) {
  1070. //>>excludeEnd("ctx");
  1071. $recv($recv($globals.Smalltalk)._classes())._do_((function(each){
  1072. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1073. return $core.withContext(function($ctx2) {
  1074. //>>excludeEnd("ctx");
  1075. return $self._recompile_(each);
  1076. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1077. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  1078. //>>excludeEnd("ctx");
  1079. }));
  1080. return self;
  1081. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1082. }, function($ctx1) {$ctx1.fill(self,"recompileAll",{},$globals.Compiler.a$cls)});
  1083. //>>excludeEnd("ctx");
  1084. },
  1085. //>>excludeStart("ide", pragmas.excludeIdeData);
  1086. args: [],
  1087. source: "recompileAll\x0a\x09Smalltalk classes do: [ :each |\x0a\x09\x09self recompile: each ]",
  1088. referencedClasses: ["Smalltalk"],
  1089. //>>excludeEnd("ide");
  1090. messageSends: ["do:", "classes", "recompile:"]
  1091. }),
  1092. $globals.Compiler.a$cls);
  1093. $core.addClass("DoIt", $globals.Object, [], "Compiler-Core");
  1094. //>>excludeStart("ide", pragmas.excludeIdeData);
  1095. $globals.DoIt.comment="`DoIt` is the class used to compile and evaluate expressions. See `Compiler >> evaluateExpression:`.";
  1096. //>>excludeEnd("ide");
  1097. $core.addClass("Evaluator", $globals.Object, [], "Compiler-Core");
  1098. //>>excludeStart("ide", pragmas.excludeIdeData);
  1099. $globals.Evaluator.comment="I evaluate code against a receiver, dispatching #evaluate:on: to the receiver.";
  1100. //>>excludeEnd("ide");
  1101. $core.addMethod(
  1102. $core.method({
  1103. selector: "evaluate:context:",
  1104. protocol: "evaluating",
  1105. fn: function (aString,aContext){
  1106. var self=this,$self=this;
  1107. var compiler,ast;
  1108. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1109. return $core.withContext(function($ctx1) {
  1110. //>>excludeEnd("ctx");
  1111. var $1;
  1112. var $early={};
  1113. try {
  1114. compiler=$recv($globals.Compiler)._new();
  1115. $recv((function(){
  1116. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1117. return $core.withContext(function($ctx2) {
  1118. //>>excludeEnd("ctx");
  1119. ast=$recv(compiler)._parseExpression_(aString);
  1120. return ast;
  1121. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1122. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  1123. //>>excludeEnd("ctx");
  1124. }))._on_do_($globals.Error,(function(ex){
  1125. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1126. return $core.withContext(function($ctx2) {
  1127. //>>excludeEnd("ctx");
  1128. throw $early=[$recv($globals.Terminal)._alert_($recv(ex)._messageText())];
  1129. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1130. }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1,2)});
  1131. //>>excludeEnd("ctx");
  1132. }));
  1133. $1=$recv($globals.AISemanticAnalyzer)._on_($recv($recv(aContext)._receiver())._class());
  1134. $recv($1)._context_(aContext);
  1135. $recv($1)._visit_(ast);
  1136. return $recv(aContext)._evaluateNode_(ast);
  1137. }
  1138. catch(e) {if(e===$early)return e[0]; throw e}
  1139. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1140. }, function($ctx1) {$ctx1.fill(self,"evaluate:context:",{aString:aString,aContext:aContext,compiler:compiler,ast:ast},$globals.Evaluator)});
  1141. //>>excludeEnd("ctx");
  1142. },
  1143. //>>excludeStart("ide", pragmas.excludeIdeData);
  1144. args: ["aString", "aContext"],
  1145. 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",
  1146. referencedClasses: ["Compiler", "Error", "Terminal", "AISemanticAnalyzer"],
  1147. //>>excludeEnd("ide");
  1148. messageSends: ["new", "on:do:", "parseExpression:", "alert:", "messageText", "context:", "on:", "class", "receiver", "visit:", "evaluateNode:"]
  1149. }),
  1150. $globals.Evaluator);
  1151. $core.addMethod(
  1152. $core.method({
  1153. selector: "evaluate:for:",
  1154. protocol: "evaluating",
  1155. fn: function (aString,anObject){
  1156. var self=this,$self=this;
  1157. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1158. return $core.withContext(function($ctx1) {
  1159. //>>excludeEnd("ctx");
  1160. return $recv(anObject)._evaluate_on_(aString,self);
  1161. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1162. }, function($ctx1) {$ctx1.fill(self,"evaluate:for:",{aString:aString,anObject:anObject},$globals.Evaluator)});
  1163. //>>excludeEnd("ctx");
  1164. },
  1165. //>>excludeStart("ide", pragmas.excludeIdeData);
  1166. args: ["aString", "anObject"],
  1167. source: "evaluate: aString for: anObject\x0a\x09^ anObject evaluate: aString on: self",
  1168. referencedClasses: [],
  1169. //>>excludeEnd("ide");
  1170. messageSends: ["evaluate:on:"]
  1171. }),
  1172. $globals.Evaluator);
  1173. $core.addMethod(
  1174. $core.method({
  1175. selector: "evaluate:receiver:",
  1176. protocol: "evaluating",
  1177. fn: function (aString,anObject){
  1178. var self=this,$self=this;
  1179. var compiler;
  1180. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1181. return $core.withContext(function($ctx1) {
  1182. //>>excludeEnd("ctx");
  1183. var $early={};
  1184. try {
  1185. compiler=$recv($globals.Compiler)._new();
  1186. $recv((function(){
  1187. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1188. return $core.withContext(function($ctx2) {
  1189. //>>excludeEnd("ctx");
  1190. return $recv(compiler)._parseExpression_(aString);
  1191. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1192. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  1193. //>>excludeEnd("ctx");
  1194. }))._on_do_($globals.Error,(function(ex){
  1195. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1196. return $core.withContext(function($ctx2) {
  1197. //>>excludeEnd("ctx");
  1198. throw $early=[$recv($globals.Terminal)._alert_($recv(ex)._messageText())];
  1199. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1200. }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1,2)});
  1201. //>>excludeEnd("ctx");
  1202. }));
  1203. return $recv(compiler)._evaluateExpression_on_(aString,anObject);
  1204. }
  1205. catch(e) {if(e===$early)return e[0]; throw e}
  1206. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1207. }, function($ctx1) {$ctx1.fill(self,"evaluate:receiver:",{aString:aString,anObject:anObject,compiler:compiler},$globals.Evaluator)});
  1208. //>>excludeEnd("ctx");
  1209. },
  1210. //>>excludeStart("ide", pragmas.excludeIdeData);
  1211. args: ["aString", "anObject"],
  1212. 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",
  1213. referencedClasses: ["Compiler", "Error", "Terminal"],
  1214. //>>excludeEnd("ide");
  1215. messageSends: ["new", "on:do:", "parseExpression:", "alert:", "messageText", "evaluateExpression:on:"]
  1216. }),
  1217. $globals.Evaluator);
  1218. $core.addMethod(
  1219. $core.method({
  1220. selector: "evaluate:for:",
  1221. protocol: "instance creation",
  1222. fn: function (aString,anObject){
  1223. var self=this,$self=this;
  1224. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1225. return $core.withContext(function($ctx1) {
  1226. //>>excludeEnd("ctx");
  1227. return $recv($self._new())._evaluate_for_(aString,anObject);
  1228. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1229. }, function($ctx1) {$ctx1.fill(self,"evaluate:for:",{aString:aString,anObject:anObject},$globals.Evaluator.a$cls)});
  1230. //>>excludeEnd("ctx");
  1231. },
  1232. //>>excludeStart("ide", pragmas.excludeIdeData);
  1233. args: ["aString", "anObject"],
  1234. source: "evaluate: aString for: anObject\x0a\x09^ self new evaluate: aString for: anObject",
  1235. referencedClasses: [],
  1236. //>>excludeEnd("ide");
  1237. messageSends: ["evaluate:for:", "new"]
  1238. }),
  1239. $globals.Evaluator.a$cls);
  1240. $core.addMethod(
  1241. $core.method({
  1242. selector: "asVariableName",
  1243. protocol: "*Compiler-Core",
  1244. fn: function (){
  1245. var self=this,$self=this;
  1246. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1247. return $core.withContext(function($ctx1) {
  1248. //>>excludeEnd("ctx");
  1249. var $1;
  1250. $1=$recv($recv($globals.Smalltalk)._reservedWords())._includes_(self);
  1251. if($core.assert($1)){
  1252. return $self.__comma("_");
  1253. } else {
  1254. return self;
  1255. }
  1256. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1257. }, function($ctx1) {$ctx1.fill(self,"asVariableName",{},$globals.String)});
  1258. //>>excludeEnd("ctx");
  1259. },
  1260. //>>excludeStart("ide", pragmas.excludeIdeData);
  1261. args: [],
  1262. source: "asVariableName\x0a\x09^ (Smalltalk reservedWords includes: self)\x0a\x09\x09ifTrue: [ self, '_' ]\x0a\x09\x09ifFalse: [ self ]",
  1263. referencedClasses: ["Smalltalk"],
  1264. //>>excludeEnd("ide");
  1265. messageSends: ["ifTrue:ifFalse:", "includes:", "reservedWords", ","]
  1266. }),
  1267. $globals.String);
  1268. });