summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-05-17 15:07:05 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-05-17 15:07:05 +0900
commit5eebbd7df23421235a2d6289784e18d572c4b18a (patch)
tree1cdb8c607f175d162ca3e316a0147ee36b2fc015 /src
parentea7f1953c3886d7597eaed21c84fdba209ee6d9b (diff)
downloadmruby-5eebbd7df23421235a2d6289784e18d572c4b18a.tar.gz
mruby-5eebbd7df23421235a2d6289784e18d572c4b18a.zip
Global renaming regarding `integer` and `float`.
Consistent number conversion function names: * `mrb_value` to immediate (C) value * `mrb_int()` -> `mrb_as_int()` * `mrb_to_flo()` -> `mrb_as_float()` * `mrb_value` to `mrb_value` (converted) * `mrb_to_int()' * `mrb_Integer()` - removed * `mrb_Float()` -> `mrb_to_float` Consistent function name (avoid `_flo` suffix): * `mrb_div_flo()` -> `mrb_div_float`
Diffstat (limited to 'src')
-rw-r--r--src/class.c4
-rw-r--r--src/numeric.c50
-rw-r--r--src/object.c8
-rw-r--r--src/range.c4
-rw-r--r--src/string.c4
-rw-r--r--src/vm.c4
6 files changed, 31 insertions, 43 deletions
diff --git a/src/class.c b/src/class.c
index dfd25b371..cd4e160ac 100644
--- a/src/class.c
+++ b/src/class.c
@@ -1151,7 +1151,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, mrb_float*);
if (i < argc) {
- *p = mrb_to_flo(mrb, argv[i++]);
+ *p = mrb_as_float(mrb, argv[i]); i++;
}
}
break;
@@ -1162,7 +1162,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, mrb_int*);
if (i < argc) {
- *p = mrb_integer(mrb_to_int(mrb, argv[i++]));
+ *p = mrb_as_int(mrb, argv[i]); i++;
}
}
break;
diff --git a/src/numeric.c b/src/numeric.c
index 704263054..8aa3459a0 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -33,7 +33,7 @@
#ifndef MRB_NO_FLOAT
MRB_API mrb_float
-mrb_to_flo(mrb_state *mrb, mrb_value val)
+mrb_as_float(mrb_state *mrb, mrb_value val)
{
switch (mrb_type(val)) {
case MRB_TT_INTEGER:
@@ -137,10 +137,6 @@ mrb_div_int(mrb_state *mrb, mrb_int x, mrb_int y)
return 0;
}
-#ifndef MRB_NO_FLOAT
-mrb_float mrb_div_flo(mrb_float x, mrb_float y);
-#endif
-
/* 15.2.8.3.4 */
/* 15.2.9.3.4 */
/*
@@ -164,7 +160,7 @@ int_div(mrb_state *mrb, mrb_value x)
#ifdef MRB_NO_FLOAT
mrb_raise(mrb, E_TYPE_ERROR, "non integer division");
#else
- return mrb_float_value(mrb, mrb_div_flo((mrb_float)a, mrb_to_flo(mrb, y)));
+ return mrb_float_value(mrb, mrb_div_float((mrb_float)a, mrb_as_float(mrb, y)));
#endif
}
@@ -219,7 +215,7 @@ coerce_step_counter(mrb_state *mrb, mrb_value self)
#ifndef MRB_NO_FLOAT
if (mrb_float_p(self) || mrb_float_p(num) || mrb_float_p(step)) {
- return mrb_Float(mrb, self);
+ return mrb_to_float(mrb, self);
}
#endif
@@ -240,7 +236,7 @@ static mrb_value
flo_pow(mrb_state *mrb, mrb_value x)
{
mrb_value y = mrb_get_arg1(mrb);
- mrb_float d = pow(mrb_to_flo(mrb, x), mrb_to_flo(mrb, y));
+ mrb_float d = pow(mrb_as_float(mrb, x), mrb_as_float(mrb, y));
return mrb_float_value(mrb, d);
}
@@ -255,7 +251,7 @@ flo_idiv(mrb_state *mrb, mrb_value xv)
}
mrb_float
-mrb_div_flo(mrb_float x, mrb_float y)
+mrb_div_float(mrb_float x, mrb_float y)
{
if (y != 0.0) {
return x / y;
@@ -275,10 +271,10 @@ flo_div(mrb_state *mrb, mrb_value x)
mrb_float a = mrb_float(x);
if (mrb_float_p(y)) {
- a = mrb_div_flo(a, mrb_float(y));
+ a = mrb_div_float(a, mrb_float(y));
}
else {
- a = mrb_div_flo(a, mrb_to_flo(mrb, y));
+ a = mrb_div_float(a, mrb_as_float(mrb, y));
}
return mrb_float_value(mrb, a);
}
@@ -376,7 +372,7 @@ flo_add(mrb_state *mrb, mrb_value x)
return mrb_funcall_id(mrb, y, MRB_OPSYM(add), 1, x);
#endif
default:
- return mrb_float_value(mrb, a + mrb_to_flo(mrb, y));
+ return mrb_float_value(mrb, a + mrb_as_float(mrb, y));
}
}
@@ -404,7 +400,7 @@ flo_sub(mrb_state *mrb, mrb_value x)
return mrb_funcall_id(mrb, x, MRB_OPSYM(minus), 0);
#endif
default:
- return mrb_float_value(mrb, a - mrb_to_flo(mrb, y));
+ return mrb_float_value(mrb, a - mrb_as_float(mrb, y));
}
}
@@ -431,7 +427,7 @@ flo_mul(mrb_state *mrb, mrb_value x)
return mrb_funcall_id(mrb, y, MRB_OPSYM(mul), 1, x);
#endif
default:
- return mrb_float_value(mrb, a * mrb_to_flo(mrb, y));
+ return mrb_float_value(mrb, a * mrb_as_float(mrb, y));
}
}
@@ -490,7 +486,7 @@ flo_mod(mrb_state *mrb, mrb_value x)
mrb_value y = mrb_get_arg1(mrb);
mrb_float mod;
- flodivmod(mrb, mrb_float(x), mrb_to_flo(mrb, y), 0, &mod);
+ flodivmod(mrb, mrb_float(x), mrb_as_float(mrb, y), 0, &mod);
return mrb_float_value(mrb, mod);
}
#endif
@@ -551,7 +547,7 @@ flo_eq(mrb_state *mrb, mrb_value x)
return mrb_bool_value(mrb_float(x) == mrb_float(y));
#ifdef MRB_USE_RATIONAL
case MRB_TT_RATIONAL:
- return mrb_bool_value(mrb_float(x) == mrb_to_flo(mrb, y));
+ return mrb_bool_value(mrb_float(x) == mrb_as_float(mrb, y));
#endif
#ifdef MRB_USE_COMPLEX
case MRB_TT_COMPLEX:
@@ -967,7 +963,7 @@ fixnum_mul(mrb_state *mrb, mrb_value x, mrb_value y)
#ifdef MRB_NO_FLOAT
mrb_raise(mrb, E_TYPE_ERROR, "non integer multiplication");
#else
- return mrb_float_value(mrb, (mrb_float)a * mrb_to_flo(mrb, y));
+ return mrb_float_value(mrb, (mrb_float)a * mrb_as_float(mrb, y));
#endif
}
}
@@ -980,7 +976,7 @@ mrb_num_mul(mrb_state *mrb, mrb_value x, mrb_value y)
}
#ifndef MRB_NO_FLOAT
if (mrb_float_p(x)) {
- return mrb_float_value(mrb, mrb_float(x) * mrb_to_flo(mrb, y));
+ return mrb_float_value(mrb, mrb_float(x) * mrb_as_float(mrb, y));
}
#endif
#if defined(MRB_USE_RATIONAL) || defined(MRB_USE_COMPLEX)
@@ -1065,7 +1061,7 @@ int_mod(mrb_state *mrb, mrb_value x)
else {
mrb_float mod;
- flodivmod(mrb, (mrb_float)a, mrb_to_flo(mrb, y), NULL, &mod);
+ flodivmod(mrb, (mrb_float)a, mrb_as_float(mrb, y), NULL, &mod);
return mrb_float_value(mrb, mod);
}
#endif
@@ -1095,7 +1091,7 @@ int_divmod(mrb_state *mrb, mrb_value x)
mrb_float div, mod;
mrb_value a, b;
- flodivmod(mrb, (mrb_float)mrb_integer(x), mrb_to_flo(mrb, y), &div, &mod);
+ flodivmod(mrb, (mrb_float)mrb_integer(x), mrb_as_float(mrb, y), &div, &mod);
a = mrb_int_value(mrb, (mrb_int)div);
b = mrb_float_value(mrb, mod);
return mrb_assoc_new(mrb, a, b);
@@ -1111,7 +1107,7 @@ flo_divmod(mrb_state *mrb, mrb_value x)
mrb_float div, mod;
mrb_value a, b;
- flodivmod(mrb, mrb_float(x), mrb_to_flo(mrb, y), &div, &mod);
+ flodivmod(mrb, mrb_float(x), mrb_as_float(mrb, y), &div, &mod);
if (!FIXABLE_FLOAT(div))
a = mrb_float_value(mrb, div);
else
@@ -1405,7 +1401,7 @@ int_plus(mrb_state *mrb, mrb_value x, mrb_value y)
#ifdef MRB_NO_FLOAT
mrb_raise(mrb, E_TYPE_ERROR, "non integer addition");
#else
- return mrb_float_value(mrb, (mrb_float)a + mrb_to_flo(mrb, y));
+ return mrb_float_value(mrb, (mrb_float)a + mrb_as_float(mrb, y));
#endif
}
}
@@ -1418,7 +1414,7 @@ mrb_num_plus(mrb_state *mrb, mrb_value x, mrb_value y)
}
#ifndef MRB_NO_FLOAT
if (mrb_float_p(x)) {
- return mrb_float_value(mrb, mrb_float(x) + mrb_to_flo(mrb, y));
+ return mrb_float_value(mrb, mrb_float(x) + mrb_as_float(mrb, y));
}
#endif
#if defined(MRB_USE_RATIONAL) || defined(MRB_USE_COMPLEX)
@@ -1477,7 +1473,7 @@ int_minus(mrb_state *mrb, mrb_value x, mrb_value y)
#ifdef MRB_NO_FLOAT
mrb_raise(mrb, E_TYPE_ERROR, "non integer subtraction");
#else
- return mrb_float_value(mrb, (mrb_float)a - mrb_to_flo(mrb, y));
+ return mrb_float_value(mrb, (mrb_float)a - mrb_as_float(mrb, y));
#endif
}
}
@@ -1490,7 +1486,7 @@ mrb_num_minus(mrb_state *mrb, mrb_value x, mrb_value y)
}
#ifndef MRB_NO_FLOAT
if (mrb_float_p(x)) {
- return mrb_float_value(mrb, mrb_float(x) - mrb_to_flo(mrb, y));
+ return mrb_float_value(mrb, mrb_float(x) - mrb_as_float(mrb, y));
}
#endif
#if defined(MRB_USE_RATIONAL) || defined(MRB_USE_COMPLEX)
@@ -1595,7 +1591,7 @@ cmpnum(mrb_state *mrb, mrb_value v1, mrb_value v2)
#ifdef MRB_NO_FLOAT
x = mrb_integer(v1);
#else
- x = mrb_to_flo(mrb, v1);
+ x = mrb_as_float(mrb, v1);
#endif
switch (mrb_type(v2)) {
case MRB_TT_INTEGER:
@@ -1611,7 +1607,7 @@ cmpnum(mrb_state *mrb, mrb_value v1, mrb_value v2)
break;
#ifdef MRB_USE_RATIONAL
case MRB_TT_RATIONAL:
- y = mrb_to_flo(mrb, v2);
+ y = mrb_as_float(mrb, v2);
break;
#endif
#endif
diff --git a/src/object.c b/src/object.c
index 685770354..7e2748018 100644
--- a/src/object.c
+++ b/src/object.c
@@ -564,15 +564,9 @@ arg_error:
return mrb_to_int(mrb, val);
}
-MRB_API mrb_value
-mrb_Integer(mrb_state *mrb, mrb_value val)
-{
- return mrb_convert_to_integer(mrb, val, 0);
-}
-
#ifndef MRB_NO_FLOAT
MRB_API mrb_value
-mrb_Float(mrb_state *mrb, mrb_value val)
+mrb_to_float(mrb_state *mrb, mrb_value val)
{
if (mrb_nil_p(val)) {
mrb_raise(mrb, E_TYPE_ERROR, "can't convert nil into Float");
diff --git a/src/range.c b/src/range.c
index 1615f03b2..be611b2a3 100644
--- a/src/range.c
+++ b/src/range.c
@@ -458,8 +458,8 @@ mrb_range_beg_len(mrb_state *mrb, mrb_value range, mrb_int *begp, mrb_int *lenp,
if (!mrb_range_p(range)) return MRB_RANGE_TYPE_MISMATCH;
r = mrb_range_ptr(mrb, range);
- beg = mrb_nil_p(RANGE_BEG(r)) ? 0 : mrb_int(mrb, RANGE_BEG(r));
- end = mrb_nil_p(RANGE_END(r)) ? -1 : mrb_int(mrb, RANGE_END(r));
+ beg = mrb_nil_p(RANGE_BEG(r)) ? 0 : mrb_as_int(mrb, RANGE_BEG(r));
+ end = mrb_nil_p(RANGE_END(r)) ? -1 : mrb_as_int(mrb, RANGE_END(r));
excl = mrb_nil_p(RANGE_END(r)) ? 0 : RANGE_EXCL(r);
if (beg < 0) {
diff --git a/src/string.c b/src/string.c
index 4125b21c4..f87471e5d 100644
--- a/src/string.c
+++ b/src/string.c
@@ -1102,8 +1102,8 @@ static enum str_convert_range
str_convert_range(mrb_state *mrb, mrb_value str, mrb_value indx, mrb_value alen, mrb_int *beg, mrb_int *len)
{
if (!mrb_undef_p(alen)) {
- *beg = mrb_int(mrb, indx);
- *len = mrb_int(mrb, alen);
+ *beg = mrb_as_int(mrb, indx);
+ *len = mrb_as_int(mrb, alen);
return STR_CHAR_RANGE;
}
else {
diff --git a/src/vm.c b/src/vm.c
index 346a14ba3..b933d36f0 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -2440,9 +2440,7 @@ RETRY_TRY_BLOCK:
CASE(OP_DIV, B) {
#ifndef MRB_NO_FLOAT
mrb_float x, y, f;
- mrb_float mrb_div_flo(mrb_float x, mrb_float y);
#endif
- mrb_int mrb_div_int(mrb_state *mrb, mrb_int x, mrb_int y);
/* need to check if op is overridden */
switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {
@@ -2475,7 +2473,7 @@ RETRY_TRY_BLOCK:
}
#ifndef MRB_NO_FLOAT
- f = mrb_div_flo(x, y);
+ f = mrb_div_float(x, y);
SET_FLOAT_VALUE(mrb, regs[a], f);
#endif
NEXT;