1
0

Compiler-Core.js 42 KB

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