Skip to content

Commit

Permalink
Showing 12 changed files with 121 additions and 127 deletions.
19 changes: 7 additions & 12 deletions core/src/main/java/org/jruby/RubySymbol.java
Original file line number Diff line number Diff line change
@@ -42,12 +42,8 @@
import org.jruby.anno.JRubyMethod;
import org.jruby.ast.util.ArgsUtil;
import org.jruby.compiler.Constantizable;
import org.jruby.RubyEncoding;
import org.jruby.parser.StaticScope;
import org.jruby.runtime.Arity;
import org.jruby.runtime.Binding;
import org.jruby.runtime.Block;
import org.jruby.runtime.Block.Type;
import org.jruby.runtime.BlockBody;
import org.jruby.runtime.CallSite;
import org.jruby.runtime.ClassIndex;
@@ -66,7 +62,6 @@

import java.lang.ref.WeakReference;
import java.util.concurrent.locks.ReentrantLock;
import java.util.Arrays;

import static org.jruby.util.StringSupport.codeLength;
import static org.jruby.util.StringSupport.codePoint;
@@ -480,38 +475,38 @@ private IRubyObject yieldInner(ThreadContext context, RubyArray array, Block blo
}

@Override
public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block, Block blockArg) {
public IRubyObject yield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self, Block blockArg) {
RubyProc.prepareArgs(context, block.type, blockArg.getBody(), args);
return yieldInner(context, context.runtime.newArrayNoCopyLight(args), blockArg);
}

@Override
public IRubyObject yield(ThreadContext context, IRubyObject value, Block block, Block blockArg) {
public IRubyObject yield(ThreadContext context, Block block, IRubyObject value, Block blockArg) {
return yieldInner(context, ArgsUtil.convertToRubyArray(context.runtime, value, false), blockArg);
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject value, Block block) {
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject value) {
return yieldInner(context, ArgsUtil.convertToRubyArray(context.runtime, value, false), Block.NULL_BLOCK);
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block) {
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self) {
return yieldInner(context, context.runtime.newArrayNoCopyLight(args), Block.NULL_BLOCK);
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, Block block) {
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0) {
return site.call(context, arg0, arg0);
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1) {
return site.call(context, arg0, arg0, arg1);
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return site.call(context, arg0, arg0, arg1, arg2);
}

28 changes: 14 additions & 14 deletions core/src/main/java/org/jruby/runtime/Block.java
Original file line number Diff line number Diff line change
@@ -104,11 +104,11 @@ public void setEvalType(EvalType evalType) {
}

public IRubyObject call(ThreadContext context, IRubyObject[] args) {
return body.call(context, args, this);
return body.call(context, this, args);
}

public IRubyObject call(ThreadContext context, IRubyObject[] args, Block blockArg) {
return body.call(context, args, this, blockArg);
return body.call(context, this, args, blockArg);
}

public IRubyObject call(ThreadContext context) {
@@ -121,39 +121,39 @@ public IRubyObject yieldSpecific(ThreadContext context) {
return body.yieldSpecific(context, this);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0) {
return body.call(context, arg0, this);
return body.call(context, this, arg0);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, Block blockArg) {
return body.call(context, arg0, this, blockArg);
return body.call(context, this, arg0, blockArg);
}
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0) {
return body.yieldSpecific(context, arg0, this);
return body.yieldSpecific(context, this, arg0);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1) {
return body.call(context, arg0, arg1, this);
return body.call(context, this, arg0, arg1);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block blockArg) {
return body.call(context, arg0, arg1, this, blockArg);
return body.call(context, this, arg0, arg1, blockArg);
}
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1) {
return body.yieldSpecific(context, arg0, arg1, this);
return body.yieldSpecific(context, this, arg0, arg1);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return body.call(context, arg0, arg1, arg2, this);
return body.call(context, this, arg0, arg1, arg2);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block blockArg) {
return body.call(context, arg0, arg1, arg2, this, blockArg);
return body.call(context, this, arg0, arg1, arg2, blockArg);
}
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return body.yieldSpecific(context, arg0, arg1, arg2, this);
return body.yieldSpecific(context, this, arg0, arg1, arg2);
}

