mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-24 05:20:17 +00:00
Update obj.h
This commit is contained in:
parent
df91490d6a
commit
f57ca260ea
14
src/obj.h
14
src/obj.h
@ -68,27 +68,25 @@ typedef pkpy::shared_ptr<Function> _Func;
|
|||||||
typedef pkpy::shared_ptr<BaseIterator> _Iterator;
|
typedef pkpy::shared_ptr<BaseIterator> _Iterator;
|
||||||
|
|
||||||
struct PyObject {
|
struct PyObject {
|
||||||
protected:
|
|
||||||
void* _value;
|
|
||||||
public:
|
|
||||||
PyVar _type;
|
PyVar _type;
|
||||||
PyVarDict attribs;
|
PyVarDict attribs;
|
||||||
|
|
||||||
inline bool isType(const PyVar& type){ return this->_type == type; }
|
inline bool isType(const PyVar& type){ return this->_type == type; }
|
||||||
inline void* value(){ return _value; }
|
inline virtual void* value() = 0;
|
||||||
|
|
||||||
// currently __name__ is only used for 'type'
|
// currently __name__ is only used for 'type'
|
||||||
PyVar _typeName(){ return _type->attribs[__name__]; }
|
PyVar _typeName(){ return _type->attribs[__name__]; }
|
||||||
|
|
||||||
|
PyObject(PyVar type) : _type(type) {}
|
||||||
|
virtual ~PyObject() = default;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct Py_ : PyObject {
|
struct Py_ : PyObject {
|
||||||
T _valueT;
|
T _valueT;
|
||||||
|
|
||||||
Py_(T val, const PyVar& type) : _valueT(val) {
|
Py_(T val, const PyVar& type) : PyObject(type), _valueT(val) {}
|
||||||
_value = &_valueT;
|
virtual void* value() override { return &_valueT; }
|
||||||
_type = type;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#define UNION_GET(T, obj) (((Py_<T>*)((obj).get()))->_valueT)
|
#define UNION_GET(T, obj) (((Py_<T>*)((obj).get()))->_valueT)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user