1
0

Compiler-Core.js 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661
  1. define(["amber/boot", "require", "amber/core/Kernel-Collections", "amber/core/Kernel-Exceptions", "amber/core/Kernel-Infrastructure", "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.context = function () { return {smalltalkParser:smalltalkParser}; };
  5. $pkg.imports = ["smalltalkParser=amber/parser"];
  6. //>>excludeStart("imports", pragmas.excludeImports);
  7. var smalltalkParser;
  8. $pkg.isReady = new Promise(function (resolve, reject) { requirejs(["amber/parser"], function ($1) {smalltalkParser=$1; resolve();}, reject); });
  9. //>>excludeEnd("imports");
  10. $pkg.transport = {"type":"amd","amdNamespace":"amber/core"};
  11. $core.addClass("AbstractCodeGenerator", $globals.Object, "Compiler-Core");
  12. $core.setSlots($globals.AbstractCodeGenerator, ["currentClass", "currentPackage", "source"]);
  13. //>>excludeStart("ide", pragmas.excludeIdeData);
  14. $globals.AbstractCodeGenerator.comment="I am the abstract super class of all code generators and provide their common API.";
  15. //>>excludeEnd("ide");
  16. $core.addMethod(
  17. $core.method({
  18. selector: "compileNode:",
  19. protocol: "compiling",
  20. //>>excludeStart("ide", pragmas.excludeIdeData);
  21. args: ["aNode"],
  22. source: "compileNode: aNode\x0a\x09^ self transformers\x0a\x09\x09inject: aNode\x0a\x09\x09into: [ :input :transformer | transformer value: input ]",
  23. referencedClasses: [],
  24. //>>excludeEnd("ide");
  25. pragmas: [],
  26. messageSends: ["inject:into:", "transformers", "value:"]
  27. }, function ($methodClass){ return function (aNode){
  28. var self=this,$self=this;
  29. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  30. return $core.withContext(function($ctx1) {
  31. //>>excludeEnd("ctx");
  32. return $recv($self._transformers())._inject_into_(aNode,(function(input,transformer){
  33. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  34. return $core.withContext(function($ctx2) {
  35. //>>excludeEnd("ctx");
  36. return $recv(transformer)._value_(input);
  37. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  38. }, function($ctx2) {$ctx2.fillBlock({input:input,transformer:transformer},$ctx1,1)});
  39. //>>excludeEnd("ctx");
  40. }));
  41. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  42. }, function($ctx1) {$ctx1.fill(self,"compileNode:",{aNode:aNode})});
  43. //>>excludeEnd("ctx");
  44. }; }),
  45. $globals.AbstractCodeGenerator);
  46. $core.addMethod(
  47. $core.method({
  48. selector: "currentClass",
  49. protocol: "accessing",
  50. //>>excludeStart("ide", pragmas.excludeIdeData);
  51. args: [],
  52. source: "currentClass\x0a\x09^ currentClass",
  53. referencedClasses: [],
  54. //>>excludeEnd("ide");
  55. pragmas: [],
  56. messageSends: []
  57. }, function ($methodClass){ return function (){
  58. var self=this,$self=this;
  59. return $self.currentClass;
  60. }; }),
  61. $globals.AbstractCodeGenerator);
  62. $core.addMethod(
  63. $core.method({
  64. selector: "currentClass:",
  65. protocol: "accessing",
  66. //>>excludeStart("ide", pragmas.excludeIdeData);
  67. args: ["aClass"],
  68. source: "currentClass: aClass\x0a\x09currentClass := aClass",
  69. referencedClasses: [],
  70. //>>excludeEnd("ide");
  71. pragmas: [],
  72. messageSends: []
  73. }, function ($methodClass){ return function (aClass){
  74. var self=this,$self=this;
  75. $self.currentClass=aClass;
  76. return self;
  77. }; }),
  78. $globals.AbstractCodeGenerator);
  79. $core.addMethod(
  80. $core.method({
  81. selector: "currentPackage",
  82. protocol: "accessing",
  83. //>>excludeStart("ide", pragmas.excludeIdeData);
  84. args: [],
  85. source: "currentPackage\x0a\x09^ currentPackage",
  86. referencedClasses: [],
  87. //>>excludeEnd("ide");
  88. pragmas: [],
  89. messageSends: []
  90. }, function ($methodClass){ return function (){
  91. var self=this,$self=this;
  92. return $self.currentPackage;
  93. }; }),
  94. $globals.AbstractCodeGenerator);
  95. $core.addMethod(
  96. $core.method({
  97. selector: "currentPackage:",
  98. protocol: "accessing",
  99. //>>excludeStart("ide", pragmas.excludeIdeData);
  100. args: ["anObject"],
  101. source: "currentPackage: anObject\x0a\x09currentPackage := anObject",
  102. referencedClasses: [],
  103. //>>excludeEnd("ide");
  104. pragmas: [],
  105. messageSends: []
  106. }, function ($methodClass){ return function (anObject){
  107. var self=this,$self=this;
  108. $self.currentPackage=anObject;
  109. return self;
  110. }; }),
  111. $globals.AbstractCodeGenerator);
  112. $core.addMethod(
  113. $core.method({
  114. selector: "pseudoVariables",
  115. protocol: "accessing",
  116. //>>excludeStart("ide", pragmas.excludeIdeData);
  117. args: [],
  118. source: "pseudoVariables\x0a\x09^ Smalltalk pseudoVariableNames",
  119. referencedClasses: ["Smalltalk"],
  120. //>>excludeEnd("ide");
  121. pragmas: [],
  122. messageSends: ["pseudoVariableNames"]
  123. }, function ($methodClass){ return function (){
  124. var self=this,$self=this;
  125. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  126. return $core.withContext(function($ctx1) {
  127. //>>excludeEnd("ctx");
  128. return $recv($globals.Smalltalk)._pseudoVariableNames();
  129. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  130. }, function($ctx1) {$ctx1.fill(self,"pseudoVariables",{})});
  131. //>>excludeEnd("ctx");
  132. }; }),
  133. $globals.AbstractCodeGenerator);
  134. $core.addMethod(
  135. $core.method({
  136. selector: "source",
  137. protocol: "accessing",
  138. //>>excludeStart("ide", pragmas.excludeIdeData);
  139. args: [],
  140. source: "source\x0a\x09^ source ifNil: [ '' ]",
  141. referencedClasses: [],
  142. //>>excludeEnd("ide");
  143. pragmas: [],
  144. messageSends: ["ifNil:"]
  145. }, function ($methodClass){ return function (){
  146. var self=this,$self=this;
  147. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  148. return $core.withContext(function($ctx1) {
  149. //>>excludeEnd("ctx");
  150. var $1;
  151. $1=$self.source;
  152. if($1 == null || $1.a$nil){
  153. return "";
  154. } else {
  155. return $1;
  156. }
  157. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  158. }, function($ctx1) {$ctx1.fill(self,"source",{})});
  159. //>>excludeEnd("ctx");
  160. }; }),
  161. $globals.AbstractCodeGenerator);
  162. $core.addMethod(
  163. $core.method({
  164. selector: "source:",
  165. protocol: "accessing",
  166. //>>excludeStart("ide", pragmas.excludeIdeData);
  167. args: ["aString"],
  168. source: "source: aString\x0a\x09source := aString",
  169. referencedClasses: [],
  170. //>>excludeEnd("ide");
  171. pragmas: [],
  172. messageSends: []
  173. }, function ($methodClass){ return function (aString){
  174. var self=this,$self=this;
  175. $self.source=aString;
  176. return self;
  177. }; }),
  178. $globals.AbstractCodeGenerator);
  179. $core.addMethod(
  180. $core.method({
  181. selector: "transformers",
  182. protocol: "compiling",
  183. //>>excludeStart("ide", pragmas.excludeIdeData);
  184. args: [],
  185. source: "transformers\x0a\x09| dict |\x0a\x09dict := self transformersDictionary.\x0a\x09^ dict keys asArray sort collect: [ :each | dict at: each ]",
  186. referencedClasses: [],
  187. //>>excludeEnd("ide");
  188. pragmas: [],
  189. messageSends: ["transformersDictionary", "collect:", "sort", "asArray", "keys", "at:"]
  190. }, function ($methodClass){ return function (){
  191. var self=this,$self=this;
  192. var dict;
  193. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  194. return $core.withContext(function($ctx1) {
  195. //>>excludeEnd("ctx");
  196. dict=$self._transformersDictionary();
  197. return $recv($recv($recv($recv(dict)._keys())._asArray())._sort())._collect_((function(each){
  198. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  199. return $core.withContext(function($ctx2) {
  200. //>>excludeEnd("ctx");
  201. return $recv(dict)._at_(each);
  202. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  203. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  204. //>>excludeEnd("ctx");
  205. }));
  206. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  207. }, function($ctx1) {$ctx1.fill(self,"transformers",{dict:dict})});
  208. //>>excludeEnd("ctx");
  209. }; }),
  210. $globals.AbstractCodeGenerator);
  211. $core.addMethod(
  212. $core.method({
  213. selector: "transformersDictionary",
  214. protocol: "compiling",
  215. //>>excludeStart("ide", pragmas.excludeIdeData);
  216. args: [],
  217. source: "transformersDictionary\x0a\x09self subclassResponsibility",
  218. referencedClasses: [],
  219. //>>excludeEnd("ide");
  220. pragmas: [],
  221. messageSends: ["subclassResponsibility"]
  222. }, function ($methodClass){ return function (){
  223. var self=this,$self=this;
  224. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  225. return $core.withContext(function($ctx1) {
  226. //>>excludeEnd("ctx");
  227. $self._subclassResponsibility();
  228. return self;
  229. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  230. }, function($ctx1) {$ctx1.fill(self,"transformersDictionary",{})});
  231. //>>excludeEnd("ctx");
  232. }; }),
  233. $globals.AbstractCodeGenerator);
  234. $core.addClass("AstGenerator", $globals.AbstractCodeGenerator, "Compiler-Core");
  235. $core.setSlots($globals.AstGenerator, ["transformersDictionary"]);
  236. //>>excludeStart("ide", pragmas.excludeIdeData);
  237. $globals.AstGenerator.comment="I am a very basic code generator.\x0aI generate semantically augmented abstract syntax tree,\x0aSome initial pragmas (eg. #inlineJS:) are applied to transform the tree.";
  238. //>>excludeEnd("ide");
  239. $core.addMethod(
  240. $core.method({
  241. selector: "semanticAnalyzer",
  242. protocol: "compiling",
  243. //>>excludeStart("ide", pragmas.excludeIdeData);
  244. args: [],
  245. source: "semanticAnalyzer\x0a\x09^ (SemanticAnalyzer on: self currentClass)\x0a\x09\x09thePackage: self currentPackage;\x0a\x09\x09yourself",
  246. referencedClasses: ["SemanticAnalyzer"],
  247. //>>excludeEnd("ide");
  248. pragmas: [],
  249. messageSends: ["thePackage:", "on:", "currentClass", "currentPackage", "yourself"]
  250. }, function ($methodClass){ return function (){
  251. var self=this,$self=this;
  252. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  253. return $core.withContext(function($ctx1) {
  254. //>>excludeEnd("ctx");
  255. var $1;
  256. $1=$recv($globals.SemanticAnalyzer)._on_($self._currentClass());
  257. $recv($1)._thePackage_($self._currentPackage());
  258. return $recv($1)._yourself();
  259. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  260. }, function($ctx1) {$ctx1.fill(self,"semanticAnalyzer",{})});
  261. //>>excludeEnd("ctx");
  262. }; }),
  263. $globals.AstGenerator);
  264. $core.addMethod(
  265. $core.method({
  266. selector: "semanticAstPragmator",
  267. protocol: "compiling",
  268. //>>excludeStart("ide", pragmas.excludeIdeData);
  269. args: [],
  270. source: "semanticAstPragmator\x0a\x09^ AstSemanticPragmator new",
  271. referencedClasses: ["AstSemanticPragmator"],
  272. //>>excludeEnd("ide");
  273. pragmas: [],
  274. messageSends: ["new"]
  275. }, function ($methodClass){ return function (){
  276. var self=this,$self=this;
  277. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  278. return $core.withContext(function($ctx1) {
  279. //>>excludeEnd("ctx");
  280. return $recv($globals.AstSemanticPragmator)._new();
  281. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  282. }, function($ctx1) {$ctx1.fill(self,"semanticAstPragmator",{})});
  283. //>>excludeEnd("ctx");
  284. }; }),
  285. $globals.AstGenerator);
  286. $core.addMethod(
  287. $core.method({
  288. selector: "transformersDictionary",
  289. protocol: "compiling",
  290. //>>excludeStart("ide", pragmas.excludeIdeData);
  291. args: [],
  292. source: "transformersDictionary\x0a\x09^ transformersDictionary ifNil: [ transformersDictionary := Dictionary new\x0a\x09\x09at: '2000-semantic' put: self semanticAnalyzer;\x0a\x09\x09at: '2500-semanticPragmas' put: self semanticAstPragmator;\x0a\x09\x09yourself ]",
  293. referencedClasses: ["Dictionary"],
  294. //>>excludeEnd("ide");
  295. pragmas: [],
  296. messageSends: ["ifNil:", "at:put:", "new", "semanticAnalyzer", "semanticAstPragmator", "yourself"]
  297. }, function ($methodClass){ return function (){
  298. var self=this,$self=this;
  299. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  300. return $core.withContext(function($ctx1) {
  301. //>>excludeEnd("ctx");
  302. var $1,$2;
  303. $1=$self.transformersDictionary;
  304. if($1 == null || $1.a$nil){
  305. $2=$recv($globals.Dictionary)._new();
  306. [$recv($2)._at_put_("2000-semantic",$self._semanticAnalyzer())
  307. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  308. ,$ctx1.sendIdx["at:put:"]=1
  309. //>>excludeEnd("ctx");
  310. ][0];
  311. $recv($2)._at_put_("2500-semanticPragmas",$self._semanticAstPragmator());
  312. $self.transformersDictionary=$recv($2)._yourself();
  313. return $self.transformersDictionary;
  314. } else {
  315. return $1;
  316. }
  317. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  318. }, function($ctx1) {$ctx1.fill(self,"transformersDictionary",{})});
  319. //>>excludeEnd("ctx");
  320. }; }),
  321. $globals.AstGenerator);
  322. $core.addClass("CodeGenerator", $globals.AstGenerator, "Compiler-Core");
  323. //>>excludeStart("ide", pragmas.excludeIdeData);
  324. $globals.CodeGenerator.comment="I am a basic code generator. I generate a valid JavaScript output, but do not perform any inlining.\x0aSee `InliningCodeGenerator` for an optimized JavaScript code generation.";
  325. //>>excludeEnd("ide");
  326. $core.addMethod(
  327. $core.method({
  328. selector: "irTranslator",
  329. protocol: "compiling",
  330. //>>excludeStart("ide", pragmas.excludeIdeData);
  331. args: [],
  332. source: "irTranslator\x0a\x09^ self irTranslatorClass new\x0a\x09\x09currentClass: self currentClass;\x0a\x09\x09yourself",
  333. referencedClasses: [],
  334. //>>excludeEnd("ide");
  335. pragmas: [],
  336. messageSends: ["currentClass:", "new", "irTranslatorClass", "currentClass", "yourself"]
  337. }, function ($methodClass){ return function (){
  338. var self=this,$self=this;
  339. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  340. return $core.withContext(function($ctx1) {
  341. //>>excludeEnd("ctx");
  342. var $1;
  343. $1=$recv($self._irTranslatorClass())._new();
  344. $recv($1)._currentClass_($self._currentClass());
  345. return $recv($1)._yourself();
  346. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  347. }, function($ctx1) {$ctx1.fill(self,"irTranslator",{})});
  348. //>>excludeEnd("ctx");
  349. }; }),
  350. $globals.CodeGenerator);
  351. $core.addMethod(
  352. $core.method({
  353. selector: "irTranslatorClass",
  354. protocol: "compiling",
  355. //>>excludeStart("ide", pragmas.excludeIdeData);
  356. args: [],
  357. source: "irTranslatorClass\x0a\x09^ IRJSTranslator",
  358. referencedClasses: ["IRJSTranslator"],
  359. //>>excludeEnd("ide");
  360. pragmas: [],
  361. messageSends: []
  362. }, function ($methodClass){ return function (){
  363. var self=this,$self=this;
  364. return $globals.IRJSTranslator;
  365. }; }),
  366. $globals.CodeGenerator);
  367. $core.addMethod(
  368. $core.method({
  369. selector: "lateIRPragmator",
  370. protocol: "compiling",
  371. //>>excludeStart("ide", pragmas.excludeIdeData);
  372. args: [],
  373. source: "lateIRPragmator\x0a\x09^ IRLatePragmator new",
  374. referencedClasses: ["IRLatePragmator"],
  375. //>>excludeEnd("ide");
  376. pragmas: [],
  377. messageSends: ["new"]
  378. }, function ($methodClass){ return function (){
  379. var self=this,$self=this;
  380. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  381. return $core.withContext(function($ctx1) {
  382. //>>excludeEnd("ctx");
  383. return $recv($globals.IRLatePragmator)._new();
  384. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  385. }, function($ctx1) {$ctx1.fill(self,"lateIRPragmator",{})});
  386. //>>excludeEnd("ctx");
  387. }; }),
  388. $globals.CodeGenerator);
  389. $core.addMethod(
  390. $core.method({
  391. selector: "transformersDictionary",
  392. protocol: "compiling",
  393. //>>excludeStart("ide", pragmas.excludeIdeData);
  394. args: [],
  395. source: "transformersDictionary\x0a\x09^ transformersDictionary ifNil: [ transformersDictionary := super transformersDictionary\x0a\x09\x09at: '5000-astToIr' put: self translator;\x0a\x09\x09at: '7000-irLatePragmas' put: self lateIRPragmator;\x0a\x09\x09at: '8000-irToJs' put: self irTranslator;\x0a\x09\x09yourself ]",
  396. referencedClasses: [],
  397. //>>excludeEnd("ide");
  398. pragmas: [],
  399. messageSends: ["ifNil:", "at:put:", "transformersDictionary", "translator", "lateIRPragmator", "irTranslator", "yourself"]
  400. }, function ($methodClass){ return function (){
  401. var self=this,$self=this;
  402. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  403. return $core.withContext(function($ctx1) {
  404. //>>excludeEnd("ctx");
  405. var $1,$2;
  406. $1=$self.transformersDictionary;
  407. if($1 == null || $1.a$nil){
  408. $2=[(
  409. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  410. $ctx1.supercall = true,
  411. //>>excludeEnd("ctx");
  412. ($methodClass.superclass||$boot.nilAsClass).fn.prototype._transformersDictionary.call($self))
  413. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  414. ,$ctx1.supercall = false
  415. //>>excludeEnd("ctx");
  416. ][0];
  417. [$recv($2)._at_put_("5000-astToIr",$self._translator())
  418. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  419. ,$ctx1.sendIdx["at:put:"]=1
  420. //>>excludeEnd("ctx");
  421. ][0];
  422. [$recv($2)._at_put_("7000-irLatePragmas",$self._lateIRPragmator())
  423. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  424. ,$ctx1.sendIdx["at:put:"]=2
  425. //>>excludeEnd("ctx");
  426. ][0];
  427. $recv($2)._at_put_("8000-irToJs",$self._irTranslator());
  428. $self.transformersDictionary=$recv($2)._yourself();
  429. return $self.transformersDictionary;
  430. } else {
  431. return $1;
  432. }
  433. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  434. }, function($ctx1) {$ctx1.fill(self,"transformersDictionary",{})});
  435. //>>excludeEnd("ctx");
  436. }; }),
  437. $globals.CodeGenerator);
  438. $core.addMethod(
  439. $core.method({
  440. selector: "translator",
  441. protocol: "compiling",
  442. //>>excludeStart("ide", pragmas.excludeIdeData);
  443. args: [],
  444. source: "translator\x0a\x09^ IRASTTranslator new\x0a\x09\x09source: self source;\x0a\x09\x09theClass: self currentClass;\x0a\x09\x09yourself",
  445. referencedClasses: ["IRASTTranslator"],
  446. //>>excludeEnd("ide");
  447. pragmas: [],
  448. messageSends: ["source:", "new", "source", "theClass:", "currentClass", "yourself"]
  449. }, function ($methodClass){ return function (){
  450. var self=this,$self=this;
  451. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  452. return $core.withContext(function($ctx1) {
  453. //>>excludeEnd("ctx");
  454. var $1;
  455. $1=$recv($globals.IRASTTranslator)._new();
  456. $recv($1)._source_($self._source());
  457. $recv($1)._theClass_($self._currentClass());
  458. return $recv($1)._yourself();
  459. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  460. }, function($ctx1) {$ctx1.fill(self,"translator",{})});
  461. //>>excludeEnd("ctx");
  462. }; }),
  463. $globals.CodeGenerator);
  464. $core.addClass("Compiler", $globals.Object, "Compiler-Core");
  465. $core.setSlots($globals.Compiler, ["currentPackage", "codeGeneratorClass", "codeGenerator"]);
  466. //>>excludeStart("ide", pragmas.excludeIdeData);
  467. $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`";
  468. //>>excludeEnd("ide");
  469. $core.addMethod(
  470. $core.method({
  471. selector: "ast:forClass:protocol:",
  472. protocol: "compiling",
  473. //>>excludeStart("ide", pragmas.excludeIdeData);
  474. args: ["aString", "aClass", "anotherString"],
  475. source: "ast: aString forClass: aClass protocol: anotherString\x0a\x09^ self\x0a\x09\x09codeGeneratorClass: AstGenerator;\x0a\x09\x09start: aString forClass: aClass protocol: anotherString;\x0a\x09\x09compileNode: (self parse: aString)",
  476. referencedClasses: ["AstGenerator"],
  477. //>>excludeEnd("ide");
  478. pragmas: [],
  479. messageSends: ["codeGeneratorClass:", "start:forClass:protocol:", "compileNode:", "parse:"]
  480. }, function ($methodClass){ return function (aString,aClass,anotherString){
  481. var self=this,$self=this;
  482. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  483. return $core.withContext(function($ctx1) {
  484. //>>excludeEnd("ctx");
  485. $self._codeGeneratorClass_($globals.AstGenerator);
  486. $self._start_forClass_protocol_(aString,aClass,anotherString);
  487. return $self._compileNode_($self._parse_(aString));
  488. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  489. }, function($ctx1) {$ctx1.fill(self,"ast:forClass:protocol:",{aString:aString,aClass:aClass,anotherString:anotherString})});
  490. //>>excludeEnd("ctx");
  491. }; }),
  492. $globals.Compiler);
  493. $core.addMethod(
  494. $core.method({
  495. selector: "basicParse:",
  496. protocol: "private",
  497. //>>excludeStart("ide", pragmas.excludeIdeData);
  498. args: ["aString"],
  499. source: "basicParse: aString\x0a\x09^ smalltalkParser parse: aString",
  500. referencedClasses: [],
  501. //>>excludeEnd("ide");
  502. pragmas: [],
  503. messageSends: ["parse:"]
  504. }, function ($methodClass){ return function (aString){
  505. var self=this,$self=this;
  506. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  507. return $core.withContext(function($ctx1) {
  508. //>>excludeEnd("ctx");
  509. return $recv(smalltalkParser)._parse_(aString);
  510. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  511. }, function($ctx1) {$ctx1.fill(self,"basicParse:",{aString:aString})});
  512. //>>excludeEnd("ctx");
  513. }; }),
  514. $globals.Compiler);
  515. $core.addMethod(
  516. $core.method({
  517. selector: "cleanCodeGenerator",
  518. protocol: "accessing",
  519. //>>excludeStart("ide", pragmas.excludeIdeData);
  520. args: [],
  521. source: "cleanCodeGenerator\x0a\x09codeGenerator := nil",
  522. referencedClasses: [],
  523. //>>excludeEnd("ide");
  524. pragmas: [],
  525. messageSends: []
  526. }, function ($methodClass){ return function (){
  527. var self=this,$self=this;
  528. $self.codeGenerator=nil;
  529. return self;
  530. }; }),
  531. $globals.Compiler);
  532. $core.addMethod(
  533. $core.method({
  534. selector: "codeGenerator",
  535. protocol: "accessing",
  536. //>>excludeStart("ide", pragmas.excludeIdeData);
  537. args: [],
  538. source: "codeGenerator\x0a\x09^ codeGenerator",
  539. referencedClasses: [],
  540. //>>excludeEnd("ide");
  541. pragmas: [],
  542. messageSends: []
  543. }, function ($methodClass){ return function (){
  544. var self=this,$self=this;
  545. return $self.codeGenerator;
  546. }; }),
  547. $globals.Compiler);
  548. $core.addMethod(
  549. $core.method({
  550. selector: "codeGenerator:",
  551. protocol: "accessing",
  552. //>>excludeStart("ide", pragmas.excludeIdeData);
  553. args: ["anObject"],
  554. source: "codeGenerator: anObject\x0a\x09codeGenerator := anObject",
  555. referencedClasses: [],
  556. //>>excludeEnd("ide");
  557. pragmas: [],
  558. messageSends: []
  559. }, function ($methodClass){ return function (anObject){
  560. var self=this,$self=this;
  561. $self.codeGenerator=anObject;
  562. return self;
  563. }; }),
  564. $globals.Compiler);
  565. $core.addMethod(
  566. $core.method({
  567. selector: "codeGeneratorClass",
  568. protocol: "accessing",
  569. //>>excludeStart("ide", pragmas.excludeIdeData);
  570. args: [],
  571. source: "codeGeneratorClass\x0a\x09^ codeGeneratorClass ifNil: [ InliningCodeGenerator ]",
  572. referencedClasses: ["InliningCodeGenerator"],
  573. //>>excludeEnd("ide");
  574. pragmas: [],
  575. messageSends: ["ifNil:"]
  576. }, function ($methodClass){ return function (){
  577. var self=this,$self=this;
  578. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  579. return $core.withContext(function($ctx1) {
  580. //>>excludeEnd("ctx");
  581. var $1;
  582. $1=$self.codeGeneratorClass;
  583. if($1 == null || $1.a$nil){
  584. return $globals.InliningCodeGenerator;
  585. } else {
  586. return $1;
  587. }
  588. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  589. }, function($ctx1) {$ctx1.fill(self,"codeGeneratorClass",{})});
  590. //>>excludeEnd("ctx");
  591. }; }),
  592. $globals.Compiler);
  593. $core.addMethod(
  594. $core.method({
  595. selector: "codeGeneratorClass:",
  596. protocol: "accessing",
  597. //>>excludeStart("ide", pragmas.excludeIdeData);
  598. args: ["aClass"],
  599. source: "codeGeneratorClass: aClass\x0a\x09codeGeneratorClass := aClass",
  600. referencedClasses: [],
  601. //>>excludeEnd("ide");
  602. pragmas: [],
  603. messageSends: []
  604. }, function ($methodClass){ return function (aClass){
  605. var self=this,$self=this;
  606. $self.codeGeneratorClass=aClass;
  607. return self;
  608. }; }),
  609. $globals.Compiler);
  610. $core.addMethod(
  611. $core.method({
  612. selector: "compile:forClass:protocol:",
  613. protocol: "compiling",
  614. //>>excludeStart("ide", pragmas.excludeIdeData);
  615. args: ["aString", "aClass", "anotherString"],
  616. source: "compile: aString forClass: aClass protocol: anotherString\x0a\x09| sanitizedSource compilationResult result pragmas closureFactory |\x0a\x09sanitizedSource := aString crlfSanitized.\x0a\x09compilationResult := self\x0a\x09\x09start: sanitizedSource forClass: aClass protocol: anotherString;\x0a\x09\x09compileNode: (self parse: sanitizedSource).\x0a\x09closureFactory := self\x0a\x09\x09eval: (self wrappedSourceOf: compilationResult)\x0a\x09\x09forPackage: self currentPackage.\x0a\x09result := Smalltalk core method: #{\x0a\x09\x09#selector -> compilationResult selector.\x0a\x09\x09#protocol -> anotherString.\x0a\x09\x09#source -> sanitizedSource.\x0a\x09\x09#messageSends -> compilationResult messageSends asArray.\x0a\x09\x09#args -> compilationResult arguments.\x0a\x09\x09#referencedClasses -> compilationResult classReferences asArray.\x0a\x09} withFactory: closureFactory.\x0a\x09result pragmas: compilationResult pragmas.\x0a\x09^ result",
  617. referencedClasses: ["Smalltalk"],
  618. //>>excludeEnd("ide");
  619. pragmas: [],
  620. messageSends: ["crlfSanitized", "start:forClass:protocol:", "compileNode:", "parse:", "eval:forPackage:", "wrappedSourceOf:", "currentPackage", "method:withFactory:", "core", "selector", "asArray", "messageSends", "arguments", "classReferences", "pragmas:", "pragmas"]
  621. }, function ($methodClass){ return function (aString,aClass,anotherString){
  622. var self=this,$self=this;
  623. var sanitizedSource,compilationResult,result,pragmas,closureFactory;
  624. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  625. return $core.withContext(function($ctx1) {
  626. //>>excludeEnd("ctx");
  627. sanitizedSource=$recv(aString)._crlfSanitized();
  628. $self._start_forClass_protocol_(sanitizedSource,aClass,anotherString);
  629. compilationResult=$self._compileNode_($self._parse_(sanitizedSource));
  630. closureFactory=$self._eval_forPackage_($self._wrappedSourceOf_(compilationResult),$self._currentPackage());
  631. result=$recv($recv($globals.Smalltalk)._core())._method_withFactory_($globals.HashedCollection._newFromPairs_(["selector",$recv(compilationResult)._selector(),"protocol",anotherString,"source",sanitizedSource,"messageSends",[$recv($recv(compilationResult)._messageSends())._asArray()
  632. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  633. ,$ctx1.sendIdx["asArray"]=1
  634. //>>excludeEnd("ctx");
  635. ][0],"args",$recv(compilationResult)._arguments(),"referencedClasses",$recv($recv(compilationResult)._classReferences())._asArray()]),closureFactory);
  636. $recv(result)._pragmas_($recv(compilationResult)._pragmas());
  637. return result;
  638. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  639. }, function($ctx1) {$ctx1.fill(self,"compile:forClass:protocol:",{aString:aString,aClass:aClass,anotherString:anotherString,sanitizedSource:sanitizedSource,compilationResult:compilationResult,result:result,pragmas:pragmas,closureFactory:closureFactory})});
  640. //>>excludeEnd("ctx");
  641. }; }),
  642. $globals.Compiler);
  643. $core.addMethod(
  644. $core.method({
  645. selector: "compileNode:",
  646. protocol: "compiling",
  647. //>>excludeStart("ide", pragmas.excludeIdeData);
  648. args: ["aNode"],
  649. source: "compileNode: aNode\x0a | result |\x0a\x09result := self codeGenerator compileNode: aNode.\x0a\x09self cleanCodeGenerator.\x0a\x09^ result",
  650. referencedClasses: [],
  651. //>>excludeEnd("ide");
  652. pragmas: [],
  653. messageSends: ["compileNode:", "codeGenerator", "cleanCodeGenerator"]
  654. }, function ($methodClass){ return function (aNode){
  655. var self=this,$self=this;
  656. var result;
  657. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  658. return $core.withContext(function($ctx1) {
  659. //>>excludeEnd("ctx");
  660. result=$recv($self._codeGenerator())._compileNode_(aNode);
  661. $self._cleanCodeGenerator();
  662. return result;
  663. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  664. }, function($ctx1) {$ctx1.fill(self,"compileNode:",{aNode:aNode,result:result})});
  665. //>>excludeEnd("ctx");
  666. }; }),
  667. $globals.Compiler);
  668. $core.addMethod(
  669. $core.method({
  670. selector: "currentPackage",
  671. protocol: "accessing",
  672. //>>excludeStart("ide", pragmas.excludeIdeData);
  673. args: [],
  674. source: "currentPackage\x0a\x09^ currentPackage",
  675. referencedClasses: [],
  676. //>>excludeEnd("ide");
  677. pragmas: [],
  678. messageSends: []
  679. }, function ($methodClass){ return function (){
  680. var self=this,$self=this;
  681. return $self.currentPackage;
  682. }; }),
  683. $globals.Compiler);
  684. $core.addMethod(
  685. $core.method({
  686. selector: "currentPackage:",
  687. protocol: "accessing",
  688. //>>excludeStart("ide", pragmas.excludeIdeData);
  689. args: ["anObject"],
  690. source: "currentPackage: anObject\x0a\x09currentPackage := anObject",
  691. referencedClasses: [],
  692. //>>excludeEnd("ide");
  693. pragmas: [],
  694. messageSends: []
  695. }, function ($methodClass){ return function (anObject){
  696. var self=this,$self=this;
  697. $self.currentPackage=anObject;
  698. return self;
  699. }; }),
  700. $globals.Compiler);
  701. $core.addMethod(
  702. $core.method({
  703. selector: "error:",
  704. protocol: "error handling",
  705. //>>excludeStart("ide", pragmas.excludeIdeData);
  706. args: ["aString"],
  707. source: "error: aString\x0a\x09CompilerError signal: aString",
  708. referencedClasses: ["CompilerError"],
  709. //>>excludeEnd("ide");
  710. pragmas: [],
  711. messageSends: ["signal:"]
  712. }, function ($methodClass){ return function (aString){
  713. var self=this,$self=this;
  714. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  715. return $core.withContext(function($ctx1) {
  716. //>>excludeEnd("ctx");
  717. $recv($globals.CompilerError)._signal_(aString);
  718. return self;
  719. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  720. }, function($ctx1) {$ctx1.fill(self,"error:",{aString:aString})});
  721. //>>excludeEnd("ctx");
  722. }; }),
  723. $globals.Compiler);
  724. $core.addMethod(
  725. $core.method({
  726. selector: "eval:",
  727. protocol: "compiling",
  728. //>>excludeStart("ide", pragmas.excludeIdeData);
  729. args: ["aString"],
  730. source: "eval: aString\x0a\x09<inlineJS: 'return eval(aString)'>",
  731. referencedClasses: [],
  732. //>>excludeEnd("ide");
  733. pragmas: [["inlineJS:", ["return eval(aString)"]]],
  734. messageSends: []
  735. }, function ($methodClass){ return function (aString){
  736. var self=this,$self=this;
  737. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  738. return $core.withContext(function($ctx1) {
  739. //>>excludeEnd("ctx");
  740. return eval(aString);
  741. return self;
  742. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  743. }, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString})});
  744. //>>excludeEnd("ctx");
  745. }; }),
  746. $globals.Compiler);
  747. $core.addMethod(
  748. $core.method({
  749. selector: "eval:forPackage:",
  750. protocol: "compiling",
  751. //>>excludeStart("ide", pragmas.excludeIdeData);
  752. args: ["aString", "aPackage"],
  753. source: "eval: aString forPackage: aPackage\x0a\x09^ aPackage\x0a\x09\x09ifNil: [ self eval: aString ]\x0a\x09\x09ifNotNil: [ aPackage eval: aString ]",
  754. referencedClasses: [],
  755. //>>excludeEnd("ide");
  756. pragmas: [],
  757. messageSends: ["ifNil:ifNotNil:", "eval:"]
  758. }, function ($methodClass){ return function (aString,aPackage){
  759. var self=this,$self=this;
  760. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  761. return $core.withContext(function($ctx1) {
  762. //>>excludeEnd("ctx");
  763. if(aPackage == null || aPackage.a$nil){
  764. return [$self._eval_(aString)
  765. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  766. ,$ctx1.sendIdx["eval:"]=1
  767. //>>excludeEnd("ctx");
  768. ][0];
  769. } else {
  770. return $recv(aPackage)._eval_(aString);
  771. }
  772. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  773. }, function($ctx1) {$ctx1.fill(self,"eval:forPackage:",{aString:aString,aPackage:aPackage})});
  774. //>>excludeEnd("ctx");
  775. }; }),
  776. $globals.Compiler);
  777. $core.addMethod(
  778. $core.method({
  779. selector: "evaluateExpression:",
  780. protocol: "compiling",
  781. //>>excludeStart("ide", pragmas.excludeIdeData);
  782. args: ["aString"],
  783. 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",
  784. referencedClasses: ["DoIt"],
  785. //>>excludeEnd("ide");
  786. pragmas: [],
  787. messageSends: ["evaluateExpression:on:", "new"]
  788. }, function ($methodClass){ return function (aString){
  789. var self=this,$self=this;
  790. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  791. return $core.withContext(function($ctx1) {
  792. //>>excludeEnd("ctx");
  793. return $self._evaluateExpression_on_(aString,$recv($globals.DoIt)._new());
  794. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  795. }, function($ctx1) {$ctx1.fill(self,"evaluateExpression:",{aString:aString})});
  796. //>>excludeEnd("ctx");
  797. }; }),
  798. $globals.Compiler);
  799. $core.addMethod(
  800. $core.method({
  801. selector: "evaluateExpression:on:",
  802. protocol: "compiling",
  803. //>>excludeStart("ide", pragmas.excludeIdeData);
  804. args: ["aString", "anObject"],
  805. 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\x0a\x09\x09install: (self sourceForExpression: aString)\x0a\x09\x09forClass: anObject class\x0a\x09\x09protocol: '**xxxDoIt'.\x0a\x09result := anObject xxxDoIt.\x0a\x09anObject class removeCompiledMethod: method.\x0a\x09^ result",
  806. referencedClasses: [],
  807. //>>excludeEnd("ide");
  808. pragmas: [],
  809. messageSends: ["install:forClass:protocol:", "sourceForExpression:", "class", "xxxDoIt", "removeCompiledMethod:"]
  810. }, function ($methodClass){ return function (aString,anObject){
  811. var self=this,$self=this;
  812. var result,method;
  813. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  814. return $core.withContext(function($ctx1) {
  815. //>>excludeEnd("ctx");
  816. method=$self._install_forClass_protocol_($self._sourceForExpression_(aString),[$recv(anObject)._class()
  817. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  818. ,$ctx1.sendIdx["class"]=1
  819. //>>excludeEnd("ctx");
  820. ][0],"**xxxDoIt");
  821. result=$recv(anObject)._xxxDoIt();
  822. $recv($recv(anObject)._class())._removeCompiledMethod_(method);
  823. return result;
  824. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  825. }, function($ctx1) {$ctx1.fill(self,"evaluateExpression:on:",{aString:aString,anObject:anObject,result:result,method:method})});
  826. //>>excludeEnd("ctx");
  827. }; }),
  828. $globals.Compiler);
  829. $core.addMethod(
  830. $core.method({
  831. selector: "install:forClass:protocol:",
  832. protocol: "compiling",
  833. //>>excludeStart("ide", pragmas.excludeIdeData);
  834. args: ["aString", "aBehavior", "anotherString"],
  835. 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",
  836. referencedClasses: [],
  837. //>>excludeEnd("ide");
  838. pragmas: [],
  839. messageSends: ["compile:forClass:protocol:", "addCompiledMethod:"]
  840. }, function ($methodClass){ return function (aString,aBehavior,anotherString){
  841. var self=this,$self=this;
  842. var compiledMethod;
  843. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  844. return $core.withContext(function($ctx1) {
  845. //>>excludeEnd("ctx");
  846. compiledMethod=$self._compile_forClass_protocol_(aString,aBehavior,anotherString);
  847. $recv(aBehavior)._addCompiledMethod_(compiledMethod);
  848. return compiledMethod;
  849. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  850. }, function($ctx1) {$ctx1.fill(self,"install:forClass:protocol:",{aString:aString,aBehavior:aBehavior,anotherString:anotherString,compiledMethod:compiledMethod})});
  851. //>>excludeEnd("ctx");
  852. }; }),
  853. $globals.Compiler);
  854. $core.addMethod(
  855. $core.method({
  856. selector: "parse:",
  857. protocol: "compiling",
  858. //>>excludeStart("ide", pragmas.excludeIdeData);
  859. args: ["aString"],
  860. source: "parse: aString\x0a\x09| result |\x0a\x09\x0a\x09[ result := self basicParse: aString ] \x0a\x09\x09tryIfTrue: [ :err | (err basicAt: 'location') notNil ]\x0a\x09\x09catch: [ :ex | (self parseError: ex parsing: aString) signal ].\x0a\x09\x09\x0a\x09^ result",
  861. referencedClasses: [],
  862. //>>excludeEnd("ide");
  863. pragmas: [],
  864. messageSends: ["tryIfTrue:catch:", "basicParse:", "notNil", "basicAt:", "signal", "parseError:parsing:"]
  865. }, function ($methodClass){ return function (aString){
  866. var self=this,$self=this;
  867. var result;
  868. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  869. return $core.withContext(function($ctx1) {
  870. //>>excludeEnd("ctx");
  871. $recv((function(){
  872. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  873. return $core.withContext(function($ctx2) {
  874. //>>excludeEnd("ctx");
  875. result=$self._basicParse_(aString);
  876. return result;
  877. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  878. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  879. //>>excludeEnd("ctx");
  880. }))._tryIfTrue_catch_((function(err){
  881. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  882. return $core.withContext(function($ctx2) {
  883. //>>excludeEnd("ctx");
  884. return $recv($recv(err)._basicAt_("location"))._notNil();
  885. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  886. }, function($ctx2) {$ctx2.fillBlock({err:err},$ctx1,2)});
  887. //>>excludeEnd("ctx");
  888. }),(function(ex){
  889. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  890. return $core.withContext(function($ctx2) {
  891. //>>excludeEnd("ctx");
  892. return $recv($self._parseError_parsing_(ex,aString))._signal();
  893. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  894. }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1,3)});
  895. //>>excludeEnd("ctx");
  896. }));
  897. return result;
  898. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  899. }, function($ctx1) {$ctx1.fill(self,"parse:",{aString:aString,result:result})});
  900. //>>excludeEnd("ctx");
  901. }; }),
  902. $globals.Compiler);
  903. $core.addMethod(
  904. $core.method({
  905. selector: "parseError:parsing:",
  906. protocol: "error handling",
  907. //>>excludeStart("ide", pragmas.excludeIdeData);
  908. args: ["anException", "aString"],
  909. source: "parseError: anException parsing: aString\x0a\x09| loc |\x0a\x09loc := anException basicAt: 'location'.\x0a\x09^ ParseError messageText:\x0a\x09\x09'Parse error on line ', loc start line asString,\x0a\x09\x09' column ' , loc start column asString,\x0a\x09\x09' : Unexpected character ', (anException basicAt: 'found')",
  910. referencedClasses: ["ParseError"],
  911. //>>excludeEnd("ide");
  912. pragmas: [],
  913. messageSends: ["basicAt:", "messageText:", ",", "asString", "line", "start", "column"]
  914. }, function ($methodClass){ return function (anException,aString){
  915. var self=this,$self=this;
  916. var loc;
  917. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  918. return $core.withContext(function($ctx1) {
  919. //>>excludeEnd("ctx");
  920. loc=[$recv(anException)._basicAt_("location")
  921. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  922. ,$ctx1.sendIdx["basicAt:"]=1
  923. //>>excludeEnd("ctx");
  924. ][0];
  925. return $recv($globals.ParseError)._messageText_([$recv([$recv([$recv([$recv("Parse error on line ".__comma([$recv($recv([$recv(loc)._start()
  926. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  927. ,$ctx1.sendIdx["start"]=1
  928. //>>excludeEnd("ctx");
  929. ][0])._line())._asString()
  930. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  931. ,$ctx1.sendIdx["asString"]=1
  932. //>>excludeEnd("ctx");
  933. ][0])).__comma(" column ")
  934. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  935. ,$ctx1.sendIdx[","]=4
  936. //>>excludeEnd("ctx");
  937. ][0]).__comma($recv($recv($recv(loc)._start())._column())._asString())
  938. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  939. ,$ctx1.sendIdx[","]=3
  940. //>>excludeEnd("ctx");
  941. ][0]).__comma(" : Unexpected character ")
  942. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  943. ,$ctx1.sendIdx[","]=2
  944. //>>excludeEnd("ctx");
  945. ][0]).__comma($recv(anException)._basicAt_("found"))
  946. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  947. ,$ctx1.sendIdx[","]=1
  948. //>>excludeEnd("ctx");
  949. ][0]);
  950. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  951. }, function($ctx1) {$ctx1.fill(self,"parseError:parsing:",{anException:anException,aString:aString,loc:loc})});
  952. //>>excludeEnd("ctx");
  953. }; }),
  954. $globals.Compiler);
  955. $core.addMethod(
  956. $core.method({
  957. selector: "parseExpression:",
  958. protocol: "compiling",
  959. //>>excludeStart("ide", pragmas.excludeIdeData);
  960. args: ["aString"],
  961. source: "parseExpression: aString\x0a\x09^ self parse: (self sourceForExpression: aString)",
  962. referencedClasses: [],
  963. //>>excludeEnd("ide");
  964. pragmas: [],
  965. messageSends: ["parse:", "sourceForExpression:"]
  966. }, function ($methodClass){ return function (aString){
  967. var self=this,$self=this;
  968. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  969. return $core.withContext(function($ctx1) {
  970. //>>excludeEnd("ctx");
  971. return $self._parse_($self._sourceForExpression_(aString));
  972. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  973. }, function($ctx1) {$ctx1.fill(self,"parseExpression:",{aString:aString})});
  974. //>>excludeEnd("ctx");
  975. }; }),
  976. $globals.Compiler);
  977. $core.addMethod(
  978. $core.method({
  979. selector: "recompile:",
  980. protocol: "compiling",
  981. //>>excludeStart("ide", pragmas.excludeIdeData);
  982. args: ["aClass"],
  983. source: "recompile: aClass\x0a\x09aClass includingPossibleMetaDo: [ :eachSide |\x0a\x09\x09eachSide methodDictionary values\x0a\x09\x09\x09do: [ :each | each origin = eachSide ifTrue: [ \x0a\x09\x09\x09\x09self \x0a\x09\x09\x09\x09\x09install: each source \x0a\x09\x09\x09\x09\x09forClass: eachSide \x0a\x09\x09\x09\x09\x09protocol: each protocol ] ]\x0a\x09\x09\x09displayingProgress: 'Recompiling ', eachSide name ]",
  984. referencedClasses: [],
  985. //>>excludeEnd("ide");
  986. pragmas: [],
  987. messageSends: ["includingPossibleMetaDo:", "do:displayingProgress:", "values", "methodDictionary", "ifTrue:", "=", "origin", "install:forClass:protocol:", "source", "protocol", ",", "name"]
  988. }, function ($methodClass){ return function (aClass){
  989. var self=this,$self=this;
  990. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  991. return $core.withContext(function($ctx1) {
  992. //>>excludeEnd("ctx");
  993. $recv(aClass)._includingPossibleMetaDo_((function(eachSide){
  994. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  995. return $core.withContext(function($ctx2) {
  996. //>>excludeEnd("ctx");
  997. return $recv($recv($recv(eachSide)._methodDictionary())._values())._do_displayingProgress_((function(each){
  998. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  999. return $core.withContext(function($ctx3) {
  1000. //>>excludeEnd("ctx");
  1001. if($core.assert($recv($recv(each)._origin()).__eq(eachSide))){
  1002. return $self._install_forClass_protocol_($recv(each)._source(),eachSide,$recv(each)._protocol());
  1003. }
  1004. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1005. }, function($ctx3) {$ctx3.fillBlock({each:each},$ctx2,2)});
  1006. //>>excludeEnd("ctx");
  1007. }),"Recompiling ".__comma($recv(eachSide)._name()));
  1008. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1009. }, function($ctx2) {$ctx2.fillBlock({eachSide:eachSide},$ctx1,1)});
  1010. //>>excludeEnd("ctx");
  1011. }));
  1012. return self;
  1013. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1014. }, function($ctx1) {$ctx1.fill(self,"recompile:",{aClass:aClass})});
  1015. //>>excludeEnd("ctx");
  1016. }; }),
  1017. $globals.Compiler);
  1018. $core.addMethod(
  1019. $core.method({
  1020. selector: "recompileAll",
  1021. protocol: "compiling",
  1022. //>>excludeStart("ide", pragmas.excludeIdeData);
  1023. args: [],
  1024. source: "recompileAll\x0a\x09Smalltalk classes \x0a\x09\x09do: [ :each | self recompile: each ]\x0a\x09\x09displayingProgress: 'Compiling all classes...'",
  1025. referencedClasses: ["Smalltalk"],
  1026. //>>excludeEnd("ide");
  1027. pragmas: [],
  1028. messageSends: ["do:displayingProgress:", "classes", "recompile:"]
  1029. }, function ($methodClass){ return function (){
  1030. var self=this,$self=this;
  1031. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1032. return $core.withContext(function($ctx1) {
  1033. //>>excludeEnd("ctx");
  1034. $recv($recv($globals.Smalltalk)._classes())._do_displayingProgress_((function(each){
  1035. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1036. return $core.withContext(function($ctx2) {
  1037. //>>excludeEnd("ctx");
  1038. return $self._recompile_(each);
  1039. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1040. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  1041. //>>excludeEnd("ctx");
  1042. }),"Compiling all classes...");
  1043. return self;
  1044. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1045. }, function($ctx1) {$ctx1.fill(self,"recompileAll",{})});
  1046. //>>excludeEnd("ctx");
  1047. }; }),
  1048. $globals.Compiler);
  1049. $core.addMethod(
  1050. $core.method({
  1051. selector: "sourceForExpression:",
  1052. protocol: "compiling",
  1053. //>>excludeStart("ide", pragmas.excludeIdeData);
  1054. args: ["aString"],
  1055. source: "sourceForExpression: aString\x0a\x09^ 'xxxDoIt ^ [ ', aString, ' ] value'",
  1056. referencedClasses: [],
  1057. //>>excludeEnd("ide");
  1058. pragmas: [],
  1059. messageSends: [","]
  1060. }, function ($methodClass){ return function (aString){
  1061. var self=this,$self=this;
  1062. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1063. return $core.withContext(function($ctx1) {
  1064. //>>excludeEnd("ctx");
  1065. return [$recv("xxxDoIt ^ [ ".__comma(aString)).__comma(" ] value")
  1066. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1067. ,$ctx1.sendIdx[","]=1
  1068. //>>excludeEnd("ctx");
  1069. ][0];
  1070. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1071. }, function($ctx1) {$ctx1.fill(self,"sourceForExpression:",{aString:aString})});
  1072. //>>excludeEnd("ctx");
  1073. }; }),
  1074. $globals.Compiler);
  1075. $core.addMethod(
  1076. $core.method({
  1077. selector: "start:forClass:protocol:",
  1078. protocol: "compiling",
  1079. //>>excludeStart("ide", pragmas.excludeIdeData);
  1080. args: ["aString", "aClass", "anotherString"],
  1081. source: "start: aString forClass: aClass protocol: anotherString\x0a\x09| package |\x0a\x09package := aClass packageOfProtocol: anotherString.\x0a\x09self\x0a\x09\x09currentPackage: package;\x0a\x09\x09codeGenerator: (self codeGeneratorClass new\x0a\x09\x09\x09source: aString;\x0a\x09\x09\x09currentClass: aClass;\x0a\x09\x09\x09currentPackage: package;\x0a\x09\x09\x09yourself)",
  1082. referencedClasses: [],
  1083. //>>excludeEnd("ide");
  1084. pragmas: [],
  1085. messageSends: ["packageOfProtocol:", "currentPackage:", "codeGenerator:", "source:", "new", "codeGeneratorClass", "currentClass:", "yourself"]
  1086. }, function ($methodClass){ return function (aString,aClass,anotherString){
  1087. var self=this,$self=this;
  1088. var package_;
  1089. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1090. return $core.withContext(function($ctx1) {
  1091. //>>excludeEnd("ctx");
  1092. var $1;
  1093. package_=$recv(aClass)._packageOfProtocol_(anotherString);
  1094. [$self._currentPackage_(package_)
  1095. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1096. ,$ctx1.sendIdx["currentPackage:"]=1
  1097. //>>excludeEnd("ctx");
  1098. ][0];
  1099. $1=$recv($self._codeGeneratorClass())._new();
  1100. $recv($1)._source_(aString);
  1101. $recv($1)._currentClass_(aClass);
  1102. $recv($1)._currentPackage_(package_);
  1103. $self._codeGenerator_($recv($1)._yourself());
  1104. return self;
  1105. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1106. }, function($ctx1) {$ctx1.fill(self,"start:forClass:protocol:",{aString:aString,aClass:aClass,anotherString:anotherString,package_:package_})});
  1107. //>>excludeEnd("ctx");
  1108. }; }),
  1109. $globals.Compiler);
  1110. $core.addMethod(
  1111. $core.method({
  1112. selector: "transformerAt:put:",
  1113. protocol: "compiling",
  1114. //>>excludeStart("ide", pragmas.excludeIdeData);
  1115. args: ["aString", "anObject"],
  1116. source: "transformerAt: aString put: anObject\x0a\x09self codeGenerator transformersDictionary at: aString put: anObject",
  1117. referencedClasses: [],
  1118. //>>excludeEnd("ide");
  1119. pragmas: [],
  1120. messageSends: ["at:put:", "transformersDictionary", "codeGenerator"]
  1121. }, function ($methodClass){ return function (aString,anObject){
  1122. var self=this,$self=this;
  1123. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1124. return $core.withContext(function($ctx1) {
  1125. //>>excludeEnd("ctx");
  1126. $recv($recv($self._codeGenerator())._transformersDictionary())._at_put_(aString,anObject);
  1127. return self;
  1128. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1129. }, function($ctx1) {$ctx1.fill(self,"transformerAt:put:",{aString:aString,anObject:anObject})});
  1130. //>>excludeEnd("ctx");
  1131. }; }),
  1132. $globals.Compiler);
  1133. $core.addMethod(
  1134. $core.method({
  1135. selector: "wrappedSourceOf:",
  1136. protocol: "private",
  1137. //>>excludeStart("ide", pragmas.excludeIdeData);
  1138. args: ["anIRMethod"],
  1139. source: "wrappedSourceOf: anIRMethod\x0a\x09^ anIRMethod attachments\x0a\x09\x09ifEmpty: [\x0a\x09\x09\x09'(function ($methodClass){ return ',\x0a\x09\x09\x09anIRMethod compiledSource,\x0a\x09\x09\x09'; })' ]\x0a\x09\x09ifNotEmpty: [ :attachments |\x0a\x09\x09\x09'(function ($methodClass){ return Object.defineProperty(',\x0a\x09\x09\x09anIRMethod compiledSource,\x0a\x09\x09\x09',\x22a$atx\x22,{enumerable:false,configurable:true,writable:true,value:',\x0a\x09\x09\x09attachments asJavaScriptSource,\x0a\x09\x09\x09'}); })' ]",
  1140. referencedClasses: [],
  1141. //>>excludeEnd("ide");
  1142. pragmas: [],
  1143. messageSends: ["ifEmpty:ifNotEmpty:", "attachments", ",", "compiledSource", "asJavaScriptSource"]
  1144. }, function ($methodClass){ return function (anIRMethod){
  1145. var self=this,$self=this;
  1146. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1147. return $core.withContext(function($ctx1) {
  1148. //>>excludeEnd("ctx");
  1149. return $recv($recv(anIRMethod)._attachments())._ifEmpty_ifNotEmpty_((function(){
  1150. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1151. return $core.withContext(function($ctx2) {
  1152. //>>excludeEnd("ctx");
  1153. return [$recv(["(function ($methodClass){ return ".__comma([$recv(anIRMethod)._compiledSource()
  1154. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1155. ,$ctx2.sendIdx["compiledSource"]=1
  1156. //>>excludeEnd("ctx");
  1157. ][0])
  1158. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1159. ,$ctx2.sendIdx[","]=2
  1160. //>>excludeEnd("ctx");
  1161. ][0]).__comma("; })")
  1162. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1163. ,$ctx2.sendIdx[","]=1
  1164. //>>excludeEnd("ctx");
  1165. ][0];
  1166. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1167. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  1168. //>>excludeEnd("ctx");
  1169. }),(function(attachments){
  1170. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1171. return $core.withContext(function($ctx2) {
  1172. //>>excludeEnd("ctx");
  1173. return [$recv([$recv([$recv("(function ($methodClass){ return Object.defineProperty(".__comma($recv(anIRMethod)._compiledSource())).__comma(",\x22a$atx\x22,{enumerable:false,configurable:true,writable:true,value:")
  1174. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1175. ,$ctx2.sendIdx[","]=5
  1176. //>>excludeEnd("ctx");
  1177. ][0]).__comma($recv(attachments)._asJavaScriptSource())
  1178. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1179. ,$ctx2.sendIdx[","]=4
  1180. //>>excludeEnd("ctx");
  1181. ][0]).__comma("}); })")
  1182. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1183. ,$ctx2.sendIdx[","]=3
  1184. //>>excludeEnd("ctx");
  1185. ][0];
  1186. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1187. }, function($ctx2) {$ctx2.fillBlock({attachments:attachments},$ctx1,2)});
  1188. //>>excludeEnd("ctx");
  1189. }));
  1190. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1191. }, function($ctx1) {$ctx1.fill(self,"wrappedSourceOf:",{anIRMethod:anIRMethod})});
  1192. //>>excludeEnd("ctx");
  1193. }; }),
  1194. $globals.Compiler);
  1195. $core.addMethod(
  1196. $core.method({
  1197. selector: "eval:",
  1198. protocol: "evaluating",
  1199. //>>excludeStart("ide", pragmas.excludeIdeData);
  1200. args: ["aString"],
  1201. source: "eval: aString\x0a\x09^ self new eval: aString",
  1202. referencedClasses: [],
  1203. //>>excludeEnd("ide");
  1204. pragmas: [],
  1205. messageSends: ["eval:", "new"]
  1206. }, function ($methodClass){ return function (aString){
  1207. var self=this,$self=this;
  1208. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1209. return $core.withContext(function($ctx1) {
  1210. //>>excludeEnd("ctx");
  1211. return $recv($self._new())._eval_(aString);
  1212. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1213. }, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString})});
  1214. //>>excludeEnd("ctx");
  1215. }; }),
  1216. $globals.Compiler.a$cls);
  1217. $core.addMethod(
  1218. $core.method({
  1219. selector: "parse:",
  1220. protocol: "parsing",
  1221. //>>excludeStart("ide", pragmas.excludeIdeData);
  1222. args: ["aString"],
  1223. source: "parse: aString\x0a\x09^ self new parse: aString",
  1224. referencedClasses: [],
  1225. //>>excludeEnd("ide");
  1226. pragmas: [],
  1227. messageSends: ["parse:", "new"]
  1228. }, function ($methodClass){ return function (aString){
  1229. var self=this,$self=this;
  1230. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1231. return $core.withContext(function($ctx1) {
  1232. //>>excludeEnd("ctx");
  1233. return $recv($self._new())._parse_(aString);
  1234. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1235. }, function($ctx1) {$ctx1.fill(self,"parse:",{aString:aString})});
  1236. //>>excludeEnd("ctx");
  1237. }; }),
  1238. $globals.Compiler.a$cls);
  1239. $core.addMethod(
  1240. $core.method({
  1241. selector: "pseudoVariableNames",
  1242. protocol: "parsing",
  1243. //>>excludeStart("ide", pragmas.excludeIdeData);
  1244. args: [],
  1245. source: "pseudoVariableNames\x0a\x09^ PseudoVar dictionary keys asArray",
  1246. referencedClasses: ["PseudoVar"],
  1247. //>>excludeEnd("ide");
  1248. pragmas: [],
  1249. messageSends: ["asArray", "keys", "dictionary"]
  1250. }, function ($methodClass){ return function (){
  1251. var self=this,$self=this;
  1252. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1253. return $core.withContext(function($ctx1) {
  1254. //>>excludeEnd("ctx");
  1255. return $recv($recv($recv($globals.PseudoVar)._dictionary())._keys())._asArray();
  1256. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1257. }, function($ctx1) {$ctx1.fill(self,"pseudoVariableNames",{})});
  1258. //>>excludeEnd("ctx");
  1259. }; }),
  1260. $globals.Compiler.a$cls);
  1261. $core.addMethod(
  1262. $core.method({
  1263. selector: "recompile:",
  1264. protocol: "compiling",
  1265. //>>excludeStart("ide", pragmas.excludeIdeData);
  1266. args: ["aClass"],
  1267. source: "recompile: aClass\x0a\x09self new recompile: aClass",
  1268. referencedClasses: [],
  1269. //>>excludeEnd("ide");
  1270. pragmas: [],
  1271. messageSends: ["recompile:", "new"]
  1272. }, function ($methodClass){ return function (aClass){
  1273. var self=this,$self=this;
  1274. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1275. return $core.withContext(function($ctx1) {
  1276. //>>excludeEnd("ctx");
  1277. $recv($self._new())._recompile_(aClass);
  1278. return self;
  1279. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1280. }, function($ctx1) {$ctx1.fill(self,"recompile:",{aClass:aClass})});
  1281. //>>excludeEnd("ctx");
  1282. }; }),
  1283. $globals.Compiler.a$cls);
  1284. $core.addMethod(
  1285. $core.method({
  1286. selector: "recompileAll",
  1287. protocol: "compiling",
  1288. //>>excludeStart("ide", pragmas.excludeIdeData);
  1289. args: [],
  1290. source: "recompileAll\x0a\x09Smalltalk classes do: [ :each |\x0a\x09\x09self recompile: each ]",
  1291. referencedClasses: ["Smalltalk"],
  1292. //>>excludeEnd("ide");
  1293. pragmas: [],
  1294. messageSends: ["do:", "classes", "recompile:"]
  1295. }, function ($methodClass){ return function (){
  1296. var self=this,$self=this;
  1297. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1298. return $core.withContext(function($ctx1) {
  1299. //>>excludeEnd("ctx");
  1300. $recv($recv($globals.Smalltalk)._classes())._do_((function(each){
  1301. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1302. return $core.withContext(function($ctx2) {
  1303. //>>excludeEnd("ctx");
  1304. return $self._recompile_(each);
  1305. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1306. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  1307. //>>excludeEnd("ctx");
  1308. }));
  1309. return self;
  1310. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1311. }, function($ctx1) {$ctx1.fill(self,"recompileAll",{})});
  1312. //>>excludeEnd("ctx");
  1313. }; }),
  1314. $globals.Compiler.a$cls);
  1315. $core.addClass("DoIt", $globals.Object, "Compiler-Core");
  1316. //>>excludeStart("ide", pragmas.excludeIdeData);
  1317. $globals.DoIt.comment="`DoIt` is the class used to compile and evaluate expressions. See `Compiler >> evaluateExpression:`.";
  1318. //>>excludeEnd("ide");
  1319. $core.addClass("Evaluator", $globals.Object, "Compiler-Core");
  1320. //>>excludeStart("ide", pragmas.excludeIdeData);
  1321. $globals.Evaluator.comment="I evaluate code against a receiver, dispatching #evaluate:on: to the receiver.";
  1322. //>>excludeEnd("ide");
  1323. $core.addMethod(
  1324. $core.method({
  1325. selector: "evaluate:for:",
  1326. protocol: "evaluating",
  1327. //>>excludeStart("ide", pragmas.excludeIdeData);
  1328. args: ["aString", "anObject"],
  1329. source: "evaluate: aString for: anObject\x0a\x09^ anObject evaluate: aString on: self",
  1330. referencedClasses: [],
  1331. //>>excludeEnd("ide");
  1332. pragmas: [],
  1333. messageSends: ["evaluate:on:"]
  1334. }, function ($methodClass){ return function (aString,anObject){
  1335. var self=this,$self=this;
  1336. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1337. return $core.withContext(function($ctx1) {
  1338. //>>excludeEnd("ctx");
  1339. return $recv(anObject)._evaluate_on_(aString,self);
  1340. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1341. }, function($ctx1) {$ctx1.fill(self,"evaluate:for:",{aString:aString,anObject:anObject})});
  1342. //>>excludeEnd("ctx");
  1343. }; }),
  1344. $globals.Evaluator);
  1345. $core.addMethod(
  1346. $core.method({
  1347. selector: "evaluate:receiver:",
  1348. protocol: "evaluating",
  1349. //>>excludeStart("ide", pragmas.excludeIdeData);
  1350. args: ["aString", "anObject"],
  1351. 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",
  1352. referencedClasses: ["Compiler", "Error", "Terminal"],
  1353. //>>excludeEnd("ide");
  1354. pragmas: [],
  1355. messageSends: ["new", "on:do:", "parseExpression:", "alert:", "messageText", "evaluateExpression:on:"]
  1356. }, function ($methodClass){ return function (aString,anObject){
  1357. var self=this,$self=this;
  1358. var compiler;
  1359. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1360. return $core.withContext(function($ctx1) {
  1361. //>>excludeEnd("ctx");
  1362. var $early={};
  1363. try {
  1364. compiler=$recv($globals.Compiler)._new();
  1365. $recv((function(){
  1366. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1367. return $core.withContext(function($ctx2) {
  1368. //>>excludeEnd("ctx");
  1369. return $recv(compiler)._parseExpression_(aString);
  1370. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1371. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  1372. //>>excludeEnd("ctx");
  1373. }))._on_do_($globals.Error,(function(ex){
  1374. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1375. return $core.withContext(function($ctx2) {
  1376. //>>excludeEnd("ctx");
  1377. throw $early=[$recv($globals.Terminal)._alert_($recv(ex)._messageText())];
  1378. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1379. }, function($ctx2) {$ctx2.fillBlock({ex:ex},$ctx1,2)});
  1380. //>>excludeEnd("ctx");
  1381. }));
  1382. return $recv(compiler)._evaluateExpression_on_(aString,anObject);
  1383. }
  1384. catch(e) {if(e===$early)return e[0]; throw e}
  1385. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1386. }, function($ctx1) {$ctx1.fill(self,"evaluate:receiver:",{aString:aString,anObject:anObject,compiler:compiler})});
  1387. //>>excludeEnd("ctx");
  1388. }; }),
  1389. $globals.Evaluator);
  1390. $core.addMethod(
  1391. $core.method({
  1392. selector: "evaluate:for:",
  1393. protocol: "instance creation",
  1394. //>>excludeStart("ide", pragmas.excludeIdeData);
  1395. args: ["aString", "anObject"],
  1396. source: "evaluate: aString for: anObject\x0a\x09^ self new evaluate: aString for: anObject",
  1397. referencedClasses: [],
  1398. //>>excludeEnd("ide");
  1399. pragmas: [],
  1400. messageSends: ["evaluate:for:", "new"]
  1401. }, function ($methodClass){ return function (aString,anObject){
  1402. var self=this,$self=this;
  1403. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1404. return $core.withContext(function($ctx1) {
  1405. //>>excludeEnd("ctx");
  1406. return $recv($self._new())._evaluate_for_(aString,anObject);
  1407. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1408. }, function($ctx1) {$ctx1.fill(self,"evaluate:for:",{aString:aString,anObject:anObject})});
  1409. //>>excludeEnd("ctx");
  1410. }; }),
  1411. $globals.Evaluator.a$cls);
  1412. $core.addClass("ParseError", $globals.Error, "Compiler-Core");
  1413. //>>excludeStart("ide", pragmas.excludeIdeData);
  1414. $globals.ParseError.comment="Instance of ParseError are signaled on any parsing error.\x0aSee `Compiler >> #parse:`";
  1415. //>>excludeEnd("ide");
  1416. $core.addTrait("TPragmator", "Compiler-Core");
  1417. $core.addMethod(
  1418. $core.method({
  1419. selector: "canProcessPragma:",
  1420. protocol: "pragma processing",
  1421. //>>excludeStart("ide", pragmas.excludeIdeData);
  1422. args: ["aMessage"],
  1423. source: "canProcessPragma: aMessage\x0a\x09^ self class includesSelector: aMessage selector",
  1424. referencedClasses: [],
  1425. //>>excludeEnd("ide");
  1426. pragmas: [],
  1427. messageSends: ["includesSelector:", "class", "selector"]
  1428. }, function ($methodClass){ return function (aMessage){
  1429. var self=this,$self=this;
  1430. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1431. return $core.withContext(function($ctx1) {
  1432. //>>excludeEnd("ctx");
  1433. return $recv($self._class())._includesSelector_($recv(aMessage)._selector());
  1434. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1435. }, function($ctx1) {$ctx1.fill(self,"canProcessPragma:",{aMessage:aMessage})});
  1436. //>>excludeEnd("ctx");
  1437. }; }),
  1438. $globals.TPragmator);
  1439. $core.addMethod(
  1440. $core.method({
  1441. selector: "processPragma:",
  1442. protocol: "pragma processing",
  1443. //>>excludeStart("ide", pragmas.excludeIdeData);
  1444. args: ["aMessage"],
  1445. source: "processPragma: aMessage\x0a\x09(self canProcessPragma: aMessage) ifTrue: [\x0a\x09\x09^ aMessage sendTo: self ]",
  1446. referencedClasses: [],
  1447. //>>excludeEnd("ide");
  1448. pragmas: [],
  1449. messageSends: ["ifTrue:", "canProcessPragma:", "sendTo:"]
  1450. }, function ($methodClass){ return function (aMessage){
  1451. var self=this,$self=this;
  1452. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1453. return $core.withContext(function($ctx1) {
  1454. //>>excludeEnd("ctx");
  1455. if($core.assert($self._canProcessPragma_(aMessage))){
  1456. return $recv(aMessage)._sendTo_(self);
  1457. }
  1458. return self;
  1459. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1460. }, function($ctx1) {$ctx1.fill(self,"processPragma:",{aMessage:aMessage})});
  1461. //>>excludeEnd("ctx");
  1462. }; }),
  1463. $globals.TPragmator);
  1464. $core.addMethod(
  1465. $core.method({
  1466. selector: "processPragmas:",
  1467. protocol: "pragma processing",
  1468. //>>excludeStart("ide", pragmas.excludeIdeData);
  1469. args: ["aCollection"],
  1470. source: "processPragmas: aCollection\x0a\x09aCollection do: [ :each | self processPragma: each ]",
  1471. referencedClasses: [],
  1472. //>>excludeEnd("ide");
  1473. pragmas: [],
  1474. messageSends: ["do:", "processPragma:"]
  1475. }, function ($methodClass){ return function (aCollection){
  1476. var self=this,$self=this;
  1477. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1478. return $core.withContext(function($ctx1) {
  1479. //>>excludeEnd("ctx");
  1480. $recv(aCollection)._do_((function(each){
  1481. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1482. return $core.withContext(function($ctx2) {
  1483. //>>excludeEnd("ctx");
  1484. return $self._processPragma_(each);
  1485. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1486. }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,1)});
  1487. //>>excludeEnd("ctx");
  1488. }));
  1489. return self;
  1490. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1491. }, function($ctx1) {$ctx1.fill(self,"processPragmas:",{aCollection:aCollection})});
  1492. //>>excludeEnd("ctx");
  1493. }; }),
  1494. $globals.TPragmator);
  1495. $core.addMethod(
  1496. $core.method({
  1497. selector: "eval:",
  1498. protocol: "*Compiler-Core",
  1499. //>>excludeStart("ide", pragmas.excludeIdeData);
  1500. args: ["aString"],
  1501. source: "eval: aString\x0a\x09^ self context\x0a\x09\x09ifEmpty: [ Compiler eval: aString ]\x0a\x09\x09ifNotEmpty: [ :context |\x0a\x09\x09\x09| wrapperSource |\x0a\x09\x09\x09wrapperSource :=\x0a\x09\x09\x09\x09'(function(', (',' join: context keys), '){return(', aString, ');})'.\x0a\x09\x09\x09(Compiler eval: wrapperSource)\x0a\x09\x09\x09\x09valueWithPossibleArguments: context values ]",
  1502. referencedClasses: ["Compiler"],
  1503. //>>excludeEnd("ide");
  1504. pragmas: [],
  1505. messageSends: ["ifEmpty:ifNotEmpty:", "context", "eval:", ",", "join:", "keys", "valueWithPossibleArguments:", "values"]
  1506. }, function ($methodClass){ return function (aString){
  1507. var self=this,$self=this;
  1508. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1509. return $core.withContext(function($ctx1) {
  1510. //>>excludeEnd("ctx");
  1511. return $recv($self._context())._ifEmpty_ifNotEmpty_((function(){
  1512. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1513. return $core.withContext(function($ctx2) {
  1514. //>>excludeEnd("ctx");
  1515. return [$recv($globals.Compiler)._eval_(aString)
  1516. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1517. ,$ctx2.sendIdx["eval:"]=1
  1518. //>>excludeEnd("ctx");
  1519. ][0];
  1520. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1521. }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
  1522. //>>excludeEnd("ctx");
  1523. }),(function(context){
  1524. var wrapperSource;
  1525. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1526. return $core.withContext(function($ctx2) {
  1527. //>>excludeEnd("ctx");
  1528. wrapperSource=[$recv([$recv([$recv("(function(".__comma(","._join_($recv(context)._keys()))).__comma("){return(")
  1529. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1530. ,$ctx2.sendIdx[","]=3
  1531. //>>excludeEnd("ctx");
  1532. ][0]).__comma(aString)
  1533. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1534. ,$ctx2.sendIdx[","]=2
  1535. //>>excludeEnd("ctx");
  1536. ][0]).__comma(");})")
  1537. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1538. ,$ctx2.sendIdx[","]=1
  1539. //>>excludeEnd("ctx");
  1540. ][0];
  1541. return $recv($recv($globals.Compiler)._eval_(wrapperSource))._valueWithPossibleArguments_($recv(context)._values());
  1542. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1543. }, function($ctx2) {$ctx2.fillBlock({context:context,wrapperSource:wrapperSource},$ctx1,2)});
  1544. //>>excludeEnd("ctx");
  1545. }));
  1546. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1547. }, function($ctx1) {$ctx1.fill(self,"eval:",{aString:aString})});
  1548. //>>excludeEnd("ctx");
  1549. }; }),
  1550. $globals.Package);
  1551. $core.addMethod(
  1552. $core.method({
  1553. selector: "asVariableName",
  1554. protocol: "*Compiler-Core",
  1555. //>>excludeStart("ide", pragmas.excludeIdeData);
  1556. args: [],
  1557. source: "asVariableName\x0a\x09^ (Smalltalk reservedWords includes: self)\x0a\x09\x09ifTrue: [ self, '_' ]\x0a\x09\x09ifFalse: [ self ]",
  1558. referencedClasses: ["Smalltalk"],
  1559. //>>excludeEnd("ide");
  1560. pragmas: [],
  1561. messageSends: ["ifTrue:ifFalse:", "includes:", "reservedWords", ","]
  1562. }, function ($methodClass){ return function (){
  1563. var self=this,$self=this;
  1564. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1565. return $core.withContext(function($ctx1) {
  1566. //>>excludeEnd("ctx");
  1567. if($core.assert($recv($recv($globals.Smalltalk)._reservedWords())._includes_(self))){
  1568. return $self.__comma("_");
  1569. } else {
  1570. return self;
  1571. }
  1572. //>>excludeStart("ctx", pragmas.excludeDebugContexts);
  1573. }, function($ctx1) {$ctx1.fill(self,"asVariableName",{})});
  1574. //>>excludeEnd("ctx");
  1575. }; }),
  1576. $globals.String);
  1577. });