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)  

value.h
Go to the documentation of this file.
1 /**
2 ** @file mruby/value.h - mruby value definitions
3 **
4 ** See Copyright Notice in mruby.h
5 */
6 
7 #ifndef MRUBY_VALUE_H
8 #define MRUBY_VALUE_H
9 
10 #include "common.h"
11 
12 /*
13  * MRuby Value definition functions and macros.
14  */
16 
17 /**
18  * mruby Symbol.
19  * @class mrb_sym
20  *
21  * You can create an mrb_sym by simply using mrb_str_intern() or mrb_intern_cstr()
22  */
23 typedef uint32_t mrb_sym;
24 
25 /**
26  * mruby Boolean.
27  * @class mrb_bool
28  *
29  *
30  * Used internally to represent boolean. Can be TRUE or FALSE.
31  * Not to be confused with Ruby's boolean classes, which can be
32  * obtained using mrb_false_value() and mrb_true_value()
33  */
34 typedef uint8_t mrb_bool;
35 struct mrb_state;
36 
37 #if defined _MSC_VER && _MSC_VER < 1800
38 # define PRIo64 "llo"
39 # define PRId64 "lld"
40 # define PRIu64 "llu"
41 # define PRIx64 "llx"
42 # define PRIo16 "ho"
43 # define PRId16 "hd"
44 # define PRIu16 "hu"
45 # define PRIx16 "hx"
46 # define PRIo32 "o"
47 # define PRId32 "d"
48 # define PRIu32 "u"
49 # define PRIx32 "x"
50 #else
51 # include <inttypes.h>
52 #endif
53 
54 #if defined(MRB_INT64)
55  typedef int64_t mrb_int;
56  typedef uint64_t mrb_uint;
57 # define MRB_INT_BIT 64
58 # define MRB_INT_MIN INT64_MIN
59 # define MRB_INT_MAX INT64_MAX
60 # define MRB_PRIo PRIo64
61 # define MRB_PRId PRId64
62 # define MRB_PRIx PRIx64
63 #else
64  typedef int32_t mrb_int;
65  typedef uint32_t mrb_uint;
66 # define MRB_INT_BIT 32
67 # define MRB_INT_MIN INT32_MIN
68 # define MRB_INT_MAX INT32_MAX
69 # define MRB_PRIo PRIo32
70 # define MRB_PRId PRId32
71 # define MRB_PRIx PRIx32
72 #endif
73 
74 #ifdef MRB_ENDIAN_BIG
75 # define MRB_ENDIAN_LOHI(a,b) a b
76 #else
77 # define MRB_ENDIAN_LOHI(a,b) b a
78 #endif
79 
80 #ifndef MRB_NO_FLOAT
81 MRB_API double mrb_float_read(const char*, char**);
82 #ifdef MRB_USE_FLOAT32
83  typedef float mrb_float;
84 #else
85  typedef double mrb_float;
86 #endif
87 #endif
88 
89 #if defined _MSC_VER && _MSC_VER < 1900
90 # include <stdarg.h>
91 MRB_API int mrb_msvc_vsnprintf(char *s, size_t n, const char *format, va_list arg);
92 MRB_API int mrb_msvc_snprintf(char *s, size_t n, const char *format, ...);
93 # define vsnprintf(s, n, format, arg) mrb_msvc_vsnprintf(s, n, format, arg)
94 # define snprintf(s, n, format, ...) mrb_msvc_snprintf(s, n, format, __VA_ARGS__)
95 # if _MSC_VER < 1800 && !defined MRB_NO_FLOAT
96 # include <float.h>
97 # define isfinite(n) _finite(n)
98 # define isnan _isnan
99 # define isinf(n) (!_finite(n) && !_isnan(n))
100 # define signbit(n) (_copysign(1.0, (n)) < 0.0)
101 static const unsigned int IEEE754_INFINITY_BITS_SINGLE = 0x7F800000;
102 # define INFINITY (*(float *)&IEEE754_INFINITY_BITS_SINGLE)
103 # define NAN ((float)(INFINITY - INFINITY))
104 # endif
105 #endif
106 
107 enum mrb_vtype {
133 };
134 
135 /* for compatibility */
136 #define MRB_TT_FIXNUM MRB_TT_INTEGER
137 
138 #include <mruby/object.h>
139 
140 #ifdef MRB_DOCUMENTATION_BLOCK
141 
142 /**
143  * @abstract
144  * MRuby value boxing.
145  *
146  * Actual implementation depends on configured boxing type.
147  *
148  * @see mruby/boxing_no.h Default boxing representation
149  * @see mruby/boxing_word.h Word representation
150  * @see mruby/boxing_nan.h Boxed double representation
151  */
152 typedef void mrb_value;
153 
154 #endif
155 
156 #if defined(MRB_WORD_BOXING) || (defined(MRB_NAN_BOXING) && defined(MRB_64BIT))
157 struct RCptr {
159  void *p;
160 };
161 #endif
162 
163 #if defined(MRB_NAN_BOXING)
164 #include "boxing_nan.h"
165 #elif defined(MRB_WORD_BOXING)
166 #include "boxing_word.h"
167 #else
168 #include "boxing_no.h"
169 #endif
170 
171 #if INTPTR_MAX < MRB_INT_MAX
172  typedef intptr_t mrb_ssize;
173 # define MRB_SSIZE_MAX INTPTR_MAX
174 #else
176 # define MRB_SSIZE_MAX MRB_INT_MAX
177 #endif
178 
179 #ifndef mrb_immediate_p
180 #define mrb_immediate_p(o) (mrb_type(o) < MRB_TT_FREE)
181 #endif
182 #ifndef mrb_integer_p
183 #define mrb_integer_p(o) (mrb_type(o) == MRB_TT_INTEGER)
184 #endif
185 #ifndef mrb_fixnum_p
186 #define mrb_fixnum_p(o) mrb_integer_p(o)
187 #endif
188 #ifndef mrb_symbol_p
189 #define mrb_symbol_p(o) (mrb_type(o) == MRB_TT_SYMBOL)
190 #endif
191 #ifndef mrb_undef_p
192 #define mrb_undef_p(o) (mrb_type(o) == MRB_TT_UNDEF)
193 #endif
194 #ifndef mrb_nil_p
195 #define mrb_nil_p(o) (mrb_type(o) == MRB_TT_FALSE && !mrb_fixnum(o))
196 #endif
197 #ifndef mrb_false_p
198 #define mrb_false_p(o) (mrb_type(o) == MRB_TT_FALSE && !!mrb_fixnum(o))
199 #endif
200 #ifndef mrb_true_p
201 #define mrb_true_p(o) (mrb_type(o) == MRB_TT_TRUE)
202 #endif
203 #ifndef MRB_NO_FLOAT
204 #ifndef mrb_float_p
205 #define mrb_float_p(o) (mrb_type(o) == MRB_TT_FLOAT)
206 #endif
207 #endif
208 #ifndef mrb_array_p
209 #define mrb_array_p(o) (mrb_type(o) == MRB_TT_ARRAY)
210 #endif
211 #ifndef mrb_string_p
212 #define mrb_string_p(o) (mrb_type(o) == MRB_TT_STRING)
213 #endif
214 #ifndef mrb_hash_p
215 #define mrb_hash_p(o) (mrb_type(o) == MRB_TT_HASH)
216 #endif
217 #ifndef mrb_cptr_p
218 #define mrb_cptr_p(o) (mrb_type(o) == MRB_TT_CPTR)
219 #endif
220 #ifndef mrb_exception_p
221 #define mrb_exception_p(o) (mrb_type(o) == MRB_TT_EXCEPTION)
222 #endif
223 #ifndef mrb_free_p
224 #define mrb_free_p(o) (mrb_type(o) == MRB_TT_FREE)
225 #endif
226 #ifndef mrb_object_p
227 #define mrb_object_p(o) (mrb_type(o) == MRB_TT_OBJECT)
228 #endif
229 #ifndef mrb_class_p
230 #define mrb_class_p(o) (mrb_type(o) == MRB_TT_CLASS)
231 #endif
232 #ifndef mrb_module_p
233 #define mrb_module_p(o) (mrb_type(o) == MRB_TT_MODULE)
234 #endif
235 #ifndef mrb_iclass_p
236 #define mrb_iclass_p(o) (mrb_type(o) == MRB_TT_ICLASS)
237 #endif
238 #ifndef mrb_sclass_p
239 #define mrb_sclass_p(o) (mrb_type(o) == MRB_TT_SCLASS)
240 #endif
241 #ifndef mrb_proc_p
242 #define mrb_proc_p(o) (mrb_type(o) == MRB_TT_PROC)
243 #endif
244 #ifndef mrb_range_p
245 #define mrb_range_p(o) (mrb_type(o) == MRB_TT_RANGE)
246 #endif
247 #ifndef mrb_env_p
248 #define mrb_env_p(o) (mrb_type(o) == MRB_TT_ENV)
249 #endif
250 #ifndef mrb_data_p
251 #define mrb_data_p(o) (mrb_type(o) == MRB_TT_DATA)
252 #endif
253 #ifndef mrb_fiber_p
254 #define mrb_fiber_p(o) (mrb_type(o) == MRB_TT_FIBER)
255 #endif
256 #ifndef mrb_istruct_p
257 #define mrb_istruct_p(o) (mrb_type(o) == MRB_TT_ISTRUCT)
258 #endif
259 #ifndef mrb_break_p
260 #define mrb_break_p(o) (mrb_type(o) == MRB_TT_BREAK)
261 #endif
262 #ifndef mrb_bool
263 #define mrb_bool(o) (mrb_type(o) != MRB_TT_FALSE)
264 #endif
265 #define mrb_test(o) mrb_bool(o)
266 
267 /**
268  * Returns a float in Ruby.
269  *
270  * Takes a float and boxes it into an mrb_value
271  */
272 #ifndef MRB_NO_FLOAT
274 {
275  mrb_value v;
276  (void) mrb;
277  SET_FLOAT_VALUE(mrb, v, f);
278  return v;
279 }
280 #endif
281 
283 mrb_cptr_value(struct mrb_state *mrb, void *p)
284 {
285  mrb_value v;
286  (void) mrb;
287  SET_CPTR_VALUE(mrb,v,p);
288  return v;
289 }
290 
291 /**
292  * Returns an integer in Ruby.
293  */
295 {
296  mrb_value v;
297  SET_INT_VALUE(mrb, v, i);
298  return v;
299 }
300 
302 {
303  mrb_value v;
304  SET_FIXNUM_VALUE(v, i);
305  return v;
306 }
307 
310 {
311  mrb_value v;
312  SET_SYM_VALUE(v, i);
313  return v;
314 }
315 
318 {
319  mrb_value v;
320  SET_OBJ_VALUE(v, (struct RBasic*)p);
321  mrb_assert(p == mrb_ptr(v));
322  mrb_assert(((struct RBasic*)p)->tt == mrb_type(v));
323  return v;
324 }
325 
326 /**
327  * Get a nil mrb_value object.
328  *
329  * @return
330  * nil mrb_value object reference.
331  */
333 {
334  mrb_value v;
335  SET_NIL_VALUE(v);
336  return v;
337 }
338 
339 /**
340  * Returns false in Ruby.
341  */
343 {
344  mrb_value v;
346  return v;
347 }
348 
349 /**
350  * Returns true in Ruby.
351  */
353 {
354  mrb_value v;
355  SET_TRUE_VALUE(v);
356  return v;
357 }
358 
361 {
362  mrb_value v;
363  SET_BOOL_VALUE(v, boolean);
364  return v;
365 }
366 
369 {
370  mrb_value v;
372  return v;
373 }
374 
375 #if defined(MRB_USE_ETEXT_EDATA) && !defined(MRB_USE_LINK_TIME_RO_DATA_P)
376 # ifdef __GNUC__
377 # warning MRB_USE_ETEXT_EDATA is deprecated. Define MRB_USE_LINK_TIME_RO_DATA_P instead.
378 # endif
379 # define MRB_USE_LINK_TIME_RO_DATA_P
380 #endif
381 
382 #if defined(MRB_USE_CUSTOM_RO_DATA_P)
383 /* If you define `MRB_USE_CUSTOM_RO_DATA_P`, you must implement `mrb_ro_data_p()`. */
384 mrb_bool mrb_ro_data_p(const char *p);
385 #elif defined(MRB_USE_LINK_TIME_RO_DATA_P)
386 extern char __ehdr_start[];
387 extern char __init_array_start[];
388 
389 static inline mrb_bool
390 mrb_ro_data_p(const char *p)
391 {
392  return __ehdr_start < p && p < __init_array_start;
393 }
394 #else
395 # define mrb_ro_data_p(p) FALSE
396 #endif
397 
399 
400 #endif /* MRUBY_VALUE_H */
#define SET_UNDEF_VALUE(r)
Definition: boxing_nan.h:128
#define SET_INT_VALUE(mrb, r, n)
Definition: boxing_nan.h:118
#define SET_SYM_VALUE(r, v)
Definition: boxing_nan.h:120
#define SET_FLOAT_VALUE(mrb, r, v)
Definition: boxing_nan.h:102
#define SET_CPTR_VALUE(mrb, r, v)
Definition: boxing_nan.h:126
struct mrb_value mrb_value
#define SET_OBJ_VALUE(r, v)
Definition: boxing_nan.h:121
#define SET_TRUE_VALUE(r)
Definition: boxing_nan.h:116
#define SET_NIL_VALUE(r)
Definition: boxing_nan.h:114
#define SET_FALSE_VALUE(r)
Definition: boxing_nan.h:115
#define mrb_ptr(o)
Definition: boxing_nan.h:79
#define SET_FIXNUM_VALUE(r, n)
Definition: boxing_nan.h:119
#define SET_BOOL_VALUE(r, b)
Definition: boxing_nan.h:117
MRB_INLINE enum mrb_vtype mrb_type(mrb_value o)
Definition: boxing_word.h:195
#define n
Definition: t4ht.c:1290
int v
Definition: dviconv.c:10
static void
Definition: fpif.c:118
mpz_t * f
Definition: gen-fib.c:34
#define s
Definition: afcover.h:80
small capitals from c petite p
Definition: afcover.h:72
small capitals from c petite p scientific i
Definition: afcover.h:80
signed __int64 int64_t
Definition: stdint.h:89
unsigned int uint32_t
Definition: stdint.h:80
signed int intptr_t
Definition: stdint.h:118
signed int int32_t
Definition: stdint.h:77
unsigned char uint8_t
Definition: stdint.h:78
unsigned __int64 uint64_t
Definition: stdint.h:90
#define mrb_assert(p)
Definition: mruby.h:65
#define MRB_OBJECT_HEADER
Definition: object.h:10
static int format
Definition: pbmclean.c:15
#define MRB_INLINE
Definition: common.h:62
#define MRB_END_DECL
Definition: common.h:28
#define MRB_BEGIN_DECL
Definition: common.h:26
#define MRB_API
Definition: common.h:73
Definition: object.h:19
#define mrb_ro_data_p(p)
Definition: value.h:395
double mrb_float_read(const char *, char **)
Definition: string.c:2982
static mrb_value mrb_true_value(void)
Definition: value.h:352
int32_t mrb_int
Definition: value.h:35
uint32_t mrb_sym
Definition: value.h:23
static mrb_value mrb_false_value(void)
Definition: value.h:342
static mrb_value mrb_nil_value(void)
Definition: value.h:332
static mrb_value mrb_bool_value(mrb_bool boolean)
Definition: value.h:360
static mrb_value mrb_float_value(struct mrb_state *mrb, mrb_float f)
Definition: value.h:273
double mrb_float
Definition: value.h:85
mrb_vtype
Definition: value.h:107
@ MRB_TT_EXCEPTION
Definition: value.h:126
@ MRB_TT_UNDEF
Definition: value.h:113
@ MRB_TT_DATA
Definition: value.h:128
@ MRB_TT_BREAK
Definition: value.h:131
@ MRB_TT_TRUE
Definition: value.h:109
@ MRB_TT_SCLASS
Definition: value.h:120
@ MRB_TT_CLASS
Definition: value.h:117
@ MRB_TT_FREE
Definition: value.h:115
@ MRB_TT_OBJECT
Definition: value.h:116
@ MRB_TT_STRING
Definition: value.h:124
@ MRB_TT_RANGE
Definition: value.h:125
@ MRB_TT_FALSE
Definition: value.h:108
@ MRB_TT_MODULE
Definition: value.h:118
@ MRB_TT_HASH
Definition: value.h:123
@ MRB_TT_SYMBOL
Definition: value.h:112
@ MRB_TT_CPTR
Definition: value.h:114
@ MRB_TT_ICLASS
Definition: value.h:119
@ MRB_TT_ARRAY
Definition: value.h:122
@ MRB_TT_FLOAT
Definition: value.h:110
@ MRB_TT_PROC
Definition: value.h:121
@ MRB_TT_MAXDEFINE
Definition: value.h:132
@ MRB_TT_INTEGER
Definition: value.h:111
@ MRB_TT_FIBER
Definition: value.h:129
@ MRB_TT_ENV
Definition: value.h:127
@ MRB_TT_ISTRUCT
Definition: value.h:130
#define mrb_bool(o)
Definition: value.h:263
static mrb_value mrb_fixnum_value(mrb_int i)
Definition: value.h:301
mrb_int mrb_ssize
Definition: value.h:175
uint32_t mrb_uint
Definition: value.h:65
static mrb_value mrb_undef_value(void)
Definition: value.h:368
static mrb_value mrb_symbol_value(mrb_sym i)
Definition: value.h:309
static mrb_value mrb_cptr_value(struct mrb_state *mrb, void *p)
Definition: value.h:283
static mrb_value mrb_int_value(struct mrb_state *mrb, mrb_int i)
Definition: value.h:294
static mrb_value mrb_obj_value(void *p)
Definition: value.h:317
char * va_list
Definition: varargs.h:22