Add am_append_arg procedure

This commit is contained in:
2025-08-10 19:44:05 +01:00
parent 6077cf571d
commit 624311d04f
3 changed files with 33 additions and 0 deletions

View File

@@ -25,3 +25,14 @@ void am_pop(am_t *am)
assert(am->sp < am->stack + AM_STACK_SIZE - 1);
am->expr = *++am->sp;
}
void am_append_arg(am_t *am)
{
expr_t *list = am->argl;
while (!list->is_atom)
list = list->pair.cdr;
list->is_atom = false;
list->pair.car = am->val;
list->pair.cdr = expr_empty_list(am);
}

View File

@@ -15,5 +15,6 @@ typedef struct am {
void am_init(am_t *am);
void am_push(am_t *am);
void am_pop(am_t *am);
void am_append_arg(am_t *am);
#endif

View File

@@ -1,6 +1,9 @@
#include "am.h"
#include "unity.h"
#define CAR(expr) (expr->pair.car)
#define CDR(expr) (expr->pair.cdr)
static am_t am;
void setUp(void)
@@ -22,9 +25,27 @@ static void test_expr_value_restored_after_push_modify_pop(void)
TEST_ASSERT_EQUAL(&a, am.expr);
}
static void test_append_arg_42_with_empty_argl(void)
{
am.argl = expr_empty_list(&am);
am.val = expr_integer(&am, 42);
am_append_arg(&am);
TEST_ASSERT_FALSE(am.argl->is_atom);
TEST_ASSERT_NOT_NULL(CAR(am.argl));
TEST_ASSERT_TRUE(CAR(am.argl)->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_INTEGER, CAR(am.argl)->atom.type);
TEST_ASSERT_EQUAL(42, CAR(am.argl)->atom.integer);
TEST_ASSERT_TRUE(CDR(am.argl)->is_atom);
TEST_ASSERT_EQUAL(ATOM_TYPE_EMPTY_LIST, CDR(am.argl)->atom.type);
}
int main(void)
{
UNITY_BEGIN();
RUN_TEST(test_expr_value_restored_after_push_modify_pop);
RUN_TEST(test_append_arg_42_with_empty_argl);
return UNITY_END();
}