summaryrefslogtreecommitdiff
path: root/src/scope.c
blob: afb9d5ce3187633ee488398e9c5bb2cd78eac865 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <stdlib.h>
#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(scope_t* scope, char* key) {
	while (scope->parent != NULL) {
		pair_t* pair = hashtable_get_pair(scope->hashtable, key);
		if (pair != NULL) {
			return pair;
		}
		scope = scope->parent;
	}
	return NULL;
}