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

Commits on Jan 25, 2015

  1. Unverified

    This commit is not signed, but one or more authors requires that any commit attributed to them is signed.
    Copy the full SHA
    15de93a View commit details
  2. [Truffle] Integer#ceil

    chrisseaton committed Jan 25, 2015
    Copy the full SHA
    0786d18 View commit details
  3. [Truffle] Integer#chr

    chrisseaton committed Jan 25, 2015
    Copy the full SHA
    8fe7e55 View commit details
  4. [Truffle] Integer#downto

    chrisseaton committed Jan 25, 2015
    Copy the full SHA
    4b58b18 View commit details
  5. Copy the full SHA
    ad55849 View commit details
  6. Copy the full SHA
    783df93 View commit details
  7. [Truffle] Integer#ord

    chrisseaton committed Jan 25, 2015
    Copy the full SHA
    f1f8fdc View commit details
  8. [Truffle] Integer#pred

    chrisseaton committed Jan 25, 2015
    Copy the full SHA
    6caabb4 View commit details
  9. Copy the full SHA
    c4348f1 View commit details
  10. [Truffle] Integer#round

    chrisseaton committed Jan 25, 2015
    Copy the full SHA
    79502d9 View commit details
  11. Copy the full SHA
    f22abf7 View commit details
  12. [Truffle] Integer#upto

    chrisseaton committed Jan 25, 2015
    Copy the full SHA
    ca65763 View commit details
Showing with 262 additions and 162 deletions.
  1. +3 −0 core/src/main/ruby/jruby/truffle/core/fixnum.rb
  2. +5 −0 core/src/main/ruby/jruby/truffle/core/rubinius/kernel/bootstrap/string.rb
  3. +106 −0 core/src/main/ruby/jruby/truffle/core/rubinius/kernel/common/integer.rb
  4. +0 −1 spec/truffle/tags/core/integer/ceil_tags.txt
  5. +1 −23 spec/truffle/tags/core/integer/chr_tags.txt
  6. +0 −1 spec/truffle/tags/core/integer/denominator_tags.txt
  7. +0 −5 spec/truffle/tags/core/integer/downto_tags.txt
  8. +0 −1 spec/truffle/tags/core/integer/even_tags.txt
  9. +0 −1 spec/truffle/tags/core/integer/floor_tags.txt
  10. +0 −11 spec/truffle/tags/core/integer/gcd_tags.txt
  11. +0 −10 spec/truffle/tags/core/integer/gcdlcm_tags.txt
  12. +0 −2 spec/truffle/tags/core/integer/integer_tags.txt
  13. +0 −11 spec/truffle/tags/core/integer/lcm_tags.txt
  14. +0 −6 spec/truffle/tags/core/integer/next_tags.txt
  15. +0 −1 spec/truffle/tags/core/integer/numerator_tags.txt
  16. +0 −1 spec/truffle/tags/core/integer/odd_tags.txt
  17. +0 −1 spec/truffle/tags/core/integer/ord_tags.txt
  18. +0 −1 spec/truffle/tags/core/integer/pred_tags.txt
  19. +0 −5 spec/truffle/tags/core/integer/rationalize_tags.txt
  20. +0 −10 spec/truffle/tags/core/integer/round_tags.txt
  21. +0 −6 spec/truffle/tags/core/integer/succ_tags.txt
  22. +0 −8 spec/truffle/tags/core/integer/times_tags.txt
  23. +0 −1 spec/truffle/tags/core/integer/to_i_tags.txt
  24. +0 −1 spec/truffle/tags/core/integer/to_int_tags.txt
  25. +0 −5 spec/truffle/tags/core/integer/to_r_tags.txt
  26. +0 −1 spec/truffle/tags/core/integer/truncate_tags.txt
  27. +0 −5 spec/truffle/tags/core/integer/upto_tags.txt
  28. +22 −4 truffle/src/main/java/org/jruby/truffle/nodes/core/BignumNodes.java
  29. +3 −2 truffle/src/main/java/org/jruby/truffle/nodes/core/EncodingNodes.java
  30. +48 −32 truffle/src/main/java/org/jruby/truffle/nodes/core/IntegerNodes.java
  31. +59 −0 truffle/src/main/java/org/jruby/truffle/nodes/rubinius/StringPrimitiveNodes.java
  32. +15 −6 truffle/src/main/java/org/jruby/truffle/runtime/core/CoreLibrary.java
3 changes: 3 additions & 0 deletions core/src/main/ruby/jruby/truffle/core/fixnum.rb
Original file line number Diff line number Diff line change
@@ -34,6 +34,9 @@

class Fixnum

MIN = -9223372036854775808
MAX = 9223372036854775807

def left_shift_fallback(other)
# Fallback from Rubinius' Fixnum#<<, after the primitive call

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

class String

def self.from_codepoint(code, enc)
Rubinius.primitive :string_from_codepoint
raise PrimitiveFailure, "String.from_codepoint primitive failed"
end

def find_string(pattern, start)
Rubinius.primitive :string_index
raise PrimitiveFailure, "String#find_string primitive failed"
Original file line number Diff line number Diff line change
@@ -58,10 +58,116 @@ def odd?
self & 1 == 1
end

