#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GcObjectType {
MonkeyObject,
FunctionBytecode,
Shape,
VarRef,
AsyncFunction,
MonkeyContext,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GcPhase {
None,
Decref,
RemoveCycles,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum GcListKind {
GcObj,
Tmp,
ZeroRef,
}
#[derive(Debug, Clone)]
pub struct GcObjectHeader {
pub ref_count: i32,
pub gc_obj_type: GcObjectType,
pub mark: u8,
pub free_mark: bool,
pub list_kind: Option<GcListKind>,
pub list_prev: Option<GcId>,
pub list_next: Option<GcId>,
}
#[derive(Debug, Clone)]
pub struct RefCountHeader {
pub ref_count: i32,
}
pub type GcId = usize;
pub type RefCountId = usize;
impl GcObjectHeader {
pub fn new(gc_obj_type: GcObjectType, ref_count: i32) -> Self {
GcObjectHeader {
ref_count,
gc_obj_type,
mark: 0,
free_mark: false,
list_kind: None,
list_prev: None,
list_next: None,
}
}
}
impl RefCountHeader {
pub fn new(ref_count: i32) -> Self {
RefCountHeader {
ref_count,
}
}
}