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 Operand buildModule(ModuleNode moduleNode) { Colon3Node cpath = moduleNode.getCPath(); RubySymbol moduleName = cpath.getName(); Operand container = getContainerFromCPath(cpath); IRModuleBody body = new IRModuleBody(manager, scope, moduleName, moduleNode.getLine(), moduleNode.getScope()); Variable moduleVar = addResultInstr(new DefineModuleInstr(createTemporaryVariable(), body, container)); Variable processBodyResult = addResultInstr(new ProcessModuleBodyInstr(createTemporaryVariable(), moduleVar, NullBlock.INSTANCE)); newIRBuilder(manager, body).buildModuleOrClassBody(moduleNode.getBodyNode(), moduleNode.getLine(), moduleNode.getEndLine()); return processBodyResult; }
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 Operand buildModule(ModuleNode moduleNode) { Colon3Node cpath = moduleNode.getCPath(); RubySymbol moduleName = cpath.getName(); Operand container = getContainerFromCPath(cpath); IRModuleBody body = new IRModuleBody(manager, scope, moduleName, moduleNode.getLine(), moduleNode.getScope()); Variable moduleVar = addResultInstr(new DefineModuleInstr(createTemporaryVariable(), body, container)); Variable processBodyResult = addResultInstr(new ProcessModuleBodyInstr(createTemporaryVariable(), moduleVar, NullBlock.INSTANCE)); newIRBuilder(manager, body).buildModuleOrClassBody(moduleNode.getBodyNode(), moduleNode.getLine(), moduleNode.getEndLine()); return processBodyResult; }
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 Operand buildModule(ModuleNode moduleNode, IRScope s) { Colon3Node cpath = moduleNode.getCPath(); String moduleName = cpath.getName(); Operand container = getContainerFromCPath(cpath, s); // Build the new module IRModuleBody m = new IRModuleBody(manager, s, moduleName, moduleNode.getPosition().getLine(), moduleNode.getScope()); Variable moduleBody = s.getNewTemporaryVariable(); s.addInstr(new DefineModuleInstr(moduleBody, m, container)); Variable ret = s.getNewTemporaryVariable(); s.addInstr(new ProcessModuleBodyInstr(ret, moduleBody)); m.addInstr(new ReceiveSelfInstr(m.getSelf())); // Set %current_scope = <c> // Set %current_module = module<c> m.addInstr(new CopyInstr(m.getCurrentScopeVariable(), new CurrentScope(m))); m.addInstr(new CopyInstr(m.getCurrentModuleVariable(), new ScopeModule(m))); // Create a new nested builder to ensure this gets its own IR builder state Operand rv = newIRBuilder(manager).build(moduleNode.getBodyNode(), m); if (rv != null) m.addInstr(new ReturnInstr(rv)); return ret; }
public Operand buildModule(ModuleNode moduleNode, IRScope s) { Colon3Node cpath = moduleNode.getCPath(); String moduleName = cpath.getName(); Operand container = getContainerFromCPath(cpath, s); // Build the new module IRModuleBody m = new IRModuleBody(manager, s, moduleName, moduleNode.getPosition().getLine(), moduleNode.getScope()); Variable moduleBody = s.getNewTemporaryVariable(); s.addInstr(new DefineModuleInstr(moduleBody, m, container)); Variable ret = s.getNewTemporaryVariable(); s.addInstr(new ProcessModuleBodyInstr(ret, moduleBody)); m.addInstr(new ReceiveSelfInstr(m.getSelf())); // Set %current_scope = <c> // Set %current_module = module<c> m.addInstr(new CopyInstr(m.getCurrentScopeVariable(), new CurrentScope(m))); m.addInstr(new CopyInstr(m.getCurrentModuleVariable(), new ScopeModule(m))); // Create a new nested builder to ensure this gets its own IR builder state Operand rv = newIRBuilder(manager).build(moduleNode.getBodyNode(), m); if (rv != null) m.addInstr(new ReturnInstr(rv)); return ret; }