diff options
| author | Rose Hogenson <rhogenson@posteo.net> | 2023-02-11 13:40:10 -0800 |
|---|---|---|
| committer | Rose Hogenson <rhogenson@posteo.net> | 2023-02-11 13:40:10 -0800 |
| commit | 60622614731bc42dd44704d3cff55b4e4c4f492c (patch) | |
| tree | dcf3b31f46c1b46e23d5c379a9201195ccb4f1ce /bytecode/heap.h | |
| parent | Avoid copies when writing to buffer. (diff) | |
| download | sml-60622614731bc42dd44704d3cff55b4e4c4f492c.tar.zst | |
Write a garbage collector.
Does it work? No, but it compiles.
Diffstat (limited to 'bytecode/heap.h')
| -rw-r--r-- | bytecode/heap.h | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/bytecode/heap.h b/bytecode/heap.h new file mode 100644 index 0000000..c8d7e2c --- /dev/null +++ b/bytecode/heap.h @@ -0,0 +1,27 @@ +#ifndef _HEAP_H_ +#define _HEAP_H_ + +#include <stddef.h> +#include <stdint.h> + +#include "slice.h" +#include "value.h" + +struct heap { + // The heap is divided into two halves for garbage collection. + // buf holds the malloc'd heap buffer. + value *buf; + // active and standby are slices that partition buf. + struct val_slice active; + struct val_slice standby; + + size_t free_ptr; + + size_t last_free; + struct val_slice gc_roots; +}; + +struct heap new_heap(struct val_slice); +value *alloc(struct heap *, int64_t); + +#endif |
