Files
LithosAnanake/v4/include/v4/capsule.h
T
rajamesandClaude Opus 5.5 42610e844f feat(v4.0.0): the nucleus is a capsule, sent to a node born empty
MESH.md step 2.  A capsule of F18 code is the words a neighbour writes to a
node's port: for each stretch of memory, "@p a! @p push", the address and
count, "@p !+ unext" and the words; then a jump to the start.  A node born
empty executes that from its port, so it needs nothing in it beforehand.

- capsule.h/.c: v4_capsule_write, any node's memory as such a capsule
- mkimage writes the nucleus so, to capsules/v4/nucleus-64.f18, and the
  addresses a host needs as a C file; the memory image is no longer linked
  into either product
- mkcapsule is unchanged: the nucleus capsule is a built file kept under
  capsules/, as BLOCK_MAP.md is, and is baked, hashed and signed with the
  rest
- boot: the node is born empty (v4_image_born); the nucleus capsule is
  found, its hash and signature checked, and given to the node a word at a
  time as it reads its port; PARITY:V4_NUCLEUS carries its name and hash

Verified: test_fabric.c (59 checks, both widths, and under ASan and UBSan):
a memory with a programme and scattered words arrives word for word in an
empty node and runs.  The nucleus capsule rebuilds byte for byte.
hosted-check passes on three ISAs; clean qemu with STARFORTH_V4=1 on amd64,
aarch64 and riscv64 takes the nucleus in, passes POST (550 of 550) and
answers lines typed at each prompt (logs/20261006-102421, -102706,
-103048).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-06 10:33:15 -04:00

37 lines
1.4 KiB
C

/* capsule.h -- a capsule of F18 code: what a neighbour writes to a node's
* port to put a programme into it and start it. docs/v4.0.0/MESH.md
* section 5.
*
* A node newly born has nothing in it and executes what arrives at its port
* (node.h). So a capsule of F18 code is not a format a node has to
* understand: it is the words themselves, in the order they are sent. For
* each stretch of memory that is not zero,
*
* @p a! @p push the node executes this from its port,
* address takes these two as its literals,
* count - 1
* @p !+ unext and then this: each word that follows is fetched
* the words ... from the port and stored
*
* and at the end
*
* jump start
*
* This is the F18's own way of loading a node through a port. Nothing here
* knows what the programme is: StarForth's nucleus is one such capsule
* (v4/tools/mkimage.c), and anything written for the node is another.
*/
#ifndef V4_CAPSULE_H
#define V4_CAPSULE_H
#include "v4/node.h"
/* Write the capsule that makes a node's memory what `n`'s is, and starts it
* at `start`: `out` is called with each word in turn. Words of `n` that
* are zero are not sent -- a node is born with its memory zero. Returns
* how many words were written. */
unsigned v4_capsule_write(const v4_node *n, v4_cell start,
void (*out)(void *self, v4_cell word), void *self);
#endif /* V4_CAPSULE_H */