summaryrefslogtreecommitdiffhomepage
path: root/src/codegen.c
diff options
context:
space:
mode:
authorYukihiro Matsumoto <[email protected]>2012-06-13 23:16:53 +0900
committerYukihiro Matsumoto <[email protected]>2012-06-13 23:16:53 +0900
commit6919ca61edb2da9ea81217fdc355eef1208a6398 (patch)
tree45db6c83b9331d5bff31308039151539c496f093 /src/codegen.c
parent8004168725dc7e3c6975400c40fc9419a0ffed65 (diff)
downloadmruby-6919ca61edb2da9ea81217fdc355eef1208a6398.tar.gz
mruby-6919ca61edb2da9ea81217fdc355eef1208a6398.zip
stop using strtol (via readint) except in load.c; use custom readint_float
Diffstat (limited to 'src/codegen.c')
-rw-r--r--src/codegen.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/codegen.c b/src/codegen.c
index 5f8d17314..63531eac1 100644
--- a/src/codegen.c
+++ b/src/codegen.c
@@ -1575,16 +1575,18 @@ codegen(codegen_scope *s, node *tree, int val)
if (val) {
char *p = (char*)tree->car;
int base = (intptr_t)tree->cdr->car;
- long i = readint(p, base);
+ mrb_float f;
+ mrb_int i;
mrb_code co;
- if ((i == LONG_MAX && errno == ERANGE) || !FIXABLE(i)) {
- mrb_float f = readint_float(s, p, base);
+ f = readint_float(s, p, base);
+ if (!FIXABLE(f)) {
int off = new_lit(s, mrb_float_value(f));
genop(s, MKOP_ABx(OP_LOADL, cursp(), off));
}
else {
+ i = (mrb_int)f;
if (i < MAXARG_sBx && i > -MAXARG_sBx) {
co = MKOP_AsBx(OP_LOADI, cursp(), i);
}
@@ -1629,17 +1631,18 @@ codegen(codegen_scope *s, node *tree, int val)
{
char *p = (char*)tree->car;
int base = (intptr_t)tree->cdr->car;
- long i = readint(p, base);
+ mrb_float f;
+ mrb_int i;
mrb_code co;
- if ((i == LONG_MAX && errno == ERANGE) || !FIXABLE(i)) {
- mrb_float f = readint_float(s, p, base);
+ f = readint_float(s, p, base);
+ if (!FIXABLE(f)) {
int off = new_lit(s, mrb_float_value(-f));
-
+
genop(s, MKOP_ABx(OP_LOADL, cursp(), off));
}
else {
- i = -i;
+ i = (mrb_int)-f;
if (i < MAXARG_sBx && i > -MAXARG_sBx) {
co = MKOP_AsBx(OP_LOADI, cursp(), i);
}