Skip to content

Commit

Permalink
[Truffle] Call #to_path for require features.
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Jul 11, 2015
1 parent 43561c1 commit 63d867b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/kernel/require_tags.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
fails:Kernel#require (path resolution) calls #to_str on non-String objects
fails:Kernel#require (path resolution) raises a TypeError if #to_str does not return a String
fails:Kernel#require (path resolution) calls #to_path on non-String objects
fails:Kernel#require (path resolution) calls #to_path on a String
fails:Kernel#require (path resolution) calls #to_str on non-String objects returned by #to_path
fails:Kernel#require (path resolution) loads a ../ relative path from the current working directory with empty $LOAD_PATH
fails:Kernel#require (path resolution) loads a ../ relative path from the current working directory with non-empty $LOAD_PATH
Expand Down Expand Up @@ -36,7 +35,6 @@ fails:Kernel#require (shell expansion) performs tilde expansion on a non-extensi
fails:Kernel.require (path resolution) calls #to_str on non-String objects
fails:Kernel.require (path resolution) raises a TypeError if #to_str does not return a String
fails:Kernel.require (path resolution) calls #to_path on non-String objects
fails:Kernel.require (path resolution) calls #to_path on a String
fails:Kernel.require (path resolution) calls #to_str on non-String objects returned by #to_path
fails:Kernel.require (path resolution) loads a ../ relative path from the current working directory with empty $LOAD_PATH
fails:Kernel.require (path resolution) loads a ../ relative path from the current working directory with non-empty $LOAD_PATH
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected Object missingConstant(VirtualFrame frame, RubyModule module, String n
}

protected RequireNode createRequireNode() {
return KernelNodesFactory.RequireNodeFactory.create(getContext(), getSourceSection(), new RubyNode[] {});
return KernelNodesFactory.RequireNodeFactory.create(getContext(), getSourceSection(), null);
}

protected boolean isValidConstantName(String name) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.oracle.truffle.api.source.Source;
import com.oracle.truffle.api.source.SourceSection;
import com.oracle.truffle.api.utilities.ConditionProfile;

import org.jcodings.Encoding;
import org.jcodings.specific.USASCIIEncoding;
import org.jcodings.specific.UTF8Encoding;
Expand All @@ -36,6 +37,7 @@
import org.jruby.truffle.nodes.cast.NumericToFloatNode;
import org.jruby.truffle.nodes.cast.NumericToFloatNodeGen;
import org.jruby.truffle.nodes.coerce.NameToJavaStringNodeGen;
import org.jruby.truffle.nodes.coerce.ToPathNodeGen;
import org.jruby.truffle.nodes.coerce.ToStrNodeGen;
import org.jruby.truffle.nodes.core.KernelNodesFactory.CopyNodeFactory;
import org.jruby.truffle.nodes.core.KernelNodesFactory.SameOrEqualNodeFactory;
Expand Down Expand Up @@ -1502,13 +1504,20 @@ protected boolean isNonZero(long max) {
}

@CoreMethod(names = "require", isModuleFunction = true, required = 1)
public abstract static class RequireNode extends CoreMethodArrayArgumentsNode {
@NodeChildren({
@NodeChild(type = RubyNode.class, value = "feature")
})
public abstract static class RequireNode extends CoreMethodNode {

public RequireNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}

@TruffleBoundary
@CreateCast("feature")
public RubyNode coerceFeatureToPath(RubyNode feature) {
return ToPathNodeGen.create(getContext(), getSourceSection(), feature);
}

@Specialization(guards = "isRubyString(feature)")
public boolean require(RubyBasicObject feature) {
CompilerDirectives.transferToInterpreter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected RubyConstant lookupForExistingModule(RubyModule lexicalParent) {
if ((constant != null) && constant.isAutoload()) {
if (requireNode == null) {
CompilerDirectives.transferToInterpreter();
requireNode = insert(KernelNodesFactory.RequireNodeFactory.create(getContext(), getSourceSection(), new RubyNode[]{}));
requireNode = insert(KernelNodesFactory.RequireNodeFactory.create(getContext(), getSourceSection(), null));
}

// We know that we're redefining this constant as we're defining a class/module with that name. We remove
Expand Down

0 comments on commit 63d867b

Please sign in to comment.