diff --git a/include/cyclone/types.h b/include/cyclone/types.h index fa32c375..d2f0959c 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -824,8 +824,8 @@ typedef struct { p.buf_idx = 0; \ p.tok_start = 0; \ p.tok_end = 0; \ - p.tok_buf = NULL; \ - p.tok_buf_len = 0; \ + p.tok_buf = malloc(CYC_IO_BUF_LEN); \ + p.tok_buf_len = CYC_IO_BUF_LEN; \ p.mem_buf = malloc(CYC_IO_BUF_LEN); \ p.mem_buf_len = 0; diff --git a/read.scm b/read.scm index 9e111854..f02f74de 100644 --- a/read.scm +++ b/read.scm @@ -698,7 +698,7 @@ " Cyc_io_read_token(data, k, port);") (write - (read-token (open-input-file "generate-c.scm"))) + (read-token (open-input-file "test.scm"))) ;; Notes on writing a fast parser: ; - Interface to the user is (read). This needs to be fast diff --git a/runtime.c b/runtime.c index 7b66801e..d58d5c02 100644 --- a/runtime.c +++ b/runtime.c @@ -5719,6 +5719,15 @@ void _read_error(void *data, port_type *p, const char *msg) Cyc_rt_raise_msg(data, buf); } +void _read_return_atom(void *data, object cont, port_type *p) +{ + // TODO: process tok_buf + p->tok_buf[p->tok_end + 1] = '\0'; // TODO: what if buffer is full? + p->tok_end = 0; + printf("TODO: return atom from %s\n", p->tok_buf); + return_closcall1(data, cont, boolean_f); +} + void Cyc_io_read_token(void *data, object cont, object port) { Cyc_check_port(data, port); @@ -5754,6 +5763,7 @@ void Cyc_io_read_token(void *data, object cont, object port) c = p->mem_buf[p->buf_idx++]; // If comment found, eat up comment chars if (c == ';') { + if (p->tok_end) _read_return_atom(data, cont, p); _read_line_comment(p); // TODO: but then what, want to go back } else if (c == '\n') { @@ -5779,13 +5789,10 @@ void Cyc_io_read_token(void *data, object cont, object port) // - token buffer // - start index (for tokens in mem_buf) // - end index (for tokens in token buf, 0 if token buf is empty) - _read_error(data, p, "Unhandled input sequence"); + //_read_error(data, p, "Unhandled input sequence"); + p->tok_buf[p->tok_end++] = c; } - // Want to use buffer instead of copying chars each time, but - // need a solution when another read is required, since that would - // overwrite buffer - // Raise an exception if any errors are found } }