mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 03:20:18 +00:00
fix a bug
This commit is contained in:
parent
efc7da7dc7
commit
fc8503cb45
@ -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 { };
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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 + "'");
|
||||
|
Loading…
x
Reference in New Issue
Block a user