diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-11-04 11:49:25 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-11-04 11:49:25 +0900 |
| commit | de2363a9f0c7d368ee9002f86931d124e644a243 (patch) | |
| tree | 2112928a80786a109ecac4b3ce200f45ac75e2cb /src/vm.c | |
| parent | 388d26d77027feaa3e107abf7209e2681868bbe6 (diff) | |
| parent | 625f9f6fa314872968632c5adbee7fb3823268b8 (diff) | |
| download | mruby-de2363a9f0c7d368ee9002f86931d124e644a243.tar.gz mruby-de2363a9f0c7d368ee9002f86931d124e644a243.zip | |
Merge branch 'mrb_without_float' of https://github.com/pandax381/mruby into pandax381-mrb_without_float
Diffstat (limited to 'src/vm.c')
| -rw-r--r-- | src/vm.c | 62 |
1 files changed, 59 insertions, 3 deletions
@@ -667,7 +667,9 @@ mrb_obj_instance_eval(mrb_state *mrb, mrb_value self) switch (mrb_type(self)) { case MRB_TT_SYMBOL: case MRB_TT_FIXNUM: +#ifndef MRB_WITHOUT_FLOAT case MRB_TT_FLOAT: +#endif c = 0; break; default: @@ -990,9 +992,11 @@ RETRY_TRY_BLOCK: int bx = GETARG_Bx(i); #ifdef MRB_WORD_BOXING mrb_value val = pool[bx]; +#ifndef MRB_WITHOUT_FLOAT if (mrb_float_p(val)) { val = mrb_float_value(mrb, mrb_float(val)); } +#endif regs[a] = val; #else regs[a] = pool[bx]; @@ -2175,12 +2179,15 @@ RETRY_TRY_BLOCK: x = mrb_fixnum(regs_a[0]); y = mrb_fixnum(regs_a[1]); if (mrb_int_add_overflow(x, y, &z)) { +#ifndef MRB_WITHOUT_FLOAT SET_FLOAT_VALUE(mrb, regs_a[0], (mrb_float)x + (mrb_float)y); break; +#endif } SET_INT_VALUE(regs[a], z); } break; +#ifndef MRB_WITHOUT_FLOAT case TYPES2(MRB_TT_FIXNUM,MRB_TT_FLOAT): { mrb_int x = mrb_fixnum(regs[a]); @@ -2210,6 +2217,7 @@ RETRY_TRY_BLOCK: OP_MATH_BODY(+,mrb_float,mrb_float); #endif break; +#endif case TYPES2(MRB_TT_STRING,MRB_TT_STRING): regs[a] = mrb_str_plus(mrb, regs[a], regs[a+1]); break; @@ -2233,12 +2241,15 @@ RETRY_TRY_BLOCK: x = mrb_fixnum(regs[a]); y = mrb_fixnum(regs[a+1]); if (mrb_int_sub_overflow(x, y, &z)) { +#ifndef MRB_WITHOUT_FLOAT SET_FLOAT_VALUE(mrb, regs[a], (mrb_float)x - (mrb_float)y); break; +#endif } SET_INT_VALUE(regs[a], z); } break; +#ifndef MRB_WITHOUT_FLOAT case TYPES2(MRB_TT_FIXNUM,MRB_TT_FLOAT): { mrb_int x = mrb_fixnum(regs[a]); @@ -2268,6 +2279,7 @@ RETRY_TRY_BLOCK: OP_MATH_BODY(-,mrb_float,mrb_float); #endif break; +#endif default: goto L_SEND; } @@ -2287,12 +2299,15 @@ RETRY_TRY_BLOCK: x = mrb_fixnum(regs[a]); y = mrb_fixnum(regs[a+1]); if (mrb_int_mul_overflow(x, y, &z)) { +#ifndef MRB_WITHOUT_FLOAT SET_FLOAT_VALUE(mrb, regs[a], (mrb_float)x * (mrb_float)y); break; +#endif } SET_INT_VALUE(regs[a], z); } break; +#ifndef MRB_WITHOUT_FLOAT case TYPES2(MRB_TT_FIXNUM,MRB_TT_FLOAT): { mrb_int x = mrb_fixnum(regs[a]); @@ -2322,6 +2337,7 @@ RETRY_TRY_BLOCK: OP_MATH_BODY(*,mrb_float,mrb_float); #endif break; +#endif default: goto L_SEND; } @@ -2331,11 +2347,21 @@ RETRY_TRY_BLOCK: CASE(OP_DIV) { /* A B C R(A) := R(A)/R(A+1) (Syms[B]=:/,C=1)*/ int a = GETARG_A(i); +#ifndef MRB_WITHOUT_FLOAT double x, y, f; +#endif /* need to check if op is overridden */ switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) { case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM): +#ifdef MRB_WITHOUT_FLOAT + { + mrb_int x = mrb_fixnum(regs[a]); + mrb_int y = mrb_fixnum(regs[a+1]); + SET_INT_VALUE(regs[a], y ? x / y : 0); + } + break; +#else x = (mrb_float)mrb_fixnum(regs[a]); y = (mrb_float)mrb_fixnum(regs[a+1]); break; @@ -2351,10 +2377,12 @@ RETRY_TRY_BLOCK: x = mrb_float(regs[a]); y = mrb_float(regs[a+1]); break; +#endif default: goto L_SEND; } +#ifndef MRB_WITHOUT_FLOAT if (y == 0) { if (x > 0) f = INFINITY; else if (x < 0) f = -INFINITY; @@ -2364,6 +2392,7 @@ RETRY_TRY_BLOCK: f = x / y; } SET_FLOAT_VALUE(mrb, regs[a], f); +#endif NEXT; } @@ -2380,12 +2409,15 @@ RETRY_TRY_BLOCK: mrb_int z; if (mrb_int_add_overflow(x, y, &z)) { +#ifndef MRB_WITHOUT_FLOAT SET_FLOAT_VALUE(mrb, regs[a], (mrb_float)x + (mrb_float)y); break; +#endif } SET_INT_VALUE(regs[a], z); } break; +#ifndef MRB_WITHOUT_FLOAT case MRB_TT_FLOAT: #ifdef MRB_WORD_BOXING { @@ -2396,6 +2428,7 @@ RETRY_TRY_BLOCK: mrb_float(regs[a]) += GETARG_C(i); #endif break; +#endif default: SET_INT_VALUE(regs[a+1], GETARG_C(i)); i = MKOP_ABC(OP_SEND, a, GETARG_B(i), 1); @@ -2418,13 +2451,15 @@ RETRY_TRY_BLOCK: mrb_int z; if (mrb_int_sub_overflow(x, y, &z)) { +#ifndef MRB_WITHOUT_FLOAT SET_FLOAT_VALUE(mrb, regs_a[0], (mrb_float)x - (mrb_float)y); + break; +#endif } - else { - SET_INT_VALUE(regs_a[0], z); - } + SET_INT_VALUE(regs_a[0], z); } break; +#ifndef MRB_WITHOUT_FLOAT case MRB_TT_FLOAT: #ifdef MRB_WORD_BOXING { @@ -2435,6 +2470,7 @@ RETRY_TRY_BLOCK: mrb_float(regs_a[0]) -= GETARG_C(i); #endif break; +#endif default: SET_INT_VALUE(regs_a[1], GETARG_C(i)); i = MKOP_ABC(OP_SEND, a, GETARG_B(i), 1); @@ -2445,6 +2481,25 @@ RETRY_TRY_BLOCK: #define OP_CMP_BODY(op,v1,v2) (v1(regs[a]) op v2(regs[a+1])) +#ifdef MRB_WITHOUT_FLOAT +#define OP_CMP(op) do {\ + int result;\ + /* need to check if - is overridden */\ + switch (TYPES2(mrb_type(regs[a]),mrb_type(regs[a+1]))) {\ + case TYPES2(MRB_TT_FIXNUM,MRB_TT_FIXNUM):\ + result = OP_CMP_BODY(op,mrb_fixnum,mrb_fixnum);\ + break;\ + default:\ + goto L_SEND;\ + }\ + if (result) {\ + SET_TRUE_VALUE(regs[a]);\ + }\ + else {\ + SET_FALSE_VALUE(regs[a]);\ + }\ +} while(0) +#else #define OP_CMP(op) do {\ int result;\ /* need to check if - is overridden */\ @@ -2471,6 +2526,7 @@ RETRY_TRY_BLOCK: SET_FALSE_VALUE(regs[a]);\ }\ } while(0) +#endif CASE(OP_EQ) { /* A B C R(A) := R(A)==R(A+1) (Syms[B]=:==,C=1)*/ |
