Add store into abstract machine struct

This commit is contained in:
2025-08-10 15:21:24 +01:00
parent b20a6749f7
commit d8e51b0aa0
18 changed files with 129 additions and 141 deletions

View File

@@ -3,10 +3,9 @@
#include <assert.h>
#include <string.h>
void parse_init(am_t *am, store_t *store, parse_ctx_t *out)
void parse_init(am_t *am, parse_ctx_t *out)
{
out->am = am;
out->store = store;
out->state = PARSE_STATE_INIT;
out->sp = out->stack + PARSE_MAX_DEPTH - 1;
}
@@ -32,7 +31,7 @@ static void append(parse_ctx_t *ctx, expr_t *expr)
list->is_atom = false;
list->pair.car = expr;
list->pair.cdr = expr_empty_list(ctx->store);
list->pair.cdr = expr_empty_list(ctx->am);
}
parse_state_t parse_proc(parse_ctx_t *ctx, const token_t *token)
@@ -41,16 +40,16 @@ parse_state_t parse_proc(parse_ctx_t *ctx, const token_t *token)
case PARSE_STATE_INIT:
switch (token->type) {
case TOKEN_TYPE_INTEGER:
ctx->am->expr = expr_integer(ctx->store, token->integer);
ctx->am->expr = expr_integer(ctx->am, token->integer);
ctx->state = PARSE_STATE_DONE;
break;
case TOKEN_TYPE_SYMBOL:
ctx->am->expr = expr_symbol(ctx->store, &token->symbol);
ctx->am->expr = expr_symbol(ctx->am, &token->symbol);
ctx->state = PARSE_STATE_DONE;
break;
case TOKEN_TYPE_OPEN_PAREN:
push_state(ctx, PARSE_STATE_DONE);
ctx->am->expr = expr_empty_list(ctx->store);
ctx->am->expr = expr_empty_list(ctx->am);
ctx->state = PARSE_STATE_LIST;
break;
case TOKEN_TYPE_CLOSE_PAREN:
@@ -62,15 +61,15 @@ parse_state_t parse_proc(parse_ctx_t *ctx, const token_t *token)
case PARSE_STATE_LIST:
switch (token->type) {
case TOKEN_TYPE_INTEGER:
append(ctx, expr_integer(ctx->store, token->integer));
append(ctx, expr_integer(ctx->am, token->integer));
break;
case TOKEN_TYPE_SYMBOL:
append(ctx, expr_symbol(ctx->store, &token->symbol));
append(ctx, expr_symbol(ctx->am, &token->symbol));
break;
case TOKEN_TYPE_OPEN_PAREN:
am_push(ctx->am);
push_state(ctx, PARSE_STATE_LIST);
ctx->am->expr = expr_empty_list(ctx->store);
ctx->am->expr = expr_empty_list(ctx->am);
ctx->state = PARSE_STATE_LIST;
break;
case TOKEN_TYPE_CLOSE_PAREN: