1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub enum GcObjectType {
4 MonkeyObject,
5 FunctionBytecode,
6 Shape,
7 VarRef,
8 AsyncFunction,
9 MonkeyContext,
10}
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq)]
15pub enum GcPhase {
16 None,
17 Decref,
18 RemoveCycles,
19}
20
21#[derive(Debug, Clone, Copy, PartialEq, Eq)]
23pub enum GcListKind {
24 GcObj,
25 Tmp,
26 ZeroRef,
27}
28
29#[derive(Debug, Clone)]
32pub struct GcObjectHeader {
33 pub ref_count: i32,
34 pub gc_obj_type: GcObjectType,
35 pub mark: u8,
37 pub free_mark: bool,
39 pub list_kind: Option<GcListKind>,
40 pub list_prev: Option<GcId>,
41 pub list_next: Option<GcId>,
42}
43
44#[derive(Debug, Clone)]
47pub struct RefCountHeader {
48 pub ref_count: i32,
49}
50
51pub type GcId = usize;
52pub type RefCountId = usize;
53
54impl GcObjectHeader {
55 pub fn new(gc_obj_type: GcObjectType, ref_count: i32) -> Self {
56 GcObjectHeader {
57 ref_count,
58 gc_obj_type,
59 mark: 0,
60 free_mark: false,
61 list_kind: None,
62 list_prev: None,
63 list_next: None,
64 }
65 }
66}
67
68impl RefCountHeader {
69 pub fn new(ref_count: i32) -> Self {
70 RefCountHeader {
71 ref_count,
72 }
73 }
74}