Skip to content

Commit

Permalink
[Truffle] Our implementation of IO.open was really File.open, so move…
Browse files Browse the repository at this point in the history
… it to the right place.
  • Loading branch information
nirvdrum committed Feb 3, 2015
1 parent afd0607 commit 24b840d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 37 deletions.
37 changes: 37 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/FileNodes.java
Expand Up @@ -347,6 +347,43 @@ public static void join(StringBuilder builder, Object[] parts) {
}
}

@CoreMethod(names = "open", onSingleton = true, needsBlock = true, required = 2)
public abstract static class OpenNode extends YieldingCoreMethodNode {

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

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

@Specialization
public Object open(VirtualFrame frame, RubyString fileName, RubyString mode, UndefinedPlaceholder block) {
notDesignedForCompilation();

return RubyFile.open(getContext(), fileName.toString(), mode.toString());
}

@Specialization
public Object open(VirtualFrame frame, RubyString fileName, RubyString mode, RubyProc block) {
notDesignedForCompilation();

final RubyFile file = RubyFile.open(getContext(), fileName.toString(), mode.toString());

if (block != null) {
try {
yield(frame, block, file);
} finally {
file.close();
}
}

return file;
}

}

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

Expand Down
37 changes: 0 additions & 37 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/IONodes.java
Expand Up @@ -31,43 +31,6 @@
@CoreClass(name = "IO")
public abstract class IONodes {

@CoreMethod(names = "open", onSingleton = true, needsBlock = true, required = 2)
public abstract static class OpenNode extends YieldingCoreMethodNode {

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

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

@Specialization
public Object open(VirtualFrame frame, RubyString fileName, RubyString mode, UndefinedPlaceholder block) {
notDesignedForCompilation();

return RubyFile.open(getContext(), fileName.toString(), mode.toString());
}

@Specialization
public Object open(VirtualFrame frame, RubyString fileName, RubyString mode, RubyProc block) {
notDesignedForCompilation();

final RubyFile file = RubyFile.open(getContext(), fileName.toString(), mode.toString());

if (block != null) {
try {
yield(frame, block, file);
} finally {
file.close();
}
}

return file;
}

}

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

Expand Down

0 comments on commit 24b840d

Please sign in to comment.