2 Commits 3bba72396c ... 496a94f2da

Author SHA1 Message Date
  Herby Vojčík 496a94f2da SuperVar; isSuperKeyword => isSuper 5 years ago
  Herby Vojčík 90cd83ac32 Extract writeActualSuperSend:. 5 years ago

+ 10 - 10
lang/src/Compiler-AST.js

@@ -232,7 +232,7 @@ $globals.ASTNode);
 
 $core.addMethod(
 $core.method({
-selector: "isSuperKeyword",
+selector: "isSuper",
 protocol: "testing",
 fn: function (){
 var self=this,$self=this;
@@ -241,7 +241,7 @@ return false;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "isSuperKeyword\x0a\x09^ false",
+source: "isSuper\x0a\x09^ false",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
@@ -2199,7 +2199,7 @@ return $recv($1)._and_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-return $recv($self._receiver())._isSuperKeyword();
+return $recv($self._receiver())._isSuper();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
 //>>excludeEnd("ctx");
@@ -2210,11 +2210,11 @@ return $recv($self._receiver())._isSuperKeyword();
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "superSend\x0a\x09^ self receiver notNil and: [ self receiver isSuperKeyword ]",
+source: "superSend\x0a\x09^ self receiver notNil and: [ self receiver isSuper ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["and:", "notNil", "receiver", "isSuperKeyword"]
+messageSends: ["and:", "notNil", "receiver", "isSuper"]
 }),
 $globals.SendNode);
 
@@ -2755,25 +2755,25 @@ $globals.VariableNode);
 
 $core.addMethod(
 $core.method({
-selector: "isSuperKeyword",
+selector: "isSuper",
 protocol: "testing",
 fn: function (){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-return $recv($self._value()).__eq("super");
+return $recv($self._binding())._isSuper();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"isSuperKeyword",{})});
+}, function($ctx1) {$ctx1.fill(self,"isSuper",{})});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "isSuperKeyword\x0a\x09^ self value = 'super'",
+source: "isSuper\x0a\x09^ self binding isSuper",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["=", "value"]
+messageSends: ["isSuper", "binding"]
 }),
 $globals.VariableNode);
 

+ 4 - 4
lang/src/Compiler-AST.st

@@ -146,7 +146,7 @@ isSequenceNode
 	^ false
 !
 
-isSuperKeyword
+isSuper
 	^ false
 !
 
@@ -500,7 +500,7 @@ shouldBeInlined: aBoolean
 !
 
 superSend
-	^ self receiver notNil and: [ self receiver isSuperKeyword ]
+	^ self receiver notNil and: [ self receiver isSuper ]
 ! !
 
 !SendNode methodsFor: 'testing'!
@@ -660,8 +660,8 @@ isNavigationNode
 	^ true
 !
 
-isSuperKeyword
-	^ self value = 'super'
+isSuper
+	^ self binding isSuper
 !
 
 isVariableNode

+ 55 - 28
lang/src/Compiler-IR.js

@@ -4632,7 +4632,7 @@ var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$4,$3,$2,$5,$6,$7;
+var $1,$4,$3,$2,$5;
 $1=$self._stream();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx["stream"]=1;
@@ -4681,66 +4681,93 @@ $recv($1)._lf();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx["lf"]=4;
 //>>excludeEnd("ctx");
-$5="(".__comma($recv($self._currentClass())._asJavaScriptSource());
+$self._writeActualSuperSend_(anIRSend);
+$5=$self._stream();
+$recv($5)._nextPutAll_(");");
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx[","]=2;
+$ctx1.sendIdx["nextPutAll:"]=5;
 //>>excludeEnd("ctx");
-$recv($1)._nextPutAll_($5);
+$recv($5)._lf();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["nextPutAll:"]=5;
+$ctx1.sendIdx["lf"]=5;
 //>>excludeEnd("ctx");
-$recv($1)._nextPutAll_(".superclass||$boot.nilAsClass).fn.prototype.");
+$recv($5)._nextPutAll_("//>>excludeStart(\x22ctx\x22, pragmas.excludeDebugContexts);");
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx["nextPutAll:"]=6;
 //>>excludeEnd("ctx");
-$6=$recv($recv(anIRSend)._javaScriptSelector()).__comma(".apply(");
+$recv($5)._lf();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx[","]=3;
+$ctx1.sendIdx["lf"]=6;
 //>>excludeEnd("ctx");
-$recv($1)._nextPutAll_($6);
+$recv($5)._nextPutAll_($recv($recv($recv(anIRSend)._scope())._alias()).__comma(".supercall = false;"));
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx1.sendIdx["nextPutAll:"]=7;
 //>>excludeEnd("ctx");
