diff options
author | kartofen <mladenovnasko0@gmail.com> | 2024-08-25 12:30:48 +0300 |
---|---|---|
committer | kartofen <mladenovnasko0@gmail.com> | 2024-08-25 12:30:48 +0300 |
commit | 54f071ac7d47ef515a3f6a4db9e83f2f9aca3c8c (patch) | |
tree | 63e9958c5961f32d191c580f6960b6f9eba02f20 /src/env.c | |
parent | df95e5bfca1c5e723b39f25f32401db8f9ebf6fe (diff) |
lambda nearly done
Diffstat (limited to 'src/env.c')
-rw-r--r-- | src/env.c | 16 |
1 files changed, 6 insertions, 10 deletions
@@ -3,7 +3,7 @@ #include "common.h" #include "env.h" -#include "hashtable.h" +#include "value.h" #define ENV_TABLE_CAP (1 << 8) @@ -32,17 +32,13 @@ static bool equal(void *key1, void *key2) return false; } -static void env_add_ref(env_t env); - env_t env_create(env_t parent, env_destroy_func destroy_func) { env_t env = malloc(sizeof(*env)); env->destroy_func = destroy_func; env->parent = parent; - env->refs = 0; + env->refs = 1; - env_add_ref(env); - ERR_Z(env->table = hashtable_create(ENV_TABLE_CAP, hash, equal), env_destroy(env)); @@ -58,7 +54,6 @@ void env_destroy(env_t env) if(env->refs > 0) return; - hashtable_for_each_item(env->table, item, i) { env->destroy_func((char *)item->key, (value_t)item->data); } @@ -67,12 +62,13 @@ void env_destroy(env_t env) free(env); } - -static void env_add_ref(env_t env) +env_t env_copy(env_t env) { env->refs++; if(env->parent) { - env_add_ref(env->parent); + env_copy(env->parent); } + + return env; } |