Ruby 3.0.5p211 (2022-11-24 revision ba5cf0f7c52d4d35cc6a173c89eda98ceffa2dcf)
special_consts.h
Go to the documentation of this file.
1#ifndef RBIMPL_SPECIAL_CONSTS_H /*-*-C++-*-vi:se ft=cpp:*/
2#define RBIMPL_SPECIAL_CONSTS_H
32#include "ruby/internal/value.h"
33
34#if defined(USE_FLONUM)
35# /* Take that. */
36#elif SIZEOF_VALUE >= SIZEOF_DOUBLE
37# define USE_FLONUM 1
38#else
39# define USE_FLONUM 0
40#endif
41
42#define RTEST RB_TEST
43
44#define FIXNUM_P RB_FIXNUM_P
45#define IMMEDIATE_P RB_IMMEDIATE_P
46#define NIL_P RB_NIL_P
47#define SPECIAL_CONST_P RB_SPECIAL_CONST_P
48#define STATIC_SYM_P RB_STATIC_SYM_P
49
50#define Qfalse RUBY_Qfalse
51#define Qnil RUBY_Qnil
52#define Qtrue RUBY_Qtrue
53#define Qundef RUBY_Qundef
54
56#define FIXNUM_FLAG RUBY_FIXNUM_FLAG
57#define FLONUM_FLAG RUBY_FLONUM_FLAG
58#define FLONUM_MASK RUBY_FLONUM_MASK
59#define FLONUM_P RB_FLONUM_P
60#define IMMEDIATE_MASK RUBY_IMMEDIATE_MASK
61#define SYMBOL_FLAG RUBY_SYMBOL_FLAG
62
63#define RB_FIXNUM_P RB_FIXNUM_P
64#define RB_FLONUM_P RB_FLONUM_P
65#define RB_IMMEDIATE_P RB_IMMEDIATE_P
66#define RB_NIL_P RB_NIL_P
67#define RB_SPECIAL_CONST_P RB_SPECIAL_CONST_P
68#define RB_STATIC_SYM_P RB_STATIC_SYM_P
69#define RB_TEST RB_TEST
73enum
76#if USE_FLONUM
77 RUBY_Qfalse = 0x00, /* ...0000 0000 */
78 RUBY_Qtrue = 0x14, /* ...0001 0100 */
79 RUBY_Qnil = 0x08, /* ...0000 1000 */
80 RUBY_Qundef = 0x34, /* ...0011 0100 */
81 RUBY_IMMEDIATE_MASK = 0x07, /* ...0000 0111 */
82 RUBY_FIXNUM_FLAG = 0x01, /* ...xxxx xxx1 */
83 RUBY_FLONUM_MASK = 0x03, /* ...0000 0011 */
84 RUBY_FLONUM_FLAG = 0x02, /* ...xxxx xx10 */
85 RUBY_SYMBOL_FLAG = 0x0c, /* ...xxxx 1100 */
86#else
87 RUBY_Qfalse = 0x00, /* ...0000 0000 */
88 RUBY_Qtrue = 0x02, /* ...0000 0010 */
89 RUBY_Qnil = 0x04, /* ...0000 0100 */
90 RUBY_Qundef = 0x06, /* ...0000 0110 */
91 RUBY_IMMEDIATE_MASK = 0x03, /* ...0000 0011 */
92 RUBY_FIXNUM_FLAG = 0x01, /* ...xxxx xxx1 */
93 RUBY_FLONUM_MASK = 0x00, /* any values ANDed with FLONUM_MASK cannot be FLONUM_FLAG */
94 RUBY_FLONUM_FLAG = 0x02, /* ...0000 0010 */
95 RUBY_SYMBOL_FLAG = 0x0e, /* ...0000 1110 */
96#endif
97
99};
100
104/*
105 * :NOTE: rbimpl_test HAS to be `__attribute__((const))` in order for clang to
106 * properly deduce `__builtin_assume()`.
107 */
108static inline bool
109RB_TEST(VALUE obj)
110{
111 /*
112 * Qfalse: ....0000 0000
113 * Qnil: ....0000 1000
114 * ~Qnil: ....1111 0111
115 * v ....xxxx xxxx
116 * ----------------------------
117 * RTEST(v) ....xxxx 0xxx
118 *
119 * RTEST(v) can be 0 if and only if (v == Qfalse || v == Qnil).
120 */
121 return obj & ~RUBY_Qnil;
122}
123
127static inline bool
128RB_NIL_P(VALUE obj)
129{
130 return obj == RUBY_Qnil;
131}
132
136static inline bool
137RB_FIXNUM_P(VALUE obj)
138{
139 return obj & RUBY_FIXNUM_FLAG;
140}
141
145static inline bool
146RB_STATIC_SYM_P(VALUE obj)
147{
150 return (obj & mask) == RUBY_SYMBOL_FLAG;
151}
152
156static inline bool
157RB_FLONUM_P(VALUE obj)
158{
159#if USE_FLONUM
160 return (obj & RUBY_FLONUM_MASK) == RUBY_FLONUM_FLAG;
161#else
162 return false;
163#endif
164}
165
169static inline bool
170RB_IMMEDIATE_P(VALUE obj)
171{
172 return obj & RUBY_IMMEDIATE_MASK;
173}
174
178static inline bool
179RB_SPECIAL_CONST_P(VALUE obj)
180{
181 return RB_IMMEDIATE_P(obj) || ! RB_TEST(obj);
182}
183
186/* This function is to mimic old rb_special_const_p macro but have anyone
187 * actually used its return value? Wasn't it just something no one needed? */
188static inline VALUE
189rb_special_const_p(VALUE obj)
190{
191 return RB_SPECIAL_CONST_P(obj) * RUBY_Qtrue;
192}
193
198#define RUBY_Qfalse RBIMPL_CAST((VALUE)RUBY_Qfalse)
199#define RUBY_Qtrue RBIMPL_CAST((VALUE)RUBY_Qtrue)
200#define RUBY_Qnil RBIMPL_CAST((VALUE)RUBY_Qnil)
201#define RUBY_Qundef RBIMPL_CAST((VALUE)RUBY_Qundef)
204#endif /* RBIMPL_SPECIAL_CONSTS_H */
Defines RBIMPL_ATTR_ARTIFICIAL.
#define RBIMPL_ATTR_ARTIFICIAL()
Wraps (or simulates) __attribute__((artificial))
Definition: artificial.h:43
Defines RBIMPL_ATTR_CONST.
#define RBIMPL_ATTR_CONST()
Wraps (or simulates) __attribute__((const))
Definition: const.h:36
RBIMPL_ATTR_CONSTEXPR.
#define RBIMPL_ATTR_CONSTEXPR(_)
Wraps (or simulates) C++11 constexpr.
Definition: constexpr.h:75
enum @11::@13::@14 mask
RBIMPL_ATTR_ENUM_EXTENSIBILITY.
#define RBIMPL_ATTR_ENUM_EXTENSIBILITY(_)
Wraps (or simulates) __attribute__((enum_extensibility))
ruby_special_consts
special constants - i.e.
@ RUBY_Qtrue
@ RUBY_SPECIAL_SHIFT
@ RUBY_FIXNUM_FLAG
@ RUBY_Qnil
@ RUBY_FLONUM_MASK
@ RUBY_FLONUM_FLAG
@ RUBY_Qundef
@ RUBY_SYMBOL_FLAG
@ RUBY_IMMEDIATE_MASK
@ RUBY_Qfalse
C99 shim for <stdbool.h>
Defines VALUE and ID.
unsigned long VALUE
Definition: value.h:38
#define RBIMPL_VALUE_FULL
Definition: value.h:45