base.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include "stdint.h"
  3. #include "stdbool.h"
  4. #include "stdlib.h"
  5. #include "assert.h"
  6. #include "string.h"
  7. #include "pocketpy/common/utils.h"
  8. #include "pocketpy/pocketpy.h"
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12. typedef int16_t py_Type;
  13. typedef struct PyObject PyObject;
  14. typedef struct py_TValue{
  15. py_Type type;
  16. bool is_ptr;
  17. int extra;
  18. union {
  19. int64_t _i64;
  20. double _f64;
  21. PyObject* _obj;
  22. void* _ptr;
  23. // Vec2
  24. };
  25. } py_TValue;
  26. static_assert(sizeof(py_TValue) <= 16, "!sizeof(py_TValue) <= 16");
  27. /* predefined vars */
  28. static const py_Type tp_object = {1}, tp_type = {2};
  29. static const py_Type tp_int = {3}, tp_float = {4}, tp_bool = {5}, tp_str = {6};
  30. static const py_Type tp_list = {7}, tp_tuple = {8};
  31. static const py_Type tp_slice = {9}, tp_range = {10}, tp_module = {11};
  32. static const py_Type tp_function = {12}, tp_nativefunc = {13}, tp_bound_method = {14};
  33. static const py_Type tp_super = {15}, tp_exception = {16}, tp_bytes = {17}, tp_mappingproxy = {18};
  34. static const py_Type tp_dict = {19}, tp_property = {20}, tp_star_wrapper = {21};
  35. static const py_Type tp_staticmethod = {22}, tp_classmethod = {23};
  36. static const py_Type tp_none_type = {24}, tp_not_implemented_type = {25};
  37. static const py_Type tp_ellipsis = {26};
  38. static const py_Type tp_op_call = {27}, tp_op_yield = {28};
  39. static const py_Type tp_syntax_error = {29}, tp_stop_iteration = {30};
  40. extern py_TValue PY_NULL, PY_OP_CALL, PY_OP_YIELD;
  41. #ifdef __cplusplus
  42. }
  43. #endif
  44. /*
  45. SSO types:
  46. 1. int64_t
  47. 2. double
  48. 3. bool (dummy)
  49. 4. tuple (extra + void*)
  50. 5. string (extra + void* or buf)
  51. */