feat(v4.0.0): the text assembler lays down dictionary headers

'header NAME [flags]' in front of a word gives it a dictionary entry in
the layout capsule/dict.v4 uses, linked to the header before it, so the
words of a capsule are in the dictionary as soon as it is assembled.
The name is taken as it stands (it may be ( or + or ;) and the
assembler's own name for the code may differ.

Tested in the assembler's own test, and by FIND and the field words
running over assembler-made entries beside ones (HEADER) made.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rajames
2026-10-04 09:58:26 -04:00
co-authored by Claude Opus 5.5
parent 880560fc00
commit 26a6a16537
4 changed files with 173 additions and 2 deletions
+16
View File
@@ -42,6 +42,15 @@
* may use other macros; it may not define a word, a label
* or a macro.
*
* header NAME a dictionary entry for NAME (capsule/dict.v4), laid down
* in front of the word that the next `:` starts, and
* linked to the header before it. NAME is taken as it
* stands -- it may be ( or \ or + -- and is at most 31
* characters. Between it and the `:` may come the flags
* immediate, data, inline and compile-only. The word after
* `:` is the assembler's name for the code, as always, and
* need not be the same: header + inline : PLUS + ;
*
* A name is looked up in this order: opcode, macro, number, constant, label
* (for a branch target), word. So an opcode's name cannot be redefined, and
* the FORTH words that share one (`@`, `!`, `+`, ...) are written as their
@@ -99,6 +108,9 @@ typedef struct {
char pool[V4_TEXT_POOL];
unsigned pool_used;
v4_cell latest; /* xt of the newest header, 0 if none */
int header_pending; /* a header waits for its `:` */
unsigned line;
int failed;
char message[224];
@@ -125,6 +137,10 @@ int v4_text_finish(v4_text *t);
/* The address of the word NAME, or -1 if there is none. */
v4_cell v4_text_word(const v4_text *t, const char *name);
/* The xt of the newest `header`, 0 if there has been none: what the
* dictionary's LATEST starts as. */
v4_cell v4_text_latest(const v4_text *t);
/* The next free word address. */
v4_cell v4_text_here(v4_text *t);