diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-11-04 12:33:07 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2017-11-04 12:33:07 +0900 |
| commit | d6cb4f9cf2027eb20f67238aa6c051448602e7e6 (patch) | |
| tree | c025d53534298097aadc3d7699de964bd8a7225f /mrbgems/mruby-compiler | |
| parent | 388d26d77027feaa3e107abf7209e2681868bbe6 (diff) | |
| parent | a751f7f196e35cf85ac6f5c0d855edeb68b2bf53 (diff) | |
| download | mruby-d6cb4f9cf2027eb20f67238aa6c051448602e7e6.tar.gz mruby-d6cb4f9cf2027eb20f67238aa6c051448602e7e6.zip | |
Merge branch 'pandax381-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 da29077b0..fce5ac490 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -481,6 +481,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]; @@ -488,6 +489,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]; @@ -513,11 +515,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; @@ -1184,6 +1188,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) { @@ -1209,6 +1214,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) @@ -2258,6 +2264,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)); @@ -2265,6 +2272,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); } @@ -2273,11 +2281,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; @@ -2288,12 +2299,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; @@ -2304,6 +2317,7 @@ codegen(codegen_scope *s, node *tree, int val) push(); } break; +#endif case NODE_INT: if (val) { @@ -2314,6 +2328,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)); @@ -2321,6 +2336,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); } @@ -2329,7 +2345,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 e5017b677..01269d8da 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; |
