Skip to content

Commit

Permalink
Rename arguments in blockBody signatures for easier understanding
Browse files Browse the repository at this point in the history
* block used to be the block argument passed in to surrounding
  scopes. It is now renamed blockArg for clarity.

* b used to be the block that was being executed. It is now
  renamed block for clarity.
subbuss committed Nov 25, 2015
1 parent f919454 commit 5e13527
Showing 13 changed files with 166 additions and 162 deletions.
25 changes: 12 additions & 13 deletions core/src/main/java/org/jruby/RubySymbol.java
Original file line number Diff line number Diff line change
@@ -469,50 +469,49 @@ public IRubyObject to_proc(ThreadContext context) {
StaticScope scope = context.runtime.getStaticScopeFactory().getDummyScope();
final CallSite site = new FunctionalCachingCallSite(symbol);
BlockBody body = new ContextAwareBlockBody(scope, Signature.OPTIONAL) {
private IRubyObject yieldInner(ThreadContext context, RubyArray array, Block block) {
private IRubyObject yieldInner(ThreadContext context, RubyArray array, Block blockArg) {
if (array.isEmpty()) {
throw context.runtime.newArgumentError("no receiver given");
}

IRubyObject self = array.shift(context);

return site.call(context, self, self, array.toJavaArray(), block);
return site.call(context, self, self, array.toJavaArray(), blockArg);
}

@Override
public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block b, Block block) {
RubyProc.prepareArgs(context, b.type, block.getBody(), args);
return yieldInner(context, context.runtime.newArrayNoCopyLight(args), block);
public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block, 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 b, Block block) {
return yieldInner(context, ArgsUtil.convertToRubyArray(context.runtime, value, false), block);
public IRubyObject yield(ThreadContext context, IRubyObject value, Block block, Block blockArg) {
return yieldInner(context, ArgsUtil.convertToRubyArray(context.runtime, value, false), blockArg);
}

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

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

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

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

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

25 changes: 15 additions & 10 deletions core/src/main/java/org/jruby/runtime/Block.java
Original file line number Diff line number Diff line change
@@ -78,6 +78,10 @@ public enum Type {

/** What block to use for determining escape; defaults to this */
private Block escapeBlock = this;

private EvalType evalType;

private boolean hasExplicitCallProtocol = false;

/**
* All Block variables should either refer to a real block or this NULL_BLOCK.
@@ -95,49 +99,50 @@ public Block(BlockBody body) {
}

public void setEvalType(EvalType evalType) {
this.evalType = evalType;
body.setEvalType(evalType);
}

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

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

public IRubyObject call(ThreadContext context) {
return body.call(context, this);
}
public IRubyObject call(ThreadContext context, Block block) {
return body.call(context, this, block);
public IRubyObject call(ThreadContext context, Block blockArg) {
return body.call(context, this, blockArg);
}
public IRubyObject yieldSpecific(ThreadContext context) {
return body.yieldSpecific(context, this);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0) {
return body.call(context, arg0, this);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, Block block) {
return body.call(context, arg0, this, block);
public IRubyObject call(ThreadContext context, IRubyObject arg0, Block blockArg) {
return body.call(context, arg0, this, blockArg);
}
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0) {
return body.yieldSpecific(context, arg0, this);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1) {
return body.call(context, arg0, arg1, this);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
return body.call(context, arg0, arg1, this, block);
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block blockArg) {
return body.call(context, arg0, arg1, this, blockArg);
}
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1) {
return body.yieldSpecific(context, arg0, arg1, this);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return body.call(context, arg0, arg1, arg2, this);
}
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
return body.call(context, arg0, arg1, arg2, this, block);
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block blockArg) {
return body.call(context, arg0, arg1, arg2, this, blockArg);
}
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2) {
return body.yieldSpecific(context, arg0, arg1, arg2, this);
90 changes: 45 additions & 45 deletions core/src/main/java/org/jruby/runtime/BlockBody.java
Original file line number Diff line number Diff line change
@@ -61,25 +61,25 @@ public void setEvalType(EvalType evalType) {
System.err.println("setEvalType unimplemented in " + this.getClass().getName());
}

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

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

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

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

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

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

/**
@@ -88,79 +88,79 @@ public final IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyO
* Should not be called directly. Gets called by {@link #yield(ThreadContext, IRubyObject, Block)}
* after ensuring that any common yield logic is taken care of.
*/
protected abstract IRubyObject doYield(ThreadContext context, IRubyObject value, Block b);
protected abstract IRubyObject doYield(ThreadContext context, IRubyObject value, Block block);

/**
* 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)}
* after ensuring that all common yield logic is taken care of.
*/
protected abstract IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block b);
protected abstract IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block);

// 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 b, Block block) {
return yield(context, args, self, b);
public IRubyObject yield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block, Block blockArg) {
return yield(context, args, self, block);
}

// 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 b, Block block) {
return yield(context, value, b);
public IRubyObject yield(ThreadContext context, IRubyObject value, Block block, Block blockArg) {
return yield(context, value, block);
}

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/runtime/CompiledIRBlockBody.java
Original file line number Diff line number Diff line change
@@ -31,8 +31,8 @@ public ArgumentDescriptor[] getArgumentDescriptors() {
return closure.getArgumentDescriptors();
}

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

// SSS: Important! Use getStaticScope() to use a copy of the static-scope stored in the block-body.
// Do not use 'closure.getStaticScope()' -- that returns the original copy of the static scope.
@@ -67,7 +67,7 @@ protected IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args,
if (usesKwargs) IRRuntimeHelpers.frobnicateKwargsArgument(context, getSignature().required(), args);

try {
return (IRubyObject)handle.invokeExact(context, getStaticScope(), self, args, block, binding.getMethod(), b.type);
return (IRubyObject)handle.invokeExact(context, getStaticScope(), self, args, blockArg, binding.getMethod(), block.type);
} catch (Throwable t) {
Helpers.throwException(t);
return null; // not reached
10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/runtime/ContextAwareBlockBody.java
Original file line number Diff line number Diff line change
@@ -20,13 +20,13 @@ public ContextAwareBlockBody(StaticScope scope, Arity arity, int argumentType) {
this(scope, Signature.from(arity));
}

protected Frame pre(ThreadContext context, Block b) {
return context.preYieldSpecificBlock(b.getBinding(), scope);
protected Frame pre(ThreadContext context, Block block) {
return context.preYieldSpecificBlock(block.getBinding(), scope);
}

protected void post(ThreadContext context, Block b, Visibility vis, Frame lastFrame) {
b.getBinding().getFrame().setVisibility(vis);
context.postYield(b.getBinding(), lastFrame);
protected void post(ThreadContext context, Block block, Visibility vis, Frame lastFrame) {
block.getBinding().getFrame().setVisibility(vis);
context.postYield(block.getBinding(), lastFrame);
}

public StaticScope getStaticScope() {
72 changes: 36 additions & 36 deletions core/src/main/java/org/jruby/runtime/IRBlockBody.java
Original file line number Diff line number Diff line change
@@ -27,81 +27,81 @@ public void setEvalType(EvalType evalType) {
}

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

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

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

@Override
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block b) {
return call(context, new IRubyObject[]{arg0, arg1, arg2}, b, Block.NULL_BLOCK);
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);
}

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

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

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

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

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

@Override
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, Block b) {
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, Block block) {
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 (b.type == Block.Type.LAMBDA) signature.checkArity(context.runtime, args);
if (block.type == Block.Type.LAMBDA) signature.checkArity(context.runtime, args);

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

IRubyObject yieldSpecificMultiArgsCommon(ThreadContext context, IRubyObject[] args, Block b) {
IRubyObject yieldSpecificMultiArgsCommon(ThreadContext context, IRubyObject[] args, Block block) {
int blockArity = getSignature().arityValue();
if (blockArity == 0) {
args = IRubyObject.NULL_ARRAY; // discard args
} else if (blockArity == 1) {
args = new IRubyObject[] { RubyArray.newArrayNoCopy(context.runtime, args) };
}

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

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

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

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

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 b) {
protected IRubyObject doYieldLambda(ThreadContext context, IRubyObject value, Block block) {
// 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, b, Block.NULL_BLOCK);
return commonYieldPath(context, args, null, block, Block.NULL_BLOCK);
}

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

int blockArity = getSignature().arityValue();

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

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

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

return commonYieldPath(context, args, self, b, Block.NULL_BLOCK);
return commonYieldPath(context, args, self, block, 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 b, Block block);
protected abstract IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block, Block blockArg);

public IRClosure getScope() {
return closure;
Original file line number Diff line number Diff line change
@@ -77,8 +77,8 @@ public String getName() {
return null;
}

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

// SSS: Important! Use getStaticScope() to use a copy of the static-scope stored in the block-body.
@@ -106,7 +106,7 @@ protected IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args,
DynamicScope actualScope = binding.getDynamicScope();
if (ic.pushNewDynScope()) {
actualScope = DynamicScope.newDynamicScope(getStaticScope(), actualScope, this.evalType.get());
if (b.type == Block.Type.LAMBDA) actualScope.setLambda(true);
if (block.type == Block.Type.LAMBDA) actualScope.setLambda(true);
context.pushScope(actualScope);
} else if (ic.reuseParentDynScope()) {
// Reuse! We can avoid the push only if surrounding vars aren't referenced!
@@ -115,7 +115,7 @@ protected IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args,
this.evalType.set(EvalType.NONE);

try {
return Interpreter.INTERPRET_BLOCK(context, self, ic, args, binding.getMethod(), block, b.type);
return Interpreter.INTERPRET_BLOCK(context, self, ic, args, binding.getMethod(), blockArg, block.type);
}
finally {
// IMPORTANT: Do not clear eval-type in case this is reused in bindings!
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 b) {
return yield(context, args, null, b);
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
return yield(context, args, null, block);
}

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

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

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

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

return yield(context, args);
16 changes: 8 additions & 8 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 b) {
args = prepareArgumentsForCall(context, args, b.type);
public IRubyObject call(ThreadContext context, IRubyObject[] args, Block block) {
args = prepareArgumentsForCall(context, args, block.type);

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

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

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

@Override
protected IRubyObject doYield(ThreadContext context, IRubyObject value, Block b) {
IRubyObject[] realArgs = Helpers.restructureBlockArgs19(value, getSignature(), b.type, false, false);
protected IRubyObject doYield(ThreadContext context, IRubyObject value, Block block) {
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 b) {
protected IRubyObject doYield(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block) {
return method.call(context, receiver, originModule, originName, args, Block.NULL_BLOCK);
}

10 changes: 5 additions & 5 deletions core/src/main/java/org/jruby/runtime/MixedModeIRBlockBody.java
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 b, Block block) {
Binding binding = b.getBinding();
protected IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args, IRubyObject self, Block block, Block blockArg) {
Binding binding = block.getBinding();
if (callCount >= 0) promoteToFullBuild(context);

CompiledIRBlockBody jittedBody = this.jittedBody;

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

// SSS: Important! Use getStaticScope() to use a copy of the static-scope stored in the block-body.
@@ -124,7 +124,7 @@ protected IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args,
DynamicScope actualScope = binding.getDynamicScope();
if (ic.pushNewDynScope()) {
actualScope = DynamicScope.newDynamicScope(getStaticScope(), actualScope, this.evalType.get());
if (b.type == Block.Type.LAMBDA) actualScope.setLambda(true);
if (block.type == Block.Type.LAMBDA) actualScope.setLambda(true);
context.pushScope(actualScope);
} else if (ic.reuseParentDynScope()) {
// Reuse! We can avoid the push only if surrounding vars aren't referenced!
@@ -133,7 +133,7 @@ protected IRubyObject commonYieldPath(ThreadContext context, IRubyObject[] args,
this.evalType.set(EvalType.NONE);

try {
return Interpreter.INTERPRET_BLOCK(context, self, ic, args, binding.getMethod(), block, b.type);
return Interpreter.INTERPRET_BLOCK(context, self, ic, args, binding.getMethod(), blockArg, block.type);
}
finally {
// IMPORTANT: Do not clear eval-type in case this is reused in bindings!
22 changes: 11 additions & 11 deletions core/src/main/java/org/jruby/runtime/NullBlockBody.java
Original file line number Diff line number Diff line change
@@ -10,50 +10,50 @@ public NullBlockBody() {
}

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

@Override
public IRubyObject call(ThreadContext context, Block b) {
public IRubyObject call(ThreadContext context, Block block) {
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.NOREASON, context.runtime.newArrayNoCopy(IRubyObject.NULL_ARRAY), "yield called out of block");
}
@Override
public IRubyObject yieldSpecific(ThreadContext context, Block b) {
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 b) {
public IRubyObject call(ThreadContext context, IRubyObject arg0, Block block) {
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 b) {
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, 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, IRubyObject arg1, Block b) {
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, Block block) {
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 b) {
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, 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, IRubyObject arg1, IRubyObject arg2, Block b) {
public IRubyObject call(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
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 b) {
public IRubyObject yieldSpecific(ThreadContext context, IRubyObject arg0, IRubyObject arg1, IRubyObject arg2, Block block) {
throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.NOREASON, context.runtime.getNil(), "yield called out of block");
}

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

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

0 comments on commit 5e13527

Please sign in to comment.