pyvar.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #ifdef __cplusplus
  3. extern "C" {
  4. #endif
  5. #include <stdbool.h>
  6. #include <stdint.h>
  7. /**
  8. * @brief A python value in pocketpy.
  9. */
  10. typedef struct {
  11. int type;
  12. int _0;
  13. int64_t _1;
  14. } pkpy_Var;
  15. /**
  16. * @brief Check if the pkpy_Var is null.
  17. * @param self The variable to check.
  18. * @return True if the variable is null, false otherwise.
  19. */
  20. #define pkpy_Var__is_null(self) ((self)->type == 0)
  21. /**
  22. * @brief Set the variable to null.
  23. * @param self The variable to set.
  24. */
  25. #define pkpy_Var__set_null(self) do { (self)->type = 0; } while(0)
  26. /**
  27. * @brief Check if two pkpy_Vars are equal, respects to __eq__ method.
  28. * @param vm The virtual machine.
  29. * @param a The first pkpy_Var.
  30. * @param b The second pkpy_Var.
  31. * @return True if the pkpy_Vars are equal, false otherwise.
  32. */
  33. bool pkpy_Var__eq__(void *vm, pkpy_Var a, pkpy_Var b);
  34. /**
  35. * @brief Get the hash of the pkpy_Var, respects to __hash__ method.
  36. * @param vm The virtual machine.
  37. * @param a The pkpy_Var to hash.
  38. * @return The hash of the pkpy_Var.
  39. */
  40. int64_t pkpy_Var__hash__(void *vm, pkpy_Var a);
  41. #ifdef __cplusplus
  42. }
  43. #endif