summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-17 06:53:48 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-05-17 06:53:48 +0000
commitf9727c12cc8fbc5f752f5983be1f14bb976e5a13 (patch)
treebdf433b181c6d6e00bd33581136ab2970bc9509d
parent565241f11f5d217631ed1e8bbafec7a088bed654 (diff)
[Feature #12005] Unify Fixnum and Bignum into Integer
* [Feature #12005] Unify Fixnum and Bignum into Integer * include/ruby/ruby.h (rb_class_of): Return rb_cInteger for fixnums. * insns.def (INTEGER_REDEFINED_OP_FLAG): Unified from FIXNUM_REDEFINED_OP_FLAG and BIGNUM_REDEFINED_OP_FLAG. * vm_core.h: Ditto. * vm_insnhelper.c (opt_eq_func): Use INTEGER_REDEFINED_OP_FLAG instead of FIXNUM_REDEFINED_OP_FLAG. * vm.c (vm_redefinition_check_flag): Use rb_cInteger instead of rb_cFixnum and rb_cBignum. (C): Use Integer instead of Fixnum and Bignum. * numeric.c (fix_succ): Removed. (Init_Numeric): Define Fixnum as Integer. * bignum.c (bignew): Use rb_cInteger instead of Rb_cBignum. (rb_int_coerce): replaced from rb_big_coerce and return fixnums as-is. (Init_Bignum): Define Bignum as Integer. Don't define ===. * error.c (builtin_class_name): Return "Integer" for fixnums. * sprintf.c (ruby__sfvextra): Use rb_cInteger instead of rb_cFixnum. * ext/-test-/testutil: New directory to test. Currently it provides utilities for fixnum and bignum. * ext/json/generator/generator.c: Define mInteger_to_json. * lib/mathn.rb (Fixnum#/): Redefinition removed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55024 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog38
-rw-r--r--bignum.c24
-rw-r--r--bootstraptest/test_literal.rb14
-rw-r--r--error.c2
-rw-r--r--ext/json/generator/generator.c38
-rw-r--r--ext/json/generator/generator.h1
-rw-r--r--include/ruby/ruby.h2
-rw-r--r--insns.def23
-rw-r--r--lib/mathn.rb17
-rw-r--r--numeric.c26
-rw-r--r--sprintf.c4
-rw-r--r--test/-ext-/num2int/test_num2int.rb4
-rw-r--r--test/-ext-/typeddata/test_typeddata.rb2
-rw-r--r--test/lib/test/unit.rb1
-rw-r--r--test/lib/test/unit/assertions.rb6
-rw-r--r--test/ruby/test_bignum.rb24
-rw-r--r--test/ruby/test_hash.rb2
-rw-r--r--test/ruby/test_integer.rb14
-rw-r--r--test/ruby/test_numeric.rb2
-rw-r--r--test/ruby/test_optimization.rb10
-rw-r--r--test/ruby/test_regexp.rb2
-rw-r--r--test/ruby/test_settracefunc.rb16
-rw-r--r--vm.c27
-rw-r--r--vm_core.h4
-rw-r--r--vm_insnhelper.c2
25 files changed, 159 insertions, 146 deletions
diff --git a/ChangeLog b/ChangeLog
index b9d78c8cd77..2f58238340c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,41 @@
+Tue May 17 15:26:10 2016 Tanaka Akira <akr@fsij.org>
+
+ * [Feature #12005] Unify Fixnum and Bignum into Integer
+
+ * include/ruby/ruby.h (rb_class_of): Return rb_cInteger for fixnums.
+
+ * insns.def (INTEGER_REDEFINED_OP_FLAG): Unified from
+ FIXNUM_REDEFINED_OP_FLAG and BIGNUM_REDEFINED_OP_FLAG.
+
+ * vm_core.h: Ditto.
+
+ * vm_insnhelper.c (opt_eq_func): Use INTEGER_REDEFINED_OP_FLAG instead
+ of FIXNUM_REDEFINED_OP_FLAG.
+
+ * vm.c (vm_redefinition_check_flag): Use rb_cInteger instead of
+ rb_cFixnum and rb_cBignum.
+ (C): Use Integer instead of Fixnum and Bignum.
+
+ * numeric.c (fix_succ): Removed.
+ (Init_Numeric): Define Fixnum as Integer.
+
+ * bignum.c (bignew): Use rb_cInteger instead of Rb_cBignum.
+ (rb_int_coerce): replaced from rb_big_coerce and return fixnums
+ as-is.
+ (Init_Bignum): Define Bignum as Integer.
+ Don't define ===.
+
+ * error.c (builtin_class_name): Return "Integer" for fixnums.
+
+ * sprintf.c (ruby__sfvextra): Use rb_cInteger instead of rb_cFixnum.
+
+ * ext/-test-/testutil: New directory to test.
+ Currently it provides utilities for fixnum and bignum.
+
+ * ext/json/generator/generator.c: Define mInteger_to_json.
+
+ * lib/mathn.rb (Fixnum#/): Redefinition removed.
+
Tue May 17 11:58:58 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* configure.in (RUBY_CHECK_BUILTIN_SETJMP): declare t as NORETURN
diff --git a/bignum.c b/bignum.c
index bb518d1a443..d1e10b95c3c 100644
--- a/bignum.c
+++ b/bignum.c
@@ -110,7 +110,7 @@ STATIC_ASSERT(sizeof_long_and_sizeof_bdigit, SIZEOF_BDIGIT % SIZEOF_LONG == 0);
#define BIGNUM_SET_NEGATIVE_SIGN(b) BIGNUM_SET_SIGN(b, 0)
#define BIGNUM_SET_POSITIVE_SIGN(b) BIGNUM_SET_SIGN(b, 1)
-#define bignew(len,sign) bignew_1(rb_cBignum,(len),(sign))
+#define bignew(len,sign) bignew_1(rb_cInteger,(len),(sign))
#define BDIGITS_ZERO(ptr, n) do { \
BDIGIT *bdigitz_zero_ptr = (ptr); \
@@ -6669,16 +6669,16 @@ rb_big_hash(VALUE x)
*/
static VALUE
-rb_big_coerce(VALUE x, VALUE y)
+rb_int_coerce(VALUE x, VALUE y)
{
- if (FIXNUM_P(y)) {
- y = rb_int2big(FIX2LONG(y));
+ if (FIXNUM_P(y) || RB_BIGNUM_TYPE_P(y)) {
+ return rb_assoc_new(y, x);
}
- else if (!RB_BIGNUM_TYPE_P(y)) {
- rb_raise(rb_eTypeError, "can't coerce %"PRIsVALUE" to Bignum",
- rb_obj_class(y));
+ else {
+ x = rb_Float(x);
+ y = rb_Float(y);
+ return rb_assoc_new(y, x);
}
- return rb_assoc_new(y, x);
}
VALUE
@@ -6783,15 +6783,13 @@ rb_big_even_p(VALUE num)
void
Init_Bignum(void)
{
- rb_cBignum = rb_define_class("Bignum", rb_cInteger);
-
- rb_define_method(rb_cBignum, "coerce", rb_big_coerce, 1);
+ rb_cBignum = rb_cInteger;
+ rb_define_const(rb_cObject, "Bignum", rb_cInteger);
- rb_define_method(rb_cBignum, "===", rb_big_eq, 1);
+ rb_define_method(rb_cInteger, "coerce", rb_int_coerce, 1);
#ifdef USE_GMP
/* The version of loaded GMP. */
- rb_define_const(rb_cBignum, "GMP_VERSION", rb_sprintf("GMP %s", gmp_version));
rb_define_const(rb_cInteger, "GMP_VERSION", rb_sprintf("GMP %s", gmp_version));
#endif
diff --git a/bootstraptest/test_literal.rb b/bootstraptest/test_literal.rb
index aa65bddae12..73b0a829841 100644
--- a/bootstraptest/test_literal.rb
+++ b/bootstraptest/test_literal.rb
@@ -15,17 +15,17 @@ assert_equal 'sym', ':sym'
assert_equal ':sym', ':sym.inspect'
assert_equal 'Symbol', ':sym.class'
assert_equal '1234', '1234'
-assert_equal 'Fixnum', '1234.class'
+assert_equal 'Integer', '1234.class'
assert_equal '1234', '1_2_3_4'
-assert_equal 'Fixnum', '1_2_3_4.class'
+assert_equal 'Integer', '1_2_3_4.class'
assert_equal '18', '0x12'
-assert_equal 'Fixnum', '0x12.class'
+assert_equal 'Integer', '0x12.class'
assert_equal '15', '0o17'
-assert_equal 'Fixnum', '0o17.class'
+assert_equal 'Integer', '0o17.class'
assert_equal '5', '0b101'
-assert_equal 'Fixnum', '0b101.class'
+assert_equal 'Integer', '0b101.class'
assert_equal '123456789012345678901234567890', '123456789012345678901234567890'
-assert_equal 'Bignum', '123456789012345678901234567890.class'
+assert_equal 'Integer', '123456789012345678901234567890.class'
assert_equal '2.0', '2.0'
assert_equal 'Float', '1.3.class'
@@ -169,7 +169,7 @@ assert_equal 'a', 'r = ("a".."c"); r.begin'
assert_equal 'c', 'r = ("a".."c"); r.end'
assert_equal 'String', '__FILE__.class'
-assert_equal 'Fixnum', '__LINE__.class'
+assert_equal 'Integer', '__LINE__.class'
###
diff --git a/error.c b/error.c
index 5a0184fa489..b795dc185c4 100644
--- a/error.c
+++ b/error.c
@@ -525,7 +525,7 @@ builtin_class_name(VALUE x)
etype = "nil";
}
else if (FIXNUM_P(x)) {
- etype = "Fixnum";
+ etype = "Integer";
}
else if (SYMBOL_P(x)) {
etype = "Symbol";
diff --git a/ext/json/generator/generator.c b/ext/json/generator/generator.c
index a135e283482..99130ea4b2c 100644
--- a/ext/json/generator/generator.c
+++ b/ext/json/generator/generator.c
@@ -7,7 +7,7 @@ static ID i_encoding, i_encode;
#endif
static VALUE mJSON, mExt, mGenerator, cState, mGeneratorMethods, mObject,
- mHash, mArray, mFixnum, mBignum, mFloat, mString, mString_Extend,
+ mHash, mArray, mInteger, mFixnum, mBignum, mFloat, mString, mString_Extend,
mTrueClass, mFalseClass, mNilClass, eGeneratorError,
eNestingError, CRegexp_MULTILINE, CJSON_SAFE_STATE_PROTOTYPE,
i_SAFE_STATE_PROTOTYPE;
@@ -347,6 +347,16 @@ static VALUE mArray_to_json(int argc, VALUE *argv, VALUE self) {
*
* Returns a JSON string representation for this Integer number.
*/
+static VALUE mInteger_to_json(int argc, VALUE *argv, VALUE self)
+{
+ GENERATE_JSON(integer);
+}
+
+/*
+ * call-seq: to_json(*)
+ *
+ * Returns a JSON string representation for this Integer number.
+ */
static VALUE mFixnum_to_json(int argc, VALUE *argv, VALUE self)
{
GENERATE_JSON(fixnum);
@@ -825,6 +835,14 @@ static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
fbuffer_append_str(buffer, tmp);
}
+static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
+{
+ if (FIXNUM_P(obj))
+ generate_json_fixnum(buffer, Vstate, state, obj);
+ else
+ generate_json_bignum(buffer, Vstate, state, obj);
+}
+
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj)
{
double value = RFLOAT_VALUE(obj);
@@ -858,9 +876,9 @@ static void generate_json(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *s
generate_json_false(buffer, Vstate, state, obj);
} else if (obj == Qtrue) {
generate_json_true(buffer, Vstate, state, obj);
- } else if (klass == rb_cFixnum) {
+ } else if (FIXNUM_P(obj)) {
generate_json_fixnum(buffer, Vstate, state, obj);
- } else if (klass == rb_cBignum) {
+ } else if (RB_TYPE_P(obj, T_BIGNUM)) {
generate_json_bignum(buffer, Vstate, state, obj);
} else if (klass == rb_cFloat) {
generate_json_float(buffer, Vstate, state, obj);
@@ -1402,10 +1420,16 @@ void Init_generator(void)
rb_define_method(mHash, "to_json", mHash_to_json, -1);
mArray = rb_define_module_under(mGeneratorMethods, "Array");
rb_define_method(mArray, "to_json", mArray_to_json, -1);
- mFixnum = rb_define_module_under(mGeneratorMethods, "Fixnum");
- rb_define_method(mFixnum, "to_json", mFixnum_to_json, -1);
- mBignum = rb_define_module_under(mGeneratorMethods, "Bignum");
- rb_define_method(mBignum, "to_json", mBignum_to_json, -1);
+ if (rb_cInteger == rb_cFixnum) {
+ mInteger = rb_define_module_under(mGeneratorMethods, "Integer");
+ rb_define_method(mInteger, "to_json", mInteger_to_json, -1);
+ }
+ else {
+ mFixnum = rb_define_module_under(mGeneratorMethods, "Fixnum");
+ rb_define_method(mFixnum, "to_json", mFixnum_to_json, -1);
+ mBignum = rb_define_module_under(mGeneratorMethods, "Bignum");
+ rb_define_method(mBignum, "to_json", mBignum_to_json, -1);
+ }
mFloat = rb_define_module_under(mGeneratorMethods, "Float");
rb_define_method(mFloat, "to_json", mFloat_to_json, -1);
mString = rb_define_module_under(mGeneratorMethods, "String");
diff --git a/ext/json/generator/generator.h b/ext/json/generator/generator.h
index 298c0a4965a..ffd55e416bb 100644
--- a/ext/json/generator/generator.h
+++ b/ext/json/generator/generator.h
@@ -122,6 +122,7 @@ static void generate_json_string(FBuffer *buffer, VALUE Vstate, JSON_Generator_S
static void generate_json_null(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
static void generate_json_false(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
static void generate_json_true(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
+static void generate_json_integer(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
static void generate_json_fixnum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
static void generate_json_bignum(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
static void generate_json_float(FBuffer *buffer, VALUE Vstate, JSON_Generator_State *state, VALUE obj);
diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h
index a05522d309a..6f7ce0f217c 100644
--- a/include/ruby/ruby.h
+++ b/include/ruby/ruby.h
@@ -1936,7 +1936,7 @@ static inline VALUE
rb_class_of(VALUE obj)
{
if (RB_IMMEDIATE_P(obj)) {
- if (RB_FIXNUM_P(obj)) return rb_cFixnum;
+ if (RB_FIXNUM_P(obj)) return rb_cInteger;
if (RB_FLONUM_P(obj)) return rb_cFloat;
if (obj == RUBY_Qtrue) return rb_cTrueClass;
if (RB_STATIC_SYM_P(obj)) return rb_cSymbol;
diff --git a/insns.def b/insns.def
index ae7f98fa03a..cdc82872abd 100644
--- a/insns.def
+++ b/insns.def
@@ -1344,9 +1344,8 @@ opt_case_dispatch
case T_STRING:
if (BASIC_OP_UNREDEFINED_P(BOP_EQQ,
SYMBOL_REDEFINED_OP_FLAG |
- FIXNUM_REDEFINED_OP_FLAG |
+ INTEGER_REDEFINED_OP_FLAG |
FLOAT_REDEFINED_OP_FLAG |
- BIGNUM_REDEFINED_OP_FLAG |
NIL_REDEFINED_OP_FLAG |
TRUE_REDEFINED_OP_FLAG |
FALSE_REDEFINED_OP_FLAG |
@@ -1379,7 +1378,7 @@ opt_plus
(VALUE val)
{
if (FIXNUM_2_P(recv, obj) &&
- BASIC_OP_UNREDEFINED_P(BOP_PLUS,FIXNUM_REDEFINED_OP_FLAG)) {
+ BASIC_OP_UNREDEFINED_P(BOP_PLUS,INTEGER_REDEFINED_OP_FLAG)) {
/* fixnum + fixnum */
#ifndef LONG_LONG_VALUE
val = (recv + (obj & (~1)));
@@ -1437,7 +1436,7 @@ opt_minus
(VALUE val)
{
if (FIXNUM_2_P(recv, obj) &&
- BASIC_OP_UNREDEFINED_P(BOP_MINUS, FIXNUM_REDEFINED_OP_FLAG)) {
+ BASIC_OP_UNREDEFINED_P(BOP_MINUS, INTEGER_REDEFINED_OP_FLAG)) {
long a, b, c;
a = FIX2LONG(recv);
@@ -1479,7 +1478,7 @@ opt_mult
(VALUE val)
{
if (FIXNUM_2_P(recv, obj) &&
- BASIC_OP_UNREDEFINED_P(BOP_MULT, FIXNUM_REDEFINED_OP_FLAG)) {
+ BASIC_OP_UNREDEFINED_P(BOP_MULT, INTEGER_REDEFINED_OP_FLAG)) {
val = rb_fix_mul_fix(recv, obj);
}
else if (FLONUM_2_P(recv, obj) &&
@@ -1515,7 +1514,7 @@ opt_div
(VALUE val)
{
if (FIXNUM_2_P(recv, obj) &&
- BASIC_OP_UNREDEFINED_P(BOP_DIV, FIXNUM_REDEFINED_OP_FLAG)) {
+ BASIC_OP_UNREDEFINED_P(BOP_DIV, INTEGER_REDEFINED_OP_FLAG)) {
if (FIX2LONG(obj) == 0) goto INSN_LABEL(normal_dispatch);
val = rb_fix_div_fix(recv, obj);
}
@@ -1552,7 +1551,7 @@ opt_mod
(VALUE val)
{
if (FIXNUM_2_P(recv, obj) &&
- BASIC_OP_UNREDEFINED_P(BOP_MOD, FIXNUM_REDEFINED_OP_FLAG )) {
+ BASIC_OP_UNREDEFINED_P(BOP_MOD, INTEGER_REDEFINED_OP_FLAG )) {
if (FIX2LONG(obj) == 0) goto INSN_LABEL(normal_dispatch);
val = rb_fix_mod_fix(recv, obj);
}
@@ -1642,7 +1641,7 @@ opt_lt
(VALUE val)
{
if (FIXNUM_2_P(recv, obj) &&
- BASIC_OP_UNREDEFINED_P(BOP_LT, FIXNUM_REDEFINED_OP_FLAG)) {
+ BASIC_OP_UNREDEFINED_P(BOP_LT, INTEGER_REDEFINED_OP_FLAG)) {
SIGNED_VALUE a = recv, b = obj;
if (a < b) {
@@ -1686,7 +1685,7 @@ opt_le
(VALUE val)
{
if (FIXNUM_2_P(recv, obj) &&
- BASIC_OP_UNREDEFINED_P(BOP_LE, FIXNUM_REDEFINED_OP_FLAG)) {
+ BASIC_OP_UNREDEFINED_P(BOP_LE, INTEGER_REDEFINED_OP_FLAG)) {
SIGNED_VALUE a = recv, b = obj;
if (a <= b) {
@@ -1721,7 +1720,7 @@ opt_gt
(VALUE val)
{
if (FIXNUM_2_P(recv, obj) &&
- BASIC_OP_UNREDEFINED_P(BOP_GT, FIXNUM_REDEFINED_OP_FLAG)) {
+ BASIC_OP_UNREDEFINED_P(BOP_GT, INTEGER_REDEFINED_OP_FLAG)) {
SIGNED_VALUE a = recv, b = obj;
if (a > b) {
@@ -1765,7 +1764,7 @@ opt_ge
(VALUE val)
{
if (FIXNUM_2_P(recv, obj) &&
- BASIC_OP_UNREDEFINED_P(BOP_GE, FIXNUM_REDEFINED_OP_FLAG)) {
+ BASIC_OP_UNREDEFINED_P(BOP_GE, INTEGER_REDEFINED_OP_FLAG)) {
SIGNED_VALUE a = recv, b = obj;
if (a >= b) {
@@ -2046,7 +2045,7 @@ opt_succ
{
if (SPECIAL_CONST_P(recv)) {
if (FIXNUM_P(recv) &&
- BASIC_OP_UNREDEFINED_P(BOP_SUCC, FIXNUM_REDEFINED_OP_FLAG)) {
+ BASIC_OP_UNREDEFINED_P(BOP_SUCC, INTEGER_REDEFINED_OP_FLAG)) {
const VALUE obj = INT2FIX(1);
/* fixnum + INT2FIX(1) */
val = (recv + (obj & (~1)));
diff --git a/lib/mathn.rb b/lib/mathn.rb
index 9e33f455807..d6f2da02100 100644
--- a/lib/mathn.rb
+++ b/lib/mathn.rb
@@ -55,27 +55,12 @@ unless defined?(Math.exp!)
end
##
-# When mathn is required, Fixnum's division is enhanced to
+# When mathn is required, Integer's division is enhanced to
# return more precise values from mathematical expressions.
#
# 2/3*3 # => 0
# require 'mathn'
# 2/3*3 # => 2
-
-class Fixnum
- remove_method :/
-
- ##
- # +/+ defines the Rational division for Fixnum.
- #
- # 1/3 # => (1/3)
-
- alias / quo
-end
-
-##
-# When mathn is required Bignum's division is enhanced to
-# return more precise values from mathematical expressions.
#
# (2**72) / ((2**70) * 3) # => 4/3
diff --git a/numeric.c b/numeric.c
index e2a14b2d063..eee539e8e1d 100644
--- a/numeric.c
+++ b/numeric.c
@@ -2948,13 +2948,6 @@ int_even_p(VALUE num)
* (-1).succ #=> 0
*/
-static VALUE
-fix_succ(VALUE num)
-{
- long i = FIX2LONG(num) + 1;
- return LONG2NUM(i);
-}
-
VALUE
rb_int_succ(VALUE num)
{
@@ -4954,6 +4947,7 @@ Init_Numeric(void)
rb_define_method(rb_cInteger, "abs", int_abs, 0);
rb_define_method(rb_cInteger, "magnitude", int_abs, 0);
+ rb_define_method(rb_cInteger, "===", int_equal, 1);
rb_define_method(rb_cInteger, "==", int_equal, 1);
rb_define_method(rb_cInteger, ">", int_gt, 1);
rb_define_method(rb_cInteger, ">=", int_ge, 1);
@@ -4972,22 +4966,8 @@ Init_Numeric(void)
rb_define_method(rb_cInteger, "size", int_size, 0);
rb_define_method(rb_cInteger, "bit_length", rb_int_bit_length, 0);
- rb_cFixnum = rb_define_class("Fixnum", rb_cInteger);
-
- rb_define_method(rb_cFixnum, "+", fix_plus, 1);
- rb_define_method(rb_cFixnum, "-", fix_minus, 1);
- rb_define_method(rb_cFixnum, "*", fix_mul, 1);
- rb_define_method(rb_cFixnum, "/", fix_div, 1);
- rb_define_method(rb_cFixnum, "%", fix_mod, 1);
-
- rb_define_method(rb_cFixnum, "==", fix_equal, 1);
- rb_define_method(rb_cFixnum, "===", fix_equal, 1);
- rb_define_method(rb_cFixnum, ">", fix_gt, 1);
- rb_define_method(rb_cFixnum, ">=", fix_ge, 1);
- rb_define_method(rb_cFixnum, "<", fix_lt, 1);
- rb_define_method(rb_cFixnum, "<=", fix_le, 1);
-
- rb_define_method(rb_cFixnum, "succ", fix_succ, 0);
+ rb_cFixnum = rb_cInteger;
+ rb_define_const(rb_cObject, "Fixnum", rb_cInteger);
rb_cFloat = rb_define_class("Float", rb_cNumeric);
diff --git a/sprintf.c b/sprintf.c
index 4d68c5731e1..d8069b69df7 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -1349,8 +1349,8 @@ ruby__sfvextra(rb_printf_buffer *fp, size_t valsize, void *valp, long *sz, int s
if (value == rb_cNilClass) {
return LITERAL("nil");
}
- else if (value == rb_cFixnum) {
- return LITERAL("Fixnum");
+ else if (value == rb_cInteger) {
+ return LITERAL("Integer");
}
else if (value == rb_cSymbol) {
return LITERAL("Symbol");
diff --git a/test/-ext-/num2int/test_num2int.rb b/test/-ext-/num2int/test_num2int.rb
index 5f1f807565a..da3bf97ecd9 100644
--- a/test/-ext-/num2int/test_num2int.rb
+++ b/test/-ext-/num2int/test_num2int.rb
@@ -104,7 +104,7 @@ class TestNum2int < Test::Unit::TestCase
end
def assert_fix2i_success(type, num, result=num)
- return if !num.kind_of?(Fixnum)
+ return if !num.fixnum?
func = "FIX2#{type}".upcase
assert_fix2i_success_internal(result.to_s, func, num)
end
@@ -116,7 +116,7 @@ class TestNum2int < Test::Unit::TestCase
end
def assert_fix2i_error(type, num)
- return if !num.kind_of?(Fixnum)
+ return if !num.fixnum?
func = "FIX2#{type}".upcase
assert_num2i_error_internal(func, num)
end
diff --git a/test/-ext-/typeddata/test_typeddata.rb b/test/-ext-/typeddata/test_typeddata.rb
index 6f649ca08ff..daeda7611a4 100644
--- a/test/-ext-/typeddata/test_typeddata.rb
+++ b/test/-ext-/typeddata/test_typeddata.rb
@@ -10,7 +10,7 @@ class Test_TypedData < Test::Unit::TestCase
assert_raise_with_message(TypeError, "wrong argument type Symbol (expected typed_data)") {Bug::TypedData.check(:e)}
- assert_raise_with_message(TypeError, "wrong argument type Fixnum (expected typed_data)") {Bug::TypedData.check(0)}
+ assert_raise_with_message(TypeError, "wrong argument type Integer (expected typed_data)") {Bug::TypedData.check(0)}
assert_raise_with_message(TypeError, "wrong argument type String (expected typed_data)") {Bug::TypedData.check("a")}
diff --git a/test/lib/test/unit.rb b/test/lib/test/unit.rb
index d34e11afa74..df7070e3fcd 100644
--- a/test/lib/test/unit.rb
+++ b/test/lib/test/unit.rb
@@ -8,6 +8,7 @@ require 'test/unit/assertions'
require_relative '../envutil'
require 'test/unit/testcase'
require 'optparse'
+require '-test-/testutil'
# See Test::Unit
module Test
diff --git a/test/lib/test/unit/assertions.rb b/test/lib/test/unit/assertions.rb
index 1df3453bc69..4e30de1be0a 100644
--- a/test/lib/test/unit/assertions.rb
+++ b/test/lib/test/unit/assertions.rb
@@ -772,11 +772,13 @@ eom
end
def assert_fixnum(v, msg=nil)
- assert_instance_of(Fixnum, v, msg)
+ assert_instance_of(Integer, v, msg)
+ assert_predicate(v, :fixnum?, msg)
end
def assert_bignum(v, msg=nil)
- assert_instance_of(Bignum, v, msg)
+ assert_instance_of(Integer, v, msg)
+ assert_predicate(v, :bignum?, msg)
end
class << (AssertFile = Struct.new(:failure_message).new)
diff --git a/test/ruby/test_bignum.rb b/test/ruby/test_bignum.rb
index 762368fda45..39f47ac6bb5 100644
--- a/test/ruby/test_bignum.rb
+++ b/test/ruby/test_bignum.rb
@@ -16,17 +16,17 @@ class TestBignum < Test::Unit::TestCase
end
BIGNUM_MIN_BITS = n
- T_ZERO = b.coerce(0).first
- T_ONE = b.coerce(1).first
- T_MONE = b.coerce(-1).first
- T31 = b.coerce(2**31).first # 2147483648
- T31P = b.coerce(T31 - 1).first # 2147483647
- T32 = b.coerce(2**32).first # 4294967296
- T32P = b.coerce(T32 - 1).first # 4294967295
- T64 = b.coerce(2**64).first # 18446744073709551616
- T64P = b.coerce(T64 - 1).first # 18446744073709551615
- T1024 = b.coerce(2**1024).first
- T1024P = b.coerce(T1024 - 1).first
+ T_ZERO = 0.to_bignum
+ T_ONE = 1.to_bignum
+ T_MONE = (-1).to_bignum
+ T31 = (2**31).to_bignum # 2147483648
+ T31P = (T31 - 1).to_bignum # 2147483647
+ T32 = (2**32).to_bignum # 4294967296
+ T32P = (T32 - 1).to_bignum # 4294967295
+ T64 = (2**64).to_bignum # 18446744073709551616
+ T64P = (T64 - 1).to_bignum # 18446744073709551615
+ T1024 = (2**1024).to_bignum
+ T1024P = (T1024 - 1).to_bignum
def setup
@verbose = $VERBOSE
@@ -656,7 +656,7 @@ class TestBignum < Test::Unit::TestCase
end
def test_too_big_to_s
- if (big = 2**31-1).is_a?(Fixnum)
+ if (big = 2**31-1).fixnum?
return
end
assert_raise_with_message(RangeError, /too big to convert/) {(1 << big).to_s}
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index 99231c73b24..6a8e7f0423d 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -826,7 +826,7 @@ class TestHash < Test::Unit::TestCase
def test_create
assert_equal({1=>2, 3=>4}, @cls[[[1,2],[3,4]]])
assert_raise(ArgumentError) { Hash[0, 1, 2] }
- assert_warning(/wrong element type Fixnum at 1 /) {@cls[[[1, 2], 3]]}
+ assert_warning(/wrong element type Integer at 1 /) {@cls[[[1, 2], 3]]}
bug5406 = '[ruby-core:39945]'
assert_raise(ArgumentError, bug5406) { @cls[[[1, 2], [3, 4, 5]]] }
assert_equal({1=>2, 3=>4}, @cls[1,2,3,4])
diff --git a/test/ruby/test_integer.rb b/test/ruby/test_integer.rb
index 12ada1709e0..e493a7546df 100644
--- a/test/ruby/test_integer.rb
+++ b/test/ruby/test_integer.rb
@@ -109,20 +109,6 @@ class TestInteger < Test::Unit::TestCase
def test_succ
assert_equal(2, 1.send(:succ))
-
- Fixnum.class_eval do
- alias succ_bak succ
- remove_method :succ
- end
-
- assert_equal(2, 1.succ)
- assert_equal(4294967297, 4294967296.succ)
-
- ensure
- Fixnum.class_eval do
- alias succ succ_bak
- remove_method :succ_bak
- end
end
def test_chr
diff --git a/test/ruby/test_numeric.rb b/test/ruby/test_numeric.rb
index 0463462d1a3..c2a2e001b8c 100644
--- a/test/ruby/test_numeric.rb
+++ b/test/ruby/test_numeric.rb
@@ -28,7 +28,7 @@ class TestNumeric < Test::Unit::TestCase
assert_raise_with_message(TypeError, /:"\\u3042"/) {1^:"\u{3042}"}
bug10711 = '[ruby-core:67405] [Bug #10711]'
- exp = "1.2 can't be coerced into Fixnum"
+ exp = "1.2 can't be coerced into Integer"
assert_raise_with_message(TypeError, exp, bug10711) { 1 & 1.2 }
end
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb
index 8fd9e208e54..3b5e24f9809 100644
--- a/test/ruby/test_optimization.rb
+++ b/test/ruby/test_optimization.rb
@@ -29,7 +29,7 @@ class TestRubyOptimization < Test::Unit::TestCase
assert_bignum FIXNUM_MAX + 1
assert_equal 21, 10 + 11
- assert_redefine_method('Fixnum', '+', 'assert_equal 11, 10 + 11')
+ assert_redefine_method('Integer', '+', 'assert_equal 11, 10 + 11')
end
def test_fixnum_minus
@@ -38,22 +38,22 @@ class TestRubyOptimization < Test::Unit::TestCase
assert_bignum FIXNUM_MIN - 1
assert_equal 5, 8 - 3
- assert_redefine_method('Fixnum', '-', 'assert_equal 3, 8 - 3')
+ assert_redefine_method('Integer', '-', 'assert_equal 3, 8 - 3')
end
def test_fixnum_mul
assert_equal 15, 3 * 5
- assert_redefine_method('Fixnum', '*', 'assert_equal 5, 3 * 5')
+ assert_redefine_method('Integer', '*', 'assert_equal 5, 3 * 5')
end
def test_fixnum_div
assert_equal 3, 15 / 5
- assert_redefine_method('Fixnum', '/', 'assert_equal 5, 15 / 5')
+ assert_redefine_method('Integer', '/', 'assert_equal 5, 15 / 5')
end
def test_fixnum_mod
assert_equal 1, 8 % 7
- assert_redefine_method('Fixnum', '%', 'assert_equal 7, 8 % 7')
+ assert_redefine_method('Integer', '%', 'assert_equal 7, 8 % 7')
end
def test_float_plus
diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb
index 24ececcbf45..1eb7e24b8cb 100644
--- a/test/ruby/test_regexp.rb
+++ b/test/ruby/test_regexp.rb
@@ -1013,7 +1013,7 @@ class TestRegexp < Test::Unit::TestCase
def test_error_message_on_failed_conversion
bug7539 = '[ruby-core:50733]'
assert_equal false, /x/=== 42
- assert_raise_with_message(TypeError, 'no implicit conversion of Fixnum into String', bug7539) {
+ assert_raise_with_message(TypeError, 'no implicit conversion of Integer into String', bug7539) {
Regexp.quote(42)
}
end
diff --git a/test/ruby/test_settracefunc.rb b/test/ruby/test_settracefunc.rb
index 018c0062c37..3132636e18f 100644
--- a/test/ruby/test_settracefunc.rb
+++ b/test/ruby/test_settracefunc.rb
@@ -35,9 +35,9 @@ class TestSetTraceFunc < Test::Unit::TestCase
events.shift)
assert_equal(["line", 4, __method__, self.class],
events.shift)
- assert_equal(["c-call", 4, :+, Fixnum],
+ assert_equal(["c-call", 4, :+, Integer],
events.shift)
- assert_equal(["c-return", 4, :+, Fixnum],
+ assert_equal(["c-return", 4, :+, Integer],
events.shift)
assert_equal(["line", 5, __method__, self.class],
events.shift)
@@ -73,9 +73,9 @@ class TestSetTraceFunc < Test::Unit::TestCase
events.shift)
assert_equal(["line", 5, :add, self.class],
events.shift)
- assert_equal(["c-call", 5, :+, Fixnum],
+ assert_equal(["c-call", 5, :+, Integer],
events.shift)
- assert_equal(["c-return", 5, :+, Fixnum],
+ assert_equal(["c-return", 5, :+, Integer],
events.shift)
assert_equal(["return", 6, :add, self.class],
events.shift)
@@ -353,8 +353,8 @@ class TestSetTraceFunc < Test::Unit::TestCase
["c-return", 8, :new, Class],
["call", 4, :foo, ThreadTraceInnerClass],
["line", 5, :foo, ThreadTraceInnerClass],
- ["c-call", 5, :+, Fixnum],
- ["c-return", 5, :+, Fixnum],
+ ["c-call", 5, :+, Integer],
+ ["c-return", 5, :+, Integer],
["return", 6, :foo, ThreadTraceInnerClass],
["line", 9, __method__, self.class],
["c-call", 9, :set_trace_func, Thread]].each do |e|
@@ -768,10 +768,10 @@ class TestSetTraceFunc < Test::Unit::TestCase
# pp events
# expected_events =
[[:b_call, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil],
- [:c_call, :times, Integer, Fixnum, nil],
+ [:c_call, :times, Integer, Integer, nil],
[:b_call, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil],
[:b_return, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, 3],
- [:c_return, :times, Integer, Fixnum, 1],
+ [:c_return, :times, Integer, Integer, 1],
[:call, :method_for_test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil],
[:b_call, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, nil],
[:b_return, :test_tracepoint_block, TestSetTraceFunc, TestSetTraceFunc, 4],
diff --git a/vm.c b/vm.c
index 907eddc7746..b8441e96c16 100644
--- a/vm.c
+++ b/vm.c
@@ -1388,12 +1388,11 @@ static st_table *vm_opt_method_table = 0;
static int
vm_redefinition_check_flag(VALUE klass)
{
- if (klass == rb_cFixnum) return FIXNUM_REDEFINED_OP_FLAG;
+ if (klass == rb_cInteger) return INTEGER_REDEFINED_OP_FLAG;
if (klass == rb_cFloat) return FLOAT_REDEFINED_OP_FLAG;
if (klass == rb_cString) return STRING_REDEFINED_OP_FLAG;
if (klass == rb_cArray) return ARRAY_REDEFINED_OP_FLAG;
if (klass == rb_cHash) return HASH_REDEFINED_OP_FLAG;
- if (klass == rb_cBignum) return BIGNUM_REDEFINED_OP_FLAG;
if (klass == rb_cSymbol) return SYMBOL_REDEFINED_OP_FLAG;
if (klass == rb_cTime) return TIME_REDEFINED_OP_FLAG;
if (klass == rb_cRegexp) return REGEXP_REDEFINED_OP_FLAG;
@@ -1461,25 +1460,25 @@ vm_init_redefined_flag(void)
#define OP(mid_, bop_) (mid = id##mid_, bop = BOP_##bop_, ruby_vm_redefined_flag[bop] = 0)
#define C(k) add_opt_method(rb_c##k, mid, bop)
- OP(PLUS, PLUS), (C(Fixnum), C(Float), C(String), C(Array));
- OP(MINUS, MINUS), (C(Fixnum), C(Float));
- OP(MULT, MULT), (C(Fixnum), C(Float));
- OP(DIV, DIV), (C(Fixnum), C(Float));
- OP(MOD, MOD), (C(Fixnum), C(Float));
- OP(Eq, EQ), (C(Fixnum), C(Float), C(String));
- OP(Eqq, EQQ), (C(Fixnum), C(Bignum), C(Float), C(Symbol), C(String),
+ OP(PLUS, PLUS), (C(Integer), C(Float), C(String), C(Array));
+ OP(MINUS, MINUS), (C(Integer), C(Float));
+ OP(MULT, MULT), (C(Integer), C(Float));
+ OP(DIV, DIV), (C(Integer), C(Float));
+ OP(MOD, MOD), (C(Integer), C(Float));
+ OP(Eq, EQ), (C(Integer), C(Float), C(String));
+ OP(Eqq, EQQ), (C(Integer), C(Float), C(Symbol), C(String),
C(NilClass), C(TrueClass), C(FalseClass));
- OP(LT, LT), (C(Fixnum), C(Float));
- OP(LE, LE), (C(Fixnum), C(Float));
- OP(GT, GT), (C(Fixnum), C(Float));
- OP(GE, GE), (C(Fixnum), C(Float));
+ OP(LT, LT), (C(Integer), C(Float));
+ OP(LE, LE), (C(Integer), C(Float));
+ OP(GT, GT), (C(Integer), C(Float));
+ OP(GE, GE), (C(Integer), C(Float));
OP(LTLT, LTLT), (C(String), C(Array));
OP(AREF, AREF), (C(Array), C(Hash));
OP(ASET, ASET), (C(Array), C(Hash));
OP(Length, LENGTH), (C(Array), C(String), C(Hash));
OP(Size, SIZE), (C(Array), C(String), C(Hash));
OP(EmptyP, EMPTY_P), (C(Array), C(String), C(Hash));
- OP(Succ, SUCC), (C(Fixnum), C(String), C(Time));
+ OP(Succ, SUCC), (C(Integer), C(String), C(Time));
OP(EqTilde, MATCH), (C(Regexp), C(String));
OP(Freeze, FREEZE), (C(String));
OP(Max, MAX), (C(Array));
diff --git a/vm_core.h b/vm_core.h
index 5c1e718efee..9ae72477e20 100644
--- a/vm_core.h
+++ b/vm_core.h
@@ -569,12 +569,12 @@ typedef struct rb_vm_struct {
#define RUBY_VM_FIBER_MACHINE_STACK_SIZE_MIN ( 16 * 1024 * sizeof(VALUE)) /* 64 KB or 128 KB */
/* optimize insn */
-#define FIXNUM_REDEFINED_OP_FLAG (1 << 0)
+#define INTEGER_REDEFINED_OP_FLAG (1 << 0)
#define FLOAT_REDEFINED_OP_FLAG (1 << 1)
#define STRING_REDEFINED_OP_FLAG (1 << 2)
#define ARRAY_REDEFINED_OP_FLAG (1 << 3)
#define HASH_REDEFINED_OP_FLAG (1 << 4)
-#define BIGNUM_REDEFINED_OP_FLAG (1 << 5)
+/* #define BIGNUM_REDEFINED_OP_FLAG (1 << 5) */
#define SYMBOL_REDEFINED_OP_FLAG (1 << 6)
#define TIME_REDEFINED_OP_FLAG (1 << 7)
#define REGEXP_REDEFINED_OP_FLAG (1 << 8)
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 403b24bdfe6..691c37a3dfc 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -1159,7 +1159,7 @@ VALUE
opt_eq_func(VALUE recv, VALUE obj, CALL_INFO ci, CALL_CACHE cc)
{
if (FIXNUM_2_P(recv, obj) &&
- BASIC_OP_UNREDEFINED_P(BOP_EQ, FIXNUM_REDEFINED_OP_FLAG)) {
+ BASIC_OP_UNREDEFINED_P(BOP_EQ, INTEGER_REDEFINED_OP_FLAG)) {
return (recv == obj) ? Qtrue : Qfalse;
}
else if (FLONUM_2_P(recv, obj) &&