Browse Source

ScopeVar asReceiver as extension method.

Responsibility of IR, not Semantic.
Herby Vojčík 4 years ago
parent
commit
8177ea7ac4
4 changed files with 78 additions and 76 deletions
  1. 61 1
      lang/src/Compiler-IR.js
  2. 17 0
      lang/src/Compiler-IR.st
  3. 0 60
      lang/src/Compiler-Semantic.js
  4. 0 15
      lang/src/Compiler-Semantic.st

+ 61 - 1
lang/src/Compiler-IR.js

@@ -1,4 +1,4 @@
-define(["amber/boot", "require", "amber/core/Compiler-AST", "amber/core/Kernel-Dag", "amber/core/Kernel-Helpers", "amber/core/Kernel-Methods", "amber/core/Kernel-Objects"], function($boot,requirejs){"use strict";
+define(["amber/boot", "require", "amber/core/Compiler-AST", "amber/core/Compiler-Semantic", "amber/core/Kernel-Dag", "amber/core/Kernel-Helpers", "amber/core/Kernel-Methods", "amber/core/Kernel-Objects"], function($boot,requirejs){"use strict";
 var $core=$boot.api,nil=$boot.nilAsValue,$nil=$boot.nilAsReceiver,$recv=$boot.asReceiver,$globals=$boot.globals;
 var $pkg = $core.addPackage("Compiler-IR");
 $pkg.innerEval = function (expr) { return eval(expr); };
@@ -5899,6 +5899,66 @@ return $recv($recv($self._parent())._isSequenceNode())._not();
 }; }),
 $globals.CascadeNode);
 
+$core.addMethod(
+$core.method({
+selector: "asReceiver",
+protocol: "*Compiler-IR",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "asReceiver\x0a\x09self class receiverNames\x0a\x09\x09at: self name\x0a\x09\x09ifPresent: [ :newName | ^ self copy name: newName; yourself ]\x0a\x09\x09ifAbsent: [ ^ self ]",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: ["at:ifPresent:ifAbsent:", "receiverNames", "class", "name", "name:", "copy", "yourself"]
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+var $1;
+var $early={};
+try {
+$recv($recv($self._class())._receiverNames())._at_ifPresent_ifAbsent_($self._name(),(function(newName){
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx2) {
+//>>excludeEnd("ctx");
+$1=$self._copy();
+$recv($1)._name_(newName);
+throw $early=[$recv($1)._yourself()];
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx2) {$ctx2.fillBlock({newName:newName},$ctx1,1)});
+//>>excludeEnd("ctx");
+}),(function(){
+throw $early=[self];
+
+}));
+return self;
+}
+catch(e) {if(e===$early)return e[0]; throw e}
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"asReceiver",{})});
+//>>excludeEnd("ctx");
+}; }),
+$globals.PseudoVar);
+
+$core.addMethod(
+$core.method({
+selector: "asReceiver",
+protocol: "*Compiler-IR",
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "asReceiver\x0a\x09\x22Return customized copy to use as receiver,\x0a\x09or self if suffices.\x22\x0a\x09^ nil",
+referencedClasses: [],
+//>>excludeEnd("ide");
+pragmas: [],
+messageSends: []
+}, function ($methodClass){ return function (){
+var self=this,$self=this;
+return nil;
+
+}; }),
+$globals.ScopeVar);
+
 $core.addMethod(
 $core.method({
 selector: "shouldBeAliased",

+ 17 - 0
lang/src/Compiler-IR.st

@@ -1363,6 +1363,23 @@ subtreeNeedsAliasing
 	^ self parent isSequenceNode not
 ! !
 
+!PseudoVar methodsFor: '*Compiler-IR'!
+
+asReceiver
+	self class receiverNames
+		at: self name
+		ifPresent: [ :newName | ^ self copy name: newName; yourself ]
+		ifAbsent: [ ^ self ]
+! !
+
+!ScopeVar methodsFor: '*Compiler-IR'!
+
+asReceiver
+	"Return customized copy to use as receiver,
+	or self if suffices."
+	^ nil
+! !
+
 !SendNode methodsFor: '*Compiler-IR'!
 
 shouldBeAliased

+ 0 - 60
lang/src/Compiler-Semantic.js

@@ -1071,24 +1071,6 @@ return $recv($self._name())._asVariableName();
 }; }),
 $globals.ScopeVar);
 
-$core.addMethod(
-$core.method({
-selector: "asReceiver",
-protocol: "converting",
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "asReceiver\x0a\x09\x22Return customized copy to use as receiver,\x0a\x09or self if suffices.\x22\x0a\x09^ nil",
-referencedClasses: [],
-//>>excludeEnd("ide");
-pragmas: [],
-messageSends: []
-}, function ($methodClass){ return function (){
-var self=this,$self=this;
-return nil;
-
-}; }),
-$globals.ScopeVar);
-
 $core.addMethod(
 $core.method({
 selector: "isClassRefVar",
@@ -1528,48 +1510,6 @@ return $self._name();
 }; }),
 $globals.PseudoVar);
 
-$core.addMethod(
-$core.method({
-selector: "asReceiver",
-protocol: "testing",
-//>>excludeStart("ide", pragmas.excludeIdeData);
-args: [],
-source: "asReceiver\x0a\x09self class receiverNames\x0a\x09\x09at: self name\x0a\x09\x09ifPresent: [ :newName | ^ self copy name: newName; yourself ]\x0a\x09\x09ifAbsent: [ ^ self ]",
-referencedClasses: [],
-//>>excludeEnd("ide");
-pragmas: [],
-messageSends: ["at:ifPresent:ifAbsent:", "receiverNames", "class", "name", "name:", "copy", "yourself"]
-}, function ($methodClass){ return function (){
-var self=this,$self=this;
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx1) {
-//>>excludeEnd("ctx");
-var $1;
-var $early={};
-try {
-$recv($recv($self._class())._receiverNames())._at_ifPresent_ifAbsent_($self._name(),(function(newName){
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-return $core.withContext(function($ctx2) {
-//>>excludeEnd("ctx");
-$1=$self._copy();
-$recv($1)._name_(newName);
-throw $early=[$recv($1)._yourself()];
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx2) {$ctx2.fillBlock({newName:newName},$ctx1,1)});
-//>>excludeEnd("ctx");
-}),(function(){
-throw $early=[self];
-
-}));
-return self;
-}
-catch(e) {if(e===$early)return e[0]; throw e}
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-}, function($ctx1) {$ctx1.fill(self,"asReceiver",{})});
-//>>excludeEnd("ctx");
-}; }),
-$globals.PseudoVar);
-
 $core.addMethod(
 $core.method({
 selector: "isImmutable",

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

@@ -233,14 +233,6 @@ scope: aScope
 	scope := aScope
 ! !
 
-!ScopeVar methodsFor: 'converting'!
-
-asReceiver
-	"Return customized copy to use as receiver,
-	or self if suffices."
-	^ nil
-! !
-
 !ScopeVar methodsFor: 'testing'!
 
 isClassRefVar
@@ -369,13 +361,6 @@ alias
 
 !PseudoVar methodsFor: 'testing'!
 
-asReceiver
-	self class receiverNames
-		at: self name
-		ifPresent: [ :newName | ^ self copy name: newName; yourself ]
-		ifAbsent: [ ^ self ]
-!
-
 isImmutable
 	^ true
 !