blob: f3d01dba0c740e50e895a7c341d6644330205157 [file] [log] [blame]
swissChili6d6525e2021-06-15 21:20:53 -07001#include "gc.h"
2#include "lisp.h"
3
swissChili9e57da42021-06-15 22:22:46 -07004value_t *gc_base;
swissChili6d6525e2021-06-15 21:20:53 -07005
swissChili9e57da42021-06-15 22:22:46 -07006void __attribute__((noinline)) gc_set_base_here()
7{
8 // Move the current stack top address to gc_base. This works nicely because
9 // it means that when another (presumably lisp) function is called right
10 // after this, the stack top for it will be the same as for this function.
11 asm("movl %%esp, %0" : "=g"(gc_base));
12}
13
14void _mark(value_t value)
15{
16 if (heapp(value))
17 {
18
19 }
swissChili6d6525e2021-06-15 21:20:53 -070020}
21
22void _sweep()
23{
24
25}
26
27void _do_gc(unsigned int esp, unsigned int ebp)
28{
swissChili9e57da42021-06-15 22:22:46 -070029 value_t *esp_p = (value_t *)esp,
30 *ebp_p = (value_t *)ebp;
swissChili6d6525e2021-06-15 21:20:53 -070031
swissChili9e57da42021-06-15 22:22:46 -070032 int num_marked = 0;
33
34 // For every stack frame until the base of the stack
35 while (esp_p < gc_base)
swissChili6d6525e2021-06-15 21:20:53 -070036 {
swissChili9e57da42021-06-15 22:22:46 -070037 // Walk up the stack until we reach either the frame pointer or the base
38 // of the stack. Basically walk to the top of this function's stack
39 // frame.
40 for (; esp_p < ebp_p && esp_p < gc_base; esp_p++)
41 {
42 _mark(*esp_p);
43 num_marked++;
44 }
45
46 // Set the frame pointer to the frame pointer on the stack
47 ebp_p = (value_t *)*esp_p;
48
49 // Step up two stack slots, one for the frame pointer and one for the
50 // return address.
51 esp_p += 2;
swissChili6d6525e2021-06-15 21:20:53 -070052 }
swissChili9e57da42021-06-15 22:22:46 -070053
54 fprintf(stderr, "Marked %d\n", num_marked);
swissChili6d6525e2021-06-15 21:20:53 -070055}