-
Notifications
You must be signed in to change notification settings - Fork 0
/
gc.c
53 lines (44 loc) · 769 Bytes
/
gc.c
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
#include <stdio.h>
#include "gc.h"
#include "mark_and_sweep.h"
word * root[ROOT_SIZE];
word rootp;
word mem[MEMORY_SIZE];
word freeStart;
word marked;
word cnt;
word swept;
void mem_init()
{
mem[0] = WORD_OF_DATA(MEMORY_SIZE);
mem[1] = WORD_OF_POINTER(null);
freeStart = 0;
rootp = 0;
}
void gc() {
printf("\nGC!\n");
mark();
sweep();
}
void root_add (word *p)
{
assert(rootp < ROOT_SIZE);
root[rootp++] = p;
}
void root_pop (int n)
{
assert(n <= rootp);
rootp -= n;
}
void print_free ()
{
// no need to keep track of rootset
word list = freeStart;
printf("free: [");
while (list != null) {
word x = DATA_OF_WORD(mem[list]);
printf("(%d, %d)", list, x);
list = POINTER_OF_WORD(mem[list+1]);
}
printf("]\n");
}