Skip to content

Commit 351c9c8

Browse files
committed
Always enable the rational and complex literals
I think they can always be enabled because the regular expression literal is always enabled.
1 parent 79e73dd commit 351c9c8

File tree

2 files changed

+11
-56
lines changed

2 files changed

+11
-56
lines changed

include/mrbconf.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,6 @@
6262
# endif
6363
#endif
6464

65-
#define MRB_COMPLEX_NUMBERS
66-
#define MRB_RATIONAL_NUMBERS
67-
6865
/* define on big endian machines; used by MRB_NAN_BOXING, etc. */
6966
#ifndef MRB_ENDIAN_BIG
7067
# if (defined(BYTE_ORDER) && defined(BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN) || \

mrbgems/mruby-compiler/core/parse.y

Lines changed: 11 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -71,23 +71,8 @@ typedef unsigned int stack_type;
7171
#define nint(x) ((node*)(intptr_t)(x))
7272
#define intn(x) ((int)(intptr_t)(x))
7373

74-
#if defined(MRB_COMPLEX_NUMBERS) || defined(MRB_RATIONAL_NUMBERS)
75-
#define MRB_SUFFIX_SUPPORT
76-
77-
#ifdef MRB_RATIONAL_NUMBERS
78-
#define NUM_SUFFIX_R (1<<0)
79-
#else
80-
#define NUM_SUFFIX_R 0
81-
#endif
82-
83-
#ifdef MRB_COMPLEX_NUMBERS
84-
#define NUM_SUFFIX_I (1<<1)
85-
#else
86-
#define NUM_SUFFIX_I 0
87-
#endif
88-
89-
#define NUM_SUFFIX_ALL (NUM_SUFFIX_R | NUM_SUFFIX_I)
90-
#endif
74+
#define NUM_SUFFIX_R (1<<0)
75+
#define NUM_SUFFIX_I (1<<1)
9176

9277
static inline mrb_sym
9378
intern_cstr_gen(parser_state *p, const char *s)
@@ -866,37 +851,29 @@ new_op_asgn(parser_state *p, node *a, mrb_sym op, node *b)
866851
return list4((node*)NODE_OP_ASGN, a, nsym(op), b);
867852
}
868853

869-
#ifdef MRB_COMPLEX_NUMBERS
870854
static node*
871855
new_imaginary(parser_state *p, node *imaginary)
872856
{
873857
return new_call(p, new_const(p, intern_lit("Kernel")), intern_lit("Complex"), list1(list2(list3((node*)NODE_INT, (node*)strdup("0"), nint(10)), imaginary)), 1);
874858
}
875-
#endif
876859

877-
#ifdef MRB_RATIONAL_NUMBERS
878860
static node*
879861
new_rational(parser_state *p, node *rational)
880862
{
881863
return new_call(p, new_const(p, intern_lit("Kernel")), intern_lit("Rational"), list1(list1(rational)), 1);
882864
}
883-
#endif
884865

885866
/* (:int . i) */
886867
static node*
887868
new_int(parser_state *p, const char *s, int base, int suffix)
888869
{
889870
node* result = list3((node*)NODE_INT, (node*)strdup(s), nint(base));
890-
#ifdef MRB_RATIONAL_NUMBERS
891871
if (suffix & NUM_SUFFIX_R) {
892872
result = new_rational(p, result);
893873
}
894-
#endif
895-
#ifdef MRB_COMPLEX_NUMBERS
896874
if (suffix & NUM_SUFFIX_I) {
897875
result = new_imaginary(p, result);
898876
}
899-
#endif
900877
return result;
901878
}
902879

@@ -906,16 +883,12 @@ static node*
906883
new_float(parser_state *p, const char *s, int suffix)
907884
{
908885
node* result = cons((node*)NODE_FLOAT, (node*)strdup(s));
909-
#ifdef MRB_RATIONAL_NUMBERS
910886
if (suffix & NUM_SUFFIX_R) {
911887
result = new_rational(p, result);
912888
}
913-
#endif
914-
#ifdef MRB_COMPLEX_NUMBERS
915889
if (suffix & NUM_SUFFIX_I) {
916890
result = new_imaginary(p, result);
917891
}
918-
#endif
919892
return result;
920893
}
921894
#endif
@@ -4585,13 +4558,13 @@ parse_string(parser_state *p)
45854558
return tSTRING;
45864559
}
45874560

