From 3b565483d9fbf6454d6d0e79a4e8fe1ae6c9eace Mon Sep 17 00:00:00 2001 From: Irene Knapp Date: Wed, 23 Sep 2026 20:36:05 -0700 Subject: properly report and handle EOF when handling input this should be a robust fix for the double-termination issue when compiling Force-Push: yes Change-Id: Ieaacdc232ea7e3036916d81139fc5c5a41087c64 --- input.e | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'input.e') 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) -- cgit 1.4.1