Browse Source

Extract direct use of `self instructions`. Part 2.

Returns.
Herbert Vojčík 7 years ago
parent
commit
678147917e
4 changed files with 52 additions and 43 deletions
  1. 23 0
      src/Compiler-IR.js
  2. 4 0
      src/Compiler-IR.st
  3. 20 38
      src/Compiler-Inlining.js
  4. 5 5
      src/Compiler-Inlining.st

+ 23 - 0
src/Compiler-IR.js

@@ -2368,6 +2368,29 @@ messageSends: []
 }),
 $globals.IRReturn);
 
+$core.addMethod(
+$core.method({
+selector: "expression",
+protocol: 'accessing',
+fn: function (){
+var self=this;
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+return $core.withContext(function($ctx1) {
+//>>excludeEnd("ctx");
+return $recv(self._instructions())._single();
+//>>excludeStart("ctx", pragmas.excludeDebugContexts);
+}, function($ctx1) {$ctx1.fill(self,"expression",{},$globals.IRReturn)});
+//>>excludeEnd("ctx");
+},
+//>>excludeStart("ide", pragmas.excludeIdeData);
+args: [],
+source: "expression\x0a\x09^ self instructions single",
+referencedClasses: [],
+//>>excludeEnd("ide");
+messageSends: ["single", "instructions"]
+}),
+$globals.IRReturn);
+
 $core.addMethod(
 $core.method({
 selector: "isBlockReturn",

+ 4 - 0
src/Compiler-IR.st

@@ -565,6 +565,10 @@ I am a local return instruction.!
 
 !IRReturn methodsFor: 'accessing'!
 
+expression
+	^ self instructions single
+!
+
 scope
 	^ scope ifNil: [ self parent scope ]
 ! !

+ 20 - 38
src/Compiler-Inlining.js

@@ -592,25 +592,16 @@ var self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $4,$3,$2,$1;
+var $1;
 $1=$recv($recv($recv(anIRReturn)._isInlined())._not())._and_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-$4=$recv(anIRReturn)._instructions();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx2.sendIdx["instructions"]=1;
-//>>excludeEnd("ctx");
-$3=$recv($4)._single();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx2.sendIdx["single"]=1;
-//>>excludeEnd("ctx");
-$2=$recv($3)._isSend();
-return $recv($2)._and_((function(){
+return $recv($recv($recv($recv(anIRReturn)._instructions())._single())._isSend())._and_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx3) {
 //>>excludeEnd("ctx");
-return self._shouldInlineSend_($recv($recv(anIRReturn)._instructions())._single());
+return self._shouldInlineSend_($recv(anIRReturn)._expression());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx3) {$ctx3.fillBlock({},$ctx2,2)});
 //>>excludeEnd("ctx");
@@ -629,10 +620,10 @@ return $1;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anIRReturn"],
-source: "shouldInlineReturn: anIRReturn\x0a\x09^ anIRReturn isInlined not and: [\x0a\x09\x09anIRReturn instructions single isSend and: [\x0a\x09\x09\x09self shouldInlineSend: (anIRReturn instructions single) ]]",
+source: "shouldInlineReturn: anIRReturn\x0a\x09^ anIRReturn isInlined not and: [\x0a\x09\x09anIRReturn instructions single isSend and: [\x0a\x09\x09\x09self shouldInlineSend: anIRReturn expression ]]",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["and:", "not", "isInlined", "isSend", "single", "instructions", "shouldInlineSend:"]
+messageSends: ["and:", "not", "isInlined", "isSend", "single", "instructions", "shouldInlineSend:", "expression"]
 }),
 $globals.IRInliner);
 
@@ -1248,7 +1239,7 @@ $recv($1)._nextPutStatementWith_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
-return self._visit_($recv($recv(anIRInlinedReturn)._instructions())._single());
+return self._visit_($recv(anIRInlinedReturn)._expression());
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx2) {$ctx2.fillBlock({},$ctx1,1)});
 //>>excludeEnd("ctx");
@@ -1263,10 +1254,10 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anIRInlinedReturn"],
-source: "visitIRInlinedNonLocalReturn: anIRInlinedReturn\x0a\x09self stream nextPutStatementWith: [\x0a\x09\x09self visit: anIRInlinedReturn instructions single ].\x0a\x09self stream nextPutNonLocalReturnWith: [ ]",
+source: "visitIRInlinedNonLocalReturn: anIRInlinedReturn\x0a\x09self stream nextPutStatementWith: [\x0a\x09\x09self visit: anIRInlinedReturn expression ].\x0a\x09self stream nextPutNonLocalReturnWith: [ ]",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["nextPutStatementWith:", "stream", "visit:", "single", "instructions", "nextPutNonLocalReturnWith:"]
+messageSends: ["nextPutStatementWith:", "stream", "visit:", "expression", "nextPutNonLocalReturnWith:"]
 }),
 $globals.IRInliningJSTranslator);
 
@@ -1279,7 +1270,7 @@ var self=this;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-self._visit_($recv($recv(anIRInlinedReturn)._instructions())._single());
+self._visit_($recv(anIRInlinedReturn)._expression());
 return self;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"visitIRInlinedReturn:",{anIRInlinedReturn:anIRInlinedReturn},$globals.IRInliningJSTranslator)});