-$recv($1)._nextPutAll_("$self, ");
+$recv($5)._lf();
+$recv($5)._nextPutAll_("//>>excludeEnd(\x22ctx\x22);");
+return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["nextPutAll:"]=8;
+}, function($ctx1) {$ctx1.fill(self,"visitSuperSend:",{anIRSend:anIRSend})});
 //>>excludeEnd("ctx");
-$self._visitInstructionList_enclosedBetween_and_($recv(anIRSend)._arguments(),"[","]");
-$7=$self._stream();
-$recv($7)._nextPutAll_("));");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: ["anIRSend"],
+source: "visitSuperSend: anIRSend\x0a\x09self stream\x0a\x09\x09nextPutAll: '('; lf;\x0a\x09\x09nextPutAll: '//>>excludeStart(\x22ctx\x22, pragmas.excludeDebugContexts);'; lf;\x0a\x09\x09nextPutAll: anIRSend scope alias, '.supercall = true,'; lf;\x0a\x09\x09nextPutAll: '//>>excludeEnd(\x22ctx\x22);'; lf.\x0a\x09self writeActualSuperSend: anIRSend.\x0a\x09self stream \x0a\x09\x09nextPutAll: ');'; lf;\x0a\x09\x09nextPutAll: '//>>excludeStart(\x22ctx\x22, pragmas.excludeDebugContexts);'; lf;\x0a\x09\x09nextPutAll: anIRSend scope alias, '.supercall = false;'; lf;\x0a\x09\x09nextPutAll: '//>>excludeEnd(\x22ctx\x22);'",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["nextPutAll:", "stream", "lf", ",", "alias", "scope", "writeActualSuperSend:"]
+}),
+$globals.IRJSTranslator);
+
+$core.addMethod(
+$core.method({
+selector: "writeActualSuperSend:",
+protocol: "visiting",
+fn: function (anIRSend){
+var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["nextPutAll:"]=9;
+return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-$recv($7)._lf();
+var $1,$2;
+$1=$self._stream();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["lf"]=5;
+$ctx1.sendIdx["stream"]=1;
 //>>excludeEnd("ctx");
-$recv($7)._nextPutAll_("//>>excludeStart(\x22ctx\x22, pragmas.excludeDebugContexts);");
+$2="(".__comma($recv($self._currentClass())._asJavaScriptSource());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["nextPutAll:"]=10;
+$ctx1.sendIdx[","]=1;
 //>>excludeEnd("ctx");
-$recv($7)._lf();
+$recv($1)._nextPutAll_($2);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["lf"]=6;
+$ctx1.sendIdx["nextPutAll:"]=1;
 //>>excludeEnd("ctx");
-$recv($7)._nextPutAll_($recv($recv($recv(anIRSend)._scope())._alias()).__comma(".supercall = false;"));
+$recv($1)._nextPutAll_(".superclass||$boot.nilAsClass).fn.prototype.");
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["nextPutAll:"]=11;
+$ctx1.sendIdx["nextPutAll:"]=2;
+//>>excludeEnd("ctx");
+$recv($1)._nextPutAll_($recv($recv(anIRSend)._javaScriptSelector()).__comma(".apply("));
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["nextPutAll:"]=3;
+//>>excludeEnd("ctx");
+$recv($1)._nextPutAll_("$self, ");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["nextPutAll:"]=4;
 //>>excludeEnd("ctx");
-$recv($7)._lf();
-$recv($7)._nextPutAll_("//>>excludeEnd(\x22ctx\x22);");
+$self._visitInstructionList_enclosedBetween_and_($recv(anIRSend)._arguments(),"[","]");
+$recv($self._stream())._nextPutAll_(")");
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"visitSuperSend:",{anIRSend:anIRSend})});
+}, function($ctx1) {$ctx1.fill(self,"writeActualSuperSend:",{anIRSend:anIRSend})});
 //>>excludeEnd("ctx");
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anIRSend"],
-source: "visitSuperSend: anIRSend\x0a\x09self stream\x0a\x09\x09nextPutAll: '('; lf;\x0a\x09\x09nextPutAll: '//>>excludeStart(\x22ctx\x22, pragmas.excludeDebugContexts);'; lf;\x0a\x09\x09nextPutAll: anIRSend scope alias, '.supercall = true,'; lf;\x0a\x09\x09nextPutAll: '//>>excludeEnd(\x22ctx\x22);'; lf;\x0a\x09\x09nextPutAll: '(', self currentClass asJavaScriptSource;\x0a\x09\x09nextPutAll: '.superclass||$boot.nilAsClass).fn.prototype.';\x0a\x09\x09nextPutAll: anIRSend javaScriptSelector, '.apply(';\x0a\x09\x09nextPutAll: '$self, '.\x0a\x09self\x0a\x09\x09visitInstructionList: anIRSend arguments\x0a\x09\x09enclosedBetween: '[' and: ']'.\x0a\x09self stream \x0a\x09\x09nextPutAll: '));'; lf;\x0a\x09\x09nextPutAll: '//>>excludeStart(\x22ctx\x22, pragmas.excludeDebugContexts);'; lf;\x0a\x09\x09nextPutAll: anIRSend scope alias, '.supercall = false;'; lf;\x0a\x09\x09nextPutAll: '//>>excludeEnd(\x22ctx\x22);'",
+source: "writeActualSuperSend: anIRSend\x0a\x09self stream\x0a\x09\x09nextPutAll: '(', self currentClass asJavaScriptSource;\x0a\x09\x09nextPutAll: '.superclass||$boot.nilAsClass).fn.prototype.';\x0a\x09\x09nextPutAll: anIRSend javaScriptSelector, '.apply(';\x0a\x09\x09nextPutAll: '$self, '.\x0a\x09self\x0a\x09\x09visitInstructionList: anIRSend arguments\x0a\x09\x09enclosedBetween: '[' and: ']'.\x0a\x09self stream\x0a\x09\x09nextPutAll: ')'",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["nextPutAll:", "stream", "lf", ",", "alias", "scope", "asJavaScriptSource", "currentClass", "javaScriptSelector", "visitInstructionList:enclosedBetween:and:", "arguments"]
+messageSends: ["nextPutAll:", "stream", ",", "asJavaScriptSource", "currentClass", "javaScriptSelector", "visitInstructionList:enclosedBetween:and:", "arguments"]
 }),
 $globals.IRJSTranslator);
 

