boxing_nan.h: allow `MRB_INT64` with `MRB_NAN_BOXING`.

Integers out of 32 bit range will be allocated in the heap.
parent 85fcd2dc
......@@ -3,8 +3,6 @@ bits = [64, 32]
ints = [64, 32]
boxings.product(bits, ints) do |boxing, bit, int|
next if boxing == "nan" && int == 64
MRuby::Build.new("boxing-#{boxing}-m#{bit}-i#{int}") do |conf|
conf.toolchain :gcc
conf.gembox 'default'
......
......@@ -15,12 +15,6 @@
# error ---->> MRB_NAN_BOXING and MRB_NO_FLOAT conflict <<----
#endif
#ifdef MRB_INT64
# error ---->> MRB_NAN_BOXING and MRB_INT64 conflict <<----
#endif
#define MRB_FIXNUM_SHIFT 0
#define MRB_SYMBOL_SHIFT 0
#define MRB_FIXNUM_MIN INT32_MIN
#define MRB_FIXNUM_MAX INT32_MAX
......@@ -74,18 +68,19 @@ mrb_nan_boxing_value_float(mrb_value v)
r.u = float_uint_union.u + 0x8004000000000000; \
} while(0)
#define NANBOX_SET_VALUE(o, tt, v) do { \
(o).u = ((uint64_t)tt<<48) | (uint64_t)(v); \
} while (0)
#define mrb_float_p(o) (((uint64_t)(o.u)&0xfffc000000000000) != 0)
struct RInteger {
MRB_OBJECT_HEADER;
mrb_int i;
};
MRB_INLINE enum mrb_vtype
mrb_type(mrb_value o)
{
if (mrb_float_p(o)) return MRB_TT_FLOAT;
uint64_t u = o.u;
int64_t u = o.u;
switch ((enum mrb_nanbox_tt_inline)((u >> 48) & 3)) {
case MRB_NANBOX_TT_POINTER: {
if (u == 0) return MRB_TT_FALSE;
......@@ -106,18 +101,51 @@ mrb_type(mrb_value o)
#define NANBOX_SET_MISC_VALUE(r,t,i) NANBOX_SET_VALUE(r, MRB_NANBOX_TT_MISC, ((t)<<8) | i)
#define mrb_float(o) mrb_nan_boxing_value_float(o)
#define mrb_float(o) mrb_nan_boxing_value_float(o)
#ifdef MRB_INT64
/*
#ifdef MRB_32BIT
#define mrb_fixnum(o) ((mrb_int)((intptr_t)0xffffffffffff&((o).u))|(((o).u & 0x800000000000)?0xffff000000000000:0))
#else
#define mrb_fixnum(o) ((mrb_int)(int32_t)((o).u))
#endif
*/
#define mrb_fixnum(o) ((mrb_int)(int32_t)((o).u))
static inline mrb_int
mrb_nan_boxing_value_int(mrb_value v)
{
uint64_t u = v.u;
if (((u>>48)&3)==MRB_NANBOX_TT_POINTER) {
struct RInteger *p = (struct RInteger*)(uintptr_t)u;
return p->i;
}
return mrb_fixnum(v);
}
#define mrb_integer(o) mrb_nan_boxing_value_int(o)
#else
#define mrb_fixnum(o) ((mrb_int)(((uintptr_t)0xffffffff)&((o).u)))
#define mrb_integer(o) mrb_fixnum(o)
#endif
#define mrb_symbol(o) ((mrb_sym)((uintptr_t)0xffffffff)&((o).u))
#define mrb_ptr(o) ((void*)(uintptr_t)(o).u)
#define mrb_cptr(o) ((void*)(uintptr_t)(0xfffffffffffe&(o).u))
#define NANBOX_SET_VALUE(o, tt, v) do { \
(o).u = ((uint64_t)tt<<48) | ((uint64_t)(v)); \
} while (0)
#define SET_NIL_VALUE(r) NANBOX_SET_MISC_VALUE(r, MRB_TT_FALSE, 0)
#define SET_FALSE_VALUE(r) NANBOX_SET_MISC_VALUE(r, MRB_TT_FALSE, 1)
#define SET_TRUE_VALUE(r) NANBOX_SET_MISC_VALUE(r, MRB_TT_TRUE, 1)
#define SET_BOOL_VALUE(r,b) NANBOX_SET_MISC_VALUE(r, (b) ? MRB_TT_TRUE : MRB_TT_FALSE, 1)
#define SET_INT_VALUE(mrb,r,n) SET_FIXNUM_VALUE(r,n)
#ifdef MRB_INT64
MRB_API mrb_value mrb_boxing_int_value(struct mrb_state*, mrb_int);
#define SET_INT_VALUE(mrb, r, n) ((r) = mrb_boxing_int_value(mrb, n))
#else
#define SET_INT_VALUE(mrb, r, n) SET_FIXNUM_VALUE(r, n)
#endif
#define SET_FIXNUM_VALUE(r,n) NANBOX_SET_VALUE(r, MRB_NANBOX_TT_INTEGER, (uint32_t)(n))
#define SET_SYM_VALUE(r,v) NANBOX_SET_VALUE(r, MRB_NANBOX_TT_SYMBOL, (uint32_t)(v))
#define SET_OBJ_VALUE(r,v) do {(r).u = (uint64_t)(uintptr_t)v;} while (0)
......@@ -126,5 +154,6 @@ mrb_type(mrb_value o)
#define mrb_nil_p(o) (mrb_type(o) == MRB_TT_FALSE && ((o).u & 3) == 0)
#define mrb_false_p(o) (mrb_type(o) == MRB_TT_FALSE && ((o).u & 2) == 0)
#define mrb_fixnum_p(o) (!mrb_float_p(o) && ((o.u>>48)&3)==MRB_NANBOX_TT_INTEGER)
#endif /* MRUBY_BOXING_NAN_H */
......@@ -144,7 +144,7 @@ MRB_API mrb_value mrb_word_boxing_cptr_value(struct mrb_state*, void*);
#ifndef MRB_NO_FLOAT
MRB_API mrb_value mrb_word_boxing_float_value(struct mrb_state*, mrb_float);
#endif
MRB_API mrb_value mrb_word_boxing_int_value(struct mrb_state*, mrb_int);
MRB_API mrb_value mrb_boxing_int_value(struct mrb_state*, mrb_int);
#define mrb_immediate_p(o) ((o).w & WORDBOX_IMMEDIATE_MASK || (o).w == MRB_Qnil)
......@@ -210,7 +210,7 @@ mrb_integer_func(mrb_value o) {
#define SET_FALSE_VALUE(r) ((r).w = MRB_Qfalse)
#define SET_TRUE_VALUE(r) ((r).w = MRB_Qtrue)
#define SET_BOOL_VALUE(r,b) ((b) ? SET_TRUE_VALUE(r) : SET_FALSE_VALUE(r))
#define SET_INT_VALUE(mrb,r,n) ((r) = mrb_word_boxing_int_value(mrb, n))
#define SET_INT_VALUE(mrb,r,n) ((r) = mrb_boxing_int_value(mrb, n))
#define SET_FIXNUM_VALUE(r,n) WORDBOX_SET_SHIFT_VALUE(r, FIXNUM, n)
#define SET_SYM_VALUE(r,n) WORDBOX_SET_SHIFT_VALUE(r, SYMBOL, n)
#define SET_OBJ_VALUE(r,v) ((r).w = (uintptr_t)(v))
......
......@@ -145,13 +145,7 @@ mrb_obj_id(mrb_value obj)
}
}
#if defined(MRB_NAN_BOXING) && defined(MRB_64BIT)
#define mrb_xxx_boxing_cptr_value mrb_nan_boxing_cptr_value
#endif
#ifdef MRB_WORD_BOXING
#define mrb_xxx_boxing_cptr_value mrb_word_boxing_cptr_value
#ifndef MRB_NO_FLOAT
MRB_API mrb_value
mrb_word_boxing_float_value(mrb_state *mrb, mrb_float f)
......@@ -190,23 +184,7 @@ mrb_word_boxing_value_float(mrb_value v)
#endif /* MRB_NO_FLOAT */
MRB_API mrb_value
mrb_word_boxing_int_value(mrb_state *mrb, mrb_int n)
{
if (FIXABLE(n)) return mrb_fixnum_value(n);
else {
union mrb_value_ v;
v.p = mrb_obj_alloc(mrb, MRB_TT_INTEGER, mrb->integer_class);
v.ip->i = n;
MRB_SET_FROZEN_FLAG(v.ip);
return v.value;
}
}
#endif /* MRB_WORD_BOXING */
#if defined(MRB_WORD_BOXING) || (defined(MRB_NAN_BOXING) && defined(MRB_64BIT))
MRB_API mrb_value
mrb_xxx_boxing_cptr_value(mrb_state *mrb, void *p)
mrb_word_boxing_cptr_value(mrb_state *mrb, void *p)
{
mrb_value v;
struct RCptr *cptr = MRB_OBJ_ALLOC(mrb, MRB_TT_CPTR, mrb->object_class);
......@@ -215,6 +193,24 @@ mrb_xxx_boxing_cptr_value(mrb_state *mrb, void *p)
cptr->p = p;
return v;
}
#endif /* MRB_WORD_BOXING */
#if defined(MRB_WORD_BOXING) || (defined(MRB_NAN_BOXING) && defined(MRB_INT64))
MRB_API mrb_value
mrb_boxing_int_value(mrb_state *mrb, mrb_int n)
{
if (FIXABLE(n)) return mrb_fixnum_value(n);
else {
mrb_value v;
struct RInteger *p;
p = (struct RInteger*)mrb_obj_alloc(mrb, MRB_TT_INTEGER, mrb->integer_class);
p->i = n;
MRB_SET_FROZEN_FLAG((struct RBasic*)p);
SET_OBJ_VALUE(v, p);
return v;
}
}
#endif
#if defined _MSC_VER && _MSC_VER < 1900
......
......@@ -97,7 +97,7 @@ mrb_equal_m(mrb_state *mrb, mrb_value self)
mrb_value
mrb_obj_id_m(mrb_state *mrb, mrb_value self)
{
return mrb_int_value(mrb, mrb_obj_id(self));
return mrb_fixnum_value(mrb_obj_id(self));
}
static int
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment