diff --git a/Makefile b/Makefile index 106ffab..129ab2d 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ LDFLAGS=-L${UNIVERSAL_SERVICE_DIR} -luniversalservice -L${UNIVERSAL_SERVICE_DIR} flatrate: main.c $(CC) main.c -o flatrate $(CFLAGS) $(LDFLAGS) run: flatrate - LD_LIBRARY_PATH="$$(pwd)/${UNIVERSAL_SERVICE_DIR}/:$$(pwd)/${UNIVERSAL_SERVICE_DIR}/examples/string" ./flatrate < prelude.scm + cat prelude.scm - | LD_LIBRARY_PATH="$$(pwd)/${UNIVERSAL_SERVICE_DIR}/:$$(pwd)/${UNIVERSAL_SERVICE_DIR}/examples/string" ./flatrate debug: flatrate LD_LIBRARY_PATH="$$(pwd)/${UNIVERSAL_SERVICE_DIR}/:$$(pwd)/${UNIVERSAL_SERVICE_DIR}/examples/string" gdb -tui ./flatrate valgrind: flatrate diff --git a/main.c b/main.c index 759f387..3594b47 100644 --- a/main.c +++ b/main.c @@ -240,7 +240,6 @@ static void tokenize(FILE *input, struct token *tok) default: if (c == '.') { c2 = getc(input); - /* Flatrate does not have floating point. */ if (tonum(c2) >= 0) { ungetc(c2, input); tok_num(input, tok, c); @@ -765,12 +764,24 @@ static void display(struct uns_ctr *ctr) tmp.p = gc.record_get_ptr(ctr->p, 1); display(&tmp); - printf(" . "); - tmp.p = gc.record_get_ptr(ctr->p, 2); - display(&tmp); - printf(")"); + switch (get_type(tmp.p)) { + case EMPTY_LIST: + printf(")"); + goto remove; + case CELL: + printf(" "); + display(&tmp); + printf(")"); + break; + default: + printf(" . "); + display(&tmp); + printf(")"); + break; + } + remove: uns_root_remove(&gc, &tmp); return; case INTEGER: @@ -790,7 +801,7 @@ static void display(struct uns_ctr *ctr) case SYMBOL: tmp.p = gc.record_get_ptr(ctr->p, 1); uns_root_add(&gc, &tmp); - printf("'%s ", uns_string_cstring(&gc, &tmp)); + printf("%s ", uns_string_cstring(&gc, &tmp)); uns_root_remove(&gc, &tmp); return; case EMPTY_LIST: @@ -867,7 +878,7 @@ int main(void) case EXPR_PARSE_IMPROPER_LIST_OVERFLOW: fprintf(stderr, "too many values at end of improper list (must be exactly one)\n"); case EXPR_PARSE_BAD_IMPROPER_LIST: - fprintf(stderr, "Bad syntax for improper list (must be (value . value))"); + fprintf(stderr, "Bad syntax for improper list (must be (value . value))\n"); break; case EXPR_PARSE_INTERNAL_ERROR: fprintf(stderr, "Bug in implementation\n");