private static boolean inReturnScope(Block.Type blockType, IRReturnJump exception, DynamicScope dynScope) { // blockType == null is any non-block scope but in this case it is always a method based on how we emit instrs. return (blockType == null || inLambda(blockType)) && exception.methodToReturnFrom == dynScope; }
private static boolean inReturnScope(Block.Type blockType, IRReturnJump exception, DynamicScope dynScope) { // blockType == null is any non-block scope but in this case it is always a method based on how we emit instrs. return (blockType == null || inLambda(blockType)) && exception.methodToReturnFrom == dynScope; }
public static IRubyObject initiateBreak(ThreadContext context, IRScope scope, int scopeIdToReturnTo, IRubyObject breakValue, Block.Type blockType) throws RuntimeException { if (inLambda(blockType)) { // Ensures would already have been run since the IR builder makes // sure that ensure code has run before we hit the break. Treat // the break as a regular return from the closure. return breakValue; } else { if (!(scope instanceof IRClosure)) { // Error -- breaks can only be initiated in closures throw IRException.BREAK_LocalJumpError.getException(context.runtime); } IRBreakJump bj = IRBreakJump.create(scopeIdToReturnTo, breakValue); if (scope instanceof IREvalScript) { // If we are in an eval, record it so we can account for it bj.breakInEval = true; } // Start the process of breaking through the intermediate scopes throw bj; } }
public static IRubyObject initiateBreak(ThreadContext context, IRScope scope, int scopeIdToReturnTo, IRubyObject breakValue, Block.Type blockType) throws RuntimeException { if (inLambda(blockType)) { // Ensures would already have been run since the IR builder makes // sure that ensure code has run before we hit the break. Treat // the break as a regular return from the closure. return breakValue; } else { if (!(scope instanceof IRClosure)) { // Error -- breaks can only be initiated in closures throw IRException.BREAK_LocalJumpError.getException(context.runtime); } IRBreakJump bj = IRBreakJump.create(scopeIdToReturnTo, breakValue); if (scope instanceof IREvalScript) { // If we are in an eval, record it so we can account for it bj.breakInEval = true; } // Start the process of breaking through the intermediate scopes throw bj; } }
public static IRubyObject initiateNonLocalReturn(ThreadContext context, DynamicScope dynScope, Block block, IRubyObject returnValue) { if (block != null && IRRuntimeHelpers.inLambda(block.type)) throw new IRWrappedLambdaReturnValue(returnValue); throw IRReturnJump.create(getContainingMethodOrLambdasDynamicScope(dynScope), returnValue); }
public static IRubyObject initiateNonLocalReturn(ThreadContext context, DynamicScope dynScope, Block block, IRubyObject returnValue) { if (block != null && IRRuntimeHelpers.inLambda(block.type)) throw new IRWrappedLambdaReturnValue(returnValue); throw IRReturnJump.create(getContainingMethodOrLambdasDynamicScope(dynScope), returnValue); }
public static IRubyObject initiateBreak(ThreadContext context, DynamicScope dynScope, IRubyObject breakValue, Block block) throws RuntimeException { // Wrap the return value in an exception object and push it through the break exception // paths so that ensures are run, frames/scopes are popped from runtime stacks, etc. if (inLambda(block.type)) throw new IRWrappedLambdaReturnValue(breakValue); IRScopeType scopeType = ensureScopeIsClosure(context, dynScope); DynamicScope parentScope = dynScope.getParentScope(); if (block.isEscaped()) { throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.BREAK, breakValue, "unexpected break"); } // Raise a break jump so we can bubble back down the stack to the appropriate place to break from. throw IRBreakJump.create(parentScope, breakValue, scopeType.isEval()); // weirdly evals are impld as closures...yes yes. }
public static IRubyObject initiateBreak(ThreadContext context, DynamicScope dynScope, IRubyObject breakValue, Block block) throws RuntimeException { // Wrap the return value in an exception object and push it through the break exception // paths so that ensures are run, frames/scopes are popped from runtime stacks, etc. if (inLambda(block.type)) throw new IRWrappedLambdaReturnValue(breakValue); IRScopeType scopeType = ensureScopeIsClosure(context, dynScope); DynamicScope parentScope = dynScope.getParentScope(); if (block.isEscaped()) { throw context.runtime.newLocalJumpError(RubyLocalJumpError.Reason.BREAK, breakValue, "unexpected break"); } // Raise a break jump so we can bubble back down the stack to the appropriate place to break from. throw IRBreakJump.create(parentScope, breakValue, scopeType.isEval()); // weirdly evals are impld as closures...yes yes. }
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(); boolean inDefineMethod = dynScope != null && staticScope.isArgumentScope() && staticScope.getScopeType().isBlock(); boolean topLevel = staticScope.getScopeType() == IRScopeType.SCRIPT_BODY; if ((definedWithinMethod || inDefineMethod || topLevel) && context.scopeExistsOnCallStack(dynScope)) { return; } throw IRException.RETURN_LocalJumpError.getException(context.runtime); }
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(); boolean inDefineMethod = dynScope != null && staticScope.isArgumentScope() && staticScope.getScopeType().isBlock(); boolean topLevel = staticScope.getScopeType() == IRScopeType.SCRIPT_BODY; if ((definedWithinMethod || inDefineMethod || topLevel) && context.scopeExistsOnCallStack(dynScope)) { return; } throw IRException.RETURN_LocalJumpError.getException(context.runtime); }
ipc = n; if (!IRRuntimeHelpers.inLambda(blockType)) { IRRuntimeHelpers.initiateNonLocalReturn(context, scope, ri.methodToReturnFrom, rv);
ipc = n; if (!IRRuntimeHelpers.inLambda(blockType)) { IRRuntimeHelpers.initiateNonLocalReturn(context, scope, ri.methodToReturnFrom, rv);