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: ca6576364c88
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b69dd1b61952
Choose a head ref
  • 12 commits
  • 43 files changed
  • 1 contributor

Commits on Jan 25, 2015

  1. Copy the full SHA
    929c40d View commit details
  2. [Truffle] Numeric#abs2

    chrisseaton committed Jan 25, 2015
    Copy the full SHA
    3c51288 View commit details
  3. Copy the full SHA
    6783b31 View commit details
  4. [Truffle] Numeric#ceil

    chrisseaton committed Jan 25, 2015
    Copy the full SHA
    0602b28 View commit details
  5. [Truffle] Numeric#coerce

    chrisseaton committed Jan 25, 2015
    Copy the full SHA
    6b47d47 View commit details
  6. Copy the full SHA
    7a00f95 View commit details
  7. [Truffle] Numeric#floor

    chrisseaton committed Jan 25, 2015
    Copy the full SHA
    da4ef5f View commit details
  8. Copy the full SHA
    5743df9 View commit details
  9. [Truffle] Numeric#+@

    chrisseaton committed Jan 25, 2015
    Copy the full SHA
    10e80bb View commit details
  10. Copy the full SHA
    45a8c67 View commit details
  11. Copy the full SHA
    b01be67 View commit details
  12. Copy the full SHA
    b69dd1b View commit details
Showing with 208 additions and 145 deletions.
  1. +2 −0 core/src/main/ruby/jruby/truffle/core/rubinius/kernel/bootstrap/kernel.rb
  2. +25 −0 core/src/main/ruby/jruby/truffle/core/rubinius/kernel/common/kernel.rb
  3. +145 −0 core/src/main/ruby/jruby/truffle/core/rubinius/kernel/common/numeric.rb
  4. +0 −3 spec/truffle/tags/core/numeric/abs2_tags.txt
  5. +0 −2 spec/truffle/tags/core/numeric/abs_tags.txt
  6. +0 −4 spec/truffle/tags/core/numeric/angle_tags.txt
  7. +0 −4 spec/truffle/tags/core/numeric/arg_tags.txt
  8. +0 −1 spec/truffle/tags/core/numeric/ceil_tags.txt
  9. +0 −7 spec/truffle/tags/core/numeric/coerce_tags.txt
  10. +0 −6 spec/truffle/tags/core/numeric/comparison_tags.txt
  11. +0 −1 spec/truffle/tags/core/numeric/conj_tags.txt
  12. +0 −1 spec/truffle/tags/core/numeric/conjugate_tags.txt
  13. +0 −2 spec/truffle/tags/core/numeric/denominator_tags.txt
  14. +0 −1 spec/truffle/tags/core/numeric/div_tags.txt
  15. +0 −2 spec/truffle/tags/core/numeric/eql_tags.txt
  16. +0 −6 spec/truffle/tags/core/numeric/fdiv_tags.txt
  17. +0 −1 spec/truffle/tags/core/numeric/floor_tags.txt
  18. +0 −3 spec/truffle/tags/core/numeric/i_tags.txt
  19. +0 −2 spec/truffle/tags/core/numeric/imag_tags.txt
  20. +0 −2 spec/truffle/tags/core/numeric/imaginary_tags.txt
  21. +0 −1 spec/truffle/tags/core/numeric/integer_tags.txt
  22. +0 −2 spec/truffle/tags/core/numeric/magnitude_tags.txt
  23. +0 −2 spec/truffle/tags/core/numeric/modulo_tags.txt
  24. +0 −2 spec/truffle/tags/core/numeric/nonzero_tags.txt
  25. +0 −2 spec/truffle/tags/core/numeric/numerator_tags.txt
  26. +0 −1 spec/truffle/tags/core/numeric/numeric_tags.txt
  27. +0 −4 spec/truffle/tags/core/numeric/phase_tags.txt
  28. +0 −5 spec/truffle/tags/core/numeric/polar_tags.txt
  29. +0 −7 spec/truffle/tags/core/numeric/quo_tags.txt
  30. +0 −3 spec/truffle/tags/core/numeric/real_tags.txt
  31. +0 −5 spec/truffle/tags/core/numeric/rect_tags.txt
  32. +0 −5 spec/truffle/tags/core/numeric/rectangular_tags.txt
  33. +0 −1 spec/truffle/tags/core/numeric/round_tags.txt
  34. +0 −43 spec/truffle/tags/core/numeric/step_tags.txt
  35. +0 −3 spec/truffle/tags/core/numeric/to_c_tags.txt
  36. +0 −1 spec/truffle/tags/core/numeric/to_int_tags.txt
  37. +0 −1 spec/truffle/tags/core/numeric/truncate_tags.txt
  38. +0 −3 spec/truffle/tags/core/numeric/uminus_tags.txt
  39. +0 −1 spec/truffle/tags/core/numeric/uplus_tags.txt
  40. +0 −2 spec/truffle/tags/core/numeric/zero_tags.txt
  41. +11 −0 truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
  42. +18 −1 truffle/src/main/java/org/jruby/truffle/nodes/core/FixnumNodes.java
  43. +7 −2 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/StringPrimitiveNodes.java
