Skip to content

Commit

Permalink
Showing 15 changed files with 365 additions and 253 deletions.
220 changes: 109 additions & 111 deletions core/src/main/java/org/jruby/RubyBignum.java

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions core/src/main/java/org/jruby/RubyComplex.java
Original file line number Diff line number Diff line change
@@ -288,8 +288,7 @@ public static void setCanonicalization(boolean canonical) {
*/
private static void realCheck(ThreadContext context, IRubyObject num) {
switch (num.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
case FLOAT:
case RATIONAL:
break;
112 changes: 51 additions & 61 deletions core/src/main/java/org/jruby/RubyFixnum.java
Original file line number Diff line number Diff line change
@@ -61,21 +61,13 @@
/**
* Implementation of the Fixnum class.
*/
@JRubyClass(name="Fixnum", parent="Integer", include="Precision")
public class RubyFixnum extends RubyInteger implements Constantizable {

public static RubyClass createFixnumClass(Ruby runtime) {
RubyClass fixnum = runtime.defineClass("Fixnum", runtime.getInteger(),
ObjectAllocator.NOT_ALLOCATABLE_ALLOCATOR);
RubyClass fixnum = runtime.getInteger();
runtime.getObject().setConstant("Fixnum", fixnum);
runtime.setFixnum(fixnum);

fixnum.setClassIndex(ClassIndex.FIXNUM);
fixnum.setReifiedClass(RubyFixnum.class);

fixnum.kindOf = new RubyModule.JavaClassKindOf(RubyFixnum.class);

fixnum.defineAnnotatedMethods(RubyFixnum.class);

for (int i = 0; i < runtime.fixnumCache.length; i++) {
runtime.fixnumCache[i] = new RubyFixnum(fixnum, i - CACHE_OFFSET);
}
@@ -280,7 +272,6 @@ public boolean equals(Object other) {
* ================
*/
@Override
@JRubyMethod
public IRubyObject times(ThreadContext context, Block block) {
if (block.isGiven()) {
final long value = this.value;
@@ -321,7 +312,6 @@ public RubyString to_s(IRubyObject[] args) {
}
}

@JRubyMethod
@Override
public RubyString to_s() {
ByteList bl = ConvertBytes.longToByteList(value, 10);
@@ -330,7 +320,7 @@ public RubyString to_s() {
return str;
}

@JRubyMethod
@Override
public RubyString to_s(IRubyObject arg0) {
int base = num2int(arg0);
if (base < 2 || base > 36) {
@@ -354,8 +344,8 @@ public IRubyObject to_sym() {
/** fix_uminus
*
*/
@JRubyMethod(name = "-@")
public IRubyObject op_uminus() {
@Override
public IRubyObject op_uminus(ThreadContext context) {
if (value == MIN) { // a gotcha
return RubyBignum.newBignum(getRuntime(), BigInteger.valueOf(value).negate());
}
@@ -365,7 +355,7 @@ public IRubyObject op_uminus() {
/** fix_plus
*
*/
@JRubyMethod(name = "+")
@Override
public IRubyObject op_plus(ThreadContext context, IRubyObject other) {
if (other instanceof RubyFixnum) {
return addFixnum(context, (RubyFixnum) other);
@@ -428,7 +418,7 @@ private IRubyObject addOther(ThreadContext context, IRubyObject other) {
/** fix_minus
*
*/
@JRubyMethod(name = "-")
@Override
public IRubyObject op_minus(ThreadContext context, IRubyObject other) {
if (other instanceof RubyFixnum) {
return subtractFixnum(context, (RubyFixnum) other);
@@ -490,7 +480,7 @@ private IRubyObject subtractOther(ThreadContext context, IRubyObject other) {
/** fix_mul
*
*/
@JRubyMethod(name = "*")
@Override
public IRubyObject op_mul(ThreadContext context, IRubyObject other) {
if (other instanceof RubyFixnum) {
return op_mul(context, ((RubyFixnum) other).value);
@@ -552,14 +542,14 @@ public IRubyObject op_mul(ThreadContext context, long otherValue) {
*
* also note that RubyFloat doesn't override Numeric.div
*/
@JRubyMethod(name = "div")
public IRubyObject div_div(ThreadContext context, IRubyObject other) {
@Override
public IRubyObject op_idiv(ThreadContext context, IRubyObject other) {
checkZeroDivisionError(context, other);

return idiv(context, other, sites(context).div);
}

@JRubyMethod(name = "/")
@Override
public IRubyObject op_div(ThreadContext context, IRubyObject other) {
return idiv(context, other, sites(context).op_quo);
}
@@ -568,15 +558,15 @@ public IRubyObject op_div(ThreadContext context, long other) {
return idiv(context, other, "/");
}

@JRubyMethod(name = {"odd?"})
@Override
public RubyBoolean odd_p(ThreadContext context) {
if(value%2 != 0) {
return context.runtime.getTrue();
}
return context.runtime.getFalse();
}

@JRubyMethod(name = {"even?"})
@Override
public RubyBoolean even_p(ThreadContext context) {
if(value%2 == 0) {
return context.runtime.getTrue();
@@ -636,7 +626,7 @@ private IRubyObject idivLong(ThreadContext context, long x, long y) {
/** fix_mod
*
*/
@JRubyMethod(name = {"%", "modulo"})
@Override
public IRubyObject op_mod(ThreadContext context, IRubyObject other) {
checkZeroDivisionError(context, other);
if (other instanceof RubyFixnum) {
@@ -670,7 +660,6 @@ private IRubyObject moduloFixnum(ThreadContext context, long other) {
/** fix_divmod
*
*/
@JRubyMethod(name = "divmod")
@Override
public IRubyObject divmod(ThreadContext context, IRubyObject other) {
checkZeroDivisionError(context, other);
@@ -730,7 +719,7 @@ public IRubyObject quo(ThreadContext context, IRubyObject other) {
/** fix_pow
*
*/
@JRubyMethod(name = "**")
@Override
public IRubyObject op_pow(ThreadContext context, IRubyObject other) {
return op_pow_19(context, other);
}
@@ -829,7 +818,6 @@ private IRubyObject powerFixnum19(ThreadContext context, IRubyObject other) {
/** fix_abs
*
*/
@JRubyMethod
@Override
public IRubyObject abs(ThreadContext context) {
if (value < 0) {
@@ -846,7 +834,6 @@ public IRubyObject abs(ThreadContext context) {
/** fix_abs/1.9
*
*/
@JRubyMethod(name = "magnitude")
@Override
public IRubyObject magnitude(ThreadContext context) {
return abs(context);
@@ -855,7 +842,6 @@ public IRubyObject magnitude(ThreadContext context) {
/** fix_equal
*
*/
@JRubyMethod(name = "==")
@Override
public IRubyObject op_equal(ThreadContext context, IRubyObject other) {
return other instanceof RubyFixnum ?
@@ -904,7 +890,7 @@ private int compareToOther(IRubyObject other) {
/** fix_cmp
*
*/
@JRubyMethod(name = "<=>")
@Override
public IRubyObject op_cmp(ThreadContext context, IRubyObject other) {
return other instanceof RubyFixnum ?
op_cmp(context, ((RubyFixnum) other).value) : compareOther(context, other);
@@ -929,7 +915,7 @@ private IRubyObject compareOther(ThreadContext context, IRubyObject other) {
/** fix_gt
*
*/
@JRubyMethod(name = ">")
@Override
public IRubyObject op_gt(ThreadContext context, IRubyObject other) {
if (other instanceof RubyFixnum) {
return RubyBoolean.newBoolean(context.runtime, value > ((RubyFixnum) other).value);
@@ -960,7 +946,7 @@ private IRubyObject op_gtOther(ThreadContext context, IRubyObject other) {
/** fix_ge
*
*/
@JRubyMethod(name = ">=")
@Override
public IRubyObject op_ge(ThreadContext context, IRubyObject other) {
if (other instanceof RubyFixnum) {
return RubyBoolean.newBoolean(context.runtime, value >= ((RubyFixnum) other).value);
@@ -990,7 +976,7 @@ private IRubyObject op_geOther(ThreadContext context, IRubyObject other) {
/** fix_lt
*
*/
@JRubyMethod(name = "<")
@Override
public IRubyObject op_lt(ThreadContext context, IRubyObject other) {
if (other instanceof RubyFixnum) {
return op_lt(context, ((RubyFixnum) other).value);
@@ -1020,7 +1006,7 @@ private IRubyObject op_ltOther(ThreadContext context, IRubyObject other) {
/** fix_le
*
*/
@JRubyMethod(name = "<=")
@Override
public IRubyObject op_le(ThreadContext context, IRubyObject other) {
if (other instanceof RubyFixnum) {
return RubyBoolean.newBoolean(context.runtime, value <= ((RubyFixnum) other).value);
@@ -1050,15 +1036,15 @@ private IRubyObject op_leOther(ThreadContext context, IRubyObject other) {
/** fix_rev
*
*/
@JRubyMethod(name = "~")
public IRubyObject op_neg() {
return newFixnum(~value);
@Override
public IRubyObject op_neg(ThreadContext context) {
return newFixnum(context.runtime, ~value);
}

/** fix_and
*
*/
@JRubyMethod(name = "&")
@Override
public IRubyObject op_and(ThreadContext context, IRubyObject other) {
if (!((other = bitCoerce(context, other)) instanceof RubyFixnum)) {
return ((RubyBignum) other).op_and(context, this);
@@ -1081,7 +1067,7 @@ public IRubyObject op_and(ThreadContext context, long other) {
/** fix_or
*
*/
@JRubyMethod(name = "|")
@Override
public IRubyObject op_or(ThreadContext context, IRubyObject other) {
if ((other = bitCoerce(context, other)) instanceof RubyFixnum) {
return newFixnum(context.runtime, value | ((RubyFixnum) other).value);
@@ -1097,7 +1083,7 @@ public IRubyObject op_or(ThreadContext context, long other) {
/** fix_xor
*
*/
@JRubyMethod(name = "^")
@Override
public IRubyObject op_xor(ThreadContext context, IRubyObject other) {
if (!((other = bitCoerce(context, other)) instanceof RubyFixnum)) {
return ((RubyBignum) other).op_xor(context, this);
@@ -1115,33 +1101,33 @@ public IRubyObject op_xor(ThreadContext context, long other) {
/** fix_aref
*
*/
@JRubyMethod(name = "[]")
public IRubyObject op_aref(IRubyObject other) {
@Override
public IRubyObject op_aref(ThreadContext context, IRubyObject other) {
if(!(other instanceof RubyFixnum) && !((other = fixCoerce(other)) instanceof RubyFixnum)) {
RubyBignum big = (RubyBignum) other;
other = RubyBignum.bignorm(getRuntime(), big.getValue());
other = RubyBignum.bignorm(context.runtime, big.getValue());
if (!(other instanceof RubyFixnum)) {
return big.getValue().signum() == 0 || value >= 0 ? RubyFixnum.zero(getRuntime()) : RubyFixnum.one(getRuntime());
return big.getValue().signum() == 0 || value >= 0 ? RubyFixnum.zero(context.runtime) : RubyFixnum.one(context.runtime);
}
}

long otherValue = fix2long(other);

if (otherValue < 0) return RubyFixnum.zero(getRuntime());
if (otherValue < 0) return RubyFixnum.zero(context.runtime);

if (BIT_SIZE - 1 < otherValue) {
return value < 0 ? RubyFixnum.one(getRuntime()) : RubyFixnum.zero(getRuntime());
return value < 0 ? RubyFixnum.one(context.runtime) : RubyFixnum.zero(context.runtime);
}

return (value & (1L << otherValue)) == 0 ? RubyFixnum.zero(getRuntime()) : RubyFixnum.one(getRuntime());
return (value & (1L << otherValue)) == 0 ? RubyFixnum.zero(context.runtime) : RubyFixnum.one(context.runtime);
}

/** fix_lshift
*
*/
@JRubyMethod(name = "<<")
public IRubyObject op_lshift(IRubyObject other) {
if (!(other instanceof RubyFixnum)) return RubyBignum.newBignum(getRuntime(), value).op_lshift(other);
@Override
public IRubyObject op_lshift(ThreadContext context, IRubyObject other) {
if (!(other instanceof RubyFixnum)) return RubyBignum.newBignum(context.runtime, value).op_lshift(other);

return op_lshift(((RubyFixnum)other).getLongValue());
}
@@ -1160,9 +1146,9 @@ private IRubyObject lshift(long width) {
/** fix_rshift
*
*/
@JRubyMethod(name = ">>")
public IRubyObject op_rshift(IRubyObject other) {
if (!(other instanceof RubyFixnum)) return RubyBignum.newBignum(getRuntime(), value).op_rshift(other);
@Override
public IRubyObject op_rshift(ThreadContext context, IRubyObject other) {
if (!(other instanceof RubyFixnum)) return RubyBignum.newBignum(context.runtime, value).op_rshift(other);

return op_rshift(((RubyFixnum)other).getLongValue());
}
@@ -1183,33 +1169,37 @@ private IRubyObject rshift(long width) {
/** fix_to_f
*
*/
@JRubyMethod
public IRubyObject to_f() {
@Override
public IRubyObject to_f(ThreadContext context) {
return RubyFloat.newFloat(getRuntime(), (double) value);
}

/** fix_size
*
*/
@JRubyMethod
public IRubyObject size() {
@Override
public IRubyObject size(ThreadContext context) {
return newFixnum((long) ((BIT_SIZE + 7) / 8));
}

public IRubyObject zero_p() {
return zero_p(getRuntime().getCurrentContext());
}

/** fix_zero_p
*
*/
@JRubyMethod(name = "zero?")
public IRubyObject zero_p() {
@Override
public IRubyObject zero_p(ThreadContext context) {
return RubyBoolean.newBoolean(getRuntime(), value == 0);
}

@JRubyMethod
@Override
public IRubyObject succ(ThreadContext context) {
return ((RubyFixnum) this).op_plus_one(context);
}

@JRubyMethod
@Override
public IRubyObject bit_length(ThreadContext context) {
long tmpValue = value;
if (value < 0) {
47 changes: 16 additions & 31 deletions core/src/main/java/org/jruby/RubyFloat.java
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@
/**
* A representation of a float object
*/
@JRubyClass(name="Float", parent="Numeric", include="Precision")
@JRubyClass(name="Float", parent="Numeric")
public class RubyFloat extends RubyNumeric {
public static final int ROUNDS = 1;
public static final int RADIX = 2;
@@ -270,8 +270,7 @@ public IRubyObject op_uminus() {
@JRubyMethod(name = "+", required = 1)
public IRubyObject op_plus(ThreadContext context, IRubyObject other) {
switch (other.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
case FLOAT:
return RubyFloat.newFloat(context.runtime, value + ((RubyNumeric) other).getDoubleValue());
default:
@@ -289,8 +288,7 @@ public IRubyObject op_plus(ThreadContext context, double other) {
@JRubyMethod(name = "-", required = 1)
public IRubyObject op_minus(ThreadContext context, IRubyObject other) {
switch (other.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
case FLOAT:
return RubyFloat.newFloat(context.runtime, value - ((RubyNumeric) other).getDoubleValue());
default:
@@ -308,8 +306,7 @@ public IRubyObject op_minus(ThreadContext context, double other) {
@JRubyMethod(name = "*", required = 1)
public IRubyObject op_mul(ThreadContext context, IRubyObject other) {
switch (other.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
case FLOAT:
return RubyFloat.newFloat(context.runtime, value * ((RubyNumeric) other).getDoubleValue());
default:
@@ -328,8 +325,7 @@ public IRubyObject op_mul(ThreadContext context, double other) {
@JRubyMethod(name = "/", required = 1)
public IRubyObject op_fdiv(ThreadContext context, IRubyObject other) { // don't override Numeric#div !
switch (other.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
case FLOAT:
return RubyFloat.newFloat(context.runtime, value / ((RubyNumeric) other).getDoubleValue());
default:
@@ -354,8 +350,7 @@ public IRubyObject magnitude(ThreadContext context, IRubyObject other) {
*/
public IRubyObject op_mod(ThreadContext context, IRubyObject other) {
switch (other.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
case FLOAT:
double y = ((RubyNumeric) other).getDoubleValue();
return op_mod(context, y);
@@ -394,8 +389,7 @@ public IRubyObject op_mod19(ThreadContext context, IRubyObject other) {
@Override
public IRubyObject divmod(ThreadContext context, IRubyObject other) {
switch (other.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
case FLOAT:
double y = ((RubyNumeric) other).getDoubleValue();
double x = value;
@@ -436,8 +430,7 @@ public IRubyObject divmod19(ThreadContext context, IRubyObject other) {
*/
public IRubyObject op_pow(ThreadContext context, IRubyObject other) {
switch (other.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
case FLOAT:
return RubyFloat.newFloat(context.runtime, Math.pow(value, ((RubyNumeric) other)
.getDoubleValue()));
@@ -453,8 +446,7 @@ public IRubyObject op_pow(ThreadContext context, double other) {
@JRubyMethod(name = "**", required = 1)
public IRubyObject op_pow19(ThreadContext context, IRubyObject other) {
switch (other.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
case FLOAT:
double d_other = ((RubyNumeric) other).getDoubleValue();
if (value < 0 && (d_other != Math.round(d_other))) {
@@ -478,8 +470,7 @@ public IRubyObject op_equal(ThreadContext context, IRubyObject other) {
return context.runtime.getFalse();
}
switch (other.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
case FLOAT:
return RubyBoolean.newBoolean(context.runtime, value == ((RubyNumeric) other).getDoubleValue());
default:
@@ -505,8 +496,7 @@ public boolean fastEqual(RubyFloat other) {
@Override
public final int compareTo(IRubyObject other) {
switch (other.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
case FLOAT:
return Double.compare(value, ((RubyNumeric) other).getDoubleValue());
default:
@@ -522,8 +512,7 @@ public final int compareTo(IRubyObject other) {
public IRubyObject op_cmp(ThreadContext context, IRubyObject other) {
final Ruby runtime = context.runtime;
switch (other.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
if (Double.isInfinite(value)) {
return value > 0.0 ? RubyFixnum.one(runtime) : RubyFixnum.minus_one(runtime);
}
@@ -559,8 +548,7 @@ public IRubyObject op_cmp(ThreadContext context, double other) {
@JRubyMethod(name = ">", required = 1)
public IRubyObject op_gt(ThreadContext context, IRubyObject other) {
switch (other.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
case FLOAT:
double b = ((RubyNumeric) other).getDoubleValue();
return RubyBoolean.newBoolean(context.runtime, !Double.isNaN(b) && value > b);
@@ -579,8 +567,7 @@ public IRubyObject op_gt(ThreadContext context, double other) {
@JRubyMethod(name = ">=", required = 1)
public IRubyObject op_ge(ThreadContext context, IRubyObject other) {
switch (other.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
case FLOAT:
double b = ((RubyNumeric) other).getDoubleValue();
return RubyBoolean.newBoolean(context.runtime, !Double.isNaN(b) && value >= b);
@@ -599,8 +586,7 @@ public IRubyObject op_ge(ThreadContext context, double other) {
@JRubyMethod(name = "<", required = 1)
public IRubyObject op_lt(ThreadContext context, IRubyObject other) {
switch (other.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
case FLOAT:
double b = ((RubyNumeric) other).getDoubleValue();
return RubyBoolean.newBoolean(context.runtime, !Double.isNaN(b) && value < b);
@@ -619,8 +605,7 @@ public IRubyObject op_lt(ThreadContext context, double other) {
@JRubyMethod(name = "<=", required = 1)
public IRubyObject op_le(ThreadContext context, IRubyObject other) {
switch (other.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
case FLOAT:
double b = ((RubyNumeric) other).getDoubleValue();
return RubyBoolean.newBoolean(context.runtime, !Double.isNaN(b) && value <= b);
131 changes: 130 additions & 1 deletion core/src/main/java/org/jruby/RubyInteger.java
Original file line number Diff line number Diff line change
@@ -63,7 +63,7 @@
*
* @author jpetersen
*/
@JRubyClass(name="Integer", parent="Numeric", include="Precision")
@JRubyClass(name="Integer", parent="Numeric")
public abstract class RubyInteger extends RubyNumeric {

public static RubyClass createIntegerClass(Ruby runtime) {
@@ -527,6 +527,135 @@ public IRubyObject denominator(ThreadContext context) {
return RubyFixnum.one(context.runtime);
}

@JRubyMethod(name = "to_s")
@Override
public abstract RubyString to_s();

@JRubyMethod(name = "to_s")
public abstract RubyString to_s(IRubyObject x);

@JRubyMethod(name = "-@")
public abstract IRubyObject op_uminus(ThreadContext context);

@JRubyMethod(name = "+")
public abstract IRubyObject op_plus(ThreadContext context, IRubyObject other);

@JRubyMethod(name = "-")
public abstract IRubyObject op_minus(ThreadContext context, IRubyObject other);

@JRubyMethod(name = "*")
public abstract IRubyObject op_mul(ThreadContext context, IRubyObject other);

@JRubyMethod(name = "div")
public abstract IRubyObject op_idiv(ThreadContext context, IRubyObject other);

public final IRubyObject div_div(ThreadContext context, IRubyObject other) {
return op_idiv(context, other);
}

@JRubyMethod(name = "/")
public abstract IRubyObject op_div(ThreadContext context, IRubyObject other);

@JRubyMethod(name = {"%", "modulo"})
public abstract IRubyObject op_mod(ThreadContext context, IRubyObject other);

@JRubyMethod(name = "**")
public abstract IRubyObject op_pow(ThreadContext context, IRubyObject other);

@JRubyMethod(name = "abs")
public abstract IRubyObject abs(ThreadContext context);

@JRubyMethod(name = "magnitude")
@Override
public IRubyObject magnitude(ThreadContext context) {
return abs(context);
}

@JRubyMethod(name = "==")
@Override
public abstract IRubyObject op_equal(ThreadContext context, IRubyObject other);

@JRubyMethod(name = "<=>")
@Override
public abstract IRubyObject op_cmp(ThreadContext context, IRubyObject other);

@JRubyMethod(name = "~")
public abstract IRubyObject op_neg(ThreadContext context);

@JRubyMethod(name = "&")
public abstract IRubyObject op_and(ThreadContext context, IRubyObject other);

@JRubyMethod(name = "|")
public abstract IRubyObject op_or(ThreadContext context, IRubyObject other);

@JRubyMethod(name = "^")
public abstract IRubyObject op_xor(ThreadContext context, IRubyObject other);

@JRubyMethod(name = "[]")
public abstract IRubyObject op_aref(ThreadContext context, IRubyObject other);

@JRubyMethod(name = "<<")
public abstract IRubyObject op_lshift(ThreadContext context, IRubyObject other);

@JRubyMethod(name = ">>")
public abstract IRubyObject op_rshift(ThreadContext context, IRubyObject other);

@JRubyMethod(name = "to_f")
public abstract IRubyObject to_f(ThreadContext context);

@JRubyMethod(name = "size")
public abstract IRubyObject size(ThreadContext context);

@JRubyMethod(name = "zero?")
public abstract IRubyObject zero_p(ThreadContext context);

@JRubyMethod(name = "bit_length")
public abstract IRubyObject bit_length(ThreadContext context);

public IRubyObject op_gt(ThreadContext context, IRubyObject other) {
return RubyComparable.op_gt(context, this, other);
}

public IRubyObject op_lt(ThreadContext context, IRubyObject other) {
return RubyComparable.op_lt(context, this, other);
}

public IRubyObject op_ge(ThreadContext context, IRubyObject other) {
return RubyComparable.op_ge(context, this, other);
}

public IRubyObject op_le(ThreadContext context, IRubyObject other) {
return RubyComparable.op_le(context, this, other);
}

public IRubyObject op_uminus() {
return op_uminus(getRuntime().getCurrentContext());
}

public IRubyObject op_neg() {
return to_f(getRuntime().getCurrentContext());
}

public IRubyObject op_aref(IRubyObject other) {
return op_aref(getRuntime().getCurrentContext(), other);
}

public IRubyObject op_lshift(IRubyObject other) {
return op_lshift(getRuntime().getCurrentContext(), other);
}

public IRubyObject op_rshift(IRubyObject other) {
return op_rshift(getRuntime().getCurrentContext(), other);
}

public IRubyObject to_f() {
return to_f(getRuntime().getCurrentContext());
}

public IRubyObject size() {
return size(getRuntime().getCurrentContext());
}

private static JavaSites.IntegerSites sites(ThreadContext context) {
return context.sites.Integer;
}
6 changes: 3 additions & 3 deletions core/src/main/java/org/jruby/RubyNumeric.java
Original file line number Diff line number Diff line change
@@ -771,15 +771,15 @@ public IRubyObject div19(ThreadContext context, IRubyObject other) {
/** num_divmod
*
*/
public IRubyObject divmod(ThreadContext context, IRubyObject other) {
return divmod19(context, other);
public IRubyObject divmod19(ThreadContext context, IRubyObject other) {
return divmod(context, other);
}

/** num_divmod
*
*/
@JRubyMethod(name = "divmod")
public IRubyObject divmod19(ThreadContext context, IRubyObject other) {
public IRubyObject divmod(ThreadContext context, IRubyObject other) {
return RubyArray.newArray(getRuntime(), div(context, other), modulo19(context, other));
}

6 changes: 2 additions & 4 deletions core/src/main/java/org/jruby/RubyProcess.java
Original file line number Diff line number Diff line change
@@ -646,8 +646,7 @@ private static int rlimitResourceValue(Ruby runtime, IRubyObject rval) {
}
/* fall through */

case FIXNUM:
case BIGNUM:
case INTEGER:
return rval.convertToInteger().getIntValue();
}

@@ -688,8 +687,7 @@ private static int rlimitResourceType(Ruby runtime, IRubyObject rtype) {
}
/* fall through */

case FIXNUM:
case BIGNUM:
case INTEGER:
return rtype.convertToInteger().getIntValue();
}

2 changes: 1 addition & 1 deletion core/src/main/java/org/jruby/RubyRational.java
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@
* 1.9 rational.c as of revision: 20011
*/

@JRubyClass(name = "Rational", parent = "Numeric", include = "Precision")
@JRubyClass(name = "Rational", parent = "Numeric")
public class RubyRational extends RubyNumeric {

public static RubyClass createRationalClass(Ruby runtime) {
6 changes: 2 additions & 4 deletions core/src/main/java/org/jruby/RubyTime.java
Original file line number Diff line number Diff line change
@@ -265,8 +265,7 @@ private static IRubyObject numExact(Ruby runtime, IRubyObject v) {
boolean typeError = false;

switch (v.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
return v;

case RATIONAL:
@@ -298,8 +297,7 @@ private static IRubyObject numExact(Ruby runtime, IRubyObject v) {
}

switch (v.getMetaClass().getClassIndex()) {
case FIXNUM:
case BIGNUM:
case INTEGER:
return v;

case RATIONAL:
Original file line number Diff line number Diff line change
@@ -69,7 +69,6 @@
/**
* @author <a href="mailto:ola.bini@ki.se">Ola Bini</a>
*/
@JRubyClass(name="BigDecimal", parent="Numeric")
public class RubyBigDecimal extends RubyNumeric {

private static final ObjectAllocator ALLOCATOR = new ObjectAllocator() {
@@ -1728,7 +1727,7 @@ public IRubyObject zero_p() {
* if the argument number is negative
* @throws IllegalArgumentException
* if rootMC has precision 0
* @see http://oldblog.novaloka.nl/blogger.xs4all.nl/novaloka/archive/2007/09/15/295396.html
* @link http://oldblog.novaloka.nl/blogger.xs4all.nl/novaloka/archive/2007/09/15/295396.html
*/
public static BigDecimal bigSqrt(BigDecimal squarD, MathContext rootMC) {
// General number and precision checking
11 changes: 6 additions & 5 deletions core/src/main/java/org/jruby/javasupport/JavaUtil.java
Original file line number Diff line number Diff line change
@@ -1463,11 +1463,12 @@ public static IRubyObject primitive_to_java(IRubyObject recv, IRubyObject object
case NIL:
javaObject = null;
break;
case FIXNUM:
javaObject = Long.valueOf(((RubyFixnum) object).getLongValue());
break;
case BIGNUM:
javaObject = ((RubyBignum) object).getValue();
case INTEGER:
if (object instanceof RubyFixnum) {
javaObject = Long.valueOf(((RubyFixnum) object).getLongValue());
} else {
javaObject = ((RubyBignum) object).getValue();
}
break;
case FLOAT:
javaObject = new Double(((RubyFloat) object).getValue());
27 changes: 14 additions & 13 deletions core/src/main/java/org/jruby/runtime/marshal/MarshalStream.java
Original file line number Diff line number Diff line change
@@ -240,20 +240,21 @@ private void writeObjectData(IRubyObject value) throws IOException {
case FALSE:
write('F');
return;
case FIXNUM: {
RubyFixnum fixnum = (RubyFixnum)value;

if (isMarshalFixnum(fixnum)) {
write('i');
writeInt((int) fixnum.getLongValue());
return;
case INTEGER:
if (value instanceof RubyFixnum) {
RubyFixnum fixnum = (RubyFixnum)value;

if (isMarshalFixnum(fixnum)) {
write('i');
writeInt((int) fixnum.getLongValue());
return;
}
// FIXME: inefficient; constructing a bignum just for dumping?
value = RubyBignum.newBignum(value.getRuntime(), fixnum.getLongValue());

// fall through
}
// FIXME: inefficient; constructing a bignum just for dumping?
value = RubyBignum.newBignum(value.getRuntime(), fixnum.getLongValue());

// fall through
}
case BIGNUM:

write('l');
RubyBignum.marshalTo((RubyBignum)value, this);
return;
4 changes: 2 additions & 2 deletions core/src/main/java/org/jruby/util/Sprintf.java
Original file line number Diff line number Diff line change
@@ -617,7 +617,7 @@ else if ((flags & FLAG_MINUS) != 0) {
}

ClassIndex type = arg.getMetaClass().getClassIndex();
if (type != ClassIndex.FIXNUM && type != ClassIndex.BIGNUM) {
if (type != ClassIndex.INTEGER) {
switch(type) {
case FLOAT:
arg = RubyNumeric.dbl2num(arg.getRuntime(),((RubyFloat)arg).getValue());
@@ -671,7 +671,7 @@ else if ((flags & FLAG_MINUS) != 0) {
// uses C-sprintf, in part, to format numeric output, while
// we'll use Java's numeric formatting code (and our own).
boolean zero;
if (type == ClassIndex.FIXNUM) {
if (type == ClassIndex.INTEGER) {
negative = ((RubyFixnum)arg).getLongValue() < 0;
zero = ((RubyFixnum)arg).getLongValue() == 0;
if (negative && fchar == 'u') {
38 changes: 26 additions & 12 deletions core/src/main/java/org/jruby/util/io/PopenExecutor.java
Original file line number Diff line number Diff line change
@@ -1474,7 +1474,10 @@ else if (id.equals("gid") && false) { // TODO
}
break;

case FIXNUM:
case INTEGER:
if (!(val instanceof RubyFixnum)) {
return ST_STOP;
}
case FILE:
case IO:
case ARRAY:
@@ -1523,9 +1526,14 @@ else if (id.equals("err")) {
case IO:
val = checkExecRedirectFd(runtime, val, false);
/* fall through */
case FIXNUM:
param = val;
eargp.fd_dup2 = checkExecRedirect1(runtime, eargp.fd_dup2, key, param);
case INTEGER:
if (val instanceof RubyFixnum) {
param = val;
eargp.fd_dup2 = checkExecRedirect1(runtime, eargp.fd_dup2, key, param);
break;
}

checkExecRedirectDefault(runtime, key, val, eargp);
break;

case ARRAY:
@@ -1574,18 +1582,24 @@ else if (flags instanceof RubyString)
break;

default:
tmp = val;
val = TypeConverter.ioCheckIO(runtime, tmp);
if (!val.isNil()) {
val = checkExecRedirectFd(runtime, val, false);
param = val;
eargp.fd_dup2 = checkExecRedirect1(runtime, eargp.fd_dup2, key, param);
}
throw runtime.newArgumentError("wrong exec redirect action");
checkExecRedirectDefault(runtime, key, val, eargp);
}

}

private static void checkExecRedirectDefault(Ruby runtime, IRubyObject key, IRubyObject val, ExecArg eargp) {
IRubyObject tmp;
IRubyObject param;
tmp = val;
val = TypeConverter.ioCheckIO(runtime, tmp);
if (!val.isNil()) {
val = checkExecRedirectFd(runtime, val, false);
param = val;
eargp.fd_dup2 = checkExecRedirect1(runtime, eargp.fd_dup2, key, param);
}
throw runtime.newArgumentError("wrong exec redirect action");
}

// MRI: check_exec_redirect_fd
static IRubyObject checkExecRedirectFd(Ruby runtime, IRubyObject v, boolean iskey) {
IRubyObject tmp;
2 changes: 1 addition & 1 deletion core/src/test/java/org/jruby/test/TestJavaUtil.java
Original file line number Diff line number Diff line change
@@ -50,7 +50,7 @@ public void setUp() {

public void testConvertJavaToRuby() {
assertEquals(JavaUtil.convertJavaToRuby(runtime, null).getType().name().toString(), "NilClass");
assertEquals(JavaUtil.convertJavaToRuby(runtime, new Integer(1000)).getType().name().toString(), "Fixnum");
assertEquals(JavaUtil.convertJavaToRuby(runtime, new Integer(1000)).getType().name().toString(), "Integer");
assertEquals(JavaUtil.convertJavaToRuby(runtime, new Double(1.0)).getType().name().toString(), "Float");
assertEquals(JavaUtil.convertJavaToRuby(runtime, Boolean.TRUE).getType().name().toString(), "TrueClass");
assertEquals(JavaUtil.convertJavaToRuby(runtime, Boolean.FALSE).getType().name().toString(), "FalseClass");

0 comments on commit 2d6d9f9

Please sign in to comment.