@Override public String toString() { return super.toString() + "(" + newIRClassBody.getName() + ", " + container + ", " + superClass + ", " + newIRClassBody.getFileName() + ")"; }
@Override public String[] toStringNonOperandArgs() { return new String[] {"name: " + newIRClassBody.getId() }; }
public DefineClassInstr(Variable result, IRClassBody newIRClassBody, Operand container, Operand superClass) { super(Operation.DEF_CLASS); assert result != null: "DefineClassInstr result is null"; this.container = container; this.superClass = superClass == null ? newIRClassBody.getManager().getNil() : superClass; this.newIRClassBody = newIRClassBody; this.result = result; }
/** * Build a new class and add it to the current scope (s). */ public Operand buildClass(ClassNode classNode, IRScope s) { Node superNode = classNode.getSuperNode(); Colon3Node cpath = classNode.getCPath(); Operand superClass = (superNode == null) ? null : build(superNode, s); String className = cpath.getName(); Operand container = getContainerFromCPath(cpath, s); IRClassBody c = new IRClassBody(manager, s, className, classNode.getPosition().getLine(), classNode.getScope()); Variable classBody = s.getNewTemporaryVariable(); s.addInstr(new DefineClassInstr(classBody, c, container, superClass)); Variable ret = s.getNewTemporaryVariable(); s.addInstr(new ProcessModuleBodyInstr(ret, classBody)); c.addInstr(new ReceiveSelfInstr(c.getSelf())); // Set %current_scope = <c> // Set %current_module = module<c> c.addInstr(new CopyInstr(c.getCurrentScopeVariable(), new CurrentScope(c))); c.addInstr(new CopyInstr(c.getCurrentModuleVariable(), new ScopeModule(c))); // Create a new nested builder to ensure this gets its own IR builder state Operand rv = newIRBuilder(manager).build(classNode.getBodyNode(), c); if (rv != null) c.addInstr(new ReturnInstr(rv)); return ret; }
public IRManager(Ruby runtime, RubyInstanceConfig config) { this.runtime = runtime; this.config = config; object = new IRClassBody(this, null, runtime.newSymbol(OBJECT), 0, null); compilerPasses = CompilerPass.getPassesFromString(RubyInstanceConfig.IR_COMPILER_PASSES, DEFAULT_BUILD_PASSES); inliningCompilerPasses = CompilerPass.getPassesFromString(RubyInstanceConfig.IR_COMPILER_PASSES, DEFAULT_INLINING_COMPILER_PASSES); jitPasses = CompilerPass.getPassesFromString(RubyInstanceConfig.IR_JIT_PASSES, DEFAULT_JIT_PASSES); safePasses = CompilerPass.getPassesFromString(null, SAFE_COMPILER_PASSES); if (RubyInstanceConfig.IR_DEBUG_IGV != null) instrsListener = new IGVInstrListener(); }
@Override public void DefineClassInstr(DefineClassInstr defineclassinstr) { IRClassBody newIRClassBody = defineclassinstr.getNewIRClassBody(); StaticScope scope = newIRClassBody.getStaticScope(); if (scope.getRequiredArgs() > 3 || scope.getRestArg() >= 0 || scope.getOptionalArgs() != 0) { throw new RuntimeException("can't compile variable method: " + this); a.ldc(newIRClassBody.getName()); a.ldc(newIRClassBody.getFileName()); a.ldc(newIRClassBody.getLineNumber()); a.ldc(newIRClassBody.getName()); // class name m.loadLocal(2); // self
private RubyModule newClass(ThreadContext context, IRubyObject self, RubyModule classContainer, DynamicScope currDynScope, Object[] temp) { if (newIRClassBody instanceof IRMetaClassBody) return classContainer.getMetaClass(); RubyClass sc; if (superClass == context.runtime.getIRManager().getNil()) { sc = null; } else { Object o = superClass.retrieve(context, self, currDynScope, temp); if (!(o instanceof RubyClass)) { throw context.runtime.newTypeError("superclass must be Class (" + o + " given)"); } sc = (RubyClass) o; } return classContainer.defineOrGetClassUnder(newIRClassBody.getName(), sc); }
/** * Build a new class and add it to the current scope (s). */ public Operand buildClass(ClassNode classNode, IRScope s) { Node superNode = classNode.getSuperNode(); Colon3Node cpath = classNode.getCPath(); Operand superClass = (superNode == null) ? null : build(superNode, s); String className = cpath.getName(); Operand container = getContainerFromCPath(cpath, s); IRClassBody c = new IRClassBody(manager, s, className, classNode.getPosition().getLine(), classNode.getScope()); Variable classBody = s.getNewTemporaryVariable(); s.addInstr(new DefineClassInstr(classBody, c, container, superClass)); Variable ret = s.getNewTemporaryVariable(); s.addInstr(new ProcessModuleBodyInstr(ret, classBody)); c.addInstr(new ReceiveSelfInstr(c.getSelf())); // Set %current_scope = <c> // Set %current_module = module<c> c.addInstr(new CopyInstr(c.getCurrentScopeVariable(), new CurrentScope(c))); c.addInstr(new CopyInstr(c.getCurrentModuleVariable(), new ScopeModule(c))); // Create a new nested builder to ensure this gets its own IR builder state Operand rv = newIRBuilder(manager).build(classNode.getBodyNode(), c); if (rv != null) c.addInstr(new ReturnInstr(rv)); return ret; }
public IRManager(Ruby runtime, RubyInstanceConfig config) { this.runtime = runtime; this.config = config; object = new IRClassBody(this, null, runtime.newSymbol(OBJECT), 0, null); compilerPasses = CompilerPass.getPassesFromString(RubyInstanceConfig.IR_COMPILER_PASSES, DEFAULT_BUILD_PASSES); inliningCompilerPasses = CompilerPass.getPassesFromString(RubyInstanceConfig.IR_COMPILER_PASSES, DEFAULT_INLINING_COMPILER_PASSES); jitPasses = CompilerPass.getPassesFromString(RubyInstanceConfig.IR_JIT_PASSES, DEFAULT_JIT_PASSES); safePasses = CompilerPass.getPassesFromString(null, SAFE_COMPILER_PASSES); if (RubyInstanceConfig.IR_DEBUG_IGV != null) instrsListener = new IGVInstrListener(); }
@Override public void DefineClassInstr(DefineClassInstr defineclassinstr) { IRClassBody newIRClassBody = defineclassinstr.getNewIRClassBody(); StaticScope scope = newIRClassBody.getStaticScope(); if (scope.getRequiredArgs() > 3 || scope.getRestArg() >= 0 || scope.getOptionalArgs() != 0) { throw new RuntimeException("can't compile variable method: " + this); a.ldc(newIRClassBody.getName()); a.ldc(newIRClassBody.getFileName()); a.ldc(newIRClassBody.getLineNumber()); a.ldc(newIRClassBody.getName()); // class name m.loadLocal(2); // self
private RubyModule newClass(ThreadContext context, IRubyObject self, RubyModule classContainer, DynamicScope currDynScope, Object[] temp) { if (newIRClassBody instanceof IRMetaClassBody) return classContainer.getMetaClass(); RubyClass sc; if (superClass == context.runtime.getIRManager().getNil()) { sc = null; } else { Object o = superClass.retrieve(context, self, currDynScope, temp); if (!(o instanceof RubyClass)) { throw context.runtime.newTypeError("superclass must be Class (" + o + " given)"); } sc = (RubyClass) o; } return classContainer.defineOrGetClassUnder(newIRClassBody.getName(), sc); }
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 String toString() { return super.toString() + "(" + newIRClassBody.getName() + ", " + container + ", " + superClass + ", " + newIRClassBody.getFileName() + ")"; }
public DefineClassInstr(Variable result, IRClassBody newIRClassBody, Operand container, Operand superClass) { super(Operation.DEF_CLASS); assert result != null: "DefineClassInstr result is null"; this.container = container; this.superClass = superClass == null ? newIRClassBody.getManager().getNil() : superClass; this.newIRClassBody = newIRClassBody; this.result = result; }
@Override public String[] toStringNonOperandArgs() { return new String[] {"name: " + newIRClassBody.getId() }; }
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; } }
/** * Build a new class and add it to the current scope (s). */ public Operand buildClass(ClassNode classNode) { Node superNode = classNode.getSuperNode(); Colon3Node cpath = classNode.getCPath(); Operand superClass = (superNode == null) ? null : build(superNode); RubySymbol className = cpath.getName(); Operand container = getContainerFromCPath(cpath); IRClassBody body = new IRClassBody(manager, scope, className, classNode.getLine(), classNode.getScope()); Variable classVar = addResultInstr(new DefineClassInstr(createTemporaryVariable(), body, container, superClass)); Variable processBodyResult = addResultInstr(new ProcessModuleBodyInstr(createTemporaryVariable(), classVar, NullBlock.INSTANCE)); newIRBuilder(manager, body).buildModuleOrClassBody(classNode.getBodyNode(), classNode.getLine(), classNode.getEndLine()); return processBodyResult; }
/** * Build a new class and add it to the current scope (s). */ public Operand buildClass(ClassNode classNode) { Node superNode = classNode.getSuperNode(); Colon3Node cpath = classNode.getCPath(); Operand superClass = (superNode == null) ? null : build(superNode); RubySymbol className = cpath.getName(); Operand container = getContainerFromCPath(cpath); IRClassBody body = new IRClassBody(manager, scope, className, classNode.getLine(), classNode.getScope()); Variable classVar = addResultInstr(new DefineClassInstr(createTemporaryVariable(), body, container, superClass)); Variable processBodyResult = addResultInstr(new ProcessModuleBodyInstr(createTemporaryVariable(), classVar, NullBlock.INSTANCE)); newIRBuilder(manager, body).buildModuleOrClassBody(classNode.getBodyNode(), classNode.getLine(), classNode.getEndLine()); return processBodyResult; }