Skip to content

Commit

Permalink
Remove "internal/complex.h"
Browse files Browse the repository at this point in the history
  • Loading branch information
yui-knk committed Apr 13, 2023
1 parent 5914d48 commit e738293
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
6 changes: 6 additions & 0 deletions external/parse.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ typedef struct rb_parser_config_struct {
void (*rational_set_num)(VALUE r, VALUE n);
VALUE (*rational_get_num)(VALUE obj);

/* Complex */
void (*rcomplex_set_real)(VALUE cmp, VALUE r);
void (*rcomplex_set_imag)(VALUE cmp, VALUE i);
VALUE (*rcomplex_get_real)(VALUE obj);
VALUE (*rcomplex_get_imag)(VALUE obj);


} rb_parser_config_t;

Expand Down
11 changes: 8 additions & 3 deletions parse.y
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ struct lex_context;
#include "internal.h"
#include "internal/compile.h"
#include "internal/compilers.h"
#include "internal/complex.h"
#include "internal/encoding.h"
#include "internal/error.h"
#include "internal/imemo.h"
Expand All @@ -61,6 +60,7 @@ struct lex_context;
#include "symbol.h"

#ifdef RIPPER
#include "internal/complex.h"
#include "internal/numeric.h"
#include "internal/hash.h"
#include "internal/rational.h"
Expand Down Expand Up @@ -137,6 +137,11 @@ RBIMPL_WARNING_POP()
#define rational_set_num p->config.rational_set_num
#define rational_get_num p->config.rational_get_num

#define rcomplex_set_real p->config.rcomplex_set_real
#define rcomplex_set_imag p->config.rcomplex_set_imag
#define rcomplex_get_real p->config.rcomplex_get_real
#define rcomplex_get_imag p->config.rcomplex_get_imag

#endif

#define NO_LEX_CTXT (struct lex_context){0}
Expand Down Expand Up @@ -12554,8 +12559,8 @@ negate_lit(struct parser_params *p, VALUE lit)
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));
RCOMPLEX_SET_IMAG(lit, negate_lit(p, RCOMPLEX(lit)->imag));
rcomplex_set_real(lit, negate_lit(p, rcomplex_get_real(lit)));
rcomplex_set_imag(lit, negate_lit(p, rcomplex_get_imag(lit)));
break;
case T_FLOAT:
lit = DBL2NUM(-RFLOAT_VALUE(lit));
Expand Down
29 changes: 29 additions & 0 deletions ruby_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "internal/array.h"
#include "internal/bignum.h"
#include "internal/complex.h"
#include "internal/hash.h"
#include "internal/parse.h"
#include "internal/rational.h"
Expand Down Expand Up @@ -65,6 +66,30 @@ rational_get_num(VALUE obj)
return RRATIONAL(obj)->num;
}

static void
rcomplex_set_real(VALUE cmp, VALUE r)
{
RCOMPLEX_SET_REAL(cmp, r);
}

static void
rcomplex_set_imag(VALUE cmp, VALUE i)
{
RCOMPLEX_SET_REAL(cmp, i);
}

static VALUE
rcomplex_get_real(VALUE obj)
{
return RCOMPLEX(obj)->real;
}

static VALUE
rcomplex_get_imag(VALUE obj)
{
return RCOMPLEX(obj)->imag;
}

void
rb_parser_config_initialize(rb_parser_config_t *config)
{
Expand Down Expand Up @@ -109,6 +134,10 @@ rb_parser_config_initialize(rb_parser_config_t *config)
config->rational_set_num = rational_set_num;
config->rational_get_num = rational_get_num;

config->rcomplex_set_real = rcomplex_set_real;
config->rcomplex_set_imag = rcomplex_set_imag;
config->rcomplex_get_real = rcomplex_get_real;
config->rcomplex_get_imag = rcomplex_get_imag;
}

VALUE
Expand Down

0 comments on commit e738293

Please sign in to comment.