diff --git a/external/parse.h b/external/parse.h index 286c5bafc03e07..bbdae5f1acfe06 100644 --- a/external/parse.h +++ b/external/parse.h @@ -47,6 +47,13 @@ typedef struct rb_parser_config_struct { VALUE (*hash_lookup)(VALUE hash, VALUE key); VALUE (*ident_hash_new)(void); + /* Bignum */ + void (*bignum_negate)(VALUE b); + + /* Rational */ + void (*rational_set_num)(VALUE r, VALUE n); + VALUE (*rational_get_num)(VALUE obj); + } rb_parser_config_t; diff --git a/parse.y b/parse.y index 578c5824129bce..c2c81640931260 100644 --- a/parse.y +++ b/parse.y @@ -46,7 +46,6 @@ struct lex_context; #include "internal/error.h" #include "internal/imemo.h" #include "internal/io.h" -#include "internal/rational.h" #include "internal/re.h" #include "internal/symbol.h" #include "internal/thread.h" @@ -64,6 +63,7 @@ struct lex_context; #ifdef RIPPER #include "internal/numeric.h" #include "internal/hash.h" +#include "internal/rational.h" #endif enum shareability { @@ -131,6 +131,12 @@ RBIMPL_WARNING_POP() #define rb_hash_aset p->config.hash_aset #define rb_hash_lookup p->config.hash_lookup #define rb_ident_hash_new p->config.ident_hash_new + +#define bignum_negate p->config.bignum_negate + +#define rational_set_num p->config.rational_set_num +#define rational_get_num p->config.rational_get_num + #endif #define NO_LEX_CTXT (struct lex_context){0} @@ -12541,11 +12547,11 @@ negate_lit(struct parser_params *p, VALUE lit) } switch (BUILTIN_TYPE(lit)) { case T_BIGNUM: - BIGNUM_NEGATE(lit); + bignum_negate(lit); lit = rb_big_norm(lit); break; case T_RATIONAL: - RATIONAL_SET_NUM(lit, negate_lit(p, RRATIONAL(lit)->num)); + rational_set_num(lit, negate_lit(p, rational_get_num(lit))); break; case T_COMPLEX: RCOMPLEX_SET_REAL(lit, negate_lit(p, RCOMPLEX(lit)->real)); diff --git a/ruby_parser.c b/ruby_parser.c index 9ab4d086528733..6d36ebfdb07477 100644 --- a/ruby_parser.c +++ b/ruby_parser.c @@ -1,8 +1,10 @@ /* This is a wrapper for parse.y */ #include "internal/array.h" +#include "internal/bignum.h" #include "internal/hash.h" #include "internal/parse.h" +#include "internal/rational.h" #include "internal/ruby_parser.h" #include "ruby/ruby.h" @@ -45,6 +47,24 @@ static const rb_data_type_t ruby_parser_data_type = { 0, 0, RUBY_TYPED_FREE_IMMEDIATELY }; +static void +bignum_negate(VALUE b) +{ + BIGNUM_NEGATE(b); +} + +static void +rational_set_num(VALUE r, VALUE n) +{ + RATIONAL_SET_NUM(r, n); +} + +static VALUE +rational_get_num(VALUE obj) +{ + return RRATIONAL(obj)->num; +} + void rb_parser_config_initialize(rb_parser_config_t *config) { @@ -84,6 +104,11 @@ rb_parser_config_initialize(rb_parser_config_t *config) config->hash_lookup = rb_hash_lookup; config->ident_hash_new = rb_ident_hash_new; + config->bignum_negate = bignum_negate; + + config->rational_set_num = rational_set_num; + config->rational_get_num = rational_get_num; + } VALUE