Add am_append_arg procedure
This commit is contained in:
11
lib/am.c
11
lib/am.c
@@ -25,3 +25,14 @@ void am_pop(am_t *am)
|
|||||||
assert(am->sp < am->stack + AM_STACK_SIZE - 1);
|
assert(am->sp < am->stack + AM_STACK_SIZE - 1);
|
||||||
am->expr = *++am->sp;
|
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);
|
||||||
|
}
|
||||||
|
|||||||
@@ -15,5 +15,6 @@ typedef struct am {
|
|||||||
void am_init(am_t *am);
|
void am_init(am_t *am);
|
||||||
void am_push(am_t *am);
|
void am_push(am_t *am);
|
||||||
void am_pop(am_t *am);
|
void am_pop(am_t *am);
|
||||||
|
void am_append_arg(am_t *am);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
#include "am.h"
|
#include "am.h"
|
||||||
#include "unity.h"
|
#include "unity.h"
|
||||||
|
|
||||||
|
#define CAR(expr) (expr->pair.car)
|
||||||
|
#define CDR(expr) (expr->pair.cdr)
|
||||||
|
|
||||||
static am_t am;
|
static am_t am;
|
||||||
|
|
||||||
void setUp(void)
|
void setUp(void)
|
||||||
@@ -22,9 +25,27 @@ static void test_expr_value_restored_after_push_modify_pop(void)
|
|||||||
TEST_ASSERT_EQUAL(&a, am.expr);
|
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)
|
int main(void)
|
||||||
{
|
{
|
||||||
UNITY_BEGIN();
|
UNITY_BEGIN();
|
||||||
RUN_TEST(test_expr_value_restored_after_push_modify_pop);
|
RUN_TEST(test_expr_value_restored_after_push_modify_pop);
|
||||||
|
RUN_TEST(test_append_arg_42_with_empty_argl);
|
||||||
return UNITY_END();
|
return UNITY_END();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user