Bladeren bron

- fix ASTPCNodeVisitor block visiting

Nicolas Petton 10 jaren geleden
bovenliggende
commit
177cea21f8
4 gewijzigde bestanden met toevoegingen van 32 en 44 verwijderingen
  1. 0 34
      js/Compiler-Interpreter.js
  2. 23 0
      js/Compiler-Tests.js
  3. 0 10
      st/Compiler-Interpreter.st
  4. 9 0
      st/Compiler-Tests.st

+ 0 - 34
js/Compiler-Interpreter.js

@@ -2232,40 +2232,6 @@ referencedClasses: []
 }),
 smalltalk.ASTPCNodeVisitor);
 
-smalltalk.addMethod(
-smalltalk.method({
-selector: "visitBlockNode:",
-category: 'visiting',
-fn: function (aNode){
-var self=this;
-return smalltalk.withContext(function($ctx1) { 
-var $3,$2,$4,$1,$5;
-$3=_st(aNode)._parent();
-$ctx1.sendIdx["parent"]=1;
-$2=_st($3)._isSendNode();
-$1=_st($2)._and_((function(){
-return smalltalk.withContext(function($ctx2) {
-$4=_st(aNode)._parent();
-return _st($4)._shouldBeInlined();
-}, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)})}));
-if(smalltalk.assert($1)){
-smalltalk.ASTPCNodeVisitor.superclass.fn.prototype._visitBlockNode_.apply(_st(self), [aNode]);
-} else {
-$5=_st(self._blockIndex()).__gt_eq(_st(self._context())._index());
-if(! smalltalk.assert($5)){
-self._increaseBlockIndex();
-smalltalk.ASTPCNodeVisitor.superclass.fn.prototype._visitBlockNode_.apply(_st(self), [aNode]);
-$ctx1.sendIdx["visitBlockNode:"]=1;
-};
-};
-return self}, function($ctx1) {$ctx1.fill(self,"visitBlockNode:",{aNode:aNode},smalltalk.ASTPCNodeVisitor)})},
-args: ["aNode"],
-source: "visitBlockNode: aNode\x0a\x09\x22Inlined send node. Assume that the block is inlined\x22\x0a\x09(aNode parent isSendNode and: [ aNode parent shouldBeInlined ])\x0a\x09\x09ifFalse: [\x0a\x09\x09\x09self blockIndex >= self context index ifFalse: [\x0a\x09\x09\x09\x09self increaseBlockIndex.\x0a\x09\x09\x09\x09super visitBlockNode: aNode ] ]\x0a\x09\x09ifTrue: [ super visitBlockNode: aNode ]",
-messageSends: ["ifFalse:ifTrue:", "and:", "isSendNode", "parent", "shouldBeInlined", "ifFalse:", ">=", "blockIndex", "index", "context", "increaseBlockIndex", "visitBlockNode:"],
-referencedClasses: []
-}),
-smalltalk.ASTPCNodeVisitor);
-
 smalltalk.addMethod(
 smalltalk.method({
 selector: "visitJSStatementNode:",

+ 23 - 0
js/Compiler-Tests.js

@@ -166,6 +166,29 @@ referencedClasses: ["Object"]
 }),
 smalltalk.ASTPCNodeVisitorTest);
 
+smalltalk.addMethod(
+smalltalk.method({
+selector: "testMessageSendWithBlocks",
+category: 'tests',
+fn: function (){
+var self=this;
+var ast;
+function $Object(){return smalltalk.Object||(typeof Object=="undefined"?nil:Object)}
+return smalltalk.withContext(function($ctx1) { 
+var $1,$2;
+ast=self._parse_forClass_("foo true ifTrue: [ [ self asString yourself ] value.  ]. ^ self asBoolean",$Object());
+$1=self._astPCNodeVisitorForSelector_("yourself");
+_st($1)._visit_(ast);
+$2=_st($1)._currentNode();
+self._assert_equals_(_st($2)._selector(),"yourself");
+return self}, function($ctx1) {$ctx1.fill(self,"testMessageSendWithBlocks",{ast:ast},smalltalk.ASTPCNodeVisitorTest)})},
+args: [],
+source: "testMessageSendWithBlocks\x0a\x09| ast |\x0a\x09\x0a\x09ast := self parse: 'foo true ifTrue: [ [ self asString yourself ] value.  ]. ^ self asBoolean' forClass: Object.\x0a\x09self assert: ((self astPCNodeVisitorForSelector: 'yourself')\x0a\x09\x09visit: ast;\x0a\x09\x09currentNode) selector equals: 'yourself'",
+messageSends: ["parse:forClass:", "assert:equals:", "selector", "visit:", "astPCNodeVisitorForSelector:", "currentNode"],
+referencedClasses: ["Object"]
+}),
+smalltalk.ASTPCNodeVisitorTest);
+
 smalltalk.addMethod(
 smalltalk.method({
 selector: "testMessageSendWithInlining",

+ 0 - 10
st/Compiler-Interpreter.st

@@ -754,16 +754,6 @@ selector: aString
 
 !ASTPCNodeVisitor methodsFor: 'visiting'!
 
-visitBlockNode: aNode
-	"Inlined send node. Assume that the block is inlined"
-	(aNode parent isSendNode and: [ aNode parent shouldBeInlined ])
-		ifFalse: [
-			self blockIndex >= self context index ifFalse: [
-				self increaseBlockIndex.
-				super visitBlockNode: aNode ] ]
-		ifTrue: [ super visitBlockNode: aNode ]
-!
-
 visitJSStatementNode: aNode
 	"If a JSStatementNode is encountered, it always is the current node.
 	Stop visiting the AST there"

+ 9 - 0
st/Compiler-Tests.st

@@ -61,6 +61,15 @@ testMessageSend
 		currentNode) selector equals: 'yourself'
 !
 
+testMessageSendWithBlocks
+	| ast |
+	
+	ast := self parse: 'foo true ifTrue: [ [ self asString yourself ] value.  ]. ^ self asBoolean' forClass: Object.
+	self assert: ((self astPCNodeVisitorForSelector: 'yourself')
+		visit: ast;
+		currentNode) selector equals: 'yourself'
+!
+
 testMessageSendWithInlining
 	| ast |