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: a714158a6fe5
Choose a base ref
...
head repository: jruby/jruby
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8bd21ecd4198
Choose a head ref

Commits on Jul 18, 2017

  1. Copy the full SHA
    0de8ebb View commit details
  2. Copy the full SHA
    0426982 View commit details
  3. Copy the full SHA
    40aca14 View commit details
  4. Copy the full SHA
    61db2ce View commit details

Commits on Jul 19, 2017

  1. Copy the full SHA
    63ea2ac View commit details

Commits on Jul 20, 2017

  1. Copy the full SHA
    5e68ee4 View commit details
  2. Copy the full SHA
    d15def1 View commit details
  3. Copy the full SHA
    171d2e2 View commit details
  4. Copy the full SHA
    d612739 View commit details
  5. Fix Range marshaling.

    * Use begini and endi names from MRI for stream compatibility.
    * Error if any marshaled pieces can't be found in the stream.
    headius committed Jul 20, 2017
    Copy the full SHA
    98cf3d8 View commit details
  6. Copy the full SHA
    b74ff3f View commit details
  7. Copy the full SHA
    4d076d8 View commit details

Commits on Jul 21, 2017

  1. Copy the full SHA
    941a7b0 View commit details
  2. Copy the full SHA
    fe237b9 View commit details

Commits on Jul 24, 2017

  1. Copy the full SHA
    ebbef48 View commit details
  2. Copy the full SHA
    60cb226 View commit details
  3. Copy the full SHA
    3c21a91 View commit details
  4. Copy the full SHA
    304342c View commit details

Commits on Jul 25, 2017

  1. Copy the full SHA
    4b13469 View commit details
  2. Copy the full SHA
    637ca8a View commit details
  3. Copy the full SHA
    c8f8c10 View commit details
  4. Copy the full SHA
    a133cb3 View commit details
  5. Copy the full SHA
    d331d07 View commit details
  6. Fix typo.

    headius committed Jul 25, 2017
    Copy the full SHA
    2c3b3bd View commit details
  7. Copy the full SHA
    afdf0a8 View commit details
  8. Provide a more accurate fixable using Big* logic.

    This is to fix cases like rounding floats near FIXNUM_MAX to an
    integer, which may produce a Bignum of FIXNUM_MAX + 1 versus
    a Fixnum of FIXNUM_MAX. Java's cast from double to long prefers
    the latter, truncating the remainder to FIXNUM_MAX.
    
    Note that the more-accurate Big* logic has the overhead of a Java
    BigDecimal and BigInteger at minimum, so I have tried to limit its
    application to cases around fixnum max and min.
    headius committed Jul 25, 2017
    Copy the full SHA
    7405e6c View commit details
  9. Copy the full SHA
    5f4caec View commit details
  10. Copy the full SHA
    52b881d View commit details
  11. Constants and a lot more ident symbol creation (half measure since I …

    …originally
    
    thought I could only change a couple of things and it rippled through
    RubyParser).
    enebo committed Jul 25, 2017
    Copy the full SHA
    349ddfd View commit details

Commits on Jul 26, 2017

  1. Copy the full SHA
    8bd21ec View commit details
