|
|
|
@@ -15,6 +15,8 @@
|
|
|
|
|
#include "v4/mesh.h"
|
|
|
|
|
#include "v4/message.h"
|
|
|
|
|
#include "v4/post.h"
|
|
|
|
|
#include "v4/place.h"
|
|
|
|
|
#include "v4/artifact.h"
|
|
|
|
|
#include "block_subsystem.h"
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
@@ -102,6 +104,50 @@ static const char *line(v4_cell node, const char *text, int *how)
|
|
|
|
|
/* the tick set for a check (v4_mesh_set_tick), and the heartbeat's clock with it, so no catch-up follows */
|
|
|
|
|
static void set_tick(uint64_t t) { v4_mesh_set_tick(&ms, t); heart = t; }
|
|
|
|
|
|
|
|
|
|
/* ---- the placed train (docs/v4.0.0/plans/2026-11-19-f18-artifact-build.md section 12, task 4) ---- */
|
|
|
|
|
static v4_cell told[16];
|
|
|
|
|
static unsigned ntold;
|
|
|
|
|
/* the kernel told of an entry, as (DEFINED) tells it (dict.f18): the word in (WORD-DEFINED) run with the xt */
|
|
|
|
|
static void tell(void *ctx, v4_cell xt)
|
|
|
|
|
{
|
|
|
|
|
char cmd[96];
|
|
|
|
|
int how_;
|
|
|
|
|
v4_cell w = v4_mesh_node(&ms, V4_MESH_HERA)->n.mem[im.word_defined];
|
|
|
|
|
(void)ctx;
|
|
|
|
|
if (ntold < 16u) told[ntold++] = xt;
|
|
|
|
|
if (w == 0) return;
|
|
|
|
|
snprintf(cmd, sizeof cmd, "%ld %ld EXECUTE", (long)xt, (long)w);
|
|
|
|
|
(void)line(V4_MESH_HERA, cmd, &how_);
|
|
|
|
|
}
|
|
|
|
|
static unsigned char *slurp(const char *path, size_t *len)
|
|
|
|
|
{
|
|
|
|
|
FILE *f = fopen(path, "rb");
|
|
|
|
|
unsigned char *b;
|
|
|
|
|
long n;
|
|
|
|
|
if (!f) return 0;
|
|
|
|
|
fseek(f, 0, SEEK_END); n = ftell(f); fseek(f, 0, SEEK_SET);
|
|
|
|
|
b = malloc(n > 0 ? (size_t)n : 1u);
|
|
|
|
|
if (b && fread(b, 1, (size_t)n, f) != (size_t)n) { free(b); b = 0; }
|
|
|
|
|
fclose(f);
|
|
|
|
|
*len = (size_t)n;
|
|
|
|
|
return b;
|
|
|
|
|
}
|
|
|
|
|
static v4_cell mem_before[V4_NODE_WORDS];
|
|
|
|
|
/* a refusal leaves Hera as she was */
|
|
|
|
|
static int refused_unchanged(v4_node *hn, const unsigned char *a, size_t len, const v4_train_env *env, const char *what)
|
|
|
|
|
{
|
|
|
|
|
v4_cell xts[8];
|
|
|
|
|
unsigned cnt = 99;
|
|
|
|
|
const char *why = 0;
|
|
|
|
|
int ok;
|
|
|
|
|
memcpy(mem_before, hn->mem, sizeof mem_before);
|
|
|
|
|
ntold = 0;
|
|
|
|
|
ok = v4_train_place(hn, a, len, env, xts, 8, &cnt, &why);
|
|
|
|
|
if (ok) { printf(" placed, not refused\n"); return 0; }
|
|
|
|
|
if (!why || !strstr(why, what)) { printf(" refused: %s\n", why ? why : "(no reason)"); return 0; }
|
|
|
|
|
return memcmp(mem_before, hn->mem, sizeof mem_before) == 0 && ntold == 0 && cnt == 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
|
int how;
|
|
|
|
@@ -650,6 +696,76 @@ int main(void)
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* A TRAIN PLACED (plan 2026-11-19-f18-artifact-build section 12, task 4; ABI.md section 5): the small
|
|
|
|
|
* train tests/train-place, built by mkf18a with one import from the nucleus, placed on Hera at her HERE
|
|
|
|
|
* by the host placer. Its words run by name, its calls into the nucleus reach the nucleus, and the
|
|
|
|
|
* kernel has a record of each. Then what placement refuses, each leaving Hera unchanged. */
|
|
|
|
|
{
|
|
|
|
|
size_t alen = 0;
|
|
|
|
|
unsigned char *art = slurp(TRAIN_F18A, &alen);
|
|
|
|
|
v4_fabric_node *hf = v4_mesh_node(&ms, V4_MESH_HERA);
|
|
|
|
|
v4_node *hn = &hf->n;
|
|
|
|
|
v4_train_env env;
|
|
|
|
|
v4_cell xts[8], here0, cur;
|
|
|
|
|
unsigned cnt = 0, k;
|
|
|
|
|
const char *why = 0;
|
|
|
|
|
char *end;
|
|
|
|
|
v4_f18a_layout lay;
|
|
|
|
|
CHECK(art != 0 && v4_f18a_check(art, alen, 64, &lay, &why), "the train's artifact, built by mkf18a: %s", why ? why : TRAIN_F18A);
|
|
|
|
|
if (art) {
|
|
|
|
|
r = line(V4_MESH_HERA, "CURRENT @ . HERE .", &how);
|
|
|
|
|
cur = (v4_cell)strtol(r, &end, 10);
|
|
|
|
|
here0 = (v4_cell)strtol(end, 0, 10);
|
|
|
|
|
env.dp = im.dp; env.dlimit = im.dict_hi * 4; env.head = cur; env.forth = im.latest; env.next_id = im.next_id;
|
|
|
|
|
env.defined = tell; env.ctx = 0;
|
|
|
|
|
|
|
|
|
|
/* what it refuses first, Hera unchanged by each */
|
|
|
|
|
{
|
|
|
|
|
unsigned char *c = malloc(alen);
|
|
|
|
|
size_t nameu = lay.pool + v4_f18a_unit(art, lay.imports + 2);
|
|
|
|
|
memcpy(c, art, alen); c[0] ^= 1;
|
|
|
|
|
CHECK(refused_unchanged(hn, c, alen, &env, "magic"), "an artifact the checker refuses");
|
|
|
|
|
memcpy(c, art, alen); c[3 * 4] ^= 1;
|
|
|
|
|
CHECK(refused_unchanged(hn, c, alen, &env, "node"), "an artifact for another node size");
|
|
|
|
|
memcpy(c, art, alen); c[nameu * 4 + 3] = 'X';
|
|
|
|
|
CHECK(refused_unchanged(hn, c, alen, &env, "ABX"), "an import the dictionary lacks: ABX");
|
|
|
|
|
memcpy(c, art, alen); c[(lay.imports + 3) * 4] = 2;
|
|
|
|
|
CHECK(refused_unchanged(hn, c, alen, &env, "effect"), "an import whose effect is not the one expected");
|
|
|
|
|
memcpy(c, art, alen); c[lay.imports * 4] = 1;
|
|
|
|
|
CHECK(refused_unchanged(hn, c, alen, &env, "train"), "an import from a train, not the nucleus: not placed yet");
|
|
|
|
|
{
|
|
|
|
|
v4_train_env small = env;
|
|
|
|
|
small.dlimit = (here0 + 4) * 4;
|
|
|
|
|
CHECK(refused_unchanged(hn, art, alen, &small, "room"), "no room for it below DLIMIT");
|
|
|
|
|
}
|
|
|
|
|
free(c);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ntold = 0;
|
|
|
|
|
CHECK(v4_train_place(hn, art, alen, &env, xts, 8, &cnt, &why), "placed on Hera: %s", why ? why : "");
|
|
|
|
|
CHECK(cnt == lay.e && cnt == 4 && ntold == cnt, "four exports entered, and the kernel told of each (%u, %u)", cnt, ntold);
|
|
|
|
|
r = line(V4_MESH_HERA, "HERE .", &how);
|
|
|
|
|
CHECK((v4_cell)strtol(r, 0, 10) > here0 && here0 != 0, "HERE moved past it, from %ld: \"%s\"", (long)here0, r);
|
|
|
|
|
r = line(V4_MESH_HERA, "' DIST .", &how);
|
|
|
|
|
CHECK((v4_cell)strtol(r, 0, 10) == xts[0] && xts[0] > here0, "DIST is found by its name, at %ld: \"%s\"", (long)xts[0], r);
|
|
|
|
|
for (k = 0; k < cnt && k < 8; k++)
|
|
|
|
|
CHECK(v4_mesh_account_at(&ms, 0, xts[k]) != 0, "the kernel keeps a record of export %u", k);
|
|
|
|
|
r = line(V4_MESH_HERA, "7 3 DIST . 3 7 DIST .", &how);
|
|
|
|
|
CHECK(strcmp(r, "4 4 ") == 0, "DIST, through the nucleus's ABS: \"%s\"", r);
|
|
|
|
|
r = line(V4_MESH_HERA, "3 7 DIST2 .", &how);
|
|
|
|
|
CHECK(strcmp(r, "8 ") == 0, "DIST2 calls DIST, moved: \"%s\"", r);
|
|
|
|
|
r = line(V4_MESH_HERA, "-5 CLAMP0 . 5 CLAMP0 .", &how);
|
|
|
|
|
CHECK(strcmp(r, "0 5 ") == 0, "CLAMP0's forward branch, moved: \"%s\"", r);
|
|
|
|
|
r = line(V4_MESH_HERA, "ADDR ' DIST = .", &how);
|
|
|
|
|
CHECK(strcmp(r, "-1 ") == 0, "ADDR's address literal is DIST's xt: \"%s\"", r);
|
|
|
|
|
r = line(V4_MESH_HERA, ": PLACED-USE 3 7 DIST2 ; PLACED-USE .", &how);
|
|
|
|
|
CHECK(strcmp(r, "8 ") == 0, "a word compiled at the prompt calls a placed one: \"%s\"", r);
|
|
|
|
|
r = line(V4_MESH_HERA, "FORGET PLACED-USE 3 4 + .", &how);
|
|
|
|
|
CHECK(strcmp(r, "7 ") == 0, "and the prompt goes on: \"%s\"", r);
|
|
|
|
|
}
|
|
|
|
|
free(art);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
printf(" %d checks, %d failures\n", checks, failures);
|
|
|
|
|
return failures ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|