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:
@@ -100,6 +100,26 @@ static int read_file(reader *r, const char *name)
|
||||
r->at = 0; r->in_block = 0; r->is_f18 = 0; r->cells_at = 0;
|
||||
return 1;
|
||||
}
|
||||
/* A capsule of FORTH blocks, as the kernel takes it in (v4/system/mesh.c; docs/v4.0.0/plans/
|
||||
* 2026-11-18-capsule-blocks.md): its blocks placed in RAM, block n at n - R, and the reader left
|
||||
* with the one line that loads the lowest. 0 if it could not be read or placed. */
|
||||
static int place_file(reader *r, const char *name)
|
||||
{
|
||||
uint32_t lowest = 0;
|
||||
int placed;
|
||||
char one[40];
|
||||
if (!read_file(r, name)) return 0;
|
||||
placed = v4_blocks_place_capsule((const uint8_t *)r->text, (const uint8_t *)r->text + r->len, &lowest);
|
||||
if (placed < 0) return 0;
|
||||
snprintf(one, sizeof one, placed ? "Block 1\n%u LOAD\n" : "\n", (unsigned)lowest);
|
||||
free(r->text);
|
||||
r->len = (long)strlen(one);
|
||||
r->text = (char *)malloc((size_t)r->len + 1);
|
||||
if (!r->text) return 0;
|
||||
memcpy(r->text, one, (size_t)r->len + 1);
|
||||
r->at = 0; r->in_block = 0;
|
||||
return 1;
|
||||
}
|
||||
/* the next line of a block that has anything on it: its length, or -1 */
|
||||
static int next_line(reader *r, char *text)
|
||||
{
|
||||
@@ -175,8 +195,8 @@ static int host_open(void *self, unsigned asker, const char *name, unsigned len)
|
||||
reader *r = &reads[asker];
|
||||
(void)self;
|
||||
if (len == 17 && memcmp(name, "v4:nucleus-64.f18", 17) == 0) { r->is_f18 = 1; r->cells_at = 0; return 1; }
|
||||
if (len == 14 && memcmp(name, "v4:forth79.4th", 14) == 0) return read_file(r, "forth79.4th");
|
||||
if (len == 13 && memcmp(name, "v4:centre.4th", 13) == 0) return read_file(r, "centre.4th");
|
||||
if (len == 14 && memcmp(name, "v4:forth79.4th", 14) == 0) return place_file(r, "forth79.4th");
|
||||
if (len == 13 && memcmp(name, "v4:centre.4th", 13) == 0) return place_file(r, "centre.4th");
|
||||
return 0;
|
||||
}
|
||||
static int host_cell(void *self, unsigned asker, v4_cell *w)
|
||||
@@ -331,15 +351,15 @@ static void post_say(void *self, const char *text, unsigned len)
|
||||
if (post_said_len + len < sizeof post_said) { memcpy(post_said + post_said_len, text, len); post_said_len += len; post_said[post_said_len] = 0; }
|
||||
}
|
||||
|
||||
/* Every line of a capsule of FORTH blocks, told to a node from the console:
|
||||
* how many lines did not complete. */
|
||||
/* A capsule of FORTH blocks, placed in RAM and its lowest block loaded, told to a node from the
|
||||
* console: how many lines did not complete. */
|
||||
static unsigned load(v4_cell node, const char *file)
|
||||
{
|
||||
static reader r;
|
||||
char line[V4_MANAGE_LINE + 1];
|
||||
unsigned bad = 0;
|
||||
int n;
|
||||
if (!read_file(&r, file)) return 1;
|
||||
if (!place_file(&r, file)) return 1;
|
||||
while ((n = next_line(&r, line)) >= 0) {
|
||||
line[n] = 0;
|
||||
(void)tell(node, line);
|
||||
|
||||
Reference in New Issue
Block a user