Переглянути джерело

- Fixed AIContext >> selector
- Interpreter test for thisContext

Nicolas Petton 11 роки тому
батько
коміт
e6885e2532

+ 4 - 4
js/Compiler-Interpreter.deploy.js

@@ -202,19 +202,19 @@ smalltalk.addMethod(
 "_selector",
 smalltalk.method({
 selector: "selector",
-fn: function () {
+fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 var $2,$1;
-$2=_st(self)._metod();
+$2=_st(self)._method();
 if(($receiver = $2) == nil || $receiver == undefined){
 $1=$2;
 } else {
 $1=_st(_st(self)._method())._selector();
 };
 return $1;
-}, function($ctx1) {$ctx1.fill(self,"selector",{},smalltalk.AIContext)});},
-messageSends: ["ifNotNil:", "selector", "method", "metod"]}),
+}, function($ctx1) {$ctx1.fill(self,"selector",{},smalltalk.AIContext)})},
+messageSends: ["ifNotNil:", "selector", "method"]}),
 smalltalk.AIContext);
 
 

+ 5 - 5
js/Compiler-Interpreter.js

@@ -269,21 +269,21 @@ smalltalk.addMethod(
 smalltalk.method({
 selector: "selector",
 category: 'accessing',
-fn: function () {
+fn: function (){
 var self=this;
 return smalltalk.withContext(function($ctx1) { 
 var $2,$1;
-$2=_st(self)._metod();
+$2=_st(self)._method();
 if(($receiver = $2) == nil || $receiver == undefined){
 $1=$2;
 } else {
 $1=_st(_st(self)._method())._selector();
 };
 return $1;
-}, function($ctx1) {$ctx1.fill(self,"selector",{},smalltalk.AIContext)});},
+}, function($ctx1) {$ctx1.fill(self,"selector",{},smalltalk.AIContext)})},
 args: [],
-source: "selector\x0a\x09^ self metod\x0a\x09\x09ifNotNil: [ self method selector ]",
-messageSends: ["ifNotNil:", "selector", "method", "metod"],
+source: "selector\x0a\x09^ self method\x0a\x09\x09ifNotNil: [ self method selector ]",
+messageSends: ["ifNotNil:", "selector", "method"],
 referencedClasses: []
 }),
 smalltalk.AIContext);

+ 14 - 0
js/Compiler-Tests.deploy.js

@@ -270,6 +270,20 @@ return self}, function($ctx1) {$ctx1.fill(self,"testTempAssignment",{},smalltalk
 messageSends: ["assert:equals:", "interpret:"]}),
 smalltalk.ASTInterpreterTest);
 
+smalltalk.addMethod(
+"_testThisContext",
+smalltalk.method({
+selector: "testThisContext",
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+_st(self)._assert_(_st(_st(_st(self)._interpret_("foo ^ thisContext"))._outerContext())._isNil());
+_st(self)._assert_(_st(_st(_st(self)._interpret_("foo ^ [ thisContext ] value"))._outerContext())._notNil());
+_st(self)._assert_(_st(self)._interpret_("foo ^ [ thisContext ] value outerContext == thisContext"));
+return self}, function($ctx1) {$ctx1.fill(self,"testThisContext",{},smalltalk.ASTInterpreterTest)})},
+messageSends: ["assert:", "isNil", "outerContext", "interpret:", "notNil"]}),
+smalltalk.ASTInterpreterTest);
+
 
 
 smalltalk.addClass('ASTSteppingInterpreterTest', smalltalk.AbstractASTInterpreterTest, ['interpreter'], 'Compiler-Tests');

+ 19 - 0
js/Compiler-Tests.js

@@ -365,6 +365,25 @@ referencedClasses: []
 }),
 smalltalk.ASTInterpreterTest);
 
+smalltalk.addMethod(
+"_testThisContext",
+smalltalk.method({
+selector: "testThisContext",
+category: 'tests',
+fn: function (){
+var self=this;
+return smalltalk.withContext(function($ctx1) { 
+_st(self)._assert_(_st(_st(_st(self)._interpret_("foo ^ thisContext"))._outerContext())._isNil());
+_st(self)._assert_(_st(_st(_st(self)._interpret_("foo ^ [ thisContext ] value"))._outerContext())._notNil());
+_st(self)._assert_(_st(self)._interpret_("foo ^ [ thisContext ] value outerContext == thisContext"));
+return self}, function($ctx1) {$ctx1.fill(self,"testThisContext",{},smalltalk.ASTInterpreterTest)})},
+args: [],
+source: "testThisContext\x0a\x09self assert: (self interpret: 'foo ^ thisContext') outerContext isNil.\x0a\x09self assert: (self interpret: 'foo ^ [ thisContext ] value') outerContext notNil.\x0a\x09self assert: (self interpret: 'foo ^ [ thisContext ] value outerContext == thisContext')",
+messageSends: ["assert:", "isNil", "outerContext", "interpret:", "notNil"],
+referencedClasses: []
+}),
+smalltalk.ASTInterpreterTest);
+
 
 
 smalltalk.addClass('ASTSteppingInterpreterTest', smalltalk.AbstractASTInterpreterTest, ['interpreter'], 'Compiler-Tests');

+ 1 - 1
st/Compiler-Interpreter.st

@@ -57,7 +57,7 @@ receiver: anObject
 !
 
 selector
-	^ self metod
+	^ self method
 		ifNotNil: [ self method selector ]
 ! !
 

+ 6 - 0
st/Compiler-Tests.st

@@ -133,6 +133,12 @@ testReceiver
 
 testTempAssignment
 	self assert: (self interpret: 'foo | a | a := 2. ^ a') equals: 2
+!
+
+testThisContext
+	self assert: (self interpret: 'foo ^ thisContext') outerContext isNil.
+	self assert: (self interpret: 'foo ^ [ thisContext ] value') outerContext notNil.
+	self assert: (self interpret: 'foo ^ [ thisContext ] value outerContext == thisContext')
 ! !
 
 AbstractASTInterpreterTest subclass: #ASTSteppingInterpreterTest