+ 13 - 6
lang/src/Compiler-IR.st

@@ -1071,7 +1071,17 @@ visitSuperSend: anIRSend
 		nextPutAll: '('; lf;
 		nextPutAll: '//>>excludeStart("ctx", pragmas.excludeDebugContexts);'; lf;
 		nextPutAll: anIRSend scope alias, '.supercall = true,'; lf;
-		nextPutAll: '//>>excludeEnd("ctx");'; lf;
+		nextPutAll: '//>>excludeEnd("ctx");'; lf.
+	self writeActualSuperSend: anIRSend.
+	self stream 
+		nextPutAll: ');'; lf;
+		nextPutAll: '//>>excludeStart("ctx", pragmas.excludeDebugContexts);'; lf;
+		nextPutAll: anIRSend scope alias, '.supercall = false;'; lf;
+		nextPutAll: '//>>excludeEnd("ctx");'
+!
+
+writeActualSuperSend: anIRSend
+	self stream
 		nextPutAll: '(', self currentClass asJavaScriptSource;
 		nextPutAll: '.superclass||$boot.nilAsClass).fn.prototype.';
 		nextPutAll: anIRSend javaScriptSelector, '.apply(';
@@ -1079,11 +1089,8 @@ visitSuperSend: anIRSend
 	self
 		visitInstructionList: anIRSend arguments
 		enclosedBetween: '[' and: ']'.
-	self stream 
-		nextPutAll: '));'; lf;
-		nextPutAll: '//>>excludeStart("ctx", pragmas.excludeDebugContexts);'; lf;
-		nextPutAll: anIRSend scope alias, '.supercall = false;'; lf;
-		nextPutAll: '//>>excludeEnd("ctx");'
+	self stream
+		nextPutAll: ')'
 ! !
 
 Object subclass: #JSStream

+ 57 - 15
lang/src/Compiler-Semantic.js

@@ -1032,7 +1032,7 @@ var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2,$4,$3,$receiver;
+var $1,$2,$4,$5,$6,$3,$7,$9,$8,$receiver;
 $1=$self.pseudoVars;
 if(($receiver = $1) == null || $receiver.a$nil){
 $self.pseudoVars=$recv($globals.Dictionary)._new();
@@ -1042,13 +1042,35 @@ return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
 $2=$self.pseudoVars;
 $4=$recv($globals.PseudoVar)._on_(each);
-$recv($4)._scope_($self._methodScope());
-$3=$recv($4)._yourself();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["on:"]=1;
+//>>excludeEnd("ctx");
+$5=$self._methodScope();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["methodScope"]=1;
+//>>excludeEnd("ctx");
+$recv($4)._scope_($5);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["scope:"]=1;
+//>>excludeEnd("ctx");
+$6=$recv($4)._yourself();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["yourself"]=1;
+//>>excludeEnd("ctx");
+$3=$6;
 return $recv($2)._at_put_(each,$3);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx2.sendIdx["at:put:"]=1;
+//>>excludeEnd("ctx");
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1,2)});
 //>>excludeEnd("ctx");
 }));
