diff --git a/src/evaluate.c b/src/evaluate.c index b2bf64b..27f462c 100644 --- a/src/evaluate.c +++ b/src/evaluate.c @@ -40,13 +40,10 @@ struct ucl_object *ucl_evaluate_builtin_form(struct ucl_scope *scope, struct ucl assert(0); } - // TODO: cleanup - return (result == NULL) ? ucl_nil_create() : result; } struct ucl_object *ucl_evaluate_special_form(struct ucl_scope *scope, struct ucl_object *list) { - // TODO: Recursively eval args const char *fun_sym = ucl_car(list)->symbol; struct ucl_object *fun = ucl_scope_get(scope, fun_sym); @@ -72,7 +69,6 @@ struct ucl_object *ucl_evaluate_list(struct ucl_scope *scope, struct ucl_object return ucl_evaluate_builtin_form(scope, list); } else { assert(0); - // TODO: Lisp functions and other errors } } diff --git a/src/internal.h b/src/internal.h index ec36301..4f70f83 100644 --- a/src/internal.h +++ b/src/internal.h @@ -15,7 +15,6 @@ // TODO: Refactor this struct's location struct ucl_scope { - // TODO: For garbage collection, we need references from the parent->child state struct ucl_object *list; struct ucl_scope *parent; }; diff --git a/src/main.c b/src/main.c index bc7dcc9..2889ec1 100644 --- a/src/main.c +++ b/src/main.c @@ -67,7 +67,6 @@ int main(int argc, const char **argv) { // TODO: // - reduce - // - booleans (e.g. not) if (argc < 2) { while (1) { diff --git a/src/memory.c b/src/memory.c index e21d11b..89ca42b 100644 --- a/src/memory.c +++ b/src/memory.c @@ -122,7 +122,7 @@ void ucl_object_delete(struct ucl_object *obj) { ucl_arena_put(object_arena, obj); } -void ucl_object_mark(struct ucl_object *obj) { +static void ucl_object_mark(struct ucl_object *obj) { if (obj == NULL || obj->reachable) { return; } @@ -134,34 +134,45 @@ void ucl_object_mark(struct ucl_object *obj) { } } -void ucl_scope_mark(struct ucl_arena * arena, void *obj) { +static void ucl_scope_mark(struct ucl_arena * arena, void *obj) { (void) arena; struct ucl_scope *scope = (struct ucl_scope *) obj; ucl_object_mark(scope->list); } -void ucl_gc_unmark(struct ucl_arena * arena, void *obj) { +static void ucl_gc_unmark(struct ucl_arena * arena, void *obj) { (void) arena; struct ucl_object *object = (struct ucl_object *) obj; object->reachable = 0; } -void ucl_gc_sweep(struct ucl_arena * arena, void *obj) { +static void ucl_gc_sweep(struct ucl_arena * arena, void *obj) { (void) arena; struct ucl_object *object = (struct ucl_object *) obj; if (object->reachable == 0) { - // TODO: Mapping across this is broken, since this is a recursive delete - ucl_object_delete(object); + ucl_object_delete(object); } } +static void ucl_gc_deleteall(struct ucl_arena * arena, void *obj) { + (void) arena; + struct ucl_object *object = (struct ucl_object *) obj; + ucl_object_delete(object); +} void ucl_gc() { - ucl_arena_map(object_arena, ucl_gc_unmark); + if (object_arena == NULL) { + return; + } - ucl_arena_map(scope_arena, ucl_scope_mark); + if (scope_arena != NULL) { + ucl_arena_map(object_arena, ucl_gc_unmark); + ucl_arena_map(scope_arena, ucl_scope_mark); + ucl_arena_map(object_arena, ucl_gc_sweep); + } else { + ucl_arena_map(object_arena, ucl_gc_deleteall); + } - ucl_arena_map(object_arena, ucl_gc_sweep); } diff --git a/src/special.c b/src/special.c index afcf1fb..170321b 100644 --- a/src/special.c +++ b/src/special.c @@ -21,7 +21,6 @@ struct ucl_object *ucl_special_let(struct ucl_scope *scope, struct ucl_object *a //assert(ucl_list_length(expr)->integer == 1); if (value->type == UCL_TYPE_ERROR) { - // TODO cleanup ucl_scope_delete(let_scope); return value; } diff --git a/test/test_e2e.c b/test/test_e2e.c index 2eca5ca..8f29304 100644 --- a/test/test_e2e.c +++ b/test/test_e2e.c @@ -34,11 +34,10 @@ void setUp(void) { } void tearDown(void) { - // TODO: Implement GC so we can clean these both up - //ucl_object_delete(input); - input = NULL; ucl_scope_delete(scope); ucl_gc(); + + input = NULL; response = NULL; scope = NULL; } diff --git a/test/test_parse.c b/test/test_parse.c index 5b05fb4..fe74e17 100644 --- a/test/test_parse.c +++ b/test/test_parse.c @@ -13,7 +13,8 @@ void setUp(void) { } void tearDown(void) { - ucl_object_delete(response); + ucl_gc(); + response = NULL; } static void test_token_next_empty_str(void) { diff --git a/test/test_scope.c b/test/test_scope.c index bc7cb52..a329f8b 100644 --- a/test/test_scope.c +++ b/test/test_scope.c @@ -18,6 +18,7 @@ void setUp(void) { void tearDown(void) { ucl_scope_delete(scope); + ucl_gc(); scope = NULL; } diff --git a/test/test_utility.c b/test/test_utility.c index 819e6a7..aa9ad18 100644 --- a/test/test_utility.c +++ b/test/test_utility.c @@ -17,10 +17,9 @@ void setUp(void) { } void tearDown(void) { - // TODO: Implement GC so we can clean these both up - //ucl_object_delete(input); + ucl_gc(); + input = NULL; - ucl_object_delete(response); response = NULL; }