Compiler-Core.js 41 KB

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