Showing with 4,830 additions and 4,492 deletions.
  1. +1 −1 core/pom.rb
  2. +1 −1 core/pom.xml
  3. +6 −6 core/src/main/java/org/jruby/Ruby.java
  4. +5 −2 core/src/main/java/org/jruby/RubyArray.java
  5. +59 −19 core/src/main/java/org/jruby/RubyBignum.java
  6. +7 −1 core/src/main/java/org/jruby/RubyFixnum.java
  7. +21 −20 core/src/main/java/org/jruby/RubyFloat.java
  8. +76 −20 core/src/main/java/org/jruby/RubyIO.java
  9. +120 −34 core/src/main/java/org/jruby/RubyInteger.java
  10. +5 −1 core/src/main/java/org/jruby/RubyKernel.java
  11. +131 −65 core/src/main/java/org/jruby/RubyNumeric.java
  12. +18 −5 core/src/main/java/org/jruby/RubyRange.java
  13. +20 −15 core/src/main/java/org/jruby/RubyRational.java
  14. +2 −2 core/src/main/java/org/jruby/RubySignal.java
  15. +16 −10 core/src/main/java/org/jruby/RubyString.java
  16. +9 −22 core/src/main/java/org/jruby/ast/ArgumentNode.java
  17. +10 −11 core/src/main/java/org/jruby/ast/AttrAssignNode.java
  18. +10 −17 core/src/main/java/org/jruby/ast/CallNode.java
  19. +10 −11 core/src/main/java/org/jruby/ast/ClassVarAsgnNode.java
  20. +10 −16 core/src/main/java/org/jruby/ast/ClassVarNode.java
  21. +2 −9 core/src/main/java/org/jruby/ast/Colon2ConstNode.java
  22. +2 −7 core/src/main/java/org/jruby/ast/Colon2ImplicitNode.java
  23. +3 −10 core/src/main/java/org/jruby/ast/Colon2Node.java
  24. +11 −16 core/src/main/java/org/jruby/ast/Colon3Node.java
  25. +12 −13 core/src/main/java/org/jruby/ast/ConstDeclNode.java
  26. +10 −16 core/src/main/java/org/jruby/ast/ConstNode.java
  27. +6 −16 core/src/main/java/org/jruby/ast/FCallNode.java
  28. +10 −11 core/src/main/java/org/jruby/ast/GlobalAsgnNode.java
  29. +10 −10 core/src/main/java/org/jruby/ast/GlobalVarNode.java
  30. +11 −17 core/src/main/java/org/jruby/ast/InstAsgnNode.java
  31. +10 −16 core/src/main/java/org/jruby/ast/InstVarNode.java
  32. +2 −7 core/src/main/java/org/jruby/ast/KeywordRestArgNode.java
  33. +4 −10 core/src/main/java/org/jruby/ast/OpAsgnConstDeclNode.java
  34. +9 −15 core/src/main/java/org/jruby/ast/OpAsgnNode.java
  35. +6 −13 core/src/main/java/org/jruby/ast/OpElementAsgnNode.java
  36. +4 −4 core/src/main/java/org/jruby/ast/RestArgNode.java
  37. +3 −2 core/src/main/java/org/jruby/ast/UnnamedRestArgNode.java
  38. +43 −11 core/src/main/java/org/jruby/ext/stringio/StringIO.java
  39. +21 −17 core/src/main/java/org/jruby/ir/IRBuilder.java
  40. +6 −0 core/src/main/java/org/jruby/ir/IRClassBody.java
  41. +1 −1 core/src/main/java/org/jruby/ir/IRClosure.java
  42. +2 −1 core/src/main/java/org/jruby/ir/IRManager.java
  43. +7 −0 core/src/main/java/org/jruby/ir/IRMethod.java
  44. +6 −0 core/src/main/java/org/jruby/ir/IRModuleBody.java
  45. +19 −2 core/src/main/java/org/jruby/ir/IRScope.java
  46. +5 −1 core/src/main/java/org/jruby/ir/IRScriptBody.java
  47. +18 −10 core/src/main/java/org/jruby/ir/instructions/SearchConstInstr.java
  48. +12 −8 core/src/main/java/org/jruby/ir/instructions/SearchModuleForConstInstr.java
  49. +1 −0 core/src/main/java/org/jruby/ir/runtime/IRRuntimeHelpers.java
  50. +51 −50 core/src/main/java/org/jruby/lexer/LexingCommon.java
  51. +1 −1 core/src/main/java/org/jruby/management/BeanManagerImpl.java
  52. +76 −93 core/src/main/java/org/jruby/parser/ParserSupport.java
  53. +376 −374 core/src/main/java/org/jruby/parser/RubyParser.java
  54. +172 −168 core/src/main/java/org/jruby/parser/RubyParser.y
  55. +3,265 −3,257 core/src/main/java/org/jruby/parser/YyTables.java
  56. +3 −0 core/src/main/java/org/jruby/runtime/JavaSites.java
  57. +9 −4 core/src/main/java/org/jruby/util/Numeric.java
  58. +63 −11 core/src/main/java/org/jruby/util/StringSupport.java
  59. +1 −4 core/src/main/java/org/jruby/util/TypeConverter.java
  60. +11 −5 core/src/main/java/org/jruby/util/io/OpenFile.java
  61. +1 −1 core/src/main/ruby/jruby/kernel/proc.rb
  62. +4 −2 test/mri/excludes/TestRubyOptions.rb
  63. +2 −0 test/mri/excludes/TestSyntax.rb
  64. +1 −0 test/mri/excludes/TestTime.rb
  65. +1 −0 test/mri/excludes/TestUnicodeEscape.rb
2 changes: 1 addition & 1 deletion core/pom.rb
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@

jar 'org.jruby.joni:joni:2.1.12-SNAPSHOT'
jar 'org.jruby.extras:bytelist:1.0.15'
jar 'org.jruby.jcodings:jcodings:1.0.18'
jar 'org.jruby.jcodings:jcodings:1.0.20'
jar 'org.jruby:dirgra:0.3'

