summaryrefslogtreecommitdiff
path: root/scope.c
blob: 4cc5249a4faa9791db5987acf071a56b1fadaed2 (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(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;
}