altos/lisp: Clean up OS integration bits, add defun
[fw/altos] / src / lisp / ao_lisp_read.c
index 8fc134e59c520629d63267b130da9bef3a9db95b..3a2ef7f1f15cef109e81589a1adcd6e33132f61a 100644 (file)
@@ -156,19 +156,7 @@ lex_get()
                c = lex_unget_c;
                lex_unget_c = 0;
        } else {
-#if AO_LISP_ALTOS
-               static uint8_t  at_eol;
-
-               if (at_eol) {
-                       ao_cmd_readline();
-                       at_eol = 0;
-               }
-               c = ao_cmd_lex();
-               if (c == '\n')
-                       at_eol = 1;
-#else
-               c = getchar();
-#endif
+               c = ao_lisp_getc();
        }
        return c;
 }
@@ -188,8 +176,6 @@ lex_quoted (void)
        int     count;
 
        c = lex_get();
-//     if (jumping)
-//             return nil;
        if (c == EOF)
                return EOF;
        c &= 0x7f;
@@ -218,8 +204,6 @@ lex_quoted (void)
                count = 1;
                while (count <= 3) {
                        c = lex_get();
-//                     if (jumping)
-//                             return nil;
                        if (c == EOF)
                                return EOF;
                        c &= 0x7f;
@@ -288,11 +272,17 @@ lex(void)
                if (lex_class & ENDOFFILE)
                        return AO_LISP_NIL;
 
-//             if (jumping)
-//                     return nil;
                if (lex_class & WHITE)
                        continue;
 
+               if (lex_class & COMMENT) {
+                       while ((c = lexc()) != '\n') {
+                               if (lex_class & ENDOFFILE)
+                                       return AO_LISP_NIL;
+                       }
+                       continue;
+               }
+
                if (lex_class & (BRA|KET|QUOTEC)) {
                        add_token(c);
                        end_token();
@@ -312,8 +302,6 @@ lex(void)
                if (lex_class & STRINGC) {
                        for (;;) {
                                c = lexc();
-//                             if (jumping)
-//                                     return nil;
                                if (lex_class & (STRINGC|ENDOFFILE)) {
                                        end_token();
                                        return STRING;
@@ -349,8 +337,6 @@ lex(void)
                                }
                                add_token (c);
                                c = lexc ();
-//                             if (jumping)
-//                                     return nil;
                                if (lex_class & (NOTNAME)) {
 //                                     if (lex_class & ENDOFFILE)
 //                                             clearerr (f);
@@ -403,6 +389,10 @@ pop_read_stack(int cons)
                     read_cons_tail && read_cons_tail->cdr;
                     read_cons_tail = ao_lisp_poly_cons(read_cons_tail->cdr))
                        ;
+       } else {
+               read_cons = 0;
+               read_cons_tail = 0;
+               read_stack = 0;
        }
        return in_quote;
 }
@@ -420,6 +410,7 @@ ao_lisp_read(void)
                ao_lisp_root_add(&ao_lisp_cons_type, &read_cons);
                ao_lisp_root_add(&ao_lisp_cons_type, &read_cons_tail);
                ao_lisp_root_add(&ao_lisp_cons_type, &read_stack);
+               been_here = 1;
        }
        parse_token = lex();