mirror of
https://github.com/justinethier/cyclone.git
synced 2025-05-24 20:45:06 +02:00
WIP
This commit is contained in:
parent
49ca5508dd
commit
28952d1056
3 changed files with 47 additions and 13 deletions
|
@ -779,10 +779,14 @@ typedef struct {
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
int mode;
|
int mode;
|
||||||
unsigned char flags;
|
unsigned char flags;
|
||||||
|
// TODO: int line_num;
|
||||||
|
// TODO: int char_num;
|
||||||
char *mem_buf;
|
char *mem_buf;
|
||||||
size_t mem_buf_len;
|
size_t mem_buf_len;
|
||||||
} port_type;
|
} port_type;
|
||||||
|
|
||||||
|
#define IO_BUF_LEN 1024
|
||||||
|
|
||||||
/** Create a new port object in the nursery */
|
/** Create a new port object in the nursery */
|
||||||
#define make_port(p,f,m) \
|
#define make_port(p,f,m) \
|
||||||
port_type p; \
|
port_type p; \
|
||||||
|
@ -803,7 +807,7 @@ typedef struct {
|
||||||
p.fp = f; \
|
p.fp = f; \
|
||||||
p.mode = m; \
|
p.mode = m; \
|
||||||
p.flags = 1; \
|
p.flags = 1; \
|
||||||
p.mem_buf = NULL; \
|
p.mem_buf = malloc(IO_BUF_LEN); \
|
||||||
p.mem_buf_len = 0;
|
p.mem_buf_len = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
45
read.scm
45
read.scm
|
@ -696,18 +696,41 @@
|
||||||
(write 'TODO)
|
(write 'TODO)
|
||||||
|
|
||||||
;; Notes on writing a fast parser:
|
;; Notes on writing a fast parser:
|
||||||
- Interface to the user is (read). This needs to be fast
|
; - 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
|
; - Could read input a line at a time, but then need to buffer in the port_type object
|
||||||
- Thinking fread would be most efficient
|
; - Thinking fread would be most efficient
|
||||||
- Port would need an array, size (could be known instead of storing), and current index
|
; - Port would need an array, size (could be known instead of storing), and current index
|
||||||
- Need a way to indicate EOF
|
; - 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
|
; - 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
|
(define cyc-read2
|
||||||
- Not sure if we need the (all?) var. Can't we just loop and quit when closing paren is seen?
|
(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
|
;; TODO: anything else? will track line/char nums within the C code
|
||||||
maybe have a scheme layer to handle nested parens (anything else?) and call C to
|
(parse2 fp)
|
||||||
get the next token
|
|
||||||
|
|
||||||
|
)))
|
||||||
|
|
||||||
|
(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))))
|
||||||
|
|
||||||
|
|
|
@ -3397,7 +3397,7 @@ port_type Cyc_io_open_input_file(void *data, object str)
|
||||||
const char *fname;
|
const char *fname;
|
||||||
Cyc_check_str(data, str);
|
Cyc_check_str(data, str);
|
||||||
fname = ((string_type *) str)->str;
|
fname = ((string_type *) str)->str;
|
||||||
make_port(p, NULL, 1);
|
make_file_backed_port(p, NULL, 1);
|
||||||
p.fp = fopen(fname, "r");
|
p.fp = fopen(fname, "r");
|
||||||
if (p.fp == NULL) {
|
if (p.fp == NULL) {
|
||||||
Cyc_rt_raise2(data, "Unable to open file", str);
|
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);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue