From 7edffea39a3d666098ebeca27ea398769e8b981b Mon Sep 17 00:00:00 2001 From: kartofen Date: Sun, 22 Sep 2024 15:35:40 +0300 Subject: make env opaque --- src/env.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'src/env.c') diff --git a/src/env.c b/src/env.c index ff9da33..b78b095 100644 --- a/src/env.c +++ b/src/env.c @@ -3,10 +3,21 @@ #include "common.h" #include "env.h" + +#include "hashtable.h" #include "value.h" +struct env { + hashtable_t table; + + struct env *parent; + size_t refs; + + env_destroy_func destroy_func; +}; + #include "mempool.h" -MEMPOOL_GENERATE(env, struct symbol_table, 64) +MEMPOOL_GENERATE(env, struct env, 64) #define ENV_TABLE_CAP (1 << 3) @@ -67,6 +78,17 @@ void env_destroy(env_t env) env_mempool_free(env); } +int env_insert(env_t env, char *key, value_t data, + char **prevkey, value_t *prevdata) +{ + return hashtable_insert(env->table, (void *)key, (void *)data, (void **)prevkey, (void **)prevdata); +} + +int env_query(env_t env, char *key, value_t *data) +{ + return hashtable_query(env->table, (void *)key, (void **)data); +} + env_t env_copy(env_t env) { if(env == ENV_EMPTY) return ENV_EMPTY; @@ -76,3 +98,8 @@ env_t env_copy(env_t env) return env; } + +env_t env_parent(env_t env) +{ + return env->parent; +} -- cgit v1.2.3