diff --git a/include/alisp/lisp.h b/include/alisp/lisp.h index ce52176..94f2caf 100644 --- a/include/alisp/lisp.h +++ b/include/alisp/lisp.h @@ -49,6 +49,8 @@ vec_t *as_vec(lisp_t *); lisp_t *car(lisp_t *); lisp_t *cdr(lisp_t *); +void lisp_free(lisp_t *); + #endif /* Copyright (C) 2026 Aryadev Chavali diff --git a/src/lisp.c b/src/lisp.c index 6a6f388..a180928 100644 --- a/src/lisp.c +++ b/src/lisp.c @@ -34,26 +34,7 @@ void sys_free(sys_t *sys) for (size_t i = 0; i < VEC_SIZE(&sys->memory, lisp_t **); ++i) { lisp_t *allocated = VEC_GET(&sys->memory, i, lisp_t *); - switch (get_tag(allocated)) - { - case TAG_CONS: - // Delete the cons - free(as_cons(allocated)); - break; - case TAG_VEC: - { - vec_t *vec = as_vec(allocated); - vec_free(vec); - free(vec); - break; - } - case TAG_NIL: - case TAG_INT: - case TAG_SYM: - case NUM_TAGS: - // shouldn't be dealt with (either constant or dealt with elsewhere) - break; - } + lisp_free(allocated); } // Free the container @@ -110,6 +91,30 @@ lisp_t *cdr(lisp_t *lsp) return CDR(lsp); } +void lisp_free(lisp_t *item) +{ + switch (get_tag(item)) + { + case TAG_CONS: + // Delete the cons + free(as_cons(item)); + break; + case TAG_VEC: + { + vec_t *vec = as_vec(item); + vec_free(vec); + free(vec); + break; + } + case TAG_NIL: + case TAG_INT: + case TAG_SYM: + case NUM_TAGS: + // shouldn't be dealt with (either constant or dealt with elsewhere) + break; + } +} + /* Copyright (C) 2025, 2026 Aryadev Chavali * This program is distributed in the hope that it will be useful, but WITHOUT