Skip to content

Commit

Permalink
Remove special block type parameter from most utility methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
headius committed Jul 10, 2018
1 parent fbd727f commit 5ff5a0e
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 35 deletions.
Expand Up @@ -66,8 +66,8 @@ public static CheckArityInstr decode(IRReaderDecoder d) {
return new CheckArityInstr(d.decodeInt(), d.decodeInt(), d.decodeBoolean(), d.decodeBoolean(), d.decodeInt());
}

public void checkArity(ThreadContext context, StaticScope scope, Object[] args, Block.Type blockType) {
IRRuntimeHelpers.checkArity(context, scope, args, required, opt, rest, receivesKeywords, restKey, blockType);
public void checkArity(ThreadContext context, StaticScope scope, Object[] args, Block block) {
IRRuntimeHelpers.checkArity(context, scope, args, required, opt, rest, receivesKeywords, restKey, block);
}

@Override
Expand Down
Expand Up @@ -57,8 +57,8 @@ public String[] toStringNonOperandArgs() {
return new String[] { "definedWithinMethod: " + definedWithinMethod};
}

public void check(ThreadContext context, DynamicScope dynamicScope, Block.Type blockType) {
IRRuntimeHelpers.checkForLJE(context, dynamicScope, definedWithinMethod, blockType);
public void check(ThreadContext context, DynamicScope dynamicScope, Block block) {
IRRuntimeHelpers.checkForLJE(context, dynamicScope, definedWithinMethod, block);
}

@Override
Expand Down
Expand Up @@ -88,7 +88,7 @@ public String[] toStringNonOperandArgs() {
return new String[] { "method: " + helperMethod};
}

public IRubyObject callHelper(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block.Type blockType) {
public IRubyObject callHelper(ThreadContext context, StaticScope currScope, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block block) {
Operand[] operands = getOperands();

if (helperMethod == Methods.IS_DEFINED_BACKREF) {
Expand All @@ -114,11 +114,11 @@ public IRubyObject callHelper(ThreadContext context, StaticScope currScope, Dyna

switch (helperMethod) {
case HANDLE_PROPAGATED_BREAK:
return IRRuntimeHelpers.handlePropagatedBreak(context, currDynScope, arg1, blockType);
return IRRuntimeHelpers.handlePropagatedBreak(context, currDynScope, arg1);
case HANDLE_NONLOCAL_RETURN:
return IRRuntimeHelpers.handleNonlocalReturn(currScope, currDynScope, arg1, blockType);
return IRRuntimeHelpers.handleNonlocalReturn(currDynScope, arg1);
case HANDLE_BREAK_AND_RETURNS_IN_LAMBDA:
return IRRuntimeHelpers.handleBreakAndReturnsInLambdas(context, currScope, currDynScope, arg1, blockType);
return IRRuntimeHelpers.handleBreakAndReturnsInLambdas(context, currDynScope, arg1, block);
case IS_DEFINED_CALL:
return IRRuntimeHelpers.isDefinedCall(
context,
Expand Down
Expand Up @@ -405,7 +405,7 @@ protected static void processBookKeepingOp(ThreadContext context, Block block, I
context.callThreadPoll();
break;
case CHECK_ARITY:
((CheckArityInstr) instr).checkArity(context, currScope, args, block == null ? null : block.type);
((CheckArityInstr) instr).checkArity(context, currScope, args, block);
break;
case LINE_NUM:
context.setLine(((LineNumberInstr)instr).lineNumber);
Expand Down Expand Up @@ -461,7 +461,6 @@ protected static IRubyObject processReturnOp(ThreadContext context, Block block,
protected static void processOtherOp(ThreadContext context, Block block, Instr instr, Operation operation, DynamicScope currDynScope,
StaticScope currScope, Object[] temp, IRubyObject self,
double[] floats, long[] fixnums, boolean[] booleans) {
Block.Type blockType = block == null ? null : block.type;
Object result;
switch(operation) {
case RECV_SELF:
Expand Down Expand Up @@ -495,12 +494,12 @@ protected static void processOtherOp(ThreadContext context, Block block, Instr i
case RUNTIME_HELPER: {
RuntimeHelperCall rhc = (RuntimeHelperCall)instr;
setResult(temp, currDynScope, rhc.getResult(),
rhc.callHelper(context, currScope, currDynScope, self, temp, blockType));
rhc.callHelper(context, currScope, currDynScope, self, temp, block));
break;
}

case CHECK_FOR_LJE:
((CheckForLJEInstr) instr).check(context, currDynScope, blockType);
((CheckForLJEInstr) instr).check(context, currDynScope, block);
break;

case BOX_FLOAT: {
Expand Down
Expand Up @@ -130,7 +130,6 @@ public IRubyObject interpret(ThreadContext context, Block block, IRubyObject sel

protected static void processOtherOp(ThreadContext context, Block block, Instr instr, Operation operation, DynamicScope currDynScope,
StaticScope currScope, Object[] temp, IRubyObject self) {
Block.Type blockType = block == null ? null : block.type;
switch(operation) {
case RECV_SELF:
break;
Expand Down Expand Up @@ -165,11 +164,11 @@ protected static void processOtherOp(ThreadContext context, Block block, Instr i
case RUNTIME_HELPER: {
RuntimeHelperCall rhc = (RuntimeHelperCall)instr;
setResult(temp, currDynScope, rhc.getResult(),
rhc.callHelper(context, currScope, currDynScope, self, temp, blockType));
rhc.callHelper(context, currScope, currDynScope, self, temp, block));
break;
}
case CHECK_FOR_LJE:
((CheckForLJEInstr) instr).check(context, currDynScope, blockType);
((CheckForLJEInstr) instr).check(context, currDynScope, block);
break;
case LOAD_FRAME_CLOSURE:
setResult(temp, currDynScope, instr, context.getFrameBlock());
Expand Down
16 changes: 8 additions & 8 deletions core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
Expand Up @@ -115,8 +115,8 @@ public static boolean inProc(Block.Type blockType) {

// FIXME: ENEBO: If we inline this instr then dynScope will be for the inlined dynscope and that scope could be many things.
// CheckForLJEInstr.clone should convert this as appropriate based on what it is being inlined into.
public static void checkForLJE(ThreadContext context, DynamicScope dynScope, boolean definedWithinMethod, Block.Type blockType) {
if (inLambda(blockType)) return; // break/return in lambda unconditionally a return.
public static void checkForLJE(ThreadContext context, DynamicScope dynScope, boolean definedWithinMethod, Block block) {
if (inLambda(block.type)) return; // break/return in lambda unconditionally a return.

dynScope = getContainingMethodsDynamicScope(dynScope);
StaticScope staticScope = dynScope.getStaticScope();
Expand Down Expand Up @@ -167,7 +167,7 @@ private static DynamicScope getContainingMethodOrLambdasDynamicScope(DynamicScop
}

@JIT
public static IRubyObject handleNonlocalReturn(StaticScope scope, DynamicScope dynScope, Object rjExc, Block.Type blockType) throws RuntimeException {
public static IRubyObject handleNonlocalReturn(DynamicScope dynScope, Object rjExc) throws RuntimeException {
if (!(rjExc instanceof IRReturnJump)) {
Helpers.throwException((Throwable)rjExc);
return null; // Unreachable
Expand Down Expand Up @@ -220,12 +220,12 @@ private static boolean inReturnScope(Block.Type blockType, IRReturnJump exceptio
}

@JIT
public static IRubyObject handleBreakAndReturnsInLambdas(ThreadContext context, StaticScope scope, DynamicScope dynScope, Object exc, Block.Type blockType) throws RuntimeException {
public static IRubyObject handleBreakAndReturnsInLambdas(ThreadContext context, DynamicScope dynScope, Object exc, Block block) throws RuntimeException {
if (exc instanceof IRWrappedLambdaReturnValue) {
// Wrap the return value in an exception object and push it through the nonlocal return exception
// paths so that ensures are run, frames/scopes are popped from runtime stacks, etc.
return ((IRWrappedLambdaReturnValue) exc).returnValue;
} else if (exc instanceof IRReturnJump && inReturnScope(blockType, (IRReturnJump) exc, dynScope)) {
} else if (exc instanceof IRReturnJump && inReturnScope(block.type, (IRReturnJump) exc, dynScope)) {
if (isDebug()) System.out.println("---> Non-local Return reached target in scope: " + dynScope);
return (IRubyObject) ((IRReturnJump) exc).returnValue;
} else {
Expand All @@ -251,7 +251,7 @@ public static IRubyObject returnOrRethrowSavedException(ThreadContext context, I
}

@JIT
public static IRubyObject handlePropagatedBreak(ThreadContext context, DynamicScope dynScope, Object bjExc, Block.Type blockType) {
public static IRubyObject handlePropagatedBreak(ThreadContext context, DynamicScope dynScope, Object bjExc) {
if (!(bjExc instanceof IRBreakJump)) {
Helpers.throwException((Throwable)bjExc);
return null; // Unreachable
Expand Down Expand Up @@ -521,7 +521,7 @@ public static Block getBlockFromObject(ThreadContext context, Object value) {
}

public static void checkArity(ThreadContext context, StaticScope scope, Object[] args, int required, int opt, boolean rest,
boolean receivesKwargs, int restKey, Block.Type blockType) {
boolean receivesKwargs, int restKey, Block block) {
int argsLength = args.length;
RubyHash keywordArgs = extractKwargsHash(args, required, receivesKwargs);

Expand All @@ -530,7 +530,7 @@ public static void checkArity(ThreadContext context, StaticScope scope, Object[]
// keyword arguments value is not used for arity checking.
if (keywordArgs != null) argsLength -= 1;

if ((blockType == null || blockType.checkArity) && (argsLength < required || (!rest && argsLength > (required + opt)))) {
if ((block == null || block.type.checkArity) && (argsLength < required || (!rest && argsLength > (required + opt)))) {
Arity.raiseArgumentError(context.runtime, argsLength, required, required + opt);
}
}
Expand Down
20 changes: 8 additions & 12 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Expand Up @@ -1158,17 +1158,17 @@ private void checkArity(int required, int opt, boolean rest, boolean receivesKey
jvmAdapter().ldc(rest);
jvmAdapter().ldc(receivesKeywords);
jvmAdapter().ldc(restKey);
jvmMethod().loadBlockType();
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "checkArity", sig(void.class, ThreadContext.class, StaticScope.class, Object[].class, int.class, int.class, boolean.class, boolean.class, int.class, Block.Type.class));
jvmMethod().loadBlock();
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "checkArity", sig(void.class, ThreadContext.class, StaticScope.class, Object[].class, int.class, int.class, boolean.class, boolean.class, int.class, Block.class));
}

@Override
public void CheckForLJEInstr(CheckForLJEInstr checkForljeinstr) {
jvmMethod().loadContext();
jvmLoadLocal(DYNAMIC_SCOPE);
jvmAdapter().ldc(checkForljeinstr.isDefinedWithinMethod());
jvmMethod().loadBlockType();
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "checkForLJE", sig(void.class, ThreadContext.class, DynamicScope.class, boolean.class, Block.Type.class));
jvmMethod().loadBlock();
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "checkForLJE", sig(void.class, ThreadContext.class, DynamicScope.class, boolean.class, Block.class));
}

@Override
Expand Down Expand Up @@ -1977,25 +1977,21 @@ public void RuntimeHelperCall(RuntimeHelperCall runtimehelpercall) {
jvmMethod().loadContext();
jvmLoadLocal(DYNAMIC_SCOPE);
visit(runtimehelpercall.getArgs()[0]);
jvmMethod().loadBlockType();
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "handlePropagatedBreak", sig(IRubyObject.class, ThreadContext.class, DynamicScope.class, Object.class, Block.Type.class));
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "handlePropagatedBreak", sig(IRubyObject.class, ThreadContext.class, DynamicScope.class, Object.class));
jvmStoreLocal(runtimehelpercall.getResult());
break;
case HANDLE_NONLOCAL_RETURN:
jvmMethod().loadStaticScope();
jvmLoadLocal(DYNAMIC_SCOPE);
visit(runtimehelpercall.getArgs()[0]);
jvmMethod().loadBlockType();
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "handleNonlocalReturn", sig(IRubyObject.class, StaticScope.class, DynamicScope.class, Object.class, Block.Type.class));
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "handleNonlocalReturn", sig(IRubyObject.class, DynamicScope.class, Object.class));
jvmStoreLocal(runtimehelpercall.getResult());
break;
case HANDLE_BREAK_AND_RETURNS_IN_LAMBDA:
jvmMethod().loadContext();
jvmMethod().loadStaticScope();
jvmLoadLocal(DYNAMIC_SCOPE);
visit(runtimehelpercall.getArgs()[0]);
jvmMethod().loadBlockType();
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "handleBreakAndReturnsInLambdas", sig(IRubyObject.class, ThreadContext.class, StaticScope.class, DynamicScope.class, Object.class, Block.Type.class));
jvmMethod().loadBlock();
jvmAdapter().invokestatic(p(IRRuntimeHelpers.class), "handleBreakAndReturnsInLambdas", sig(IRubyObject.class, ThreadContext.class, DynamicScope.class, Object.class, Block.class));
jvmStoreLocal(runtimehelpercall.getResult());
break;
case IS_DEFINED_BACKREF:
Expand Down

0 comments on commit 5ff5a0e

Please sign in to comment.