-
Notifications
You must be signed in to change notification settings - Fork 1
/
gc.spl
63 lines (55 loc) · 857 Bytes
/
gc.spl
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
Int _bssSize() {}
Int _bss(Int pos) {}
Int _stackSize() {}
Int _stack(Int pos) {}
Void _touch(t obj) {}
Bool _valid(Int val) {}
(Int,Int) _read(Int addr) {}
Int _reinitHeap() {}
Void _mkAvail(Int pos) {}
Bool _reached(Int pos) {}
Void gc_mark(Int addr)
{
while(_valid(addr)) {
(Int,Int) cell = _read(addr);
_touch(cell);
gc_mark(fst(cell));
addr = snd(cell);
}
}
Void gc_sweep()
{
Int i = _reinitHeap();
while(i > 0) {
i = i-1;
if(!_reached(i)) _mkAvail(i);
}
}
Void gc_collect()
{
Int i = _stackSize();
while(i > 0) {
i = i - 1;
gc_mark(_stack(i));
}
i = _bssSize();
while(i > 0) {
i = i - 1;
gc_mark(_bss(i));
}
gc_sweep();
}
Void doNothing(u x)
{
return;
}
Void main()
{
Int i = 0;
while(True) {
doNothing(1:2:3:4:[]);
print(i);
i=i+1;
if(i%500==0) gc_collect();
}
}