gc.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #ifndef VIRTUALMATH_GC_H
  2. #define VIRTUALMATH_GC_H
  3. struct Inter;
  4. struct Value;
  5. struct LinkValue;
  6. struct HashTable;
  7. struct Var;
  8. struct VarList;
  9. #if START_GC
  10. struct GCStatus{
  11. long int tmp_link; // tmp link的次数
  12. long int statement_link; // statement link的次数
  13. long int link; // 被直接link的次数
  14. enum {
  15. not_free,
  16. run_del,
  17. need_free,
  18. } c_value; // value的计数 (先call __del__ 后释放)
  19. bool continue_; // 是否迭代过
  20. };
  21. #else
  22. struct GCStatus {};
  23. #endif
  24. typedef struct GCStatus GCStatus;
  25. #if START_GC
  26. #define gc_addTmpLink(gcs) ((gcs)->tmp_link ++)
  27. #define gc_addStatementLink(gcs) ((gcs)->statement_link ++)
  28. #define gc_addLink(gcs) ((gcs)->link ++)
  29. #define gc_freeTmpLink(gcs) ((gcs)->tmp_link --)
  30. #define gc_freeStatementLink(gcs) ((gcs)->statement_link --)
  31. #define setGC(gcs) ((gcs)->continue_ = false, (gcs)->link = 0, (gcs)->tmp_link = 0, (gcs)->statement_link = 0, (gcs)->c_value = not_free)
  32. void gc_runDelAll(struct Inter *inter);
  33. void gc_run(struct Inter *inter, struct VarList *run_var);
  34. #else
  35. #define gc_addTmpLink(gcs) ((void)0)
  36. #define gc_addStatementLink(gcs) ((void)0)
  37. #define gc_addLink(gcs) ((void)0)
  38. #define gc_freeTmpLink(gcs) ((void)0)
  39. #define gc_freeStatementLink(gcs) ((void)0)
  40. #define setGC(...) ((void)0)
  41. #define gc_run(...) ((void)0)
  42. #define gc_runDelAll(...) ((void)0)
  43. #endif
  44. #endif //VIRTUALMATH_GC_H