Make AM registers into an array
This commit is contained in:
24
lib/env.c
24
lib/env.c
@@ -12,18 +12,18 @@ static bool symbol_eq(symbol_t *s, symbol_t *t)
|
||||
|
||||
static expr_t **lookup(am_t *am, bool *found)
|
||||
{
|
||||
assert(am->expr != NULL);
|
||||
assert(am->expr->is_atom);
|
||||
assert(am->expr->atom.type == ATOM_TYPE_SYMBOL);
|
||||
assert(AM_EXPR(am) != NULL);
|
||||
assert(AM_EXPR(am)->is_atom);
|
||||
assert(AM_EXPR(am)->atom.type == ATOM_TYPE_SYMBOL);
|
||||
|
||||
if (am->env->is_atom) {
|
||||
assert(am->env->atom.type == ATOM_TYPE_EMPTY_LIST);
|
||||
if (AM_ENV(am)->is_atom) {
|
||||
assert(AM_ENV(am)->atom.type == ATOM_TYPE_EMPTY_LIST);
|
||||
*found = false;
|
||||
return &am->env;
|
||||
return &AM_ENV(am);
|
||||
}
|
||||
|
||||
expr_t *prev;
|
||||
for (expr_t *list = am->env; !list->is_atom; list = list->pair.cdr) {
|
||||
for (expr_t *list = AM_ENV(am); !list->is_atom; list = list->pair.cdr) {
|
||||
assert(list != NULL);
|
||||
|
||||
expr_t *entry = list->pair.car;
|
||||
@@ -34,7 +34,7 @@ static expr_t **lookup(am_t *am, bool *found)
|
||||
assert(key->is_atom);
|
||||
assert(key->atom.type == ATOM_TYPE_SYMBOL);
|
||||
|
||||
if (symbol_eq(&am->expr->atom.symbol, &key->atom.symbol)) {
|
||||
if (symbol_eq(&AM_EXPR(am)->atom.symbol, &key->atom.symbol)) {
|
||||
*found = true;
|
||||
return &entry->pair.cdr;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ static expr_t **lookup(am_t *am, bool *found)
|
||||
|
||||
void env_init(am_t *am)
|
||||
{
|
||||
am->env = expr_empty_list(am);
|
||||
AM_ENV(am) = expr_empty_list(am);
|
||||
prim_load(am);
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ void env_fetch(am_t *am)
|
||||
{
|
||||
bool found;
|
||||
expr_t *val = *lookup(am, &found);
|
||||
am->val = found ? val : NULL;
|
||||
AM_VAL(am) = found ? val : NULL;
|
||||
}
|
||||
|
||||
void env_set(am_t *am)
|
||||
@@ -67,10 +67,10 @@ void env_set(am_t *am)
|
||||
bool found;
|
||||
expr_t **loc = lookup(am, &found);
|
||||
if (found) {
|
||||
*loc = am->val;
|
||||
*loc = AM_VAL(am);
|
||||
} else {
|
||||
(*loc)->is_atom = false;
|
||||
(*loc)->pair.cdr = expr_empty_list(am);
|
||||
(*loc)->pair.car = expr_pair(am, am->expr, am->val);
|
||||
(*loc)->pair.car = expr_pair(am, AM_EXPR(am), AM_VAL(am));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user