Original file line number Diff line number Diff line change
@@ -35,8 +35,10 @@
# Only part of Rubinius' kernel.rb

module Kernel

alias_method :eql?, :equal?

# Truffle: no extra indirection for Kernel#send.
alias_method :send, :__send__ # from BasicObject

end
Original file line number Diff line number Diff line change
@@ -52,6 +52,29 @@ def Float(obj)
end
module_function :Float

##
# MRI uses a macro named NUM2DBL which has essentially the same semantics as
# Float(), with the difference that it raises a TypeError and not a
# ArgumentError. It is only used in a few places (in MRI and Rubinius).
#--
# If we can, we should probably get rid of this.

def FloatValue(obj)
exception = TypeError.new 'no implicit conversion to float'

case obj
when String
raise exception
else
begin
Rubinius::Type.coerce_object_to_float obj
rescue
raise exception
end
end
end
private :FloatValue

##
# MRI uses a macro named StringValue which has essentially the same
# semantics as obj.coerce_to(String, :to_str), but rather than using that
@@ -82,4 +105,6 @@ def object_id
raise PrimitiveFailure, "Kernel#object_id primitive failed"
end



end
Original file line number Diff line number Diff line change
@@ -28,6 +28,14 @@

class Numeric

def +@
self
end

def -@
0 - self
end

def eql?(other)
return false unless other.instance_of? self.class
self == other
@@ -120,4 +128,141 @@ def denominator
to_r.denominator
end

def abs2
self * self
end

def arg
if self < 0
Math::PI
else
0
end
end

alias_method :angle, :arg
alias_method :phase, :arg

def ceil
FloatValue(self).ceil
end

def conjugate
self
end
alias_method :conj, :conjugate

def floor
FloatValue(self).floor
end

def i
Complex(0, self)
end

def to_c
Complex(self, 0)
end

def real
self
end

def imag
0
end
alias_method :imaginary, :imag

def rect
[self, 0]
end
alias_method :rectangular, :rect

def truncate
Float(self).truncate
end

def round
to_f.round
end

def polar
return abs, arg
end

# Delegate #to_int to #to_i in subclasses
def to_int
to_i
end

def integer?
false
end

def modulo(other)
self - other * self.div(other)
end
alias_method :%, :modulo

def quo(other)
Rubinius.privately do
Rational.convert(self, 1, false) / other
end
end

def step(limit, step=1)
return to_enum(:step, limit, step) unless block_given?

raise ArgumentError, "step cannot be 0" if step == 0

value = self
if value.kind_of? Float or limit.kind_of? Float or step.kind_of? Float
# Ported from MRI

value = FloatValue(value)
limit = FloatValue(limit)
step = FloatValue(step)

if step.infinite?
yield value if step > 0 ? value <= limit : value >= limit
else
err = (value.abs + limit.abs + (limit - value).abs) / step.abs * Float::EPSILON
if err.finite?
err = 0.5 if err > 0.5
n = ((limit - value) / step + err).floor
i = 0
if step > 0
while i <= n
d = i * step + value
d = limit if limit < d
yield d
i += 1
end
else
while i <= n
d = i * step + value
d = limit if limit > d
yield d
i += 1
end
end
end
end
else
if step > 0
until value > limit
yield value
value += step
end
else
until value < limit
yield value
value += step
end
end
end

return self
end

end
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/numeric/abs2_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/numeric/abs_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/truffle/tags/core/numeric/angle_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/truffle/tags/core/numeric/arg_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/numeric/ceil_tags.txt

This file was deleted.

7 changes: 0 additions & 7 deletions spec/truffle/tags/core/numeric/coerce_tags.txt

This file was deleted.

6 changes: 0 additions & 6 deletions spec/truffle/tags/core/numeric/comparison_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/numeric/conj_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/numeric/conjugate_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/numeric/denominator_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/numeric/div_tags.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
fails:Numeric#div calls self#/ with other, then returns the #floor'ed result
fails:Numeric#div raises ZeroDivisionError for 0
2 changes: 0 additions & 2 deletions spec/truffle/tags/core/numeric/eql_tags.txt

This file was deleted.

