This commit is contained in:
Justin Ethier 2017-08-10 19:03:38 -04:00
parent 49ca5508dd
commit 28952d1056
3 changed files with 47 additions and 13 deletions

View file

@ -779,10 +779,14 @@ typedef struct {
FILE *fp;
int mode;
unsigned char flags;
// TODO: int line_num;
// TODO: int char_num;
char *mem_buf;
size_t mem_buf_len;
} port_type;
#define IO_BUF_LEN 1024
/** Create a new port object in the nursery */
#define make_port(p,f,m) \
port_type p; \
@ -803,7 +807,7 @@ typedef struct {
p.fp = f; \
p.mode = m; \
p.flags = 1; \
p.mem_buf = NULL; \
p.mem_buf = malloc(IO_BUF_LEN); \
p.mem_buf_len = 0;
/**

View file

@ -696,18 +696,41 @@
(write 'TODO)
;; Notes on writing a fast parser:
- Interface to the user is (read). This needs to be fast
- Could read input a line at a time, but then need to buffer in the port_type object
- Thinking fread would be most efficient
- Port would need an array, size (could be known instead of storing), and current index
- Need a way to indicate EOF
- One drawback - will not integrate nicely with other I/O on same port (read-char, read-line, etc) until those functions are updated to work with buffered I/O
; - Interface to the user is (read). This needs to be fast
; - Could read input a line at a time, but then need to buffer in the port_type object
; - Thinking fread would be most efficient
; - Port would need an array, size (could be known instead of storing), and current index
; - Need a way to indicate EOF
; - One drawback - will not integrate nicely with other I/O on same port (read-char, read-line, etc) until those functions are updated to work with buffered I/O
;
; - Shouldn't chars for comments be immediately read? Not sure why existing code attempts to pass state
; - Not sure if we need the (all?) var. Can't we just loop and quit when closing paren is seen?
;
; - could main parsing code be written in C? this could save a lot of time
; maybe have a scheme layer to handle nested parens (anything else?) and call C to
; get the next token
- Shouldn't chars for comments be immediately read? Not sure why existing code attempts to pass state
- Not sure if we need the (all?) var. Can't we just loop and quit when closing paren is seen?
(define cyc-read2
(lambda args
(let ((fp (if (null? args)
(current-input-port)
(car args))))
;(parse fp '() '() #f #f 0 (reg-port fp))
- could main parsing code be written in C? this could save a lot of time
maybe have a scheme layer to handle nested parens (anything else?) and call C to
get the next token
;; TODO: anything else? will track line/char nums within the C code
(parse2 fp)
)))
(define (parse2 fp)
(let ((token (read-token fp))) ;; TODO: this will be a C call
(cond
;; Open paren, start read loop
;; Close parent, stop current read loop
;; Quote
;; , - could be unquote or unquote-splicing
;; # - get next char(s)
;; Other special cases?
(else
token))))

View file

@ -3397,7 +3397,7 @@ port_type Cyc_io_open_input_file(void *data, object str)
const char *fname;
Cyc_check_str(data, str);
fname = ((string_type *) str)->str;
make_port(p, NULL, 1);
make_file_backed_port(p, NULL, 1);
p.fp = fopen(fname, "r");
if (p.fp == NULL) {
Cyc_rt_raise2(data, "Unable to open file", str);
@ -5674,3 +5674,10 @@ void Cyc_import_shared_object(void *data, object cont, object filename, object e
entry_pt(data, 0, &clo, &clo);
}
/** Read */
void Cyc_read(void *data, object cont, object port)
{
//Cyc_check_port(data, port);
port_type *p = (port_type *)port;
}