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.
This commit is contained in:
Jesse D. McDonald 2009-11-19 22:16:57 -06:00
parent ce3c4f1ce9
commit 912a620c5a
4 changed files with 31 additions and 5 deletions

21
cat.rla Normal file → Executable file
View File

@ -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
)

1
core-image.rla Normal file → Executable file
View File

@ -1,3 +1,4 @@
#! /home/nybble/src/c/rosella/rosella
#S(#="lambda"
#(
#S(#="template" ; g1

View File

@ -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
{

View File

@ -76,9 +76,12 @@ int main(int argc, char **argv)
nl();
}
#if 0
nl();
fflush(stdout);
fprint_gc_stats(stderr);
#endif
}
else
{