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; }
/** * Evaluates a script under the current scope (perhaps the top-level * scope) and returns the result (generally the last value calculated). * This version goes straight into the interpreter, bypassing compilation * and runtime preparation typical to normal script runs. * * @param script The scriptlet to run * @returns The result of the eval */ public IRubyObject evalScriptlet(String script) { ThreadContext context = getCurrentContext(); DynamicScope currentScope = context.getCurrentScope(); ManyVarsDynamicScope newScope = new ManyVarsDynamicScope(getStaticScopeFactory().newEvalScope(currentScope.getStaticScope()), currentScope); return evalScriptlet(script, newScope); }
/** * Evaluates a script under the current scope (perhaps the top-level * scope) and returns the result (generally the last value calculated). * This version goes straight into the interpreter, bypassing compilation * and runtime preparation typical to normal script runs. * * @param script The scriptlet to run * @returns The result of the eval */ public IRubyObject evalScriptlet(String script) { ThreadContext context = getCurrentContext(); DynamicScope currentScope = context.getCurrentScope(); ManyVarsDynamicScope newScope = new ManyVarsDynamicScope(getStaticScopeFactory().newEvalScope(currentScope.getStaticScope()), currentScope); return evalScriptlet(script, newScope); }
/** * Evaluates a script under the current scope (perhaps the top-level * scope) and returns the result (generally the last value calculated). * This version goes straight into the interpreter, bypassing compilation * and runtime preparation typical to normal script runs. * * @param script The scriptlet to run * @returns The result of the eval */ public IRubyObject evalScriptlet(String script) { ThreadContext context = getCurrentContext(); DynamicScope currentScope = context.getCurrentScope(); ManyVarsDynamicScope newScope = new ManyVarsDynamicScope(getStaticScopeFactory().newEvalScope(currentScope.getStaticScope()), currentScope); return evalScriptlet(script, newScope); }
/** * Evaluates a script under the current scope (perhaps the top-level * scope) and returns the result (generally the last value calculated). * This version goes straight into the interpreter, bypassing compilation * and runtime preparation typical to normal script runs. * * @param script The scriptlet to run * @returns The result of the eval */ public IRubyObject evalScriptlet(String script) { ThreadContext context = getCurrentContext(); DynamicScope currentScope = context.getCurrentScope(); ManyVarsDynamicScope newScope = new ManyVarsDynamicScope(getStaticScopeFactory().newEvalScope(currentScope.getStaticScope()), currentScope); return evalScriptlet(script, newScope); }
} else { evalScopeBinding.evalScope = new ManyVarsDynamicScope(runtime.getStaticScopeFactory().newEvalScope(dynamicScope.getStaticScope()), dynamicScope);
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. I take it having the ability to have // succesive binding evals be able to share same scope makes sense from a programmers // perspective. One crappy outcome of this design is it requires Dynamic and Static // scopes to be mutable for this one case. // Note: In Ruby 1.9 all of this logic can go away since they will require explicit // bindings for evals. // We only define one special dynamic scope per 'logical' binding. So all bindings for // the same scope should share the same dynamic scope. This allows multiple evals with // different different bindings in the same scope to see the same stuff. // No binding scope so we should create one if (evalScope == null) { // If the next scope out has the same binding scope as this scope it means // we are evaling within an eval and in that case we should be sharing the same // binding scope. DynamicScope parent = getNextCapturedScope(); if (parent != null && parent.getEvalScope(runtime) == this) { evalScope = this; } else { // bindings scopes must always be ManyVars scopes since evals can grow them evalScope = new ManyVarsDynamicScope(runtime.getStaticScopeFactory().newEvalScope(getStaticScope()), this); } } return evalScope; }
/** * Attempts to remove this variable from top self or receiver. * */ public void remove() { ThreadContext context = receiver.getRuntime().getCurrentContext(); try { DynamicScope currentScope = context.getCurrentScope(); ManyVarsDynamicScope scope = (ManyVarsDynamicScope) context.getCurrentScope(); scope = new ManyVarsDynamicScope(context.runtime.getStaticScopeFactory().newEvalScope(currentScope.getStaticScope()), currentScope); } catch (ArrayIndexOutOfBoundsException e) { //no context is left. //no operation is needed. } } }
/** * Attempts to remove this variable from top self or receiver. * */ public void remove() { ThreadContext context = receiver.getRuntime().getCurrentContext(); try { DynamicScope currentScope = context.getCurrentScope(); ManyVarsDynamicScope scope = (ManyVarsDynamicScope) context.getCurrentScope(); scope = new ManyVarsDynamicScope(context.runtime.getStaticScopeFactory().newEvalScope(currentScope.getStaticScope()), currentScope); } catch (ArrayIndexOutOfBoundsException e) { //no context is left. //no operation is needed. } } }
static ManyVarsDynamicScope getManyVarsDynamicScope(ScriptingContainer container, int depth) { ManyVarsDynamicScope scope; StaticScopeFactory scopeFactory = container.getProvider().getRuntime().getStaticScopeFactory(); // root our parsing scope with a dummy scope StaticScope topStaticScope = scopeFactory.newLocalScope(null); topStaticScope.setModule(container.getProvider().getRuntime().getObject()); DynamicScope currentScope = new ManyVarsDynamicScope(topStaticScope, null); String[] names4Injection = container.getVarMap().getLocalVarNames(); StaticScope evalScope = names4Injection == null || names4Injection.length == 0 ? scopeFactory.newEvalScope(currentScope.getStaticScope()) : scopeFactory.newEvalScope(currentScope.getStaticScope(), names4Injection); scope = new ManyVarsDynamicScope(evalScope, currentScope); // JRUBY-5501: ensure we've set up a cref for the scope too scope.getStaticScope().determineModule(); return scope; }
static ManyVarsDynamicScope getManyVarsDynamicScope(ScriptingContainer container, int depth) { ManyVarsDynamicScope scope; StaticScopeFactory scopeFactory = container.getProvider().getRuntime().getStaticScopeFactory(); // root our parsing scope with a dummy scope StaticScope topStaticScope = scopeFactory.newLocalScope(null); topStaticScope.setModule(container.getProvider().getRuntime().getObject()); DynamicScope currentScope = new ManyVarsDynamicScope(topStaticScope, null); String[] names4Injection = container.getVarMap().getLocalVarNames(); StaticScope evalScope = names4Injection == null || names4Injection.length == 0 ? scopeFactory.newEvalScope(currentScope.getStaticScope()) : scopeFactory.newEvalScope(currentScope.getStaticScope(), names4Injection); scope = new ManyVarsDynamicScope(evalScope, currentScope); // JRUBY-5501: ensure we've set up a cref for the scope too scope.getStaticScope().determineModule(); return scope; }
static ManyVarsDynamicScope getManyVarsDynamicScope(ScriptingContainer container, int depth) { ManyVarsDynamicScope scope; StaticScopeFactory scopeFactory = container.getProvider().getRuntime().getStaticScopeFactory(); // root our parsing scope with a dummy scope StaticScope topStaticScope = scopeFactory.newLocalScope(null); topStaticScope.setModule(container.getProvider().getRuntime().getObject()); DynamicScope currentScope = new ManyVarsDynamicScope(topStaticScope, null); String[] names4Injection = container.getVarMap().getLocalVarNames(); StaticScope evalScope = names4Injection == null || names4Injection.length == 0 ? scopeFactory.newEvalScope(currentScope.getStaticScope()) : scopeFactory.newEvalScope(currentScope.getStaticScope(), names4Injection); scope = new ManyVarsDynamicScope(evalScope, currentScope); // JRUBY-5501: ensure we've set up a cref for the scope too scope.getStaticScope().determineModule(); return scope; }
static ManyVarsDynamicScope getManyVarsDynamicScope(ScriptingContainer container, int depth) { ManyVarsDynamicScope scope; StaticScopeFactory scopeFactory = container.getProvider().getRuntime().getStaticScopeFactory(); // root our parsing scope with a dummy scope StaticScope topStaticScope = scopeFactory.newLocalScope(null); topStaticScope.setModule(container.getProvider().getRuntime().getObject()); DynamicScope currentScope = new ManyVarsDynamicScope(topStaticScope, null); String[] names4Injection = container.getVarMap().getLocalVarNames(); StaticScope evalScope = names4Injection == null || names4Injection.length == 0 ? scopeFactory.newEvalScope(currentScope.getStaticScope()) : scopeFactory.newEvalScope(currentScope.getStaticScope(), names4Injection); scope = new ManyVarsDynamicScope(evalScope, currentScope); // JRUBY-5501: ensure we've set up a cref for the scope too scope.getStaticScope().determineModule(); return scope; }
public static StaticScope decodeScope(ThreadContext context, StaticScope parent, String scopeString) { String[][] decodedScope = decodeScopeDescriptor(scopeString); StaticScope scope = null; switch (StaticScope.Type.valueOf(decodedScope[0][0])) { case BLOCK: scope = context.runtime.getStaticScopeFactory().newBlockScope(parent, decodedScope[1]); break; case EVAL: scope = context.runtime.getStaticScopeFactory().newEvalScope(parent, decodedScope[1]); break; case LOCAL: scope = context.runtime.getStaticScopeFactory().newLocalScope(parent, decodedScope[1]); break; } setAritiesFromDecodedScope(scope, decodedScope[0]); return scope; }
public static StaticScope decodeScope(ThreadContext context, StaticScope parent, String scopeString) { String[][] decodedScope = decodeScopeDescriptor(scopeString); StaticScope scope = null; switch (StaticScope.Type.valueOf(decodedScope[0][0])) { case BLOCK: scope = context.runtime.getStaticScopeFactory().newBlockScope(parent, decodedScope[1]); break; case EVAL: scope = context.runtime.getStaticScopeFactory().newEvalScope(parent, decodedScope[1]); break; case LOCAL: scope = context.runtime.getStaticScopeFactory().newLocalScope(parent, decodedScope[1]); break; } setAritiesFromDecodedScope(scope, decodedScope[0]); return scope; }
/** * Evaluate the given string. * @param context the current thread's context * @param self the self to evaluate under * @param src The string containing the text to be evaluated * @param file The filename to use when reporting errors during the evaluation * @param lineNumber that the eval supposedly starts from * @return An IRubyObject result from the evaluation */ public static IRubyObject evalSimple(ThreadContext context, RubyModule under, IRubyObject self, RubyString src, String file, int lineNumber, EvalType evalType) { Ruby runtime = context.runtime; // no binding, just eval in "current" frame (caller's frame) DynamicScope parentScope = context.getCurrentScope(); DynamicScope evalScope = new ManyVarsDynamicScope(runtime.getStaticScopeFactory().newEvalScope(parentScope.getStaticScope()), parentScope); evalScope.getStaticScope().setModule(under); context.pushEvalSimpleFrame(self); try { return evalCommon(context, evalScope, self, src, file, lineNumber, "(eval)", Block.NULL_BLOCK, evalType); } finally { context.popFrame(); } }
/** * Evaluate the given string. * @param context the current thread's context * @param self the self to evaluate under * @param src The string containing the text to be evaluated * @param file The filename to use when reporting errors during the evaluation * @param lineNumber that the eval supposedly starts from * @return An IRubyObject result from the evaluation */ public static IRubyObject evalSimple(ThreadContext context, RubyModule under, IRubyObject self, RubyString src, String file, int lineNumber, EvalType evalType) { Ruby runtime = context.runtime; // no binding, just eval in "current" frame (caller's frame) DynamicScope parentScope = context.getCurrentScope(); DynamicScope evalScope = new ManyVarsDynamicScope(runtime.getStaticScopeFactory().newEvalScope(parentScope.getStaticScope()), parentScope); evalScope.getStaticScope().setModule(under); context.pushEvalSimpleFrame(self); try { return evalCommon(context, evalScope, self, src, file, lineNumber, "(eval)", Block.NULL_BLOCK, evalType); } finally { context.popFrame(); } }
@SuppressWarnings("deprecation") static StaticScope decodeScope(ThreadContext context, StaticScope parent, String scopeString) { String[][] decodedScope = decodeScopeDescriptor(scopeString); String scopeTypeName = decodedScope[0][0]; String[] names = decodedScope[1]; StaticScope scope = null; switch (StaticScope.Type.valueOf(scopeTypeName)) { case BLOCK: scope = context.runtime.getStaticScopeFactory().newBlockScope(parent, names); break; case EVAL: scope = context.runtime.getStaticScopeFactory().newEvalScope(parent, names); break; case LOCAL: scope = context.runtime.getStaticScopeFactory().newLocalScope(parent, names); break; } setAritiesFromDecodedScope(scope, decodedScope[0][2]); scope.setScopeType(IRScopeType.valueOf(decodedScope[0][3])); return scope; }
@SuppressWarnings("deprecation") static StaticScope decodeScope(ThreadContext context, StaticScope parent, String scopeString) { String[][] decodedScope = decodeScopeDescriptor(scopeString); String scopeTypeName = decodedScope[0][0]; String[] names = decodedScope[1]; StaticScope scope = null; switch (StaticScope.Type.valueOf(scopeTypeName)) { case BLOCK: scope = context.runtime.getStaticScopeFactory().newBlockScope(parent, names); break; case EVAL: scope = context.runtime.getStaticScopeFactory().newEvalScope(parent, names); break; case LOCAL: scope = context.runtime.getStaticScopeFactory().newLocalScope(parent, names); break; } setAritiesFromDecodedScope(scope, decodedScope[0][2]); scope.setScopeType(IRScopeType.valueOf(decodedScope[0][3])); return scope; }