v4 text.c: a word's flags and capabilities after its name; import lines (task 3, part 1)

As ruled (plans §10.2, §10.3, §10.5): ': NAME inline pinned mode N
ports request N' records the word's attributes and lays nothing down;
'import TRAIN NAME' declares another train's word, its calls, jumps and
&NAME recorded as that import. test_text: 11 checks failed before; 274
pass at both widths. The check that ': T immediate ;' is refused is
replaced, as ruled. Full gates run at the end of task 3.

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 19:53:07 +00:00
parent d6b894769c
commit 84f119a1b3
5 changed files with 253 additions and 8 deletions
+44
View File
@@ -112,7 +112,11 @@ typedef struct {
unsigned name; /* offset into pool */
unsigned char kind;
unsigned char addr; /* a set variable: its value is an address of the assembly */
unsigned char ports; /* a word: it says it touches ports */
v4_cell value; /* address, constant, or macro text offset */
v4_cell attr; /* a word: its flags, as v4_text_word_info's */
unsigned req, nreq; /* a word: its requests, in reqs[]; an import: req is its index */
unsigned train; /* an import: its train's name, offset into pool */
} v4_text_symbol;
/* THE ADDRESS RECORD (docs/v4.0.0/plans/2026-11-19-f18-artifact-build.md §2). A cell laid down
@@ -125,8 +129,30 @@ typedef struct {
typedef struct {
v4_cell cell;
unsigned slot;
int import; /* -1: an address of this assembly; k: import k's (an import line) */
} v4_text_addr;
/* A word's attributes, written after its : name (plans/2026-11-19-f18-artifact-build.md §10.2, §10.5):
* : NAME [immediate] [data] [inline] [compile-only] [pinned] [mode N] [ports] [request N]...
* They are recorded for the artifact and lay nothing down. `flags` is as a dictionary entry's flags cell
* holds them (dict.f18): 1 immediate, 4 data, 8 in line, 16 compile-only, 64 pinned, the mode in bits
* 8-15. `ports`: it says it touches ports; `req`: the kernel requests it says it makes. */
#define V4_TEXT_MAX_REQS 256u
typedef struct {
const char *name;
v4_cell addr;
v4_cell flags;
int ports;
const v4_cell *req;
unsigned nreq;
} v4_text_word_info;
/* IMPORTS (§10.3). `import TRAIN NAME` declares NAME, a word of the train TRAIN, before it is used. A
* call, jump or &NAME of it is recorded as that import (v4_text_addr.import); its branch field or cell
* holds V4_TEXT_IMPORT_ADDR(k), an address above the code that placement replaces. */
#define V4_TEXT_MAX_IMPORTS 256u
#define V4_TEXT_IMPORT_ADDR(k) ((v4_cell)(V4_NODE_WORDS - 1u - (unsigned)(k)))
typedef struct {
unsigned name;
v4_asm_ref ref;
@@ -160,6 +186,12 @@ typedef struct {
v4_text_addr *rec; /* the address record, or NULL when it is off */
unsigned rec_cap, nrec;
v4_cell reqs[V4_TEXT_MAX_REQS]; /* the words' requests */
unsigned nreqs;
unsigned import_sym[V4_TEXT_MAX_IMPORTS]; /* each import's symbol */
unsigned nimport;
int attr_open; /* the word whose attributes may follow, or -1 */
unsigned line;
int failed;
char message[224];
@@ -175,6 +207,18 @@ 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);
/* The attributes of the word NAME: 1 and *out, or 0 if NAME is not a word. The strings and the request
* list stay the assembly's. */
int v4_text_word_attrs(const v4_text *t, const char *name, v4_text_word_info *out);
/* The words, in the order defined: how many, and the i-th's attributes. */
unsigned v4_text_word_count(const v4_text *t);
int v4_text_word_at(const v4_text *t, unsigned i, v4_text_word_info *out);
/* The imports, in the order declared: how many, and the k-th's train and name. */
unsigned v4_text_import_count(const v4_text *t);
int v4_text_import_at(const v4_text *t, unsigned k, const char **train, const char **name);
/* 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);