v4 mkf18a: import nucleus NAME -- hash 0, the effect from the nucleus (task 4, part 1)
mkf18a takes nucleus=SYSDIR, assembles the nucleus as the ROM does and looks NAME up by its dictionary name; a word in line there, or one with no fixed effect, is refused (plan section 12, rulings 3 and 4). test_mkf18a: 5 new checks failed first, 93 pass at both widths. Its build now has the host node's size, as the tool's has: the nucleus did not fit a mesh node's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include "v4/artifact.h"
|
||||
#include "v4/effect.h"
|
||||
#include "v4/text.h"
|
||||
#include "v4/sys_files.h"
|
||||
#include "starkernel/sha512.h"
|
||||
#include "starkernel/xxhash64.h"
|
||||
#include <dirent.h>
|
||||
@@ -22,6 +23,15 @@
|
||||
static v4_node n; /* large: not on the stack */
|
||||
static v4_text tx;
|
||||
|
||||
/* The nucleus, for `import nucleus NAME` (plan section 12, rulings 3 and 4): assembled as the ROM assembles
|
||||
* it, its map first, sys_files.h's order, end.f18 last, at the system's origin (tests/host_map.h's
|
||||
* ROM_ORIGIN, as test_host_rom_nucleus assembles it), once per build that needs it. */
|
||||
#define NUCLEUS_ORIGIN 16
|
||||
#define NUCLEUS_FILE(x) #x,
|
||||
static const char *const nucleus_files[] = { V4_SYS_FILES(NUCLEUS_FILE) };
|
||||
static v4_node nn;
|
||||
static v4_text ntx;
|
||||
|
||||
typedef struct { /* an import, resolved */
|
||||
uint64_t id;
|
||||
v4_effect fx;
|
||||
@@ -165,6 +175,61 @@ static int import_effect(void *ctx, v4_cell addr, v4_effect *out)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* the nucleus assembled, and its effects: 1, or 0 having failed */
|
||||
static v4_effects *nfx;
|
||||
static int nucleus_ready(build_t *b, const char *dir)
|
||||
{
|
||||
char path[1024];
|
||||
unsigned i;
|
||||
if (nfx) return 1;
|
||||
v4_node_reset(&nn);
|
||||
v4_text_begin(&ntx, &nn, NUCLEUS_ORIGIN);
|
||||
snprintf(path, sizeof path, "%s/map-%d.f18", dir, V4_CELL_BITS);
|
||||
if (!v4_text_assemble_file(&ntx, path)) return fail(b, "the nucleus: %s", v4_text_error(&ntx));
|
||||
for (i = 0; i < sizeof nucleus_files / sizeof nucleus_files[0]; i++) {
|
||||
snprintf(path, sizeof path, "%s/%s.f18", dir, nucleus_files[i]);
|
||||
if (!v4_text_assemble_file(&ntx, path)) return fail(b, "the nucleus: %s", v4_text_error(&ntx));
|
||||
}
|
||||
snprintf(path, sizeof path, "%s/end.f18", dir);
|
||||
if (!v4_text_assemble_file(&ntx, path) || !v4_text_finish(&ntx)) return fail(b, "the nucleus: %s", v4_text_error(&ntx));
|
||||
nfx = v4_effects_new(&nn, NUCLEUS_ORIGIN, v4_text_here(&ntx), NULL, NULL);
|
||||
if (!nfx) return fail(b, "out of memory");
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* the xt of the nucleus's entry named `name`, by its dictionary's links from the newest, or -1 */
|
||||
static v4_cell nucleus_word(const char *name)
|
||||
{
|
||||
v4_cell link;
|
||||
size_t len = strlen(name), i;
|
||||
if (!v4_text_value(&ntx, "HDR-LINK", &link)) return -1;
|
||||
for (; link > 4; link = nn.mem[link - 1]) {
|
||||
v4_cell nfa = nn.mem[link - 2];
|
||||
if ((nn.mem[nfa] & 255) != (v4_cell)len) continue;
|
||||
for (i = 0; i < len; i++)
|
||||
if (((nn.mem[nfa + (v4_cell)((i + 1) / 4)] >> (8 * ((i + 1) % 4))) & 255) != (unsigned char)name[i]) break;
|
||||
if (i == len) return link;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* an import from the nucleus: hash 0, the effect derived from the nucleus; it declares no capabilities */
|
||||
static int resolve_nucleus(build_t *b, const f18a_args *a, import_t *im, const char *name)
|
||||
{
|
||||
v4_cell xt;
|
||||
if (!a->nucleus) return fail(b, "import of %s from the nucleus, which is not given", name);
|
||||
if (!nucleus_ready(b, a->nucleus)) return 0;
|
||||
xt = nucleus_word(name);
|
||||
if (xt < 0) return fail(b, "the nucleus does not have %s", name);
|
||||
if (nn.mem[xt - 3] & 8) return fail(b, "%s is in line in the nucleus: it cannot be called", name);
|
||||
im->fx = v4_effect_of(nfx, xt, V4_EFFECT_CALLED);
|
||||
if (!im->fx.fixed) return fail(b, "%s in the nucleus has no fixed effect: %s", name, im->fx.why);
|
||||
im->id = 0;
|
||||
im->caps = 0;
|
||||
im->nreq = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int resolve_import(build_t *b, const f18a_args *a, unsigned k)
|
||||
{
|
||||
const char *train, *name;
|
||||
@@ -176,6 +241,7 @@ static int resolve_import(build_t *b, const f18a_args *a, unsigned k)
|
||||
import_t *im = &b->imp[k];
|
||||
|
||||
v4_text_import_at(&tx, k, &train, &name);
|
||||
if (strcmp(train, "nucleus") == 0) return resolve_nucleus(b, a, im, name);
|
||||
for (i = 0; i < a->ntrains && strcmp(a->trains[i].name, train) != 0; i++) ;
|
||||
if (i == a->ntrains) return fail(b, "import of %s from %s, a train not given", name, train);
|
||||
art = (unsigned char *)read_file(a->trains[i].path, &len);
|
||||
|
||||
Reference in New Issue
Block a user