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)
31 #define st_table parser_st_table
32 #define st_data_t parser_st_data_t
33 #define st_hash_type parser_st_hash_type
34 #define ST_CONTINUE ST2_CONTINUE
35 #define ST_STOP ST2_STOP
36 #define ST_DELETE ST2_DELETE
37 #define ST_CHECK ST2_CHECK
38 #define ST_REPLACE ST2_REPLACE
39 #undef st_init_numtable
40 #define st_init_numtable rb_parser_st_init_numtable
42 #define st_free_table rb_parser_st_free_table
43 #undef st_init_table_with_size
44 #define st_init_table_with_size rb_parser_st_init_table_with_size
46 #define st_insert rb_parser_st_insert
48 #define st_foreach rb_parser_st_foreach
50 #define st_delete rb_parser_st_delete
52 #define st_is_member parser_st_is_member
54 #define st_init_table rb_parser_st_init_table
56 #define st_lookup rb_parser_st_lookup
58 #define rb_encoding const void
61 #define xmalloc p->config->malloc
63 #define xcalloc p->config->calloc
65 #define xrealloc p->config->realloc
67 #define ALLOC_N(type,n) ((type *)p->config->alloc_n((n), sizeof(type)))
69 #define ALLOC(type) ((type *)p->config->alloc(sizeof(type)))
71 #define xfree p->config->free
73 // alloca(rbimpl_size_mul_or_raise(x, y));
74 #define ALLOCA_N(type,n) ((type *)alloca(sizeof(type) * (n)))
76 #define REALLOC_N(var,type,n) ((var) = (type *)p->config->realloc_n((void *)var, n, sizeof(type)))
78 #define ZALLOC(type) ((type *)p->config->zalloc(sizeof(type)))
80 #define MEMMOVE(p1,p2,type,n) (p->config->rb_memmove((p1), (p2), sizeof(type), (n)))
82 #define MEMCPY(p1,p2,type,n) (p->config->nonempty_memcpy((p1), (p2), sizeof(type), (n)))
84 #define compile_callback p->config->compile_callback
85 #define reg_named_capture_assign p->config->reg_named_capture_assign
87 #define rb_attr_get p->config->attr_get
89 #define rb_ary_new p->config->ary_new
90 #define rb_ary_push p->config->ary_push
91 #undef rb_ary_new_from_args
92 #define rb_ary_new_from_args p->config->ary_new_from_args
93 #define rb_ary_unshift p->config->ary_unshift
95 #define rb_make_temporary_id p->config->make_temporary_id
96 #define is_local_id p->config->is_local_id
97 #define is_attrset_id p->config->is_attrset_id
98 #define is_global_name_punct p->config->is_global_name_punct
99 #define id_type p->config->id_type
100 #define rb_id_attrset p->config->id_attrset
102 #define rb_intern p->config->intern
103 #define rb_intern2 p->config->intern2
104 #define rb_intern3 p->config->intern3
105 #define rb_intern_str p->config->intern_str
106 #define is_notop_id p->config->is_notop_id
107 #define rb_enc_symname_type p->config->enc_symname_type
108 #define rb_id2name p->config->id2name
109 #define rb_id2str p->config->id2str
111 #define ID2SYM p->config->id2sym
113 #define SYM2ID p->config->sym2id
115 #define rb_str_catf p->config->str_catf
116 #undef rb_str_cat_cstr
117 #define rb_str_cat_cstr p->config->str_cat_cstr
118 #define rb_str_resize p->config->str_resize
120 #define rb_str_new p->config->str_new
121 #undef rb_str_new_cstr
122 #define rb_str_new_cstr p->config->str_new_cstr
123 #define rb_str_to_interned_str p->config->str_to_interned_str
124 #define rb_enc_str_new p->config->enc_str_new
125 #define rb_str_vcatf p->config->str_vcatf
126 #define rb_sprintf p->config->rb_sprintf
128 #define RSTRING_PTR p->config->rstring_ptr
130 #define RSTRING_END p->config->rstring_end
132 #define RSTRING_LEN p->config->rstring_len
133 #define rb_obj_as_string p->config->obj_as_string
136 #define INT2NUM p->config->int2num
138 #define rb_stderr_tty_p p->config->stderr_tty_p
139 #define rb_write_error_str p->config->write_error_str
140 #define rb_io_write p->config->io_write
141 #define rb_io_flush p->config->io_flush
142 #define rb_io_puts p->config->io_puts
144 #define rb_ractor_stdout p->config->debug_output_stdout
145 #define rb_ractor_stderr p->config->debug_output_stderr
147 #define rb_is_usascii_enc p->config->is_usascii_enc
148 #define rb_enc_isalnum p->config->enc_isalnum
149 #define rb_enc_precise_mbclen p->config->enc_precise_mbclen
150 #define MBCLEN_CHARFOUND_P p->config->mbclen_charfound_p
151 #define MBCLEN_CHARFOUND_LEN p->config->mbclen_charfound_len
152 #define rb_enc_name p->config->enc_name
153 #define rb_enc_prev_char p->config->enc_prev_char
154 #define rb_enc_get p->config->enc_get
155 #define rb_enc_asciicompat p->config->enc_asciicompat
156 #define rb_utf8_encoding p->config->utf8_encoding
157 #define rb_enc_associate p->config->enc_associate
158 #define rb_ascii8bit_encoding p->config->ascii8bit_encoding
159 #define rb_enc_codelen p->config->enc_codelen
160 #define rb_enc_mbcput p->config->enc_mbcput
161 #define rb_enc_find_index p->config->enc_find_index
162 #define rb_enc_from_index p->config->enc_from_index
163 #define rb_enc_isspace p->config->enc_isspace
164 #define ENC_CODERANGE_7BIT p->config->enc_coderange_7bit
165 #define ENC_CODERANGE_UNKNOWN p->config->enc_coderange_unknown
166 #define rb_usascii_encoding p->config->usascii_encoding
168 #define rb_local_defined p->config->local_defined
169 #define rb_dvar_defined p->config->dvar_defined
171 #define rb_syntax_error_append p->config->syntax_error_append
172 #define rb_raise p->config->raise
173 #define syntax_error_new p->config->syntax_error_new
175 #define rb_errinfo p->config->errinfo
176 #define rb_set_errinfo p->config->set_errinfo
177 #define rb_exc_raise p->config->exc_raise
178 #define rb_make_exception p->config->make_exception
180 #define ruby_sized_xfree p->config->sized_xfree
181 #define SIZED_REALLOC_N(v, T, m, n) ((v) = (T *)p->config->sized_realloc_n((void *)(v), (m), sizeof(T), (n)))
183 #define RB_GC_GUARD p->config->gc_guard
184 #define rb_gc_mark p->config->gc_mark
186 #define rb_reg_compile p->config->reg_compile
187 #define rb_reg_check_preprocess p->config->reg_check_preprocess
188 #define rb_memcicmp p->config->memcicmp
190 #define rb_compile_warn p->config->compile_warn
191 #define rb_compile_warning p->config->compile_warning
192 #define rb_bug p->config->bug
193 #define rb_fatal p->config->fatal
195 #define ruby_verbose p->config->verbose()
197 #define errno (*p->config->errno_ptr())
199 #define rb_make_backtrace p->config->make_backtrace
201 #define ruby_scan_hex p->config->scan_hex
202 #define ruby_scan_oct p->config->scan_oct
203 #define ruby_scan_digits p->config->scan_digits
204 #define strtod p->config->strtod
207 #define RTEST p->config->rtest
209 #define NIL_P p->config->nil_p
211 #define Qnil p->config->qnil
213 #define Qfalse p->config->qfalse
214 #define rb_eArgError p->config->eArgError()
216 #define rb_long2int p->config->long2int
217 #define rb_enc_mbminlen p->config->enc_mbminlen
218 #define rb_enc_isascii p->config->enc_isascii
219 #define rb_enc_mbc_to_codepoint p->config->enc_mbc_to_codepoint
221 #define rb_ast_new() \
222 rb_ast_new(p->config)