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 IRException decode(IRReaderDecoder d) { return getExceptionFromOrdinal(d.decodeByte()); } @Override
@Override public String toString() { return "LocalJumpError:" + getType(); } }
case GLOBAL_VARIABLE: return GlobalVariable.decode(this); case HASH: return Hash.decode(this); case IR_EXCEPTION: return IRException.decode(this); case LABEL: return Label.decode(this); case LOCAL_VARIABLE: return LocalVariable.decode(this);
case GLOBAL_VARIABLE: return GlobalVariable.decode(this); case HASH: return Hash.decode(this); case IR_EXCEPTION: return IRException.decode(this); case LABEL: return Label.decode(this); case LOCAL_VARIABLE: return LocalVariable.decode(this);
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; } }
@Override public String toString() { return "LocalJumpError:" + getType(); } }
public static IRException decode(IRReaderDecoder d) { return getExceptionFromOrdinal(d.decodeByte()); } @Override
public static void catchUncaughtBreakInLambdas(ThreadContext context, IRScope scope, Object exc, Block.Type blockType) throws RuntimeException { if ((exc instanceof IRBreakJump) && inNonMethodBodyLambda(scope, blockType)) { // We just unwound all the way up because of a non-local break throw IRException.BREAK_LocalJumpError.getException(context.getRuntime()); } else { // Propagate Helpers.throwException((Throwable)exc); } }
public RuntimeException getException(Ruby runtime) { switch (getType()) { case NEXT: return runtime.newLocalJumpError(getType(), null, "unexpected next"); case BREAK: return runtime.newLocalJumpError(getType(), null, "unexpected break"); case RETURN: return runtime.newLocalJumpError(getType(), null, "unexpected return"); case REDO: return runtime.newLocalJumpError(getType(), null, "unexpected redo"); case RETRY: return runtime.newLocalJumpError(getType(), null, "retry outside of rescue not supported"); } throw new RuntimeException("Unhandled case in operands/IRException.java"); }
private static IRScopeType ensureScopeIsClosure(ThreadContext context, DynamicScope dynamicScope) { IRScopeType scopeType = dynamicScope.getStaticScope().getScopeType(); // Error -- breaks can only be initiated in closures if (!scopeType.isClosureType()) throw IRException.BREAK_LocalJumpError.getException(context.runtime); return scopeType; }
public RuntimeException getException(Ruby runtime) { switch (getType()) { case NEXT: return runtime.newLocalJumpError(getType(), null, "unexpected next"); case BREAK: return runtime.newLocalJumpError(getType(), null, "unexpected break"); case RETURN: return runtime.newLocalJumpError(getType(), null, "unexpected return"); case REDO: return runtime.newLocalJumpError(getType(), null, "unexpected redo"); case RETRY: return runtime.newLocalJumpError(getType(), null, "retry outside of rescue not supported"); } throw new RuntimeException("Unhandled case in operands/IRException.java"); }
private static IRScopeType ensureScopeIsClosure(ThreadContext context, DynamicScope dynamicScope) { IRScopeType scopeType = dynamicScope.getStaticScope().getScopeType(); // Error -- breaks can only be initiated in closures if (!scopeType.isClosureType()) throw IRException.BREAK_LocalJumpError.getException(context.runtime); return scopeType; }
public void IRException(IRException irexception) { print(irexception.getType()); } public void Label(Label label) { print(label.toString()); }
public static void catchUncaughtBreakInLambdas(ThreadContext context, IRScope scope, Object exc, Block.Type blockType) throws RuntimeException { if ((exc instanceof IRBreakJump) && inNonMethodBodyLambda(scope, blockType)) { // We just unwound all the way up because of a non-local break throw IRException.BREAK_LocalJumpError.getException(context.getRuntime()); } else { // Propagate Helpers.throwException((Throwable)exc); } }
public void IRException(IRException irexception) { print(irexception.getType()); } public void Label(Label label) { print(label.toString()); }
public static IRubyObject handlePropagatedBreak(ThreadContext context, IRScope scope, Object bjExc, Block.Type blockType) throws RuntimeException { if (!(bjExc instanceof IRBreakJump)) { throw (RuntimeException)bjExc; } IRBreakJump bj = (IRBreakJump)bjExc; if (bj.breakInEval) { // If the break was in an eval, we pretend as if it was in the containing scope if (!(scope instanceof IRClosure)) { // Error -- breaks can only be initiated in closures throw IRException.BREAK_LocalJumpError.getException(context.getRuntime()); } else { bj.breakInEval = false; throw bj; } } else if (bj.scopeIdToReturnTo == scope.getScopeId()) { // Done!! Hurray! return bj.breakValue; /* --------------------------------------------------------------- * FIXME: Puzzled .. Why is this not needed? } else if (!context.scopeExistsOnCallStack(bj.scopeToReturnTo.getStaticScope())) { throw IRException.BREAK_LocalJumpError.getException(context.runtime); * --------------------------------------------------------------- */ } else { // Propagate throw bj; } } };
@Override public void encode(IRWriterEncoder e) { super.encode(e); e.encode((byte) getType().ordinal()); }
public static IRubyObject handlePropagatedBreak(ThreadContext context, IRScope scope, Object bjExc, Block.Type blockType) throws RuntimeException { if (!(bjExc instanceof IRBreakJump)) { throw (RuntimeException)bjExc; } IRBreakJump bj = (IRBreakJump)bjExc; if (bj.breakInEval) { // If the break was in an eval, we pretend as if it was in the containing scope if (!(scope instanceof IRClosure)) { // Error -- breaks can only be initiated in closures throw IRException.BREAK_LocalJumpError.getException(context.getRuntime()); } else { bj.breakInEval = false; throw bj; } } else if (bj.scopeIdToReturnTo == scope.getScopeId()) { // Done!! Hurray! return bj.breakValue; /* --------------------------------------------------------------- * FIXME: Puzzled .. Why is this not needed? } else if (!context.scopeExistsOnCallStack(bj.scopeToReturnTo.getStaticScope())) { throw IRException.BREAK_LocalJumpError.getException(context.runtime); * --------------------------------------------------------------- */ } else { // Propagate throw bj; } } };
@Override public void encode(IRWriterEncoder e) { super.encode(e); e.encode((byte) getType().ordinal()); }