Browse Source

Fixes issue #414

Nicolas Petton 11 years ago
parent
commit
f809f0b774
6 changed files with 32 additions and 68 deletions
  1. 0 14
      js/Compiler-IR.deploy.js
  2. 0 19
      js/Compiler-IR.js
  3. 13 13
      js/Compiler-Inlining.deploy.js
  4. 15 15
      js/Compiler-Inlining.js
  5. 0 4
      st/Compiler-IR.st
  6. 4 3
      st/Compiler-Inlining.st

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

@@ -2508,20 +2508,6 @@ return self}, function($ctx1) {$ctx1.fill(self,"nextPutStatementWith:",{aBlock:a
 messageSends: ["value", "nextPutAll:", "lf"]}),
 smalltalk.JSStream);
 
-smalltalk.addMethod(
-"_nextPutVar_",
-smalltalk.method({
-selector: "nextPutVar:",
-fn: function (aString){
-var self=this;
-return smalltalk.withContext(function($ctx1) { 
var $1,$2;
-$1=self["@stream"];
-_st($1)._nextPutAll_(_st(_st("var ").__comma(aString)).__comma(";"));
-$2=_st($1)._lf();
-return self}, function($ctx1) {$ctx1.fill(self,"nextPutVar:",{aString:aString},smalltalk.JSStream)})},
-messageSends: ["nextPutAll:", ",", "lf"]}),
-smalltalk.JSStream);
-
 smalltalk.addMethod(
 "_nextPutVars_",
 smalltalk.method({

+ 0 - 19
js/Compiler-IR.js

@@ -3352,25 +3352,6 @@ referencedClasses: []
 }),
 smalltalk.JSStream);
 
