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; }
@JIT @Interp public static RubyString getFileNameStringFromScope(ThreadContext context, StaticScope currScope) { // FIXME: Not very efficient to do all this every time return context.runtime.newString(currScope.getIRScope().getFile()); }
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; }
@JIT @Interp public static RubyString getFileNameStringFromScope(ThreadContext context, StaticScope currScope) { // FIXME: Not very efficient to do all this every time return context.runtime.newString(currScope.getIRScope().getFile()); }
@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; }
@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; }
@JRubyMethod(name = "using", required = 1, frame = true, reads = SCOPE) public IRubyObject using(ThreadContext context, IRubyObject refinedModule) { if (context.getFrameSelf() != this) throw context.runtime.newRuntimeError("Module#using is not called on self"); // FIXME: This is a lame test and I am unsure it works with JIT'd bodies... if (context.getCurrentScope().getStaticScope().getIRScope() instanceof IRMethod) { throw context.runtime.newRuntimeError("Module#using is not permitted in methods"); } // I pass the cref even though I don't need to so that the concept is simpler to read StaticScope staticScope = context.getCurrentStaticScope(); RubyModule overlayModule = staticScope.getOverlayModuleForWrite(context); usingModule(context, overlayModule, refinedModule); return this; }
@JRubyMethod(name = "using", required = 1, frame = true, reads = SCOPE) public IRubyObject using(ThreadContext context, IRubyObject refinedModule) { if (context.getFrameSelf() != this) throw context.runtime.newRuntimeError("Module#using is not called on self"); // FIXME: This is a lame test and I am unsure it works with JIT'd bodies... if (context.getCurrentScope().getStaticScope().getIRScope() instanceof IRMethod) { throw context.runtime.newRuntimeError("Module#using is not permitted in methods"); } // I pass the cref even though I don't need to so that the concept is simpler to read StaticScope staticScope = context.getCurrentStaticScope(); RubyModule overlayModule = staticScope.getOverlayModuleForWrite(context); usingModule(context, overlayModule, refinedModule); return this; }
public IRubyObject lexicalSearchConst(ThreadContext context, StaticScope scope) { Ruby runtime = context.runtime; IRubyObject constant = scope.getConstantDefined(name); if (constant == null) { constant = UndefinedValue.UNDEFINED; } SwitchPoint switchPoint = (SwitchPoint) runtime.getConstantInvalidator(name).getData(); // bind constant until invalidated MethodHandle target = Binder.from(type()) .drop(0, 2) .constant(constant); MethodHandle fallback = Binder.from(type()) .insert(0, this) .invokeVirtualQuiet(Bootstrap.LOOKUP, "lexicalSearchConst"); setTarget(switchPoint.guardWithTest(target, fallback)); if (Options.INVOKEDYNAMIC_LOG_CONSTANTS.load()) { LOG.info(name + "\tretrieved and cached from scope (lexicalSearchConst) " + scope.getIRScope());// + " added to PIC" + extractSourceInfo(site)); } return constant; }
public IRubyObject lexicalSearchConst(ThreadContext context, StaticScope scope) { Ruby runtime = context.runtime; IRubyObject constant = scope.getConstantDefined(name); if (constant == null) { constant = UndefinedValue.UNDEFINED; } SwitchPoint switchPoint = (SwitchPoint) runtime.getConstantInvalidator(name).getData(); // bind constant until invalidated MethodHandle target = Binder.from(type()) .drop(0, 2) .constant(constant); MethodHandle fallback = Binder.from(type()) .insert(0, this) .invokeVirtualQuiet(Bootstrap.LOOKUP, "lexicalSearchConst"); setTarget(switchPoint.guardWithTest(target, fallback)); if (Options.INVOKEDYNAMIC_LOG_CONSTANTS.load()) { LOG.info(name + "\tretrieved and cached from scope (lexicalSearchConst) " + scope.getIRScope());// + " added to PIC" + extractSourceInfo(site)); } return constant; }
private static BeginEndInterpreterContext prepareIC(ThreadContext context, DynamicScope evalScope, IRubyObject src, String file, int lineNumber, EvalType evalType) { Ruby runtime = context.runtime; IRScope containingIRScope = evalScope.getStaticScope().getEnclosingScope().getIRScope(); RootNode rootNode = (RootNode) runtime.parseEval(src.convertToString().getByteList(), file, evalScope, lineNumber); StaticScope staticScope = evalScope.getStaticScope(); // Top-level script! IREvalScript script = new IREvalScript(runtime.getIRManager(), containingIRScope, file, lineNumber, staticScope, evalType); // enable refinements if incoming scope already has an overlay active if (staticScope.getOverlayModuleForRead() != null) { script.setIsMaybeUsingRefinements(); } // We link IRScope to StaticScope because we may add additional variables (like %block). During execution // we end up growing dynamicscope potentially based on any changes made. staticScope.setIRScope(script); BeginEndInterpreterContext ic = (BeginEndInterpreterContext) IRBuilder.topIRBuilder(runtime.getIRManager(), script).buildEvalRoot(rootNode); if (IRRuntimeHelpers.isDebug()) LOG.info(script.debugOutput()); return ic; } }
private static BeginEndInterpreterContext prepareIC(ThreadContext context, DynamicScope evalScope, IRubyObject src, String file, int lineNumber, EvalType evalType) { Ruby runtime = context.runtime; IRScope containingIRScope = evalScope.getStaticScope().getEnclosingScope().getIRScope(); RootNode rootNode = (RootNode) runtime.parseEval(src.convertToString().getByteList(), file, evalScope, lineNumber); StaticScope staticScope = evalScope.getStaticScope(); // Top-level script! IREvalScript script = new IREvalScript(runtime.getIRManager(), containingIRScope, file, lineNumber, staticScope, evalType); // enable refinements if incoming scope already has an overlay active if (staticScope.getOverlayModuleForRead() != null) { script.setIsMaybeUsingRefinements(); } // We link IRScope to StaticScope because we may add additional variables (like %block). During execution // we end up growing dynamicscope potentially based on any changes made. staticScope.setIRScope(script); BeginEndInterpreterContext ic = (BeginEndInterpreterContext) IRBuilder.topIRBuilder(runtime.getIRManager(), script).buildEvalRoot(rootNode); if (IRRuntimeHelpers.isDebug()) LOG.info(script.debugOutput()); return ic; } }
LOG.info(name + "\tretrieved and cached from scope (searchConst) " + staticScope.getIRScope());
LOG.info(name + "\tretrieved and cached from scope (searchConst) " + staticScope.getIRScope());