diff --git a/src/common.h b/src/common.h index 0d66017d..d3c2f46d 100644 --- a/src/common.h +++ b/src/common.h @@ -39,9 +39,13 @@ #if defined(__EMSCRIPTEN__) || defined(__arm__) || defined(__i386__) typedef int32_t i64; typedef float f64; +#define S_TO_INT std::stoi +#define S_TO_FLOAT std::stof #else typedef int64_t i64; typedef double f64; +#define S_TO_INT std::stoll +#define S_TO_FLOAT std::stod #endif struct Dummy { }; diff --git a/src/compiler.h b/src/compiler.h index 212db7cd..16157a31 100644 --- a/src/compiler.h +++ b/src/compiler.h @@ -168,9 +168,9 @@ private: if (m[1].matched) base = 16; if (m[2].matched) { if(base == 16) SyntaxError("hex literal should not contain a dot"); - parser->set_next_token(TK("@num"), vm->PyFloat(std::stod(m[0], &size))); + parser->set_next_token(TK("@num"), vm->PyFloat(S_TO_FLOAT(m[0], &size))); } else { - parser->set_next_token(TK("@num"), vm->PyInt(std::stoll(m[0], &size, base))); + parser->set_next_token(TK("@num"), vm->PyInt(S_TO_INT(m[0], &size, base))); } if (size != m.length()) UNREACHABLE(); } diff --git a/src/pocketpy.h b/src/pocketpy.h index 543de4a3..35b4a327 100644 --- a/src/pocketpy.h +++ b/src/pocketpy.h @@ -206,7 +206,7 @@ void init_builtins(VM* _vm) { const Str& s = vm->PyStr_AS_C(args[0]); try{ size_t parsed = 0; - i64 val = std::stoll(s, &parsed, 10); + i64 val = S_TO_INT(s, &parsed, 10); if(parsed != s.size()) throw std::invalid_argument(""); return vm->PyInt(val); }catch(std::invalid_argument&){ @@ -253,7 +253,7 @@ void init_builtins(VM* _vm) { if(s == "inf") return vm->PyFloat(INFINITY); if(s == "-inf") return vm->PyFloat(-INFINITY); try{ - f64 val = std::stod(s); + f64 val = S_TO_FLOAT(s); return vm->PyFloat(val); }catch(std::invalid_argument&){ vm->ValueError("invalid literal for float(): '" + s + "'");