Compiler-Core.js 41 KB

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