object.h 739 B

123456789101112131415161718192021222324252627
  1. #pragma once
  2. #include "pocketpy/objects/namedict.h"
  3. #include "pocketpy/objects/base.h"
  4. typedef struct PyObject {
  5. py_Type type; // we have a duplicated type here for convenience
  6. // bool _;
  7. bool gc_marked;
  8. int slots; // number of slots in the object
  9. char flex[];
  10. } PyObject;
  11. // slots >= 0, allocate N slots
  12. // slots == -1, allocate a dict
  13. // | HEADER | <N slots> | <userdata>
  14. // | HEADER | <dict> | <userdata>
  15. py_TValue* PyObject__slots(PyObject* self);
  16. NameDict* PyObject__dict(PyObject* self);
  17. void* PyObject__userdata(PyObject* self);
  18. #define PK_OBJ_SLOTS_SIZE(slots) ((slots) >= 0 ? sizeof(py_TValue) * (slots) : sizeof(NameDict))
  19. void PyObject__dtor(PyObject* self);
  20. void PyObject__mark(PyObject* self);