public static InterpreterContext buildRoot(IRManager manager, RootNode rootNode) { // FIXME: This filename should switch to ByteList String file = rootNode.getFile(); if (file == null) file = "(anon)"; IRScriptBody script = new IRScriptBody(manager, manager.runtime.newSymbol(file), rootNode.getStaticScope()); return topIRBuilder(manager, script).buildRootInner(rootNode); }
public static InterpreterContext buildRoot(IRManager manager, RootNode rootNode) { // FIXME: This filename should switch to ByteList String file = rootNode.getFile(); if (file == null) file = "(anon)"; IRScriptBody script = new IRScriptBody(manager, manager.runtime.newSymbol(file), rootNode.getStaticScope()); return topIRBuilder(manager, script).buildRootInner(rootNode); }
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 IRMethod loadInternalMethod(ThreadContext context, IRubyObject self, String method) { try { RubyModule type = self.getMetaClass(); String fileName = "classpath:/jruby/ruby_implementations/" + type + "/" + method + ".rb"; FileResource file = JRubyFile.createResourceAsFile(context.runtime, fileName); Node parseResult = parse(context, file, fileName); IScopingNode scopeNode = (IScopingNode) parseResult.childNodes().get(0); scopeNode.getScope().setModule(type); DefNode defNode = (DefNode) scopeNode.getBodyNode(); IRScriptBody script = new IRScriptBody(this, runtime.newSymbol(parseResult.getFile()), ((RootNode) parseResult).getStaticScope()); IRModuleBody containingScope; if (scopeNode instanceof ModuleNode) { containingScope = new IRModuleBody(this, script, scopeNode.getCPath().getName(), 0, scopeNode.getScope()); } else { containingScope = new IRClassBody(this, script, scopeNode.getCPath().getName(), 0, scopeNode.getScope()); } IRMethod newMethod = new IRMethod(this, containingScope, defNode, context.runtime.newSymbol(method), true, 0, defNode.getScope(), false); newMethod.prepareForCompilation(); return newMethod; } catch (IOException e) { e.printStackTrace(); // FIXME: More elegantly handle broken internal implementations return null; } }
public IRMethod loadInternalMethod(ThreadContext context, IRubyObject self, String method) { try { RubyModule type = self.getMetaClass(); String fileName = "classpath:/jruby/ruby_implementations/" + type + "/" + method + ".rb"; FileResource file = JRubyFile.createResourceAsFile(context.runtime, fileName); Node parseResult = parse(context, file, fileName); IScopingNode scopeNode = (IScopingNode) parseResult.childNodes().get(0); scopeNode.getScope().setModule(type); DefNode defNode = (DefNode) scopeNode.getBodyNode(); IRScriptBody script = new IRScriptBody(this, runtime.newSymbol(parseResult.getFile()), ((RootNode) parseResult).getStaticScope()); IRModuleBody containingScope; if (scopeNode instanceof ModuleNode) { containingScope = new IRModuleBody(this, script, scopeNode.getCPath().getName(), 0, scopeNode.getScope()); } else { containingScope = new IRClassBody(this, script, scopeNode.getCPath().getName(), 0, scopeNode.getScope()); } IRMethod newMethod = new IRMethod(this, containingScope, defNode, context.runtime.newSymbol(method), true, 0, defNode.getScope(), false); newMethod.prepareForCompilation(); return newMethod; } catch (IOException e) { e.printStackTrace(); // FIXME: More elegantly handle broken internal implementations return null; } }
public IRScope buildRoot(RootNode rootNode) { String file = rootNode.getPosition().getFile(); StaticScope staticScope = rootNode.getStaticScope(); // Top-level script! IRScriptBody script = new IRScriptBody(manager, "__file__", file, staticScope); script.addInstr(new ReceiveSelfInstr(script.getSelf())); // 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 script.addInstr(new ReturnInstr(build(rootNode.getBodyNode(), script))); return script; }
public IRScope buildRoot(RootNode rootNode) { String file = rootNode.getPosition().getFile(); StaticScope staticScope = rootNode.getStaticScope(); // Top-level script! IRScriptBody script = new IRScriptBody(manager, "__file__", file, staticScope); script.addInstr(new ReceiveSelfInstr(script.getSelf())); // 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 script.addInstr(new ReturnInstr(build(rootNode.getBodyNode(), script))); return script; }
IRScope top = new IRScriptBody(irManager, newSymbol(""), context.getCurrentScope().getStaticScope()); top.allocateInterpreterContext(new ArrayList<Instr>());
IRScope top = new IRScriptBody(irManager, newSymbol(""), context.getCurrentScope().getStaticScope()); top.allocateInterpreterContext(new ArrayList<Instr>());