v4 text.c: the address record (ADR step 3, task 1)
Build / Image RASPI (push) Successful in 4m13s
Build / Image PC (push) Successful in 3m51s
Build / Image MILKV (push) Successful in 4m30s
Build / v4 tests (32- and 64-bit cells) (push) Successful in 17m32s

Every cell laid down that holds an address of the assembly is recorded,
with its branch slot or 7 for the whole cell, as ARTIFACT.md's
relocations need. Test first: test_text 13 checks failed before.
test_host_rom_nucleus runs with the record on: 1825 branches, 664 whole
cells, the ROM still equal word for word. v4 test, test-32 and
ASan+UBSan pass.

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 17:51:54 +00:00
parent 29b99f90e6
commit 4d64e677f5
11 changed files with 1898 additions and 14 deletions
+23
View File
@@ -111,9 +111,22 @@
typedef struct {
unsigned name; /* offset into pool */
unsigned char kind;
unsigned char addr; /* a set variable: its value is an address of the assembly */
v4_cell value; /* address, constant, or macro text offset */
} v4_text_symbol;
/* THE ADDRESS RECORD (docs/v4.0.0/plans/2026-11-19-f18-artifact-build.md §2). A cell laid down
* that holds an address of this assembly -- a word's or a label's, `here`, or a set variable that
* holds one -- as ARTIFACT.md §5's relocations need it: the cell, and the slot (0-3) whose branch
* field holds the address, or V4_TEXT_WHOLE_CELL when the whole cell does (an &NAME literal, a
* header's name and link, `#,`, `store`). The map's constants and numbers are not addresses of
* the assembly, and are not recorded. */
#define V4_TEXT_WHOLE_CELL 7u
typedef struct {
v4_cell cell;
unsigned slot;
} v4_text_addr;
typedef struct {
unsigned name;
v4_asm_ref ref;
@@ -144,6 +157,9 @@ typedef struct {
int header_pending; /* a header waits for its `:` */
v4_cell next_id; /* the next word ID a header is given (#189, Phase 2) */
v4_text_addr *rec; /* the address record, or NULL when it is off */
unsigned rec_cap, nrec;
unsigned line;
int failed;
char message[224];
@@ -152,6 +168,13 @@ typedef struct {
/* Start assembling at word address `origin` of node `n`. */
void v4_text_begin(v4_text *t, v4_node *n, v4_cell origin);
/* Turn the address record on, into `buf`, which holds `cap`: every address laid down from now on
* is recorded. More than `cap` is an error. v4_text_begin turns it off. It changes no cell. */
void v4_text_record(v4_text *t, v4_text_addr *buf, unsigned cap);
/* How many addresses have been recorded. */
unsigned v4_text_addresses(const v4_text *t);
/* Give NAME a value; written in the text it is a literal. */
void v4_text_constant(v4_text *t, const char *name, v4_cell value);