+$7=$self.pseudoVars;
+$9=$recv($globals.SuperVar)._on_("super");
+$recv($9)._scope_($self._methodScope());
+$8=$recv($9)._yourself();
+$recv($7)._at_put_("super",$8);
 } else {
 $1;
 }
@@ -1059,8 +1081,8 @@ return $self.pseudoVars;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "pseudoVars\x0a\x09pseudoVars ifNil: [\x0a\x09\x09pseudoVars := Dictionary new.\x0a\x09\x09Smalltalk pseudoVariableNames do: [ :each |\x0a\x09\x09\x09pseudoVars at: each put: ((PseudoVar on: each)\x0a\x09\x09\x09\x09scope: self methodScope;\x0a\x09\x09\x09\x09yourself) ]].\x0a\x09^ pseudoVars",
-referencedClasses: ["Dictionary", "Smalltalk", "PseudoVar"],
+source: "pseudoVars\x0a\x09pseudoVars ifNil: [\x0a\x09\x09pseudoVars := Dictionary new.\x0a\x09\x09Smalltalk pseudoVariableNames do: [ :each |\x0a\x09\x09\x09pseudoVars at: each put: ((PseudoVar on: each)\x0a\x09\x09\x09\x09scope: self methodScope;\x0a\x09\x09\x09\x09yourself) ].\x0a\x09\x09pseudoVars at: #super put: ((SuperVar on: #super) scope: self methodScope; yourself) ].\x0a\x09^ pseudoVars",
+referencedClasses: ["Dictionary", "Smalltalk", "PseudoVar", "SuperVar"],
 //>>excludeEnd("ide");
 pragmas: [],
 messageSends: ["ifNil:", "new", "do:", "pseudoVariableNames", "at:put:", "scope:", "on:", "methodScope", "yourself"]
@@ -1787,29 +1809,49 @@ messageSends: ["="]
 }),
 $globals.PseudoVar);
 
+
+
+$core.addClass("SuperVar", $globals.PseudoVar, [], "Compiler-Semantic");
+//>>excludeStart("ide", pragmas.excludeIdeData);
+$globals.SuperVar.comment="I am a 'super' pseudo variable.";
+//>>excludeEnd("ide");
+$core.addMethod(
+$core.method({
+selector: "alias",
+protocol: "accessing",
+fn: function (){
+var self=this,$self=this;
+return "self";
+
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "alias\x0a\x09^ 'self'",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: []
+}),
+$globals.SuperVar);
+
 $core.addMethod(
 $core.method({
 selector: "isSuper",
 protocol: "testing",
 fn: function (){
 var self=this,$self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-return $recv($self.name).__eq("super");
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"isSuper",{})});
-//>>excludeEnd("ctx");
+return true;
+
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: [],
-source: "isSuper\x0a\x09^ name = 'super'",
+source: "isSuper\x0a\x09^ true",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["="]
+messageSends: []
 }),
-$globals.PseudoVar);
+$globals.SuperVar);
 
 
 

+ 18 - 3
lang/src/Compiler-Semantic.st

@@ -166,7 +166,8 @@ pseudoVars
 		Smalltalk pseudoVariableNames do: [ :each |
 			pseudoVars at: each put: ((PseudoVar on: each)
 				scope: self methodScope;
-				yourself) ]].
+				yourself) ].
+		pseudoVars at: #super put: ((SuperVar on: #super) scope: self methodScope; yourself) ].
 	^ pseudoVars
 !
 
@@ -395,10 +396,24 @@ isPseudoVar
 
 isSelf
 	^ name = 'self'
-!
+! !
+
+PseudoVar subclass: #SuperVar
+	slots: {}
+	package: 'Compiler-Semantic'!
+!SuperVar commentStamp!
+I am a 'super' pseudo variable.!
+
+!SuperVar methodsFor: 'accessing'!
+
+alias
+	^ 'self'
+! !
+
+!SuperVar methodsFor: 'testing'!
 
 isSuper
-	^ name = 'super'
+	^ true
 ! !
 
 ScopeVar subclass: #TempVar