Capsule blocks steps 3+4 for v4: capsules are placed in RAM and load their lowest block
Captain Bob ruled: Block n lands at n-R; the lowest block is interpreted; chaining is the developer's; together, v4 first. - v4_blocks_place_capsule copies each Block n into RAM block n - R as 16 lines of 64, space-padded, in any file order. A later block of the same number overwrites. It refuses a block below R. - The mesh's load(), its capsule reader (CAPSULE-OPEN/(LINES), so a child's forth79.4th via BIRTH too), boot.c and test_host_unit's model each place a capsule, then interpret "<lowest> LOAD". - mkdictionary.py skips --> when it types capsules at the hosted prompt. - The v4 capsules are renumbered into R..2R-1, landing at RAM 1900 and up, away from POST's blocks 0-5. Each is chained with -->, and centre.4th's gap at 8103 is closed. Test first: - test_host_blocks.c gained 6 placement checks; it failed to build before. - test_mesh_boot.c checks forth79's lowest block in RAM block 1900; it failed before. After: POST is 990/990; all 52 tests at 64 bits, test-32, hosted-check and ASan/UBSan pass; the amd64 kernel builds; the dictionary has 404 words. Logs are in logs/20261118-capsule-place. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
+29
-4
@@ -65,6 +65,25 @@ static void put_cell(void *self, v4_cell w)
|
||||
typedef struct { const uint8_t *p, *end; int in_block; } reader;
|
||||
static reader reads[MAX_PLACES];
|
||||
|
||||
/* A capsule of FORTH blocks is placed in RAM, block n at n - R, and what is told to the node is the one
|
||||
* line that loads its lowest block (docs/v4.0.0/plans/2026-11-18-capsule-blocks.md): the rest is the
|
||||
* capsule's own (`-->`, `LOAD`, `THRU`). The line goes in text; its length, 0 when the capsule had no
|
||||
* block, or -1 when it could not be placed. */
|
||||
static int placed_line(const uint8_t *p, uint32_t length, char *text)
|
||||
{
|
||||
uint32_t lowest = 0, v;
|
||||
char d[12];
|
||||
int placed = v4_blocks_place_capsule(p, p + length, &lowest), at = 0, nd = 0;
|
||||
const char *s;
|
||||
if (placed <= 0) return placed;
|
||||
v = lowest;
|
||||
do { d[nd++] = (char)('0' + v % 10u); v /= 10u; } while (v);
|
||||
while (nd) text[at++] = d[--nd];
|
||||
for (s = " LOAD"; *s; s++) text[at++] = *s;
|
||||
return at;
|
||||
}
|
||||
static char load_text[MAX_PLACES][24]; /* each place's one line, while its reader gives it */
|
||||
|
||||
static int open_cb(void *self, unsigned asker, const char *name, unsigned len)
|
||||
{
|
||||
char cname[V4_MANAGE_LINE + 1u];
|
||||
@@ -84,7 +103,13 @@ static int open_cb(void *self, unsigned asker, const char *name, unsigned len)
|
||||
p = v4_boot_capsule(&bt, cname, &length, &id, &hash);
|
||||
if (!p) return 0;
|
||||
the->reading_nucleus[asker] = 0;
|
||||
reads[asker].p = p; reads[asker].end = p + length; reads[asker].in_block = 0;
|
||||
{
|
||||
int len = placed_line(p, length, load_text[asker]);
|
||||
if (len < 0) return 0;
|
||||
reads[asker].p = (const uint8_t *)load_text[asker];
|
||||
reads[asker].end = reads[asker].p + len;
|
||||
reads[asker].in_block = 1; /* the one line is the reader's: no header before it */
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
static int cell_cb(void *self, unsigned asker, v4_cell *w)
|
||||
@@ -1225,7 +1250,6 @@ static void post_say(void *self, const char *text, unsigned len) { ((v4_mesh *)s
|
||||
/* Every line of a capsule of FORTH blocks, told to Hera; then its parity line, as v4_boot_run prints it. */
|
||||
static int load(v4_mesh *ms, const char *name)
|
||||
{
|
||||
static reader r;
|
||||
char text[V4_MSG_MAX_CHARS + 1u];
|
||||
uint32_t length;
|
||||
uint64_t id, hash;
|
||||
@@ -1233,8 +1257,9 @@ static int load(v4_mesh *ms, const char *name)
|
||||
int n;
|
||||
v4_fabric_node *h = v4_fabric_node_at(&ms->f, ms->hera_place);
|
||||
if (!p) return 0;
|
||||
r.p = p; r.end = p + length; r.in_block = 0;
|
||||
while ((n = next_line(&r, text, V4_MSG_MAX_CHARS)) >= 0) {
|
||||
n = placed_line(p, length, text);
|
||||
if (n < 0) { say("V4: "); say(name); say(" could not be placed in RAM\n"); return 0; }
|
||||
if (n > 0) {
|
||||
int how = v4_mesh_tell(ms, V4_MESH_HERA, text, (unsigned)n);
|
||||
if (how != V4_TEXT_COMPLETED) {
|
||||
say("V4: "); say(name); say(" did not complete: "); ms->out(text, (unsigned)n); say("\n");
|
||||
|
||||
Reference in New Issue
Block a user