lisp-take-1/gc/free.c
2024-11-28 18:36:25 -06:00

51 lines
896 B
C

#include <debug.h>
#include <value/struct.h>
#include <value/shallow_free.h>
#include "dotout.h"
#include "flags.h"
#include "struct.h"
#include "free.h"
void free_gc(
struct gc* this)
{
ENTER;
#ifdef DOTOUT_BUILD
if (this->flags->dotout)
{
gc_dotout(this, "free_gc: bye!");
}
#endif
for (size_t i = 0; i < this->blocks.n; i++)
{
struct block_info info = this->blocks.data[i];
struct value* start = info.start;
for (size_t j = 0, m = info.cap; j < m; j++)
{
struct value* value = &start[j];
dpvp(value);
if (!value->reaped.in_set)
{
shallow_free_value(value);
}
}
free(info.start);
}
free(this->blocks.data);
free(this);
EXIT;
}