def pred
self - 1
end

def next
self + 1
end

alias_method :succ, :next
alias_method :ceil, :to_i
alias_method :floor, :to_i
alias_method :truncate, :to_i

def chr(enc=undefined)
if self < 0 || (self & 0xffff_ffff) != self
raise RangeError, "#{self} is outside of the valid character range"
end

if undefined.equal? enc
if 0xff < self
enc = Encoding.default_internal
if enc.nil?
raise RangeError, "#{self} is outside of the valid character range"
end
elsif self < 0x80
enc = Encoding::US_ASCII
else
enc = Encoding::ASCII_8BIT
end
else
enc = Rubinius::Type.coerce_to_encoding enc
end

String.from_codepoint self, enc
end

def lcm(other)
raise TypeError, "Expected Integer but got #{other.class}" unless other.kind_of?(Integer)
if self.zero? or other.zero?
0
else
(self.div(self.gcd(other)) * other).abs
end
end

def gcdlcm(other)
gcd = self.gcd(other)
if self.zero? or other.zero?
[gcd, 0]
else
[gcd, (self.div(gcd) * other).abs]
end
end

def integer?
true
end

def ord
self
end

def rationalize(eps = nil)
Rational(self, 1)
end

def round(ndigits=undefined)
return self if undefined.equal? ndigits

if ndigits.kind_of? Numeric
if ndigits > Fixnum::MAX or ndigits <= Fixnum::MIN
raise RangeError, "precision is outside of the range of Fixnum"
end
end

ndigits = Rubinius::Type.coerce_to ndigits, Integer, :to_int

if ndigits > 0
to_f
elsif ndigits == 0
self
else
ndigits = -ndigits

# We want to return 0 if 10 ** ndigits / 2 > self.abs, or, taking
# log_256 of both sides, if log_256(10 ** ndigits / 2) > self.size.
# We have log_256(10) > 0.415241 and log_256(2) = 0.125, so:
return 0 if 0.415241 * ndigits - 0.125 > size

f = 10 ** ndigits

if kind_of? Fixnum and f.kind_of? Fixnum
x = self < 0 ? -self : self
x = (x + f / 2) / f * f
x = -x if self < 0
return x
end

return 0 if f.kind_of? Float

h = f / 2
r = self % f
n = self - r

unless self < 0 ? r <= h : r < h
n += f
end

n
end
end

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

This file was deleted.

24 changes: 1 addition & 23 deletions spec/truffle/tags/core/integer/chr_tags.txt
Original file line number Diff line number Diff line change
@@ -1,23 +1 @@
fails:Integer#chr without argument returns a String
fails:Integer#chr without argument returns a new String for each call
fails:Integer#chr without argument raises a RangeError is self is less than 0
fails:Integer#chr without argument when Encoding.default_internal is nil raises a RangeError is self is greater than 255
fails:Integer#chr without argument when Encoding.default_internal is nil and self is between 0 and 127 (inclusive) returns a US-ASCII String
fails:Integer#chr without argument when Encoding.default_internal is nil and self is between 0 and 127 (inclusive) returns a String encoding self interpreted as a US-ASCII codepoint
fails:Integer#chr without argument when Encoding.default_internal is nil and self is between 128 and 255 (inclusive) returns an ASCII-8BIT String
fails:Integer#chr without argument when Encoding.default_internal is nil and self is between 128 and 255 (inclusive) returns a String containing self interpreted as a byte
fails:Integer#chr without argument when Encoding.default_internal is not nil and self is between 0 and 127 (inclusive) returns a US-ASCII String
fails:Integer#chr without argument when Encoding.default_internal is not nil and self is between 0 and 127 (inclusive) returns a String encoding self interpreted as a US-ASCII codepoint
fails:Integer#chr without argument when Encoding.default_internal is not nil and self is between 128 and 255 (inclusive) returns an ASCII-8BIT String
fails:Integer#chr without argument when Encoding.default_internal is not nil and self is between 128 and 255 (inclusive) returns a String containing self interpreted as a byte
fails:Integer#chr without argument when Encoding.default_internal is not nil and self is greater than 255 returns a String with the default internal encoding
fails:Integer#chr without argument when Encoding.default_internal is not nil and self is greater than 255 returns a String encoding self interpreted as a codepoint in the default internal encoding
fails:Integer#chr without argument when Encoding.default_internal is not nil and self is greater than 255 raises RangeError if self is invalid as a codepoint in the default internal encoding
fails:Integer#chr with an encoding argument returns a String
fails:Integer#chr with an encoding argument returns a new String for each call
fails:Integer#chr with an encoding argument accepts a String as an argument
fails:Integer#chr with an encoding argument converts a String to an Encoding as Encoding.find does
fails:Integer#chr with an encoding argument raises a RangeError is self is less than 0
fails:Integer#chr with an encoding argument returns a String with the specified encoding
fails:Integer#chr with an encoding argument returns a String encoding self interpreted as a codepoint in the specified encoding
fails:Integer#chr with an encoding argument raises RangeError if self is invalid as a codepoint in the specified encoding
fails(jcodings?):Integer#chr with an encoding argument raises RangeError if self is invalid as a codepoint in the specified encoding
1 change: 0 additions & 1 deletion spec/truffle/tags/core/integer/denominator_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/core/integer/downto_tags.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
fails:Integer#downto [stop] when self and stop are Fixnums does not yield when stop is greater than self
fails:Integer#downto [stop] when self and stop are Fixnums yields once when stop equals self
fails:Integer#downto [stop] when self and stop are Fixnums yields while decreasing self until it is less than stop
fails:Integer#downto [stop] when self and stop are Fixnums yields while decreasing self until it less than ceil for a Float endpoint
fails:Integer#downto [stop] when self and stop are Fixnums raises an ArgumentError for invalid endpoints
fails:Integer#downto [stop] when self and stop are Fixnums returns an Enumerator
1 change: 0 additions & 1 deletion spec/truffle/tags/core/integer/even_tags.txt

