8 #include "internal/parse.h"
12 #include "internal/compilers.h"
13 #include "ruby/backward/2/inttypes.h"
16 #define LIKELY(x) RB_LIKELY(x)
17 #define UNLIKELY(x) RB_UNLIKELY(x)
25 #define numberof(array) ((int)(sizeof(array) / sizeof((array)[0])))
26 #define rb_strlen_lit(str) (sizeof(str "") - 1)
28 #define FIXNUM_MAX (LONG_MAX / 2)
30 #define RSTRING_GETMEM(str, ptrvar, lenvar) \
31 ((ptrvar) = RSTRING_PTR(str), \
32 (lenvar) = RSTRING_LEN(str))
33 #if defined(USE_FLONUM)
35 #elif SIZEOF_VALUE >= SIZEOF_DOUBLE
42 #define st_table parser_st_table
43 #define st_data_t parser_st_data_t
44 #define st_hash_type parser_st_hash_type
45 #define ST_CONTINUE ST2_CONTINUE
46 #define ST_STOP ST2_STOP
47 #define ST_DELETE ST2_DELETE
48 #define ST_CHECK ST2_CHECK
49 #define ST_REPLACE ST2_REPLACE
50 #undef st_init_numtable
51 #define st_init_numtable rb_parser_st_init_numtable
53 #define st_free_table rb_parser_st_free_table
54 #undef st_init_table_with_size
55 #define st_init_table_with_size rb_parser_st_init_table_with_size
57 #define st_insert rb_parser_st_insert
59 #define st_foreach rb_parser_st_foreach
61 #define st_delete rb_parser_st_delete
63 #define st_is_member parser_st_is_member
65 #define rb_encoding void
76 #define T_COMPLEX 0x0e
78 #define T_RATIONAL 0x0f
80 struct rb_imemo_tmpbuf_struct
{
83 VALUE
*ptr
; /* malloc'ed buffer */
84 struct rb_imemo_tmpbuf_struct
*next
; /* next imemo */
85 size_t cnt
; /* buffer size in VALUE */
89 #define xmalloc p->config->malloc
91 #define xcalloc p->config->calloc
93 #define xrealloc p->config->realloc
95 #define ALLOC_N(type,n) ((type *)p->config->alloc_n((n), sizeof(type)))
97 #define ALLOC(type) ((type *)p->config->alloc(sizeof(type)))
99 #define xfree p->config->free
101 // alloca(rbimpl_size_mul_or_raise(x, y));
102 #define ALLOCA_N(type,n) ((type *)alloca(sizeof(type) * (n)))
104 #define REALLOC_N(var,type,n) ((var) = (type *)p->config->realloc_n((void *)var, n, sizeof(type)))
106 #define ZALLOC(type) ((type *)p->config->zalloc(sizeof(type)))
108 #define MEMMOVE(p1,p2,type,n) (p->config->rb_memmove((p1), (p2), sizeof(type), (n)))
110 #define MEMCPY(p1,p2,type,n) (p->config->nonempty_memcpy((p1), (p2), sizeof(type), (n)))
112 #define new_strterm p->config->new_strterm
113 #define strterm_is_heredoc p->config->strterm_is_heredoc
114 #define rb_imemo_tmpbuf_auto_free_pointer p->config->tmpbuf_auto_free_pointer
115 #define rb_imemo_tmpbuf_set_ptr p->config->tmpbuf_set_ptr
116 #define rb_imemo_tmpbuf_parser_heap p->config->tmpbuf_parser_heap
118 #define compile_callback p->config->compile_callback
119 #define reg_named_capture_assign p->config->reg_named_capture_assign
120 #define script_lines_defined p->config->script_lines_defined
121 #define script_lines_get p->config->script_lines_get
123 #define rb_obj_freeze p->config->obj_freeze
124 #define rb_obj_hide p->config->obj_hide
126 #define RB_OBJ_FROZEN p->config->obj_frozen
128 #define RB_TYPE_P p->config->type_p
129 #undef OBJ_FREEZE_RAW
130 #define OBJ_FREEZE_RAW p->config->obj_freeze_raw
133 #define FIXNUM_P p->config->fixnum_p
135 #define SYMBOL_P p->config->symbol_p
137 #define rb_attr_get p->config->attr_get
139 #define rb_ary_new p->config->ary_new
140 #define rb_ary_push p->config->ary_push
141 #undef rb_ary_new_from_args
142 #define rb_ary_new_from_args p->config->ary_new_from_args
143 #define rb_ary_pop p->config->ary_pop
144 #define rb_ary_last p->config->ary_last
145 #define rb_ary_unshift p->config->ary_unshift
147 #define rb_ary_new2 p->config->ary_new2
148 #define rb_ary_entry p->config->ary_entry
149 #define rb_ary_join p->config->ary_join
150 #define rb_ary_reverse p->config->ary_reverse
151 #define rb_ary_clear p->config->ary_clear
153 #define RARRAY_LEN p->config->array_len
154 #define RARRAY_AREF p->config->array_aref
156 #undef rb_sym_intern_ascii_cstr
157 #define rb_sym_intern_ascii_cstr p->config->sym_intern_ascii_cstr
158 #define rb_make_temporary_id p->config->make_temporary_id
159 #define is_local_id p->config->is_local_id
160 #define is_attrset_id p->config->is_attrset_id
161 #define is_global_name_punct p->config->is_global_name_punct
162 #define id_type p->config->id_type
163 #define rb_id_attrset p->config->id_attrset
165 #define rb_intern p->config->intern
166 #define rb_intern2 p->config->intern2
167 #define rb_intern3 p->config->intern3
168 #define rb_intern_str p->config->intern_str
169 #define is_notop_id p->config->is_notop_id
170 #define rb_enc_symname_type p->config->enc_symname_type
171 #define rb_str_intern p->config->str_intern
172 #define rb_id2name p->config->id2name
173 #define rb_id2str p->config->id2str
174 #define rb_id2sym p->config->id2sym
176 #define ID2SYM p->config->id2sym
178 #define SYM2ID p->config->sym2id
180 #define rb_str_catf p->config->str_catf
181 #undef rb_str_cat_cstr
182 #define rb_str_cat_cstr p->config->str_cat_cstr
183 #define rb_str_subseq p->config->str_subseq
184 #define rb_str_dup p->config->str_dup
185 #define rb_str_new_frozen p->config->str_new_frozen
186 #define rb_str_buf_new p->config->str_buf_new
187 #undef rb_str_buf_cat
188 #define rb_str_buf_cat p->config->str_buf_cat
189 #define rb_str_modify p->config->str_modify
190 #define rb_str_set_len p->config->str_set_len
191 #define rb_str_cat p->config->str_cat
192 #define rb_str_resize p->config->str_resize
194 #define rb_str_new p->config->str_new
195 #undef rb_str_new_cstr
196 #define rb_str_new_cstr p->config->str_new_cstr
197 #define rb_fstring p->config->fstring
198 #define is_ascii_string p->config->is_ascii_string
199 #define rb_enc_str_new p->config->enc_str_new
200 #define rb_enc_str_buf_cat p->config->enc_str_buf_cat
201 #define rb_str_buf_append p->config->str_buf_append
202 #define rb_str_vcatf p->config->str_vcatf
203 #undef StringValueCStr
204 #define StringValueCStr(v) p->config->string_value_cstr(&(v))
205 #define rb_sprintf p->config->rb_sprintf
207 #define RSTRING_PTR p->config->rstring_ptr
209 #define RSTRING_END p->config->rstring_end
211 #define RSTRING_LEN p->config->rstring_len
212 #define rb_filesystem_str_new_cstr p->config->filesystem_str_new_cstr
213 #define rb_obj_as_string p->config->obj_as_string
215 #define rb_hash_clear p->config->hash_clear
216 #define rb_hash_new p->config->hash_new
217 #define rb_hash_aset p->config->hash_aset
218 #define rb_hash_lookup p->config->hash_lookup
219 #define rb_ident_hash_new p->config->ident_hash_new
222 #define INT2FIX p->config->int2fix
224 #define LONG2FIX p->config->int2fix
226 #define bignum_negate p->config->bignum_negate
227 #define rb_big_norm p->config->big_norm
228 #define rb_cstr_to_inum p->config->cstr_to_inum
230 #define rb_float_new p->config->float_new
232 #define RFLOAT_VALUE p->config->float_value
234 #define DBL2NUM p->config->float_new
236 #define rb_fix2int p->config->fix2int
238 #define NUM2INT p->config->num2int
239 #define rb_int_positive_pow p->config->int_positive_pow
241 #define INT2NUM p->config->int2num
243 #define FIX2LONG p->config->fix2long
245 #define rb_rational_new p->config->rational_new
246 #define rb_rational_raw p->config->rational_raw
247 #undef rb_rational_raw1
248 #define rb_rational_raw1 p->config->rational_raw1
249 #define rational_set_num p->config->rational_set_num
250 #define rational_get_num p->config->rational_get_num