aboutsummaryrefslogtreecommitdiffstats
path: root/src/bootstrap/gc.h
blob: 90a1196e6840af42462de2b74ae29d007b878700 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#ifndef BDL_GC_H
#define BDL_GC_H

#include "objects.h"
#include "environment.h"

typedef struct FreeList {
    size_t *buf;
    size_t size;
    size_t cap;
    size_t position;
} FreeList;

typedef struct GC {
    Object **roots;
    Environment *envs;
    Object *objects;
    FreeList free_objects;
    FreeList free_envs;
    Environment **active_envs;
} GC;

void init_gc(void);

// Allocation functions for objects and environments.
Object * alloc_object(ObjectType type);
Environment * alloc_env(void);

// Root and environment protector functions.
void push_root(Object *obj);
Object * pop_root(void);
void push_active_env(Environment *env);
Environment * pop_active_env(void);

// Mark and sweep algorithm functions.
void mark_environment(Environment *env);
void mark_obj(Object *obj);
void mark_and_sweep(void);

// Debugging function to print out the contentes of some GC fields.
void dump_gc(void);

#define GC_OBJS_CAP  1024 * 1024
#define GC_ROOTS_CAP 1024
#define GC_ACTIVE_ENVS_CAP 2
#define GC_ENVS_CAP  1024 * 4

#endif // BDL_GC_H