diff options
| author | kitty <nepeta@canaglie.net> | 2026-03-04 14:34:13 +1100 |
|---|---|---|
| committer | kitty <nepeta@canaglie.net> | 2026-03-04 14:34:13 +1100 |
| commit | b281bf7d9ee53e4585210bb8461d78bb2f386a21 (patch) | |
| tree | 3bd520e6d2803b630773834564b9df7ab930d87d | |
| parent | 886aae5a9021f96aa9327958e962df06bb4870a6 (diff) | |
buffer-key
none of this is tested yet
need to do ACCEPT then REFILL then LOAD i guess?
| -rw-r--r-- | jefs.fs | 12 |
1 files changed, 3 insertions, 9 deletions
@@ -290,21 +290,15 @@ make buffers /buffer #buffers * allot make buffers-used #buffers cells allot make buffers->in #buffers cells allot -\ how to handle EOF? : cbuffer include-depth /buffer * buffers + ; : cbuffer-used include-depth cells buffers-used + ; : cbuffer->in include-depth cells buffers->in + ; : buffer-refill ( u|0 ) cbuffer /buffer stdin read-file 0<> if 0 then 0 cbuffer->in ! dup cbuffer-used ! ; \ returns zero on error or nothing read. -\ : buffer-key current-buffer current-buffer-used ( TODO ) ; : buffer-remaining? cbuffer->in @ cbuffer-used @ >= ; -: buffer-key ( -- key|-1 ) buffer-remaining? not if - buffer-refill 0<> if -1 [ ret, ] else 0= if -1 [ ret, ] then then then - ; -( check if remaining buffer is empty ) -( if it is, try to fill it ) -( if it doesn't work then the file has ended, yield -1 ) -( otherwise get the next char, add one to the buffer's >in, yield char ) +: buffer-key buffer-remaining? not if buffer-refill 0= if -1 [ ret, ] then then + cbuffer cbuffer->in @ + c@ + cbuffer->in @ 1+ cbuffer->in ! ; \ i think i'll just take the wonkiness of \ 'if you use LOAD or something like that you lose the rest of that line' |
