Add necessary structs and functions

This commit is contained in:
flameyosflow 2025-12-17 10:34:54 +02:00
commit 798434a55d

View file

@ -15,6 +15,8 @@
/* Forward declare Obj so ObjHeader can reference it */ /* Forward declare Obj so ObjHeader can reference it */
typedef struct Obj Obj; typedef struct Obj Obj;
typedef struct TypeInfo TypeInfo;
/* Header must come first */ /* Header must come first */
typedef struct ObjHeader { typedef struct ObjHeader {
uint32_t size; // total object size incl header uint32_t size; // total object size incl header
@ -24,11 +26,11 @@ typedef struct ObjHeader {
const TypeInfo *type; const TypeInfo *type;
} ObjHeader; } ObjHeader;
typedef struct TypeInfo { struct TypeInfo {
uint16_t field_count; uint16_t field_count;
uint16_t pointer_count; uint16_t pointer_count;
const uint8_t *pointer_bitmap; const uint8_t *pointer_bitmap;
} TypeInfo; };
/* Full object definition */ /* Full object definition */
struct Obj { struct Obj {
@ -44,7 +46,7 @@ void gc_init(void);
void gc_shutdown(void); void gc_shutdown(void);
// Allocate object in young generation // Allocate object in young generation
void* gc_alloc(size_t size); void *gc_alloc(const TypeInfo *type, size_t payload_size);
// Root management // Root management
void gc_add_root(void **ptr); void gc_add_root(void **ptr);
@ -56,7 +58,13 @@ void gc_write_barrier(void *src, void *dst);
// Minor GC slice (incremental) // Minor GC slice (incremental)
void gc_minor_collect_slice(size_t max_objects); void gc_minor_collect_slice(size_t max_objects);
// Trigger major GC (async background) // Trigger major GC
void gc_major_collect(void); void gc_major_collect(void);
static inline void scan_object_fields(Obj *obj);
static void mark_obj(Obj *obj);
void gc_collect_old(void);
#endif // SUICMEZ_GC_H #endif // SUICMEZ_GC_H