blueloveTH 3 ani în urmă
părinte
comite
fc8503cb45
3 a modificat fișierele cu 8 adăugiri și 4 ștergeri
  1. 4 0
      src/common.h
  2. 2 2
      src/compiler.h
  3. 2 2
      src/pocketpy.h

+ 4 - 0
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 {  };

+ 2 - 2
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();
             }

+ 2 - 2
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 + "'");