public static boolean inNonMethodBodyLambda(StaticScope scope, Block.Type blockType) { // SSS FIXME: Hack! AST interpreter and JIT compiler marks a proc's static scope as // an argument scope if it is used to define a method's body via :define_method. // Since that is exactly what we want to figure out here, am just using that flag here. // But, this is ugly (as is the original hack in the current runtime). What is really // needed is a new block type -- a block that is used to define a method body. return blockType == LAMBDA && !scope.isArgumentScope(); }
public static boolean inNonMethodBodyLambda(StaticScope scope, Block.Type blockType) { // SSS FIXME: Hack! AST interpreter and JIT compiler marks a proc's static scope as // an argument scope if it is used to define a method's body via :define_method. // Since that is exactly what we want to figure out here, am just using that flag here. // But, this is ugly (as is the original hack in the current runtime). What is really // needed is a new block type -- a block that is used to define a method body. return blockType == LAMBDA && !scope.isArgumentScope(); }
public static boolean inNonMethodBodyLambda(IRScope scope, Block.Type blockType) { // SSS FIXME: Hack! AST interpreter and JIT compiler marks a proc's static scope as // an argument scope if it is used to define a method's body via :define_method. // Since that is exactly what we want to figure out here, am just using that flag here. // But, this is ugly (as is the original hack in the current runtime). What is really // needed is a new block type -- a block that is used to define a method body. return blockType == Block.Type.LAMBDA && !scope.getStaticScope().isArgumentScope(); }
public static boolean inNonMethodBodyLambda(IRScope scope, Block.Type blockType) { // SSS FIXME: Hack! AST interpreter and JIT compiler marks a proc's static scope as // an argument scope if it is used to define a method's body via :define_method. // Since that is exactly what we want to figure out here, am just using that flag here. // But, this is ugly (as is the original hack in the current runtime). What is really // needed is a new block type -- a block that is used to define a method body. return blockType == Block.Type.LAMBDA && !scope.getStaticScope().isArgumentScope(); }
@Override public IRubyObject[] getArgValues() { // if we're not the "argument scope" for zsuper, try our parent if (!staticScope.isArgumentScope()) { return parent.getArgValues(); } int totalArgs = staticScope.getRequiredArgs() + staticScope.getOptionalArgs(); assert totalArgs == 0 : this.getClass().getSimpleName() + " only supports scopes with no variables"; return IRubyObject.NULL_ARRAY; } }
@Override public IRubyObject[] getArgValues() { // if we're not the "argument scope" for zsuper, try our parent if (!staticScope.isArgumentScope()) { return parent.getArgValues(); } int totalArgs = staticScope.getRequiredArgs() + staticScope.getOptionalArgs(); assert totalArgs == 0 : this.getClass().getSimpleName() + " only supports scopes with no variables"; return IRubyObject.NULL_ARRAY; } }
@JIT public static RubyFixnum getArgScopeDepth(ThreadContext context, StaticScope currScope) { int i = 0; while (!currScope.isArgumentScope()) { currScope = currScope.getEnclosingScope(); i++; } return context.runtime.newFixnum(i); }
@JIT public static RubyFixnum getArgScopeDepth(ThreadContext context, StaticScope currScope) { int i = 0; while (!currScope.isArgumentScope()) { currScope = currScope.getEnclosingScope(); i++; } return context.runtime.newFixnum(i); }
private static DynamicScope getContainingMethodOrLambdasDynamicScope(DynamicScope dynScope) { // If not in a lambda, check if this was a non-local return for (; dynScope != null; dynScope = dynScope.getParentScope()) { StaticScope staticScope = dynScope.getStaticScope(); IRScope scope = staticScope.getIRScope(); // 1) method 2) root of script 3) lambda 3) closure (define_method) for zsuper if (scope instanceof IRMethod || scope instanceof IRScriptBody || (scope instanceof IRClosure && (dynScope.isLambda() || staticScope.isArgumentScope()))) return dynScope; } return null; }
private static DynamicScope getContainingMethodOrLambdasDynamicScope(DynamicScope dynScope) { // If not in a lambda, check if this was a non-local return for (; dynScope != null; dynScope = dynScope.getParentScope()) { StaticScope staticScope = dynScope.getStaticScope(); IRScope scope = staticScope.getIRScope(); // 1) method 2) root of script 3) lambda 3) closure (define_method) for zsuper if (scope instanceof IRMethod || scope instanceof IRScriptBody || (scope instanceof IRClosure && (dynScope.isLambda() || staticScope.isArgumentScope()))) return dynScope; } return null; }
private static DynamicScope getContainingMethodsDynamicScope(DynamicScope dynScope) { for (; dynScope != null; dynScope = dynScope.getParentScope()) { StaticScope scope = dynScope.getStaticScope(); IRScopeType scopeType = scope.getScopeType(); // We hit a method boundary (actual method or a define_method closure). if (scopeType.isMethodType() || scopeType.isBlock() && scope.isArgumentScope() || scopeType == IRScopeType.SCRIPT_BODY) return dynScope; } return null; }
private static DynamicScope getContainingMethodsDynamicScope(DynamicScope dynScope) { for (; dynScope != null; dynScope = dynScope.getParentScope()) { StaticScope scope = dynScope.getStaticScope(); IRScopeType scopeType = scope.getScopeType(); // We hit a method boundary (actual method or a define_method closure). if (scopeType.isMethodType() || scopeType.isBlock() && scope.isArgumentScope() || scopeType == IRScopeType.SCRIPT_BODY) return dynScope; } return null; }
if (!staticScope.isArgumentScope()) { return parent.getArgValues();
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); }
@Override public IRubyObject[] getArgValues() { if (!staticScope.isArgumentScope()) { return parent.getArgValues();
protected static final Signature signatureFor(IRScope method, boolean aritySplit) { if (aritySplit) { StaticScope argScope = method.getStaticScope(); if (argScope.isArgumentScope() && argScope.getSignature().isFixed() && !argScope.getSignature().hasKwargs()) { // we have only required arguments...emit a signature appropriate to that arity String[] args = new String[argScope.getSignature().required()]; Class[] types = new Class[args.length]; // Class... for (int i = 0; i < args.length; i++) { args[i] = "arg" + i; types[i] = IRubyObject.class; } return METHOD_SIGNATURE_BASE.insertArgs(BLOCK_ARG_NAME, args, types); } // we can't do an specific-arity signature return null; } // normal boxed arg list signature return METHOD_SIGNATURE_BASE.insertArgs(BLOCK_ARG_NAME, new String[]{"args"}, IRubyObject[].class); }
@Override public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block aBlock) { DynamicScope argsDynScope = currDynScope; // Find args that need to be passed into super while (!argsDynScope.getStaticScope().isArgumentScope()) argsDynScope = argsDynScope.getNextCapturedScope(); IRScope argsIRScope = ((IRStaticScope)argsDynScope.getStaticScope()).getIRScope(); Operand[] superArgs = (argsIRScope instanceof IRMethod) ? ((IRMethod)argsIRScope).getCallArgs() : ((IRClosure)argsIRScope).getBlockArgs(); // Prepare args -- but look up in 'argsDynScope', not 'currDynScope' IRubyObject[] args = prepareArguments(context, self, superArgs, argsDynScope, temp); // Prepare block -- fetching from the frame stack, if necessary Block block = prepareBlock(context, self, currDynScope, temp); if (block == null || !block.isGiven()) block = context.getFrameBlock(); return interpretSuper(context, self, args, block); }
protected static final Signature signatureFor(IRScope method, boolean aritySplit) { if (aritySplit) { StaticScope argScope = method.getStaticScope(); if (argScope.isArgumentScope() && argScope.getSignature().isFixed() && !argScope.getSignature().hasKwargs()) { // we have only required arguments...emit a signature appropriate to that arity String[] args = new String[argScope.getSignature().required()]; Class[] types = new Class[args.length]; // Class... for (int i = 0; i < args.length; i++) { args[i] = "arg" + i; types[i] = IRubyObject.class; } return METHOD_SIGNATURE_BASE.insertArgs(BLOCK_ARG_NAME, args, types); } // we can't do an specific-arity signature return null; } // normal boxed arg list signature return METHOD_SIGNATURE_BASE.insertArgs(BLOCK_ARG_NAME, new String[]{"args"}, IRubyObject[].class); }
@Override public Object interpret(ThreadContext context, DynamicScope currDynScope, IRubyObject self, Object[] temp, Block aBlock) { DynamicScope argsDynScope = currDynScope; // Find args that need to be passed into super while (!argsDynScope.getStaticScope().isArgumentScope()) argsDynScope = argsDynScope.getNextCapturedScope(); IRScope argsIRScope = ((IRStaticScope)argsDynScope.getStaticScope()).getIRScope(); Operand[] superArgs = (argsIRScope instanceof IRMethod) ? ((IRMethod)argsIRScope).getCallArgs() : ((IRClosure)argsIRScope).getBlockArgs(); // Prepare args -- but look up in 'argsDynScope', not 'currDynScope' IRubyObject[] args = prepareArguments(context, self, superArgs, argsDynScope, temp); // Prepare block -- fetching from the frame stack, if necessary Block block = prepareBlock(context, self, currDynScope, temp); if (block == null || !block.isGiven()) block = context.getFrameBlock(); return interpretSuper(context, self, args, block); }