revert(v4.0.0): step 6d, the wait, is backed out -- two reviews found it unsound
Ruled 2026-10-08. The engine, the nucleus and their tests are as they
were at dfabfa46, before step 6d; the code of the wait and its tests are
in history at 075385ab..2cf37aab. The limit of MESH.md 7b.7 stands: a
node that is stuck can hold up its neighbours until Hera kills it.
MESH.md 7c is kept as the record of the design as approved, and 7c.6 says
what was built, what the two reviews found, the cause the findings share
-- a node's message machinery runs on the stacks its text is using, and a
fault abandons whatever was in progress -- and what a second attempt
must settle before anything is built.
Kept from it, in hosted-check: a line that leaves 29 values on the stack,
and WORDS with 26 values on it. Both hung the products at some commit of
the wait.
make -C v4 test and sanitize at both widths, hosted-check, lint; three
bare-metal boots typing both. POST 538 of 538, word_count=317,
dict_hash=0xc0769523a47b7dc3 on all six: the hash of step 6c's code.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
10f5ffd00b
commit
6015c87157
+78
-143
@@ -131,22 +131,25 @@ header CMOVE
|
||||
NONE: drop drop (ROUTE-DEFAULT) a! @ ;
|
||||
HIT: drop drop @+ pop drop ;
|
||||
|
||||
\ BEGINNING A MESSAGE: THE WAIT (MESH.md section 7c). A write waits until
|
||||
\ the neighbour reads, and a node that is waiting to write reads nothing:
|
||||
\ two neighbours that each began to write to the other would wait for ever,
|
||||
\ and a node that wrote to one that was stuck would be stuck with it. So
|
||||
\ a node does not write the first word of a message. It offers it, (GATE):
|
||||
\ the word is stored at the port's offer address, and the node then reads
|
||||
\ the wait, where it sleeps until the offer is taken or a word comes for
|
||||
\ it, whichever is first. If a word comes, that message is taken in and
|
||||
\ kept with the messages waiting, and the node offers again. When the
|
||||
\ offer is taken the neighbour has the first word and reads to the end:
|
||||
\ the rest is written, each word waiting for it.
|
||||
\ (OFFER) is the offer address of port 0, and (WAIT) the wait. (READERS)
|
||||
\ is the node's look at its neighbours, a bit for each port that has one
|
||||
\ waiting to read, and above those a bit for each port that has anything
|
||||
\ on it at all. (NEAR) is the number of the node on each port, told by
|
||||
\ whoever wires it (NEIGHBOUR, quit.v4): it is how a node knows its centre.
|
||||
\ LOOKING BEFORE WRITING (MESH.md section 7a). A write waits until the
|
||||
\ neighbour reads, and a node that is waiting to write reads nothing: two
|
||||
\ neighbours that each began to write to the other would wait for ever. So
|
||||
\ a node does not begin a message until it has looked, (GATE):
|
||||
\ - while any neighbour is waiting to write to it, it takes that message
|
||||
\ in and keeps it with the messages waiting, to deal with when it has
|
||||
\ nothing else to do;
|
||||
\ - then, if the neighbour it means to write to is waiting to read, it
|
||||
\ writes;
|
||||
\ - and if that neighbour is not, it writes all the same when the
|
||||
\ neighbour's number is the higher of the two, and otherwise looks
|
||||
\ again. Of two neighbours one only may wait to write to the other, and
|
||||
\ it is the lower: so those that wait are waiting on ever higher
|
||||
\ numbers, and the highest of them is not waiting to write; it is
|
||||
\ looking, and takes in what is being written to it.
|
||||
\ (WRITERS) and (READERS) are the node's two looks at its neighbours, a bit
|
||||
\ for each port. (NEAR) is the number of the node on each port, told by
|
||||
\ whoever wires it (NEIGHBOUR, quit.v4); a port not told of -- a device's
|
||||
\ -- is written to only when what is there is waiting to read.
|
||||
\
|
||||
\ THE MESSAGES WAITING are kept in (MQ) .. (MQ-END), one after another,
|
||||
\ going round: for each its seven words, the port it came on, and its text.
|
||||
@@ -159,6 +162,12 @@ header CMOVE
|
||||
if Z -1 + FOR 2/ NEXT 1 and ;
|
||||
Z: drop 1 and ;
|
||||
|
||||
\ ( mask -- index ) the lowest port in it; the mask is not zero
|
||||
: (LOW)
|
||||
0 push
|
||||
L: dup 1 and if UP drop drop pop ;
|
||||
UP: drop 2/ pop 1 + push jump L
|
||||
|
||||
\ ( w -- ) one more cell of the messages waiting. B is kept.
|
||||
: (MQ!)
|
||||
(MQ-TAIL) a! @ a! !+
|
||||
@@ -182,7 +191,7 @@ header CMOVE
|
||||
\ messages in so as to be free to write, where it cannot begin a message
|
||||
\ of its own: so it notes what it owes, (OWE), in the eight pairs at
|
||||
\ (OWED) -- whom it is owed to, and the node the message was for -- and
|
||||
\ sends it when it next has nothing else to do, (PAY-SET). With eight owed
|
||||
\ sends it when it next has nothing else to do, (PAY). With eight owed
|
||||
\ already, one more is let go and counted. Nothing is owed for a NACK or
|
||||
\ for a GONE, type 5: there is no NACK for a NACK. The last 36 cells of
|
||||
\ the messages waiting are kept for those two types, so that ordinary
|
||||
@@ -239,76 +248,37 @@ 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 0 (TAKING) a! ! ;
|
||||
NOTEXT: drop 0 (TAKING) a! ! ;
|
||||
pop if NOTEXT -1 + FOR @b (MQ!) NEXT ;
|
||||
NOTEXT: drop ;
|
||||
FULL: drop if READ -1 + FOR @b drop UNEXT jump LOSE
|
||||
READ: drop
|
||||
LOSE: (LOST) a! @ 1 + !
|
||||
(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 ;
|
||||
(MQ-HDR)+1 a! @ (MQ-HDR) a! @ (MQ-HDR)+2 a! @ jump (TELL-OF)
|
||||
|
||||
\ ( port to -- ) take in a message and keep it
|
||||
: (TAKE) (TAKE-HDR) jump (TAKE-KEEP)
|
||||
|
||||
\ ( -- how ) THE WAIT, once. Whatever has been offered stands until
|
||||
\ this returns. 0: a word came for this node instead; that whole message
|
||||
\ has been taken in and kept, (TAKE), and its seven words are still in
|
||||
\ (MQ-HDR). -1: an offer was taken; B is at the port it was taken on, and
|
||||
\ (GATE-PORT) holds that port's address. 1: there is nothing on a port
|
||||
\ that had an offer: no one will ever take it.
|
||||
: (OFFERS)
|
||||
(WAIT) b! @b push (PORT)+9 b! @b \ ( which ) R: the word
|
||||
dup -PORTS + -if TAKEN
|
||||
drop (PORT) + dup b! pop (TAKE) 0 ; \ a word, from that port: the message's first
|
||||
TAKEN: dup -PORTS + -if NOONE \ ( which k x ) k: the port, by its number
|
||||
drop (PORT) + (GATE-PORT) a! ! drop pop drop
|
||||
(GATE-PORT) a! @ b! -1 ;
|
||||
NOONE: drop drop drop pop drop 1 ;
|
||||
|
||||
\ ( w port -- ) BEGIN A MESSAGE: the word, its first, is offered on the
|
||||
\ port, by its address, until it is taken; whatever is written to this
|
||||
\ node meanwhile is taken in. B is left at the port. The two are kept in
|
||||
\ (GATE-WORD) and (GATE-PORT), not on the stack: (GATE1), which is this
|
||||
\ with the word already in (GATE-WORD), is run with the stack as full as
|
||||
\ EMIT may be.
|
||||
\ TEXT FROM THE CONSOLE for this node, coming while text it is doing waits
|
||||
\ here, ends that text in error 21, Interrupted (MESH.md 7c.3); it is with
|
||||
\ the messages waiting and is done next. It is how a node whose text must
|
||||
\ begin a message to a node that is stuck is typed to. Not while (QUIET)
|
||||
\ is set: what waits then is no text's doing.
|
||||
\ With nothing on the port it is error 18.
|
||||
: (GATE1) ( port -- )
|
||||
\ ( port -- ) wait until a message may be begun on the port, by its
|
||||
\ address, taking in whatever is being written to this node meanwhile; and
|
||||
\ leave B at the port. The port is kept in (GATE-PORT), not on the stack:
|
||||
\ this is run with the stack as full as EMIT may be.
|
||||
: (GATE)
|
||||
(GATE-PORT) a! !
|
||||
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
|
||||
(QUIET) a! @ if TEXTS drop jump L
|
||||
TEXTS: drop
|
||||
(MQ-HDR) a! @ (ME) a! @ xor if MINE drop jump L
|
||||
MINE: drop
|
||||
(MQ-HDR)+2 a! @ -1 + if TEXT drop jump L
|
||||
TEXT: drop
|
||||
(CONSOLE) a! @ if C0 jump C1
|
||||
C0: drop (MSG)+1 a! @ \ no console told of: whoever sent the text being done
|
||||
C1: (MQ-HDR)+1 a! @ xor if BREAK drop jump L
|
||||
BREAK: drop NODE-ERROR b! 21 !b ;
|
||||
|
||||
: (GATE) ( w port -- ) push (GATE-WORD) a! ! pop jump (GATE1)
|
||||
L: (WRITERS) b! @b if QUIET
|
||||
(LOW) (PORT) + dup b! @b (TAKE) jump L
|
||||
QUIET: drop
|
||||
(GATE-PORT) a! @ (PORT) - (NEAR) + a! @ if ASK
|
||||
(ME) a! @ - -if GO jump ASK \ its number less this node's
|
||||
GO: drop (GATE-PORT) a! @ b! ; \ the neighbour's is the higher
|
||||
ASK: drop
|
||||
(READERS) b! @b (GATE-PORT) a! @ (PORT) - (BIT) if NOTYET
|
||||
drop (GATE-PORT) a! @ b! ; \ it is waiting to read
|
||||
NOTYET: drop
|
||||
(READERS) b! @b (GATE-PORT) a! @ (PORT) - -PORTS - (BIT) if NOONE \ is there anything on the port at all?
|
||||
drop jump L
|
||||
NOONE: drop NODE-ERROR b! 18 !b ; \ no: what waits here would wait for ever
|
||||
|
||||
\ ( type -- ) words 1 to 5 of a message this node sends: from, type, and
|
||||
\ the three that are carried and not used yet. Its caller has put B at the
|
||||
@@ -319,30 +289,14 @@ header CMOVE
|
||||
!b \ type
|
||||
16 !b 0 !b 0 !b ; \ how many nodes may pass it on (the TTL: MESH.md 7b); ACL tag; sequence
|
||||
|
||||
\ PAYING WHAT IS OWED (MESH.md 7c.3). Every refusal owed is offered at
|
||||
\ once, each on the port it goes by, one to a port, with whatever the node
|
||||
\ has to pass on (quit.v4, (IDLE)), and the node sleeps in the wait: so
|
||||
\ one owed to a node that is stuck does not keep back one owed to a node
|
||||
\ that waits for it, and the node takes in whatever is written to it
|
||||
\ meanwhile. One there is no way for, or whose way is a
|
||||
\ port with nothing on it, is let go and counted first. (PAY-K) has a
|
||||
\ 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! ! ;
|
||||
\ PAYING WHAT IS OWED does not hold this node up. A refusal is sent if the
|
||||
\ neighbour it goes by is reading at this moment. If it is not, and its
|
||||
\ number is the higher, the refusal is written all the same, as any message
|
||||
\ would be (MESH.md 7a): that neighbour takes it in when it next looks. If
|
||||
\ its number is the lower, or it has not been told of, the refusal stays
|
||||
\ owed, and this node goes on with what it has to do and tries again; it
|
||||
\ does not sleep while it owes one (quit.v4, (IDLE)). One there is no way
|
||||
\ for, or whose way is a port with nothing on it, is let go and counted.
|
||||
|
||||
\ ( k -- ) the k-th refusal owed is done with: the last takes its place
|
||||
: (PAID)
|
||||
@@ -350,55 +304,36 @@ header CMOVE
|
||||
2* (OWED) + a! @+ @
|
||||
push push 2* (OWED) + a! pop !+ pop ! ;
|
||||
|
||||
\ ( k -- ) the k-th refusal owed is let go if it cannot be sent at all
|
||||
: (PAY-DROP)
|
||||
dup 2* (OWED) + a! @ \ k to
|
||||
(PORT-FOR) if NOWAY \ k port
|
||||
(THERE) if GONE drop drop ;
|
||||
GONE:
|
||||
NOWAY: drop (LOST) a! @ 1 + ! jump (PAID)
|
||||
\ ( k -- ) send the k-th refusal owed, if it can go now
|
||||
: (PAY1)
|
||||
dup 2* (OWED) + a! @+ @ \ k to about
|
||||
over (PORT-FOR) if NOWAY \ k to about port
|
||||
dup (THERE) if GONE
|
||||
drop (READERS) b! @b over (PORT) - (BIT) if BUSY
|
||||
drop
|
||||
WRITE: b! \ k to about B: the port
|
||||
SWAP !b 4 (HDR) 4 !b !b \ k to; from, type 4; four characters; about
|
||||
jump (PAID)
|
||||
BUSY: drop \ it is not reading:
|
||||
dup (PORT) - (NEAR) + a! @ if LEAVE \ k to about port near
|
||||
(ME) a! @ - -if BLIND jump LEAVE \ its number less this node's
|
||||
BLIND: drop jump WRITE \ the higher: it will take it in
|
||||
LEAVE: drop drop drop drop drop ;
|
||||
GONE: drop
|
||||
NOWAY: drop drop drop (LOST) a! @ 1 + ! jump (PAID)
|
||||
|
||||
\ ( k -- ) offer the k-th refusal owed on its port, if nothing is there yet
|
||||
: (PAY-OFFER)
|
||||
dup push 2* (OWED) + a! @ \ to R: k (the stack is kept shallow: this runs between lines)
|
||||
dup (PORT-FOR) (PORT) - \ to n the port, by its number
|
||||
dup (PAY-K) + a! @ if FREE
|
||||
drop drop drop pop drop ;
|
||||
FREE: drop
|
||||
dup push (OFFER) + a! ! \ the message's first word, whom it is to
|
||||
pop pop 1 + SWAP (PAY-K) + a! ! ;
|
||||
|
||||
\ ( -- ) 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
|
||||
NONE: drop
|
||||
CLEAR: (PAY-K) a! PORTS-1 FOR 0 !+ NEXT
|
||||
(OWED#) a! @ if NONE2
|
||||
-1 + FOR pop dup push (PAY-OFFER) NEXT ;
|
||||
NONE2: drop ;
|
||||
|
||||
\ ( 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 (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 every refusal this node owes that can go now
|
||||
: (PAY)
|
||||
(OWED#) a! @ if NONE -1 +
|
||||
FOR pop dup push (PAY1) NEXT ;
|
||||
NONE: drop ;
|
||||
|
||||
\ ( -- ) 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
|
||||
\ lowest. quit.v4 sets those two when text for this node arrives.
|
||||
: (FLUSH-OUT)
|
||||
(OUT^) a! @ (OUT) xor if NONE drop
|
||||
(PRINT-TO) a! @ (GATE-WORD) a! ! (PRINT-PORT) a! @ (GATE1)
|
||||
(PRINT-PORT) a! @ (GATE) (PRINT-TO) a! @ !b
|
||||
2 (HDR)
|
||||
(OUT^) a! @ (OUT) - dup !b
|
||||
3 + 2/ 2/ -1 + (OUT) a!
|
||||
|
||||
Reference in New Issue
Block a user