@@ -1287,10 +1278,10 @@ return self;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anIRInlinedReturn"],
-source: "visitIRInlinedReturn: anIRInlinedReturn\x0a\x09self visit: anIRInlinedReturn instructions single",
+source: "visitIRInlinedReturn: anIRInlinedReturn\x0a\x09self visit: anIRInlinedReturn expression",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["visit:", "single", "instructions"]
+messageSends: ["visit:", "expression"]
 }),
 $globals.IRInliningJSTranslator);
 
@@ -1578,7 +1569,7 @@ var inlinedClosure,sequence,statements;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1,$2,$3,$5,$6,$4,$7,$9,$11,$13,$14,$15,$12,$10,$17,$19,$20,$18,$16,$8,$23,$22,$24,$21,$25,$28,$27,$26;
+var $1,$2,$3,$5,$6,$4,$7,$9,$11,$13,$14,$15,$12,$10,$17,$19,$20,$18,$16,$8,$23,$22,$24,$21,$25,$27,$26;
 inlinedClosure=self._inlinedClosure();
 $1=inlinedClosure;
 $2=$recv(anIRClosure)._scope();
@@ -1700,9 +1691,6 @@ $recv(inlinedClosure)._add_(sequence);
 $ctx1.sendIdx["add:"]=6;
 //>>excludeEnd("ctx");
 statements=$recv($recv(anIRClosure)._sequence())._instructions();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["instructions"]=1;
-//>>excludeEnd("ctx");
 $recv(statements)._ifNotEmpty_((function(){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
@@ -1739,12 +1727,11 @@ return $recv($24)._isBlockReturn();
 }));
 if($core.assert($21)){
 $25=sequence;
-$28=$recv(statements)._last();
+$27=$recv(statements)._last();
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx["last"]=3;
 //>>excludeEnd("ctx");
-$27=$recv($28)._instructions();
-$26=$recv($27)._single();
+$26=$recv($27)._expression();
 return $recv($25)._add_($26);
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 $ctx2.sendIdx["add:"]=8;
@@ -1763,10 +1750,10 @@ return inlinedClosure;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anIRClosure"],
-source: "inlineClosure: anIRClosure\x0a\x09| inlinedClosure sequence statements |\x0a\x0a\x09inlinedClosure := self inlinedClosure.\x0a\x09inlinedClosure \x0a\x09\x09scope: anIRClosure scope;\x0a\x09\x09parent: anIRClosure parent.\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\x0a\x09\x22Map the closure arguments to the receiver of the message send\x22\x0a\x09anIRClosure arguments do: [ :each |\x0a\x09\x09inlinedClosure add: (IRTempDeclaration new name: each; yourself).\x0a\x09\x09sequence add: (IRAssignment new\x0a\x09\x09\x09add: (IRVariable new variable: (AliasVar new scope: inlinedClosure scope; name: each; yourself));\x0a\x09\x09\x09add: (IRVariable new variable: (AliasVar new scope: inlinedClosure scope; name: '$receiver'; yourself));\x0a\x09\x09\x09yourself) ].\x0a\x09\x09\x09\x0a\x09\x22To ensure the correct order of the closure instructions: first the temps then the sequence\x22\x0a\x09inlinedClosure add: sequence.\x0a\x0a\x09\x22Get all the statements\x22\x0a\x09statements := anIRClosure sequence 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 single ]\x0a\x09\x09\x09ifFalse: [ sequence add: statements last ] ].\x0a\x0a\x09^ inlinedClosure",
+source: "inlineClosure: anIRClosure\x0a\x09| inlinedClosure sequence statements |\x0a\x0a\x09inlinedClosure := self inlinedClosure.\x0a\x09inlinedClosure \x0a\x09\x09scope: anIRClosure scope;\x0a\x09\x09parent: anIRClosure parent.\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\x0a\x09\x22Map the closure arguments to the receiver of the message send\x22\x0a\x09anIRClosure arguments do: [ :each |\x0a\x09\x09inlinedClosure add: (IRTempDeclaration new name: each; yourself).\x0a\x09\x09sequence add: (IRAssignment new\x0a\x09\x09\x09add: (IRVariable new variable: (AliasVar new scope: inlinedClosure scope; name: each; yourself));\x0a\x09\x09\x09add: (IRVariable new variable: (AliasVar new scope: inlinedClosure scope; name: '$receiver'; yourself));\x0a\x09\x09\x09yourself) ].\x0a\x09\x09\x09\x0a\x09\x22To ensure the correct order of the closure instructions: first the temps then the sequence\x22\x0a\x09inlinedClosure add: sequence.\x0a\x0a\x09\x22Get all the statements\x22\x0a\x09statements := anIRClosure sequence 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 expression ]\x0a\x09\x09\x09ifFalse: [ sequence add: statements last ] ].\x0a\x0a\x09^ inlinedClosure",
 referencedClasses: ["IRTempDeclaration", "IRAssignment", "IRVariable", "AliasVar"],
 //>>excludeEnd("ide");
-messageSends: ["inlinedClosure", "scope:", "scope", "parent:", "parent", "do:", "tempDeclarations", "add:", "inlinedSequence", "arguments", "name:", "new", "yourself", "variable:", "instructions", "sequence", "ifNotEmpty:", "allButLast", "ifTrue:ifFalse:", "and:", "isReturn", "last", "isBlockReturn", "single"]
+messageSends: ["inlinedClosure", "scope:", "scope", "parent:", "parent", "do:", "tempDeclarations", "add:", "inlinedSequence", "arguments", "name:", "new", "yourself", "variable:", "instructions", "sequence", "ifNotEmpty:", "allButLast", "ifTrue:ifFalse:", "and:", "isReturn", "last", "isBlockReturn", "expression"]
 }),
 $globals.IRSendInliner);
 
