diff options
| author | kitty <nepeta@canaglie.net> | 2026-03-04 14:14:41 +1100 |
|---|---|---|
| committer | kitty <nepeta@canaglie.net> | 2026-03-04 14:14:41 +1100 |
| commit | 886aae5a9021f96aa9327958e962df06bb4870a6 (patch) | |
| tree | 950b3f59710e3dcfa02bdd7fac59521f262bedbf | |
| parent | 2514a1194acf7c6579ee7a1f7437e2436a8aa4c2 (diff) | |
kinda losing steam i think, but i'd like to get this done
| -rw-r--r-- | jefs.fs | 43 |
1 files changed, 31 insertions, 12 deletions
@@ -279,17 +279,36 @@ variable source-id -1 constant string-source init-source source-id ! -\ plan: stdin buffering is separated from loaded file buffering. -\ these words will only be used when source-id = 0. -\ when a file loads another file, the new file will not be buffered -\ because the buffer is already in use. -\ solution seems bad but i don't know the best way to handle it -8192 constant input-buffer-length -make input-buffer input-buffer-length allot - -: buffer-refill input-buffer input-buffer-length stdin read-file ( handle err ) ; -: buffer-key ; - +\ including the console input, we can recurse input buffers +\ up to four levels. (max-include-depth <=) +\ todo maybe these should be renamed +0 value include-depth +3 constant max-include-depth +max-include-depth 1+ constant #buffers +8192 constant /buffer +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 ) + +\ i think i'll just take the wonkiness of +\ 'if you use LOAD or something like that you lose the rest of that line' +\ i dont think that's that big a deal 2048 constant line-buffer-length make line-buffer line-buffer-length allot @@ -317,5 +336,5 @@ make line-buffer line-buffer-length allot \ }}} .free -input-buffer input-buffer-length stdin read-file drop input-buffer swap evaluate +\ input-buffer buffer-length stdin read-file drop input-buffer swap evaluate bye |
