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_word.h
Go to the documentation of this file.
1 /**
2 ** @file mruby/boxing_word.h - word boxing mrb_value definition
3 **
4 ** See Copyright Notice in mruby.h
5 */
6 
7 #ifndef MRUBY_BOXING_WORD_H
8 #define MRUBY_BOXING_WORD_H
9 
10 #ifndef MRB_NO_FLOAT
11 struct RFloat {
14 };
15 #endif
16 
17 struct RInteger {
20 };
21 
23  MRB_Qnil = 0,
25  MRB_Qtrue = 12,
26  MRB_Qundef = 20,
27 };
28 
29 #if defined(MRB_64BIT) && defined(MRB_INT32)
30 #define MRB_FIXNUM_SHIFT 0
31 #else
32 #define MRB_FIXNUM_SHIFT BOXWORD_FIXNUM_SHIFT
33 #endif
34 #define MRB_SYMBOL_SHIFT BOXWORD_SYMBOL_SHIFT
35 
36 #if defined(MRB_64BIT) && defined(MRB_INT64)
37 # define MRB_FIXNUM_MIN (INT64_MIN>>MRB_FIXNUM_SHIFT)
38 # define MRB_FIXNUM_MAX (INT64_MAX>>MRB_FIXNUM_SHIFT)
39 #else
40 # define MRB_FIXNUM_MIN (INT32_MIN>>MRB_FIXNUM_SHIFT)
41 # define MRB_FIXNUM_MAX (INT32_MAX>>MRB_FIXNUM_SHIFT)
42 #endif
43 
44 #define BOXWORD_FIXNUM_BIT_POS 1
45 #define BOXWORD_SYMBOL_BIT_POS 2
46 #define BOXWORD_FIXNUM_SHIFT BOXWORD_FIXNUM_BIT_POS
47 #ifdef MRB_64BIT
48 #define BOXWORD_SYMBOL_SHIFT 0
49 #else
50 #define BOXWORD_SYMBOL_SHIFT BOXWORD_SYMBOL_BIT_POS
51 #endif
52 #define BOXWORD_FIXNUM_FLAG (1 << (BOXWORD_FIXNUM_BIT_POS - 1))
53 #define BOXWORD_SYMBOL_FLAG (1 << (BOXWORD_SYMBOL_BIT_POS - 1))
54 #define BOXWORD_FIXNUM_MASK ((1 << BOXWORD_FIXNUM_BIT_POS) - 1)
55 #define BOXWORD_SYMBOL_MASK ((1 << BOXWORD_SYMBOL_BIT_POS) - 1)
56 #define BOXWORD_IMMEDIATE_MASK 0x07
57 
58 #define BOXWORD_SET_SHIFT_VALUE(o,n,v) \
59  ((o).w = (((uintptr_t)(v)) << BOXWORD_##n##_SHIFT) | BOXWORD_##n##_FLAG)
60 #define BOXWORD_SHIFT_VALUE_P(o,n) \
61  (((o).w & BOXWORD_##n##_MASK) == BOXWORD_##n##_FLAG)
62 #define BOXWORD_OBJ_TYPE_P(o,n) \
63  (!mrb_immediate_p(o) && mrb_val_union(o).bp->tt == MRB_TT_##n)
64 
65 /*
66  * mrb_value representation:
67  *
68  * nil : ...0000 0000 (all bits are 0)
69  * false : ...0000 0100 (mrb_fixnum(v) != 0)
70  * true : ...0000 1100
71  * undef : ...0001 0100
72  * fixnum: ...IIII III1
73  * symbol: ...SSSS SS10 (use only upper 32-bit as symbol value on 64-bit CPU)
74  * object: ...PPPP P000 (any bits are 1)
75  */
76 typedef struct mrb_value {
79 
80 union mrb_value_ {
81  void *p;
82 #ifdef MRB_64BIT
83  /* use struct to avoid bit shift. */
84  struct {
86  mrb_sym sym;
87  ,uint32_t sym_flag;
88  )
89  };
90 #endif
91  struct RBasic *bp;
92 #ifndef MRB_NO_FLOAT
93  struct RFloat *fp;
94 #endif
95  struct RInteger *ip;
96  struct RCptr *vp;
99 };
100 
101 mrb_static_assert1(sizeof(mrb_value) == sizeof(union mrb_value_));
102 
103 static inline union mrb_value_
105 {
106  union mrb_value_ x;
107  x.value = v;
108  return x;
109 }
110 
112 #ifndef MRB_NO_FLOAT
114 #endif
116 
117 #define mrb_immediate_p(o) ((o).w & BOXWORD_IMMEDIATE_MASK || (o).w == MRB_Qnil)
118 
119 #define mrb_ptr(o) mrb_val_union(o).p
120 #define mrb_cptr(o) mrb_val_union(o).vp->p
121 #ifndef MRB_NO_FLOAT
122 #define mrb_float(o) mrb_val_union(o).fp->f
123 #endif
124 #define mrb_fixnum(o) (mrb_int)(((intptr_t)(o).w) >> BOXWORD_FIXNUM_SHIFT)
127  if (mrb_immediate_p(o)) return mrb_fixnum(o);
128  return mrb_val_union(o).ip->i;
129 }
130 #define mrb_integer(o) mrb_integer_func(o)
131 #ifdef MRB_64BIT
132 #define mrb_symbol(o) mrb_val_union(o).sym
133 #else
134 #define mrb_symbol(o) (mrb_sym)(((o).w) >> BOXWORD_SYMBOL_SHIFT)
135 #endif
136 #define mrb_bool(o) (((o).w & ~(uintptr_t)MRB_Qfalse) != 0)
137 
138 #define mrb_fixnum_p(o) BOXWORD_SHIFT_VALUE_P(o, FIXNUM)
139 #define mrb_integer_p(o) (BOXWORD_SHIFT_VALUE_P(o, FIXNUM)||BOXWORD_OBJ_TYPE_P(o, INTEGER))
140 #ifdef MRB_64BIT
141 #define mrb_symbol_p(o) (mrb_val_union(o).sym_flag == BOXWORD_SYMBOL_FLAG)
142 #else
143 #define mrb_symbol_p(o) BOXWORD_SHIFT_VALUE_P(o, SYMBOL)
144 #endif
145 #define mrb_undef_p(o) ((o).w == MRB_Qundef)
146 #define mrb_nil_p(o) ((o).w == MRB_Qnil)
147 #define mrb_false_p(o) ((o).w == MRB_Qfalse)
148 #define mrb_true_p(o) ((o).w == MRB_Qtrue)
149 #ifndef MRB_NO_FLOAT
150 #define mrb_float_p(o) BOXWORD_OBJ_TYPE_P(o, FLOAT)
151 #endif
152 #define mrb_array_p(o) BOXWORD_OBJ_TYPE_P(o, ARRAY)
153 #define mrb_string_p(o) BOXWORD_OBJ_TYPE_P(o, STRING)
154 #define mrb_hash_p(o) BOXWORD_OBJ_TYPE_P(o, HASH)
155 #define mrb_cptr_p(o) BOXWORD_OBJ_TYPE_P(o, CPTR)
156 #define mrb_exception_p(o) BOXWORD_OBJ_TYPE_P(o, EXCEPTION)
157 #define mrb_free_p(o) BOXWORD_OBJ_TYPE_P(o, FREE)
158 #define mrb_object_p(o) BOXWORD_OBJ_TYPE_P(o, OBJECT)
159 #define mrb_class_p(o) BOXWORD_OBJ_TYPE_P(o, CLASS)
160 #define mrb_module_p(o) BOXWORD_OBJ_TYPE_P(o, MODULE)
161 #define mrb_iclass_p(o) BOXWORD_OBJ_TYPE_P(o, ICLASS)
162 #define mrb_sclass_p(o) BOXWORD_OBJ_TYPE_P(o, SCLASS)
163 #define mrb_proc_p(o) BOXWORD_OBJ_TYPE_P(o, PROC)
164 #define mrb_range_p(o) BOXWORD_OBJ_TYPE_P(o, RANGE)
165 #define mrb_env_p(o) BOXWORD_OBJ_TYPE_P(o, ENV)
166 #define mrb_data_p(o) BOXWORD_OBJ_TYPE_P(o, DATA)
167 #define mrb_fiber_p(o) BOXWORD_OBJ_TYPE_P(o, FIBER)
168 #define mrb_istruct_p(o) BOXWORD_OBJ_TYPE_P(o, ISTRUCT)
169 #define mrb_break_p(o) BOXWORD_OBJ_TYPE_P(o, BREAK)
170 
171 #ifndef MRB_NO_FLOAT
172 #define SET_FLOAT_VALUE(mrb,r,v) ((r) = mrb_word_boxing_float_value(mrb, v))
173 #endif
174 #define SET_CPTR_VALUE(mrb,r,v) ((r) = mrb_word_boxing_cptr_value(mrb, v))
175 #define SET_UNDEF_VALUE(r) ((r).w = MRB_Qundef)
176 #define SET_NIL_VALUE(r) ((r).w = MRB_Qnil)
177 #define SET_FALSE_VALUE(r) ((r).w = MRB_Qfalse)
178 #define SET_TRUE_VALUE(r) ((r).w = MRB_Qtrue)
179 #define SET_BOOL_VALUE(r,b) ((b) ? SET_TRUE_VALUE(r) : SET_FALSE_VALUE(r))
180 #define SET_INT_VALUE(mrb,r,n) ((r) = mrb_word_boxing_int_value(mrb, n))
181 #define SET_FIXNUM_VALUE(r,n) BOXWORD_SET_SHIFT_VALUE(r, FIXNUM, n)
182 #ifdef MRB_64BIT
183 #define SET_SYM_VALUE(r,v) do {\
184  union mrb_value_ mrb_value_union_variable;\
185  mrb_value_union_variable.sym = v;\
186  mrb_value_union_variable.sym_flag = BOXWORD_SYMBOL_FLAG;\
187  (r) = mrb_value_union_variable.value;\
188 } while (0)
189 #else
190 #define SET_SYM_VALUE(r,n) BOXWORD_SET_SHIFT_VALUE(r, SYMBOL, n)
191 #endif
192 #define SET_OBJ_VALUE(r,v) ((r).w = (uintptr_t)(v))
193 
196 {
197  return !mrb_bool(o) ? MRB_TT_FALSE :
198  mrb_true_p(o) ? MRB_TT_TRUE :
202  mrb_val_union(o).bp->tt;
203 }
204 
205 #endif /* MRUBY_BOXING_WORD_H */
MRB_API mrb_value mrb_word_boxing_cptr_value(struct mrb_state *, void *)
Definition: etc.c:185
struct mrb_value mrb_value
#define mrb_symbol_p(o)
Definition: boxing_word.h:143
#define mrb_fixnum(o)
Definition: boxing_word.h:124
mrb_static_assert1(sizeof(mrb_value)==sizeof(union mrb_value_))
#define mrb_bool(o)
Definition: boxing_word.h:136
MRB_INLINE mrb_int mrb_integer_func(mrb_value o)
Definition: boxing_word.h:126
#define mrb_undef_p(o)
Definition: boxing_word.h:145
#define mrb_immediate_p(o)
Definition: boxing_word.h:117
#define mrb_true_p(o)
Definition: boxing_word.h:148
MRB_API mrb_value mrb_word_boxing_int_value(struct mrb_state *, mrb_int)
Definition: etc.c:169
#define mrb_fixnum_p(o)
Definition: boxing_word.h:138
static union mrb_value_ mrb_val_union(mrb_value v)
Definition: boxing_word.h:104
mrb_special_consts
Definition: boxing_word.h:22
@ MRB_Qnil
Definition: boxing_word.h:23
@ MRB_Qundef
Definition: boxing_word.h:26
@ MRB_Qtrue
Definition: boxing_word.h:25
@ MRB_Qfalse
Definition: boxing_word.h:24
MRB_INLINE enum mrb_vtype mrb_type(mrb_value o)
Definition: boxing_word.h:195
MRB_API mrb_value mrb_word_boxing_float_value(struct mrb_state *, mrb_float)
Definition: etc.c:157
int v
Definition: dviconv.c:10
unsigned int uint32_t
Definition: stdint.h:80
unsigned int uintptr_t
Definition: stdint.h:119
float x
Definition: cordic.py:15
#define MRB_INLINE
Definition: common.h:62
#define MRB_API
Definition: common.h:73
Definition: object.h:19
enum mrb_vtype tt
Definition: object.h:20
MRB_OBJECT_HEADER
Definition: boxing_word.h:12
mrb_float f
Definition: boxing_word.h:13
mrb_int i
Definition: boxing_word.h:19
MRB_OBJECT_HEADER
Definition: boxing_word.h:18
uintptr_t w
Definition: boxing_word.h:77
struct RBasic * bp
Definition: boxing_word.h:91
void * p
Definition: boxing_word.h:81
struct RInteger * ip
Definition: boxing_word.h:95
mrb_value value
Definition: boxing_nan.h:54
uintptr_t w
Definition: boxing_word.h:97
struct RFloat * fp
Definition: boxing_word.h:93
struct RCptr * vp
Definition: boxing_word.h:96
int32_t mrb_int
Definition: value.h:35
double mrb_float
Definition: value.h:85
mrb_vtype
Definition: value.h:107
@ MRB_TT_UNDEF
Definition: value.h:113
@ MRB_TT_TRUE
Definition: value.h:109
@ MRB_TT_FALSE
Definition: value.h:108
@ MRB_TT_SYMBOL
Definition: value.h:112
@ MRB_TT_INTEGER
Definition: value.h:111
#define MRB_ENDIAN_LOHI(a, b)
Definition: value.h:77
#define sym(x)
Definition: y.tab.c:133