Browse Source

Code gens: Transformer dictionary in the state.

Herbert Vojčík 7 years ago
parent
commit
2d3d59b6b2
4 changed files with 34 additions and 22 deletions
  1. 15 9
      src/Compiler-Core.js
  2. 3 3
      src/Compiler-Core.st
  3. 14 8
      src/Compiler-Inlining.js
  4. 2 2
      src/Compiler-Inlining.st

+ 15 - 9
src/Compiler-Core.js

@@ -245,7 +245,7 @@ $globals.AbstractCodeGenerator);
 
 
 
-$core.addClass("CodeGenerator", $globals.AbstractCodeGenerator, [], "Compiler-Core");
+$core.addClass("CodeGenerator", $globals.AbstractCodeGenerator, ["transformersDictionary"], "Compiler-Core");
 //>>excludeStart("ide", pragmas.excludeIdeData);
 $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.";
 //>>excludeEnd("ide");
@@ -328,28 +328,34 @@ var self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1;
-$1=$recv($globals.Dictionary)._new();
-$recv($1)._at_put_("2000-semantic",self._semanticAnalyzer());
+var $1,$2,$receiver;
+$1=self["@transformersDictionary"];
+if(($receiver = $1) == null || $receiver.isNil){
+$2=$recv($globals.Dictionary)._new();
+$recv($2)._at_put_("2000-semantic",self._semanticAnalyzer());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx["at:put:"]=1;
 //>>excludeEnd("ctx");
-$recv($1)._at_put_("5000-astToIr",self._translator());
+$recv($2)._at_put_("5000-astToIr",self._translator());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx["at:put:"]=2;
 //>>excludeEnd("ctx");
-$recv($1)._at_put_("8000-irToJs",self._irTranslator());
-return $recv($1)._yourself();
+$recv($2)._at_put_("8000-irToJs",self._irTranslator());
+self["@transformersDictionary"]=$recv($2)._yourself();
+return self["@transformersDictionary"];
+} else {
+return $1;
+}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"transformersDictionary",{},$globals.CodeGenerator)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "transformersDictionary\x0a\x09^ Dictionary new\x0a\x09\x09at: '2000-semantic' put: self semanticAnalyzer;\x0a\x09\x09at: '5000-astToIr' put: self translator;\x0a\x09\x09at: '8000-irToJs' put: self irTranslator;\x0a\x09\x09yourself",
+source: "transformersDictionary\x0a\x09^ transformersDictionary ifNil: [ transformersDictionary := Dictionary new\x0a\x09\x09at: '2000-semantic' put: self semanticAnalyzer;\x0a\x09\x09at: '5000-astToIr' put: self translator;\x0a\x09\x09at: '8000-irToJs' put: self irTranslator;\x0a\x09\x09yourself ]",
 referencedClasses: ["Dictionary"],
 //>>excludeEnd("ide");
-messageSends: ["at:put:", "new", "semanticAnalyzer", "translator", "irTranslator", "yourself"]
+messageSends: ["ifNil:", "at:put:", "new", "semanticAnalyzer", "translator", "irTranslator", "yourself"]
 }),
 $globals.CodeGenerator);
 

+ 3 - 3
src/Compiler-Core.st

@@ -54,7 +54,7 @@ transformersDictionary
 ! !
 
 AbstractCodeGenerator subclass: #CodeGenerator
-	instanceVariableNames: ''
+	instanceVariableNames: 'transformersDictionary'
 	package: 'Compiler-Core'!
 !CodeGenerator commentStamp!
 I am a basic code generator. I generate a valid JavaScript output, but no not perform any inlining.
@@ -79,11 +79,11 @@ semanticAnalyzer
 !
 
 transformersDictionary
-	^ Dictionary new
+	^ transformersDictionary ifNil: [ transformersDictionary := Dictionary new
 		at: '2000-semantic' put: self semanticAnalyzer;
 		at: '5000-astToIr' put: self translator;
 		at: '8000-irToJs' put: self irTranslator;
-		yourself
+		yourself ]
 !
 
 translator

+ 14 - 8
src/Compiler-Inlining.js

@@ -2194,8 +2194,10 @@ var self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1;
-$1=(
+var $1,$2,$receiver;
+$1=self["@transformersDictionary"];
+if(($receiver = $1) == null || $receiver.isNil){
+$2=(
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = true,
 //>>excludeEnd("ctx");
@@ -2203,26 +2205,30 @@ $ctx1.supercall = true,
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.supercall = false;
 //>>excludeEnd("ctx");;
-$recv($1)._at_put_("3000-inlinerTagging",self._preInliner());
+$recv($2)._at_put_("3000-inlinerTagging",self._preInliner());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx["at:put:"]=1;
 //>>excludeEnd("ctx");
-$recv($1)._at_put_("6000-inliner",self._inliner());
+$recv($2)._at_put_("6000-inliner",self._inliner());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx["at:put:"]=2;
 //>>excludeEnd("ctx");
-$recv($1)._at_put_("8000-irToJs",self._irTranslator());
-return $recv($1)._yourself();
+$recv($2)._at_put_("8000-irToJs",self._irTranslator());
+self["@transformersDictionary"]=$recv($2)._yourself();
+return self["@transformersDictionary"];
+} else {
+return $1;
+}
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"transformersDictionary",{},$globals.InliningCodeGenerator)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "transformersDictionary\x0a\x09^ super transformersDictionary\x0a\x09\x09at: '3000-inlinerTagging' put: self preInliner;\x0a\x09\x09at: '6000-inliner' put: self inliner;\x0a\x09\x09at: '8000-irToJs' put: self irTranslator;\x0a\x09\x09yourself",
+source: "transformersDictionary\x0a\x09^ transformersDictionary ifNil: [ transformersDictionary := super transformersDictionary\x0a\x09\x09at: '3000-inlinerTagging' put: self preInliner;\x0a\x09\x09at: '6000-inliner' put: self inliner;\x0a\x09\x09at: '8000-irToJs' put: self irTranslator;\x0a\x09\x09yourself ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["at:put:", "transformersDictionary", "preInliner", "inliner", "irTranslator", "yourself"]
+messageSends: ["ifNil:", "at:put:", "transformersDictionary", "preInliner", "inliner", "irTranslator", "yourself"]
 }),
 $globals.InliningCodeGenerator);
 

+ 2 - 2
src/Compiler-Inlining.st

@@ -574,11 +574,11 @@ preInliner
 !
 
 transformersDictionary
-	^ super transformersDictionary
+	^ transformersDictionary ifNil: [ transformersDictionary := super transformersDictionary
 		at: '3000-inlinerTagging' put: self preInliner;
 		at: '6000-inliner' put: self inliner;
 		at: '8000-irToJs' put: self irTranslator;
-		yourself
+		yourself ]
 ! !
 
 SemanticError subclass: #InliningError