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:
+45
-1
@@ -496,7 +496,10 @@ int main(void)
|
||||
CHECK(refused("header X header Y : W ;", "header must be followed by :", 1), "so is another header");
|
||||
CHECK(refused("header X", "header must be followed by :", 0), "and the end of the text");
|
||||
CHECK(refused("header", "header without a name", 0), "header with no name is refused");
|
||||
CHECK(refused(": T immediate ;", "a flag with no header", 1), "a flag with no header is refused");
|
||||
/* Ruled 2026-11-19 (plans/2026-11-19-f18-artifact-build.md §10.2, "After the name, like header"): the
|
||||
* flags may follow the : name. Until then this was refused, "a flag with no header". */
|
||||
CHECK(ok(": T immediate ;"), "a flag after the : name");
|
||||
CHECK(refused(": T 1 immediate ;", "a flag", 1), "a flag after the word's code is refused");
|
||||
CHECK(refused("macro M header X endmacro", "", 0) || 1, "(header inside a macro body is only text until the macro is used)");
|
||||
CHECK(refused("macro M header X : W ; endmacro", "not allowed in a macro", 1), "a word in a macro is still refused");
|
||||
CHECK(refused(": immediate 1 ;", "cannot be used as a name", 1), "a flag's name cannot name a word");
|
||||
@@ -635,6 +638,47 @@ int main(void)
|
||||
"the record changes no cell");
|
||||
}
|
||||
|
||||
/* FLAGS AND CAPABILITIES AFTER THE : NAME (§10.2, §10.5): recorded for the artifact, nothing laid down. */
|
||||
{
|
||||
v4_text_word_info wi;
|
||||
CHECK(ok(": W inline ;") && v4_text_word_attrs(&tx, "W", &wi) && wi.flags == 8 && wi.addr == ORIGIN
|
||||
&& v4_text_here(&tx) == ORIGIN + 1, "inline after the name: flag 8, and only the word's ; laid down");
|
||||
CHECK(ok(": W immediate compile-only pinned mode 3 ;") && v4_text_word_attrs(&tx, "W", &wi)
|
||||
&& wi.flags == (1 | 16 | 64 | (3 << 8)), "immediate, compile-only, pinned and mode 3");
|
||||
CHECK(ok(": W ports request 7 request 9 ;") && v4_text_word_attrs(&tx, "W", &wi) && wi.ports == 1
|
||||
&& wi.nreq == 2 && wi.req[0] == 7 && wi.req[1] == 9 && wi.flags == 0, "ports, and the requests it makes");
|
||||
CHECK(ok(": W ;") && v4_text_word_attrs(&tx, "W", &wi) && wi.flags == 0 && wi.ports == 0 && wi.nreq == 0,
|
||||
"a word with none");
|
||||
CHECK(refused(": W mode 256 ;", "mode", 1), "a mode is 0 to 255");
|
||||
CHECK(refused(": W mode ;", "mode", 1), "mode needs a number");
|
||||
CHECK(refused(": W request ;", "request", 1), "request needs a number");
|
||||
CHECK(refused(": ports ;", "cannot be used as a name", 1) && refused(": import ;", "cannot be used as a name", 1)
|
||||
&& refused(": pinned ;", "cannot be used as a name", 1) && refused(": mode ;", "cannot be used as a name", 1)
|
||||
&& refused(": request ;", "cannot be used as a name", 1), "the new words are reserved");
|
||||
CHECK(ok("header N inline : N' ;") && v4_text_word_attrs(&tx, "N'", &wi) && wi.flags == 0,
|
||||
"a header's flags stay the header's");
|
||||
}
|
||||
|
||||
/* IMPORTS (§10.3): `import TRAIN NAME`. A call, a jump or an &NAME of it is recorded as that import;
|
||||
* its field holds a placeholder outside the code, which placement replaces. */
|
||||
{
|
||||
const char *train, *name;
|
||||
CHECK(rec_ok("import LIB FOO : W FOO ;", 8) && v4_text_import_count(&tx) == 1
|
||||
&& v4_text_import_at(&tx, 0, &train, &name) && strcmp(train, "LIB") == 0 && strcmp(name, "FOO") == 0
|
||||
&& v4_text_addresses(&tx) == 1 && rec[0].cell == ORIGIN && rec[0].slot == 0 && rec[0].import == 0,
|
||||
"a call to an import: recorded as import 0");
|
||||
CHECK(rec_ok(": A ; : B A ;", 8) && v4_text_addresses(&tx) == 1 && rec[0].import == -1,
|
||||
"a call within the code is not an import");
|
||||
CHECK(rec_ok("import LIB FOO import LIB2 BAR : W BAR &FOO drop jump FOO", 8) && v4_text_import_count(&tx) == 2
|
||||
&& v4_text_addresses(&tx) == 3 && rec[0].import == 1 && rec[2].import == 0
|
||||
&& rec[1].slot == V4_TEXT_WHOLE_CELL && rec[1].import == 0, "a call, an &NAME and a jump, each to its import");
|
||||
CHECK(ok("import LIB FOO : W FOO ;") && nb.mem[ORIGIN] != 0, "the import's placeholder is in the branch field");
|
||||
CHECK(refused("import LIB FOO import LIB FOO", "already defined", 1), "an import is named once");
|
||||
CHECK(refused(": W FOO ; import LIB FOO", "never defined", 0) || refused(": W FOO ; import LIB FOO", "already", 0),
|
||||
"an import is declared before it is used");
|
||||
CHECK(refused("import LIB", "import", 1), "import needs a train and a name");
|
||||
}
|
||||
|
||||
CHECK(v4_node_guards_intact(&na) && v4_node_guards_intact(&nb), "guards intact");
|
||||
|
||||
printf(" %d checks, %d failures\n", checks, failures);
|
||||
|
||||
Reference in New Issue
Block a user