fix(v4.0.0): step 6d after its review -- no error in the middle of the messages waiting, no offer left standing

Ruled 2026-10-08: A, B, C, D and the guard for a half message.  Each with
a scene in test_host_mesh.c that failed first.

A. The words of a message after its first are written from the passes
   over the messages waiting by (!W): an offer and a wait for that offer
   only (a new engine address).  A reader removed in mid-message makes no
   error; the rest is let go and counted.  Before, the error left the
   messages waiting in pieces and the node going round for ever.
B. A store to the wait withdraws every offer; (GATE1) and (PAY-SET) do it
   first.  Before, text begun after a node went round without sleeping
   could go to the port of an older offer: text for one node was done by
   another.
C. What a finished text printed is put with the messages waiting, as how
   it ended is.  With no room either is let go and counted; neither is
   begun as a message from (FINISH) any more, where a stuck node on the
   way held the whole node.
D. Only what a sender is owed from an earlier text -- its output, how it
   ended -- holds that sender's next text back; a GONE does not; and what
   cannot be noted holds nothing.  A node's own messages keep the order
   they were made in.
-  A message half taken in when its writer is removed is let go
   ((MQ-MEND)), not kept as if whole.
-  Smaller: a refused line no longer ends a waiting text 'Interrupted';
   a node's own queued messages may be passed on by 16 nodes, not 15; no
   value is left on the stack when a port goes in mid-refusal.

make -C v4 test and sanitize at both widths, hosted-check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rajames
2026-10-08 06:34:15 -04:00
co-authored by Claude Opus 5.5
parent 380f1cc6ec
commit 2cf37aab4f
9 changed files with 289 additions and 62 deletions
+41 -7
View File
@@ -239,14 +239,26 @@ header CMOVE
KEPT-FOR: drop -MQ-ROOM +
ROOM: -if FULL
drop push
(MQ-TAIL) a! @ (T-TAIL) a! ! (MQ#) a! @ (T-COUNT) a! ! 1 (TAKING) a! ! \ until all of it is here: (MQ-MEND)
(MQ-HDR) a! @ (MQ!) (MQ-HDR)+1 a! @ (MQ!) (MQ-HDR)+2 a! @ (MQ!) (MQ-HDR)+3 a! @ (MQ!)
(MQ-HDR)+4 a! @ (MQ!) (MQ-HDR)+5 a! @ (MQ!) (MQ-HDR)+6 a! @ (MQ!) (MQ-HDR)+7 a! @ (MQ!)
pop if NOTEXT -1 + FOR @b (MQ!) NEXT ;
NOTEXT: drop ;
pop if NOTEXT -1 + FOR @b (MQ!) NEXT 0 (TAKING) a! ! ;
NOTEXT: drop 0 (TAKING) a! ! ;
FULL: drop if READ -1 + FOR @b drop UNEXT jump LOSE
READ: drop
LOSE: (LOST) a! @ 1 + !
(MQ-HDR)+1 a! @ (MQ-HDR) a! @ (MQ-HDR)+2 a! @ jump (TELL-OF)
(MQ-HDR)+2 a! @ push 0 (MQ-HDR)+2 a! ! \ its type is taken out of (MQ-HDR): it is not here
(MQ-HDR)+1 a! @ (MQ-HDR) a! @ pop jump (TELL-OF)
\ ( -- ) A MESSAGE HALF TAKEN IN IS LET GO. Whoever was writing it was
\ removed, and the error that told this node so ended the taking in: what
\ had come is with the messages waiting, and would be taken for a whole
\ message. They are put back as they were before it, and it is counted.
: (MQ-MEND)
(TAKING) a! @ if WHOLE
drop (T-TAIL) a! @ (MQ-TAIL) a! ! (T-COUNT) a! @ (MQ#) a! ! 0 (TAKING) a! !
(LOST) a! @ 1 + ! ;
WHOLE: drop ;
\ ( port to -- ) take in a message and keep it
: (TAKE) (TAKE-HDR) jump (TAKE-KEEP)
@@ -280,7 +292,8 @@ header CMOVE
\ With nothing on the port it is error 18.
: (GATE1) ( port -- )
(GATE-PORT) a! !
L: (GATE-WORD) a! @ (GATE-PORT) a! @ -PORTS - 4 + a! ! \ the offer
L: 0 (WAIT) a! ! \ nothing else is offered
(GATE-WORD) a! @ (GATE-PORT) a! @ -PORTS - 4 + a! ! \ the offer
(OFFERS) if CAME -if NOONE drop ;
NOONE: drop NODE-ERROR b! 18 !b ; \ no one on that port
CAME: drop
@@ -316,6 +329,21 @@ header CMOVE
\ cell for each port: which refusal is offered there, counted from 1; 0,
\ none; -1, a message being passed on.
\ ( w -- ) WRITE A WORD OF A MESSAGE AFTER ITS FIRST, on the port
\ (GATE-PORT) holds, from where no error must come: the passes over the
\ messages waiting (quit.v4). It is offered, and the node waits for that
\ offer only: the neighbour has the first word and is reading the rest.
\ If there turns out to be nothing on the port -- the neighbour was removed
\ -- (W-GONE) is set, and this word and every one after it is let go
\ without waiting. Whoever begins the writing clears (W-GONE) first.
: (!W)
(W-GONE) a! @ if THERE drop drop ;
THERE: drop
(GATE-PORT) a! @ -PORTS - 4 + a! !
(WAIT1) b! @b drop (PORT)+9 b! @b
-PORTS + -PORTS + -if NOONE drop ;
NOONE: drop 1 (W-GONE) a! ! ;
\ ( k -- ) the k-th refusal owed is done with: the last takes its place
: (PAID)
(OWED#) a! @ -1 + dup !
@@ -343,6 +371,7 @@ header CMOVE
\ ( -- ) let go every refusal owed that cannot be sent; no port has an
\ offer; then offer each that is left on its port
: (PAY-SET)
0 (WAIT) a! ! \ what was offered before is not: (IDLE) may have gone round without waiting
(OWED#) a! @ if NONE
-1 + FOR pop dup push (PAY-DROP) NEXT
jump CLEAR
@@ -355,9 +384,14 @@ header CMOVE
\ ( k -- ) the offer of the k-th refusal owed was taken, and B is at the
\ port: its other words are written, and it is done with
: (PAY-GO)
dup 2* (OWED) + 1 + a! @ \ k about
4 (HDR) 4 !b !b \ from, type 4; four characters; about
jump (PAID)
dup (A-WORD) a! ! \ k is kept off the stack: nothing is left there if the port goes
2* (OWED) + 1 + a! @ push \ R: about
0 (W-GONE) a! !
(ME) a! @ (!W) 4 (!W) 16 (!W) 0 (!W) 0 (!W) \ from, type 4, and the three carried
4 (!W) pop (!W) \ four characters; about
(W-GONE) a! @ if SENT drop (LOST) a! @ 1 + ! jump DONE
SENT: drop
DONE: (A-WORD) a! @ jump (PAID)
\ ( -- ) send what has been printed, to where (PRINT-TO) says, by the port
\ (PRINT-PORT): its length, then its characters, four to a word, the first