Add minimal abstract machine module
This commit is contained in:
22
lib/am.c
Normal file
22
lib/am.c
Normal file
@@ -0,0 +1,22 @@
|
||||
#include "am.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;
|
||||
}
|
||||
|
||||
void am_push(am_t *am)
|
||||
{
|
||||
assert(am->sp >= am->stack);
|
||||
*am->sp-- = am->expr;
|
||||
}
|
||||
|
||||
void am_pop(am_t *am)
|
||||
{
|
||||
assert(am->sp < am->stack + AM_STACK_SIZE - 1);
|
||||
am->expr = *++am->sp;
|
||||
}
|
||||
Reference in New Issue
Block a user