w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

boxing_nan.h
Go to the documentation of this file.
1 /**
2 ** @file mruby/boxing_nan.h - nan boxing mrb_value definition
3 **
4 ** See Copyright Notice in mruby.h
5 */
6 
7 #ifndef MRUBY_BOXING_NAN_H
8 #define MRUBY_BOXING_NAN_H
9 
10 #ifdef MRB_USE_FLOAT32
11 # error ---->> MRB_NAN_BOXING and MRB_USE_FLOAT32 conflict <<----
12 #endif
13 
14 #ifdef MRB_NO_FLOAT
15 # error ---->> MRB_NAN_BOXING and MRB_NO_FLOAT conflict <<----
16 #endif
17 
18 #ifdef MRB_INT64
19 # error ---->> MRB_NAN_BOXING and MRB_INT64 conflict <<----
20 #endif
21 
22 #define MRB_FIXNUM_SHIFT 0
23 #define MRB_SYMBOL_SHIFT 0
24 #define MRB_FIXNUM_MIN INT32_MIN
25 #define MRB_FIXNUM_MAX INT32_MAX
26 
27 /* value representation by nan-boxing:
28  * float : FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF FFFFFFFFFFFFFFFF
29  * object: 111111111111TTTT TTPPPPPPPPPPPPPP PPPPPPPPPPPPPPPP PPPPPPPPPPPPPPPP
30  * int : 1111111111110001 0000000000000000 IIIIIIIIIIIIIIII IIIIIIIIIIIIIIII
31  * sym : 1111111111110001 0100000000000000 SSSSSSSSSSSSSSSS SSSSSSSSSSSSSSSS
32  * In order to get enough bit size to save TT, all pointers are shifted 2 bits
33  * in the right direction. Also, TTTTTT is the mrb_vtype + 1;
34  */
35 typedef struct mrb_value {
38 
39 union mrb_value_ {
42 #ifdef MRB_64BIT
43  void *p;
44 # define BOXNAN_IMMEDIATE_VALUE uint32_t i
45 #else
46 # define BOXNAN_IMMEDIATE_VALUE union { uint32_t i; void *p; }
47 #endif
48  struct {
50  uint32_t ttt;
52  )
53  };
55 };
56 
57 mrb_static_assert1(sizeof(mrb_value) == sizeof(union mrb_value_));
58 
59 static inline union mrb_value_
61 {
62  union mrb_value_ x;
63  x.value = v;
64  return x;
65 }
66 
67 #define mrb_tt(o) ((enum mrb_vtype)((mrb_val_union(o).ttt & 0xfc000)>>14)-1)
68 #define mrb_type(o) (enum mrb_vtype)((uint32_t)0xfff00000 < mrb_val_union(o).ttt ? mrb_tt(o) : MRB_TT_FLOAT)
69 #define mrb_float(o) mrb_val_union(o).f
70 #define mrb_fixnum(o) ((mrb_int)mrb_val_union(o).i)
71 #define mrb_integer(o) mrb_fixnum(o)
72 #define mrb_symbol(o) ((mrb_sym)mrb_val_union(o).i)
73 
74 #ifdef MRB_64BIT
75 #define mrb_ptr(o) ((void*)((((uintptr_t)0x3fffffffffff)&((uintptr_t)(mrb_val_union(o).p)))<<2))
76 #define mrb_cptr(o) (((struct RCptr*)mrb_ptr(o))->p)
77 #define BOXNAN_SHIFT_LONG_POINTER(v) (((uintptr_t)(v)>>34)&0x3fff)
78 #else
79 #define mrb_ptr(o) ((void*)mrb_val_union(o).i)
80 #define mrb_cptr(o) mrb_ptr(o)
81 #define BOXNAN_SHIFT_LONG_POINTER(v) 0
82 #endif
83 
84 #define BOXNAN_SET_VALUE(o, tt, attr, v) do { \
85  union mrb_value_ mrb_value_union_variable; \
86  mrb_value_union_variable.attr = (v);\
87  mrb_value_union_variable.ttt = 0xfff00000 | (((tt)+1)<<14);\
88  o = mrb_value_union_variable.value;\
89 } while (0)
90 
91 #ifdef MRB_64BIT
92 #define BOXNAN_SET_OBJ_VALUE(o, tt, v) do {\
93  union mrb_value_ mrb_value_union_variable;\
94  mrb_value_union_variable.p = (void*)((uintptr_t)(v)>>2);\
95  mrb_value_union_variable.ttt = (0xfff00000|(((tt)+1)<<14)|BOXNAN_SHIFT_LONG_POINTER(v));\
96  o = mrb_value_union_variable.value;\
97 } while (0)
98 #else
99 #define BOXNAN_SET_OBJ_VALUE(o, tt, v) BOXNAN_SET_VALUE(o, tt, i, (uint32_t)v)
100 #endif
101 
102 #define SET_FLOAT_VALUE(mrb,r,v) do { \
103  union mrb_value_ mrb_value_union_variable; \
104  if ((v) != (v)) { /* NaN */ \
105  mrb_value_union_variable.ttt = 0x7ff80000; \
106  mrb_value_union_variable.i = 0; \
107  } \
108  else { \
109  mrb_value_union_variable.f = (v); \
110  } \
111  r = mrb_value_union_variable.value; \
112 } while(0)
113 
114 #define SET_NIL_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE, i, 0)
115 #define SET_FALSE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_FALSE, i, 1)
116 #define SET_TRUE_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_TRUE, i, 1)
117 #define SET_BOOL_VALUE(r,b) BOXNAN_SET_VALUE(r, b ? MRB_TT_TRUE : MRB_TT_FALSE, i, 1)
118 #define SET_INT_VALUE(mrb, r,n) BOXNAN_SET_VALUE(r, MRB_TT_INTEGER, i, (uint32_t)(n))
119 #define SET_FIXNUM_VALUE(r,n) BOXNAN_SET_VALUE(r, MRB_TT_INTEGER, i, (uint32_t)(n))
120 #define SET_SYM_VALUE(r,v) BOXNAN_SET_VALUE(r, MRB_TT_SYMBOL, i, (uint32_t)(v))
121 #define SET_OBJ_VALUE(r,v) BOXNAN_SET_OBJ_VALUE(r, (((struct RObject*)(v))->tt), (v))
122 #ifdef MRB_64BIT
123 MRB_API mrb_value mrb_nan_boxing_cptr_value(struct mrb_state*, void*);
124 #define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_nan_boxing_cptr_value(mrb, v))
125 #else
126 #define SET_CPTR_VALUE(mrb,r,v) BOXNAN_SET_VALUE(r, MRB_TT_CPTR, p, v)
127 #endif
128 #define SET_UNDEF_VALUE(r) BOXNAN_SET_VALUE(r, MRB_TT_UNDEF, i, 0)
129 
130 #endif /* MRUBY_BOXING_NAN_H */
#define BOXNAN_IMMEDIATE_VALUE
Definition: boxing_nan.h:46
struct mrb_value mrb_value
mrb_static_assert1(sizeof(mrb_value)==sizeof(union mrb_value_))
static union mrb_value_ mrb_val_union(mrb_value v)
Definition: boxing_nan.h:60
int v
Definition: dviconv.c:10
unsigned int uint32_t
Definition: stdint.h:80
unsigned __int64 uint64_t
Definition: stdint.h:90
float x
Definition: cordic.py:15
#define MRB_API
Definition: common.h:73
uint64_t u
Definition: boxing_nan.h:36
mrb_float f
Definition: boxing_nan.h:40
void * p
Definition: boxing_word.h:81
mrb_value value
Definition: boxing_nan.h:54
uint64_t u
Definition: boxing_nan.h:41
double mrb_float
Definition: value.h:85
#define MRB_ENDIAN_LOHI(a, b)
Definition: value.h:77