Skip to content
Permalink
Browse files
Implement NonLocalReturn.
  • Loading branch information
headius committed Sep 15, 2014
1 parent b1484af commit 3ba53e0f5b96460c9aab4d4f505c084c3a14c782
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 21 deletions.
@@ -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;
@@ -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;
@@ -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.