Compiler-Core.js 45 KB

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