Compiler-Core.js 38 KB

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