|
|
@@ -67,22 +67,43 @@
|
|
|
|
|
|
#endif
|
|
|
|
|
|
-#if defined(__EMSCRIPTEN__) || defined(__arm__) || defined(__i386__)
|
|
|
-typedef int32_t i64;
|
|
|
-typedef float f64;
|
|
|
-#define S_TO_INT(...) static_cast<i64>(std::stoi(__VA_ARGS__))
|
|
|
-#define S_TO_FLOAT(...) static_cast<f64>(std::stof(__VA_ARGS__))
|
|
|
-#else
|
|
|
-typedef int64_t i64;
|
|
|
-typedef double f64;
|
|
|
-#define S_TO_INT(...) static_cast<i64>(std::stoll(__VA_ARGS__))
|
|
|
-#define S_TO_FLOAT(...) static_cast<f64>(std::stod(__VA_ARGS__))
|
|
|
-#endif
|
|
|
-
|
|
|
namespace pkpy{
|
|
|
|
|
|
namespace std = ::std;
|
|
|
|
|
|
+template <size_t T>
|
|
|
+struct NumberTraits;
|
|
|
+
|
|
|
+template <>
|
|
|
+struct NumberTraits<4> {
|
|
|
+ using int_t = int32_t;
|
|
|
+ using float_t = float;
|
|
|
+
|
|
|
+ template<typename... Args>
|
|
|
+ static int_t stoi(Args&&... args) { return std::stoi(std::forward<Args>(args)...); }
|
|
|
+ template<typename... Args>
|
|
|
+ static float_t stof(Args&&... args) { return std::stof(std::forward<Args>(args)...); }
|
|
|
+};
|
|
|
+
|
|
|
+template <>
|
|
|
+struct NumberTraits<8> {
|
|
|
+ using int_t = int64_t;
|
|
|
+ using float_t = double;
|
|
|
+
|
|
|
+ template<typename... Args>
|
|
|
+ static int_t stoi(Args&&... args) { return std::stoll(std::forward<Args>(args)...); }
|
|
|
+ template<typename... Args>
|
|
|
+ static float_t stof(Args&&... args) { return std::stod(std::forward<Args>(args)...); }
|
|
|
+};
|
|
|
+
|
|
|
+using Number = NumberTraits<sizeof(void*)>;
|
|
|
+using i64 = Number::int_t;
|
|
|
+using f64 = Number::float_t;
|
|
|
+
|
|
|
+static_assert(sizeof(i64) == sizeof(void*));
|
|
|
+static_assert(sizeof(f64) == sizeof(void*));
|
|
|
+static_assert(std::numeric_limits<f64>::is_iec559);
|
|
|
+
|
|
|
struct Dummy { };
|
|
|
struct DummyInstance { };
|
|
|
struct DummyModule { };
|
|
|
@@ -110,11 +131,6 @@ struct Type {
|
|
|
inline const float kInstAttrLoadFactor = 0.67f;
|
|
|
inline const float kTypeAttrLoadFactor = 0.5f;
|
|
|
|
|
|
-static_assert(sizeof(i64) == sizeof(int*));
|
|
|
-static_assert(sizeof(f64) == sizeof(int*));
|
|
|
-static_assert(std::numeric_limits<float>::is_iec559);
|
|
|
-static_assert(std::numeric_limits<double>::is_iec559);
|
|
|
-
|
|
|
struct PyObject;
|
|
|
#define BITS(p) (reinterpret_cast<i64>(p))
|
|
|
inline bool is_tagged(PyObject* p) noexcept { return (BITS(p) & 0b11) != 0b00; }
|