From 912a620c5a82502ec0288b14e29ae9735ba74d30 Mon Sep 17 00:00:00 2001 From: Jesse McDonald Date: Thu, 19 Nov 2009 22:16:57 -0600 Subject: [PATCH] Add some error-handling to cat.rla. Add support for #! lines. Also fix an off-by-one error in the column counter and suppress GC stats. --- cat.rla | 21 ++++++++++++++++++--- core-image.rla | 1 + reader.c | 11 +++++++++-- rosella.c | 3 +++ 4 files changed, 31 insertions(+), 5 deletions(-) mode change 100644 => 100755 cat.rla mode change 100644 => 100755 core-image.rla diff --git a/cat.rla b/cat.rla old mode 100644 new mode 100755 index d8228b6..c243153 --- a/cat.rla +++ b/cat.rla @@ -1,3 +1,5 @@ +#! /home/nybble/src/c/rosella/rosella + ;(lambda (pathname) ; (let [(fd (posix-open pathname O_RDONLY))] ; (let [(str (make-byte-string 4096))] @@ -5,6 +7,7 @@ ; (let [(size (posix-read fd str (byte-string-size str)))] ; (posix-write 1 str size)) ; (loop))))) + #S(#="lambda" #( 0 @@ -68,16 +71,28 @@ 0x40 ; i0 0x41 ; i1 ) + #S(#="template" + #(0 #f) + "\x81\xfe" ; f1 k + 1 + "\x00\x80\x03\xfd\; (set! f0 (car argv)) + \x80\x80\x40\x41"; (set! f0 (if f0 i0 i1)) + 0x80 ; f0 + 0xfd ; argv + 0x02 ; g2 + 0x02 ; g2 + ) ) #() - 2 + 3 "\x02\x80\x01\x00\; (set! f0 (cons g1 nil)) \x00\x81\x03\xfd\; (set! f1 (car argv)) \x02\x80\x81\x80\; (set! f0 (cons f1 f0)) - \x00\x81\x1b\x03"; (set! f1 (lambda g3)) + \x00\x81\x1b\x03\; (set! f1 (lambda g3)) + \x00\x82\x1b\x04"; (set! f2 (lambda g4)) 0x02 ; g2 0x80 ; f0 - 0x81 ; f1 + 0x82 ; f2 0xff ; ctx ) diff --git a/core-image.rla b/core-image.rla old mode 100644 new mode 100755 index 96e84ff..a9bd8d4 --- a/core-image.rla +++ b/core-image.rla @@ -1,3 +1,4 @@ +#! /home/nybble/src/c/rosella/rosella #S(#="lambda" #( #S(#="template" ; g1 diff --git a/reader.c b/reader.c index b2f0a24..fb74605 100644 --- a/reader.c +++ b/reader.c @@ -55,7 +55,8 @@ value_t read_value(FILE *f) register_gc_root(&state.ref_list, NIL); state.file = f; - state.line = state.column = 1; + state.line = 1; + state.column = 0; next_char(&state); result = read_one_value(&state); ungetc(state.ch, f); @@ -120,6 +121,12 @@ static value_t read_special(reader_state_t *state) switch (state->ch) { + case '!': + release_assert((state->line == 1) && (state->column == 2)); + do { + next_char(state); + } while (state->ch != '\n'); + return read_one_value(state); case 'F': case 'f': next_char(state); @@ -799,7 +806,7 @@ static void next_char(reader_state_t *state) if (state->ch == '\n') { ++state->line; - state->column = 1; + state->column = 0; } else { diff --git a/rosella.c b/rosella.c index f277f85..37bc309 100644 --- a/rosella.c +++ b/rosella.c @@ -76,9 +76,12 @@ int main(int argc, char **argv) nl(); } +#if 0 nl(); fflush(stdout); + fprint_gc_stats(stderr); +#endif } else {