forked from jruby/jruby
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move call form of block_given? to its own instr
The optimized block_given? still needs to be treated as a call, which would pollute the flags for defined?(yield) unnecessarily. This patch moves it to its own instr.
- Loading branch information
Showing
6 changed files
with
83 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
core/src/main/java/org/jruby/ir/instructions/BlockGivenCallInstr.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package org.jruby.ir.instructions; | ||
|
||
import org.jruby.ir.IRVisitor; | ||
import org.jruby.ir.Operation; | ||
import org.jruby.ir.operands.Operand; | ||
import org.jruby.ir.operands.Variable; | ||
import org.jruby.ir.persistence.IRReaderDecoder; | ||
import org.jruby.ir.persistence.IRWriterEncoder; | ||
import org.jruby.ir.runtime.IRRuntimeHelpers; | ||
import org.jruby.ir.transformations.inlining.CloneInfo; | ||
import org.jruby.parser.StaticScope; | ||
import org.jruby.runtime.DynamicScope; | ||
import org.jruby.runtime.ThreadContext; | ||
import org.jruby.runtime.builtin.IRubyObject; | ||
import org.jruby.runtime.callsite.FunctionalCachingCallSite; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* A call to block_given? which can be optimized like defined?(yield) or a regular call. | ||
*/ | ||
public class BlockGivenCallInstr extends OneOperandResultBaseInstr implements FixedArityInstr { | ||
private final String callName; | ||
private final FunctionalCachingCallSite blockGivenSite; | ||
|
||
public BlockGivenCallInstr(Variable result, Operand block, String callName) { | ||
super(Operation.BLOCK_GIVEN_CALL, Objects.requireNonNull(result, "BlockGivenCallInstr result is null"), block); | ||
|
||
this.callName = Objects.requireNonNull(callName, "BlockGivenCallInstr callName is null"); | ||
this.blockGivenSite = new FunctionalCachingCallSite(callName); | ||
} | ||
|
||
public Operand getBlockArg() { | ||
return getOperand1(); | ||
} | ||
|
||
public String getCallName() { | ||
return callName; | ||
} | ||
|
||
@Override | ||
public Instr clone(CloneInfo ii) { | ||
return new BlockGivenCallInstr(ii.getRenamedVariable(result), getBlockArg().cloneForInlining(ii), callName); | ||
} | ||
|
||
public static BlockGivenCallInstr decode(IRReaderDecoder d) { | ||
return new BlockGivenCallInstr(d.decodeVariable(), d.decodeOperand(), d.decodeString()); | ||
} | ||
|
||
@Override | ||
public void encode(IRWriterEncoder e) { | ||
super.encode(e); | ||
e.encode(callName); | ||
} | ||
|
||
@Override | ||
public Object interpret(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp) { | ||
Object blk = getBlockArg().retrieve(context, self, currScope, currDynScope, temp); | ||
|
||
return IRRuntimeHelpers.blockGivenOrCall(context, self, blockGivenSite, blk); | ||
} | ||
|
||
@Override | ||
public void visit(IRVisitor visitor) { | ||
visitor.BlockGivenCallInstr(this); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters