@Override public LocalVariable getNewFlipStateVariable() { ByteList flipVarName = new ByteList(("%flip_" + allocateNextPrefixedName("%flip")).getBytes()); RubySymbol name = getManager().getRuntime().newSymbol(flipVarName); LocalVariable v = lookupExistingLVar(name); return v == null ? getNewLocalVariable(name, 0) : v; }
@Override public Label getNewLabel() { return getNewLabel("EV" + closureId + "_LBL"); }
@Override public LocalVariable getNewFlipStateVariable() { return getLocalVariable("%flip_" + allocateNextPrefixedName("%flip"), 0); }
public IREvalScript buildEvalRoot(StaticScope staticScope, IRScope containingScope, String file, int lineNumber, RootNode rootNode) { // Top-level script! IREvalScript script = new IREvalScript(manager, containingScope, file, lineNumber, staticScope); // Debug info: record line number script.addInstr(new LineNumberInstr(script, lineNumber)); // Set %current_scope = <current-scope> // Set %current_module = <current-module> script.addInstr(new CopyInstr(script.getCurrentScopeVariable(), new CurrentScope(script))); script.addInstr(new CopyInstr(script.getCurrentModuleVariable(), new ScopeModule(script))); // Build IR for the tree and return the result of the expression tree Operand rval = rootNode.getBodyNode() == null ? manager.getNil() : build(rootNode.getBodyNode(), script); script.addInstr(new ReturnInstr(rval)); return script; }
public static IRubyObject interpretCommonEval(Ruby runtime, String file, int lineNumber, String backtraceName, RootNode rootNode, IRubyObject self, Block block) { // SSS FIXME: Is this required here since the IR version cannot change from eval-to-eval? This is much more of a global setting. boolean is_1_9 = runtime.is1_9(); if (is_1_9) IRBuilder.setRubyVersion("1.9"); StaticScope ss = rootNode.getStaticScope(); IRScope containingIRScope = getEvalContainerScope(runtime, ss); IREvalScript evalScript = IRBuilder.createIRBuilder(runtime, runtime.getIRManager()).buildEvalRoot(ss, containingIRScope, file, lineNumber, rootNode); evalScript.prepareForInterpretation(false); // evalScript.runCompilerPass(new CallSplitter()); ThreadContext context = runtime.getCurrentContext(); runBeginEndBlocks(evalScript.getBeginBlocks(), context, self, null); // FIXME: No temp vars yet right? IRubyObject rv = evalScript.call(context, self, evalScript.getStaticScope().getModule(), rootNode.getScope(), block, backtraceName); runBeginEndBlocks(evalScript.getEndBlocks(), context, self, null); // FIXME: No temp vars right? return rv; }
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; } }
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, DynamicScope evalScope, Block block, String backtraceName) { if (IRRuntimeHelpers.isDebug()) { LOG.info("CFG:\n" + cfg()); } try { context.pushScope(evalScope); // Since IR introduces additional local vars, we may need to grow the dynamic scope. // To do that, IREvalScript has to tell the dyn-scope how many local vars there are. // Since the same static scope (the scope within which the eval string showed up) // might be shared by multiple eval-scripts, we cannot 'setIRScope(this)' once and // forget about it. We need to set this right before we are ready to grow the // dynamic scope local var space. ((IRStaticScope)getStaticScope()).setIRScope(this); evalScope.growIfNeeded(); // FIXME: Do not push new empty arg array in every time return Interpreter.INTERPRET_EVAL(context, self, this, clazz, new IRubyObject[] {}, backtraceName, block, null); } finally { context.popScope(); } }
public static IRScope createScope(IRManager manager, IRScopeType type, RubySymbol name, int line, IRScope lexicalParent, Signature signature, StaticScope staticScope) { switch (type) { case CLASS_BODY: return new IRClassBody(manager, lexicalParent, name, line, staticScope); case METACLASS_BODY: return new IRMetaClassBody(manager, lexicalParent, manager.getMetaClassName(), line, staticScope); case INSTANCE_METHOD: return new IRMethod(manager, lexicalParent, null, name, true, line, staticScope, false); case CLASS_METHOD: return new IRMethod(manager, lexicalParent, null, name, false, line, staticScope, false); case MODULE_BODY: return new IRModuleBody(manager, lexicalParent, name, line, staticScope); case SCRIPT_BODY: return new IRScriptBody(manager, name, staticScope); case FOR: return new IRFor(manager, lexicalParent, line, staticScope, signature); case CLOSURE: return new IRClosure(manager, lexicalParent, line, staticScope, signature); case EVAL_SCRIPT: // SSS FIXME: This is broken right now -- the isModuleEval arg has to be persisted and then read back. return new IREvalScript(manager, lexicalParent, lexicalParent.getFileName(), line, staticScope, EvalType.NONE); } throw new RuntimeException("No such scope type: " + type); } }
public IREvalScript buildEvalRoot(StaticScope staticScope, IRScope containingScope, String file, int lineNumber, RootNode rootNode) { // Top-level script! IREvalScript script = new IREvalScript(manager, containingScope, file, lineNumber, staticScope); // Debug info: record line number script.addInstr(new LineNumberInstr(script, lineNumber)); // Set %current_scope = <current-scope> // Set %current_module = <current-module> script.addInstr(new CopyInstr(script.getCurrentScopeVariable(), new CurrentScope(script))); script.addInstr(new CopyInstr(script.getCurrentModuleVariable(), new ScopeModule(script))); // Build IR for the tree and return the result of the expression tree Operand rval = rootNode.getBodyNode() == null ? manager.getNil() : build(rootNode.getBodyNode(), script); script.addInstr(new ReturnInstr(rval)); return script; }
public static IRubyObject interpretCommonEval(Ruby runtime, String file, int lineNumber, String backtraceName, RootNode rootNode, IRubyObject self, Block block) { // SSS FIXME: Is this required here since the IR version cannot change from eval-to-eval? This is much more of a global setting. boolean is_1_9 = runtime.is1_9(); if (is_1_9) IRBuilder.setRubyVersion("1.9"); StaticScope ss = rootNode.getStaticScope(); IRScope containingIRScope = getEvalContainerScope(runtime, ss); IREvalScript evalScript = IRBuilder.createIRBuilder(runtime, runtime.getIRManager()).buildEvalRoot(ss, containingIRScope, file, lineNumber, rootNode); evalScript.prepareForInterpretation(false); // evalScript.runCompilerPass(new CallSplitter()); ThreadContext context = runtime.getCurrentContext(); runBeginEndBlocks(evalScript.getBeginBlocks(), context, self, null); // FIXME: No temp vars yet right? IRubyObject rv = evalScript.call(context, self, evalScript.getStaticScope().getModule(), rootNode.getScope(), block, backtraceName); runBeginEndBlocks(evalScript.getEndBlocks(), context, self, null); // FIXME: No temp vars right? return rv; }
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; } }
@Override public LocalVariable getNewFlipStateVariable() { return getLocalVariable("%flip_" + allocateNextPrefixedName("%flip"), 0); }
public IRubyObject call(ThreadContext context, IRubyObject self, RubyModule clazz, DynamicScope evalScope, Block block, String backtraceName) { if (IRRuntimeHelpers.isDebug()) { LOG.info("CFG:\n" + cfg()); } try { context.pushScope(evalScope); // Since IR introduces additional local vars, we may need to grow the dynamic scope. // To do that, IREvalScript has to tell the dyn-scope how many local vars there are. // Since the same static scope (the scope within which the eval string showed up) // might be shared by multiple eval-scripts, we cannot 'setIRScope(this)' once and // forget about it. We need to set this right before we are ready to grow the // dynamic scope local var space. ((IRStaticScope)getStaticScope()).setIRScope(this); evalScope.growIfNeeded(); // FIXME: Do not push new empty arg array in every time return Interpreter.INTERPRET_EVAL(context, self, this, clazz, new IRubyObject[] {}, backtraceName, block, null); } finally { context.popScope(); } }
public static IRScope createScope(IRManager manager, IRScopeType type, RubySymbol name, int line, IRScope lexicalParent, Signature signature, StaticScope staticScope) { switch (type) { case CLASS_BODY: return new IRClassBody(manager, lexicalParent, name, line, staticScope); case METACLASS_BODY: return new IRMetaClassBody(manager, lexicalParent, manager.getMetaClassName(), line, staticScope); case INSTANCE_METHOD: return new IRMethod(manager, lexicalParent, null, name, true, line, staticScope, false); case CLASS_METHOD: return new IRMethod(manager, lexicalParent, null, name, false, line, staticScope, false); case MODULE_BODY: return new IRModuleBody(manager, lexicalParent, name, line, staticScope); case SCRIPT_BODY: return new IRScriptBody(manager, name, staticScope); case FOR: return new IRFor(manager, lexicalParent, line, staticScope, signature); case CLOSURE: return new IRClosure(manager, lexicalParent, line, staticScope, signature); case EVAL_SCRIPT: // SSS FIXME: This is broken right now -- the isModuleEval arg has to be persisted and then read back. return new IREvalScript(manager, lexicalParent, lexicalParent.getFileName(), line, staticScope, EvalType.NONE); } throw new RuntimeException("No such scope type: " + type); } }
@Override public LocalVariable getNewFlipStateVariable() { ByteList flipVarName = new ByteList(("%flip_" + allocateNextPrefixedName("%flip")).getBytes()); RubySymbol name = getManager().getRuntime().newSymbol(flipVarName); LocalVariable v = lookupExistingLVar(name); return v == null ? getNewLocalVariable(name, 0) : v; }
@Override public Label getNewLabel() { return getNewLabel("EV" + closureId + "_LBL"); }
@Override public Label getNewLabel() { return getNewLabel("EV" + closureId + "_LBL"); }
@Override public Label getNewLabel() { return getNewLabel("EV" + closureId + "_LBL"); }