diff options
author | Keith Packard <keithp@keithp.com> | 2016-11-10 23:28:26 -0800 |
---|---|---|
committer | Keith Packard <keithp@keithp.com> | 2017-02-20 11:16:50 -0800 |
commit | 137898e3431d887e75b09d8c1ce57297a1558e43 (patch) | |
tree | 8c98f715c0828fb250c4dd7b99c080e823ac7027 /src/test/ao_lisp_test.c | |
parent | 92cdc0cf0e80c1ff3f31cce20fc2b9bda86e3638 (diff) |
altos/lisp: Improve lisp test program UI
Add a prompt for stdin, read from other files on command line before
stdin.
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/test/ao_lisp_test.c')
-rw-r--r-- | src/test/ao_lisp_test.c | 68 |
1 files changed, 26 insertions, 42 deletions
diff --git a/src/test/ao_lisp_test.c b/src/test/ao_lisp_test.c index 8bc677da..69739100 100644 --- a/src/test/ao_lisp_test.c +++ b/src/test/ao_lisp_test.c @@ -15,55 +15,39 @@ #include "ao_lisp.h" #include <stdio.h> -#if 0 -static struct ao_lisp_cons *list; -static char *string; -#endif +static FILE *ao_lisp_file; +static int newline = 1; int -main (int argc, char **argv) +ao_lisp_getc(void) { -#if 0 - int i, j; + int c; - struct ao_lisp_atom *atom; - ao_lisp_root_add(&ao_lisp_cons_type, (void **) &list); - ao_lisp_root_add(&ao_lisp_string_type, (void **) &string); + if (ao_lisp_file) + return getc(ao_lisp_file); - /* allocator test */ - for (j = 0; j < 10; j++) { - list = 0; - string = ao_lisp_string_new(0); - for (i = 0; i < 2; i++) { - string = ao_lisp_string_cat(string, "a"); - list = ao_lisp_cons_cons(ao_lisp_string_poly(string), list); - list = ao_lisp_cons_cons(ao_lisp_int_poly(i), list); - atom = ao_lisp_atom_intern("ant"); - list = ao_lisp_cons_cons(ao_lisp_atom_poly(atom), list); - } - ao_lisp_poly_print(ao_lisp_cons_poly(list)); - printf("\n"); + if (newline) { + printf("> "); + newline = 0; } + c = getchar(); + if (c == '\n') + newline = 1; + return c; +} - for (atom = ao_lisp_poly_atom(ao_builtin_atoms); atom; atom = ao_lisp_poly_atom(atom->next)) { - printf("%s = ", atom->name); - ao_lisp_poly_print(ao_lisp_atom_get(ao_lisp_atom_poly(atom))); - printf("\n"); +int +main (int argc, char **argv) +{ + while (*++argv) { + ao_lisp_file = fopen(*argv, "r"); + if (!ao_lisp_file) { + perror(*argv); + exit(1); + } + ao_lisp_read_eval_print(); + fclose(ao_lisp_file); + ao_lisp_file = NULL; } -#endif -#if 0 - list = ao_lisp_cons_cons(ao_lisp_atom_poly(ao_lisp_atom_intern("+")), - ao_lisp_cons_cons(ao_lisp_cons_poly(ao_lisp_cons_cons(ao_lisp_atom_poly(ao_lisp_atom_intern("+")), - ao_lisp_cons_cons(ao_lisp_int_poly(3), - ao_lisp_cons_cons(ao_lisp_int_poly(4), NULL)))), - ao_lisp_cons_cons(ao_lisp_int_poly(2), NULL))); - printf("list: "); - ao_lisp_poly_print(ao_lisp_cons_poly(list)); - printf ("\n"); - ao_lisp_poly_print(ao_lisp_eval(ao_lisp_cons_poly(list))); - printf ("\n"); -#endif -#if 1 ao_lisp_read_eval_print(); -#endif } |