Skip to content

Commit

Permalink
Showing 7 changed files with 94 additions and 10 deletions.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/dir/each_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:Dir#each returns the directory which remains open
fails:Dir#each raises an IOError when called on a closed Dir instance
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/dir/pos_tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
fails:Dir#pos returns an Integer representing the current position in the directory
fails:Dir#pos returns a different Integer if moved from previous position
fails:Dir#pos raises an IOError when called on a closed Dir instance
fails:Dir#pos= moves the read position to a previously obtained position
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/dir/rewind_tags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
fails:Dir#rewind resets the next read to start from the first entry
fails:Dir#rewind returns the Dir instance
fails:Dir#rewind raises an IOError when called on a closed Dir instance
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/dir/seek_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/dir/tell_tags.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
fails:Dir#tell returns an Integer representing the current position in the directory
fails:Dir#tell returns a different Integer if moved from previous position
fails:Dir#tell raises an IOError when called on a closed Dir instance
Original file line number Diff line number Diff line change
@@ -6,6 +6,34 @@
* Eclipse Public License version 1.0
* GNU General Public License version 2
* GNU Lesser General Public License version 2.1
*
* Some of the code in this class is transliterated from C++ code in Rubinius.
*
* Copyright (c) 2007-2014, Evan Phoenix and contributors
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of Rubinius nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package org.jruby.truffle.nodes.rubinius;

@@ -136,6 +164,44 @@ public Object read(RubyBasicObject dir) {

}


@RubiniusPrimitive(name = "dir_control")
public static abstract class DirControlPrimitiveNode extends RubiniusPrimitiveNode {

@Child private ReadHeadObjectFieldNode readPositionNode;
@Child private WriteHeadObjectFieldNode writePositionNode;

public DirControlPrimitiveNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
readPositionNode = new ReadHeadObjectFieldNode(positionKey);
writePositionNode = new WriteHeadObjectFieldNode(positionKey);
}

@CompilerDirectives.TruffleBoundary
@Specialization
public Object control(RubyBasicObject dir, int kind, int position) {
switch (kind) {
case 0:
writePositionNode.execute(dir, position);
return true;
case 1:
writePositionNode.execute(dir, -2);
return true;
case 2:
try {
return readPositionNode.executeInteger(dir);
} catch (UnexpectedResultException e) {
throw new IllegalStateException();
}

}
return nil();
}

}



@RubiniusPrimitive(name = "dir_close")
public static abstract class DirClosePrimitiveNode extends RubiniusPrimitiveNode {

28 changes: 28 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/dir.rb
Original file line number Diff line number Diff line change
@@ -183,6 +183,34 @@ def each
self
end

SeekKind = 0
RewindKind = 1
TellKind = 2

def pos
control TellKind, 0
end

alias_method :tell, :pos

def pos=(position)
seek(position)

position
end

def seek(position)
control SeekKind, position

self
end

def rewind
control RewindKind, 0

self
end

class << self
alias_method :pwd, :getwd
alias_method :delete, :rmdir

0 comments on commit ef1fc91

Please sign in to comment.