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

@@ -2,12 +2,14 @@
#define AM_H
#include "expr.h"
#include "store.h"
#define AM_STACK_SIZE 128U
typedef struct am {
expr_t *argl, *env, *expr, *val;
expr_t **sp, *stack[AM_STACK_SIZE];
store_t store;
} am_t;
void am_init(am_t *am);

View File

@@ -2,10 +2,9 @@
#define ENV_H
#include "am.h"
#include "store.h"
void env_init(am_t *am, store_t *store);
void env_init(am_t *am);
void env_fetch(am_t *am);
void env_set(am_t *am, store_t *store);
void env_set(am_t *am);
#endif

View File

@@ -8,14 +8,13 @@
#include <stdint.h>
struct am;
struct store;
typedef struct {
char buf[MAX_SYMBOL_LEN];
size_t len;
} symbol_t;
typedef void (*prim_proc_t)(struct am *am, struct store *store);
typedef void (*prim_proc_t)(struct am *am);
typedef enum {
ATOM_TYPE_EMPTY_LIST,
@@ -47,11 +46,11 @@ typedef struct expr {
};
} expr_t;
expr_t *expr_integer(struct store *store, int64_t value);
expr_t *expr_symbol(struct store *store, const symbol_t *symbol);
expr_t *expr_str_symbol(struct store *store, const char *str);
expr_t *expr_empty_list(struct store *store);
expr_t *expr_pair(struct store *store, expr_t *car, expr_t *cdr);
expr_t *expr_prim_proc(struct store *store, prim_proc_t prim_proc);
expr_t *expr_integer(struct am *am, int64_t value);
expr_t *expr_symbol(struct am *am, const symbol_t *symbol);
expr_t *expr_str_symbol(struct am *am, const char *str);
expr_t *expr_empty_list(struct am *am);
expr_t *expr_pair(struct am *am, expr_t *car, expr_t *cdr);
expr_t *expr_prim_proc(struct am *am, prim_proc_t prim_proc);
#endif

View File

@@ -2,7 +2,6 @@
#define PARSE_H
#include "am.h"
#include "store.h"
#include "token.h"
#define PARSE_MAX_DEPTH 128U
@@ -21,7 +20,7 @@ typedef struct {
parse_state_t *sp, stack[PARSE_MAX_DEPTH];
} parse_ctx_t;
void parse_init(am_t *am, store_t *store, parse_ctx_t *out);
void parse_init(am_t *am, parse_ctx_t *out);
parse_state_t parse_proc(parse_ctx_t *ctx, const token_t *token);
#endif

View File

@@ -3,8 +3,7 @@
#include "am.h"
#include "expr.h"
#include "store.h"
void prim_load(am_t *am, store_t *store);
void prim_load(am_t *am);
#endif

View File

@@ -10,7 +10,9 @@ typedef struct store {
expr_t buffer[STORE_SIZE];
} store_t;
void store_init(store_t *store);
expr_t *store_alloc(store_t *store);
struct am;
void store_init(struct am *am);
expr_t *store_alloc(struct am *am);
#endif