Browse Source

Extract ASTPreInliner.

Herbert Vojčík 8 years ago
parent
commit
54c7f5723d
4 changed files with 84 additions and 59 deletions
  1. 3 21
      src/Compiler-Core.js
  2. 1 5
      src/Compiler-Core.st
  3. 62 29
      src/Compiler-Inlining.js
  4. 18 4
      src/Compiler-Inlining.st

+ 3 - 21
src/Compiler-Core.js

@@ -249,7 +249,7 @@ var self=this;
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
 var $1;
-$1=$recv(self._semanticAnalyzerClass())._on_(self._currentClass());
+$1=$recv($globals.SemanticAnalyzer)._on_(self._currentClass());
 $recv($1)._thePackage_(self._currentPackage());
 return $recv($1)._yourself();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
@@ -258,28 +258,10 @@ return $recv($1)._yourself();
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "semanticAnalyzer\x0a\x09^ (self semanticAnalyzerClass on: self currentClass)\x0a\x09\x09thePackage: self currentPackage;\x0a\x09\x09yourself",
-referencedClasses: [],
-//>>excludeEnd("ide");
-messageSends: ["thePackage:", "on:", "semanticAnalyzerClass", "currentClass", "currentPackage", "yourself"]
-}),
-$globals.CodeGenerator);
-
-$core.addMethod(
-$core.method({
-selector: "semanticAnalyzerClass",
-protocol: 'compiling',
-fn: function (){
-var self=this;
-return $globals.SemanticAnalyzer;
-
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "semanticAnalyzerClass\x0a\x09^ SemanticAnalyzer",
+source: "semanticAnalyzer\x0a\x09^ (SemanticAnalyzer on: self currentClass)\x0a\x09\x09thePackage: self currentPackage;\x0a\x09\x09yourself",
 referencedClasses: ["SemanticAnalyzer"],
 //>>excludeEnd("ide");
-messageSends: []
+messageSends: ["thePackage:", "on:", "currentClass", "currentPackage", "yourself"]
 }),
 $globals.CodeGenerator);
 

+ 1 - 5
src/Compiler-Core.st

@@ -61,15 +61,11 @@ irTranslator
 !
 
 semanticAnalyzer
-	^ (self semanticAnalyzerClass on: self currentClass)
+	^ (SemanticAnalyzer on: self currentClass)
 		thePackage: self currentPackage;
 		yourself
 !
 
-semanticAnalyzerClass
-	^ SemanticAnalyzer
-!
-
 transformers
 	^ {
 		self semanticAnalyzer.

+ 62 - 29
src/Compiler-Inlining.js

@@ -1,4 +1,4 @@
-define(["amber/boot", "amber_core/Compiler-Core", "amber_core/Compiler-IR", "amber_core/Compiler-Semantic", "amber_core/Kernel-Objects"], function($boot){"use strict";
+define(["amber/boot", "amber_core/Compiler-AST", "amber_core/Compiler-Core", "amber_core/Compiler-IR", "amber_core/Compiler-Semantic", "amber_core/Kernel-Objects"], function($boot){"use strict";
 if(!$boot.nilAsReceiver)$boot.nilAsReceiver=$boot.nil;
 var $core=$boot.api,nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
 if(!$boot.nilAsClass)$boot.nilAsClass=$boot.dnu;
@@ -6,6 +6,56 @@ $core.addPackage('Compiler-Inlining');
 $core.packages["Compiler-Inlining"].innerEval = function (expr) { return eval(expr); };
 $core.packages["Compiler-Inlining"].transport = {"type":"amd","amdNamespace":"amber_core"};
 
+$core.addClass('ASTPreInliner', $globals.NodeVisitor, [], 'Compiler-Inlining');
+$core.addMethod(
+$core.method({
+selector: "visitSendNode:",
+protocol: 'visiting',
+fn: function (aNode){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1,$2,$3,$4,$receiver;
+$1=$recv(aNode)._superSend();
+if(!$core.assert($1)){
+$2=$recv($recv($globals.IRSendInliner)._inlinedSelectors())._includes_($recv(aNode)._selector());
+if($core.assert($2)){
+$recv(aNode)._shouldBeInlined_(true);
+$3=$recv(aNode)._receiver();
+if(($receiver = $3) == null || $receiver.isNil){
+$3;
+} else {
+var receiver;
+receiver=$receiver;
+$recv(receiver)._shouldBeAliased_(true);
+}
+}
+}
+$4=(
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.supercall = true,
+//>>excludeEnd("ctx");
+($globals.ASTPreInliner.superclass||$boot.nilAsClass).fn.prototype._visitSendNode_.apply($recv(self), [aNode]));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.supercall = false;
+//>>excludeEnd("ctx");;
+return $4;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"visitSendNode:",{aNode:aNode},$globals.ASTPreInliner)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["aNode"],
+source: "visitSendNode: aNode\x0a\x0a\x09aNode superSend ifFalse: [ \x0a\x09\x09(IRSendInliner inlinedSelectors includes: aNode selector) ifTrue: [\x0a\x09\x09\x09aNode shouldBeInlined: true.\x0a\x09\x09\x09aNode receiver ifNotNil: [ :receiver |\x0a\x09\x09\x09\x09receiver shouldBeAliased: true ] ] ].\x0a\x0a\x09^ super visitSendNode: aNode",
+referencedClasses: ["IRSendInliner"],
+//>>excludeEnd("ide");
+messageSends: ["ifFalse:", "superSend", "ifTrue:", "includes:", "inlinedSelectors", "selector", "shouldBeInlined:", "ifNotNil:", "receiver", "shouldBeAliased:", "visitSendNode:"]
+}),
+$globals.ASTPreInliner);
+
+
+
 $core.addClass('IRInlinedClosure', $globals.IRClosure, [], 'Compiler-Inlining');
 //>>excludeStart("ide", pragmas.excludeIdeData);
 $globals.IRInlinedClosure.comment="I represent an inlined closure instruction.";
@@ -2117,24 +2167,6 @@ messageSends: ["new"]
 }),
 $globals.InliningCodeGenerator);
 
-$core.addMethod(
-$core.method({
-selector: "semanticAnalyzerClass",
-protocol: 'compiling',
-fn: function (){
-var self=this;
-return $globals.InliningSemanticAnalyzer;
-
-},
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "semanticAnalyzerClass\x0a\x09^ InliningSemanticAnalyzer",
-referencedClasses: ["InliningSemanticAnalyzer"],
-//>>excludeEnd("ide");
-messageSends: []
-}),
-$globals.InliningCodeGenerator);
-
 $core.addMethod(
 $core.method({
 selector: "transformers",
@@ -2144,24 +2176,25 @@ var self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2,$3,$5,$4;
+var $1,$2,$3,$4,$6,$5;
 $1=self._semanticAnalyzer();
-$2=self._translator();
-$3=self._inliner();
-$5=self._irTranslator();
-$recv($5)._currentClass_(self._currentClass());
-$4=$recv($5)._yourself();
-return [$1,$2,$3,$4];
+$2=$recv($globals.ASTPreInliner)._new();
+$3=self._translator();
+$4=self._inliner();
+$6=self._irTranslator();
+$recv($6)._currentClass_(self._currentClass());
+$5=$recv($6)._yourself();
+return [$1,$2,$3,$4,$5];
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"transformers",{},$globals.InliningCodeGenerator)});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "transformers\x0a\x09^ {\x0a\x09\x09self semanticAnalyzer.\x0a\x09\x09self translator.\x0a\x09\x09self inliner.\x0a\x09\x09self irTranslator currentClass: self currentClass; yourself\x0a\x09}",
-referencedClasses: [],
+source: "transformers\x0a\x09^ {\x0a\x09\x09self semanticAnalyzer.\x0a\x09\x09ASTPreInliner new.\x0a\x09\x09self translator.\x0a\x09\x09self inliner.\x0a\x09\x09self irTranslator currentClass: self currentClass; yourself\x0a\x09}",
+referencedClasses: ["ASTPreInliner"],
 //>>excludeEnd("ide");
-messageSends: ["semanticAnalyzer", "translator", "inliner", "currentClass:", "irTranslator", "currentClass", "yourself"]
+messageSends: ["semanticAnalyzer", "new", "translator", "inliner", "currentClass:", "irTranslator", "currentClass", "yourself"]
 }),
 $globals.InliningCodeGenerator);
 

+ 18 - 4
src/Compiler-Inlining.st

@@ -1,4 +1,21 @@
 Smalltalk createPackage: 'Compiler-Inlining'!
+NodeVisitor subclass: #ASTPreInliner
+	instanceVariableNames: ''
+	package: 'Compiler-Inlining'!
+
+!ASTPreInliner methodsFor: 'visiting'!
+
+visitSendNode: aNode
+
+	aNode superSend ifFalse: [ 
+		(IRSendInliner inlinedSelectors includes: aNode selector) ifTrue: [
+			aNode shouldBeInlined: true.
+			aNode receiver ifNotNil: [ :receiver |
+				receiver shouldBeAliased: true ] ] ].
+
+	^ super visitSendNode: aNode
+! !
+
 IRClosure subclass: #IRInlinedClosure
 	instanceVariableNames: ''
 	package: 'Compiler-Inlining'!
@@ -552,13 +569,10 @@ irTranslator
 	^ IRInliningJSTranslator new
 !
 
-semanticAnalyzerClass
-	^ InliningSemanticAnalyzer
-!
-
 transformers
 	^ {
 		self semanticAnalyzer.
+		ASTPreInliner new.
 		self translator.
 		self inliner.
 		self irTranslator currentClass: self currentClass; yourself