6 changes: 0 additions & 6 deletions spec/truffle/tags/core/numeric/fdiv_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/numeric/floor_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/core/numeric/i_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/numeric/imag_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/numeric/imaginary_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/numeric/integer_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/numeric/magnitude_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/numeric/modulo_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/numeric/nonzero_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/numeric/numerator_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/numeric/numeric_tags.txt

This file was deleted.

4 changes: 0 additions & 4 deletions spec/truffle/tags/core/numeric/phase_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/core/numeric/polar_tags.txt

This file was deleted.

7 changes: 0 additions & 7 deletions spec/truffle/tags/core/numeric/quo_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/core/numeric/real_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/core/numeric/rect_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/core/numeric/rectangular_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/numeric/round_tags.txt

This file was deleted.

43 changes: 0 additions & 43 deletions spec/truffle/tags/core/numeric/step_tags.txt
Original file line number Diff line number Diff line change
@@ -1,50 +1,7 @@
fails:Numeric#step raises an ArgumentError when step is 0
fails:Numeric#step raises an ArgumentError when step is 0.0
fails:Numeric#step defaults to step = 1
fails:Numeric#step returns an Enumerator when step is 0
fails:Numeric#step returns an Enumerator when not passed a block and self > stop
fails:Numeric#step returns an Enumerator when not passed a block and self < stop
fails:Numeric#step returns an Enumerator that uses the given step
fails:Numeric#step does not rescue ArgumentError exceptions
fails:Numeric#step does not rescue TypeError exceptions
fails:Numeric#step with [stop, step] increments self using #+ until self > stop when step > 0
fails:Numeric#step with [stop, step] decrements self using #+ until self < stop when step < 0
fails:Numeric#step Numeric#step with [stop, step] when self, stop and step are Fixnums yields only Fixnums
fails:Numeric#step Numeric#step with [stop, step] when self and stop are Fixnums but step is a String returns an Enumerator if not given a block
fails:Numeric#step Numeric#step with [stop, step] when self and stop are Fixnums but step is a String raises an ArgumentError if given a block
fails:Numeric#step Numeric#step with [stop, step] when self and stop are Floats but step is a String returns an Enumerator if not given a block
fails:Numeric#step Numeric#step with [stop, step] when self and stop are Floats but step is a String raises a TypeError if given a block
fails:Numeric#step Numeric#step with [stop, +step] when self, stop and step are Fixnums yields while increasing self by step until stop is reached
fails:Numeric#step Numeric#step with [stop, +step] when self, stop and step are Fixnums yields once when self equals stop
fails:Numeric#step Numeric#step with [stop, +step] when self, stop and step are Fixnums does not yield when self is greater than stop
fails:Numeric#step Numeric#step with [stop, -step] when self, stop and step are Fixnums yields while decreasing self by step until stop is reached
fails:Numeric#step Numeric#step with [stop, -step] when self, stop and step are Fixnums yields once when self equals stop
fails:Numeric#step Numeric#step with [stop, -step] when self, stop and step are Fixnums does not yield when self is less than stop
fails:Numeric#step Numeric#step with [stop, step] yields only Floats when self is a Float
fails:Numeric#step Numeric#step with [stop, step] yields only Floats when stop is a Float
fails:Numeric#step Numeric#step with [stop, step] yields only Floats when step is a Float
fails:Numeric#step Numeric#step with [stop, +step] when self, stop or step is a Float yields while increasing self by step while < stop
fails:Numeric#step Numeric#step with [stop, +step] when self, stop or step is a Float yields once when self equals stop
fails:Numeric#step Numeric#step with [stop, +step] when self, stop or step is a Float does not yield when self is greater than stop
fails:Numeric#step Numeric#step with [stop, +step] when self, stop or step is a Float is careful about not yielding a value greater than limit
fails:Numeric#step Numeric#step with [stop, -step] when self, stop or step is a Float yields while decreasing self by step while self > stop
fails:Numeric#step Numeric#step with [stop, -step] when self, stop or step is a Float yields once when self equals stop
fails:Numeric#step Numeric#step with [stop, -step] when self, stop or step is a Float does not yield when self is less than stop
fails:Numeric#step Numeric#step with [stop, -step] when self, stop or step is a Float is careful about not yielding a value smaller than limit
fails:Numeric#step Numeric#step with [stop, +Infinity] yields once if self < stop
fails:Numeric#step Numeric#step with [stop, +Infinity] yields once when stop is Infinity
fails:Numeric#step Numeric#step with [stop, +Infinity] yields once when self equals stop
fails:Numeric#step Numeric#step with [stop, +Infinity] yields once when self and stop are Infinity
fails:Numeric#step Numeric#step with [stop, +Infinity] does not yield when self > stop
fails:Numeric#step Numeric#step with [stop, +Infinity] does not yield when stop is -Infinity
fails:Numeric#step Numeric#step with [stop, -infinity] yields once if self > stop
fails:Numeric#step Numeric#step with [stop, -infinity] yields once if stop is -Infinity
fails:Numeric#step Numeric#step with [stop, -infinity] yields once when self equals stop
fails:Numeric#step Numeric#step with [stop, -infinity] yields once when self and stop are Infinity
fails:Numeric#step Numeric#step with [stop, -infinity] does not yield when self > stop
fails:Numeric#step Numeric#step with [stop, -infinity] does not yield when stop is Infinity
fails:Numeric#step Numeric#step with [infinity, -step] does not yield when self is -infinity
fails:Numeric#step Numeric#step with [infinity, -step] does not yield when self is +infinity
fails:Numeric#step Numeric#step with [infinity, step] does not yield when self is infinity
fails:Numeric#step Numeric#step with [-infinity, step] does not yield when self is -infinity
fails:Numeric#step Numeric#step with [-infinity, -step] does not yield when self is -infinity
3 changes: 0 additions & 3 deletions spec/truffle/tags/core/numeric/to_c_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/numeric/to_int_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/numeric/truncate_tags.txt

