From 030a289497db1fcbd22eafb99d7d8827bca94563 Mon Sep 17 00:00:00 2001 From: Aryadev Chavali Date: Mon, 1 Sep 2025 21:47:25 +0100 Subject: Some changes to how streams work, clean up alisp.org --- alisp.h | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'alisp.h') diff --git a/alisp.h b/alisp.h index 41c507c..a1f1748 100644 --- a/alisp.h +++ b/alisp.h @@ -136,19 +136,24 @@ stream_err_t stream_init_string(stream_t *, char *, sv_t); stream_err_t stream_init_file(stream_t *, char *, FILE *); void stream_stop(stream_t *); -// end of stream -bool stream_eos(stream_t *); -// end of cache +// End of Content (i.e. we've consumed all cached content/file) bool stream_eoc(stream_t *); +// size of immediately accessible content u64 stream_size(stream_t *); -bool stream_chunk(stream_t *); +// Return current character, push position by 1 char stream_next(stream_t *); +// Peek current character, do not push position char stream_peek(stream_t *); +// Seek forward or backward in the stream, return success bool stream_seek(stream_t *, i64); bool stream_seek_forward(stream_t *, u64); bool stream_seek_backward(stream_t *, u64); + +// Return a relative substring (using sv_t) of a given size sv_t stream_substr(stream_t *, u64); +// Return an absolutely located substring (using sv_t) at given index and of +// given size. sv_t stream_substr_abs(stream_t *, u64, u64); /// Basic defintions for a Lisp @@ -231,4 +236,18 @@ lisp_t *tag_sym(char *); lisp_t *tag_cons(cons_t *); lisp_t *tag_vec(vec_t *); +/// Reader +typedef enum +{ + READ_OK = 0, +} read_err_t; + +// Attempt to read an expression from the stream, storing it in a pointer, +// returning any errors if failed +read_err_t read(sys_t *, stream_t *, lisp_t **); + +// Attempt to read all expressions from a stream till end of content, storing +// them in the given vector. Return any error at any point during the read. +read_err_t read_all(sys_t *, stream_t *, vec_t *); + #endif -- cgit v1.2.3-13-gbd6f