lambda-calc-1/environment/lookup.c
2025-01-13 20:36:07 -06:00

53 lines
853 B
C

#include <stdlib.h>
#include <assert.h>
#include <debug.h>
#include <extern/avl/avl.h>
#include <string/struct.h>
#include <value/inc.h>
#include "variable/struct.h"
#include "struct.h"
#include "lookup.h"
struct value* environment_lookup(
struct environment* this,
struct string* name)
{
ENTER;
struct value* result = NULL;
for (struct environment* moving = this;
!result && moving;
moving = moving->fallback)
{
struct avl_node_t* node = avl_search(moving->tree, &name);
if (node)
{
struct variable* variable = node->item;
result = inc_value(variable->value);
}
}
if (!result)
{
dpvu(*name->data);
TODO;
exit(1);
}
EXIT;
return result;
}