aboutsummaryrefslogtreecommitdiff
path: root/src/env.c
diff options
context:
space:
mode:
authorkartofen <mladenovnasko0@gmail.com>2024-09-22 15:35:40 +0300
committerkartofen <mladenovnasko0@gmail.com>2024-09-22 15:35:40 +0300
commit7edffea39a3d666098ebeca27ea398769e8b981b (patch)
treed114e34f34fdc01e1d61126a0989a1b91c449642 /src/env.c
parentf60047d4b013eb7f75ad4f5c63eda63153a4bf8e (diff)
make env opaque
Diffstat (limited to 'src/env.c')
-rw-r--r--src/env.c29
1 files changed, 28 insertions, 1 deletions
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;
+}