Skip to content

Commit

Permalink
Remove "internal/rational.h"
Browse files Browse the repository at this point in the history
  • Loading branch information
yui-knk committed Apr 13, 2023
1 parent fb8649c commit 5914d48
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
7 changes: 7 additions & 0 deletions external/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
12 changes: 9 additions & 3 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -64,6 +63,7 @@ struct lex_context;
#ifdef RIPPER
#include "internal/numeric.h"
#include "internal/hash.h"
#include "internal/rational.h"
#endif

enum shareability {
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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));
Expand Down
25 changes: 25 additions & 0 deletions ruby_parser.c
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5914d48

Please sign in to comment.