diff options
| author | YAMAMOTO Masaya <[email protected]> | 2017-10-11 17:53:17 +0900 |
|---|---|---|
| committer | YAMAMOTO Masaya <[email protected]> | 2017-10-11 17:58:11 +0900 |
| commit | acdc2d1f242f2547ca842be5d62a2b06356b39ea (patch) | |
| tree | 3479c21be76ce7edde6a5fcacb6f60c1a5698a8a /mrbgems/mruby-compiler | |
| parent | 679dfd75a8aeb26ee4ff0d7c148e1f6e88e39c3d (diff) | |
| download | mruby-acdc2d1f242f2547ca842be5d62a2b06356b39ea.tar.gz mruby-acdc2d1f242f2547ca842be5d62a2b06356b39ea.zip | |
Add MRB_WITHOUT_FLOAT
Diffstat (limited to 'mrbgems/mruby-compiler')
| -rw-r--r-- | mrbgems/mruby-compiler/core/codegen.c | 18 | ||||
| -rw-r--r-- | mrbgems/mruby-compiler/core/parse.y | 8 |
2 files changed, 26 insertions, 0 deletions
diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 8f15a9b18..ba8ed2c71 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -460,6 +460,7 @@ new_lit(codegen_scope *s, mrb_value val) return i; } break; +#ifndef MRB_WITHOUT_FLOAT case MRB_TT_FLOAT: for (i=0; i<s->irep->plen; i++) { pv = &s->irep->pool[i]; @@ -467,6 +468,7 @@ new_lit(codegen_scope *s, mrb_value val) if (mrb_float(*pv) == mrb_float(val)) return i; } break; +#endif case MRB_TT_FIXNUM: for (i=0; i<s->irep->plen; i++) { pv = &s->irep->pool[i]; @@ -492,11 +494,13 @@ new_lit(codegen_scope *s, mrb_value val) *pv = mrb_str_pool(s->mrb, val); break; +#ifndef MRB_WITHOUT_FLOAT case MRB_TT_FLOAT: #ifdef MRB_WORD_BOXING *pv = mrb_float_pool(s->mrb, mrb_float(val)); break; #endif +#endif case MRB_TT_FIXNUM: *pv = val; break; @@ -1163,6 +1167,7 @@ raise_error(codegen_scope *s, const char *msg) genop(s, MKOP_ABx(OP_ERR, 1, idx)); } +#ifndef MRB_WITHOUT_FLOAT static double readint_float(codegen_scope *s, const char *p, int base) { @@ -1188,6 +1193,7 @@ readint_float(codegen_scope *s, const char *p, int base) } return f; } +#endif static mrb_int readint_mrb_int(codegen_scope *s, const char *p, int base, mrb_bool neg, mrb_bool *overflow) @@ -2237,6 +2243,7 @@ codegen(codegen_scope *s, node *tree, int val) mrb_bool overflow; i = readint_mrb_int(s, p, base, FALSE, &overflow); +#ifndef MRB_WITHOUT_FLOAT if (overflow) { double f = readint_float(s, p, base); int off = new_lit(s, mrb_float_value(s->mrb, f)); @@ -2244,6 +2251,7 @@ codegen(codegen_scope *s, node *tree, int val) genop(s, MKOP_ABx(OP_LOADL, cursp(), off)); } else { +#endif if (i < MAXARG_sBx && i > -MAXARG_sBx) { co = MKOP_AsBx(OP_LOADI, cursp(), i); } @@ -2252,11 +2260,14 @@ codegen(codegen_scope *s, node *tree, int val) co = MKOP_ABx(OP_LOADL, cursp(), off); } genop(s, co); +#ifndef MRB_WITHOUT_FLOAT } +#endif push(); } break; +#ifndef MRB_WITHOUT_FLOAT case NODE_FLOAT: if (val) { char *p = (char*)tree; @@ -2267,12 +2278,14 @@ codegen(codegen_scope *s, node *tree, int val) push(); } break; +#endif case NODE_NEGATE: { nt = nint(tree->car); tree = tree->cdr; switch (nt) { +#ifndef MRB_WITHOUT_FLOAT case NODE_FLOAT: if (val) { char *p = (char*)tree; @@ -2283,6 +2296,7 @@ codegen(codegen_scope *s, node *tree, int val) push(); } break; +#endif case NODE_INT: if (val) { @@ -2293,6 +2307,7 @@ codegen(codegen_scope *s, node *tree, int val) mrb_bool overflow; i = readint_mrb_int(s, p, base, TRUE, &overflow); +#ifndef MRB_WITHOUT_FLOAT if (overflow) { double f = readint_float(s, p, base); int off = new_lit(s, mrb_float_value(s->mrb, -f)); @@ -2300,6 +2315,7 @@ codegen(codegen_scope *s, node *tree, int val) genop(s, MKOP_ABx(OP_LOADL, cursp(), off)); } else { +#endif if (i < MAXARG_sBx && i > -MAXARG_sBx) { co = MKOP_AsBx(OP_LOADI, cursp(), i); } @@ -2308,7 +2324,9 @@ codegen(codegen_scope *s, node *tree, int val) co = MKOP_ABx(OP_LOADL, cursp(), off); } genop(s, co); +#ifndef MRB_WITHOUT_FLOAT } +#endif push(); } break; diff --git a/mrbgems/mruby-compiler/core/parse.y b/mrbgems/mruby-compiler/core/parse.y index 82e4c7bdd..b4a70873d 100644 --- a/mrbgems/mruby-compiler/core/parse.y +++ b/mrbgems/mruby-compiler/core/parse.y @@ -740,12 +740,14 @@ new_int(parser_state *p, const char *s, int base) return list3((node*)NODE_INT, (node*)strdup(s), nint(base)); } +#ifndef MRB_WITHOUT_FLOAT /* (:float . i) */ static node* new_float(parser_state *p, const char *s) { return cons((node*)NODE_FLOAT, (node*)strdup(s)); } +#endif /* (:str . (s . len)) */ static node* @@ -4962,6 +4964,11 @@ parser_yylex(parser_state *p) } tokfix(p); if (is_float) { +#ifdef MRB_WITHOUT_FLOAT + yywarning_s(p, "floating point numbers are not supported", tok(p)); + pylval.nd = new_int(p, "0", 10); + return tINTEGER; +#else double d; char *endp; @@ -4976,6 +4983,7 @@ parser_yylex(parser_state *p) } pylval.nd = new_float(p, tok(p)); return tFLOAT; +#endif } pylval.nd = new_int(p, tok(p), 10); return tINTEGER; |
