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 #ifndef INTERNAL_IMEMO_H
81 struct rb_imemo_tmpbuf_struct
{
84 VALUE
*ptr
; /* malloc'ed buffer */
85 struct rb_imemo_tmpbuf_struct
*next
; /* next imemo */
86 size_t cnt
; /* buffer size in VALUE */
91 #define xmalloc p->config->malloc
93 #define xcalloc p->config->calloc
95 #define xrealloc p->config->realloc
97 #define ALLOC_N(type,n) ((type *)p->config->alloc_n((n), sizeof(type)))
99 #define ALLOC(type) ((type *)p->config->alloc(sizeof(type)))
101 #define xfree p->config->free
103 // alloca(rbimpl_size_mul_or_raise(x, y));
104 #define ALLOCA_N(type,n) ((type *)alloca(sizeof(type) * (n)))
106 #define REALLOC_N(var,type,n) ((var) = (type *)p->config->realloc_n((void *)var, n, sizeof(type)))
108 #define ZALLOC(type) ((type *)p->config->zalloc(sizeof(type)))
110 #define MEMMOVE(p1,p2,type,n) (p->config->rb_memmove((p1), (p2), sizeof(type), (n)))
112 #define MEMCPY(p1,p2,type,n) (p->config->nonempty_memcpy((p1), (p2), sizeof(type), (n)))
114 #define rb_imemo_tmpbuf_parser_heap p->config->tmpbuf_parser_heap
116 #define compile_callback p->config->compile_callback
117 #define reg_named_capture_assign p->config->reg_named_capture_assign
118 #define script_lines_defined p->config->script_lines_defined
119 #define script_lines_get p->config->script_lines_get
121 #define rb_obj_freeze p->config->obj_freeze
122 #define rb_obj_hide p->config->obj_hide
124 #define RB_OBJ_FROZEN p->config->obj_frozen
126 #define RB_TYPE_P p->config->type_p
127 #undef OBJ_FREEZE_RAW
128 #define OBJ_FREEZE_RAW p->config->obj_freeze_raw
131 #define FIXNUM_P p->config->fixnum_p
133 #define SYMBOL_P p->config->symbol_p
135 #define rb_attr_get p->config->attr_get
137 #define rb_ary_new p->config->ary_new
138 #define rb_ary_push p->config->ary_push
139 #undef rb_ary_new_from_args
140 #define rb_ary_new_from_args p->config->ary_new_from_args
141 #define rb_ary_pop p->config->ary_pop
142 #define rb_ary_last p->config->ary_last
143 #define rb_ary_unshift p->config->ary_unshift
145 #define rb_ary_new2 p->config->ary_new2
146 #define rb_ary_entry p->config->ary_entry
147 #define rb_ary_clear p->config->ary_clear
148 #define rb_ary_modify p->config->ary_modify
150 #define RARRAY_LEN p->config->array_len
151 #define RARRAY_AREF p->config->array_aref
153 #undef rb_sym_intern_ascii_cstr
154 #define rb_sym_intern_ascii_cstr p->config->sym_intern_ascii_cstr
155 #define rb_make_temporary_id p->config->make_temporary_id
156 #define is_local_id p->config->is_local_id
157 #define is_attrset_id p->config->is_attrset_id
158 #define is_global_name_punct p->config->is_global_name_punct
159 #define id_type p->config->id_type
160 #define rb_id_attrset p->config->id_attrset
162 #define rb_intern p->config->intern
163 #define rb_intern2 p->config->intern2
164 #define rb_intern3 p->config->intern3
165 #define rb_intern_str p->config->intern_str
166 #define is_notop_id p->config->is_notop_id
167 #define rb_enc_symname_type p->config->enc_symname_type
168 #define rb_str_intern p->config->str_intern
169 #define rb_id2name p->config->id2name
170 #define rb_id2str p->config->id2str
171 #define rb_id2sym p->config->id2sym
173 #define ID2SYM p->config->id2sym
175 #define SYM2ID p->config->sym2id
177 #define rb_str_catf p->config->str_catf
178 #undef rb_str_cat_cstr
179 #define rb_str_cat_cstr p->config->str_cat_cstr
180 #define rb_str_subseq p->config->str_subseq
181 #define rb_str_dup p->config->str_dup
182 #define rb_str_new_frozen p->config->str_new_frozen
183 #define rb_str_buf_new p->config->str_buf_new
184 #undef rb_str_buf_cat
185 #define rb_str_buf_cat p->config->str_buf_cat
186 #define rb_str_modify p->config->str_modify
187 #define rb_str_set_len p->config->str_set_len
188 #define rb_str_cat p->config->str_cat
189 #define rb_str_resize p->config->str_resize
191 #define rb_str_new p->config->str_new
192 #undef rb_str_new_cstr
193 #define rb_str_new_cstr p->config->str_new_cstr
194 #define rb_fstring p->config->fstring
195 #define is_ascii_string p->config->is_ascii_string
196 #define rb_enc_str_new p->config->enc_str_new
197 #define rb_enc_str_buf_cat p->config->enc_str_buf_cat
198 #define rb_str_buf_append p->config->str_buf_append
199 #define rb_str_vcatf p->config->str_vcatf
200 #undef StringValueCStr
201 #define StringValueCStr(v) p->config->string_value_cstr(&(v))
202 #define rb_sprintf p->config->rb_sprintf
204 #define RSTRING_PTR p->config->rstring_ptr
206 #define RSTRING_END p->config->rstring_end
208 #define RSTRING_LEN p->config->rstring_len
209 #define rb_filesystem_str_new_cstr p->config->filesystem_str_new_cstr
210 #define rb_obj_as_string p->config->obj_as_string
212 #define rb_hash_clear p->config->hash_clear
213 #define rb_hash_new p->config->hash_new
214 #define rb_hash_aset p->config->hash_aset
215 #define rb_hash_lookup p->config->hash_lookup
216 #define rb_ident_hash_new p->config->ident_hash_new
219 #define NUM2INT p->config->num2int
221 #define INT2NUM p->config->int2num
223 #define rb_stderr_tty_p p->config->stderr_tty_p
224 #define rb_write_error_str p->config->write_error_str
225 #define rb_default_rs p->config->default_rs()
226 #define rb_io_write p->config->io_write
227 #define rb_io_flush p->config->io_flush
228 #define rb_io_puts p->config->io_puts
229 #define rb_io_gets_internal p->config->io_gets_internal
231 #define rb_ractor_stdout p->config->debug_output_stdout
232 #define rb_ractor_stderr p->config->debug_output_stderr
234 #define rb_is_usascii_enc p->config->is_usascii_enc
235 #define rb_enc_isalnum p->config->enc_isalnum
236 #define rb_enc_precise_mbclen p->config->enc_precise_mbclen
237 #define MBCLEN_CHARFOUND_P p->config->mbclen_charfound_p
238 #define MBCLEN_CHARFOUND_LEN p->config->mbclen_charfound_len
239 #define rb_enc_name p->config->enc_name
240 #define rb_enc_prev_char p->config->enc_prev_char
241 #define rb_enc_get p->config->enc_get
242 #define rb_enc_asciicompat p->config->enc_asciicompat
243 #define rb_utf8_encoding p->config->utf8_encoding
244 #define rb_enc_associate p->config->enc_associate
245 #define rb_ascii8bit_encoding p->config->ascii8bit_encoding
246 #define rb_enc_codelen p->config->enc_codelen
247 #define rb_enc_mbcput p->config->enc_mbcput
248 #define rb_char_to_option_kcode p->config->char_to_option_kcode
249 #define rb_ascii8bit_encindex p->config->ascii8bit_encindex
250 #define rb_enc_find_index p->config->enc_find_index
251 #define rb_enc_from_index p->config->enc_from_index
252 #define rb_enc_associate_index p->config->enc_associate_index
253 #define rb_enc_isspace p->config->enc_isspace
254 #define ENC_CODERANGE_7BIT p->config->enc_coderange_7bit
255 #define ENC_CODERANGE_UNKNOWN p->config->enc_coderange_unknown
256 #define rb_enc_compatible p->config->enc_compatible
257 #define rb_enc_from_encoding p->config->enc_from_encoding
258 #define ENCODING_GET p->config->encoding_get
259 #define ENCODING_SET p->config->encoding_set
260 #define ENCODING_IS_ASCII8BIT p->config->encoding_is_ascii8bit
261 #define rb_usascii_encoding p->config->usascii_encoding
263 #define rb_ractor_make_shareable p->config->ractor_make_shareable
265 #define ruby_vm_keep_script_lines p->config->vm_keep_script_lines()
266 #define rb_local_defined p->config->local_defined
267 #define rb_dvar_defined p->config->dvar_defined
269 #define literal_cmp p->config->literal_cmp
270 #define literal_hash p->config->literal_hash
272 #define rb_syntax_error_append p->config->syntax_error_append
273 #define rb_raise p->config->raise
274 #define syntax_error_new p->config->syntax_error_new
276 #define rb_errinfo p->config->errinfo
277 #define rb_set_errinfo p->config->set_errinfo
278 #define rb_exc_raise p->config->exc_raise
279 #define rb_make_exception p->config->make_exception
281 #define ruby_sized_xfree p->config->sized_xfree
282 #define SIZED_REALLOC_N(v, T, m, n) ((v) = (T *)p->config->sized_realloc_n((void *)(v), (m), sizeof(T), (n)))
284 #define RB_OBJ_WRITE(old, slot, young) p->config->obj_write((VALUE)(old), (VALUE *)(slot), (VALUE)(young))
285 #undef RB_OBJ_WRITTEN
286 #define RB_OBJ_WRITTEN(old, oldv, young) p->config->obj_written((VALUE)(old), (VALUE)(oldv), (VALUE)(young))
287 #define rb_gc_register_mark_object p->config->gc_register_mark_object
289 #define RB_GC_GUARD p->config->gc_guard
290 #define rb_gc_mark p->config->gc_mark
292 #define rb_reg_compile p->config->reg_compile
293 #define rb_reg_check_preprocess p->config->reg_check_preprocess
294 #define rb_memcicmp p->config->memcicmp
296 #define rb_compile_warn p->config->compile_warn
297 #define rb_compile_warning p->config->compile_warning
298 #define rb_bug p->config->bug
299 #define rb_fatal p->config->fatal
301 #define ruby_verbose p->config->verbose()
303 #define errno (*p->config->errno_ptr())
305 #define rb_make_backtrace p->config->make_backtrace
307 #define ruby_scan_hex p->config->scan_hex
308 #define ruby_scan_oct p->config->scan_oct
309 #define ruby_scan_digits p->config->scan_digits
310 #define strtod p->config->strtod
313 #define RBOOL p->config->rbool
315 #define UNDEF_P p->config->undef_p
317 #define RTEST p->config->rtest
319 #define NIL_P p->config->nil_p
321 #define Qnil p->config->qnil
323 #define Qtrue p->config->qtrue
325 #define Qfalse p->config->qfalse
327 #define Qundef p->config->qundef
328 #define rb_eArgError p->config->eArgError()
329 #define rb_mRubyVMFrozenCore p->config->mRubyVMFrozenCore()
331 #define rb_long2int p->config->long2int
332 #undef SPECIAL_CONST_P
333 #define SPECIAL_CONST_P p->config->special_const_p
335 #define BUILTIN_TYPE p->config->builtin_type
336 #define ruby_snprintf p->config->snprintf
338 #define rb_node_case_when_optimizable_literal p->config->node_case_when_optimizable_literal
340 #undef st_init_table_with_size
341 #define st_init_table_with_size rb_parser_st_init_table_with_size
343 #define rb_ast_new() \
344 rb_ast_new(p->config)