mirror of
https://github.com/pocketpy/pocketpy
synced 2025-12-07 10:40:16 +00:00
some fix
This commit is contained in:
parent
26815fae74
commit
d21a9cffab
@ -34,7 +34,6 @@ typedef struct PyVar{
|
|||||||
static_assert(sizeof(PyVar) == 16, "sizeof(PyVar) != 16");
|
static_assert(sizeof(PyVar) == 16, "sizeof(PyVar) != 16");
|
||||||
|
|
||||||
PK_INLINE bool PyVar__is_null(const PyVar* self) { return self->type == 0; }
|
PK_INLINE bool PyVar__is_null(const PyVar* self) { return self->type == 0; }
|
||||||
PK_INLINE PyObject* PyVar__get(const PyVar* self) { return self->_obj; }
|
|
||||||
PK_INLINE int64_t PyVar__hash(const PyVar* self) { return self->flags_ex + self->_i64; }
|
PK_INLINE int64_t PyVar__hash(const PyVar* self) { return self->flags_ex + self->_i64; }
|
||||||
|
|
||||||
PK_INLINE bool PyVar__less(const PyVar* self, const PyVar* other){
|
PK_INLINE bool PyVar__less(const PyVar* self, const PyVar* other){
|
||||||
@ -52,6 +51,8 @@ PK_INLINE void PyVar__ctor(PyVar* self, pkpy_Type type, PyObject* obj){
|
|||||||
self->_obj = obj;
|
self->_obj = obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PyVar__ctor2(PyVar* self, PyObject* existing);
|
||||||
|
|
||||||
#define pkpy_Var__is_null(self) ((self)->type == 0)
|
#define pkpy_Var__is_null(self) ((self)->type == 0)
|
||||||
#define pkpy_Var__set_null(self) do { (self)->type = 0; } while(0)
|
#define pkpy_Var__set_null(self) do { (self)->type = 0; } while(0)
|
||||||
bool pkpy_Var__eq__(void *vm, PyVar a, PyVar b);
|
bool pkpy_Var__eq__(void *vm, PyVar a, PyVar b);
|
||||||
|
|||||||
@ -25,7 +25,9 @@ struct PyVar final: ::PyVar {
|
|||||||
PyVar() = default;
|
PyVar() = default;
|
||||||
|
|
||||||
// implict conversion
|
// implict conversion
|
||||||
PyVar(PyObject* p);
|
PyVar(PyObject* existing){
|
||||||
|
PyVar__ctor2(this, (::PyObject*)existing);
|
||||||
|
}
|
||||||
|
|
||||||
/* We must initialize all members to allow == operator to work correctly */
|
/* We must initialize all members to allow == operator to work correctly */
|
||||||
// zero initialized
|
// zero initialized
|
||||||
@ -35,11 +37,7 @@ struct PyVar final: ::PyVar {
|
|||||||
|
|
||||||
// PyObject* initialized (is_sso = false)
|
// PyObject* initialized (is_sso = false)
|
||||||
PyVar(Type type, PyObject* p){
|
PyVar(Type type, PyObject* p){
|
||||||
this->type = type;
|
PyVar__ctor(this, type, (::PyObject*)p);
|
||||||
this->is_ptr = true;
|
|
||||||
this->flags = 0;
|
|
||||||
this->flags_ex = 0;
|
|
||||||
this->_obj = (::PyObject*)p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SSO initialized (is_sso = true)
|
// SSO initialized (is_sso = true)
|
||||||
@ -67,20 +65,12 @@ struct PyVar final: ::PyVar {
|
|||||||
explicit operator bool () const { return (bool)type; }
|
explicit operator bool () const { return (bool)type; }
|
||||||
|
|
||||||
void set_null() {
|
void set_null() {
|
||||||
_qword(0) = 0;
|
memset(this, 0, sizeof(PyVar));
|
||||||
_qword(1) = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
i64 _qword(int i) const { return ((const i64*)this)[i]; }
|
bool operator== (const PyVar& other) const { return PyVar__equal(this, &other); }
|
||||||
|
bool operator!= (const PyVar& other) const { return !PyVar__equal(this, &other); }
|
||||||
i64& _qword(int i) { return ((i64*)this)[i]; }
|
|
||||||
|
|
||||||
bool operator== (const PyVar& other) const { return _qword(0) == other._qword(0) && _qword(1) == other._qword(1); }
|
|
||||||
|
|
||||||
bool operator!= (const PyVar& other) const { return _qword(0) != other._qword(0) || _qword(1) != other._qword(1); }
|
|
||||||
|
|
||||||
bool operator== (std::nullptr_t) const { return !(bool)type; }
|
bool operator== (std::nullptr_t) const { return !(bool)type; }
|
||||||
|
|
||||||
bool operator!= (std::nullptr_t) const { return (bool)type; }
|
bool operator!= (std::nullptr_t) const { return (bool)type; }
|
||||||
|
|
||||||
PyObject* get() const {
|
PyObject* get() const {
|
||||||
@ -99,7 +89,9 @@ struct PyVar final: ::PyVar {
|
|||||||
obj_get_t<T> obj_get();
|
obj_get_t<T> obj_get();
|
||||||
|
|
||||||
// std::less<> for map-like containers
|
// std::less<> for map-like containers
|
||||||
bool operator< (const PyVar& other) const { return memcmp(this, &other, sizeof(PyVar)) < 0; }
|
bool operator< (const PyVar& other) const {
|
||||||
|
return PyVar__less(this, &other);
|
||||||
|
}
|
||||||
|
|
||||||
// implicit convert from ::PyVar
|
// implicit convert from ::PyVar
|
||||||
PyVar(const ::PyVar& var) {
|
PyVar(const ::PyVar& var) {
|
||||||
|
|||||||
@ -26,16 +26,6 @@ PK_INLINE void PyObject__ctor(PyObject* self, pkpy_Type type, bool gc_is_large){
|
|||||||
self->_attr = NULL;
|
self->_attr = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
PK_INLINE PyVar PyVar__fromobj(PyObject* self){
|
|
||||||
PyVar var;
|
|
||||||
var.type = self->type;
|
|
||||||
var.is_ptr = true;
|
|
||||||
var.flags = 0;
|
|
||||||
var.flags_ex = 0;
|
|
||||||
var._obj = self;
|
|
||||||
return var;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -27,10 +27,7 @@ struct PyObject final: ::PyObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
PyObject(Type type, bool gc_is_large){
|
PyObject(Type type, bool gc_is_large){
|
||||||
this->type = type;
|
PyObject__ctor(this, type, gc_is_large);
|
||||||
this->gc_is_large = gc_is_large;
|
|
||||||
this->gc_marked = false;
|
|
||||||
this->_attr = nullptr;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
10
src/objects/object.c
Normal file
10
src/objects/object.c
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
#include "pocketpy/objects/object.h"
|
||||||
|
|
||||||
|
void PyVar__ctor2(PyVar* self, PyObject* existing){
|
||||||
|
assert(existing);
|
||||||
|
self->type = existing->type;
|
||||||
|
self->is_ptr = true;
|
||||||
|
self->flags = 0;
|
||||||
|
self->flags_ex = 0;
|
||||||
|
self->_obj = existing;
|
||||||
|
}
|
||||||
@ -1,5 +0,0 @@
|
|||||||
#include "pocketpy/objects/object.hpp"
|
|
||||||
|
|
||||||
namespace pkpy {
|
|
||||||
PyVar::PyVar(PyObject* p) : PyVar(p->type, p) {}
|
|
||||||
} // namespace pkpy
|
|
||||||
Loading…
x
Reference in New Issue
Block a user