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

@@ -1,19 +1,17 @@
#include "am.h"
#include "expr.h"
#include "store.h"
#include "unity.h"
static store_t store;
static am_t am;
void test_prim_proc(am_t *am, store_t *store)
void test_prim_proc(am_t *am)
{
(void)am;
(void)store;
}
void setUp(void)
{
store_init(&store);
am_init(&am);
}
void tearDown(void)
@@ -22,7 +20,7 @@ void tearDown(void)
static void test_expr_integer_123(void)
{
expr_t *expr = expr_integer(&store, 123);
expr_t *expr = expr_integer(&am, 123);
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_TRUE(expr->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_INTEGER, expr->atom.type);
@@ -31,7 +29,7 @@ static void test_expr_integer_123(void)
static void test_expr_integer_456(void)
{
expr_t *expr = expr_integer(&store, 456);
expr_t *expr = expr_integer(&am, 456);
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_TRUE(expr->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_INTEGER, expr->atom.type);
@@ -41,7 +39,7 @@ static void test_expr_integer_456(void)
static void test_expr_symbol_foo(void)
{
const symbol_t symbol = { .buf = "foo", .len = 3 };
expr_t *expr = expr_symbol(&store, &symbol);
expr_t *expr = expr_symbol(&am, &symbol);
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_TRUE(expr->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_SYMBOL, expr->atom.type);
@@ -52,7 +50,7 @@ static void test_expr_symbol_foo(void)
static void test_expr_symbol_quux(void)
{
const symbol_t symbol = { .buf = "quux", .len = 4 };
expr_t *expr = expr_symbol(&store, &symbol);
expr_t *expr = expr_symbol(&am, &symbol);
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_TRUE(expr->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_SYMBOL, expr->atom.type);
@@ -62,7 +60,7 @@ static void test_expr_symbol_quux(void)
static void test_expr_str_symbol_foo(void)
{
expr_t *expr = expr_str_symbol(&store, "foo");
expr_t *expr = expr_str_symbol(&am, "foo");
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_TRUE(expr->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_SYMBOL, expr->atom.type);
@@ -72,7 +70,7 @@ static void test_expr_str_symbol_foo(void)
static void test_expr_str_symbol_quux(void)
{
expr_t *expr = expr_str_symbol(&store, "quux");
expr_t *expr = expr_str_symbol(&am, "quux");
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_TRUE(expr->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_SYMBOL, expr->atom.type);
@@ -82,7 +80,7 @@ static void test_expr_str_symbol_quux(void)
static void test_expr_empty_list(void)
{
expr_t *expr = expr_empty_list(&store);
expr_t *expr = expr_empty_list(&am);
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_TRUE(expr->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_EMPTY_LIST, expr->atom.type);
@@ -90,9 +88,9 @@ static void test_expr_empty_list(void)
static void test_expr_pair(void)
{
expr_t *car = expr_integer(&store, 123);
expr_t *cdr = expr_integer(&store, 456);
expr_t *expr = expr_pair(&store, car, cdr);
expr_t *car = expr_integer(&am, 123);
expr_t *cdr = expr_integer(&am, 456);
expr_t *expr = expr_pair(&am, car, cdr);
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_FALSE(expr->is_atom);
TEST_ASSERT_EQUAL(car, expr->pair.car);
@@ -102,7 +100,7 @@ static void test_expr_pair(void)
static void test_expr_prim_proc(void)
{
expr_t *expr = expr_prim_proc(&store, test_prim_proc);
expr_t *expr = expr_prim_proc(&am, test_prim_proc);
TEST_ASSERT_NOT_NULL(expr);
TEST_ASSERT_TRUE(expr->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_PRIM_PROC, expr->atom.type);