feat(v4): the ROM assembles text as text.c does -- words, labels, macros, FOR, directives, start
word.f18: (NEXT-TOKEN) reads the console or a macro being expanded; labels, branches by name (a label of the word, or a word, now or later), the table of branches waiting, end of word, FOR/NEXT/UNEXT, macros, &NAME, CONST+N, and (ONE), which dispatches a token. A forward branch to a name not yet defined waits on a placeholder symbol, filled in by (DEFINE). dir.f18: constant set here #, ", store, and start, which resolves, clears the tables the ROM used and runs the word it names. main.f18: the ROM itself, entry 12; on an error it stops at (ROM-FAILED) with the code and line in its state, for the loader to report. sym.f18 generalized: any counted string, placeholders, a hash of only a name's own cells. test_host_rom_asm.c gives test_text.c's own texts (accepted and refused), its four real definitions and the ROM's directives to text.c and to the ROM: the same words, the same errors on the same lines, at both widths. The ROM is 2036 words. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c233cb6536
commit
084c520a54
@@ -149,6 +149,38 @@
|
||||
#define ROM_PTR (OUT_W - 124) /* (SAME?), (DEFINE): where in a name */
|
||||
#define ROM_I (OUT_W - 123) /* where in the token */
|
||||
#define ROM_WI (OUT_W - 122) /* (WALK): which entry of a table */
|
||||
#define ROM_NREF (OUT_W - 121) /* word.f18: how many branches wait for a target */
|
||||
#define ROM_NLAB (OUT_W - 120) /* how many labels the word being assembled has */
|
||||
#define ROM_WNP (OUT_W - 119) /* cells of the word's name area used */
|
||||
#define ROM_NFOR (OUT_W - 118) /* how many FORs are open */
|
||||
#define ROM_FORS (OUT_W - 117) /* where each began, 8 cells */
|
||||
#define ROM_RDEPTH (OUT_W - 109) /* how many macros are being expanded */
|
||||
#define ROM_RPTRS (OUT_W - 108) /* where each is reading, 8 cells */
|
||||
#define ROM_T1 (OUT_W - 100) /* working cells */
|
||||
#define ROM_T2 (OUT_W - 99)
|
||||
#define ROM_T3 (OUT_W - 98)
|
||||
#define ROM_T4 (OUT_W - 97)
|
||||
#define ROM_CFROM (OUT_W - 96)
|
||||
#define ROM_CTO (OUT_W - 95)
|
||||
#define ROM_CN (OUT_W - 94)
|
||||
#define ROM_RAW (OUT_W - 93) /* in.f18: 1 while a token is read raw, ( and \ being names */
|
||||
#define ROM_T5 (OUT_W - 92)
|
||||
#define ROM_T6 (OUT_W - 91)
|
||||
#define ROM_MLEN (OUT_W - 90) /* the length of the token saved in ROM_MTEMP */
|
||||
#define ROM_ORIGIN 16 /* where the system's code begins */
|
||||
/* The ROM's other tables, used only while it assembles (cleared at `start`): in the block window, the branches
|
||||
* waiting -- four cells each: the word, the line, a symbol record (or, while local, a name), 1 if local -- the
|
||||
* labels of the word being assembled -- a name and an address -- and their names; in the text input buffer, a
|
||||
* saved token, a character to a cell, a macro's name and its body being collected. */
|
||||
#define ROM_REFS BUF0_W /* 128 entries */
|
||||
#define ROM_REFS_MAX 128
|
||||
#define ROM_LABELS (BUF0_W + 512) /* 64 entries */
|
||||
#define ROM_WNAMES (BUF0_W + 640) /* 384 cells */
|
||||
#define ROM_WN_SIZE 384
|
||||
#define ROM_TSAVE TIB_W /* 16 cells */
|
||||
#define ROM_MTEMP (TIB_W + 16) /* 64 cells */
|
||||
#define ROM_MBODY (TIB_W + 80) /* 180 cells */
|
||||
#define ROM_MBODY_SIZE 180
|
||||
/* THE ROM'S SYMBOL TABLE, used only while it assembles, in dictionary space (cleared at `start`): 256 hash heads,
|
||||
* then records growing up -- link, name, kind, value -- and names, as counted strings, growing down from the top. */
|
||||
#define ROM_SYMH DICT_W
|
||||
@@ -170,6 +202,23 @@
|
||||
#define ROM_ERR_NAMES 5 /* the symbol table is full: "too many names" */
|
||||
#define ROM_ERR_FIT 6 /* memory is full, or a branch cannot reach: "does not fit" */
|
||||
#define ROM_ERR_OPCODE 7 /* not an opcode the packer takes there */
|
||||
#define ROM_ERR_IN_MACRO 8 /* "not allowed in a macro" */
|
||||
#define ROM_ERR_MACRO 9 /* "macro without endmacro", "endmacro without macro" */
|
||||
#define ROM_ERR_LABEL_DUP 10 /* "label already defined in this word" */
|
||||
#define ROM_ERR_LABELS 11 /* "too many labels in one word" */
|
||||
#define ROM_ERR_FOR 12 /* FOR nested too deep, NEXT or UNEXT without FOR, FOR without NEXT */
|
||||
#define ROM_ERR_UNEXT 13 /* "FOR ... UNEXT must fit one instruction word and hold no literal" */
|
||||
#define ROM_ERR_TARGET 14 /* "not something to branch to" */
|
||||
#define ROM_ERR_UNDEFINED 15 /* "never defined" */
|
||||
#define ROM_ERR_BIG 16 /* "number does not fit a cell" */
|
||||
#define ROM_ERR_AMP 17 /* "& needs a word that is already defined" */
|
||||
#define ROM_ERR_FETCH_P 18 /* "write the number, not @p" */
|
||||
#define ROM_ERR_MISSING 19 /* a name, a target, a value or a string missing at the end */
|
||||
#define ROM_ERR_DEEP 20 /* "macros nested too deep" */
|
||||
#define ROM_ERR_REFS 21 /* "too many unresolved branches" */
|
||||
#define ROM_ERR_VALUE 22 /* "not a value", "not a number" */
|
||||
#define ROM_ERR_NO_START 23 /* the input ended with no start */
|
||||
#define ROM_ERR_START 24 /* start: not a word */
|
||||
#define ROM_ADDR_TOP ((v4_cell)(V4_NODE_WORDS + V4_ROM_WORDS - 1u)) /* the top of the address space */
|
||||
#define WORD_DEFINED (BUF0_W - 11) /* the xt of the word that is told of each new entry, or 0 */
|
||||
#define WORD_FORGOTTEN (BUF0_W - 12) /* the xt of the word that is told when entries go, or 0 */
|
||||
|
||||
Reference in New Issue
Block a user