summary refs log tree commit diff
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@irenes.space>2026-04-08 16:50:21 -0700
committerIrene Knapp <ireneista@irenes.space>2026-04-08 16:50:21 -0700
commit786da04fbd52177a43f337060833debaeb3737cb (patch)
tree5fe4b5953d7e815eeb3cb1c806c2e62ec3fcafd8
parent72e2c06a1eb055be291a79c03748213de943da40 (diff)
change guess_entry_end_in's behavior for inputs that don't exist
this had been an outstanding TODO

Force-Push: yes
Change-Id: Ib3e4a654f3a4323175e2bbf37a6403a8b84ffc8d
-rw-r--r--quine.asm21
1 files changed, 13 insertions, 8 deletions
diff --git a/quine.asm b/quine.asm
index 213cb23..fdf55c9 100644
--- a/quine.asm
+++ b/quine.asm
@@ -5298,18 +5298,23 @@ defword guess_entry_end_in, 0
   ; saying the length is zero.
   dq swap, drop, swap, drop, exit
   ; If not, search backwards from the end to find the following entry.
+  ; (here, original entry address)
+  dq dup, unroll3
+  ; (original entry address, here, original entry address)
   dq next_newer_entry_in
-  ; (here, next entry address or 0)
+  ; (original entry address, here, next entry address or 0)
 
   ; Check whether we were able to find the next-entry address.
-  dq dup, lit, 0, eq, zbranch, 3*8
+  dq dup, lit, 0, eq, zbranch, 4*8
+
   ; This is the branch where the original entry is not in the list. Return
-  ; "here".
-  ;
-  ; TODO it would probably be better to return the original entry address.
-  dq drop, exit
-  ; This is the branch where it's found. Return the next entry address.
-  dq swap, drop, exit
+  ; the original entry address as the result; as above, this means we're
+  ; saying the length is zero. Since we don't have anything else to go on,
+  ; this is the safe assumption.
+  dq drop, drop, exit
+
+  ; This is the branch where we found it. Return the next entry address.
+  dq swap, drop, swap, drop, exit
 
 ;   Jonesforth calls this "CFA>". Jonesforth's implementation searches the
 ; entire dictionary, since its word header format isn't designed to be