aboutsummaryrefslogtreecommitdiffstats
path: root/src/bootstrap/gc.h
blob: 038c82087a49085c16b3e79b208c2a78cb2a5d48 (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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef BDL_GC_H
#define BDL_GC_H

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

// Stack of root nodes.
typedef struct RootNodes {
    Object **buf;
    size_t size;
    size_t cap;
} RootNodes;

// Stack of active environments.
typedef struct ActiveEnvs {
    Environment **buf;
    size_t size;
    size_t cap;
} ActiveEnvs;

typedef struct Environments {
    Environment *buf;
    size_t size;
    size_t cap;
} Environments;

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

typedef struct GC {
    RootNodes roots;
    Environments envs;
    Object *objects;
    size_t obj_cap;
    FreeList free_objects;
    FreeList free_envs;
    ActiveEnvs 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