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