Compiler-Core.js 46 KB

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