Compiler-Core.js 42 KB

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