Skip to content

Commit

Permalink
Merge pull request #2811 from jruby/truffle-io
Browse files Browse the repository at this point in the history
[Truffle] Start to support the Rubinius FFI and POSIX calls
  • Loading branch information
chrisseaton committed Apr 8, 2015
2 parents 4c86703 + 0923cbc commit 2e27cfc
Show file tree
Hide file tree
Showing 26 changed files with 2,942 additions and 225 deletions.
9 changes: 0 additions & 9 deletions spec/truffle/tags/core/file/constants_tags.txt
@@ -1,14 +1,5 @@
fails:File::Constants matches mode constants
fails:File::Constants the open mode constants
fails:File::Constants lock mode constants
fails:File::Constants File::RDONLY
fails:File::Constants File::WRONLY
fails:File::Constants File::CREAT
fails:File::Constants File::RDWR
fails:File::Constants File::APPEND
fails:File::Constants File::TRUNC
fails:File::Constants File::NOCTTY
fails:File::Constants File::NONBLOCK
fails:File::Constants File::LOCK_EX
fails:File::Constants File::LOCK_NB
fails:File::Constants File::LOCK_SH
Expand Down
4 changes: 0 additions & 4 deletions spec/truffle/tags/core/file/delete_tags.txt
@@ -1,5 +1 @@
fails:File.delete returns 0 when called without arguments
fails:File.delete deletes multiple files
fails:File.delete raises an Errno::ENOENT when the given file doesn't exist
fails:File.delete coerces a given parameter into a string if possible
fails:File.delete accepts an object that has a #to_path method
1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/exist_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/exists_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/file/file_tags.txt
@@ -1,5 +1,4 @@
fails:File includes File::Constants
fails:File.file? accepts an object that has a #to_path method
windows:File.file? returns true if the named file exists and is a regular file.
windows:File.file? raises an ArgumentError if not passed one argument
windows:File.file? raises a TypeError if not passed a String type
4 changes: 0 additions & 4 deletions spec/truffle/tags/core/file/open_tags.txt
@@ -1,9 +1,7 @@
fails:File.open opens the file (basic case)
fails:File.open opens a file when called with a block
fails:File.open opens with mode string
fails:File.open opens a file with mode string and block
fails:File.open opens a file with mode num
fails:File.open opens a file with mode num and block
fails:File.open opens a file with mode and permission as nil
fails:File.open opens the file when passed mode, num and permissions
fails:File.open opens the file when passed mode, num, permissions and block
Expand All @@ -28,7 +26,6 @@ fails:File.open raises an IO exception when write in a block opened with 'r' mod
fails:File.open can't write in a block when call open with File::WRONLY||File::RDONLY mode
fails:File.open can't read in a block when call open with File::WRONLY||File::RDONLY mode
fails:File.open can write in a block when call open with WRONLY mode
fails:File.open can write in a block when call open with 'w' mode
fails:File.open raises an IOError when read in a block opened with WRONLY mode
fails:File.open raises an IOError when read in a block opened with 'w' mode
fails:File.open raises an IOError when read in a block opened with 'a' mode
Expand Down Expand Up @@ -56,7 +53,6 @@ fails:File.open opens a file for binary read-write starting at the beginning of
fails:File.open opens a file for binary read-write and truncate the file
fails:File.open raises a TypeError if passed a filename that is not a String or Integer type
fails:File.open raises a SystemCallError if passed an invalid Integer type
fails:File.open raises an ArgumentError if passed the wrong number of arguments
fails:File.open raises an ArgumentError if passed an invalid string for mode
fails:File.open defaults external_encoding to ASCII-8BIT for binary modes
fails:File.open uses the second argument as an options Hash
Expand Down
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/file/stat/sticky_tags.txt
@@ -1,3 +1 @@
fails:File::Stat#sticky? returns true if the named file has the sticky bit, otherwise false
fails:File::Stat#sticky? accepts an object that has a #to_path method
fails:File::Stat#sticky? needs to be reviewed for spec completeness
Expand Up @@ -22,6 +22,7 @@
import org.jruby.truffle.nodes.control.SequenceNode;
import org.jruby.truffle.nodes.core.*;
import org.jruby.truffle.nodes.rubinius.ByteArrayNodesFactory;
import org.jruby.truffle.nodes.rubinius.PosixNodesFactory;
import org.jruby.truffle.runtime.RubyContext;
import org.jruby.truffle.runtime.backtrace.Backtrace;
import org.jruby.truffle.runtime.control.RaiseException;
Expand Down Expand Up @@ -100,6 +101,7 @@ public void init() {
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, UnboundMethodNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, ByteArrayNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, TimeNodesFactory.getFactories());
CoreMethodNodeManager.addCoreMethodNodes(rubyObjectClass, PosixNodesFactory.getFactories());

// Give the core library manager a chance to tweak some of those methods

