diff options
| -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' |
