mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-23 20:15:05 +02:00
WIP
This commit is contained in:
parent
24bfd89774
commit
0e2c9b6244
3 changed files with 15 additions and 8 deletions
|
@ -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;
|
||||
|
||||
|
|
2
read.scm
2
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
|
||||
|
|
17
runtime.c
17
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue