Mercurial > lbo > hg > ylisp
changeset 157:15825a4a3580
preprocess: Implement preprocessing with hacks for REPL
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Tue, 03 Sep 2019 15:36:03 +0200 |
parents | 3cd189bd595c |
children | 8c6d3494924a |
files | src/built-ins.c src/preprocess.c src/preprocess.h |
diffstat | 3 files changed, 18 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/built-ins.c Tue Sep 03 15:35:33 2019 +0200 +++ b/src/built-ins.c Tue Sep 03 15:36:03 2019 +0200 @@ -31,7 +31,7 @@ }; static const char* YBUILTIN_ENUM_STR[] = { - "BUILTIN:UNDEF", "BUILTIN:FOR", "BUILTIN:LET", "BUILTIN:DEFN", + "BUILTIN:UNDEF", "BUILTIN:FOR", "BUILTIN:LET", "BUILTIN:DEFN", "BUILTIN:+", "BUILTIN:-", "BUILTIN:*", "BUILTIN:/", "BUILTIN:IF", "BUILTIN:SEQ", "BUILTIN:EQ", "BUILTIN:LT", "BUILTIN:CAR", "BUILTIN:CDR", "BUILTIN:PUSH", @@ -98,7 +98,7 @@ yexpr_t exc = ybuiltin_type_error( \ YBUILTIN_##BUILTINTYPE, \ ystr_new("type mismatch for " #BUILTINTYPE "; want " want \ - "received something else"), \ + " received something else"), \ &invalid_expr); \ return exc; \ } @@ -344,6 +344,7 @@ yexpr_t evald = yeval(state, YVEC_AT(&print.value.list, i, yexpr_t), false); ystr_t repr = yexpr_debug_str(&evald); fputs(ystr_str(&repr), stdout); + fputc(' ', stdout); yexpr_destroy(&evald); ystr_destroy(&repr); }
--- a/src/preprocess.c Tue Sep 03 15:35:33 2019 +0200 +++ b/src/preprocess.c Tue Sep 03 15:36:03 2019 +0200 @@ -252,3 +252,17 @@ yvec_destroy(&scope_stack); } +void ypreprocess_refs_repl(yexpr_t* repl_expr, yvec_t** scope_stack) { + if (*scope_stack == NULL) { + *scope_stack = malloc(sizeof(yvec_t)); + **scope_stack = YVEC_NEW(NULL, 16, ypreprocess_scope_t*); + ypreprocess_scope_t* root = malloc(sizeof(ypreprocess_scope_t)); + root->refs = YVEC_NEW(NULL, 4, ypreprocess_existing_t); + YVEC_PUSH(*scope_stack, &root); + } + assert(YEXPR_LIST == repl_expr->typ); + for (size_t i = 0; i < repl_expr->value.list.len; i++) { + yexpr_t* elem = YVEC_AT(&repl_expr->value.list, i, yexpr_t); + ypreprocess_refs_recursive(*scope_stack, elem); + } +}