From 54f071ac7d47ef515a3f6a4db9e83f2f9aca3c8c Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 25 Aug 2024 12:30:48 +0300 Subject: lambda nearly done --- src/env.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/env.c') diff --git a/src/env.c b/src/env.c index 1aa452b..fcf8b49 100644 --- a/src/env.c +++ b/src/env.c @@ -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; } -- cgit v1.2.3