Permalink
Browse files

NaN boxing

  • Loading branch information...
1 parent e74600c commit 7d02df3016b0c6eb3f4ee945198772cf4ebca3fa @matz matz committed Aug 14, 2012
View
11 include/mrbconf.h
@@ -13,6 +13,12 @@
/* add -DMRB_USE_FLOAT to use float instead of double for floating point numbers */
//#define MRB_USE_FLOAT
+/* represent mrb_value in boxed double; conflict with MRB_USE_FLOAT */
+//#define MRB_NAN_BOXING
+
+/* define on big endian machines; used by MRB_NAN_BOXING */
+//#define MRB_ENDIAN_BIG
+
/* argv max size in mrb_funcall */
//#define MRB_FUNCALL_ARGC_MAX 16
@@ -54,8 +60,13 @@ typedef double mrb_float;
#endif
#define readfloat(p) (mrb_float)strtod((p),NULL)
+#ifdef MRB_NAN_BOXING
+typedef int32_t mrb_int;
+typedef int32_t mrb_sym;
+#else
typedef int mrb_int;
typedef intptr_t mrb_sym;
+#endif
/* define ENABLE_XXXX from DISABLE_XXX */
#ifndef DISABLE_REGEXP
View
2 include/mruby.h
@@ -229,7 +229,7 @@ int mrb_gc_arena_save(mrb_state*);
void mrb_gc_arena_restore(mrb_state*,int);
void mrb_gc_mark(mrb_state*,struct RBasic*);
#define mrb_gc_mark_value(mrb,val) do {\
- if ((val).tt >= MRB_TT_OBJECT) mrb_gc_mark((mrb), mrb_object(val));\
+ if (mrb_type(val) >= MRB_TT_OBJECT) mrb_gc_mark((mrb), mrb_object(val));\
} while (0);
void mrb_field_write_barrier(mrb_state *, struct RBasic*, struct RBasic*);
#define mrb_field_write_barrier_value(mrb, obj, val) do{\
View
2 include/mruby/array.h
@@ -1,5 +1,5 @@
/*
-** array.h - Array class
+** mruby/array.h - Array class
**
** See Copyright Notice in mruby.h
*/
View
2 include/mruby/cdump.h
@@ -1,5 +1,5 @@
/*
-** cdump.h - mruby binary dumper (C source format)
+** mruby/cdump.h - mruby binary dumper (C source format)
**
** See Copyright Notice in mruby.h
*/
View
2 include/mruby/class.h
@@ -1,5 +1,5 @@
/*
-** class.h - Class class
+** mruby/class.h - Class class
**
** See Copyright Notice in mruby.h
*/
View
2 include/mruby/compile.h
@@ -1,5 +1,5 @@
/*
-** compile.h - mruby parser
+** mruby/compile.h - mruby parser
**
** See Copyright Notice in mruby.h
*/
View
2 include/mruby/data.h
@@ -1,5 +1,5 @@
/*
-** data.h - Data class
+** mruby/data.h - Data class
**
** See Copyright Notice in mruby.h
*/
View
2 include/mruby/dump.h
@@ -1,5 +1,5 @@
/*
-** dump.h - mruby binary dumper (Rite binary format)
+** mruby/dump.h - mruby binary dumper (Rite binary format)
**
** See Copyright Notice in mruby.h
*/
View
2 include/mruby/hash.h
@@ -1,5 +1,5 @@
/*
-** hash.h - Hash class
+** mruby/hash.h - Hash class
**
** See Copyright Notice in mruby.h
*/
View
2 include/mruby/irep.h
@@ -1,5 +1,5 @@
/*
-** irep.h - mrb_irep structure
+** mruby/irep.h - mrb_irep structure
**
** See Copyright Notice in mruby.h
*/
View
2 include/mruby/khash.h
@@ -1,5 +1,5 @@
/*
-** ritehash.c - Rite Hash for mruby
+** mruby/khash.c - Hash for mruby
**
** See Copyright Notice in mruby.h
*/
View
2 include/mruby/numeric.h
@@ -1,5 +1,5 @@
/*
-** numeric.h - Numeric, Integer, Float, Fixnum class
+** mruby/numeric.h - Numeric, Integer, Float, Fixnum class
**
** See Copyright Notice in mruby.h
*/
View
2 include/mruby/object.h
@@ -8,7 +8,7 @@
#define MRUBY_OBJECT_H
#define MRUBY_OBJECT_HEADER \
- enum mrb_vtype tt:8; \
+ enum mrb_vtype tt; \
unsigned int color:3;\
unsigned int flags:21;\
struct RClass *c;\
View
2 include/mruby/proc.h
@@ -1,5 +1,5 @@
/*
-** proc.h - Proc class
+** mruby/proc.h - Proc class
**
** See Copyright Notice in mruby.h
*/
View
2 include/mruby/range.h
@@ -1,5 +1,5 @@
/*
-** range.h - Range class
+** mruby/range.h - Range class
**
** See Copyright Notice in mruby.h
*/
View
2 include/mruby/string.h
@@ -1,5 +1,5 @@
/*
-** string.h - String class
+** mruby/string.h - String class
**
** See Copyright Notice in mruby.h
*/
View
2 include/mruby/struct.h
@@ -1,5 +1,5 @@
/*
-** struct.h - Struct class
+** mruby/struct.h - Struct class
**
** See Copyright Notice in mruby.h
*/
View
134 include/mruby/value.h
@@ -7,6 +7,8 @@
#ifndef MRUBY_VALUE_H
#define MRUBY_VALUE_H
+#ifndef MRB_NAN_BOXING
+
enum mrb_vtype {
MRB_TT_FALSE = 0, /* 0 */
MRB_TT_FREE, /* 1 */
@@ -46,14 +48,104 @@ typedef struct mrb_value {
} mrb_value;
#define mrb_type(o) (o).tt
-#define mrb_nil_p(o) ((o).tt == MRB_TT_FALSE && !(o).value.i)
-#define mrb_test(o) ((o).tt != MRB_TT_FALSE)
-#define mrb_fixnum(o) (o).value.i
#define mrb_float(o) (o).value.f
+
+#define MRB_SET_VALUE(o, ttt, attr, v) do {\
+ (o).tt = ttt;\
+ (o).attr = v;\
+} while (0);
+
+static inline mrb_value
+mrb_float_value(mrb_float f)
+{
+ mrb_value v;
+
+ MRB_SET_VALUE(v, MRB_TT_FLOAT, value.f, f);
+ return v;
+}
+#else /* MRB_NAN_BOXING */
+
+#ifdef MRB_USE_FLOAT
+# error ---->> MRB_NAN_BOXING and MRB_USE_FLOAT conflict <<----
+#endif
+
+enum mrb_vtype {
+ MRB_TT_FALSE = 1, /* 1 */
+ MRB_TT_FREE, /* 2 */
+ MRB_TT_TRUE, /* 3 */
+ MRB_TT_FIXNUM, /* 4 */
+ MRB_TT_SYMBOL, /* 5 */
+ MRB_TT_UNDEF, /* 6 */
+ MRB_TT_FLOAT, /* 7 */
+ MRB_TT_OBJECT, /* 8 */
+ MRB_TT_CLASS, /* 9 */
+ MRB_TT_MODULE, /* 10 */
+ MRB_TT_ICLASS, /* 11 */
+ MRB_TT_SCLASS, /* 12 */
+ MRB_TT_PROC, /* 13 */
+ MRB_TT_ARRAY, /* 14 */
+ MRB_TT_HASH, /* 15 */
+ MRB_TT_STRING, /* 16 */
+ MRB_TT_RANGE, /* 17 */
+ MRB_TT_REGEX, /* 18 */
+ MRB_TT_STRUCT, /* 19 */
+ MRB_TT_EXCEPTION, /* 20 */
+ MRB_TT_MATCH, /* 21 */
+ MRB_TT_FILE, /* 22 */
+ MRB_TT_ENV, /* 23 */
+ MRB_TT_DATA, /* 24 */
+ MRB_TT_MAXDEFINE /* 25 */
+};
+
+#ifdef MRB_ENDIAN_BIG
+#define MRB_ENDIAN_LOHI(a,b) a b
+#else
+#define MRB_ENDIAN_LOHI(a,b) b a
+#endif
+
+typedef struct mrb_value {
+ union {
+ mrb_float f;
+ struct {
+ MRB_ENDIAN_LOHI(
+ uint32_t ttt;
+ ,union {
+ void *p;
+ mrb_int i;
+ mrb_sym sym;
+ } value;
+ )
+ };
+ };
+} mrb_value;
+
+#define mrb_tt(o) ((o).ttt & 0xff)
+#define mrb_mktt(tt) (0xfff00000|(tt))
+#define mrb_type(o) ((uint32_t)0xfff00000 < (o).ttt ? mrb_tt(o) : MRB_TT_FLOAT)
+#define mrb_float(o) (o).f
+
+#define MRB_SET_VALUE(o, tt, attr, v) do {\
+ (o).ttt = mrb_mktt(tt);\
+ (o).attr = v;\
+} while (0);
+
+static inline mrb_value
+mrb_float_value(mrb_float f)
+{
+ mrb_value v;
+
+ v.f = f;
+ return v;
+}
+#endif /* MRB_NAN_BOXING */
+
+#define mrb_fixnum(o) (o).value.i
#define mrb_symbol(o) (o).value.sym
#define mrb_object(o) ((struct RBasic *) (o).value.p)
-#define FIXNUM_P(o) ((o).tt == MRB_TT_FIXNUM)
-#define mrb_undef_p(o) ((o).tt == MRB_TT_UNDEF)
+#define FIXNUM_P(o) (mrb_type(o) == MRB_TT_FIXNUM)
+#define mrb_undef_p(o) (mrb_type(o) == MRB_TT_UNDEF)
+#define mrb_nil_p(o) (mrb_type(o) == MRB_TT_FALSE && !(o).value.i)
+#define mrb_test(o) (mrb_type(o) != MRB_TT_FALSE)
#include "mruby/object.h"
@@ -75,23 +167,13 @@ mrb_special_const_p(mrb_value obj)
if (SPECIAL_CONST_P(obj)) return 1;
return 0;
}
-static inline mrb_value
-mrb_fixnum_value(mrb_int i)
-{
- mrb_value v;
-
- v.tt = MRB_TT_FIXNUM;
- v.value.i = i;
- return v;
-}
static inline mrb_value
-mrb_float_value(mrb_float f)
+mrb_fixnum_value(mrb_int i)
{
mrb_value v;
- v.tt = MRB_TT_FLOAT;
- v.value.f = f;
+ MRB_SET_VALUE(v, MRB_TT_FIXNUM, value.i, i);
return v;
}
@@ -100,8 +182,7 @@ mrb_symbol_value(mrb_sym i)
{
mrb_value v;
- v.tt = MRB_TT_SYMBOL;
- v.value.sym = i;
+ MRB_SET_VALUE(v, MRB_TT_SYMBOL, value.sym, i);
return v;
}
@@ -111,8 +192,7 @@ mrb_obj_value(void *p)
mrb_value v;
struct RBasic *b = (struct RBasic*) p;
- v.tt = b->tt;
- v.value.p = p;
+ MRB_SET_VALUE(v, b->tt, value.p, p);
return v;
}
@@ -121,8 +201,7 @@ mrb_false_value(void)
{
mrb_value v;
- v.tt = MRB_TT_FALSE;
- v.value.i = 1;
+ MRB_SET_VALUE(v, MRB_TT_FALSE, value.i, 1);
return v;
}
@@ -131,8 +210,7 @@ mrb_nil_value(void)
{
mrb_value v;
- v.tt = MRB_TT_FALSE;
- v.value.i = 0;
+ MRB_SET_VALUE(v, MRB_TT_FALSE, value.i, 0);
return v;
}
@@ -141,8 +219,7 @@ mrb_true_value(void)
{
mrb_value v;
- v.tt = MRB_TT_TRUE;
- v.value.i = 1;
+ MRB_SET_VALUE(v, MRB_TT_TRUE, value.i, 1);
return v;
}
@@ -151,8 +228,7 @@ mrb_undef_value(void)
{
mrb_value v;
- v.tt = MRB_TT_UNDEF;
- v.value.i = 0;
+ MRB_SET_VALUE(v, MRB_TT_UNDEF, value.i, 0);
return v;
}
View
2 include/mruby/variable.h
@@ -1,5 +1,5 @@
/*
-** variable.h - mruby variables
+** mruby/variable.h - mruby variables
**
** See Copyright Notice in mruby.h
*/
View
6 src/cdump.c
@@ -135,11 +135,11 @@ make_cdump_irep(mrb_state *mrb, int irep_no, FILE *f)
if(irep->plen > 0) {
SOURCE_CODE (" irep->pool = mrb_malloc(mrb, sizeof(mrb_value)*%d);", irep->plen);
for (n=0; n<irep->plen; n++) {
- switch (irep->pool[n].tt) {
+ switch (mrb_type(irep->pool[n])) {
case MRB_TT_FLOAT:
- SOURCE_CODE(" irep->pool[%d] = mrb_float_value(%.16e);", n, irep->pool[n].value.f); break;
+ SOURCE_CODE(" irep->pool[%d] = mrb_float_value(%.16e);", n, mrb_float(irep->pool[n])); break;
case MRB_TT_FIXNUM:
- SOURCE_CODE(" irep->pool[%d] = mrb_fixnum_value(%d);", n, irep->pool[n].value.i); break;
+ SOURCE_CODE(" irep->pool[%d] = mrb_fixnum_value(%d);", n, mrb_fixnum(irep->pool[n])); break;
case MRB_TT_STRING:
str_len = str_format_len(irep->pool[n]) + 1;
if ( str_len > buf_len ) {
View
13 src/class.c
@@ -204,7 +204,7 @@ class_from_sym(mrb_state *mrb, struct RClass *klass, mrb_sym id)
{
mrb_value c = mrb_const_get(mrb, mrb_obj_value(klass), id);
- if (c.tt != MRB_TT_MODULE && c.tt != MRB_TT_CLASS) {
+ if (mrb_type(c) != MRB_TT_MODULE && mrb_type(c) != MRB_TT_CLASS) {
mrb_raise(mrb, E_TYPE_ERROR, "%s is not a class/module", mrb_sym2name(mrb, id));
}
return mrb_class_ptr(c);
@@ -496,7 +496,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, mrb_float*);
if (i < argc) {
- switch (sp->tt) {
+ switch (mrb_type(*sp)) {
case MRB_TT_FLOAT:
*p = mrb_float(*sp);
break;
@@ -526,7 +526,7 @@ mrb_get_args(mrb_state *mrb, const char *format, ...)
p = va_arg(ap, mrb_int*);
if (i < argc) {
- switch (sp->tt) {
+ switch (mrb_type(*sp)) {
case MRB_TT_FIXNUM:
*p = mrb_fixnum(*sp);
break;
@@ -1264,8 +1264,7 @@ undef_method(mrb_state *mrb, struct RClass *c, mrb_sym a)
{
mrb_value m;
- m.tt = MRB_TT_PROC;
- m.value.p = 0;
+ MRB_SET_VALUE(m, MRB_TT_PROC, value.p, 0);
mrb_define_method_vm(mrb, c, a, m);
}
@@ -1317,10 +1316,10 @@ mod_define_method(mrb_state *mrb, mrb_value self)
static mrb_sym
mrb_sym_value(mrb_state *mrb, mrb_value val)
{
- if(val.tt == MRB_TT_STRING) {
+ if(mrb_type(val) == MRB_TT_STRING) {
return mrb_intern_str(mrb, val);
}
- else if(val.tt != MRB_TT_SYMBOL) {
+ else if(mrb_type(val) != MRB_TT_SYMBOL) {
mrb_value obj = mrb_funcall(mrb, val, "inspect", 0);
mrb_raise(mrb, E_TYPE_ERROR, "%s is not a symbol",
mrb_string_value_ptr(mrb, obj));
View
14 src/dump.c
@@ -224,13 +224,13 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep, int type)
uint16_t nlen =0;
int len;
- switch (irep->pool[pool_no].tt) {
+ switch (mrb_type(irep->pool[pool_no])) {
case MRB_TT_FIXNUM:
- len = sprintf( buf, "%d", irep->pool[pool_no].value.i);
+ len = sprintf( buf, "%d", mrb_fixnum(irep->pool[pool_no]));
size += (uint32_t)len;
break;
case MRB_TT_FLOAT:
- len = sprintf( buf, "%.16e", irep->pool[pool_no].value.f);
+ len = sprintf( buf, "%.16e", mrb_float(irep->pool[pool_no]));
size += (uint32_t)len;
break;
case MRB_TT_STRING:
@@ -343,16 +343,16 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, char *buf, int type)
for (pool_no = 0; pool_no < irep->plen; pool_no++) {
uint16_t nlen =0;
- buf += uint8_dump(irep->pool[pool_no].tt, buf, type); /* data type */
+ buf += uint8_dump(mrb_type(irep->pool[pool_no]), buf, type); /* data type */
memset(char_buf, 0, buf_size);
- switch (irep->pool[pool_no].tt) {
+ switch (mrb_type(irep->pool[pool_no])) {
case MRB_TT_FIXNUM:
- sprintf(char_buf, "%d", irep->pool[pool_no].value.i);
+ sprintf(char_buf, "%d", mrb_fixnum(irep->pool[pool_no]));
break;
case MRB_TT_FLOAT:
- sprintf(char_buf, "%.16e", irep->pool[pool_no].value.f);
+ sprintf(char_buf, "%.16e", mrb_float(irep->pool[pool_no]));
break;
case MRB_TT_STRING:
View
2 src/etc.c
@@ -140,7 +140,7 @@ float_id(mrb_float f)
mrb_int
mrb_obj_id(mrb_value obj)
{
- mrb_int tt = obj.tt;
+ mrb_int tt = mrb_type(obj);
#define MakeID2(p,t) (((intptr_t)(p))^(t))
#define MakeID(p) MakeID2(p,tt)
View
2 src/kernel.c
@@ -344,7 +344,7 @@ mrb_obj_clone(mrb_state *mrb, mrb_value self)
if (mrb_special_const_p(self)) {
mrb_raise(mrb, E_TYPE_ERROR, "can't clone %s", mrb_obj_classname(mrb, self));
}
- clone = (struct RObject*)mrb_obj_alloc(mrb, self.tt, mrb_obj_class(mrb, self));
+ clone = (struct RObject*)mrb_obj_alloc(mrb, mrb_type(self), mrb_obj_class(mrb, self));
clone->c = mrb_singleton_class_clone(mrb, self);
init_copy(mrb, mrb_obj_value(clone), self);
View
6 src/object.c
@@ -14,8 +14,8 @@
int
mrb_obj_eq(mrb_state *mrb, mrb_value v1, mrb_value v2)
{
- if (v1.tt != v2.tt) return FALSE;
- switch (v1.tt) {
+ if (mrb_type(v1) != mrb_type(v2)) return FALSE;
+ switch (mrb_type(v1)) {
case MRB_TT_TRUE:
return 1;
@@ -26,7 +26,7 @@ mrb_obj_eq(mrb_state *mrb, mrb_value v1, mrb_value v2)
return (v1.value.sym == v2.value.sym);
case MRB_TT_FLOAT:
- return (v1.value.f == v2.value.f);
+ return (mrb_float(v1) == mrb_float(v2));
default:
return (v1.value.p == v2.value.p);
View
2 src/range.c
@@ -392,7 +392,7 @@ range_eql(mrb_state *mrb, mrb_value range)
return mrb_false_value();
r = mrb_range_ptr(range);
- if (obj.tt != MRB_TT_RANGE) return mrb_false_value();
+ if (mrb_type(obj) != MRB_TT_RANGE) return mrb_false_value();
o = mrb_range_ptr(obj);
if (!mrb_eql(mrb, r->edges->beg, o->edges->beg))
return mrb_false_value();
View
2 src/variable.c
@@ -677,7 +677,7 @@ mrb_const_defined(mrb_state *mrb, mrb_value mod, mrb_sym sym)
static void
mod_const_check(mrb_state *mrb, mrb_value mod)
{
- switch (mod.tt) {
+ switch (mrb_type(mod)) {
case MRB_TT_CLASS:
case MRB_TT_MODULE:
break;
View
94 src/vm.c
@@ -78,7 +78,15 @@ stack_extend(mrb_state *mrb, int room, int keep)
envadjust(mrb, oldbase, mrb->stbase);
}
if (room > keep) {
+#ifndef MRB_NAN_BOXING
memset(mrb->stack+keep, 0, sizeof(mrb_value) * (room-keep));
+#else
+ int i;
+
+ for (i=keep; i<room; i++) {
+ mrb->stack[i] = mrb_nil_value();
+ }
+#endif
}
}
@@ -380,40 +388,12 @@ argnum_error(mrb_state *mrb, int num)
mrb->exc = (struct RObject*)mrb_object(exc);
}
-#define SET_TRUE_VALUE(r) {\
- (r).tt = MRB_TT_TRUE;\
- (r).value.i = 1;\
-}
-
-#define SET_FALSE_VALUE(r) {\
- (r).tt = MRB_TT_FALSE;\
- (r).value.i = 1;\
-}
-
-#define SET_NIL_VALUE(r) { \
- (r).tt = MRB_TT_FALSE;\
- (r).value.p = 0;\
-}
-
-#define SET_INT_VALUE(r,n) {\
- (r).tt = MRB_TT_FIXNUM;\
- (r).value.i = (n);\
-}
-
-#define SET_FLOAT_VALUE(r,v) {\
- (r).tt = MRB_TT_FLOAT;\
- (r).value.f = (v);\
-}
-
-#define SET_SYM_VALUE(r,v) {\
- (r).tt = MRB_TT_SYMBOL;\
- (r).value.sym = (v);\
-}
-
-#define SET_OBJ_VALUE(r,v) {\
- (r).tt = (((struct RObject*)(v))->tt);\
- (r).value.p = (void*)(v);\
-}
+#define SET_TRUE_VALUE(r) MRB_SET_VALUE(r, MRB_TT_TRUE, value.i, 1)
+#define SET_FALSE_VALUE(r) MRB_SET_VALUE(r, MRB_TT_FALSE, value.i, 1)
+#define SET_NIL_VALUE(r) MRB_SET_VALUE(r, MRB_TT_FALSE, value.i, 0)
+#define SET_INT_VALUE(r,n) MRB_SET_VALUE(r, MRB_TT_FIXNUM, value.i, (n))
+#define SET_SYM_VALUE(r,v) MRB_SET_VALUE(r, MRB_TT_SYMBOL, value.sym, (v))
+#define SET_OBJ_VALUE(r,v) MRB_SET_VALUE(r, (((struct RObject*)(v))->tt), value.p, (v))
#ifdef __GNUC__
#define DIRECT_THREADED
@@ -496,6 +476,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
mrb->ci->proc = proc;
mrb->ci->nregs = irep->nregs + 2;
regs = mrb->stack;
+ regs[0] = self;
INIT_DISPATCH {
CASE(OP_NOP) {
@@ -978,7 +959,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
struct RArray *rest;
int len = 0;
- if (stack[m1].tt == MRB_TT_ARRAY) {
+ if (mrb_type(stack[m1]) == MRB_TT_ARRAY) {
struct RArray *ary = mrb_ary_ptr(stack[m1]);
pp = ary->ptr;
@@ -1032,7 +1013,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
}
}
}
- else if (len > 1 && argc == 1 && argv[0].tt == MRB_TT_ARRAY) {
+ else if (len > 1 && argc == 1 && mrb_type(argv[0]) == MRB_TT_ARRAY) {
argc = mrb_ary_ptr(argv[0])->len;
argv = mrb_ary_ptr(argv[0])->ptr;
}
@@ -1248,9 +1229,16 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
NEXT;
}
+#define attr_i value.i
+#ifdef MRB_NAN_BOXING
+#define attr_f f
+#else
+#define attr_f value.f
+#endif
+
#define TYPES2(a,b) (((((int)(a))<<8)|((int)(b)))&0xffff)
#define OP_MATH_BODY(op,v1,v2) do {\
- regs[a].value.v1 = regs[a].value.v1 op regs[a+1].value.v2;\
+ regs[a].v1 = regs[a].v1 op regs[a+1].v2;\
} while(0)
#define OP_MATH(op,iop,s) do {\
@@ -1262,16 +1250,16 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
break;\
case TYPES2(MRB_TT_FIXNUM,MRB_TT_FLOAT):\
{\
- mrb_int x = regs[a].value.i;\
- mrb_float y = regs[a+1].value.f;\
- SET_FLOAT_VALUE(regs[a], (mrb_float)x op y);\
+ mrb_int x = mrb_fixnum(regs[a]);\
+ mrb_float y = mrb_float(regs[a+1]);\
+ regs[a] = mrb_float_value((mrb_float)x op y);\
}\
break;\
case TYPES2(MRB_TT_FLOAT,MRB_TT_FIXNUM):\
- OP_MATH_BODY(op,f,i);\
+ OP_MATH_BODY(op,attr_f,attr_i);\
break;\
case TYPES2(MRB_TT_FLOAT,MRB_TT_FLOAT):\
- OP_MATH_BODY(op,f,f);\
+ OP_MATH_BODY(op,attr_f,attr_f);\
break;\
s\
default:\
@@ -1316,10 +1304,10 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
/* need to check if + is overridden */
switch (mrb_type(regs[a])) {
case MRB_TT_FIXNUM:
- regs[a].value.i += GETARG_C(i);
+ regs[a].attr_i += GETARG_C(i);
break;
case MRB_TT_FLOAT:
- regs[a].value.f += GETARG_C(i);
+ regs[a].attr_f += GETARG_C(i);
break;
default:
SET_NIL_VALUE(regs[a+2]);
@@ -1337,10 +1325,10 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
/* need to check if + is overridden */
switch (mrb_type(regs[a])) {
case MRB_TT_FIXNUM:
- regs[a].value.i -= GETARG_C(i);
+ regs[a].attr_i -= GETARG_C(i);
break;
case MRB_TT_FLOAT:
- regs[a].value.f -= GETARG_C(i);
+ regs[a].attr_f -= GETARG_C(i);
break;
default:
SET_NIL_VALUE(regs[a+2]);
@@ -1352,7 +1340,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
}
#define OP_CMP_BODY(op,v1,v2) do {\
- if (regs[a].value.v1 op regs[a+1].value.v2) {\
+ if (regs[a].v1 op regs[a+1].v2) {\
SET_TRUE_VALUE(regs[a]);\
}\
else {\
@@ -1365,16 +1353,16 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
/* 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):\
- OP_CMP_BODY(op,i,i); \
+ OP_CMP_BODY(op,attr_i,attr_i);\
break;\
case TYPES2(MRB_TT_FIXNUM,MRB_TT_FLOAT):\
- OP_CMP_BODY(op,i,f);\
+ OP_CMP_BODY(op,attr_i,attr_f);\
break;\
case TYPES2(MRB_TT_FLOAT,MRB_TT_FIXNUM):\
- OP_CMP_BODY(op,f,i);\
+ OP_CMP_BODY(op,attr_f,attr_i);\
break;\
case TYPES2(MRB_TT_FLOAT,MRB_TT_FLOAT):\
- OP_CMP_BODY(op,f,f);\
+ OP_CMP_BODY(op,attr_f,attr_f);\
break;\
default:\
SET_NIL_VALUE(regs[a+2]);\
@@ -1447,7 +1435,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
int c = GETARG_C(i);
mrb_value v = regs[GETARG_B(i)];
- if (v.tt != MRB_TT_ARRAY) {
+ if (mrb_type(v) != MRB_TT_ARRAY) {
if (c == 0) {
regs[GETARG_A(i)] = v;
}
@@ -1474,7 +1462,7 @@ mrb_run(mrb_state *mrb, struct RProc *proc, mrb_value self)
int pre = GETARG_B(i);
int post = GETARG_C(i);
- if (v.tt != MRB_TT_ARRAY) {
+ if (mrb_type(v) != MRB_TT_ARRAY) {
regs[a++] = mrb_ary_new_capa(mrb, 0);
while (post--) {
SET_NIL_VALUE(regs[a]);

0 comments on commit 7d02df3

Please sign in to comment.