Compiler-Core.js 48 KB

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