v4: mkf18a, the host tool that builds a train's F18 artifact (ADR step 3, task 3)
Build / Image RASPI (push) Successful in 3m59s
Build / Image PC (push) Successful in 3m58s
Build / Image MILKV (push) Successful in 4m7s
Build / v4 tests (32- and 64-bit cells) (push) Successful in 16m5s

The artifact's layout and its check (artifact.h, artifact.c), the tool
(tools/f18a.c, mkf18a.c) and make -C v4 artifacts. test_mkf18a, 83
checks at both widths, failed against a stub first. Gates: test,
test-32 and sanitize pass, POST 990/990. Plan section 11.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
Claude
2026-11-19 21:09:22 +00:00
parent 84f119a1b3
commit dc3803ab47
12 changed files with 2924 additions and 3 deletions
+540
View File
File diff suppressed because it is too large Load Diff
+46
View File
@@ -0,0 +1,46 @@
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* f18a.h -- build a train's engine, its F18 artifact, on the build machine (mkf18a).
*
* docs/v4.0.0/plans/2026-11-19-f18-artifact-build.md section 2 and section 10. Every .f18 in the train's
* directory is assembled by text.c, at 0, in name order, after the map; then:
* - every : word with a fixed stack effect (effect.c) is an export, with the flags and the capabilities
* written after its name;
* - every `import TRAIN NAME` is an import of TRAIN's export NAME: TRAIN is given as an artifact, whose
* capsule ID (the XXHash64 of its bytes, as mkcapsule gives it) names it, and whose export gives the
* effects expected;
* - every address text.c records is a relocation;
* - the provenance's four SHA-512 hashes, each over files framed as: the file's name, a NUL, its length
* in 8 bytes low first, its bytes. The source: the train's .f18, in name order. The tool: its own
* source (tools/mkf18a.c, tools/f18a.c, tools/f18a.h, src/artifact.c, src/asm.c, src/effect.c,
* src/iword.c, src/text.c, then every .h of include/v4 in name order), named from the v4 directory.
* The configuration: the text "V4_CELL_BITS=.. V4_NODE_WORDS=.. V4_DATA_RING=.. V4_RET_RING=..
* V4_ROM_WORDS=..", framed as "config", then the map. The ROM: the ROM's file as given.
* It refuses what the ABI cannot carry: a header, a store or a start in the source; an export's name
* over 31 characters; a port or a request it can see that the word does not declare, or one declared by
* a word it calls.
*/
#ifndef V4_TOOLS_F18A_H
#define V4_TOOLS_F18A_H
#include <stddef.h>
typedef struct {
const char *name; /* as `import` names it */
const char *path; /* its .f18a */
} f18a_train;
typedef struct {
const char *map; /* the memory map's constants: map-<width>.f18 */
const char *dir; /* the train's .f18 */
const char *rom; /* the ROM it is built against */
const f18a_train *trains; /* the trains it may import from */
unsigned ntrains;
const char *tool_root; /* the v4 directory, for the tool's hash */
} f18a_args;
/* 1 and the artifact in *out (malloc'd, *len bytes), or 0 and why in err. */
int f18a_build(const f18a_args *a, unsigned char **out, size_t *len, char *err, size_t errlen);
#endif /* V4_TOOLS_F18A_H */
+50
View File
@@ -0,0 +1,50 @@
/* SPDX-License-Identifier: LicenseRef-Starship-1.0
* Copyright (c) 2023-2026 Robert A. James
*/
/* mkf18a.c -- build a train's engine, its F18 artifact, off the node (f18a.h).
*
* mkf18a OUT.f18a MAP.f18 ROM DIR [TRAIN=PATH.f18a ...]
*
* docs/v4.0.0/plans/2026-11-19-f18-artifact-build.md section 2. Built as mkrom is, one per cell width,
* with the node's size. DIR holds the train's .f18; each TRAIN=PATH is a train it may import from.
*/
#include "f18a.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifndef V4_ROOT
#error "V4_ROOT must name the v4 directory"
#endif
int main(int argc, char **argv)
{
f18a_args a;
f18a_train trains[64];
unsigned char *out = NULL;
size_t len = 0;
char err[512];
int i;
FILE *f;
if (argc < 5) { fprintf(stderr, "usage: mkf18a OUT.f18a MAP.f18 ROM DIR [TRAIN=PATH.f18a ...]\n"); return 2; }
a.map = argv[2];
a.rom = argv[3];
a.dir = argv[4];
a.ntrains = 0;
for (i = 5; i < argc; i++) {
char *eq = strchr(argv[i], '=');
if (!eq || a.ntrains == 64) { fprintf(stderr, "mkf18a: not TRAIN=PATH: %s\n", argv[i]); return 2; }
*eq = 0;
trains[a.ntrains].name = argv[i];
trains[a.ntrains].path = eq + 1;
a.ntrains++;
}
a.trains = trains;
a.tool_root = V4_ROOT;
if (!f18a_build(&a, &out, &len, err, sizeof err)) { fprintf(stderr, "mkf18a: %s: %s\n", a.dir, err); return 1; }
f = fopen(argv[1], "wb");
if (!f || fwrite(out, 1, len, f) != len || fclose(f) != 0) { fprintf(stderr, "mkf18a: cannot write %s\n", argv[1]); return 1; }
free(out);
return 0;
}