Also make it an exception to hit eof in the middle of an sexpr.
Signed-off-by: Keith Packard <keithp@keithp.com>
#define _ao_lisp_atom_delay _atom("delay")
#define _ao_lisp_atom_eval _atom("eval")
#define _ao_lisp_atom_read _atom("read")
#define _ao_lisp_atom_delay _atom("delay")
#define _ao_lisp_atom_eval _atom("eval")
#define _ao_lisp_atom_read _atom("read")
+#define _ao_lisp_atom_eof _atom("eof")
#else
#include "ao_lisp_const.h"
#ifndef AO_LISP_POOL
#else
#include "ao_lisp_const.h"
#ifndef AO_LISP_POOL
#define AO_LISP_DIVIDE_BY_ZERO 0x02
#define AO_LISP_INVALID 0x04
#define AO_LISP_UNDEFINED 0x08
#define AO_LISP_DIVIDE_BY_ZERO 0x02
#define AO_LISP_INVALID 0x04
#define AO_LISP_UNDEFINED 0x08
+#define AO_LISP_EOF 0x10
extern uint8_t ao_lisp_exception;
extern uint8_t ao_lisp_exception;
* General Public License for more details.
*/
* General Public License for more details.
*/
#include "ao_lisp.h"
#include "ao_lisp_read.h"
#include "ao_lisp.h"
#include "ao_lisp_read.h"
for (;;) {
c = lexc();
if (lex_class & ENDOFFILE)
for (;;) {
c = lexc();
if (lex_class & ENDOFFILE)
if (lex_class & WHITE)
continue;
if (lex_class & WHITE)
continue;
if (lex_class & COMMENT) {
while ((c = lexc()) != '\n') {
if (lex_class & ENDOFFILE)
if (lex_class & COMMENT) {
while ((c = lexc()) != '\n') {
if (lex_class & ENDOFFILE)
static int
push_read_stack(int cons, int in_quote)
{
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),
if (cons) {
read_stack = ao_lisp_cons_cons(ao_lisp_cons_poly(read_cons),
ao_lisp_cons_cons(ao_lisp_int_poly(in_quote),
read_cons_tail = 0;
read_stack = 0;
}
read_cons_tail = 0;
read_stack = 0;
}
+ DBG_OUT();
+ DBGI("pop read stack %p %d\n", read_cons, in_quote);
been_here = 1;
}
parse_token = lex();
been_here = 1;
}
parse_token = lex();
+ DBGI("token %d (%s)\n", parse_token, token_string);
cons++;
in_quote = 0;
parse_token = lex();
cons++;
in_quote = 0;
parse_token = lex();
+ DBGI("token %d (%s)\n", parse_token, token_string);
+ 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);
break;
case NAME:
atom = ao_lisp_atom_intern(token_string);
+ DBGI("token %d (%s)\n", parse_token, token_string);
ao_poly in, out = AO_LISP_NIL;
for(;;) {
in = ao_lisp_read();
ao_poly in, out = AO_LISP_NIL;
for(;;) {
in = ao_lisp_read();
+ if (in == _ao_lisp_atom_eof)
-// printf ("in: "); ao_lisp_poly_print(in); printf("\n");
out = ao_lisp_eval(in);
if (ao_lisp_exception) {
ao_lisp_exception = 0;
out = ao_lisp_eval(in);
if (ao_lisp_exception) {
ao_lisp_exception = 0;