altos/lisp: Improve lisp test program UI
authorKeith Packard <keithp@keithp.com>
Fri, 11 Nov 2016 07:28:26 +0000 (23:28 -0800)
committerKeith Packard <keithp@keithp.com>
Mon, 20 Feb 2017 19:16:50 +0000 (11:16 -0800)
Add a prompt for stdin, read from other files on command line before
stdin.

Signed-off-by: Keith Packard <keithp@keithp.com>
src/test/ao_lisp_os.h [new file with mode: 0644]
src/test/ao_lisp_test.c

diff --git a/src/test/ao_lisp_os.h b/src/test/ao_lisp_os.h
new file mode 100644 (file)
index 0000000..19bd4f6
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright © 2016 Keith Packard <keithp@keithp.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+
+#ifndef _AO_LISP_OS_H_
+#define _AO_LISP_OS_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+
+extern int ao_lisp_getc(void);
+
+static inline void
+ao_lisp_abort(void)
+{
+       abort();
+}
+
+static inline void
+ao_lisp_os_led(int led)
+{
+       printf("leds set to 0x%x\n", led);
+}
+
+static inline void
+ao_lisp_os_delay(int delay)
+{
+       struct timespec ts = {
+               .tv_sec = delay / 1000,
+               .tv_nsec = (delay % 1000) * 1000000,
+       };
+       nanosleep(&ts, NULL);
+}
+#endif
index 8bc677daa5a54e947f4c86c69caa704e0f4f949d..6973910016ec0fc7072f65c54d7a0edcec739696 100644 (file)
 #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
 }