Mercurial > lbo > hg > ylisp
changeset 140:a4a6169cccc0
preprocess: Update test and add one new
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Tue, 03 Sep 2019 09:41:40 +0200 |
parents | d320f32169ee |
children | 08bf6c4a9017 |
files | src/preprocess_test.c |
diffstat | 1 files changed, 41 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/preprocess_test.c Tue Sep 03 09:41:17 2019 +0200 +++ b/src/preprocess_test.c Tue Sep 03 09:41:40 2019 +0200 @@ -22,11 +22,11 @@ ypreprocess_resolve_builtins(&program); yexpr_debug(&program); - ypreprocess_defn(&program); + ypreprocess_refs(&program); yexpr_debug(&program); - yvalue_t* func = yvalue_get(yref_new_c("my-func")); - assert(func != NULL); + /// We can't do these anymore, as functions are now anonymous: + /* fprintf(stderr, "arg ref 0: %lu\n", YVEC_AT(&func->value.func.args, 0, yarg_desc_t)->argref.ref.id); fprintf(stderr, "arg ref 1: %lu\n", @@ -37,6 +37,7 @@ fprintf( stderr, "arg name 1: %s\n", ystr_str(&YVEC_AT(&func->value.func.args, 1, yarg_desc_t)->argname)); + */ yeval_state_t state; state.call_stack = YVEC_NEW(NULL, 0, yexpr_t); @@ -51,8 +52,45 @@ yexpr_destroy(&result); } +void test_preprocess_refs(void) { + fprintf(stderr, "test_preprocess_refs ===========\n"); + + // my-func adds the two arguments plus 42. + ystr_t input = ystr_new( + "(defn my-func (arg) (+ arg 1))" + "(let a 33)" + "(let b 44)" + "(+ a b)" + "(let a b)" + "(my-func a)"); + yexpr_t program = yexpr_new(); + ystr_t error = ystr_new(NULL); + assert(yparse_str(&input, &program, &error)); + + yexpr_debug(&program); + ypreprocess_resolve_builtins(&program); + ypreprocess_defn(&program); + yexpr_debug(&program); + ypreprocess_refs(&program); + yexpr_debug(&program); + + yeval_state_t state; + state.call_stack = YVEC_NEW(NULL, 0, yexpr_t); + yexpr_t result = yeval_list_return_last(&state, &program.value.list, 0); + assert(result.typ == YEXPR_NUMBER); + assert(45 == result.value.n); + yexpr_debug(&result); + + yexpr_destroy(&program); + ystr_destroy(&input); + ystr_destroy(&error); + yvec_destroy(&state.call_stack); +} + int main(void) { test_preprocess_defn(); + test_preprocess_refs(); + fprintf(stderr, "global destroy ===========\n"); yvalue_free_all(); return 0; }