1 struct _EnvironmentNode;
2 typedef struct _EnvironmentNode _EnvironmentNode;
3 struct _EnvironmentNode {
6 _EnvironmentNode* next;
10 typedef struct Environment Environment;
12 _EnvironmentNode* top;
15 struct Environment_get_Result;
16 typedef struct Environment_get_Result Environment_get_Result;
17 struct Environment_get_Result {
22 void Environment_initialize(Environment* self) {
26 void Environment_deinitialize(Environment* self) {
27 while(self->top != NULL) {
28 _EnvironmentNode* en = self->top;
30 Object_deinitialize(&(en->value));
35 Environment* Environment_construct() {
36 Environment* result = malloc(sizeof(Environment));
37 Environment_initialize(result);
41 void Environment_destruct(Environment* self) {
42 Environment_deinitialize(self);
46 Environment_get_Result Environment_get(Environment* self, char* symbol) {
47 for(_EnvironmentNode* current = self->top; current != NULL; current = current->next) {
48 if(strcmp(current->symbol, symbol) == 0) {
49 return (Environment_get_Result) { true, current->value };
52 return (Environment_get_Result) { false, BUILTIN_NIL };
55 void Environment_set(Environment* self, char* symbol, Object value) {
56 assert(!(Environment_get(self, symbol).found));
58 _EnvironmentNode* en = malloc(sizeof(_EnvironmentNode));