feat(v4): the kernel keeps a registry of nodes and checks who may ask (MESH.md 9a.4)
Any node may birth and wire its own; only Hera sleeps, wakes and kills, by number. Requests have fixed numbers, -6 to -18. NODE-BORN takes the number; NODE-KILL a number. test_manage.c: 41 checks at both widths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
bf97f339f6
commit
d154342314
@@ -162,23 +162,23 @@ static void host_gone(void *self, unsigned place, v4_fabric_node *was)
|
||||
(void)self; (void)place;
|
||||
pool_used[was - pool] = 0;
|
||||
}
|
||||
static int host_open(void *self, const char *name, unsigned len)
|
||||
static int host_open(void *self, unsigned asker, const char *name, unsigned len)
|
||||
{
|
||||
(void)self;
|
||||
(void)self; (void)asker;
|
||||
if (len == 17 && memcmp(name, "v4:nucleus-64.f18", 17) == 0) { hera_reads.is_f18 = 1; hera_reads.cells_at = 0; return 1; }
|
||||
if (len == 14 && memcmp(name, "v4:forth79.4th", 14) == 0) return read_file(&hera_reads, "forth79.4th");
|
||||
return 0;
|
||||
}
|
||||
static int host_cell(void *self, v4_cell *w)
|
||||
static int host_cell(void *self, unsigned asker, v4_cell *w)
|
||||
{
|
||||
(void)self;
|
||||
(void)self; (void)asker;
|
||||
if (!hera_reads.is_f18 || hera_reads.cells_at >= f18_count) return 0;
|
||||
*w = f18[hera_reads.cells_at++];
|
||||
return 1;
|
||||
}
|
||||
static int host_line(void *self, char *text)
|
||||
static int host_line(void *self, unsigned asker, char *text)
|
||||
{
|
||||
(void)self;
|
||||
(void)self; (void)asker;
|
||||
return hera_reads.is_f18 ? -1 : next_line(&hera_reads, text);
|
||||
}
|
||||
static void host_parity(void *self, unsigned place, v4_cell number, const v4_node *n)
|
||||
@@ -187,7 +187,8 @@ static void host_parity(void *self, unsigned place, v4_cell number, const v4_nod
|
||||
if (parity_count < 8) { parity_number[parity_count] = number; parity_hash[parity_count] = v4_image_dict_hash(n, &im); }
|
||||
parity_count++;
|
||||
}
|
||||
static const v4_manage manage = { &f, host_born, host_gone, host_open, host_cell, host_line, host_parity, 0 };
|
||||
static v4_manage manage;
|
||||
static v4_manage_entry registry[PLACES]; /* the kernel's registry of live nodes (MESH.md 9a.4) */
|
||||
|
||||
/* ---- the kernel: a device on Hera's port 0 ---- */
|
||||
#define FIRST_REQUEST 1 /* the number of NODE-ME on her */
|
||||
@@ -203,7 +204,7 @@ static int kernel_take(void *self, v4_cell value) /* a request */
|
||||
{
|
||||
(void)self;
|
||||
if (v4_blocks_serve(&node_blocks[0], &pool[0].n, value)) return 1; /* a block, as for any node; Hera is the first in the pool */
|
||||
if (value < FIRST_REQUEST || !v4_manage_serve(&manage, hera_place, (unsigned)(value - FIRST_REQUEST))) refused++;
|
||||
if (!v4_manage_serve(&manage, hera_place, value)) refused++;
|
||||
return 1;
|
||||
}
|
||||
static const v4_device kernel = { kernel_take, kernel_give, 0 };
|
||||
@@ -378,6 +379,9 @@ int main(void)
|
||||
printf(" not run at this width: the capsules are the 64-bit products'\n");
|
||||
return 0;
|
||||
}
|
||||
manage.f = &f; manage.reg = registry; manage.reg_cap = PLACES;
|
||||
manage.born = host_born; manage.gone = host_gone; manage.open = host_open;
|
||||
manage.cell = host_cell; manage.line = host_line; manage.parity = host_parity;
|
||||
CHECK(storage_made(), "the kernel's blocks are there before any node is");
|
||||
CHECK(rom_build_system(&nucleus, 0), "the host's machine assembles the system with its ROM");
|
||||
if (failures) { printf(" %d checks, %d failures\n", checks, failures); return 1; }
|
||||
@@ -396,6 +400,7 @@ int main(void)
|
||||
place = host_born(0);
|
||||
CHECK(place == 0, "a node is born");
|
||||
hera_place = (unsigned)place;
|
||||
manage.hera = hera_place;
|
||||
for (i = 0; i < 4096 && pool[0].n.mem[i] == 0; i++) { }
|
||||
CHECK(i == 4096 && pool[0].n.p == PORT + (v4_cell)V4_PORT_ANY, "with nothing in it, listening at its ports");
|
||||
CHECK(v4_fabric_wire_kernel(&f, hera_place, 0, &kernel) && v4_fabric_wire_device(&f, hera_place, 1, &console), "the kernel is on its port 0 and the console on its port 1");
|
||||
@@ -404,10 +409,11 @@ int main(void)
|
||||
"it takes in the nucleus through its port, a word at a time, and sleeps until a message comes: %u of %u cells", given_cells, f18_count);
|
||||
|
||||
CHECK(told(0, "10 (ME) ! 1 (CONSOLE) ! 1 1 ROUTE") && ended_from == 10, "it is told it is 10, and where the console is");
|
||||
CHECK(v4_manage_enter(&manage, 10, hera_place, 0), "the kernel enters her in its registry, as v3's enters Hera");
|
||||
{
|
||||
char text[600];
|
||||
size_t at = 0;
|
||||
for (i = 0; i < V4_MANAGE_WORDS; i++) at += (size_t)snprintf(text + at, sizeof text - at, "%u KERNEL-WORD %s ", FIRST_REQUEST + i, v4_manage_words[i]);
|
||||
for (i = 0; i < V4_MANAGE_WORDS; i++) at += (size_t)snprintf(text + at, sizeof text - at, "%d KERNEL-WORD %s ", (int)(V4_REQ_NODE_ME - (v4_cell)i), v4_manage_words[i]);
|
||||
CHECK(told(10, text), "and given the words that ask for nodes and capsules: \"%s\"", printed);
|
||||
}
|
||||
CHECK(strcmp(tell(10, "NODE-ME ."), "0 ") == 0 && refused == 0, "it asks where it is, and is answered");
|
||||
|
||||
Reference in New Issue
Block a user