4588-
#ifdef MRB_SUFFIX_SUPPORT
45894561
static int
4590-
number_literal_suffix(parser_state *p, int mask)
4562+
number_literal_suffix(parser_state *p)
45914563
{
45924564
int c, result = 0;
45934565
node *list = 0;
45944566
int column = p->column;
4567+
int mask = NUM_SUFFIX_R|NUM_SUFFIX_I;
45954568

45964569
while ((c = nextc(p)) != -1) {
45974570
list = push(list, (node*)(intptr_t)c);
@@ -4623,7 +4596,6 @@ number_literal_suffix(parser_state *p, int mask)
46234596
}
46244597
return result;
46254598
}
4626-
#endif
46274599

46284600
static int
46294601
heredoc_identifier(parser_state *p)
@@ -5246,9 +5218,7 @@ parser_yylex(parser_state *p)
52465218
no_digits();
52475219
}
52485220
else if (nondigit) goto trailing_uc;
5249-
#ifdef MRB_SUFFIX_SUPPORT
5250-
suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
5251-
#endif
5221+
suffix = number_literal_suffix(p);
52525222
pylval.nd = new_int(p, tok(p), 16, suffix);
52535223
return tINTEGER;
52545224
}
@@ -5273,9 +5243,7 @@ parser_yylex(parser_state *p)
52735243
no_digits();
52745244
}
52755245
else if (nondigit) goto trailing_uc;
5276-
#ifdef MRB_SUFFIX_SUPPORT
5277-
suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
5278-
#endif
5246+
suffix = number_literal_suffix(p);
52795247
pylval.nd = new_int(p, tok(p), 2, suffix);
52805248
return tINTEGER;
52815249
}
@@ -5300,9 +5268,7 @@ parser_yylex(parser_state *p)
53005268
no_digits();
53015269
}
53025270
else if (nondigit) goto trailing_uc;
5303-
#ifdef MRB_SUFFIX_SUPPORT
5304-
suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
5305-
#endif
5271+
suffix = number_literal_suffix(p);
53065272
pylval.nd = new_int(p, tok(p), 10, suffix);
53075273
return tINTEGER;
53085274
}
@@ -5336,9 +5302,7 @@ parser_yylex(parser_state *p)
53365302
pushback(p, c);
53375303
tokfix(p);
53385304
if (nondigit) goto trailing_uc;
5339-
#ifdef MRB_SUFFIX_SUPPORT
5340-
suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
5341-
#endif
5305+
suffix = number_literal_suffix(p);
53425306
pylval.nd = new_int(p, tok(p), 8, suffix);
53435307
return tINTEGER;
53445308
}
@@ -5356,9 +5320,7 @@ parser_yylex(parser_state *p)
53565320
}
53575321
else {
53585322
pushback(p, c);
5359-
#ifdef MRB_SUFFIX_SUPPORT
5360-
suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
5361-
#endif
5323+
suffix = number_literal_suffix(p);
53625324
pylval.nd = new_int(p, "0", 10, suffix);
53635325
return tINTEGER;
53645326
}
@@ -5448,16 +5410,12 @@ parser_yylex(parser_state *p)
54485410
yywarning_s(p, "float out of range", tok(p));
54495411
errno = 0;
54505412
}
5451-
#ifdef MRB_SUFFIX_SUPPORT
5452-
suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
5453-
#endif
5413+
suffix = number_literal_suffix(p);
54545414
pylval.nd = new_float(p, tok(p), suffix);
54555415
return tFLOAT;
54565416
#endif
54575417
}
5458-
#ifdef MRB_SUFFIX_SUPPORT
5459-
suffix = number_literal_suffix(p, NUM_SUFFIX_ALL);
5460-
#endif
5418+
suffix = number_literal_suffix(p);
54615419
pylval.nd = new_int(p, tok(p), 10, suffix);
54625420
return tINTEGER;
54635421
}

0 commit comments

Comments
 (0)