This file was deleted.

3 changes: 0 additions & 3 deletions spec/truffle/tags/core/numeric/uminus_tags.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
fails:Numeric#-@ returns the same value with opposite sign (integers)
fails:Numeric#-@ returns the same value with opposite sign (floats)
fails:Numeric#-@ returns the same value with opposite sign (two complement)
fails:Numeric#-@ with a Numeric subclass calls #coerce(0) on self, then subtracts the second element of the result from the first
1 change: 0 additions & 1 deletion spec/truffle/tags/core/numeric/uplus_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/numeric/zero_tags.txt

This file was deleted.

11 changes: 11 additions & 0 deletions truffle/src/main/java/org/jruby/truffle/nodes/core/ArrayNodes.java
Original file line number Diff line number Diff line change
@@ -1749,6 +1749,17 @@ public Object firstIntegerFixnum(RubyArray array) {
}
}

@Specialization(guards = "isFloat")
public Object firstFloat(RubyArray array) {
notDesignedForCompilation();

if (array.getSize() == 0) {
return getContext().getCoreLibrary().getNilObject();
} else {
return ((double[]) array.getStore())[0];
}
}

@Specialization(guards = "isObject")
public Object firstObject(RubyArray array) {
notDesignedForCompilation();
Original file line number Diff line number Diff line change
@@ -119,7 +119,6 @@ public Object add(int a, RubyBignum b) {
public Object add(VirtualFrame frame, int a, RubyBasicObject b) {
if (rationalAdd == null) {
CompilerDirectives.transferToInterpreterAndInvalidate();

rationalAdd = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
}

@@ -172,12 +171,17 @@ public Object add(VirtualFrame frame, long a, RubyBasicObject b) {
@CoreMethod(names = "-", required = 1)
public abstract static class SubNode extends BignumNodes.BignumCoreMethodNode {

@Child private CallDispatchHeadNode rationalConvertNode;
@Child private CallDispatchHeadNode rationalSubNode;

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

public SubNode(SubNode prev) {
super(prev);
rationalConvertNode = prev.rationalConvertNode;
rationalSubNode = prev.rationalSubNode;
}

@Specialization(rewriteOn = ArithmeticException.class)
@@ -210,6 +214,19 @@ public double sub(int a, double b) {
return a - b;
}

@Specialization(guards = "isRational(arguments[1])")
public Object sub(VirtualFrame frame, int a, RubyBasicObject b) {
if (rationalConvertNode == null) {
CompilerDirectives.transferToInterpreter();
rationalConvertNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext(), true));
rationalSubNode = insert(DispatchHeadNodeFactory.createMethodCall(getContext()));
}

final Object aComplex = rationalConvertNode.call(frame, getContext().getCoreLibrary().getRationalClass(), "convert", null, a, 1);

return rationalSubNode.call(frame, aComplex, "-", null, b);
}

@Specialization(rewriteOn = ArithmeticException.class)
public long sub(long a, int b) {
return ExactMath.subtractExact(a, b);
Original file line number Diff line number Diff line change
@@ -118,9 +118,14 @@ public StringToFPrimitiveNode(StringToFPrimitiveNode prev) {
}

@Specialization
public double stringToF(RubyString string) {
public Object stringToF(RubyString string) {
notDesignedForCompilation();
return Double.parseDouble(string.toString());

try {
return Double.parseDouble(string.toString());
} catch (NumberFormatException e) {
return null;
}
}

}