Skip to content

Commit

Permalink
Showing 3 changed files with 13 additions and 21 deletions.
6 changes: 1 addition & 5 deletions core/src/main/java/org/jruby/ir/interpreter/Interpreter.java
Original file line number Diff line number Diff line change
@@ -403,11 +403,7 @@ private static IRubyObject processReturnOp(ThreadContext context, Instr instr, O
case NONLOCAL_RETURN: {
NonlocalReturnInstr ri = (NonlocalReturnInstr)instr;
IRubyObject rv = (IRubyObject)retrieveOp(ri.getReturnValue(), context, self, currDynScope, currScope, temp);
// If not in a lambda, check if this was a non-local return
if (!IRRuntimeHelpers.inLambda(blockType)) {
IRRuntimeHelpers.initiateNonLocalReturn(context, currDynScope, ri.maybeLambda, rv);
}
return rv;
return IRRuntimeHelpers.initiateNonLocalReturn(context, currDynScope, blockType, ri.maybeLambda, rv);
}
}
return null;
Original file line number Diff line number Diff line change
@@ -53,7 +53,10 @@ public static boolean inProc(Block.Type blockType) {
/*
* Handle non-local returns (ex: when nested in closures, root scopes of module/class/sclass bodies)
*/
public static void initiateNonLocalReturn(ThreadContext context, DynamicScope dynScope, boolean maybeLambda, IRubyObject returnValue) {
public static IRubyObject initiateNonLocalReturn(ThreadContext context, DynamicScope dynScope, Block.Type blockType, boolean maybeLambda, IRubyObject returnValue) {
// If not in a lambda, check if this was a non-local return
if (IRRuntimeHelpers.inLambda(blockType)) return returnValue;

IRStaticScope scope = (IRStaticScope)dynScope.getStaticScope();
IRScopeType scopeType = scope.getScopeType();
boolean inDefineMethod = false;
23 changes: 8 additions & 15 deletions core/src/main/java/org/jruby/ir/targets/JVMVisitor.java
Original file line number Diff line number Diff line change
@@ -1657,21 +1657,14 @@ public void RuntimeHelperCall(RuntimeHelperCall runtimehelpercall) {

@Override
public void NonlocalReturnInstr(NonlocalReturnInstr returninstr) {
// disable for now
super.NonlocalReturnInstr(returninstr);

if (this.currentScope instanceof IRClosure) {
/* generate run-time call to check non-local-return, errors, etc */
SkinnyMethodAdapter a = jvmAdapter();
jvmMethod().loadContext(); // 1. ThreadContext
jvmMethod().loadStaticScope(); // 2. current scope
// 3. ref. to returnInstr.methodIdToReturnFrom
visit(returninstr.getReturnValue()); // 4. return value
// boolean about whether we are in a closure or not
// call to handle non-local return
} else {
/* throw IR-return-jump */
}
jvmMethod().loadContext();
jvmLoadLocal(DYNAMIC_SCOPE);
jvmMethod().loadBlockType();
jvmAdapter().ldc(returninstr.maybeLambda);
visit(returninstr.getReturnValue());

jvmMethod().invokeIRHelper("initiateNonLocalReturn", sig(IRubyObject.class, ThreadContext.class, DynamicScope.class, Block.Type.class, boolean.class, IRubyObject.class));
jvmMethod().returnValue();
}

@Override

0 comments on commit 3ba53e0

Please sign in to comment.