public DynamicScope getDummyScope(StaticScope staticScope) { if (dummyScope == null || dummyScope.getStaticScope() != staticScope) { return dummyScope = DynamicScope.newDummyScope(staticScope, dynamicScope); } return dummyScope; }
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; }
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; }
/** * Description of the RubyMethod */ public void initTopLocalVariables() { DynamicScope scope = configuration.getScope(); currentScope = scope.getStaticScope(); result.setScope(scope); }
@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); }
@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); }
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; }
/** * Description of the RubyMethod */ public void initTopLocalVariables() { DynamicScope scope = configuration.getScope(lexer.getFile()); currentScope = scope.getStaticScope(); result.setScope(scope); }
protected static RubyModule getRubyClass(final Ruby runtime) { ThreadContext context = runtime.getCurrentContext(); StaticScope scope = context.getCurrentScope().getStaticScope(); RubyModule rubyClass = scope.getModule(); return rubyClass; }
public final DynamicScope getEvalScope(Ruby runtime) { // We create one extra dynamicScope on a binding so that when we 'eval "b=1", binding' the // 'b' will get put into this new dynamic scope. The original scope does not see the new // 'b' and successive evals with this binding will. Note: This only happens for explicit // bindings. Implicit bindings will always dispose of the scope they create. // No eval scope set, so we create one if (evalScopeBinding.evalScope == null) { // bindings scopes must always be ManyVars scopes since evals can grow them evalScopeBinding.evalScope = new ManyVarsDynamicScope(runtime.getStaticScopeFactory().newEvalScope(dynamicScope.getStaticScope()), dynamicScope); } return evalScopeBinding.evalScope; }
public final DynamicScope getEvalScope(Ruby runtime) { // We create one extra dynamicScope on a binding so that when we 'eval "b=1", binding' the // 'b' will get put into this new dynamic scope. The original scope does not see the new // 'b' and successive evals with this binding will. Note: This only happens for explicit // bindings. Implicit bindings will always dispose of the scope they create. // No eval scope set, so we create one if (evalScopeBinding.evalScope == null) { // bindings scopes must always be ManyVars scopes since evals can grow them evalScopeBinding.evalScope = new ManyVarsDynamicScope(runtime.getStaticScopeFactory().newEvalScope(dynamicScope.getStaticScope()), dynamicScope); } return evalScopeBinding.evalScope; }
/** * Description of the RubyMethod */ public void initTopLocalVariables() { DynamicScope scope = configuration.getScope(lexer.getFile()); currentScope = scope.getStaticScope(); result.setScope(scope); }
protected RubyModule getRubyClass(Ruby runtime) { ThreadContext context = runtime.getCurrentContext(); StaticScope scope = context.getCurrentScope().getStaticScope(); RubyModule rubyClass = scope.getModule(); return rubyClass; }
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; }
@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); }
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; }
public void prepareTopLevel(RubyClass objectClass, IRubyObject topSelf) { pushFrame(); setCurrentVisibility(Visibility.PRIVATE); Frame frame = getCurrentFrame(); frame.setSelf(topSelf); getCurrentScope().getStaticScope().setModule(objectClass); }
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); }
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()); }