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 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 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; }
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; } }