Skip to content

Commit

Permalink
Fix precompiled execution broken by MethodNodes.
Browse files Browse the repository at this point in the history
Precompiled method definition does not have access to an AST, so
there's no way to build a MethodNodes object usable by Truffle. We
will null out MethodNodes for now and look to (possibly) add AST
to precompiled classes for #1395.
  • Loading branch information
headius committed Jan 10, 2014
1 parent 5588b7c commit 778ab12
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Expand Up @@ -2723,10 +2723,10 @@ public void defineNewMethod(String name, int methodArity, StaticScope scope,

if (receiver != null) {
invokeUtilityMethod("defs", sig(IRubyObject.class,
params(ThreadContext.class, IRubyObject.class, IRubyObject.class, Object.class, String.class, String.class, StaticScope.class, int.class, String.class, int.class, CallConfiguration.class, String.class, MethodNodes.class)));
params(ThreadContext.class, IRubyObject.class, IRubyObject.class, Object.class, String.class, String.class, StaticScope.class, int.class, String.class, int.class, CallConfiguration.class, String.class)));
} else {
invokeUtilityMethod("def", sig(IRubyObject.class,
params(ThreadContext.class, IRubyObject.class, Object.class, String.class, String.class, StaticScope.class, int.class, String.class, int.class, CallConfiguration.class, String.class, MethodNodes.class)));
params(ThreadContext.class, IRubyObject.class, Object.class, String.class, String.class, StaticScope.class, int.class, String.class, int.class, CallConfiguration.class, String.class)));
}

script.addInvokerDescriptor(name, newMethodName, methodArity, scope, inspector.getCallConfig(), filename, line, methodNodes);
Expand Down
Expand Up @@ -239,6 +239,12 @@ public String[] getParameterList() {
}

}

// Called by Class.newInstance in InvocationMethodCompiler and precompiled method subclasses
public CompiledMethod() {
// TODO: Need to have access to AST for recompilation. See #1395
this(null);
}

protected CompiledMethod(MethodNodes methodNodes) {
this.methodNodes = methodNodes;
Expand Down
Expand Up @@ -19,7 +19,6 @@ public class MethodNodes {

public MethodNodes(ArgsNode argsNode, Node bodyNode) {
assert argsNode != null;
assert bodyNode != null;

this.argsNode = argsNode;
this.bodyNode = bodyNode;
Expand Down
16 changes: 14 additions & 2 deletions core/src/main/java/org/jruby/runtime/Helpers.java
Expand Up @@ -285,9 +285,15 @@ public static Block createSharedScopeBlock(ThreadContext context, IRubyObject se
return CompiledSharedScopeBlock.newCompiledSharedScopeClosure(context, self, Arity.createArity(arity),
context.getCurrentScope(), callback, hasMultipleArgsHead, argsNodeType);
}

public static IRubyObject def(ThreadContext context, IRubyObject self, Object scriptObject, String rubyName, String javaName, StaticScope scope,
int arity, String filename, int line, CallConfiguration callConfig, String parameterDesc, MethodNodes methodNodes) {
int arity, String filename, int line, CallConfiguration callConfig, String parameterDesc) {
// TODO: Need to have access to AST for recompilation. See #1395
return def(context, self, scriptObject, rubyName, javaName, scope, arity, filename, line, callConfig, parameterDesc, null);
}

public static IRubyObject def(ThreadContext context, IRubyObject self, Object scriptObject, String rubyName, String javaName, StaticScope scope,
int arity, String filename, int line, CallConfiguration callConfig, String parameterDesc, MethodNodes methodNodes) {
Class compiledClass = scriptObject.getClass();
Ruby runtime = context.runtime;

Expand All @@ -306,6 +312,12 @@ rubyName, containingClass, new SimpleSourcePosition(filename, line), arity, scop
return addInstanceMethod(containingClass, rubyName, method, currVisibility, context, runtime);
}

public static IRubyObject defs(ThreadContext context, IRubyObject self, IRubyObject receiver, Object scriptObject, String rubyName, String javaName, StaticScope scope,
int arity, String filename, int line, CallConfiguration callConfig, String parameterDesc) {
// TODO: Need to have access to AST for recompilation. See #1395
return defs(context, self, receiver, scriptObject, rubyName, javaName, scope, arity, filename, line, callConfig, parameterDesc, null);
}

public static IRubyObject defs(ThreadContext context, IRubyObject self, IRubyObject receiver, Object scriptObject, String rubyName, String javaName, StaticScope scope,
int arity, String filename, int line, CallConfiguration callConfig, String parameterDesc, MethodNodes methodNodes) {
Class compiledClass = scriptObject.getClass();
Expand Down

0 comments on commit 778ab12

Please sign in to comment.