From 24f981233bc3e0b000acf4615d4bc6f2332eefb0 Mon Sep 17 00:00:00 2001 From: Kai Stevenson Date: Tue, 14 Feb 2023 02:02:50 -0800 Subject: init --- scope.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 scope.c (limited to 'scope.c') diff --git a/scope.c b/scope.c new file mode 100644 index 0000000..4cc5249 --- /dev/null +++ b/scope.c @@ -0,0 +1,20 @@ +#include +#include "scope.h" +#include "hashtable.h" + +scope_t* init_scope(scope_t parent) { + scope_t* scope = malloc(sizeof(scope_t)); + scope->hashtable = init_hashtable(1000); + *(scope->parent) = parent; + return scope; +} +pair_t* get_pair_global(char* key, scope_t* scope) { + while (scope->parent != NULL) { + pair_t* pair = hashtable_get_pair(scope->hashtable, key); + if (pair != NULL) { + return pair; + } + scope = scope->parent; + } + return NULL; +} -- cgit v1.3.1