diff options
Diffstat (limited to 'input.e')
| -rw-r--r-- | input.e | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/input.e b/input.e index 3d8fabb..16fa836 100644 --- a/input.e +++ b/input.e @@ -134,16 +134,20 @@ swap buffer-logical-start ! ; -~ (metadata pointer -- byte or 0) +~ We use -1 as a return value to indicate end-of-file. This can be +~ distinguished from valid data, because it's a full 64 bits, whereas a byte +~ of 0xFF wouldn't be. +~ +~ (metadata pointer -- byte or -1) : peek-from dup buffer-logical-length @ { ~ If the length is zero, there is no input, but we can still try calling ~ the "refill" word. ~ (metadata pointer) dup input-buffer-refill @ dup { - ~ If the refill word is zero, we can't help, just return null. + ~ If the refill word is zero, we can't help, just return EOF. ~ (metadata pointer, refill word) - drop drop 0 exit + drop drop -1 exit } unless ~ If the refill word is nonzero, call it. It expects a copy of the metadata @@ -153,9 +157,9 @@ ~ (metadata pointer) ~ Now we check if the length is still zero. dup buffer-logical-length @ { - ~ The length is zero even after calling the refill word, so return null. + ~ The length is zero even after calling the refill word, so return EOF. ~ (metadata pointer) - drop 0 exit + drop -1 exit } unless } unless @@ -171,7 +175,9 @@ buffer-logical-start @ 8@ ; -~ (metadata pointer -- byte or 0) +~ Just as with peek-from, we use -1 for EOF. +~ +~ (metadata pointer -- byte or -1) : key-from dup peek-from ~ (metadata pointer, result byte) |