Compiler-Core.js 38 KB

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