Add register parameters to AM append operation

This commit is contained in:
2025-08-10 20:50:35 +01:00
parent 76efcef953
commit eaef6f3cd3
5 changed files with 40 additions and 24 deletions

View File

@@ -3,6 +3,7 @@
#define CAR(expr) (expr->pair.car)
#define CDR(expr) (expr->pair.cdr)
#define CADR(expr) CAR(CDR(expr))
static am_t am;
@@ -39,11 +40,11 @@ static void test_argl_value_restored_after_push_modify_pop(void)
TEST_ASSERT_EQUAL(&a, am.regs[ARGL]);
}
static void test_append_arg_42_with_empty_argl(void)
static void test_append_val_42_to_empty_argl(void)
{
am.regs[ARGL] = expr_empty_list(&am);
am.regs[VAL] = expr_integer(&am, 42);
am_append_arg(&am);
am_append(&am, ARGL, VAL);
TEST_ASSERT_FALSE(am.regs[ARGL]->is_atom);
TEST_ASSERT_NOT_NULL(CAR(am.regs[ARGL]));
@@ -56,11 +57,36 @@ static void test_append_arg_42_with_empty_argl(void)
TEST_ASSERT_EQUAL(ATOM_TYPE_EMPTY_LIST, CDR(am.regs[ARGL])->atom.type);
}
static void test_append_unev_2_to_expr_list_1(void)
{
am.regs[EXPR]
= expr_pair(&am, expr_integer(&am, 1), expr_empty_list(&am));
am.regs[UNEV] = expr_integer(&am, 2);
am_append(&am, EXPR, UNEV);
TEST_ASSERT_NOT_NULL(am.regs[EXPR]);
TEST_ASSERT_FALSE(am.regs[EXPR]->is_atom);
TEST_ASSERT_NOT_NULL(CAR(am.regs[EXPR]));
TEST_ASSERT_TRUE(CAR(am.regs[EXPR])->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_INTEGER, CAR(am.regs[EXPR])->atom.type);
TEST_ASSERT_EQUAL(1, CAR(am.regs[EXPR])->atom.integer);
TEST_ASSERT_NOT_NULL(CDR(am.regs[EXPR]));
TEST_ASSERT_FALSE(CDR(am.regs[EXPR])->is_atom);
TEST_ASSERT_NOT_NULL(CADR(am.regs[EXPR]));
TEST_ASSERT_TRUE(CADR(am.regs[EXPR])->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_INTEGER, CADR(am.regs[EXPR])->atom.type);
TEST_ASSERT_EQUAL(2, CADR(am.regs[EXPR])->atom.integer);
}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_expr_value_restored_after_push_modify_pop);
RUN_TEST(test_argl_value_restored_after_push_modify_pop);
RUN_TEST(test_append_arg_42_with_empty_argl);
RUN_TEST(test_append_val_42_to_empty_argl);
RUN_TEST(test_append_unev_2_to_expr_list_1);
return UNITY_END();
}