X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Flisp%2Fao_lisp_read.c;h=7a5751cef0315a7ec4662b3a49ab6ab0490a6592;hb=affcf6ffc08313151541993ee543bfe390165e81;hp=8fc134e59c520629d63267b130da9bef3a9db95b;hpb=9e1a787f8828fb7b750ad3310c89a89536ea5286;p=fw%2Faltos diff --git a/src/lisp/ao_lisp_read.c b/src/lisp/ao_lisp_read.c index 8fc134e5..7a5751ce 100644 --- a/src/lisp/ao_lisp_read.c +++ b/src/lisp/ao_lisp_read.c @@ -12,6 +12,7 @@ * General Public License for more details. */ +#define DBG_EVAL 0 #include "ao_lisp.h" #include "ao_lisp_read.h" @@ -156,19 +157,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 +177,6 @@ lex_quoted (void) int count; c = lex_get(); -// if (jumping) -// return nil; if (c == EOF) return EOF; c &= 0x7f; @@ -218,8 +205,6 @@ lex_quoted (void) count = 1; while (count <= 3) { c = lex_get(); -// if (jumping) -// return nil; if (c == EOF) return EOF; c &= 0x7f; @@ -286,13 +271,19 @@ lex(void) for (;;) { c = lexc(); if (lex_class & ENDOFFILE) - return AO_LISP_NIL; + return END; -// if (jumping) -// return nil; if (lex_class & WHITE) continue; + if (lex_class & COMMENT) { + while ((c = lexc()) != '\n') { + if (lex_class & ENDOFFILE) + return END; + } + continue; + } + if (lex_class & (BRA|KET|QUOTEC)) { add_token(c); end_token(); @@ -312,8 +303,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 +338,6 @@ lex(void) } add_token (c); c = lexc (); -// if (jumping) -// return nil; if (lex_class & (NOTNAME)) { // if (lex_class & ENDOFFILE) // clearerr (f); @@ -378,6 +365,8 @@ static struct ao_lisp_cons *read_stack; static int push_read_stack(int cons, int in_quote) { + DBGI("push read stack %p %d\n", read_cons, in_quote); + DBG_IN(); if (cons) { read_stack = ao_lisp_cons_cons(ao_lisp_cons_poly(read_cons), ao_lisp_cons_cons(ao_lisp_int_poly(in_quote), @@ -403,7 +392,13 @@ 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; } + DBG_OUT(); + DBGI("pop read stack %p %d\n", read_cons, in_quote); return in_quote; } @@ -420,8 +415,10 @@ 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(); + DBGI("token %d (%s)\n", parse_token, token_string); cons = 0; in_quote = 0; @@ -433,12 +430,15 @@ ao_lisp_read(void) cons++; in_quote = 0; parse_token = lex(); + DBGI("token %d (%s)\n", parse_token, token_string); } switch (parse_token) { - case ENDOFFILE: + case END: default: - v = AO_LISP_NIL; + if (cons) + ao_lisp_error(AO_LISP_EOF, "unexpected end of file"); + return _ao_lisp_atom_eof; break; case NAME: atom = ao_lisp_atom_intern(token_string); @@ -499,6 +499,7 @@ ao_lisp_read(void) } parse_token = lex(); + DBGI("token %d (%s)\n", parse_token, token_string); } return v; }