-smalltalk.addMethod(
-"_nextPutVar_",
-smalltalk.method({
-selector: "nextPutVar:",
-category: 'streaming',
-fn: function (aString){
-var self=this;
-return smalltalk.withContext(function($ctx1) { 
var $1,$2;
-$1=self["@stream"];
-_st($1)._nextPutAll_(_st(_st("var ").__comma(aString)).__comma(";"));
-$2=_st($1)._lf();
-return self}, function($ctx1) {$ctx1.fill(self,"nextPutVar:",{aString:aString},smalltalk.JSStream)})},
-args: ["aString"],
-source: "nextPutVar: aString\x0a\x09stream nextPutAll: 'var ', aString, ';'; lf",
-messageSends: ["nextPutAll:", ",", "lf"],
-referencedClasses: []
-}),
-smalltalk.JSStream);
-
 smalltalk.addMethod(
 "_nextPutVars_",
 smalltalk.method({

+ 13 - 13
js/Compiler-Inlining.deploy.js

@@ -446,11 +446,14 @@ smalltalk.method({
 selector: "visitIRInlinedClosure:",
 fn: function (anIRInlinedClosure){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
_st(_st(anIRInlinedClosure)._instructions())._do_((function(each){
+return smalltalk.withContext(function($ctx1) { 
_st(_st(self)._stream())._nextPutVars_(_st(_st(anIRInlinedClosure)._tempDeclarations())._collect_((function(each){
+return smalltalk.withContext(function($ctx2) {
return _st(_st(each)._name())._asVariableName();
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})})));
+_st(_st(anIRInlinedClosure)._instructions())._do_((function(each){
 return smalltalk.withContext(function($ctx2) {
return _st(self)._visit_(each);
 }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
 return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedClosure:",{anIRInlinedClosure:anIRInlinedClosure},smalltalk.IRInliningJSTranslator)})},
-messageSends: ["do:", "visit:", "instructions"]}),
+messageSends: ["nextPutVars:", "collect:", "asVariableName", "name", "tempDeclarations", "stream", "do:", "visit:", "instructions"]}),
 smalltalk.IRInliningJSTranslator);
 
 smalltalk.addMethod(
@@ -711,14 +714,11 @@ selector: "inlineClosure:",
 fn: function (anIRClosure){
 var self=this;
 var inlinedClosure,sequence,statements;
-return smalltalk.withContext(function($ctx1) { 
var $1,$2,$3;
+return smalltalk.withContext(function($ctx1) { 
var $1,$2;
 inlinedClosure=_st(self)._inlinedClosure();
 _st(inlinedClosure)._scope_(_st(anIRClosure)._scope());
-_st(_st(anIRClosure)._instructions())._do_((function(each){
-return smalltalk.withContext(function($ctx2) {
$1=_st(each)._isSequence();
-if(! smalltalk.assert($1)){
-return _st(inlinedClosure)._add_(each);
-};
+_st(_st(anIRClosure)._tempDeclarations())._do_((function(each){
+return smalltalk.withContext(function($ctx2) {
return _st(inlinedClosure)._add_(each);
 }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
 sequence=_st(self)._inlinedSequence();
 _st(inlinedClosure)._add_(sequence);
@@ -727,19 +727,19 @@ _st(statements)._ifNotEmpty_((function(){
 return smalltalk.withContext(function($ctx2) {
_st(_st(statements)._allButLast())._do_((function(each){
 return smalltalk.withContext(function($ctx3) {
return _st(sequence)._add_(each);
 }, function($ctx3) {$ctx3.fillBlock({each:each},$ctx1)})}));
-$2=_st(_st(_st(statements)._last())._isReturn())._and_((function(){
+$1=_st(_st(_st(statements)._last())._isReturn())._and_((function(){
 return smalltalk.withContext(function($ctx3) {
return _st(_st(statements)._last())._isBlockReturn();
 }, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}));
-if(smalltalk.assert($2)){
+if(smalltalk.assert($1)){
 return _st(sequence)._add_(_st(_st(_st(statements)._last())._instructions())._first());
 } else {
 return _st(sequence)._add_(_st(statements)._last());
 };
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
-$3=inlinedClosure;
-return $3;
+$2=inlinedClosure;
+return $2;
 }, function($ctx1) {$ctx1.fill(self,"inlineClosure:",{anIRClosure:anIRClosure,inlinedClosure:inlinedClosure,sequence:sequence,statements:statements},smalltalk.IRSendInliner)})},
-messageSends: ["inlinedClosure", "scope:", "scope", "do:", "ifFalse:", "add:", "isSequence", "instructions", "inlinedSequence", "last", "ifNotEmpty:", "allButLast", "ifTrue:ifFalse:", "first", "and:", "isBlockReturn", "isReturn"]}),
+messageSends: ["inlinedClosure", "scope:", "scope", "do:", "add:", "tempDeclarations", "inlinedSequence", "instructions", "last", "ifNotEmpty:", "allButLast", "ifTrue:ifFalse:", "first", "and:", "isBlockReturn", "isReturn"]}),
 smalltalk.IRSendInliner);
 
 smalltalk.addMethod(

+ 15 - 15
js/Compiler-Inlining.js

@@ -600,13 +600,16 @@ selector: "visitIRInlinedClosure:",
 category: 'visiting',
 fn: function (anIRInlinedClosure){
 var self=this;
-return smalltalk.withContext(function($ctx1) { 
_st(_st(anIRInlinedClosure)._instructions())._do_((function(each){
+return smalltalk.withContext(function($ctx1) { 
_st(_st(self)._stream())._nextPutVars_(_st(_st(anIRInlinedClosure)._tempDeclarations())._collect_((function(each){
+return smalltalk.withContext(function($ctx2) {
return _st(_st(each)._name())._asVariableName();
+}, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})})));
+_st(_st(anIRInlinedClosure)._instructions())._do_((function(each){
 return smalltalk.withContext(function($ctx2) {
return _st(self)._visit_(each);
 }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
 return self}, function($ctx1) {$ctx1.fill(self,"visitIRInlinedClosure:",{anIRInlinedClosure:anIRInlinedClosure},smalltalk.IRInliningJSTranslator)})},
 args: ["anIRInlinedClosure"],
-source: "visitIRInlinedClosure: anIRInlinedClosure\x0a\x09anIRInlinedClosure instructions do: [ :each |\x0a\x09\x09self visit: each ]",
-messageSends: ["do:", "visit:", "instructions"],
+source: "visitIRInlinedClosure: anIRInlinedClosure\x0a\x09self stream nextPutVars: (anIRInlinedClosure tempDeclarations collect: [ :each |\x0a\x09\x09each name asVariableName ]).\x0a\x09anIRInlinedClosure instructions do: [ :each |\x0a\x09\x09self visit: each ]",
+messageSends: ["nextPutVars:", "collect:", "asVariableName", "name", "tempDeclarations", "stream", "do:", "visit:", "instructions"],
 referencedClasses: []
 }),
 smalltalk.IRInliningJSTranslator);
@@ -951,14 +954,11 @@ category: 'inlining',
 fn: function (anIRClosure){
 var self=this;
 var inlinedClosure,sequence,statements;
-return smalltalk.withContext(function($ctx1) { 
var $1,$2,$3;
+return smalltalk.withContext(function($ctx1) { 
var $1,$2;
 inlinedClosure=_st(self)._inlinedClosure();
 _st(inlinedClosure)._scope_(_st(anIRClosure)._scope());
-_st(_st(anIRClosure)._instructions())._do_((function(each){
-return smalltalk.withContext(function($ctx2) {
$1=_st(each)._isSequence();
-if(! smalltalk.assert($1)){
-return _st(inlinedClosure)._add_(each);
-};
+_st(_st(anIRClosure)._tempDeclarations())._do_((function(each){
+return smalltalk.withContext(function($ctx2) {
return _st(inlinedClosure)._add_(each);
 }, function($ctx2) {$ctx2.fillBlock({each:each},$ctx1)})}));
 sequence=_st(self)._inlinedSequence();
 _st(inlinedClosure)._add_(sequence);
@@ -967,21 +967,21 @@ _st(statements)._ifNotEmpty_((function(){
 return smalltalk.withContext(function($ctx2) {
_st(_st(statements)._allButLast())._do_((function(each){
 return smalltalk.withContext(function($ctx3) {
return _st(sequence)._add_(each);
 }, function($ctx3) {$ctx3.fillBlock({each:each},$ctx1)})}));
-$2=_st(_st(_st(statements)._last())._isReturn())._and_((function(){
+$1=_st(_st(_st(statements)._last())._isReturn())._and_((function(){
 return smalltalk.withContext(function($ctx3) {
return _st(_st(statements)._last())._isBlockReturn();
 }, function($ctx3) {$ctx3.fillBlock({},$ctx1)})}));
-if(smalltalk.assert($2)){
+if(smalltalk.assert($1)){
 return _st(sequence)._add_(_st(_st(_st(statements)._last())._instructions())._first());
 } else {
 return _st(sequence)._add_(_st(statements)._last());
 };
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1)})}));
-$3=inlinedClosure;
-return $3;
+$2=inlinedClosure;
+return $2;
 }, function($ctx1) {$ctx1.fill(self,"inlineClosure:",{anIRClosure:anIRClosure,inlinedClosure:inlinedClosure,sequence:sequence,statements:statements},smalltalk.IRSendInliner)})},
 args: ["anIRClosure"],
-source: "inlineClosure: anIRClosure\x0a\x09| inlinedClosure sequence statements |\x0a\x0a\x09inlinedClosure := self inlinedClosure.\x0a\x09inlinedClosure scope: anIRClosure scope.\x0a\x0a\x09\x22Add the possible temp declarations\x22\x0a\x09anIRClosure instructions do: [ :each |\x0a\x09\x09each isSequence ifFalse: [\x0a\x09\x09\x09inlinedClosure add: each ]].\x0a\x0a\x09\x22Add a block sequence\x22\x0a\x09sequence := self inlinedSequence.\x0a\x09inlinedClosure add: sequence.\x0a\x0a\x09\x22Get all the statements\x22\x0a\x09statements := anIRClosure instructions last instructions.\x0a\x09\x0a\x09statements ifNotEmpty: [\x0a\x09\x09statements allButLast do: [ :each | sequence add: each ].\x0a\x0a\x09\x09\x22Inlined closures don't have implicit local returns\x22\x0a\x09\x09(statements last isReturn and: [ statements last isBlockReturn ])\x0a\x09\x09\x09ifTrue: [ sequence add: statements last instructions first ]\x0a\x09\x09\x09ifFalse: [ sequence add: statements last ] ].\x0a\x0a\x09^ inlinedClosure",
-messageSends: ["inlinedClosure", "scope:", "scope", "do:", "ifFalse:", "add:", "isSequence", "instructions", "inlinedSequence", "last", "ifNotEmpty:", "allButLast", "ifTrue:ifFalse:", "first", "and:", "isBlockReturn", "isReturn"],
+source: "inlineClosure: anIRClosure\x0a\x09| inlinedClosure sequence statements |\x0a\x0a\x09inlinedClosure := self inlinedClosure.\x0a\x09inlinedClosure scope: anIRClosure scope.\x0a\x0a\x09\x22Add the possible temp declarations\x22\x0a\x09anIRClosure tempDeclarations do: [ :each |\x0a\x09\x09\x09inlinedClosure add: each ].\x0a\x0a\x09\x22Add a block sequence\x22\x0a\x09sequence := self inlinedSequence.\x0a\x09inlinedClosure add: sequence.\x0a\x0a\x09\x22Get all the statements\x22\x0a\x09statements := anIRClosure instructions last instructions.\x0a\x09\x0a\x09statements ifNotEmpty: [\x0a\x09\x09statements allButLast do: [ :each | sequence add: each ].\x0a\x0a\x09\x09\x22Inlined closures don't have implicit local returns\x22\x0a\x09\x09(statements last isReturn and: [ statements last isBlockReturn ])\x0a\x09\x09\x09ifTrue: [ sequence add: statements last instructions first ]\x0a\x09\x09\x09ifFalse: [ sequence add: statements last ] ].\x0a\x0a\x09^ inlinedClosure",
+messageSends: ["inlinedClosure", "scope:", "scope", "do:", "add:", "tempDeclarations", "inlinedSequence", "instructions", "last", "ifNotEmpty:", "allButLast", "ifTrue:ifFalse:", "first", "and:", "isBlockReturn", "isReturn"],
 referencedClasses: []
 }),
 smalltalk.IRSendInliner);

+ 0 - 4
st/Compiler-IR.st

@@ -1179,10 +1179,6 @@ nextPutStatementWith: aBlock
 	stream nextPutAll: ';'; lf
 !
 
-nextPutVar: aString
-	stream nextPutAll: 'var ', aString, ';'; lf
-!
-
 nextPutVars: aCollection
 	aCollection ifEmpty: [ ^self ].
 	

+ 4 - 3
st/Compiler-Inlining.st

@@ -255,6 +255,8 @@ visitIRInlinedAssignment: anIRInlinedAssignment
 !
 
 visitIRInlinedClosure: anIRInlinedClosure
+	self stream nextPutVars: (anIRInlinedClosure tempDeclarations collect: [ :each |
+		each name asVariableName ]).
 	anIRInlinedClosure instructions do: [ :each |
 		self visit: each ]
 !
@@ -415,9 +417,8 @@ inlineClosure: anIRClosure
 	inlinedClosure scope: anIRClosure scope.
 
 	"Add the possible temp declarations"
-	anIRClosure instructions do: [ :each |
-		each isSequence ifFalse: [
-			inlinedClosure add: each ]].
+	anIRClosure tempDeclarations do: [ :each |
+			inlinedClosure add: each ].
 
 	"Add a block sequence"
 	sequence := self inlinedSequence.