Compiler-Core.js 41 KB

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