Expand Down
182 changes: 0 additions & 182 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/FileNodes.java
Expand Up @@ -121,51 +121,6 @@ public RubyNilClass close(RubyFile file) {

}

@CoreMethod(names = { "delete", "unlink" }, onSingleton = true, required = 1)
public abstract static class DeleteNode extends CoreMethodNode {

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

public DeleteNode(DeleteNode prev) {
super(prev);
}

@Specialization
public int delete(RubyString file) {
notDesignedForCompilation();

if (!new File(file.toString()).delete()) {
// TODO(CS, 12-Jan-15) handle failure
throw new UnsupportedOperationException();
}

return 1;
}

}

@CoreMethod(names = "directory?", onSingleton = true, required = 1)
public abstract static class DirectoryNode extends CoreMethodNode {

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

public DirectoryNode(DirectoryNode prev) {
super(prev);
}

@Specialization
public boolean directory(RubyString path) {
notDesignedForCompilation();

return new File(path.toString()).isDirectory();
}

}

@CoreMethod(names = "dirname", onSingleton = true, required = 1)
public abstract static class DirnameNode extends CoreMethodNode {

Expand Down Expand Up @@ -234,51 +189,6 @@ public RubyNilClass eachLine(VirtualFrame frame, RubyFile file, RubyProc block)

}

@CoreMethod(names = "executable?", onSingleton = true, required = 1)
public abstract static class ExecutableNode extends CoreMethodNode {

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

public ExecutableNode(ExecutableNode prev) {
super(prev);
}

@Specialization
public boolean executable(RubyString path) {
notDesignedForCompilation();

return new File(path.toString()).canExecute();
}

}

@CoreMethod(names = {"exist?", "exists?"}, onSingleton = true, required = 1)
@NodeChild(value = "path")
public abstract static class ExistsNode extends RubyNode {

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

public ExistsNode(ExistsNode prev) {
super(prev);
}

@CreateCast("path") public RubyNode coercePathToString(RubyNode path) {
return ToStrNodeFactory.create(getContext(), getSourceSection(), path);
}

@Specialization
public boolean exists(RubyString path) {
notDesignedForCompilation();

return new File(path.toString()).exists();
}

}

@CoreMethod(names = "expand_path", onSingleton = true, required = 1, optional = 1)
public abstract static class ExpandPathNode extends CoreMethodNode {

Expand All @@ -304,26 +214,6 @@ public RubyString expandPath(RubyString path, RubyString dir) {

}

@CoreMethod(names = "file?", onSingleton = true, required = 1)
public abstract static class FileNode extends CoreMethodNode {

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

public FileNode(FileNode prev) {
super(prev);
}

@Specialization
public boolean file(RubyString path) {
notDesignedForCompilation();

return new File(path.toString()).isFile();
}

}

@CoreMethod(names = "join", onSingleton = true, argumentsAsArray = true)
public abstract static class JoinNode extends CoreMethodNode {

Expand Down Expand Up @@ -399,26 +289,6 @@ public Object open(VirtualFrame frame, RubyString fileName, RubyString mode, Rub

}

@CoreMethod(names = "path", onSingleton = true, required = 1)
public abstract static class PathNode extends CoreMethodNode {

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

public PathNode(PathNode prev) {
super(prev);
}

@Specialization
public RubyString path(RubyString path) {
notDesignedForCompilation();

return getContext().makeString(path.toString());
}

}

@CoreMethod(names = "puts", required = 1)
public abstract static class PutsNode extends CoreMethodNode {

Expand Down Expand Up @@ -507,26 +377,6 @@ public RubyString read(RubyFile file) {

}

@CoreMethod(names = "readable?", onSingleton = true, needsSelf = false, required = 1)
public abstract static class ReadableQueryNode extends CoreMethodNode {

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

public ReadableQueryNode(ReadableQueryNode prev) {
super(prev);
}

@Specialization
public boolean isReadable(RubyString file) {
notDesignedForCompilation();

return new File(file.toString()).canRead();
}

}

@CoreMethod(names = "realpath", onSingleton = true, required = 1, optional = 1)
public abstract static class RealpathNode extends CoreMethodNode {

Expand Down Expand Up @@ -562,38 +412,6 @@ private String realpath(String path, String dir) {

}

@CoreMethod(names = "size?", onSingleton = true, required = 1)
public abstract static class SizeNode extends CoreMethodNode {

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

public SizeNode(SizeNode prev) {
super(prev);
}

@Specialization
public Object read(RubyString file) {
notDesignedForCompilation();

final File f = new File(file.toString());

if (!f.exists()) {
return nil();
}

final long size = f.length();

if (size == 0) {
return nil();
}

return size;
}

}

@CoreMethod(names = "symlink?", onSingleton = true, required = 1)
public abstract static class SymlinkQueryNode extends CoreMethodNode {

Expand Down

0 comments on commit 2e27cfc

Please sign in to comment.