Explorar el Código

ThisContextVar

Herby Vojčík hace 4 años
padre
commit
44092774eb
Se han modificado 4 ficheros con 68 adiciones y 29 borrados
  1. 2 20
      lang/src/Compiler-IR.js
  2. 1 3
      lang/src/Compiler-IR.st
  3. 50 5
      lang/src/Compiler-Semantic.js
  4. 15 1
      lang/src/Compiler-Semantic.st

+ 2 - 20
lang/src/Compiler-IR.js

@@ -4219,35 +4219,17 @@ selector: "visitIRVariable:",
 protocol: "visiting",
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anIRVariable"],
-source: "visitIRVariable: anIRVariable\x0a\x09anIRVariable variable name = 'thisContext'\x0a\x09\x09ifTrue: [ self stream nextPutAll: '$core.getThisContext()' ]\x0a\x09\x09ifFalse: [ self stream nextPutAll: anIRVariable variable alias ]",
+source: "visitIRVariable: anIRVariable\x0a\x09self stream nextPutAll: anIRVariable variable alias",
 referencedClasses: [],
 //>>excludeEnd("ide");
 pragmas: [],
-messageSends: ["ifTrue:ifFalse:", "=", "name", "variable", "nextPutAll:", "stream", "alias"]
+messageSends: ["nextPutAll:", "stream", "alias", "variable"]
 }, function ($methodClass){ return function (anIRVariable){
 var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $3,$2,$1,$4;
-$3=$recv(anIRVariable)._variable();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["variable"]=1;
-//>>excludeEnd("ctx");
-$2=$recv($3)._name();
-$1=$recv($2).__eq("thisContext");
-if($core.assert($1)){
-$4=$self._stream();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["stream"]=1;
-//>>excludeEnd("ctx");
-$recv($4)._nextPutAll_("$core.getThisContext()");
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["nextPutAll:"]=1;
-//>>excludeEnd("ctx");
-} else {
 $recv($self._stream())._nextPutAll_($recv($recv(anIRVariable)._variable())._alias());
-}
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"visitIRVariable:",{anIRVariable:anIRVariable})});

+ 1 - 3
lang/src/Compiler-IR.st

@@ -1018,9 +1018,7 @@ visitIRValue: anIRValue
 !
 
 visitIRVariable: anIRVariable
-	anIRVariable variable name = 'thisContext'
-		ifTrue: [ self stream nextPutAll: '$core.getThisContext()' ]
-		ifFalse: [ self stream nextPutAll: anIRVariable variable alias ]
+	self stream nextPutAll: anIRVariable variable alias
 !
 
 visitIRVerbatim: anIRVerbatim

+ 50 - 5
lang/src/Compiler-Semantic.js

@@ -993,8 +993,8 @@ selector: "pseudoVars",
 protocol: "accessing",
 //>>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\x09pseudoVars at: #super put: ((SuperVar on: #super) scope: self methodScope; yourself) ].\x0a\x09^ pseudoVars",
-referencedClasses: ["Dictionary", "Smalltalk", "PseudoVar", "SuperVar"],
+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\x0a\x09\x09\x09at: #super put: ((SuperVar on: #super) scope: self methodScope; yourself);\x0a\x09\x09\x09at: #thisContext put: ((ThisContextVar on: #thisContext) scope: self methodScope; yourself) ].\x0a\x09^ pseudoVars",
+referencedClasses: ["Dictionary", "Smalltalk", "PseudoVar", "SuperVar", "ThisContextVar"],
 //>>excludeEnd("ide");
 pragmas: [],
 messageSends: ["ifNil:", "new", "do:", "pseudoVariableNames", "at:put:", "scope:", "on:", "methodScope", "yourself"]
@@ -1003,7 +1003,7 @@ var self=this,$self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2,$4,$5,$6,$3,$7,$9,$8,$receiver;
+var $1,$2,$4,$5,$6,$3,$7,$9,$10,$11,$8,$13,$12,$receiver;
 $1=$self.pseudoVars;
 if(($receiver = $1) == null || $receiver.a$nil){
 $self.pseudoVars=$recv($globals.Dictionary)._new();
@@ -1039,9 +1039,30 @@ $ctx2.sendIdx["at:put:"]=1;
 }));
 $7=$self.pseudoVars;
 $9=$recv($globals.SuperVar)._on_("super");
-$recv($9)._scope_($self._methodScope());
-$8=$recv($9)._yourself();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["on:"]=2;
+//>>excludeEnd("ctx");
+$10=$self._methodScope();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["methodScope"]=2;
+//>>excludeEnd("ctx");
+$recv($9)._scope_($10);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["scope:"]=2;
+//>>excludeEnd("ctx");
+$11=$recv($9)._yourself();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["yourself"]=2;
+//>>excludeEnd("ctx");
+$8=$11;
 $recv($7)._at_put_("super",$8);
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+$ctx1.sendIdx["at:put:"]=2;
+//>>excludeEnd("ctx");
+$13=$recv($globals.ThisContextVar)._on_("thisContext");
+$recv($13)._scope_($self._methodScope());
+$12=$recv($13)._yourself();
+$recv($7)._at_put_("thisContext",$12);
 } else {
 $1;
 }
@@ -1802,6 +1823,30 @@ $globals.SuperVar);
 
 
 
+$core.addClass("ThisContextVar", $globals.PseudoVar, [], "Compiler-Semantic");
+//>>excludeStart("ide", pragmas.excludeIdeData);
+$globals.ThisContextVar.comment="I am a 'thisContext' pseudo variable.";
+//>>excludeEnd("ide");
+$core.addMethod(
+$core.method({
+selector: "alias",
+protocol: "accessing",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "alias\x0a\x09^ '$core.getThisContext()'",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: []
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+return "$core.getThisContext()";
+
+}; }),
+$globals.ThisContextVar);
+
+
+
 $core.addClass("TempVar", $globals.ScopeVar, [], "Compiler-Semantic");
 //>>excludeStart("ide", pragmas.excludeIdeData);
 $globals.TempVar.comment="I am an temporary variable of a method or block.";

+ 15 - 1
lang/src/Compiler-Semantic.st

@@ -167,7 +167,9 @@ pseudoVars
 			pseudoVars at: each put: ((PseudoVar on: each)
 				scope: self methodScope;
 				yourself) ].
-		pseudoVars at: #super put: ((SuperVar on: #super) scope: self methodScope; yourself) ].
+		pseudoVars
+			at: #super put: ((SuperVar on: #super) scope: self methodScope; yourself);
+			at: #thisContext put: ((ThisContextVar on: #thisContext) scope: self methodScope; yourself) ].
 	^ pseudoVars
 !
 
@@ -420,6 +422,18 @@ isSuper
 	^ true
 ! !
 
+PseudoVar subclass: #ThisContextVar
+	slots: {}
+	package: 'Compiler-Semantic'!
+!ThisContextVar commentStamp!
+I am a 'thisContext' pseudo variable.!
+
+!ThisContextVar methodsFor: 'accessing'!
+
+alias
+	^ '$core.getThisContext()'
+! !
+
 ScopeVar subclass: #TempVar
 	slots: {}
 	package: 'Compiler-Semantic'!