/** * Find the scope to use for flip-flops. Flip-flops live either in the * topmost "method scope" or in their nearest containing "eval scope". * * @return The scope to use for flip-flops */ public DynamicScope getFlipScope() { if (staticScope.getLocalScope() == staticScope) { return this; } else { return parent.getFlipScope(); } }
@JRubyMethod public IRubyObject local_variable_set(ThreadContext context, IRubyObject symbol, IRubyObject value) { String name = symbol.asJavaString().intern(); DynamicScope evalScope = binding.getEvalScope(context.runtime); int slot = evalScope.getStaticScope().isDefined(name); if (slot == -1) { // Yay! New variable associated with this binding slot = evalScope.getStaticScope().addVariable(name.intern()); evalScope.growIfNeeded(); } return evalScope.setValue(slot & 0xffff, value, slot >> 16); }
@Override public Object retrieve(ThreadContext context, IRubyObject self, StaticScope currScope, DynamicScope currDynScope, Object[] temp) { IRubyObject value = currDynScope.getValue(offset, scopeDepth); if (value == null) value = context.nil; return value; }
public DynamicScope getDummyScope(StaticScope staticScope) { if (dummyScope == null || dummyScope.getStaticScope() != staticScope) { return dummyScope = DynamicScope.newDummyScope(staticScope, dynamicScope); } return dummyScope; }
/** * Variation of getValue that checks for nulls, returning and setting the given value (presumably nil) */ public IRubyObject getValueOrNil(int offset, int depth, IRubyObject nil) { if (depth > 0) { return parent.getValueOrNil(offset, depth - 1, nil); } else { return getValueDepthZeroOrNil(offset, nil); } }
public static DynamicScope newDynamicScope(StaticScope staticScope, DynamicScope parent, EvalType evalType) { DynamicScope newScope = newDynamicScope(staticScope, parent); newScope.setEvalType(evalType); return newScope; }
DynamicScope flipScope = scope.getFlipScope(); flipScope.growIfNeeded(); IRubyObject result = flipScope.getValueDepthZeroOrNil(index, nil); flipScope.setValueDepthZero(result, index); return result; } else { if (endNode.interpret(runtime, context, self, aBlock).isTrue()) { flipScope.setValueDepthZero(runtime.getFalse(), index); if (result == null || !result.isTrue()) { if (beginNode.interpret(runtime, context, self, aBlock).isTrue()) { flipScope.setValueDepthZero(falseIfTrue(runtime, endNode.interpret(runtime, context, self, aBlock)), index); return runtime.getTrue(); } else { if (endNode.interpret(runtime, context, self, aBlock).isTrue()) { flipScope.setValueDepthZero(runtime.getFalse(), index);
private static IRubyObject evalCommon(ThreadContext context, DynamicScope evalScope, IRubyObject self, IRubyObject src, String file, int lineNumber, String name, Block blockArg, EvalType evalType) { StaticScope ss = evalScope.getStaticScope(); BeginEndInterpreterContext ic = prepareIC(context, evalScope, src, file, lineNumber, evalType); evalScope.setEvalType(evalType); context.pushScope(evalScope); try { evalScope.growIfNeeded(); runBeginBlocks(ic.getBeginBlocks(), context, self, ss, null); return Interpreter.INTERPRET_EVAL(context, self, ic, ic.getStaticScope().getModule(), IRubyObject.NULL_ARRAY, name, blockArg); } finally { evalScope.clearEvalType(); context.popScope(); } }
/** * Set value in current dynamic scope or one of its captured scopes. * * @param offset zero-indexed value that represents where variable lives * @param value to set * @param depth how many captured scopes down this variable should be set */ public IRubyObject setValue(IRubyObject value, int offset, int depth) { return setValue(offset, value, depth); }
/** * Variation of getValue that checks for nulls, returning and setting the given value (presumably nil) */ public IRubyObject getValueOrNil(int offset, int depth, IRubyObject nil) { return parent.getValueOrNil(offset, depth - 1, nil); }
/** * Get a new dynamic scope. Note: This only works for method scopes (ClosureIC will throw). */ public DynamicScope newDynamicScope(ThreadContext context) { // Add a parent-link to current dynscope to support non-local returns cheaply. This doesn't // affect variable scoping since local variables will all have the right scope depth. if (metaClassBodyScope) return DynamicScope.newDynamicScope(getStaticScope(), context.getCurrentScope()); return DynamicScope.newDynamicScope(getStaticScope()); }
public void preExecuteUnder(IRubyObject executeUnderObj, RubyModule executeUnderClass, Block block) { Frame frame = getCurrentFrame(); DynamicScope scope = getCurrentScope(); StaticScope sScope = runtime.getStaticScopeFactory().newBlockScope(scope.getStaticScope()); sScope.setModule(executeUnderClass); pushScope(DynamicScope.newDynamicScope(sScope, scope)); pushCallFrame(frame.getKlazz(), frame.getName(), executeUnderObj, block); getCurrentFrame().setVisibility(getPreviousFrame().getVisibility()); }
@JRubyMethod public IRubyObject local_variable_get(ThreadContext context, IRubyObject symbol) { String name = symbol.asJavaString().intern(); DynamicScope evalScope = binding.getEvalScope(context.runtime); int slot = evalScope.getStaticScope().isDefined(name); if (slot == -1) throw context.runtime.newNameError("local variable `" + name + "' not defined for " + inspect(), name); return evalScope.getValueOrNil(slot & 0xffff, slot >> 16, context.nil); }
@JIT public static DynamicScope prepareScriptScope(ThreadContext context, StaticScope scope) { IRScope irScope = scope.getIRScope(); if (irScope.isScriptScope()) { DynamicScope tlbScope = ((IRScriptBody) irScope).getScriptDynamicScope(); if (tlbScope != null) { context.preScopedBody(tlbScope); tlbScope.growIfNeeded(); return tlbScope; } } DynamicScope dynScope = DynamicScope.newDynamicScope(scope); context.pushScope(dynScope); return dynScope; }
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; }
public RootNode(ISourcePosition position, DynamicScope scope, Node bodyNode, String file, int endPosition, boolean needsCodeCoverage) { super(position, bodyNode.containsVariableAssignment()); this.scope = scope; this.staticScope = scope.getStaticScope(); this.bodyNode = bodyNode; this.file = file; this.endPosition = endPosition; this.needsCodeCoverage = needsCodeCoverage; }
result.getScope().growIfNeeded();
public DynamicScope allocScope(DynamicScope parentScope) { // SSS: Important! Use getStaticScope() to use a copy of the static-scope stored in the block-body. // Do not use 'closure.getStaticScope()' -- that returns the original copy of the static scope. // This matters because blocks created for Thread bodies modify the static-scope field of the block-body // that records additional state about the block body. // // FIXME: Rather than modify static-scope, it seems we ought to set a field in block-body which is then // used to tell dynamic-scope that it is a dynamic scope for a thread body. Anyway, to be revisited later! DynamicScope newScope = DynamicScope.newDynamicScope(body.getStaticScope(), parentScope, body.getEvalType()); if (type == Block.Type.LAMBDA) newScope.setLambda(true); return newScope; }
(staticScope.isBlockScope() ? "block" : "local")+" ["); int size = staticScope.getNumberOfVariables(); IRubyObject[] variableValues = getValues();
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; }