jar 'com.headius:invokebinder:1.8-SNAPSHOT'
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
@@ -183,7 +183,7 @@ DO NOT MODIFIY - GENERATED CODE
<dependency>
<groupId>org.jruby.jcodings</groupId>
<artifactId>jcodings</artifactId>
<version>1.0.18</version>
<version>1.0.20</version>
</dependency>
<dependency>
<groupId>org.jruby</groupId>
12 changes: 6 additions & 6 deletions core/src/main/java/org/jruby/Ruby.java
Original file line number Diff line number Diff line change
@@ -700,25 +700,25 @@ public IRubyObject runWithGetsLoop(RootNode scriptNode, boolean printing, boolea
private RootNode addGetsLoop(RootNode oldRoot, boolean printing, boolean processLineEndings, boolean split) {
ISourcePosition pos = oldRoot.getPosition();
BlockNode newBody = new BlockNode(pos);
newBody.add(new GlobalAsgnNode(pos, "$/", new StrNode(pos, ((RubyString) globalVariables.get("$/")).getByteList())));
newBody.add(new GlobalAsgnNode(pos, newSymbol("$/"), new StrNode(pos, ((RubyString) globalVariables.get("$/")).getByteList())));

if (processLineEndings) newBody.add(new GlobalAsgnNode(pos, "$\\", new GlobalVarNode(pos, "$/")));
if (processLineEndings) newBody.add(new GlobalAsgnNode(pos, newSymbol("$\\"), new GlobalVarNode(pos, newSymbol("$/"))));

GlobalVarNode dollarUnderscore = new GlobalVarNode(pos, "$_");
GlobalVarNode dollarUnderscore = new GlobalVarNode(pos, newSymbol("$_"));

BlockNode whileBody = new BlockNode(pos);
newBody.add(new WhileNode(pos, new VCallNode(pos, "gets"), whileBody));

if (processLineEndings) whileBody.add(new CallNode(pos, dollarUnderscore, "chop!", null, null));
if (split) whileBody.add(new GlobalAsgnNode(pos, "$F", new CallNode(pos, dollarUnderscore, "split", null, null)));
if (processLineEndings) whileBody.add(new CallNode(pos, dollarUnderscore, newSymbol("chop!"), null, null, false));
if (split) whileBody.add(new GlobalAsgnNode(pos, newSymbol("$F"), new CallNode(pos, dollarUnderscore, newSymbol("split"), null, null, false)));

if (oldRoot.getBodyNode() instanceof BlockNode) { // common case n stmts
whileBody.addAll(((BlockNode) oldRoot.getBodyNode()));
} else { // single expr script
whileBody.add(oldRoot.getBodyNode());
}

if (printing) whileBody.add(new FCallNode(pos, "puts", new ArrayNode(pos, dollarUnderscore), null));
if (printing) whileBody.add(new FCallNode(pos, newSymbol("puts"), new ArrayNode(pos, dollarUnderscore), null));

return new RootNode(pos, oldRoot.getScope(), newBody, oldRoot.getFile());
}
7 changes: 5 additions & 2 deletions core/src/main/java/org/jruby/RubyArray.java
Original file line number Diff line number Diff line change
@@ -4645,8 +4645,11 @@ public RubyString pack(ThreadContext context, IRubyObject obj, IRubyObject maybe
RubyString str;

try {
IRubyObject buffer = opts.convertToHash().fastARef(runtime.newSymbol("buffer"));
if (buffer != null) {
IRubyObject buffer = ArgsUtil.extractKeywordArg(context, "buffer", opts);
if (!buffer.isNil() && !(buffer instanceof RubyString)) {
throw runtime.newTypeError("buffer must be String, not " + buffer.getType().getName());
}
if (buffer.isNil()) {
str = buffer.convertToString();
} else {
str = RubyString.newString(runtime, "");
78 changes: 59 additions & 19 deletions core/src/main/java/org/jruby/RubyBignum.java
Original file line number Diff line number Diff line change
@@ -89,6 +89,11 @@ public static RubyBignum newBignum(Ruby runtime, long value) {
return newBignum(runtime, BigInteger.valueOf(value));
}

/**
* Return a Bignum for the given value, or raise FloatDomainError if it is out of range.
*
* Note this method may return Bignum that are in Fixnum range.
*/
public static RubyBignum newBignum(Ruby runtime, double value) {
try {
return newBignum(runtime, new BigDecimal(value).toBigInteger());
@@ -97,6 +102,19 @@ public static RubyBignum newBignum(Ruby runtime, double value) {
}
}

/**
* Return a Bignum or Fixnum (Integer) for the given value, or raise FloatDomainError if it is out of range.
*
* MRI: rb_dbl2big
*/
public static RubyInteger newBignorm(Ruby runtime, double value) {
try {
return bignorm(runtime, new BigDecimal(value).toBigInteger());
} catch (NumberFormatException nfe) {
throw runtime.newFloatDomainError(Double.toString(value));
}
}

public static RubyBignum newBignum(Ruby runtime, BigInteger value) {
return new RubyBignum(runtime, value);
}
@@ -547,7 +565,7 @@ public IRubyObject op_div(ThreadContext context, IRubyObject other) {
*
*/
@Override
public IRubyObject op_idiv(ThreadContext context, IRubyObject other) {
public IRubyObject idiv(ThreadContext context, IRubyObject other) {
return op_divide(context, other, false);
}

@@ -683,17 +701,32 @@ public IRubyObject op_pow(ThreadContext context, IRubyObject other) {
Ruby runtime = context.runtime;
if (other == RubyFixnum.zero(runtime)) return RubyFixnum.one(runtime);
final double d;
if (other instanceof RubyFixnum) {
return op_pow(context, ((RubyFixnum) other).getLongValue());
} else if (other instanceof RubyBignum) {
d = ((RubyBignum) other).getDoubleValue();
context.runtime.getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big");
} else if (other instanceof RubyFloat) {
if (other instanceof RubyFloat) {
d = ((RubyFloat) other).getDoubleValue();
if (compareTo(RubyFixnum.zero(runtime)) == -1 && d != Math.round(d)) {
RubyComplex complex = RubyComplex.newComplexRaw(context.runtime, this);
return sites(context).op_exp.call(context, complex, complex, other);
}
} else if (other instanceof RubyBignum) {
d = ((RubyBignum) other).getDoubleValue();
context.runtime.getWarnings().warn(ID.MAY_BE_TOO_BIG, "in a**b, b may be too big");
} else if (other instanceof RubyFixnum) {
long yy = other.convertToInteger().getLongValue();
if (yy < 0)
return RubyRational.newRationalRaw(runtime, this).op_expt(context, other);
else {
int xbits = value.bitLength();
int BIGLEN_LIMIT = 32*1024*1024;

if ((xbits > BIGLEN_LIMIT) ||
(xbits * yy > BIGLEN_LIMIT)) {
runtime.getWarnings().warn("in a**b, b may be too big");
d = (double)yy;
}
else {
return newBignum(runtime, value.pow((int)yy));
}
}
} else {
return coerceBin(context, sites(context).op_exp, other);
}
@@ -704,18 +737,6 @@ public IRubyObject op_pow(ThreadContext context, IRubyObject other) {
return RubyNumeric.dbl2ival(runtime, pow);
}

public final IRubyObject op_pow(final ThreadContext context, final long other) {
if (other >= 0) {
if (other <= Integer.MAX_VALUE) { // only have BigInteger#pow(int)
return bignorm(context.runtime, value.pow((int) other)); // num2int is also implemented
}
warnIfPowExponentTooBig(context, other);
return RubyFloat.newFloat(context.runtime, Math.pow(big2dbl(this), (double) other));
}
// (other < 0)
return RubyRational.newRationalRaw(context.runtime, this).op_expt(context, other);
}

private void warnIfPowExponentTooBig(final ThreadContext context, final long other) {
// MRI issuses warning here on (RBIGNUM(x)->len * SIZEOF_BDIGITS * yy > 1024*1024)
if ( ((value.bitLength() + 7) / 8) * 4 * Math.abs((double) other) > 1024 * 1024 ) {
@@ -1087,6 +1108,25 @@ public IRubyObject isPositive(ThreadContext context) {
return sites(context).basic_op_gt.call(context, this, this, RubyFixnum.zero(runtime));
}

@Override
protected boolean int_round_zero_p(ThreadContext context, int ndigits) {
long bytes = value.bitLength() / 8 + 1;
return (-0.415241 * ndigits - 0.125 > bytes);
}

@Deprecated
public final IRubyObject op_pow(final ThreadContext context, final long other) {
if (other >= 0) {
if (other <= Integer.MAX_VALUE) { // only have BigInteger#pow(int)
return bignorm(context.runtime, value.pow((int) other)); // num2int is also implemented
}
warnIfPowExponentTooBig(context, other);
return RubyFloat.newFloat(context.runtime, Math.pow(big2dbl(this), (double) other));
}
// (other < 0)
return RubyRational.newRationalRaw(context.runtime, this).op_expt(context, other);
}

private static JavaSites.BignumSites sites(ThreadContext context) {
return context.sites.Bignum;
}
8 changes: 7 additions & 1 deletion core/src/main/java/org/jruby/RubyFixnum.java
Original file line number Diff line number Diff line change
@@ -642,7 +642,7 @@ public IRubyObject op_mul(ThreadContext context, long otherValue) {
* also note that RubyFloat doesn't override Numeric.div
*/
@Override
public IRubyObject op_idiv(ThreadContext context, IRubyObject other) {
public IRubyObject idiv(ThreadContext context, IRubyObject other) {
checkZeroDivisionError(context, other);

return idiv(context, other, sites(context).div);
@@ -1336,6 +1336,12 @@ public IRubyObject isPositive(ThreadContext context) {
return sites(context).basic_op_gt.call(context, this, this, RubyFixnum.zero(runtime));
}

@Override
protected boolean int_round_zero_p(ThreadContext context, int ndigits) {
long bytes = 8; // sizeof(long)
return (-0.415241 * ndigits - 0.125 > bytes);
}

private static JavaSites.FixnumSites sites(ThreadContext context) {
return context.sites.Fixnum;
}
41 changes: 21 additions & 20 deletions core/src/main/java/org/jruby/RubyFloat.java
Original file line number Diff line number Diff line change
@@ -748,32 +748,37 @@ public IRubyObject rationalize(ThreadContext context, IRubyObject[] args) {

final Ruby runtime = context.runtime;
RubyFixnum one = RubyFixnum.one(runtime);
RubyFixnum two = RubyFixnum.two(runtime);

IRubyObject eps, a, b;
if (args.length != 0) {
eps = f_abs(context, args[0]);
a = f_sub(context, this, eps);
b = f_add(context, this, eps);
} else {
IRubyObject flt;
IRubyObject p, q;
long[] exp = new long[1];

// float_decode_internal
double f = frexp(value, exp);
f = ldexp(f, DBL_MANT_DIG);
long n = exp[0] - DBL_MANT_DIG;

RubyInteger rf = RubyBignum.newBignorm(runtime, f);
RubyFixnum rn = RubyFixnum.newFixnum(runtime, n);

if (rf.zero_p(context).isTrue() || fix2int(rn) >= 0) {
return RubyRational.newRationalRaw(runtime, rf.op_lshift(context, rn));
}

IRubyObject rf = RubyNumeric.dbl2ival(runtime, f);
IRubyObject rn = RubyFixnum.newFixnum(runtime, n);
RubyInteger two_times_f, den;

if (f_zero_p(context, rf) || !(f_negative_p(context, rn) || f_zero_p(context, rn)))
return RubyRational.newRationalRaw(runtime, f_lshift(context,rf,rn));
RubyFixnum two = RubyFixnum.two(runtime);
two_times_f = (RubyInteger) two.op_mul(context, rf);
den = (RubyInteger) RubyFixnum.one(runtime).op_lshift(context, RubyFixnum.one(runtime).op_minus(context, n));

a = RubyRational.newRationalRaw(runtime,
f_sub(context,f_mul(context, two, rf),one),
f_lshift(context, one, f_sub(context,one,rn)));
b = RubyRational.newRationalRaw(runtime,
f_add(context,f_mul(context, two, rf),one),
f_lshift(context, one, f_sub(context,one,rn)));
a = RubyRational.newRationalRaw(runtime, two_times_f.op_minus(context, RubyFixnum.one(runtime)), den);
b = RubyRational.newRationalRaw(runtime, two_times_f.op_plus(context, RubyFixnum.one(runtime)), den);
}

if (sites(context).op_equal.call(context, a, a, b).isTrue()) return f_to_r(context, this);
@@ -949,17 +954,10 @@ private IRubyObject roundShared(ThreadContext context, RoundingMode roundingMode
return this;
}

if (Double.isInfinite(value)) {
if (Double.isNaN(value)) {
if (ndigits <= 0) throw context.runtime.newFloatDomainError("NaN");
return this;
}
double binexp;
// Missing binexp values for NaN and (-|+)Infinity. frexp man page just says unspecified.
if (value == 0) {
binexp = 0;
} else {
binexp = Math.ceil(Math.log(value)/Math.log(2));
}

if (ndigits < 0) {
return ((RubyInteger) truncate(context)).round(context, ndigits);
@@ -1026,7 +1024,10 @@ private static double roundHalfDown(double x, double s) {
}

private static double roundHalfUp(double xs) {
return Math.floor((Math.floor((xs + 0.5) * 2.0)) / 2.0);
if (xs < 0.0) {
return Math.round(xs * -1.0) * -1.0;
}
return Math.round(xs);
}

private static double roundHalfEven(double x, double s) {
Loading