Skip to content

Commit

Permalink
[Truffle] Re-use Module#Include implementation for main.include.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisseaton committed Oct 3, 2014
1 parent 7d97cfc commit cf817d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
15 changes: 6 additions & 9 deletions core/src/main/java/org/jruby/truffle/nodes/core/MainNodes.java
Expand Up @@ -12,22 +12,22 @@
import com.oracle.truffle.api.source.*;
import com.oracle.truffle.api.dsl.*;
import com.oracle.truffle.api.frame.VirtualFrame;
import org.jruby.truffle.nodes.RubyNode;
import org.jruby.truffle.nodes.dispatch.DispatchHeadNode;
import org.jruby.truffle.runtime.*;
import org.jruby.truffle.runtime.core.*;

@CoreClass(name = "main")
public abstract class MainNodes {

@CoreMethod(names = "include", isSplatted = true, minArgs = 1)
@CoreMethod(names = "include", isSplatted = true, needsSelf = false, minArgs = 1)
public abstract static class IncludeNode extends CoreMethodNode {

@Child protected DispatchHeadNode includeNode;
@Child protected ModuleNodes.IncludeNode includeNode;

public IncludeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
includeNode = new DispatchHeadNode(context);

includeNode = ModuleNodesFactory.IncludeNodeFactory.create(context, sourceSection, new RubyNode[]{null, null});

This comment has been minimized.

Copy link
@chrisseaton

chrisseaton Oct 3, 2014

Author Contributor

@eregon You need a RubyNode[] here with as many nulls as there are arguments to the specialisation.

}

public IncludeNode(IncludeNode prev) {
Expand All @@ -38,11 +38,8 @@ public IncludeNode(IncludeNode prev) {
@Specialization
public NilPlaceholder include(VirtualFrame frame, Object[] args) {
notDesignedForCompilation();

RubyClass object = getContext().getCoreLibrary().getObjectClass();

// TODO: MRI does this call statically
return (NilPlaceholder) includeNode.call(frame, object, "include", null, args);
final RubyClass object = getContext().getCoreLibrary().getObjectClass();
return includeNode.executeInclude(frame, object, args);
}
}

Expand Down
Expand Up @@ -654,6 +654,8 @@ public IncludeNode(IncludeNode prev) {
appendFeaturesNode = prev.appendFeaturesNode;
}

public abstract NilPlaceholder executeInclude(VirtualFrame frame, RubyModule module, Object[] args);

This comment has been minimized.

Copy link
@chrisseaton

chrisseaton Oct 3, 2014

Author Contributor

@eregon The DSL will implement this method for us.


@Specialization
public NilPlaceholder include(VirtualFrame frame, RubyModule module, Object[] args) {
notDesignedForCompilation();
Expand Down
3 changes: 3 additions & 0 deletions spec/truffle/tags/language/constants_tags.txt
Expand Up @@ -31,3 +31,6 @@ fails:Constant resolution within methods with dynamically assigned constants doe
fails:Module#public_constant marked constants in a module is defined? with A::B form
fails:Module#public_constant marked constants in a class is defined? with A::B form
fails:Literal (A::X) constant resolution with statically assigned constants searches Object if a toplevel qualifier (::X) is given
fails:Literal (A::X) constant resolution with statically assigned constants searches a module included in the superclass
fails:Constant resolution within methods with statically assigned constants searches a module included in the superclass
fails:Constant resolution within methods with statically assigned constants searches Object as a lexical scope only if Object is explicitly opened

1 comment on commit cf817d7

@chrisseaton
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@eregon This caused some extra specs to fail - but sometimes specs fail because they were passing for the wrong reason.

Please sign in to comment.