Compiler-Core.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121
  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($globals.SemanticAnalyzer)._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^ (SemanticAnalyzer on: self currentClass)\x0a\x09\x09thePackage: self currentPackage;\x0a\x09\x09yourself",
  249. referencedClasses: ["SemanticAnalyzer"],
  250. //>>excludeEnd("ide");
  251. messageSends: ["thePackage:", "on:", "currentClass", "currentPackage", "yourself"]
  252. }),
  253. $globals.CodeGenerator);
  254. $core.addMethod(
  255. $core.method({
  256. selector: "translator",
  257. protocol: 'compiling',
  258. fn: function (){
  259. var self=this;
  260. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  261. return $core.withContext(function($ctx1) {
  262. //>>excludeEnd("ctx");
  263. var $1;
  264. $1=$recv($globals.IRASTTranslator)._new();
  265. $recv($1)._source_(self._source());
  266. $recv($1)._theClass_(self._currentClass());
  267. return $recv($1)._yourself();
  268. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  269. }, function($ctx1) {$ctx1.fill(self,"translator",{},$globals.CodeGenerator)});
  270. //>>excludeEnd("ctx");
  271. },
  272. //>>excludeStart("ide", pragmas.excludeIdeData);
  273. args: [],
  274. source: "translator\x0a\x09^ IRASTTranslator new\x0a\x09\x09source: self source;\x0a\x09\x09theClass: self currentClass;\x0a\x09\x09yourself",
  275. referencedClasses: ["IRASTTranslator"],
  276. //>>excludeEnd("ide");
  277. messageSends: ["source:", "new", "source", "theClass:", "currentClass", "yourself"]
  278. }),
  279. $globals.CodeGenerator);
  280. $core.addClass('Compiler', $globals.Object, ['currentClass', 'currentPackage', 'source', 'unknownVariables', 'codeGeneratorClass'], 'Compiler-Core');
  281. //>>excludeStart("ide", pragmas.excludeIdeData);
  282. $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`";
  283. //>>excludeEnd("ide");
  284. $core.addMethod(
  285. $core.method({
  286. selector: "codeGeneratorClass",
  287. protocol: 'accessing',
  288. fn: function (){
  289. var self=this;
  290. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  291. return $core.withContext(function($ctx1) {
  292. //>>excludeEnd("ctx");
  293. var $1,$receiver;
  294. $1=self["@codeGeneratorClass"];
  295. if(($receiver = $1) == null || $receiver.isNil){
  296. return $globals.InliningCodeGenerator;
  297. } else {
  298. return $1;
  299. };
  300. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  301. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{},$globals.Compiler)});
  302. //>>excludeEnd("ctx");
  303. },
  304. //>>excludeStart("ide", pragmas.excludeIdeData);
  305. args: [],
  306. source: "codeGeneratorClass\x0a\x09^ codeGeneratorClass ifNil: [ InliningCodeGenerator ]",
  307. referencedClasses: ["InliningCodeGenerator"],
  308. //>>excludeEnd("ide");
  309. messageSends: ["ifNil:"]
  310. }),
  311. $globals.Compiler);
  312. $core.addMethod(
  313. $core.method({
  314. selector: "codeGeneratorClass:",
  315. protocol: 'accessing',
  316. fn: function (aClass){
  317. var self=this;
  318. self["@codeGeneratorClass"]=aClass;
  319. return self;
  320. },
  321. //>>excludeStart("ide", pragmas.excludeIdeData);
  322. args: ["aClass"],
  323. source: "codeGeneratorClass: aClass\x0a\x09codeGeneratorClass := aClass",
  324. referencedClasses: [],
  325. //>>excludeEnd("ide");
  326. messageSends: []
  327. }),
  328. $globals.Compiler);
  329. $core.addMethod(
  330. $core.method({
  331. selector: "compile:forClass:protocol:",
  332. protocol: 'compiling',
  333. fn: function (aString,aClass,anotherString){
  334. var self=this;
  335. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  336. return $core.withContext(function($ctx1) {
  337. //>>excludeEnd("ctx");
  338. self._source_(aString);
  339. return self._compileNode_forClass_package_(self._parse_(aString),aClass,$recv(aClass)._packageOfProtocol_(anotherString));
  340. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  341. }, function($ctx1) {$ctx1.fill(self,"compile:forClass:protocol:",{aString:aString,aClass:aClass,anotherString:anotherString},$globals.Compiler)});
  342. //>>excludeEnd("ctx");
  343. },
  344. //>>excludeStart("ide", pragmas.excludeIdeData);
  345. args: ["aString", "aClass", "anotherString"],
  346. 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)",
  347. referencedClasses: [],
  348. //>>excludeEnd("ide");
  349. messageSends: ["source:", "compileNode:forClass:package:", "parse:", "packageOfProtocol:"]
  350. }),
  351. $globals.Compiler);
  352. $core.addMethod(
  353. $core.method({
  354. selector: "compileExpression:on:",
  355. protocol: 'compiling',
  356. fn: function (aString,anObject){
  357. var self=this;
  358. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  359. return $core.withContext(function($ctx1) {
  360. //>>excludeEnd("ctx");
  361. var $1;
  362. $1=$recv("xxxDoIt ^ [ ".__comma(aString)).__comma(" ] value");
  363. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  364. $ctx1.sendIdx[","]=1;
  365. //>>excludeEnd("ctx");
  366. return self._compile_forClass_protocol_($1,$recv(anObject)._class(),"**xxxDoIt");
  367. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  368. }, function($ctx1) {$ctx1.fill(self,"compileExpression:on:",{aString:aString,anObject:anObject},$globals.Compiler)});
  369. //>>excludeEnd("ctx");
  370. },
  371. //>>excludeStart("ide", pragmas.excludeIdeData);
  372. args: ["aString", "anObject"],
  373. source: "compileExpression: aString on: anObject\x0a\x09^ self\x0a\x09\x09compile: 'xxxDoIt ^ [ ', aString, ' ] value'\x0a\x09\x09forClass: anObject class\x0a\x09\x09protocol: '**xxxDoIt'",
  374. referencedClasses: [],
  375. //>>excludeEnd("ide");
  376. messageSends: ["compile:forClass:protocol:", ",", "class"]
  377. }),
  378. $globals.Compiler);
  379. $core.addMethod(
  380. $core.method({
  381. selector: "compileNode:",
  382. protocol: 'compiling',
  383. fn: function (aNode){
  384. var self=this;
  385. var generator,result;
  386. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  387. return $core.withContext(function($ctx1) {
  388. //>>excludeEnd("ctx");
  389. var $1;
  390. generator=$recv(self._codeGeneratorClass())._new();
  391. $1=generator;
  392. $recv($1)._source_(self._source());
  393. $recv($1)._currentClass_(self._currentClass());
  394. $recv($1)._currentPackage_(self._currentPackage());
  395. result=$recv(generator)._compileNode_(aNode);
  396. self._unknownVariables_([]);
  397. return result;
  398. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  399. }, function($ctx1) {$ctx1.fill(self,"compileNode:",{aNode:aNode,generator:generator,result:result},$globals.Compiler)});
  400. //>>excludeEnd("ctx");
  401. },
  402. //>>excludeStart("ide", pragmas.excludeIdeData);
  403. args: ["aNode"],
  404. 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",
  405. referencedClasses: [],
  406. //>>excludeEnd("ide");
  407. messageSends: ["new", "codeGeneratorClass", "source:", "source", "currentClass:", "currentClass", "currentPackage:", "currentPackage", "compileNode:", "unknownVariables:"]
  408. }),
  409. $globals.Compiler);
  410. $core.addMethod(
  411. $core.method({
  412. selector: "compileNode:forClass:package:",
  413. protocol: 'compiling',
  414. fn: function (aNode,aClass,aPackage){
  415. var self=this;
  416. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  417. return $core.withContext(function($ctx1) {
  418. //>>excludeEnd("ctx");
  419. self._currentClass_(aClass);
  420. self._currentPackage_(aPackage);
  421. return self._compileNode_(aNode);
  422. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  423. }, function($ctx1) {$ctx1.fill(self,"compileNode:forClass:package:",{aNode:aNode,aClass:aClass,aPackage:aPackage},$globals.Compiler)});
  424. //>>excludeEnd("ctx");
  425. },
  426. //>>excludeStart("ide", pragmas.excludeIdeData);
  427. args: ["aNode", "aClass", "aPackage"],
  428. source: "compileNode: aNode forClass: aClass package: aPackage\x0a\x09^ self\x0a\x09\x09currentClass: aClass;\x0a\x09\x09currentPackage: aPackage;\x0a\x09\x09compileNode: aNode",
  429. referencedClasses: [],
  430. //>>excludeEnd("ide");
  431. messageSends: ["currentClass:", "currentPackage:", "compileNode:"]
  432. }),
  433. $globals.Compiler);
  434. $core.addMethod(
  435. $core.method({
  436. selector: "currentClass",
  437. protocol: 'accessing',
  438. fn: function (){
  439. var self=this;
  440. return self["@currentClass"];
  441. },
  442. //>>excludeStart("ide", pragmas.excludeIdeData);
  443. args: [],
  444. source: "currentClass\x0a\x09^ currentClass",
  445. referencedClasses: [],
  446. //>>excludeEnd("ide");
  447. messageSends: []
  448. }),
  449. $globals.Compiler);
  450. $core.addMethod(
  451. $core.method({
  452. selector: "currentClass:",
  453. protocol: 'accessing',
  454. fn: function (aClass){
  455. var self=this;
  456. self["@currentClass"]=aClass;
  457. return self;
  458. },
  459. //>>excludeStart("ide", pragmas.excludeIdeData);
  460. args: ["aClass"],
  461. source: "currentClass: aClass\x0a\x09currentClass := aClass",
  462. referencedClasses: [],
  463. //>>excludeEnd("ide");
  464. messageSends: []
  465. }),
  466. $globals.Compiler);
  467. $core.addMethod(
  468. $core.method({
  469. selector: "currentPackage",
  470. protocol: 'accessing',
  471. fn: function (){
  472. var self=this;
  473. return self["@currentPackage"];
  474. },
  475. //>>excludeStart("ide", pragmas.excludeIdeData);
  476. args: [],
  477. source: "currentPackage\x0a\x09^ currentPackage",
  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 (anObject){
  488. var self=this;
  489. self["@currentPackage"]=anObject;
  490. return self;
  491. },
  492. //>>excludeStart("ide", pragmas.excludeIdeData);
  493. args: ["anObject"],
  494. source: "currentPackage: anObject\x0a\x09currentPackage := anObject",
  495. referencedClasses: [],
  496. //>>excludeEnd("ide");
  497. messageSends: []
  498. }),
  499. $globals.Compiler);
  500. $core.addMethod(
  501. $core.method({
  502. selector: "eval:",
  503. protocol: 'compiling',
  504. fn: function (aString){
  505. var self=this;
  506. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  507. return $core.withContext(function($ctx1) {
  508. //>>excludeEnd("ctx");
  509. return eval(aString);
  510. return self;
  511. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  512. }, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString},$globals.Compiler)});
  513. //>>excludeEnd("ctx");
  514. },
  515. //>>excludeStart("ide", pragmas.excludeIdeData);
  516. args: ["aString"],
  517. source: "eval: aString\x0a\x09<inlineJS: 'return eval(aString)'>",
  518. referencedClasses: [],
  519. //>>excludeEnd("ide");
  520. messageSends: []
  521. }),
  522. $globals.Compiler);
  523. $core.addMethod(
  524. $core.method({
  525. selector: "eval:forPackage:",
  526. protocol: 'compiling',
  527. fn: function (aString,aPackage){
  528. var self=this;
  529. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  530. return $core.withContext(function($ctx1) {
  531. //>>excludeEnd("ctx");
  532. return aPackage && aPackage.innerEval
  533. ? aPackage.innerEval(aString)
  534. : eval(aString);
  535. return self;
  536. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  537. }, function($ctx1) {$ctx1.fill(self,"eval:forPackage:",{aString:aString,aPackage:aPackage},$globals.Compiler)});
  538. //>>excludeEnd("ctx");
  539. },
  540. //>>excludeStart("ide", pragmas.excludeIdeData);
  541. args: ["aString", "aPackage"],
  542. source: "eval: aString forPackage: aPackage\x0a\x09<inlineJS: 'return aPackage && aPackage.innerEval\x0a\x09\x09? aPackage.innerEval(aString)\x0a\x09\x09: eval(aString)'>",
  543. referencedClasses: [],
  544. //>>excludeEnd("ide");
  545. messageSends: []
  546. }),
  547. $globals.Compiler);
  548. $core.addMethod(
  549. $core.method({
  550. selector: "evaluateExpression:",
  551. protocol: 'compiling',
  552. fn: function (aString){
  553. var self=this;
  554. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  555. return $core.withContext(function($ctx1) {
  556. //>>excludeEnd("ctx");
  557. return self._evaluateExpression_on_(aString,$recv($globals.DoIt)._new());
  558. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  559. }, function($ctx1) {$ctx1.fill(self,"evaluateExpression:",{aString:aString},$globals.Compiler)});
  560. //>>excludeEnd("ctx");
  561. },
  562. //>>excludeStart("ide", pragmas.excludeIdeData);
  563. args: ["aString"],
  564. 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",
  565. referencedClasses: ["DoIt"],
  566. //>>excludeEnd("ide");
  567. messageSends: ["evaluateExpression:on:", "new"]
  568. }),
  569. $globals.Compiler);
  570. $core.addMethod(
  571. $core.method({
  572. selector: "evaluateExpression:on:",
  573. protocol: 'compiling',
  574. fn: function (aString,anObject){
  575. var self=this;
  576. var result,method;
  577. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  578. return $core.withContext(function($ctx1) {
  579. //>>excludeEnd("ctx");
  580. var $1;
  581. method=self._eval_(self._compileExpression_on_(aString,anObject));
  582. $recv(method)._protocol_("**xxxDoIt");
  583. $1=$recv(anObject)._class();
  584. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  585. $ctx1.sendIdx["class"]=1;
  586. //>>excludeEnd("ctx");
  587. $recv($1)._addCompiledMethod_(method);
  588. result=$recv(anObject)._xxxDoIt();
  589. $recv($recv(anObject)._class())._removeCompiledMethod_(method);
  590. return result;
  591. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  592. }, function($ctx1) {$ctx1.fill(self,"evaluateExpression:on:",{aString:aString,anObject:anObject,result:result,method:method},$globals.Compiler)});
  593. //>>excludeEnd("ctx");
  594. },
  595. //>>excludeStart("ide", pragmas.excludeIdeData);
  596. args: ["aString", "anObject"],
  597. 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",
  598. referencedClasses: [],
  599. //>>excludeEnd("ide");
  600. messageSends: ["eval:", "compileExpression:on:", "protocol:", "addCompiledMethod:", "class", "xxxDoIt", "removeCompiledMethod:"]
  601. }),
  602. $globals.Compiler);
  603. $core.addMethod(
  604. $core.method({
  605. selector: "install:forClass:protocol:",
  606. protocol: 'compiling',
  607. fn: function (aString,aBehavior,anotherString){
  608. var self=this;
  609. var compiledMethod;
  610. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  611. return $core.withContext(function($ctx1) {
  612. //>>excludeEnd("ctx");
  613. compiledMethod=self._eval_forPackage_(self._compile_forClass_protocol_(aString,aBehavior,anotherString),$recv(aBehavior)._packageOfProtocol_(anotherString));
  614. return $recv($recv($globals.ClassBuilder)._new())._installMethod_forClass_protocol_(compiledMethod,aBehavior,anotherString);
  615. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  616. }, function($ctx1) {$ctx1.fill(self,"install:forClass:protocol:",{aString:aString,aBehavior:aBehavior,anotherString:anotherString,compiledMethod:compiledMethod},$globals.Compiler)});
  617. //>>excludeEnd("ctx");
  618. },
  619. //>>excludeStart("ide", pragmas.excludeIdeData);
  620. args: ["aString", "aBehavior", "anotherString"],
  621. 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",
  622. referencedClasses: ["ClassBuilder"],
  623. //>>excludeEnd("ide");
  624. messageSends: ["eval:forPackage:", "compile:forClass:protocol:", "packageOfProtocol:", "installMethod:forClass:protocol:", "new"]
  625. }),
  626. $globals.Compiler);
  627. $core.addMethod(
  628. $core.method({
  629. selector: "parse:",
  630. protocol: 'compiling',
  631. fn: function (aString){
  632. var self=this;
  633. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  634. return $core.withContext(function($ctx1) {
  635. //>>excludeEnd("ctx");
  636. return $recv($globals.Smalltalk)._parse_(aString);
  637. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  638. }, function($ctx1) {$ctx1.fill(self,"parse:",{aString:aString},$globals.Compiler)});
  639. //>>excludeEnd("ctx");
  640. },
  641. //>>excludeStart("ide", pragmas.excludeIdeData);
  642. args: ["aString"],
  643. source: "parse: aString\x0a\x09^ Smalltalk parse: aString",
  644. referencedClasses: ["Smalltalk"],
  645. //>>excludeEnd("ide");
  646. messageSends: ["parse:"]
  647. }),
  648. $globals.Compiler);
  649. $core.addMethod(
  650. $core.method({
  651. selector: "parseExpression:",
  652. protocol: 'compiling',
  653. fn: function (aString){
  654. var self=this;
  655. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  656. return $core.withContext(function($ctx1) {
  657. //>>excludeEnd("ctx");
  658. var $1;
  659. $1=$recv("doIt ^ [ ".__comma(aString)).__comma(" ] value");
  660. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  661. $ctx1.sendIdx[","]=1;
  662. //>>excludeEnd("ctx");
  663. return self._parse_($1);
  664. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  665. }, function($ctx1) {$ctx1.fill(self,"parseExpression:",{aString:aString},$globals.Compiler)});
  666. //>>excludeEnd("ctx");
  667. },
  668. //>>excludeStart("ide", pragmas.excludeIdeData);
  669. args: ["aString"],
  670. source: "parseExpression: aString\x0a\x09^ self parse: 'doIt ^ [ ', aString, ' ] value'",
  671. referencedClasses: [],
  672. //>>excludeEnd("ide");
  673. messageSends: ["parse:", ","]
  674. }),
  675. $globals.Compiler);
  676. $core.addMethod(
  677. $core.method({
  678. selector: "recompile:",
  679. protocol: 'compiling',
  680. fn: function (aClass){
  681. var self=this;
  682. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  683. return $core.withContext(function($ctx1) {
  684. //>>excludeEnd("ctx");
  685. var $1;
  686. $recv($recv($recv(aClass)._methodDictionary())._values())._do_displayingProgress_((function(each){
  687. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  688. return $core.withContext(function($ctx2) {
  689. //>>excludeEnd("ctx");
  690. return self._install_forClass_protocol_($recv(each)._source(),aClass,$recv(each)._protocol());
  691. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  692. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  693. //>>excludeEnd("ctx");
  694. }),"Recompiling ".__comma($recv(aClass)._name()));
  695. $1=$recv(aClass)._isMetaclass();
  696. if(!$core.assert($1)){
  697. self._recompile_($recv(aClass)._class());
  698. };
  699. return self;
  700. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  701. }, function($ctx1) {$ctx1.fill(self,"recompile:",{aClass:aClass},$globals.Compiler)});
  702. //>>excludeEnd("ctx");
  703. },
  704. //>>excludeStart("ide", pragmas.excludeIdeData);
  705. args: ["aClass"],
  706. 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 ]",
  707. referencedClasses: [],
  708. //>>excludeEnd("ide");
  709. messageSends: ["do:displayingProgress:", "values", "methodDictionary", "install:forClass:protocol:", "source", "protocol", ",", "name", "ifFalse:", "isMetaclass", "recompile:", "class"]
  710. }),
  711. $globals.Compiler);
  712. $core.addMethod(
  713. $core.method({
  714. selector: "recompileAll",
  715. protocol: 'compiling',
  716. fn: function (){
  717. var self=this;
  718. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  719. return $core.withContext(function($ctx1) {
  720. //>>excludeEnd("ctx");
  721. $recv($recv($globals.Smalltalk)._classes())._do_displayingProgress_((function(each){
  722. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  723. return $core.withContext(function($ctx2) {
  724. //>>excludeEnd("ctx");
  725. return self._recompile_(each);
  726. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  727. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  728. //>>excludeEnd("ctx");
  729. }),"Compiling all classes...");
  730. return self;
  731. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  732. }, function($ctx1) {$ctx1.fill(self,"recompileAll",{},$globals.Compiler)});
  733. //>>excludeEnd("ctx");
  734. },
  735. //>>excludeStart("ide", pragmas.excludeIdeData);
  736. args: [],
  737. source: "recompileAll\x0a\x09Smalltalk classes \x0a\x09\x09do: [ :each | self recompile: each ]\x0a\x09\x09displayingProgress: 'Compiling all classes...'",
  738. referencedClasses: ["Smalltalk"],
  739. //>>excludeEnd("ide");
  740. messageSends: ["do:displayingProgress:", "classes", "recompile:"]
  741. }),
  742. $globals.Compiler);
  743. $core.addMethod(
  744. $core.method({
  745. selector: "source",
  746. protocol: 'accessing',
  747. fn: function (){
  748. var self=this;
  749. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  750. return $core.withContext(function($ctx1) {
  751. //>>excludeEnd("ctx");
  752. var $1,$receiver;
  753. $1=self["@source"];
  754. if(($receiver = $1) == null || $receiver.isNil){
  755. return "";
  756. } else {
  757. return $1;
  758. };
  759. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  760. }, function($ctx1) {$ctx1.fill(self,"source",{},$globals.Compiler)});
  761. //>>excludeEnd("ctx");
  762. },
  763. //>>excludeStart("ide", pragmas.excludeIdeData);
  764. args: [],
  765. source: "source\x0a\x09^ source ifNil: [ '' ]",
  766. referencedClasses: [],
  767. //>>excludeEnd("ide");
  768. messageSends: ["ifNil:"]
  769. }),
  770. $globals.Compiler);
  771. $core.addMethod(
  772. $core.method({
  773. selector: "source:",
  774. protocol: 'accessing',
  775. fn: function (aString){
  776. var self=this;
  777. self["@source"]=aString;
  778. return self;
  779. },
  780. //>>excludeStart("ide", pragmas.excludeIdeData);
  781. args: ["aString"],
  782. source: "source: aString\x0a\x09source := aString",
  783. referencedClasses: [],
  784. //>>excludeEnd("ide");
  785. messageSends: []
  786. }),
  787. $globals.Compiler);
  788. $core.addMethod(
  789. $core.method({
  790. selector: "unknownVariables",
  791. protocol: 'accessing',
  792. fn: function (){
  793. var self=this;
  794. return self["@unknownVariables"];
  795. },
  796. //>>excludeStart("ide", pragmas.excludeIdeData);
  797. args: [],
  798. source: "unknownVariables\x0a\x09^ unknownVariables",
  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 (aCollection){
  809. var self=this;
  810. self["@unknownVariables"]=aCollection;
  811. return self;
  812. },
  813. //>>excludeStart("ide", pragmas.excludeIdeData);
  814. args: ["aCollection"],
  815. source: "unknownVariables: aCollection\x0a\x09unknownVariables := aCollection",
  816. referencedClasses: [],
  817. //>>excludeEnd("ide");
  818. messageSends: []
  819. }),
  820. $globals.Compiler);
  821. $core.addMethod(
  822. $core.method({
  823. selector: "recompile:",
  824. protocol: 'compiling',
  825. fn: function (aClass){
  826. var self=this;
  827. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  828. return $core.withContext(function($ctx1) {
  829. //>>excludeEnd("ctx");
  830. $recv(self._new())._recompile_(aClass);
  831. return self;
  832. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  833. }, function($ctx1) {$ctx1.fill(self,"recompile:",{aClass:aClass},$globals.Compiler.klass)});
  834. //>>excludeEnd("ctx");
  835. },
  836. //>>excludeStart("ide", pragmas.excludeIdeData);
  837. args: ["aClass"],
  838. source: "recompile: aClass\x0a\x09self new recompile: aClass",
  839. referencedClasses: [],
  840. //>>excludeEnd("ide");
  841. messageSends: ["recompile:", "new"]
  842. }),
  843. $globals.Compiler.klass);
  844. $core.addMethod(
  845. $core.method({
  846. selector: "recompileAll",
  847. protocol: 'compiling',
  848. fn: function (){
  849. var self=this;
  850. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  851. return $core.withContext(function($ctx1) {
  852. //>>excludeEnd("ctx");
  853. $recv($recv($globals.Smalltalk)._classes())._do_((function(each){
  854. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  855. return $core.withContext(function($ctx2) {
  856. //>>excludeEnd("ctx");
  857. return self._recompile_(each);
  858. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  859. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  860. //>>excludeEnd("ctx");
  861. }));
  862. return self;
  863. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  864. }, function($ctx1) {$ctx1.fill(self,"recompileAll",{},$globals.Compiler.klass)});
  865. //>>excludeEnd("ctx");
  866. },
  867. //>>excludeStart("ide", pragmas.excludeIdeData);
  868. args: [],
  869. source: "recompileAll\x0a\x09Smalltalk classes do: [ :each |\x0a\x09\x09self recompile: each ]",
  870. referencedClasses: ["Smalltalk"],
  871. //>>excludeEnd("ide");
  872. messageSends: ["do:", "classes", "recompile:"]
  873. }),
  874. $globals.Compiler.klass);
  875. $core.addClass('CompilerError', $globals.Error, [], 'Compiler-Core');
  876. //>>excludeStart("ide", pragmas.excludeIdeData);
  877. $globals.CompilerError.comment="I am the common superclass of all compiling errors.";
  878. //>>excludeEnd("ide");
  879. $core.addClass('DoIt', $globals.Object, [], 'Compiler-Core');
  880. //>>excludeStart("ide", pragmas.excludeIdeData);
  881. $globals.DoIt.comment="`DoIt` is the class used to compile and evaluate expressions. See `Compiler >> evaluateExpression:`.";
  882. //>>excludeEnd("ide");
  883. $core.addClass('Evaluator', $globals.Object, [], 'Compiler-Core');
  884. //>>excludeStart("ide", pragmas.excludeIdeData);
  885. $globals.Evaluator.comment="I evaluate code against a receiver, dispatching #evaluate:on: to the receiver.";
  886. //>>excludeEnd("ide");
  887. $core.addMethod(
  888. $core.method({
  889. selector: "evaluate:context:",
  890. protocol: 'evaluating',
  891. fn: function (aString,aContext){
  892. var self=this;
  893. var compiler,ast;
  894. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  895. return $core.withContext(function($ctx1) {
  896. //>>excludeEnd("ctx");
  897. var $1;
  898. var $early={};
  899. try {
  900. compiler=$recv($globals.Compiler)._new();
  901. $recv((function(){
  902. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  903. return $core.withContext(function($ctx2) {
  904. //>>excludeEnd("ctx");
  905. ast=$recv(compiler)._parseExpression_(aString);
  906. return ast;
  907. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  908. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  909. //>>excludeEnd("ctx");
  910. }))._on_do_($globals.Error,(function(ex){
  911. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  912. return $core.withContext(function($ctx2) {
  913. //>>excludeEnd("ctx");
  914. throw $early=[$recv($globals.Terminal)._alert_($recv(ex)._messageText())];
  915. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  916. }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1,2)});
  917. //>>excludeEnd("ctx");
  918. }));
  919. $1=$recv($globals.AISemanticAnalyzer)._on_($recv($recv(aContext)._receiver())._class());
  920. $recv($1)._context_(aContext);
  921. $recv($1)._visit_(ast);
  922. return $recv(aContext)._evaluateNode_(ast);
  923. }
  924. catch(e) {if(e===$early)return e[0]; throw e}
  925. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  926. }, function($ctx1) {$ctx1.fill(self,"evaluate:context:",{aString:aString,aContext:aContext,compiler:compiler,ast:ast},$globals.Evaluator)});
  927. //>>excludeEnd("ctx");
  928. },
  929. //>>excludeStart("ide", pragmas.excludeIdeData);
  930. args: ["aString", "aContext"],
  931. 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",
  932. referencedClasses: ["Compiler", "Error", "Terminal", "AISemanticAnalyzer"],
  933. //>>excludeEnd("ide");
  934. messageSends: ["new", "on:do:", "parseExpression:", "alert:", "messageText", "context:", "on:", "class", "receiver", "visit:", "evaluateNode:"]
  935. }),
  936. $globals.Evaluator);
  937. $core.addMethod(
  938. $core.method({
  939. selector: "evaluate:for:",
  940. protocol: 'evaluating',
  941. fn: function (aString,anObject){
  942. var self=this;
  943. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  944. return $core.withContext(function($ctx1) {
  945. //>>excludeEnd("ctx");
  946. return $recv(anObject)._evaluate_on_(aString,self);
  947. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  948. }, function($ctx1) {$ctx1.fill(self,"evaluate:for:",{aString:aString,anObject:anObject},$globals.Evaluator)});
  949. //>>excludeEnd("ctx");
  950. },
  951. //>>excludeStart("ide", pragmas.excludeIdeData);
  952. args: ["aString", "anObject"],
  953. source: "evaluate: aString for: anObject\x0a\x09^ anObject evaluate: aString on: self",
  954. referencedClasses: [],
  955. //>>excludeEnd("ide");
  956. messageSends: ["evaluate:on:"]
  957. }),
  958. $globals.Evaluator);
  959. $core.addMethod(
  960. $core.method({
  961. selector: "evaluate:receiver:",
  962. protocol: 'evaluating',
  963. fn: function (aString,anObject){
  964. var self=this;
  965. var compiler;
  966. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  967. return $core.withContext(function($ctx1) {
  968. //>>excludeEnd("ctx");
  969. var $early={};
  970. try {
  971. compiler=$recv($globals.Compiler)._new();
  972. $recv((function(){
  973. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  974. return $core.withContext(function($ctx2) {
  975. //>>excludeEnd("ctx");
  976. return $recv(compiler)._parseExpression_(aString);
  977. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  978. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  979. //>>excludeEnd("ctx");
  980. }))._on_do_($globals.Error,(function(ex){
  981. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  982. return $core.withContext(function($ctx2) {
  983. //>>excludeEnd("ctx");
  984. throw $early=[$recv($globals.Terminal)._alert_($recv(ex)._messageText())];
  985. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  986. }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1,2)});
  987. //>>excludeEnd("ctx");
  988. }));
  989. return $recv(compiler)._evaluateExpression_on_(aString,anObject);
  990. }
  991. catch(e) {if(e===$early)return e[0]; throw e}
  992. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  993. }, function($ctx1) {$ctx1.fill(self,"evaluate:receiver:",{aString:aString,anObject:anObject,compiler:compiler},$globals.Evaluator)});
  994. //>>excludeEnd("ctx");
  995. },
  996. //>>excludeStart("ide", pragmas.excludeIdeData);
  997. args: ["aString", "anObject"],
  998. 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",
  999. referencedClasses: ["Compiler", "Error", "Terminal"],
  1000. //>>excludeEnd("ide");
  1001. messageSends: ["new", "on:do:", "parseExpression:", "alert:", "messageText", "evaluateExpression:on:"]
  1002. }),
  1003. $globals.Evaluator);
  1004. $core.addMethod(
  1005. $core.method({
  1006. selector: "evaluate:for:",
  1007. protocol: 'instance creation',
  1008. fn: function (aString,anObject){
  1009. var self=this;
  1010. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1011. return $core.withContext(function($ctx1) {
  1012. //>>excludeEnd("ctx");
  1013. return $recv(self._new())._evaluate_for_(aString,anObject);
  1014. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1015. }, function($ctx1) {$ctx1.fill(self,"evaluate:for:",{aString:aString,anObject:anObject},$globals.Evaluator.klass)});
  1016. //>>excludeEnd("ctx");
  1017. },
  1018. //>>excludeStart("ide", pragmas.excludeIdeData);
  1019. args: ["aString", "anObject"],
  1020. source: "evaluate: aString for: anObject\x0a\x09^ self new evaluate: aString for: anObject",
  1021. referencedClasses: [],
  1022. //>>excludeEnd("ide");
  1023. messageSends: ["evaluate:for:", "new"]
  1024. }),
  1025. $globals.Evaluator.klass);
  1026. $core.addMethod(
  1027. $core.method({
  1028. selector: "asVariableName",
  1029. protocol: '*Compiler-Core',
  1030. fn: function (){
  1031. var self=this;
  1032. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1033. return $core.withContext(function($ctx1) {
  1034. //>>excludeEnd("ctx");
  1035. var $1;
  1036. $1=$recv($recv($globals.Smalltalk)._reservedWords())._includes_(self);
  1037. if($core.assert($1)){
  1038. return self.__comma("_");
  1039. } else {
  1040. return self;
  1041. };
  1042. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1043. }, function($ctx1) {$ctx1.fill(self,"asVariableName",{},$globals.String)});
  1044. //>>excludeEnd("ctx");
  1045. },
  1046. //>>excludeStart("ide", pragmas.excludeIdeData);
  1047. args: [],
  1048. source: "asVariableName\x0a\x09^ (Smalltalk reservedWords includes: self)\x0a\x09\x09ifTrue: [ self, '_' ]\x0a\x09\x09ifFalse: [ self ]",
  1049. referencedClasses: ["Smalltalk"],
  1050. //>>excludeEnd("ide");
  1051. messageSends: ["ifTrue:ifFalse:", "includes:", "reservedWords", ","]
  1052. }),
  1053. $globals.String);
  1054. });