1
0

Compiler-Core.js 40 KB

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