56 lines
1.0 KiB
C
56 lines
1.0 KiB
C
#include "am.h"
|
|
|
|
#include "env.h"
|
|
#include "store.h"
|
|
|
|
#include <assert.h>
|
|
#include <string.h>
|
|
|
|
void am_init(am_t *am)
|
|
{
|
|
memset(am, 0, sizeof(am_t));
|
|
am->sp = am->stack + AM_STACK_SIZE - 1;
|
|
store_init(am);
|
|
env_init(am);
|
|
}
|
|
|
|
void am_push(am_t *am, am_reg_t reg)
|
|
{
|
|
assert(am->sp >= am->stack);
|
|
*am->sp-- = am->regs[reg];
|
|
}
|
|
|
|
void am_pop(am_t *am, am_reg_t reg)
|
|
{
|
|
assert(am->sp < am->stack + AM_STACK_SIZE - 1);
|
|
am->regs[reg] = *++am->sp;
|
|
}
|
|
|
|
void am_append(am_t *am, am_reg_t list_reg, am_reg_t item_reg)
|
|
{
|
|
expr_t *list = am->regs[list_reg];
|
|
while (!list->is_atom)
|
|
list = list->pair.cdr;
|
|
|
|
list->is_atom = false;
|
|
list->pair.car = am->regs[item_reg];
|
|
list->pair.cdr = expr_empty_list(am);
|
|
}
|
|
|
|
void am_car(am_t *am, am_reg_t dest, am_reg_t src)
|
|
{
|
|
assert(!am->regs[src]->is_atom);
|
|
am->regs[dest] = am->regs[src]->pair.car;
|
|
}
|
|
|
|
void am_cdr(am_t *am, am_reg_t dest, am_reg_t src)
|
|
{
|
|
assert(!am->regs[src]->is_atom);
|
|
am->regs[dest] = am->regs[src]->pair.cdr;
|
|
}
|
|
|
|
void am_assign(am_t *am, am_reg_t dest, am_reg_t src)
|
|
{
|
|
am->regs[dest] = am->regs[src];
|
|
}
|