MESH.md step 5, in the fabric under test; the products are still one node each until steps 8 and 9. manage.c: what Hera asks of whoever holds the fabric, eleven requests by KERNEL-WORD -- NODE-ME -BORN -WIRE -UNWIRE -SLEEP -WAKE -KILL -PARITY and CAPSULE-OPEN -CELL -LINE. Nucleus: PORT!, SEND-ON, AWAIT, (SEAL). capsules/v4/hera.4th: BIRTH and UNIT, the unit rule in FORTH and nowhere else. The dictionary hash moves to the engine (v4_image_dict_hash). test_host_unit.c, 34 checks, 64-bit: Hera is born empty, takes the nucleus through her port, FORTH-79, POST and her capsule; 10 UNIT; four nodes are born, each takes the nucleus and FORTH-79 through its port from Hera and passes POST 538/538; four parities, one dictionary hash; they talk, and a message between two corners not wired goes by Hera. All v4 tests at both widths and under ASan+UBSan. hosted-check on three ISAs. Bare metal: logs/20261006-143934 (amd64), -144204 (aarch64), -144601 (riscv64). Open, recorded in MESH.md: not run at 32 bits; a node that never answers leaves Hera waiting; the capsules are read from files in the test, not from the baked directory. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
81 lines
3.4 KiB
Forth
81 lines
3.4 KiB
Forth
Block 8000
|
|
( hera.4th -- Hera: the node that has the others born and )
|
|
( manages them. docs/v4.0.0/MESH.md sections 9 and 10. )
|
|
( She asks whoever holds the fabric for a node, wires it, )
|
|
( and sends it its capsules through the port that joins )
|
|
( them. The unit rule is here and nowhere else: four outer )
|
|
( nodes round a centre, an outer node wired only inside its )
|
|
( unit. )
|
|
( Text for another node is built in PAD. )
|
|
VARIABLE (T#)
|
|
: (T0) ( -- ) 0 (T#) ! ;
|
|
: (TC) ( c -- ) PAD (T#) @ + C! 1 (T#) +! ;
|
|
: (TS) ( baddr u -- )
|
|
DUP IF 0 DO DUP I + C@ (TC) LOOP DROP ELSE DROP DROP THEN ;
|
|
: (TN) ( n -- ) 0 <# #S #> (TS) 32 (TC) ;
|
|
: (T) ( -- baddr u ) PAD (T#) @ ;
|
|
Block 8001
|
|
( The node being born: its place in the fabric, the number )
|
|
( it is to have, and the port of this node that leads to it. )
|
|
VARIABLE (KID) VARIABLE (KID#) VARIABLE (KIDP)
|
|
: (FAIL) ( -- )
|
|
." BIRTH: node " (KID#) @ . ." did not do as it was told" CR
|
|
-1 NODE-ERROR ! ;
|
|
: (TOLD) ( how -- ) 1 - IF (FAIL) THEN ;
|
|
: (TELL) ( baddr u -- ) (KID#) @ SEND (KID#) @ AWAIT (TOLD) ;
|
|
( the nucleus, a capsule of F18 code, cell by cell to its port )
|
|
: (NUCLEUS) ( -- )
|
|
S" v4:nucleus-64.f18" CAPSULE-OPEN 0= IF (FAIL) THEN
|
|
BEGIN CAPSULE-CELL WHILE (KIDP) @ PORT! REPEAT DROP ;
|
|
( a capsule of FORTH blocks, a line at a time )
|
|
: (LINES) ( baddr u -- ) CAPSULE-OPEN 0= IF (FAIL) THEN
|
|
BEGIN PAD CAPSULE-LINE DUP 0< 0= WHILE PAD SWAP (TELL) REPEAT
|
|
DROP ;
|
|
Block 8002
|
|
( who it is, where its printing goes, and that everything )
|
|
( not told of goes by its port 2, where this node is )
|
|
: (WHO) ( -- )
|
|
(T0) (KID#) @ (TN) S" (ME) ! " (TS)
|
|
(CONSOLE) @ (TN) S" (CONSOLE) ! 2 DEFAULT-ROUTE " (TS)
|
|
(ME) @ (TN) S" 2 NEIGHBOUR" (TS)
|
|
(T) 0 (KIDP) @ SEND-ON (KID#) @ AWAIT (TOLD) ;
|
|
( number port -- place A NODE IS BORN on that port of )
|
|
( this one: empty, then the nucleus, then FORTH-79 and POST. )
|
|
: BIRTH ( number port -- place )
|
|
(KIDP) ! (KID#) !
|
|
NODE-BORN DUP 0< IF (FAIL) THEN (KID) !
|
|
NODE-ME (KIDP) @ (KID) @ 2 NODE-WIRE 0= IF (FAIL) THEN
|
|
(NUCLEUS)
|
|
(KID#) @ (KIDP) @ ROUTE (KID#) @ (KIDP) @ NEIGHBOUR (WHO)
|
|
S" v4:forth79.4th" (LINES) S" v4:post79.4th" (LINES)
|
|
Block 8003
|
|
S" (SEAL)" (TELL)
|
|
(KID) @ (KID#) @ NODE-PARITY
|
|
(KID) @ ;
|
|
( Two outer nodes are joined: port 3 of X to port 4 of Y, )
|
|
( and each is told the other is there. )
|
|
VARIABLE (XP) VARIABLE (XN) VARIABLE (YP) VARIABLE (YN)
|
|
: (X) ( place number -- ) (XN) ! (XP) ! ;
|
|
: (Y) ( place number -- ) (YN) ! (YP) ! ;
|
|
: (SAY) ( them port me -- ) (KID#) !
|
|
(T0) OVER (TN) DUP (TN) S" ROUTE " (TS)
|
|
SWAP (TN) (TN) S" NEIGHBOUR" (TS) (T) (TELL) ;
|
|
: (JOIN) ( -- )
|
|
(XP) @ 3 (YP) @ 4 NODE-WIRE 0= IF (FAIL) THEN
|
|
(YN) @ 3 (XN) @ (SAY) (XN) @ 4 (YN) @ (SAY) ;
|
|
Block 8004
|
|
( n -- A UNIT: four outer nodes, n+1 to n+4, on ports 2 )
|
|
( to 5 of this one, and joined in a square: 1-2, 2-4, 4-3, )
|
|
( 3-1. The corners across from each other are not wired: )
|
|
( what one sends the other goes by this node. )
|
|
VARIABLE (U)
|
|
VARIABLE (P1) VARIABLE (P2) VARIABLE (P3) VARIABLE (P4)
|
|
: (N) ( k -- number ) (U) @ + ;
|
|
: UNIT ( n -- ) (U) !
|
|
1 (N) 2 BIRTH (P1) ! 2 (N) 3 BIRTH (P2) !
|
|
3 (N) 4 BIRTH (P3) ! 4 (N) 5 BIRTH (P4) !
|
|
(P1) @ 1 (N) (X) (P2) @ 2 (N) (Y) (JOIN)
|
|
(P2) @ 2 (N) (X) (P4) @ 4 (N) (Y) (JOIN)
|
|
(P4) @ 4 (N) (X) (P3) @ 3 (N) (Y) (JOIN)
|
|
(P3) @ 3 (N) (X) (P1) @ 1 (N) (Y) (JOIN) ;
|