public IRubyObject yield(ThreadContext context, IRubyObject value) {
return body.yield(context, value, this);
return body.yield(context, this, value);
}

public IRubyObject yieldNonArray(ThreadContext context, IRubyObject value, IRubyObject self) {
return body.yield(context, new IRubyObject[] { value }, self, this);
return body.yield(context, this, new IRubyObject[] { value }, self);
}

public IRubyObject yieldArray(ThreadContext context, IRubyObject value, IRubyObject self) {
@@ -163,7 +163,7 @@ public IRubyObject yieldArray(ThreadContext context, IRubyObject value, IRubyObj
} else {
args = value.convertToArray().toJavaArray();
}
return body.yield(context, args, self, this);
return body.yield(context, this, args, self);
}

public Block cloneBlock() {
72 changes: 36 additions & 36 deletions core/src/main/java/org/jruby/runtime/BlockBody.java
Original file line number Diff line number Diff line change
@@ -61,106 +61,106 @@ public void setEvalType(EvalType evalType) {
System.err.println("setEvalType unimplemented in " + this.getClass().getName());
}

public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args) {
args = prepareArgumentsForCall(context, args, block.type);

return yield(context, args, null, block);
return yield(context, block, args, null);
}

public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block, Block blockArg) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args, Block blockArg) {
args = prepareArgumentsForCall(context, args, block.type);

return yield(context, args, null, block, blockArg);
return yield(context, block, args, null, blockArg);
}

public final IRubyObject yield(ThreadContext context, IRubyObject value, Block block) {
return doYield(context, value, block);
public final IRubyObject yield(ThreadContext context, Block block, IRubyObject value) {
return doYield(context, block, value);
}

public final IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block) {
public final IRubyObject yield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self) {
IRubyObject[] preppedValue = RubyProc.prepareArgs(context, block.type, this, args);
return doYield(context, preppedValue, self, block);
return doYield(context, block, preppedValue, self);
}

/**
* Subclass specific yield implementation.
* <p>
* Should not be called directly. Gets called by {@link #yield(ThreadContext, IRubyObject, Block)}
* Should not be called directly. Gets called by {@link #yield(ThreadContext, Block, org.jruby.runtime.builtin.IRubyObject)}
* after ensuring that any common yield logic is taken care of.
*/
protected abstract IRubyObject doYield(ThreadContext context, IRubyObject value, Block block);
protected abstract IRubyObject doYield(ThreadContext context, Block block, IRubyObject value);

/**
* Subclass specific yield implementation.
* <p>
* Should not be called directly. Gets called by {@link #yield(ThreadContext, org.jruby.runtime.builtin.IRubyObject[], org.jruby.runtime.builtin.IRubyObject, Block)}
* Should not be called directly. Gets called by {@link #yield(ThreadContext, Block, org.jruby.runtime.builtin.IRubyObject[], org.jruby.runtime.builtin.IRubyObject)}
* after ensuring that all common yield logic is taken care of.
*/
protected abstract IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block);
protected abstract IRubyObject doYield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self);

// FIXME: This should be unified with the final versions above
// Here to allow incremental replacement. Overriden by subclasses which support it.
public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block, Block blockArg) {
return yield(context, args, self, block);
public IRubyObject yield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self, Block blockArg) {
return yield(context, block, args, self);
}

