Add store into abstract machine struct
This commit is contained in:
@@ -3,13 +3,10 @@
|
||||
#include "unity.h"
|
||||
|
||||
static am_t am;
|
||||
static store_t store;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
am_init(&am);
|
||||
store_init(&store);
|
||||
env_init(&am, &store);
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
@@ -18,14 +15,14 @@ void tearDown(void)
|
||||
|
||||
static void test_add_empty_list_is_0(void)
|
||||
{
|
||||
am.expr = expr_str_symbol(&store, "+");
|
||||
am.expr = expr_str_symbol(&am, "+");
|
||||
env_fetch(&am);
|
||||
TEST_ASSERT_NOT_NULL(am.val);
|
||||
TEST_ASSERT_TRUE(am.val->is_atom);
|
||||
TEST_ASSERT_EQUAL(ATOM_TYPE_PRIM_PROC, am.val->atom.type);
|
||||
|
||||
am.argl = expr_empty_list(&store);
|
||||
am.val->atom.prim_proc(&am, &store);
|
||||
am.argl = expr_empty_list(&am);
|
||||
am.val->atom.prim_proc(&am);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(am.val);
|
||||
TEST_ASSERT_TRUE(am.val->is_atom);
|
||||
@@ -35,19 +32,18 @@ static void test_add_empty_list_is_0(void)
|
||||
|
||||
static void test_add_1_2_3_is_6(void)
|
||||
{
|
||||
am.expr = expr_str_symbol(&store, "+");
|
||||
am.expr = expr_str_symbol(&am, "+");
|
||||
env_fetch(&am);
|
||||
TEST_ASSERT_NOT_NULL(am.val);
|
||||
TEST_ASSERT_TRUE(am.val->is_atom);
|
||||
TEST_ASSERT_EQUAL(ATOM_TYPE_PRIM_PROC, am.val->atom.type);
|
||||
|
||||
am.argl = expr_pair(
|
||||
&store, expr_integer(&store, 1),
|
||||
&am, expr_integer(&am, 1),
|
||||
expr_pair(
|
||||
&store, expr_integer(&store, 2),
|
||||
expr_pair(
|
||||
&store, expr_integer(&store, 3), expr_empty_list(&store))));
|
||||
am.val->atom.prim_proc(&am, &store);
|
||||
&am, expr_integer(&am, 2),
|
||||
expr_pair(&am, expr_integer(&am, 3), expr_empty_list(&am))));
|
||||
am.val->atom.prim_proc(&am);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(am.val);
|
||||
TEST_ASSERT_TRUE(am.val->is_atom);
|
||||
@@ -57,14 +53,14 @@ static void test_add_1_2_3_is_6(void)
|
||||
|
||||
static void test_mul_empty_list_is_1(void)
|
||||
{
|
||||
am.expr = expr_str_symbol(&store, "*");
|
||||
am.expr = expr_str_symbol(&am, "*");
|
||||
env_fetch(&am);
|
||||
TEST_ASSERT_NOT_NULL(am.val);
|
||||
TEST_ASSERT_TRUE(am.val->is_atom);
|
||||
TEST_ASSERT_EQUAL(ATOM_TYPE_PRIM_PROC, am.val->atom.type);
|
||||
|
||||
am.argl = expr_empty_list(&store);
|
||||
am.val->atom.prim_proc(&am, &store);
|
||||
am.argl = expr_empty_list(&am);
|
||||
am.val->atom.prim_proc(&am);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(am.val);
|
||||
TEST_ASSERT_TRUE(am.val->is_atom);
|
||||
@@ -74,19 +70,18 @@ static void test_mul_empty_list_is_1(void)
|
||||
|
||||
static void test_mul_2_3_4_is_24(void)
|
||||
{
|
||||
am.expr = expr_str_symbol(&store, "*");
|
||||
am.expr = expr_str_symbol(&am, "*");
|
||||
env_fetch(&am);
|
||||
TEST_ASSERT_NOT_NULL(am.val);
|
||||
TEST_ASSERT_TRUE(am.val->is_atom);
|
||||
TEST_ASSERT_EQUAL(ATOM_TYPE_PRIM_PROC, am.val->atom.type);
|
||||
|
||||
am.argl = expr_pair(
|
||||
&store, expr_integer(&store, 2),
|
||||
&am, expr_integer(&am, 2),
|
||||
expr_pair(
|
||||
&store, expr_integer(&store, 3),
|
||||
expr_pair(
|
||||
&store, expr_integer(&store, 4), expr_empty_list(&store))));
|
||||
am.val->atom.prim_proc(&am, &store);
|
||||
&am, expr_integer(&am, 3),
|
||||
expr_pair(&am, expr_integer(&am, 4), expr_empty_list(&am))));
|
||||
am.val->atom.prim_proc(&am);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(am.val);
|
||||
TEST_ASSERT_TRUE(am.val->is_atom);
|
||||
@@ -96,15 +91,14 @@ static void test_mul_2_3_4_is_24(void)
|
||||
|
||||
static void test_sub_1_is_minus_1(void)
|
||||
{
|
||||
am.expr = expr_str_symbol(&store, "-");
|
||||
am.expr = expr_str_symbol(&am, "-");
|
||||
env_fetch(&am);
|
||||
TEST_ASSERT_NOT_NULL(am.val);
|
||||
TEST_ASSERT_TRUE(am.val->is_atom);
|
||||
TEST_ASSERT_EQUAL(ATOM_TYPE_PRIM_PROC, am.val->atom.type);
|
||||
|
||||
am.argl = expr_pair(
|
||||
&store, expr_integer(&store, 1), expr_empty_list(&store));
|
||||
am.val->atom.prim_proc(&am, &store);
|
||||
am.argl = expr_pair(&am, expr_integer(&am, 1), expr_empty_list(&am));
|
||||
am.val->atom.prim_proc(&am);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(am.val);
|
||||
TEST_ASSERT_TRUE(am.val->is_atom);
|
||||
@@ -114,19 +108,18 @@ static void test_sub_1_is_minus_1(void)
|
||||
|
||||
static void test_sub_5_4_3_is_minus_2(void)
|
||||
{
|
||||
am.expr = expr_str_symbol(&store, "-");
|
||||
am.expr = expr_str_symbol(&am, "-");
|
||||
env_fetch(&am);
|
||||
TEST_ASSERT_NOT_NULL(am.val);
|
||||
TEST_ASSERT_TRUE(am.val->is_atom);
|
||||
TEST_ASSERT_EQUAL(ATOM_TYPE_PRIM_PROC, am.val->atom.type);
|
||||
|
||||
am.argl = expr_pair(
|
||||
&store, expr_integer(&store, 5),
|
||||
&am, expr_integer(&am, 5),
|
||||
expr_pair(
|
||||
&store, expr_integer(&store, 4),
|
||||
expr_pair(
|
||||
&store, expr_integer(&store, 3), expr_empty_list(&store))));
|
||||
am.val->atom.prim_proc(&am, &store);
|
||||
&am, expr_integer(&am, 4),
|
||||
expr_pair(&am, expr_integer(&am, 3), expr_empty_list(&am))));
|
||||
am.val->atom.prim_proc(&am);
|
||||
|
||||
TEST_ASSERT_NOT_NULL(am.val);
|
||||
TEST_ASSERT_TRUE(am.val->is_atom);
|
||||
|
||||
Reference in New Issue
Block a user