NaN boxing

This commit is contained in:
Yukihiro Matsumoto
2012-08-14 13:16:34 +09:00
parent e74600c919
commit 7d02df3016
28 changed files with 197 additions and 123 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
/*
** array.h - Array class
** mruby/array.h - Array class
**
** See Copyright Notice in mruby.h
*/
+1 -1
View File
@@ -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
*/
+1 -1
View File
@@ -1,5 +1,5 @@
/*
** class.h - Class class
** mruby/class.h - Class class
**
** See Copyright Notice in mruby.h
*/
+1 -1
View File
@@ -1,5 +1,5 @@
/*
** compile.h - mruby parser
** mruby/compile.h - mruby parser
**
** See Copyright Notice in mruby.h
*/
+1 -1
View File
@@ -1,5 +1,5 @@
/*
** data.h - Data class
** mruby/data.h - Data class
**
** See Copyright Notice in mruby.h
*/
+1 -1
View File
@@ -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
*/
+1 -1
View File
@@ -1,5 +1,5 @@
/*
** hash.h - Hash class
** mruby/hash.h - Hash class
**
** See Copyright Notice in mruby.h
*/
+1 -1
View File
@@ -1,5 +1,5 @@
/*
** irep.h - mrb_irep structure
** mruby/irep.h - mrb_irep structure
**
** See Copyright Notice in mruby.h
*/
+1 -1
View File
@@ -1,5 +1,5 @@
/*
** ritehash.c - Rite Hash for mruby
** mruby/khash.c - Hash for mruby
**
** See Copyright Notice in mruby.h
*/
+1 -1
View File
@@ -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
*/
+1 -1
View File
@@ -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;\
+1 -1
View File
@@ -1,5 +1,5 @@
/*
** proc.h - Proc class
** mruby/proc.h - Proc class
**
** See Copyright Notice in mruby.h
*/
+1 -1
View File
@@ -1,5 +1,5 @@
/*
** range.h - Range class
** mruby/range.h - Range class
**
** See Copyright Notice in mruby.h
*/
+1 -1
View File
@@ -1,5 +1,5 @@
/*
** string.h - String class
** mruby/string.h - String class
**
** See Copyright Notice in mruby.h
*/
+1 -1
View File
@@ -1,5 +1,5 @@
/*
** struct.h - Struct class
** mruby/struct.h - Struct class
**
** See Copyright Notice in mruby.h
*/
+105 -29
View File
@@ -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_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;
}
+1 -1
View File
@@ -1,5 +1,5 @@
/*
** variable.h - mruby variables
** mruby/variable.h - mruby variables
**
** See Copyright Notice in mruby.h
*/