tisp

tiny lisp
git clone git://edryd.org/tisp
Log | Files | Refs | LICENSE

commit 5fa86a458d383918eeb515c7b16d98501b51a828
parent b13a59fb6ab6f57c269e0ac2aceb8202dfbac01c
Author: Ed van Bruggen <edvb@uw.edu>
Date:   Fri, 24 Aug 2018 14:30:42 -0700

Add tisp_env_free()

Diffstat:
main.c | 2++
tisp.c | 19+++++++++++++++++++
tisp.h | 1+
3 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/main.c b/main.c @@ -83,5 +83,7 @@ main(int argc, char *argv[]) if (!*str.d) break; } + tisp_env_free(env); + return 0; } diff --git a/tisp.c b/tisp.c @@ -701,6 +701,25 @@ tisp_env_init(size_t cap) } void +tisp_env_free(Env env) +{ + int i; + Hash h; + + for (h = env->h; h; h = h->next) { + for (i = 0; i < h->cap; i++) + if (h->items[i].key) + free(h->items[i].val); + free(h->items); + } + free(env->h); + for (i = 0; i < env->libhc; i++) + dlclose(env->libh[i]); + free(env->nil); + free(env); +} + +void val_free(Val v) { if (v->t == PAIR) { diff --git a/tisp.h b/tisp.h @@ -132,3 +132,4 @@ void tisp_print(Val v); Val tisp_eval(Env env, Val v); Env tisp_env_init(size_t cap); +void tisp_env_free(Env env);