Mercurial > lbo > hg > ylisp
changeset 165:97e8d35ede6d
built-ins: Enhance print behavior
author | Lewin Bormann <lbo@spheniscida.de> |
---|---|
date | Tue, 03 Sep 2019 20:01:46 +0200 |
parents | f91caf9fe066 |
children | b5f1940e8651 |
files | src/built-ins.c src/built-ins_test.c |
diffstat | 2 files changed, 12 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/src/built-ins.c Tue Sep 03 17:17:02 2019 +0200 +++ b/src/built-ins.c Tue Sep 03 20:01:46 2019 +0200 @@ -35,10 +35,10 @@ }; static const char* YBUILTIN_ENUM_STR[] = { - "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", + "BUILTIN:UNDEF", "BUILTIN:FOR", "BUILTIN:LET", "BUILTIN:DEFN", + "BUILTIN:+", "BUILTIN:-", "BUILTIN:*", "BUILTIN:/", + "BUILTIN:IF", "BUILTIN:PRINT", "BUILTIN:EQ", "BUILTIN:LT", + "BUILTIN:CAR", "BUILTIN:CDR", "BUILTIN:PUSH", }; /// Ownership of msg is transferred to this function, ownership of offending is @@ -348,9 +348,16 @@ for (size_t i = 1; i < print.value.list.len; i++) { yexpr_t evald = yeval(state, YVEC_AT(&print.value.list, i, yexpr_t), false); + if (evald.typ == YEXPR_STRING) { + fputs(ystr_str(&evald.value.str), out); + goto cleanup_continue; + } ystr_t repr = yexpr_debug_str(&evald); fputs(ystr_str(&repr), out); + + cleanup_continue: if (i != print.value.list.len - (size_t)1) fputc(' ', out); + yexpr_destroy(&evald); ystr_destroy(&repr); }
--- a/src/built-ins_test.c Tue Sep 03 17:17:02 2019 +0200 +++ b/src/built-ins_test.c Tue Sep 03 20:01:46 2019 +0200 @@ -296,7 +296,7 @@ "(let a \"hello\")" "(let b 'world)" "(print 1 a b)"); - ystr_t expected = ystr_new("1 \"hello\" world"); + ystr_t expected = ystr_new("1 hello world"); ystr_t error = ystr_new(NULL); yexpr_t program = yexpr_new();