// FIXME: This should be unified with the final versions above
// Here to allow incremental replacement. Overriden by subclasses which support it.
public IRubyObject yield(ThreadContext context, IRubyObject value, Block block, Block blockArg) {
return yield(context, value, block);
public IRubyObject yield(ThreadContext context, Block block, IRubyObject value, Block blockArg) {
return yield(context, block, value);
}

public IRubyObject call(ThreadContext context, Block block) {
IRubyObject[] args = IRubyObject.NULL_ARRAY;
args = prepareArgumentsForCall(context, args, block.type);

return yield(context, args, null, block);
return yield(context, block, args, null);
}
public IRubyObject call(ThreadContext context, Block block, Block unusedBlock) {
return call(context, block);
}

public IRubyObject yieldSpecific(ThreadContext context, Block block) {
return yield(context, null, block);
return yield(context, block, null);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, Block block) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject arg0) {
IRubyObject[] args = new IRubyObject[] {arg0};
args = prepareArgumentsForCall(context, args, block.type);

return yield(context, args, null, block);
return yield(context, block, args, null);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, Block block, Block unusedBlock) {
return call(context, arg0, block);
public IRubyObject call(ThreadContext context, Block block, IRubyObject arg0, Block unusedBlock) {
return call(context, block, arg0);
}

public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, Block block) {
return yield(context, arg0, block);
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0) {
return yield(context, block, arg0);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1) {
IRubyObject[] args = new IRubyObject[] {arg0, arg1};
args = prepareArgumentsForCall(context, args, block.type);

return yield(context, args, null, block);
return yield(context, block, args, null);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block, Block unusedBlock) {
return call(context, arg0, arg1, block);
public IRubyObject call(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1, Block unusedBlock) {
return call(context, block, arg0, arg1);
}

public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
return yield(context, new IRubyObject[] { arg0, arg1 }, null, block);
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1) {
return yield(context, block, new IRubyObject[] { arg0, arg1 }, null);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
IRubyObject[] args = new IRubyObject[] {arg0, arg1, arg2};
args = prepareArgumentsForCall(context, args, block.type);

return yield(context, args, null, block);
return yield(context, block, args, null);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block, Block unusedBlock) {
return call(context, arg0, arg1, arg2, block);
public IRubyObject call(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block unusedBlock) {
return call(context, block, arg0, arg1, arg2);
}

public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
return yield(context, new IRubyObject[] { arg0, arg1, arg2 }, null, block);
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return yield(context, block, new IRubyObject[] { arg0, arg1, arg2 }, null);
}


10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/runtime/CallBlock.java
Original file line number Diff line number Diff line change
@@ -58,12 +58,12 @@ private CallBlock(Signature signature, BlockCallback callback, ThreadContext con
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args) {
return callback.call(context, args, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block, Block blockArg) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args, Block blockArg) {
return callback.call(context, args, blockArg);
}

@@ -73,17 +73,17 @@ public IRubyObject yieldSpecific(ThreadContext context, Block block) {
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, Block block) {
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0) {
return callback.call(context, new IRubyObject[]{arg0}, Block.NULL_BLOCK);
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject value, Block block) {
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject value) {
return callback.call(context, new IRubyObject[]{value}, Block.NULL_BLOCK);
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block) {
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self) {
return callback.call(context, args, Block.NULL_BLOCK);
}

14 changes: 7 additions & 7 deletions core/src/main/java/org/jruby/runtime/CallBlock19.java
Original file line number Diff line number Diff line change
@@ -63,12 +63,12 @@ public CallBlock19(Signature signature, BlockCallback callback, ThreadContext co
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args) {
return callback.call(context, args, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block, Block blockArg) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args, Block blockArg) {
return callback.call(context, args, blockArg);
}

@@ -78,22 +78,22 @@ public IRubyObject yieldSpecific(ThreadContext context, Block block) {
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, Block block) {
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0) {
return callback.call(context, new IRubyObject[] {arg0}, Block.NULL_BLOCK);
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1) {
return callback.call(context, new IRubyObject[] {arg0, arg1}, Block.NULL_BLOCK);
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return callback.call(context, new IRubyObject[] {arg0, arg1, arg2}, Block.NULL_BLOCK);
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject value, Block block) {
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject value) {
return callback.call(context, new IRubyObject[] {value}, Block.NULL_BLOCK);
}

@@ -106,7 +106,7 @@ protected IRubyObject doYield(ThreadContext context, IRubyObject value, Block bl
* @return
*/
@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block) {
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self) {
return callback.call(context, args, Block.NULL_BLOCK);
}

Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ public ArgumentDescriptor[] getArgumentDescriptors() {
return closure.getArgumentDescriptors();
}

