Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: jruby/jruby
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a7e148fddfd9
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 25ab93383260
Choose a head ref
  • 5 commits
  • 15 files changed
  • 1 contributor

Commits on Mar 7, 2015

  1. [Truffle] Hash#keep_if

    chrisseaton committed Mar 7, 2015
    Copy the full SHA
    7c1a4c8 View commit details
  2. [Truffle] Hash#flatten

    chrisseaton committed Mar 7, 2015
    Copy the full SHA
    05222e7 View commit details
  3. [Truffle] Hash#fetch

    chrisseaton committed Mar 7, 2015
    Copy the full SHA
    618f57f View commit details
  4. Copy the full SHA
    9c5003a View commit details
  5. Copy the full SHA
    25ab933 View commit details
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/array/to_ary_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/core/hash/constructor_tags.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
fails:Hash.[] coerces a single argument which responds to #to_ary
fails:Hash.[] ignores elements that are not arrays
fails:Hash.[] raises an ArgumentError for arrays of more than 2 elements
fails:Hash.[] raises an ArgumentError when passed a list of value-invalid-pairs in an array
fails:Hash.[] raises an ArgumentError when passed an odd number of arguments
fails:Hash.[] calls to_hash
fails:Hash.[] passed an array treats elements that are 1 element arrays as keys with value nil
fails:Hash.[] passed a single argument which responds to #to_hash coerces it and returns a copy
1 change: 0 additions & 1 deletion spec/truffle/tags/core/hash/fetch_tags.txt

This file was deleted.

9 changes: 0 additions & 9 deletions spec/truffle/tags/core/hash/flatten_tags.txt

This file was deleted.

7 changes: 0 additions & 7 deletions spec/truffle/tags/core/hash/keep_if_tags.txt

This file was deleted.

4 changes: 4 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/RubyNode.java
Original file line number Diff line number Diff line change
@@ -493,4 +493,8 @@ protected Object ruby(VirtualFrame frame, String expression, Object... arguments
return getContext().eval(ByteList.create(expression), binding, true, "inline-ruby", this);
}

public boolean isSingleArgument(Object[] arguments) {
return arguments.length == 1;
}

}
Original file line number Diff line number Diff line change
@@ -139,7 +139,7 @@ public ConstructNode(ConstructNode prev) {
}

@ExplodeLoop
@Specialization
@Specialization(guards = {"!isSingleArgument(arguments[1])", "isEvenArguments(arguments[1])"})
public RubyHash construct(RubyClass hashClass, Object[] args) {
if (args.length == 1) {
singleObject.enter();
@@ -241,6 +241,24 @@ public RubyHash construct(RubyClass hashClass, Object[] args) {
}
}

@Specialization(guards = {"!isSingleArgument(arguments[1])", "!isEvenArguments(arguments[1])"})
public Object construct(VirtualFrame frame, RubyClass hashClass, Object[] args) {
notDesignedForCompilation();

return ruby(frame, "_construct_fallback(args)", "args", RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), args));
}

@Specialization(guards = "isSingleArgument(arguments[1])")
public Object constructSingle(VirtualFrame frame, RubyClass hashClass, Object[] args) {
notDesignedForCompilation();

return ruby(frame, "_construct_fallback(args)", "args", RubyArray.fromObjects(getContext().getCoreLibrary().getArrayClass(), args));
}

protected boolean isEvenArguments(Object[] arguments) {
return arguments.length % 2 == 0;
}

}

@CoreMethod(names = "[]", required = 1)
Original file line number Diff line number Diff line change
@@ -1637,6 +1637,28 @@ public RubyNode visitInstVarNode(org.jruby.ast.InstVarNode node) {
}
}

if (sourceSection.getSource().getPath().equals("core:/core/rubinius/common/range.rb")) {
if (nameWithoutSigil.equals("@begin")) {
return new RubyCallNode(context, sourceSection,
"begin",
new SelfNode(context, sourceSection),
null,
false);
} else if (nameWithoutSigil.equals("@end")) {
return new RubyCallNode(context, sourceSection,
"end",
new SelfNode(context, sourceSection),
null,
false);
} else if (nameWithoutSigil.equals("@excl")) {
return new RubyCallNode(context, sourceSection,
"exclude_end?",
new SelfNode(context, sourceSection),
null,
false);
}
}

final RubyNode receiver = new SelfNode(context, sourceSection);

