Skip to content

Commit

Permalink
[IR] blocks passed to yield & calls are always NORMAL blocks no matte…
Browse files Browse the repository at this point in the history
…r where they are created
  • Loading branch information
subbuss committed Aug 17, 2011
1 parent 2da866f commit 373abc5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
15 changes: 10 additions & 5 deletions src/org/jruby/compiler/ir/instructions/CallInstr.java
Expand Up @@ -343,17 +343,22 @@ protected Block prepareBlock(InterpreterContext interp, ThreadContext context, I

Object value = closure.retrieve(interp, context, self);

Block b = null;
if (value instanceof Block)
return (Block)value;
b = (Block)value;
else if (value instanceof RubyProc)
return ((RubyProc) value).getBlock();
b = ((RubyProc) value).getBlock();
else if (value instanceof RubyMethod)
return ((RubyProc)((RubyMethod)value).to_proc(context, null)).getBlock();
b = ((RubyProc)((RubyMethod)value).to_proc(context, null)).getBlock();
else if ((value instanceof IRubyObject) && ((IRubyObject)value).isNil())
return Block.NULL_BLOCK;
b = Block.NULL_BLOCK;
else if (value instanceof IRubyObject)
return ((RubyProc)TypeConverter.convertToType((IRubyObject)value, context.getRuntime().getProc(), "to_proc", true)).getBlock();
b = ((RubyProc)TypeConverter.convertToType((IRubyObject)value, context.getRuntime().getProc(), "to_proc", true)).getBlock();
else
throw new RuntimeException("Unhandled case in CallInstr:prepareBlock. Got block arg: " + value);

// Blocks passed in through calls are always normal blocks, no matter where they came from
b.type = Block.Type.NORMAL;
return b;
}
}
18 changes: 8 additions & 10 deletions src/org/jruby/compiler/ir/instructions/YieldInstr.java
Expand Up @@ -40,20 +40,18 @@ public Label interpret(InterpreterContext interp, ThreadContext context, IRubyOb
Object blk = (Object)block.retrieve(interp, context, self);
if (blk instanceof RubyProc) blk = ((RubyProc)blk).getBlock();
if (blk instanceof RubyNil) blk = Block.NULL_BLOCK;
// Blocks that get yielded are always normal
Block b = (Block)blk;
b.type = Block.Type.NORMAL;
if (yieldArg == null) {
resultValue = ((Block)blk).yieldSpecific(context);
resultValue = b.yieldSpecific(context);
} else {
IRubyObject yieldVal = (IRubyObject)yieldArg.retrieve(interp, context, self);
if ((yieldArg instanceof Splat) || (yieldArg instanceof CompoundArray)) {
if (wrapIntoArray) {
resultValue = ((Block)blk).yield(context, yieldVal);
}
else {
resultValue = ((Block)blk).yieldArray(context, yieldVal, null, null);
}
}
else {
resultValue = ((Block)blk).yield(context, yieldVal);
if (wrapIntoArray) resultValue = b.yield(context, yieldVal);
else resultValue = b.yieldArray(context, yieldVal, null, null);
} else {
resultValue = b.yield(context, yieldVal);
}
}
getResult().store(interp, context, self, resultValue);
Expand Down

0 comments on commit 373abc5

Please sign in to comment.