@@ -2337,13 +2324,8 @@ var return_;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx1) {
 //>>excludeEnd("ctx");
-var $1;
 return_=self._inlinedReturn();
-$1=$recv(anIRReturn)._instructions();
-//>>excludeStart("ctx", pragmas.excludeDebugContexts);
-$ctx1.sendIdx["instructions"]=1;
-//>>excludeEnd("ctx");
-$recv($1)._do_((function(each){
+$recv($recv(anIRReturn)._instructions())._do_((function(each){
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 return $core.withContext(function($ctx2) {
 //>>excludeEnd("ctx");
@@ -2353,7 +2335,7 @@ return $recv(return_)._add_(each);
 //>>excludeEnd("ctx");
 }));
 $recv(anIRReturn)._replaceWith_(return_);
-self._inlineSend_($recv($recv(return_)._instructions())._single());
+self._inlineSend_($recv(return_)._expression());
 return return_;
 //>>excludeStart("ctx", pragmas.excludeDebugContexts);
 }, function($ctx1) {$ctx1.fill(self,"inlineReturn:",{anIRReturn:anIRReturn,return_:return_},$globals.IRReturnInliner)});
@@ -2361,10 +2343,10 @@ return return_;
 },
 //>>excludeStart("ide", pragmas.excludeIdeData);
 args: ["anIRReturn"],
-source: "inlineReturn: anIRReturn\x0a\x09| return |\x0a\x09return := self inlinedReturn.\x0a\x09anIRReturn instructions do: [ :each |\x0a\x09\x09return add: each ].\x0a\x09anIRReturn replaceWith: return.\x0a\x09self inlineSend: return instructions single.\x0a\x09^ return",
+source: "inlineReturn: anIRReturn\x0a\x09| return |\x0a\x09return := self inlinedReturn.\x0a\x09anIRReturn instructions do: [ :each |\x0a\x09\x09return add: each ].\x0a\x09anIRReturn replaceWith: return.\x0a\x09self inlineSend: return expression.\x0a\x09^ return",
 referencedClasses: [],
 //>>excludeEnd("ide");
-messageSends: ["inlinedReturn", "do:", "instructions", "add:", "replaceWith:", "inlineSend:", "single"]
+messageSends: ["inlinedReturn", "do:", "instructions", "add:", "replaceWith:", "inlineSend:", "expression"]
 }),
 $globals.IRReturnInliner);
 

+ 5 - 5
src/Compiler-Inlining.st

@@ -201,7 +201,7 @@ shouldInlineAssignment: anIRAssignment
 shouldInlineReturn: anIRReturn
 	^ anIRReturn isInlined not and: [
 		anIRReturn instructions single isSend and: [
-			self shouldInlineSend: (anIRReturn instructions single) ]]
+			self shouldInlineSend: anIRReturn expression ]]
 !
 
 shouldInlineSend: anIRSend
@@ -308,12 +308,12 @@ visitIRInlinedIfTrueIfFalse: anIRInlinedIfTrueIfFalse
 
 visitIRInlinedNonLocalReturn: anIRInlinedReturn
 	self stream nextPutStatementWith: [
-		self visit: anIRInlinedReturn instructions single ].
+		self visit: anIRInlinedReturn expression ].
 	self stream nextPutNonLocalReturnWith: [ ]
 !
 
 visitIRInlinedReturn: anIRInlinedReturn
-	self visit: anIRInlinedReturn instructions single
+	self visit: anIRInlinedReturn expression
 !
 
 visitIRInlinedSequence: anIRInlinedSequence
@@ -445,7 +445,7 @@ inlineClosure: anIRClosure
 
 		"Inlined closures don't have implicit local returns"
 		(statements last isReturn and: [ statements last isBlockReturn ])
-			ifTrue: [ sequence add: statements last instructions single ]
+			ifTrue: [ sequence add: statements last expression ]
 			ifFalse: [ sequence add: statements last ] ].
 
 	^ inlinedClosure
@@ -601,7 +601,7 @@ inlineReturn: anIRReturn
 	anIRReturn instructions do: [ :each |
 		return add: each ].
 	anIRReturn replaceWith: return.
-	self inlineSend: return instructions single.
+	self inlineSend: return expression.
 	^ return
 ! !