return new ReadInstanceVariableNode(context, sourceSection, nameWithoutSigil, receiver, false);
1 change: 1 addition & 0 deletions truffle/src/main/ruby/core.rb
Original file line number Diff line number Diff line change
@@ -62,6 +62,7 @@
require_relative 'core/rubinius/common/object_space'
require_relative 'core/rubinius/common/proc'
require_relative 'core/rubinius/common/string'
require_relative 'core/rubinius/common/range'
require_relative 'core/rubinius/common/struct'
require_relative 'core/rubinius/common/symbol'
require_relative 'core/rubinius/common/regexp'
60 changes: 59 additions & 1 deletion truffle/src/main/ruby/core/hash.rb
Original file line number Diff line number Diff line change
@@ -6,6 +6,32 @@
# GNU General Public License version 2
# GNU Lesser General Public License version 2.1

# 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 Hash

def invert
@@ -40,12 +66,44 @@ def merge_fallback(other, &block)

def find_item(key)
value = _get_or_undefined(key)
if undefined == value
if undefined.equal?(value)
nil
else
# TODO CS 7-Mar-15 maybe we should return the stored key?
KeyValue.new(key, value)
end
end

# From Rubinius

def self._construct_fallback(*args)
if args.size == 1
obj = args.first
if hash = Rubinius::Type.check_convert_type(obj, Hash, :to_hash)
new_hash = allocate.replace(hash)
new_hash.default = nil
return new_hash
elsif associate_array = Rubinius::Type.check_convert_type(obj, Array, :to_ary)
return new_from_associate_array(associate_array)
end
end

return new if args.empty?

if args.size & 1 == 1
raise ArgumentError, "Expected an even number, got #{args.length}"
end

hash = new
i = 0
total = args.size

while i < total
hash[args[i]] = args[i+1]
i += 2
end

hash
end

end
4 changes: 4 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/array.rb
Original file line number Diff line number Diff line change
@@ -415,4 +415,8 @@ def fetch(idx, default=undefined)
at(idx)
end

def to_ary
self
end

end
47 changes: 47 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/hash.rb
Original file line number Diff line number Diff line change
@@ -280,4 +280,51 @@ def index(value)

alias_method :key, :index

def keep_if
return to_enum(:keep_if) unless block_given?

Rubinius.check_frozen

each_item { |e| delete e.key unless yield(e.key, e.value) }

self
end

def flatten(level=1)
to_a.flatten(level)
end

def fetch(key, default=undefined)
if item = find_item(key)
return item.value
end

return yield(key) if block_given?
return default unless undefined.equal?(default)
raise KeyError, "key #{key} not found"
end

def value?(value)
each_item do |item|
return true if item.value == value
end
false
end

alias_method :has_value?, :value?

def self.new_from_associate_array(associate_array)
hash = new
associate_array.each do |array|
next unless array.respond_to? :to_ary
array = array.to_ary
unless (1..2).cover? array.size
raise ArgumentError, "invalid number of elements (#{array.size} for 1..2)"
end
hash[array.at(0)] = array.at(1)
end
hash
end
private_class_method :new_from_associate_array

end
2 changes: 1 addition & 1 deletion truffle/src/main/ruby/core/rubinius/common/integer.rb
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@
# 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' kernel.rb
# Only part of Rubinius' integer.rb

class Integer < Numeric

50 changes: 50 additions & 0 deletions truffle/src/main/ruby/core/rubinius/common/range.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 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' range.rb

class Range

def cover?(value)
# MRI uses <=> to compare, so must we.

beg_compare = (@begin <=> value)
return false unless beg_compare

if Comparable.compare_int(beg_compare) <= 0
end_compare = (value <=> @end)

if @excl
return true if Comparable.compare_int(end_compare) < 0
else
return true if Comparable.compare_int(end_compare) <= 0
end
end

false
end

end
22 changes: 0 additions & 22 deletions truffle/src/main/ruby/core/shims.rb
Original file line number Diff line number Diff line change
@@ -75,28 +75,6 @@ def puts(*values)

ARGF = Object.new

class Hash

def fetch(key, default=nil)
if key?(key)
self[key]
elsif block_given?
yield(key)
elsif default
default
else
raise(KeyError, "key not found: #{key}")
end
end

def value?(value)
values.any? { |v| v == value }
end

alias_method :has_value?, :value?

end

class Regexp
def self.last_match(n = nil)
if n