-
-
Notifications
You must be signed in to change notification settings - Fork 925
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 9.4.12.0
- 9.4.11.0
- 9.4.10.0
- 9.4.9.0
- 9.4.8.0
- 9.4.7.0
- 9.4.6.0
- 9.4.5.0
- 9.4.4.0
- 9.4.3.0
- 9.4.2.0
- 9.4.1.0
- 9.4.0.0
- 9.3.15.0
- 9.3.14.0
- 9.3.13.0
- 9.3.12.0
- 9.3.11.0
- 9.3.10.0
- 9.3.9.0
- 9.3.8.0
- 9.3.7.0
- 9.3.6.0
- 9.3.5.0
- 9.3.4.0
- 9.3.3.0
- 9.3.2.0
- 9.3.1.0
- 9.3.0.0
- 9.2.21.0
- 9.2.20.1
- 9.2.20.0
- 9.2.19.0
- 9.2.18.0
- 9.2.17.0
- 9.2.16.0
- 9.2.15.0
- 9.2.14.0
- 9.2.13.0
- 9.2.12.0
- 9.2.11.1
- 9.2.11.0
- 9.2.10.0
- 9.2.9.0
- 9.2.8.0
- 9.2.7.0
- 9.2.6.0
- 9.2.5.0
- 9.2.4.1
- 9.2.4.0
- 9.2.3.0
- 9.2.2.0
- 9.2.1.0
- 9.2.0.0
- 9.1.17.0
- 9.1.16.0
- 9.1.15.0
- 9.1.14.0
- 9.1.13.0
- 9.1.12.0
- 9.1.11.0
- 9.1.10.0
- 9.1.9.0
- 9.1.8.0
- 9.1.7.0
- 9.1.6.0
- 9.1.5.0
- 9.1.4.0
- 9.1.3.0
- 9.1.2.0
- 9.1.1.0
- 9.1.0.0
- 9.0.5.0
- 9.0.4.0
- 9.0.3.0
- 9.0.1.0
- 9.0.0.0
- 9.0.0.0.rc2
- 9.0.0.0.rc1
- 9.0.0.0.pre2
1 parent
67d23f1
commit 3063622
Showing
22 changed files
with
1,268 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
fails:File includes File::Constants | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,23 @@ | ||
fails:File.fnmatch matches entire strings | ||
fails:File.fnmatch does not match partial strings | ||
fails:File.fnmatch does not support { } patterns by default | ||
fails:File.fnmatch supports some { } patterns when File::FNM_EXTGLOB is passed | ||
fails:File.fnmatch doesn't support some { } patterns even when File::FNM_EXTGLOB is passed | ||
fails:File.fnmatch doesn't match an extra } when File::FNM_EXTGLOB is passed | ||
fails:File.fnmatch matches when both FNM_EXTGLOB and FNM_PATHNAME are passed | ||
fails:File.fnmatch matches a single character for each ? character | ||
fails:File.fnmatch matches zero or more characters for each * character | ||
fails:File.fnmatch matches ranges of characters using bracket expresions (e.g. [a-z]) | ||
fails:File.fnmatch matches ranges of characters using bracket expresions, taking case into account | ||
fails:File.fnmatch does not match characters outside of the range of the bracket expresion | ||
fails:File.fnmatch matches ranges of characters using exclusive bracket expresions (e.g. [^t] or [!t]) | ||
fails:File.fnmatch matches characters with a case sensitive comparison | ||
fails:File.fnmatch matches characters with case insensitive comparison when flags includes FNM_CASEFOLD | ||
fails:File.fnmatch doesn't match case sensitive characters on platfroms with case sensitive paths, when flags include FNM_SYSCASE | ||
fails:File.fnmatch does not match '/' characters with ? or * when flags includes FNM_PATHNAME | ||
fails:File.fnmatch does not match '/' characters inside bracket expressions when flags includes FNM_PATHNAME | ||
fails:File.fnmatch matches literal ? or * in path when pattern includes \? or \* | ||
fails:File.fnmatch matches literal character (e.g. 'a') in path when pattern includes escaped character (e.g. \a) | ||
fails:File.fnmatch matches '\' characters in path when flags includes FNM_NOESACPE | ||
fails:File.fnmatch escapes special characters inside bracket expression | ||
fails:File.fnmatch does not match leading periods in filenames with wildcards by default | ||
fails:File.fnmatch matches patterns with leading periods to dotfiles by default | ||
fails:File.fnmatch matches leading periods in filenames when flags includes FNM_DOTMATCH | ||
fails:File.fnmatch matches multiple directories with ** and * | ||
fails:File.fnmatch matches multiple directories with ** when flags includes File::FNM_PATHNAME | ||
fails:File.fnmatch returns false if '/' in pattern do not match '/' in path when flags includes FNM_PATHNAME | ||
fails:File.fnmatch returns true if '/' in pattern match '/' in path when flags includes FNM_PATHNAME | ||
fails:File.fnmatch accepts an object that has a #to_path method | ||
fails:File.fnmatch raises a TypeError if the first and second arguments are not string-like | ||
fails:File.fnmatch raises a TypeError if the third argument is not an Integer | ||
fails:File.fnmatch does not raise a TypeError if the third argument can be coerced to an Integer | ||
fails:File.fnmatch? matches entire strings | ||
fails:File.fnmatch? does not match partial strings | ||
fails:File.fnmatch? does not support { } patterns by default | ||
fails:File.fnmatch? supports some { } patterns when File::FNM_EXTGLOB is passed | ||
fails:File.fnmatch? doesn't support some { } patterns even when File::FNM_EXTGLOB is passed | ||
fails:File.fnmatch? doesn't match an extra } when File::FNM_EXTGLOB is passed | ||
fails:File.fnmatch? matches when both FNM_EXTGLOB and FNM_PATHNAME are passed | ||
fails:File.fnmatch? matches a single character for each ? character | ||
fails:File.fnmatch? matches zero or more characters for each * character | ||
fails:File.fnmatch? matches ranges of characters using bracket expresions (e.g. [a-z]) | ||
fails:File.fnmatch? matches ranges of characters using bracket expresions, taking case into account | ||
fails:File.fnmatch? does not match characters outside of the range of the bracket expresion | ||
fails:File.fnmatch? matches ranges of characters using exclusive bracket expresions (e.g. [^t] or [!t]) | ||
fails:File.fnmatch? matches characters with a case sensitive comparison | ||
fails:File.fnmatch? matches characters with case insensitive comparison when flags includes FNM_CASEFOLD | ||
fails:File.fnmatch? doesn't match case sensitive characters on platfroms with case sensitive paths, when flags include FNM_SYSCASE | ||
fails:File.fnmatch? does not match '/' characters with ? or * when flags includes FNM_PATHNAME | ||
fails:File.fnmatch? does not match '/' characters inside bracket expressions when flags includes FNM_PATHNAME | ||
fails:File.fnmatch? matches literal ? or * in path when pattern includes \? or \* | ||
fails:File.fnmatch? matches literal character (e.g. 'a') in path when pattern includes escaped character (e.g. \a) | ||
fails:File.fnmatch? matches '\' characters in path when flags includes FNM_NOESACPE | ||
fails:File.fnmatch? escapes special characters inside bracket expression | ||
fails:File.fnmatch? does not match leading periods in filenames with wildcards by default | ||
fails:File.fnmatch? matches patterns with leading periods to dotfiles by default | ||
fails:File.fnmatch? matches leading periods in filenames when flags includes FNM_DOTMATCH | ||
fails:File.fnmatch? matches multiple directories with ** and * | ||
fails:File.fnmatch? matches multiple directories with ** when flags includes File::FNM_PATHNAME | ||
fails:File.fnmatch? returns false if '/' in pattern do not match '/' in path when flags includes FNM_PATHNAME | ||
fails:File.fnmatch? returns true if '/' in pattern match '/' in path when flags includes FNM_PATHNAME | ||
fails:File.fnmatch? accepts an object that has a #to_path method | ||
fails:File.fnmatch? raises a TypeError if the first and second arguments are not string-like | ||
fails:File.fnmatch? raises a TypeError if the third argument is not an Integer | ||
fails:File.fnmatch? does not raise a TypeError if the third argument can be coerced to an Integer | ||
fails(windows):File.fnmatch matches case sensitive characters on platfroms with case insensitive paths, when flags include FNM_SYSCASE | ||
fails(windows):File.fnmatch? matches case sensitive characters on platfroms with case insensitive paths, when flags include FNM_SYSCASE |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
141 changes: 141 additions & 0 deletions
141
truffle/src/main/java/org/jruby/truffle/nodes/rubinius/DirPrimitiveNodes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.nodes.rubinius; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.nodes.UnexpectedResultException; | ||
import com.oracle.truffle.api.object.HiddenKey; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.nodes.objectstorage.ReadHeadObjectFieldNode; | ||
import org.jruby.truffle.nodes.objectstorage.WriteHeadObjectFieldNode; | ||
import org.jruby.truffle.runtime.RubyCallStack; | ||
import org.jruby.truffle.runtime.RubyContext; | ||
import org.jruby.truffle.runtime.control.RaiseException; | ||
import org.jruby.truffle.runtime.core.*; | ||
|
||
import java.io.File; | ||
|
||
public abstract class DirPrimitiveNodes { | ||
|
||
// TODO CS 14-April-15 use a shape, properties and allocator | ||
|
||
private static final HiddenKey contentsKey = new HiddenKey("contents"); | ||
private static final HiddenKey positionKey = new HiddenKey("position"); | ||
|
||
@RubiniusPrimitive(name = "dir_open") | ||
public static abstract class DirOpenPrimitiveNode extends RubiniusPrimitiveNode { | ||
|
||
@Child private WriteHeadObjectFieldNode writeContentsNode; | ||
@Child private WriteHeadObjectFieldNode writePositionNode; | ||
|
||
public DirOpenPrimitiveNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
writeContentsNode = new WriteHeadObjectFieldNode(contentsKey); | ||
writePositionNode = new WriteHeadObjectFieldNode(positionKey); | ||
} | ||
|
||
public DirOpenPrimitiveNode(DirOpenPrimitiveNode prev) { | ||
super(prev); | ||
writeContentsNode = prev.writeContentsNode; | ||
writePositionNode = prev.writePositionNode; | ||
} | ||
|
||
@CompilerDirectives.TruffleBoundary | ||
@Specialization | ||
public RubyNilClass open(RubyBasicObject dir, RubyString path, RubyNilClass encoding) { | ||
final String[] contents = new File(path.toString()).list(); | ||
|
||
if (contents == null) { | ||
throw new RaiseException(new RubyException( | ||
getContext().getCoreLibrary().getEnoentClass(), | ||
getContext().makeString("No such file or directory @ dir_initialize - " + path.toString()), | ||
RubyCallStack.getBacktrace(this))); | ||
} | ||
|
||
writeContentsNode.execute(dir, contents); | ||
writePositionNode.execute(dir, -2); // -2 for . and then .. | ||
|
||
return nil(); | ||
} | ||
|
||
} | ||
|
||
@RubiniusPrimitive(name = "dir_read") | ||
public static abstract class DirReadPrimitiveNode extends RubiniusPrimitiveNode { | ||
|
||
@Child private ReadHeadObjectFieldNode readContentsNode; | ||
@Child private ReadHeadObjectFieldNode readPositionNode; | ||
@Child private WriteHeadObjectFieldNode writePositionNode; | ||
|
||
public DirReadPrimitiveNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
readContentsNode = new ReadHeadObjectFieldNode(contentsKey); | ||
readPositionNode = new ReadHeadObjectFieldNode(positionKey); | ||
writePositionNode = new WriteHeadObjectFieldNode(positionKey); | ||
} | ||
|
||
public DirReadPrimitiveNode(DirReadPrimitiveNode prev) { | ||
super(prev); | ||
readContentsNode = prev.readContentsNode; | ||
readPositionNode = prev.readPositionNode; | ||
writePositionNode = prev.writePositionNode; | ||
} | ||
|
||
@CompilerDirectives.TruffleBoundary | ||
@Specialization | ||
public Object read(RubyBasicObject dir) { | ||
final int position; | ||
|
||
try { | ||
position = readPositionNode.executeInteger(dir); | ||
} catch (UnexpectedResultException e) { | ||
throw new IllegalStateException(); | ||
} | ||
|
||
writePositionNode.execute(dir, position + 1); | ||
|
||
if (position == -2) { | ||
return getContext().makeString("."); | ||
} else if (position == -1) { | ||
return getContext().makeString(".."); | ||
} else { | ||
final String[] contents = (String[]) readContentsNode.execute(dir); | ||
|
||
if (position < contents.length) { | ||
return getContext().makeString(contents[position]); | ||
} else { | ||
return nil(); | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
@RubiniusPrimitive(name = "dir_close") | ||
public static abstract class DirClosePrimitiveNode extends RubiniusPrimitiveNode { | ||
|
||
public DirClosePrimitiveNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
public DirClosePrimitiveNode(DirClosePrimitiveNode prev) { | ||
super(prev); | ||
} | ||
|
||
@CompilerDirectives.TruffleBoundary | ||
@Specialization | ||
public RubyNilClass open(RubyBasicObject dir) { | ||
return nil(); | ||
} | ||
|
||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
truffle/src/main/java/org/jruby/truffle/nodes/rubinius/IOPrimitiveNodes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. This | ||
* code is released under a tri EPL/GPL/LGPL license. You can use it, | ||
* redistribute it and/or modify it under the terms of the: | ||
* | ||
* Eclipse Public License version 1.0 | ||
* GNU General Public License version 2 | ||
* GNU Lesser General Public License version 2.1 | ||
*/ | ||
package org.jruby.truffle.nodes.rubinius; | ||
|
||
import com.oracle.truffle.api.CompilerDirectives; | ||
import com.oracle.truffle.api.dsl.Specialization; | ||
import com.oracle.truffle.api.source.SourceSection; | ||
import org.jruby.truffle.runtime.RubyContext; | ||
import org.jruby.truffle.runtime.core.RubyString; | ||
import org.jruby.util.Dir; | ||
|
||
public abstract class IOPrimitiveNodes { | ||
|
||
@RubiniusPrimitive(name = "io_fnmatch", needsSelf = false) | ||
public static abstract class IOFNMatchPrimitiveNode extends RubiniusPrimitiveNode { | ||
|
||
public IOFNMatchPrimitiveNode(RubyContext context, SourceSection sourceSection) { | ||
super(context, sourceSection); | ||
} | ||
|
||
public IOFNMatchPrimitiveNode(IOFNMatchPrimitiveNode prev) { | ||
super(prev); | ||
} | ||
|
||
@CompilerDirectives.TruffleBoundary | ||
@Specialization | ||
public boolean fnmatch(RubyString pattern, RubyString path, int flags) { | ||
return Dir.fnmatch(pattern.getByteList().getUnsafeBytes(), | ||
pattern.getByteList().getBegin(), | ||
pattern.getByteList().getBegin() + pattern.getByteList().getRealSize(), | ||
path.getByteList().getUnsafeBytes(), | ||
path.getByteList().getBegin(), | ||
path.getByteList().getBegin() + path.getByteList().getRealSize(), | ||
flags) != Dir.FNM_NOMATCH; | ||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# 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. | ||
|
||
class Dir | ||
def self.allocate | ||
Rubinius.primitive :dir_allocate | ||
raise PrimitiveFailure, "Dir.allocate primitive failed" | ||
end | ||
|
||
def initialize(path, options=undefined) | ||
path = Rubinius::Type.coerce_to_path path | ||
|
||
if options.equal? undefined | ||
enc = nil | ||
else | ||
options = Rubinius::Type.coerce_to options, Hash, :to_hash | ||
enc = options[:encoding] | ||
enc = Rubinius::Type.coerce_to_encoding enc if enc | ||
end | ||
|
||
Rubinius.invoke_primitive :dir_open, self, path, enc | ||
end | ||
|
||
private :initialize | ||
|
||
def close | ||
Rubinius.primitive :dir_close | ||
raise PrimitiveFailure, "Dir#close primitive failed" | ||
end | ||
|
||
def closed? | ||
Rubinius.primitive :dir_closed_p | ||
raise PrimitiveFailure, "Dir#closed? primitive failed" | ||
end | ||
|
||
def read | ||
entry = Rubinius.invoke_primitive :dir_read, self | ||
return unless entry | ||
|
||
if Encoding.default_external == Encoding::US_ASCII && !entry.valid_encoding? | ||
entry.force_encoding Encoding::ASCII_8BIT | ||
return entry | ||
end | ||
|
||
enc = Encoding.default_internal | ||
enc ? entry.encode(enc) : entry | ||
end | ||
|
||
def control(kind, pos) | ||
Rubinius.primitive :dir_control | ||
raise PrimitiveFailure, "Dir#__control__ primitive failed" | ||
end | ||
|
||
private :control | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# 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. | ||
|
||
# Only part of Rubinius' io.rb | ||
|
||
class IO | ||
|
||
def self.fnmatch(pattern, path, flags) | ||
Rubinius.primitive :io_fnmatch | ||
raise PrimitiveFailure, "IO#fnmatch primitive failed" | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# 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. | ||
|
||
# Only part of Rubinius' dir.rb | ||
|
||
class Dir | ||
|
||
def self.[](*patterns) | ||
if patterns.size == 1 | ||
pattern = Rubinius::Type.coerce_to_path(patterns[0]) | ||
return [] if pattern.empty? | ||
patterns = glob_split pattern | ||
end | ||
|
||
glob patterns | ||
end | ||
|
||
def self.glob(pattern, flags=0, &block) | ||
if pattern.kind_of? Array | ||
patterns = pattern | ||
else | ||
pattern = Rubinius::Type.coerce_to_path pattern | ||
|
||
return [] if pattern.empty? | ||
|
||
patterns = glob_split pattern | ||
end | ||
|
||
matches = [] | ||
index = 0 | ||
|
||
patterns.each do |pat| | ||
pat = Rubinius::Type.coerce_to_path pat | ||
enc = Rubinius::Type.ascii_compatible_encoding pat | ||
Dir::Glob.glob pat, flags, matches | ||
|
||
total = matches.size | ||
while index < total | ||
Rubinius::Type.encode_string matches[index], enc | ||
index += 1 | ||
end | ||
end | ||
|
||
if block | ||
matches.each(&block) | ||
return nil | ||
end | ||
|
||
return matches | ||
end | ||
|
||
def self.glob_split(pattern) | ||
result = [] | ||
start = 0 | ||
while idx = pattern.find_string("\0", start) | ||
result << pattern.byteslice(start, idx) | ||
start = idx + 1 | ||
end | ||
result << pattern.byteslice(start, pattern.bytesize) | ||
end | ||
|
||
end |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
169 changes: 169 additions & 0 deletions
169
truffle/src/main/ruby/core/rubinius/common/lru_cache.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,169 @@ | ||
# 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. | ||
|
||
module Rubinius | ||
class LRUCache | ||
class Entry | ||
attr_reader :hits | ||
attr_reader :key | ||
attr_accessor :value | ||
attr_accessor :next_entry | ||
attr_accessor :prev_entry | ||
|
||
def initialize(key, value) | ||
@key = key | ||
@value = value | ||
@hits = 0 | ||
@next_entry = nil | ||
@prev_entry = nil | ||
end | ||
|
||
def insert_after(entry) | ||
nxt = entry.next_entry | ||
|
||
@prev_entry = entry | ||
@next_entry = nxt | ||
|
||
entry.next_entry = self | ||
nxt.prev_entry = self if nxt | ||
end | ||
|
||
def insert_before(entry) | ||
prev = entry.prev_entry | ||
|
||
@prev_entry = prev | ||
@next_entry = entry | ||
|
||
entry.prev_entry = self | ||
prev.next_entry = self if prev | ||
end | ||
|
||
def detach! | ||
@next_entry.prev_entry = @prev_entry if @next_entry | ||
@prev_entry.next_entry = @next_entry if @prev_entry | ||
|
||
@next_entry = nil | ||
@prev_entry = nil | ||
end | ||
|
||
def become_first! | ||
@prev_entry = nil | ||
end | ||
|
||
def inc! | ||
@hits += 1 | ||
end | ||
end | ||
|
||
def initialize(total) | ||
@cache = {} | ||
@total = total | ||
@current = 0 | ||
|
||
@head = Entry.new(nil, nil) | ||
@tail = Entry.new(nil, nil) | ||
|
||
@tail.insert_after(@head) | ||
|
||
@misses = 0 | ||
end | ||
|
||
attr_reader :current | ||
attr_reader :misses | ||
|
||
def clear! | ||
Rubinius.synchronize(self) do | ||
@cache = {} | ||
@current = 0 | ||
|
||
@head = Entry.new(nil, nil, -1) | ||
@tail = Entry.new(nil, nil, -2) | ||
|
||
@tail.insert_after(@head) | ||
end | ||
end | ||
|
||
def explain | ||
entry = @head.next_entry | ||
while entry != @tail | ||
str, layout = entry.key | ||
puts "hits: #{entry.hits}" | ||
puts "layout: #{layout.inspect}" | ||
puts "<STRING>" | ||
puts str | ||
puts "</STRING>" | ||
|
||
entry = entry.next_entry | ||
end | ||
end | ||
|
||
def retrieve(key) | ||
Rubinius.synchronize(self) do | ||
if entry = @cache[key] | ||
entry.inc! | ||
|
||
entry.detach! | ||
entry.insert_before @tail | ||
|
||
return entry.value | ||
end | ||
|
||
@misses += 1 | ||
|
||
nil | ||
end | ||
end | ||
|
||
def set(key, value) | ||
Rubinius.synchronize(self) do | ||
if entry = @cache[key] | ||
entry.value = value | ||
|
||
entry.detach! | ||
entry.insert_before @tail | ||
|
||
return value | ||
end | ||
|
||
if @current == @total | ||
entry = @head.next_entry | ||
|
||
entry.detach! | ||
|
||
@cache.delete entry.key | ||
else | ||
@current += 1 | ||
end | ||
|
||
entry = Entry.new(key, value) | ||
|
||
entry.insert_before @tail | ||
|
||
@cache[key] = entry | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters