aboutsummaryrefslogtreecommitdiffstats
path: root/src/bootstrap/gc.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/bootstrap/gc.h')
-rw-r--r--src/bootstrap/gc.h69
1 files changed, 69 insertions, 0 deletions
diff --git a/src/bootstrap/gc.h b/src/bootstrap/gc.h
new file mode 100644
index 0000000..038c820
--- /dev/null
+++ b/src/bootstrap/gc.h
@@ -0,0 +1,69 @@
1#ifndef BDL_GC_H
2#define BDL_GC_H
3
4#include "objects.h"
5#include "environment.h"
6
7// Stack of root nodes.
8typedef struct RootNodes {
9 Object **buf;
10 size_t size;
11 size_t cap;
12} RootNodes;
13
14// Stack of active environments.
15typedef struct ActiveEnvs {
16 Environment **buf;
17 size_t size;
18 size_t cap;
19} ActiveEnvs;
20
21typedef struct Environments {
22 Environment *buf;
23 size_t size;
24 size_t cap;
25} Environments;
26
27typedef struct FreeList {
28 size_t *buf;
29 size_t size;
30 size_t cap;
31 size_t position;
32} FreeList;
33
34typedef struct GC {
35 RootNodes roots;
36 Environments envs;
37 Object *objects;
38 size_t obj_cap;
39 FreeList free_objects;
40 FreeList free_envs;
41 ActiveEnvs active_envs;
42} GC;
43
44void init_gc(void);
45
46// Allocation functions for objects and environments.
47Object * alloc_object(ObjectType type);
48Environment * alloc_env(void);
49
50// Root and environment protector functions.
51void push_root(Object *obj);
52Object * pop_root(void);
53void push_active_env(Environment *env);
54Environment * pop_active_env(void);
55
56// Mark and sweep algorithm functions.
57void mark_environment(Environment *env);
58void mark_obj(Object *obj);
59void mark_and_sweep(void);
60
61// Debugging function to print out the contentes of some GC fields.
62void dump_gc(void);
63
64#define GC_OBJS_CAP 1024 * 1024
65#define GC_ROOTS_CAP 1024
66#define GC_ACTIVE_ENVS_CAP 2
67#define GC_ENVS_CAP 1024 * 4
68
69#endif // BDL_GC_H