This commit is contained in:
blueloveTH 2023-07-09 01:03:14 +08:00
parent a06a8918ce
commit 383a6d3194

View File

@ -35,7 +35,7 @@
#define THREAD_LOCAL thread_local #define THREAD_LOCAL thread_local
#include <mutex> #include <mutex>
struct PK_EXPORT GIL { struct GIL {
inline static std::mutex _mutex; inline static std::mutex _mutex;
explicit GIL() { _mutex.lock(); } explicit GIL() { _mutex.lock(); }
~GIL() { _mutex.unlock(); } ~GIL() { _mutex.unlock(); }
@ -59,7 +59,7 @@ template <size_t T>
struct NumberTraits; struct NumberTraits;
template <> template <>
struct PK_EXPORT NumberTraits<4> { struct NumberTraits<4> {
using int_t = int32_t; using int_t = int32_t;
using float_t = float; using float_t = float;
@ -74,7 +74,7 @@ struct PK_EXPORT NumberTraits<4> {
}; };
template <> template <>
struct PK_EXPORT NumberTraits<8> { struct NumberTraits<8> {
using int_t = int64_t; using int_t = int64_t;
using float_t = double; using float_t = double;
@ -96,13 +96,13 @@ static_assert(sizeof(i64) == sizeof(void*));
static_assert(sizeof(f64) == sizeof(void*)); static_assert(sizeof(f64) == sizeof(void*));
static_assert(std::numeric_limits<f64>::is_iec559); static_assert(std::numeric_limits<f64>::is_iec559);
struct PK_EXPORT Dummy { }; struct Dummy { };
struct PK_EXPORT DummyInstance { }; struct DummyInstance { };
struct PK_EXPORT DummyModule { }; struct DummyModule { };
struct PK_EXPORT NoReturn { }; struct NoReturn { };
struct PK_EXPORT Discarded { }; struct Discarded { };
struct PK_EXPORT Type { struct Type {
int index; int index;
Type(): index(-1) {} Type(): index(-1) {}
Type(int index): index(index) {} Type(int index): index(index) {}
@ -125,27 +125,27 @@ struct PK_EXPORT Type {
struct PyObject; struct PyObject;
#define PK_BITS(p) (reinterpret_cast<i64>(p)) #define PK_BITS(p) (reinterpret_cast<i64>(p))
PK_EXPORT inline bool is_tagged(PyObject* p) noexcept { return (PK_BITS(p) & 0b11) != 0b00; } inline bool is_tagged(PyObject* p) noexcept { return (PK_BITS(p) & 0b11) != 0b00; }
PK_EXPORT inline bool is_int(PyObject* p) noexcept { return (PK_BITS(p) & 0b11) == 0b01; } inline bool is_int(PyObject* p) noexcept { return (PK_BITS(p) & 0b11) == 0b01; }
PK_EXPORT inline bool is_float(PyObject* p) noexcept { return (PK_BITS(p) & 0b11) == 0b10; } inline bool is_float(PyObject* p) noexcept { return (PK_BITS(p) & 0b11) == 0b10; }
PK_EXPORT inline bool is_special(PyObject* p) noexcept { return (PK_BITS(p) & 0b11) == 0b11; } inline bool is_special(PyObject* p) noexcept { return (PK_BITS(p) & 0b11) == 0b11; }
PK_EXPORT inline bool is_both_int_or_float(PyObject* a, PyObject* b) noexcept { inline bool is_both_int_or_float(PyObject* a, PyObject* b) noexcept {
return is_tagged(a) && is_tagged(b); return is_tagged(a) && is_tagged(b);
} }
PK_EXPORT inline bool is_both_int(PyObject* a, PyObject* b) noexcept { inline bool is_both_int(PyObject* a, PyObject* b) noexcept {
return is_int(a) && is_int(b); return is_int(a) && is_int(b);
} }
PK_EXPORT inline bool is_both_float(PyObject* a, PyObject* b) noexcept { inline bool is_both_float(PyObject* a, PyObject* b) noexcept {
return is_float(a) && is_float(b); return is_float(a) && is_float(b);
} }
// special singals, is_tagged() for them is true // special singals, is_tagged() for them is true
PK_EXPORT inline PyObject* const PY_NULL = (PyObject*)0b000011; // tagged null inline PyObject* const PY_NULL = (PyObject*)0b000011; // tagged null
PK_EXPORT inline PyObject* const PY_OP_CALL = (PyObject*)0b100011; inline PyObject* const PY_OP_CALL = (PyObject*)0b100011;
PK_EXPORT inline PyObject* const PY_OP_YIELD = (PyObject*)0b110011; inline PyObject* const PY_OP_YIELD = (PyObject*)0b110011;
#define ADD_MODULE_PLACEHOLDER(name) namespace pkpy { inline void add_module_##name(void* vm) { (void)vm; } } #define ADD_MODULE_PLACEHOLDER(name) namespace pkpy { inline void add_module_##name(void* vm) { (void)vm; } }