This file was deleted.

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

This file was deleted.

11 changes: 0 additions & 11 deletions spec/truffle/tags/core/integer/gcd_tags.txt

This file was deleted.

10 changes: 0 additions & 10 deletions spec/truffle/tags/core/integer/gcdlcm_tags.txt

This file was deleted.

2 changes: 0 additions & 2 deletions spec/truffle/tags/core/integer/integer_tags.txt

This file was deleted.

11 changes: 0 additions & 11 deletions spec/truffle/tags/core/integer/lcm_tags.txt

This file was deleted.

6 changes: 0 additions & 6 deletions spec/truffle/tags/core/integer/next_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/integer/numerator_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/integer/odd_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/integer/ord_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/integer/pred_tags.txt

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/core/integer/rationalize_tags.txt

This file was deleted.

10 changes: 0 additions & 10 deletions spec/truffle/tags/core/integer/round_tags.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1 @@
fails:Integer#round returns self
fails:Integer#round rounds itself as a float if passed a positive precision
fails:Integer#round returns itself if passed zero
fails:Integer#round returns itself rounded if passed a negative value
fails:Integer#round raises a RangeError when passed a big negative value
fails:Integer#round raises a RangeError when passed Float::INFINITY
fails:Integer#round raises a RangeError when passed a beyond signed int
fails:Integer#round raises a TypeError when passed a String
fails:Integer#round raises a TypeError when its argument cannot be converted to an Integer
fails:Integer#round calls #to_int on the argument to convert it to an Integer
fails:Integer#round raises a TypeError when #to_int does not return an Integer
6 changes: 0 additions & 6 deletions spec/truffle/tags/core/integer/succ_tags.txt

This file was deleted.

8 changes: 0 additions & 8 deletions spec/truffle/tags/core/integer/times_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/truffle/tags/core/integer/to_i_tags.txt

This file was deleted.

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

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/core/integer/to_r_tags.txt

This file was deleted.

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

This file was deleted.

5 changes: 0 additions & 5 deletions spec/truffle/tags/core/integer/upto_tags.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1 @@
fails:Integer#upto [stop] when self and stop are Fixnums does not yield when stop is less than self
fails:Integer#upto [stop] when self and stop are Fixnums yields once when stop equals self
fails:Integer#upto [stop] when self and stop are Fixnums yields while increasing self until it is less than stop
fails:Integer#upto [stop] when self and stop are Fixnums yields while increasing self until it is greater than floor of a Float endpoint
fails:Integer#upto [stop] when self and stop are Fixnums raises an ArgumentError for non-numeric endpoints
fails:Integer#upto [stop] when self and stop are Fixnums returns an Enumerator
Original file line number Diff line number Diff line change
@@ -77,13 +77,13 @@ public AddNode(AddNode prev) {
}

@Specialization
public RubyBignum add(RubyBignum a, int b) {
return a.add(b);
public Object add(RubyBignum a, int b) {
return fixnumOrBignum(a.add(b));
}

@Specialization
public RubyBignum add(RubyBignum a, long b) {
return a.add(b);
public Object add(RubyBignum a, long b) {
return fixnumOrBignum(a.add(b));
}

@Specialization
@@ -692,6 +692,24 @@ public int hash(RubyBignum self) {

}

@CoreMethod(names = "size")
public abstract static class SizeNode extends CoreMethodNode {

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

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

@Specialization
public int size(RubyBignum value) {
return value.bigIntegerValue().bitLength();
}

}

@CoreMethod(names = "to_f")
public abstract static class ToFNode extends CoreMethodNode {

Original file line number Diff line number Diff line change
@@ -108,13 +108,14 @@ public DefaultInternalNode(DefaultInternalNode prev) {
}

@Specialization
public RubyEncoding defaultInternal() {
public Object defaultInternal() {
notDesignedForCompilation();

Encoding encoding = getContext().getRuntime().getDefaultInternalEncoding();

if (encoding == null) {
encoding = UTF8Encoding.INSTANCE;
return getContext().getCoreLibrary().getNilObject();
//encoding = UTF8Encoding.INSTANCE;
}

return RubyEncoding.getEncoding(encoding);
Loading