protected IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block, Block blockArg) {
protected IRubyObject commonYieldPath(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self, Block blockArg) {
Binding binding = block.getBinding();

// SSS: Important! Use getStaticScope() to use a copy of the static-scope stored in the block-body.
58 changes: 29 additions & 29 deletions core/src/main/java/org/jruby/runtime/IRBlockBody.java
Original file line number Diff line number Diff line change
@@ -28,60 +28,60 @@ public void setEvalType(EvalType evalType) {

@Override
public IRubyObject call(ThreadContext context, Block block) {
return call(context, IRubyObject.NULL_ARRAY, block, Block.NULL_BLOCK);
return call(context, block, IRubyObject.NULL_ARRAY, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject arg0, Block block) {
return call(context, new IRubyObject[] {arg0}, block, Block.NULL_BLOCK);
public IRubyObject call(ThreadContext context, Block block, IRubyObject arg0) {
return call(context, block, new IRubyObject[] {arg0}, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
return call(context, new IRubyObject[] {arg0, arg1}, block, Block.NULL_BLOCK);
public IRubyObject call(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1) {
return call(context, block, new IRubyObject[] {arg0, arg1}, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
return call(context, new IRubyObject[]{arg0, arg1, arg2}, block, Block.NULL_BLOCK);
public IRubyObject call(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return call(context, block, new IRubyObject[]{arg0, arg1, arg2}, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
return call(context, args, block, Block.NULL_BLOCK);
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args) {
return call(context, block, args, Block.NULL_BLOCK);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block, Block blockArg) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args, Block blockArg) {
if (block.type == Block.Type.LAMBDA) signature.checkArity(context.runtime, args);

return commonYieldPath(context, prepareArgumentsForCall(context, args, block.type), null, block, blockArg);
return commonYieldPath(context, block, prepareArgumentsForCall(context, args, block.type), null, blockArg);
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, Block block) {
IRubyObject[] args = IRubyObject.NULL_ARRAY;
if (block.type == Block.Type.LAMBDA) signature.checkArity(context.runtime, args);

return commonYieldPath(context, args, null, block, Block.NULL_BLOCK);
return commonYieldPath(context, block, args, null, Block.NULL_BLOCK);
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, Block block) {
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0) {
if (arg0 instanceof RubyArray) {
// Unwrap the array arg
IRubyObject[] args = IRRuntimeHelpers.convertValueIntoArgArray(context, arg0, signature.arityValue(), true);

// FIXME: arity error is aginst new args but actual error shows arity of original args.
if (block.type == Block.Type.LAMBDA) signature.checkArity(context.runtime, args);

return commonYieldPath(context, args, null, block, Block.NULL_BLOCK);
return commonYieldPath(context, block, args, null, Block.NULL_BLOCK);
} else {
return yield(context, arg0, block);
return yield(context, block, arg0);
}
}

IRubyObject yieldSpecificMultiArgsCommon(ThreadContext context, IRubyObject[] args, Block block) {
IRubyObject yieldSpecificMultiArgsCommon(ThreadContext context, Block block, IRubyObject[] args) {
int blockArity = getSignature().arityValue();
if (blockArity == 0) {
args = IRubyObject.NULL_ARRAY; // discard args
@@ -91,17 +91,17 @@ IRubyObject yieldSpecificMultiArgsCommon(ThreadContext context, IRubyObject[] ar

if (block.type == Block.Type.LAMBDA) signature.checkArity(context.runtime, args);

return commonYieldPath(context, args, null, block, Block.NULL_BLOCK);
return commonYieldPath(context, block, args, null, Block.NULL_BLOCK);
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
return yieldSpecificMultiArgsCommon(context, new IRubyObject[]{arg0, arg1}, block);
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1) {
return yieldSpecificMultiArgsCommon(context, block, new IRubyObject[]{arg0, arg1});
}

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
return yieldSpecificMultiArgsCommon(context, new IRubyObject[]{arg0, arg1, arg2}, block);
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return yieldSpecificMultiArgsCommon(context, block, new IRubyObject[]{arg0, arg1, arg2});
}

private IRubyObject[] toAry(ThreadContext context, IRubyObject value) {
@@ -116,7 +116,7 @@ private IRubyObject[] toAry(ThreadContext context, IRubyObject value) {
return ((RubyArray)val0).toJavaArray();
}

protected IRubyObject doYieldLambda(ThreadContext context, IRubyObject value, Block block) {
protected IRubyObject doYieldLambda(ThreadContext context, Block block, IRubyObject value) {
// Lambda does not splat arrays even if a rest arg is present when it wants a single parameter filled.
IRubyObject[] args;

@@ -130,12 +130,12 @@ protected IRubyObject doYieldLambda(ThreadContext context, IRubyObject value, Bl

signature.checkArity(context.runtime, args);

return commonYieldPath(context, args, null, block, Block.NULL_BLOCK);
return commonYieldPath(context, block, args, null, Block.NULL_BLOCK);
}

@Override
public IRubyObject doYield(ThreadContext context, IRubyObject value, Block block) {
if (block.type == Block.Type.LAMBDA) return doYieldLambda(context, value, block);
public IRubyObject doYield(ThreadContext context, Block block, IRubyObject value) {
if (block.type == Block.Type.LAMBDA) return doYieldLambda(context, block, value);

int blockArity = getSignature().arityValue();

@@ -148,14 +148,14 @@ public IRubyObject doYield(ThreadContext context, IRubyObject value, Block block
args = toAry(context, value);
}

return commonYieldPath(context, args, null, block, Block.NULL_BLOCK);
return commonYieldPath(context, block, args, null, Block.NULL_BLOCK);
}

@Override
public IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block) {
public IRubyObject doYield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self) {
if (block.type == Block.Type.LAMBDA) signature.checkArity(context.runtime, args);

return commonYieldPath(context, args, self, block, Block.NULL_BLOCK);
return commonYieldPath(context, block, args, self, Block.NULL_BLOCK);
}

protected IRubyObject useBindingSelf(Binding binding) {
@@ -165,7 +165,7 @@ protected IRubyObject useBindingSelf(Binding binding) {
return self;
}

protected abstract IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block, Block blockArg);
protected abstract IRubyObject commonYieldPath(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self, Block blockArg);

public IRClosure getScope() {
return closure;
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jruby.runtime;

import org.jruby.EvalType;
import org.jruby.RubyInstanceConfig;
import org.jruby.RubyModule;
import org.jruby.compiler.Compilable;
import org.jruby.ir.IRClosure;
@@ -77,7 +76,7 @@ public String getName() {
return null;
}

protected IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block, Block blockArg) {
protected IRubyObject commonYieldPath(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self, Block blockArg) {
Binding binding = block.getBinding();
if (callCount >= 0) promoteToFullBuild(context);

12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/runtime/JavaInternalBlockBody.java
Original file line number Diff line number Diff line change
@@ -42,24 +42,24 @@ private void threadCheck(ThreadContext yieldingContext) {
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
return yield(context, args, null, block);
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args) {
return yield(context, block, args, null);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block b, Block blockArg) {
return yield(context, args, null, b, blockArg);
public IRubyObject call(ThreadContext context, Block b, IRubyObject[] args, Block blockArg) {
return yield(context, b, args, null, blockArg);
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject value, Block block) {
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject value) {
threadCheck(context);

return yield(context, new IRubyObject[] { value });
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block) {
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self) {
threadCheck(context);

return yield(context, args);
8 changes: 4 additions & 4 deletions core/src/main/java/org/jruby/runtime/MethodBlockBody.java
Original file line number Diff line number Diff line change
@@ -47,27 +47,27 @@ public static Block createMethodBlock(MethodBlockBody body) {
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args) {
args = prepareArgumentsForCall(context, args, block.type);

return method.call(context, receiver, originModule, originName, args);
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block, Block blockArg) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args, Block blockArg) {
args = prepareArgumentsForCall(context, args, block.type);

return method.call(context, receiver, originModule, originName, args, blockArg);
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject value, Block block) {
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject value) {
IRubyObject[] realArgs = Helpers.restructureBlockArgs19(value, getSignature(), block.type, false, false);
return method.call(context, receiver, originModule, originName, realArgs, Block.NULL_BLOCK);
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block) {
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self) {
return method.call(context, receiver, originModule, originName, args, Block.NULL_BLOCK);
}

Original file line number Diff line number Diff line change
@@ -89,14 +89,14 @@ public String getName() {
return closure.getName();
}

protected IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block, Block blockArg) {
protected IRubyObject commonYieldPath(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self, Block blockArg) {
Binding binding = block.getBinding();
if (callCount >= 0) promoteToFullBuild(context);

CompiledIRBlockBody jittedBody = this.jittedBody;

if (jittedBody != null) {
return jittedBody.commonYieldPath(context, args, self, block, blockArg);
return jittedBody.commonYieldPath(context, block, args, self, blockArg);
}

// SSS: Important! Use getStaticScope() to use a copy of the static-scope stored in the block-body.
18 changes: 9 additions & 9 deletions core/src/main/java/org/jruby/runtime/NullBlockBody.java
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ public NullBlockBody() {
}

@Override
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject[] args) {
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.NOREASON, context.runtime.newArrayNoCopy(args), "yield called out of block");
}

@@ -23,37 +23,37 @@ public IRubyObject yieldSpecific(ThreadContext context, Block block) {
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.NOREASON, context.runtime.getNil(), "yield called out of block");
}
@Override
public IRubyObject call(ThreadContext context, IRubyObject arg0, Block block) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject arg0) {
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.NOREASON, context.runtime.newArrayNoCopy(new IRubyObject[]{arg0}), "yield called out of block");
}
@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, Block block) {
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0) {
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.NOREASON, context.runtime.getNil(), "yield called out of block");
}
@Override
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1) {
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.NOREASON, context.runtime.newArrayNoCopy(new IRubyObject[]{arg0, arg1}), "yield called out of block");
}
@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1) {
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.NOREASON, context.runtime.getNil(), "yield called out of block");
}
@Override
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
public IRubyObject call(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.NOREASON, context.runtime.newArrayNoCopy(new IRubyObject[]{arg0, arg1, arg2}), "yield called out of block");
}
@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
public IRubyObject yieldSpecific(ThreadContext context, Block block, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.NOREASON, context.runtime.getNil(), "yield called out of block");
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject value, Block block) {
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject value) {
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.NOREASON, value, "yield called out of block");
}

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block) {
protected IRubyObject doYield(ThreadContext context, Block block, IRubyObject[] args, IRubyObject self) {
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.NOREASON, args[0], "yield called out of block");
}

6 comments on commit 6bb6149

@kares
Copy link
Member

@kares kares commented on 6bb6149 Nov 25, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might break stuff - such as Java extensions that do create blocks - using a home-grown block-body impl

@subbuss
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the last 5-6 commits, I made sure that the block api itself is unchanged. Ideally, extensions shouldn't really be messing around with JRuby internals like BlockBody, but I am curious to find out if there are extensions out there that are doing this.

In the coming months, I am going to make a fair bit of changes to the BlockBody interface (and hopefully eventually get rid of that class altogether). More code will migrate into IR land via instructions so they can be analyzed and optimized away. There is too much unnecessary block-invocation overhead that I want to get rid of.

So it is good to surface any of these extensions now and have them migrate to using the Block API only.
If really necessary, we can deprecate the old signatures and add them back temporarily for backward compatibility.

@enebo
Copy link
Member

@enebo enebo commented on 6bb6149 Nov 25, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kares if you can find an example of someone making their own blockbody or even how you might try and search for that I would love to see it in the wild. Worst-case is we add back the deprecations (at least for now).

@kares
Copy link
Member

@kares kares commented on 6bb6149 Nov 25, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm, can't find what I though - but I recall I've seen it ... just can't figure where (feel free to ignore for now).
there's a piece in JRuby-Rack but that should be fine as it's using the JavaInternalBlockBody as a base: https://github.com/jruby/jruby-rack/blob/710c1a4cbde684f1d0bec5907ba3071d51de0a96/src/main/java/org/jruby/rack/ext/Response.java#L288-L294

@kares
Copy link
Member

@kares kares commented on 6bb6149 Nov 25, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems it was my own 💩 old experiment with an extension that never got out ... searched github and did not find anything that would break. looking forward for the refactorings. sorry for the false alarm, but knowing the API it's hard to imagine creating a block on the J side without running into some BlockBody sub-classing (which is probably a very rare use-case).

@enebo
Copy link
Member

@enebo enebo commented on 6bb6149 Dec 1, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kares Thanks for looking. I suspect custom BlockBody is only going to come from core contributors if that and we probably have enough pull to get them to change or version based on newer design.

Sorry, something went wrong.

Please sign in to comment.