This commit is contained in:
blueloveTH 2024-05-13 18:03:56 +08:00
parent 1714195da4
commit 393952d800
2 changed files with 10 additions and 1 deletions

View File

@ -219,6 +219,9 @@ struct PyVar final{
} }
i64 hash() const { return as<i64>(); } i64 hash() const { return as<i64>(); }
template<typename T>
T& obj_get();
}; };
static_assert(sizeof(PyVar) == 16 && is_pod_v<PyVar>); static_assert(sizeof(PyVar) == 16 && is_pod_v<PyVar>);

View File

@ -165,8 +165,14 @@ StrName _type_name(VM* vm, Type type);
template<typename T> T to_void_p(VM*, PyVar); template<typename T> T to_void_p(VM*, PyVar);
PyVar from_void_p(VM*, void*); PyVar from_void_p(VM*, void*);
template<typename T>
T& PyVar::obj_get(){
static_assert(!std::is_reference_v<T>);
if(is_sso) return as<T>();
return ((Py_<T>*)(get()))->_value;
}
#define PK_OBJ_GET(T, obj) (is_sso_v<T> ? obj.as<T>() : (((Py_<T>*)(obj.get()))->_value)) #define PK_OBJ_GET(T, obj) (obj).obj_get<T>()
#define PK_OBJ_MARK(obj) \ #define PK_OBJ_MARK(obj) \
if(!is_tagged(obj) && !(obj)->gc_marked) { \ if(!is_tagged(obj) && !(obj)->gc_marked) { \