feat(v4): v3's whole POST is v4's POST -- 990 cases, all passed on Hera (#189)
Phase 7, Task 8: PARITY:V4_POST tests=990 pass=990 fail=0 on Hera (mesh-boot); the hosted
product 945 of them, all passed -- the 45 cases of physics.4th's words need the kernel.
- Enlarged, as ruled ("Enlarge v4 to fit"): a node is 32768 words, its data stack 1024
deep (v3's), host and kernel alike; the dictionary's end moves with them.
- POST's runner compares every value a case leaves (v3's leave 101); V4_POST_KERNEL marks
a case of the kernel's words, and a host without a kernel does not run it.
- mkpost.py --all is POST's table (make -C v4 post79), with docs/v4.0.0/POST.md; it reads a
module's #defines (v3's Mama cases are MAMA_IMPLEMENTED, 0: v3's own POST skips all 20);
it cuts no line between a word and the name it takes.
- Rules for the last of the table: the min/max and array-sum programs written as meant,
CREATE's 26-character name (FORTH-79: 31), many_defs.
- POST_FLOOR 990.
- Tests sized for a 32-deep stack and a 16384-word node made deep-stack-ready
(test_host_depth, test_host_quit, test_host_node, hosted-check, depthsweep.py).
make -C v4 test: all v4 tests passed. make -C kernel/tests test: all passed.
depthsweep at 1024: 230 runs, 0 failures. v4-checks running.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
+62
-33
@@ -452,7 +452,7 @@ static void post_say(void *self, const char *text, unsigned len)
|
||||
(void)self;
|
||||
if (post_said_len + len < sizeof post_said) { memcpy(post_said + post_said_len, text, len); post_said_len += len; post_said[post_said_len] = 0; }
|
||||
}
|
||||
static const v4_post_host post_host = { 0, &n, post_line, post_say };
|
||||
static const v4_post_host post_host = { 0, &n, post_line, post_say, 0 };
|
||||
/* Run one case; 1 if it passed. What the runner said is in post_said. */
|
||||
static int post_one(const char *name, const char *l0, const char *l1, int expect, const long long *stack, unsigned depth, const char *output)
|
||||
{
|
||||
@@ -517,6 +517,24 @@ static int is(const char *got, const char *want)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Words that push 1, 2, 4, 8, 16, 64 and 256 values (7s), and a short text of them that pushes any count: the
|
||||
* stack is 1024 deep (#189 Phase 7), and a line of that many numbers is more than a line may be. */
|
||||
static int pwords(void)
|
||||
{
|
||||
return is(say(": P1 7 ; : P2 7 7 ; : P4 7 7 7 7 ; : P8 7 7 7 7 7 7 7 7 ; : P16 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 ;\n"), " ok\nok> ")
|
||||
&& is(say(": P64 P16 P16 P16 P16 ; : P256 P64 P64 P64 P64 ;\n"), " ok\nok> ");
|
||||
}
|
||||
|
||||
static void pfill(char *text, size_t cap, unsigned count)
|
||||
{
|
||||
static const unsigned sizes[] = { 256, 64, 16, 8, 4, 2, 1 };
|
||||
size_t at = 0;
|
||||
unsigned i;
|
||||
text[0] = 0;
|
||||
for (i = 0; i < sizeof sizes / sizeof sizes[0]; i++)
|
||||
for (; count >= sizes[i]; count -= sizes[i]) at += (size_t)snprintf(text + at, cap - at, "P%u ", sizes[i]);
|
||||
}
|
||||
|
||||
/* What v3 prints starts with its first prompt; the node's first prompt is
|
||||
* printed at switch-on, before the input, so a v4 session lacks the leading
|
||||
* "ok> " and is otherwise the same. */
|
||||
@@ -859,7 +877,7 @@ static const transcript script[] = {
|
||||
{ "65 EMIT DROP 66 EMIT\n67 EMIT\n", "AStack underflow\n ERROR\nok> C ok\nok> ", 0 },
|
||||
{ "+\n1 +\nDUP\nOVER\n1 OVER\n", "Stack underflow\n ERROR\nok> Stack underflow\n ERROR\nok> Stack underflow\n ERROR\nok> "
|
||||
"Stack underflow\n ERROR\nok> Stack underflow\n ERROR\nok> ", 0 },
|
||||
{ ": OV 65 EMIT 1000 0 DO I LOOP 66 EMIT ; 7 8 9 OV\nDEPTH 48 + EMIT\n", "AStack overflow\n ERROR\nok> 0 ok\nok> ", 0 },
|
||||
{ ": OV 65 EMIT 2000 0 DO I LOOP 66 EMIT ; 7 8 9 OV\nDEPTH 48 + EMIT\n", "AStack overflow\n ERROR\nok> 0 ok\nok> ", 0 }, /* 2000: the stack is 1024 deep (#189) */
|
||||
{ "1 2 3 -1 @\nDEPTH 48 + EMIT\n", "Address out of range\n ERROR\nok> 0 ok\nok> ", 0 },
|
||||
{ ": RU R> DROP R> DROP ; 65 EMIT RU 66 EMIT\n67 EMIT\n", "AReturn stack underflow\n ERROR\nok> C ok\nok> ", 0 },
|
||||
/* a word that runs itself, through EXECUTE, until the return stack is full */
|
||||
@@ -1004,13 +1022,18 @@ int main(void)
|
||||
|
||||
/* ---- an address outside memory (D-14): a message, ERROR, and the prompt ---- */
|
||||
{
|
||||
static char past_rom[48], into_rom[48]; /* past the ROM; and the ROM's first word, which may not be written */
|
||||
static const char *const lines[] = {
|
||||
"65 EMIT -1 @ 66 EMIT\n", "65 EMIT 5 -1 ! 66 EMIT\n", "65 EMIT 20480 @ 66 EMIT\n", "65 EMIT 5 16384 ! 66 EMIT\n",
|
||||
"65 EMIT -1 @ 66 EMIT\n", "65 EMIT 5 -1 ! 66 EMIT\n", past_rom, into_rom,
|
||||
"65 EMIT 99999999 C@ 66 EMIT\n", "65 EMIT 7 -4 C! 66 EMIT\n", "65 EMIT -1 EXECUTE 66 EMIT\n", "65 EMIT 1 -1 +! 66 EMIT\n",
|
||||
"65 EMIT PAD -8 4 CMOVE 66 EMIT\n", "65 EMIT -9 COUNT 66 EMIT\n", "65 EMIT -9 3 TYPE 66 EMIT\n",
|
||||
": F0 -1 @ ; : F1 F0 ; : F2 F1 ; : F3 65 EMIT F2 66 EMIT ; F3 67 EMIT\n",
|
||||
": G0 9 0 DO I 3 = IF 0 -1 ! THEN LOOP ; : G1 65 EMIT G0 66 EMIT ; G1\n",
|
||||
};
|
||||
char last[64];
|
||||
snprintf(past_rom, sizeof past_rom, "65 EMIT %u @ 66 EMIT\n", (unsigned)(V4_NODE_WORDS + V4_ROM_WORDS));
|
||||
snprintf(into_rom, sizeof into_rom, "65 EMIT 5 %u ! 66 EMIT\n", (unsigned)V4_NODE_WORDS);
|
||||
snprintf(last, sizeof last, "%u @ DROP 0 @ DROP 67 EMIT\n", (unsigned)(V4_NODE_WORDS - 1u));
|
||||
boot();
|
||||
for (i = 0; i < sizeof lines / sizeof lines[0]; i++) {
|
||||
unsigned before = n.faults;
|
||||
@@ -1018,7 +1041,7 @@ int main(void)
|
||||
CHECK(n.faults == before + 1 && !n.stopped && n.mem[STATE] == 0, "fault %u: one fault, and the node is at its prompt", i);
|
||||
CHECK(is(say("1 2 + 48 + EMIT\n"), "3 ok\nok> "), "and the next line runs, after fault %u", i);
|
||||
}
|
||||
CHECK(is(say("16383 @ DROP 0 @ DROP 67 EMIT\n"), "C ok\nok> "), "the first and last words of memory are not faults");
|
||||
CHECK(is(say(last), "C ok\nok> "), "the first and last words of memory are not faults");
|
||||
CHECK(is(say(": H5 1 IF [ -1 @ ]\n"), "Address out of range\n ERROR\nok> ") && n.mem[STATE] == 0 && n.mem[CFP] == CFS_W,
|
||||
"a fault while a definition is open ends it");
|
||||
CHECK(is(say("H5\n"), "UNKNOWN WORD: 'H5'\n ERROR\nok> ") && is(say(": H6 68 EMIT ; H6\n"), "D ok\nok> "), "and the next definition compiles and runs");
|
||||
@@ -1163,20 +1186,17 @@ int main(void)
|
||||
* P1 P2 P4 P8 P16 push that many values and call nothing while they do, so
|
||||
* a word can fill the stack to any depth in a short line. */
|
||||
{
|
||||
char line[128], want[32], fill[64];
|
||||
unsigned c, bit;
|
||||
#define FILL(count) do { size_t at_ = 0; fill[0] = 0; \
|
||||
for (c = (count), bit = 16; bit; bit >>= 1) if (c >= bit) { at_ += (size_t)snprintf(fill + at_, sizeof fill - at_, "P%u ", bit); c -= bit; } \
|
||||
for (; c >= 16; c -= 16) at_ += (size_t)snprintf(fill + at_, sizeof fill - at_, "P16 "); } while (0)
|
||||
char line[256], want[32], fill[128];
|
||||
#define FILL(count) pfill(fill, sizeof fill, (count))
|
||||
boot_bare();
|
||||
CHECK(is(say(": P1 7 ; : P2 7 7 ; : P4 7 7 7 7 ; : P8 7 7 7 7 7 7 7 7 ;\n"), " ok\nok> ")
|
||||
&& is(say(": P16 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 ;\n"), " ok\nok> "), "words that push 1, 2, 4, 8 and 16 values");
|
||||
CHECK(pwords(), "words that push 1, 2, 4, 8, 16, 64 and 256 values");
|
||||
/* 65, then DEPTH-2 more, then n = DEPTH-1: the stack is full when PICK and ROLL start */
|
||||
FILL(V4_DATA_DEPTH - 2u);
|
||||
snprintf(line, sizeof line, ": PF 65 %s%u PICK >R DROP R> EMIT ABORT ; PF\n", fill, (unsigned)(V4_DATA_DEPTH - 1u));
|
||||
CHECK(is(say(line), "A ok\nok> ") && n.faults == 0, "PICK of the deepest value of a full stack");
|
||||
snprintf(line, sizeof line, ": RF 65 %s%u ROLL EMIT DROP DEPTH 33 + EMIT ABORT ; RF\n", fill, (unsigned)(V4_DATA_DEPTH - 1u));
|
||||
snprintf(want, sizeof want, "A%c ok\nok> ", (char)(33 + V4_DATA_DEPTH - 3u));
|
||||
snprintf(line, sizeof line, ": RF 65 %s%u ROLL EMIT DROP DEPTH %u - 33 + EMIT ABORT ; RF\n", fill, (unsigned)(V4_DATA_DEPTH - 1u),
|
||||
(unsigned)(V4_DATA_DEPTH - 32u));
|
||||
snprintf(want, sizeof want, "A%c ok\nok> ", (char)(33 + 32 - 3));
|
||||
CHECK(is(say(line), want) && n.faults == 0, "ROLL of the deepest value of a full stack");
|
||||
/* exactly full is not a fault; one more is */
|
||||
FILL(V4_DATA_DEPTH);
|
||||
@@ -1195,18 +1215,23 @@ int main(void)
|
||||
/* ---- how many values may wait on the stack from one line to the next ---- */
|
||||
{
|
||||
unsigned k, most = 0;
|
||||
for (k = 1; k < V4_DATA_DEPTH; k++) {
|
||||
char line[4 * V4_DATA_DEPTH + 16], want[16];
|
||||
size_t at = 0;
|
||||
unsigned m;
|
||||
/* every depth near the bottom and the top, and every 61st between (the stack is 1024 deep, #189) */
|
||||
for (k = 1; k < V4_DATA_DEPTH; k = (k < 16u || k + 16u >= V4_DATA_DEPTH) ? k + 1u
|
||||
: (k + 61u + 16u < V4_DATA_DEPTH ? k + 61u : V4_DATA_DEPTH - 16u)) {
|
||||
char line[256];
|
||||
size_t at;
|
||||
boot_bare();
|
||||
for (m = 0; m < k; m++) at += (size_t)snprintf(line + at, sizeof line - at, "1 ");
|
||||
snprintf(line + at, sizeof line - at, "\n");
|
||||
if (!pwords() || !is(say(": A1 + ; : A2 + + ; : A4 + + + + ; : A8 A4 A4 ; : A16 A8 A8 ; : A64 A16 A16 A16 A16 ; "
|
||||
": A256 A64 A64 A64 A64 ;\n"), " ok\nok> ")) break;
|
||||
pfill(line, sizeof line - 2, k);
|
||||
strcat(line, "\n");
|
||||
if (strcmp(say(line), " ok\nok> ") != 0) break;
|
||||
for (at = 0, m = 1; m < k; m++) at += (size_t)snprintf(line + at, sizeof line - at, "+ ");
|
||||
snprintf(line + at, sizeof line - at, "32 + EMIT\n");
|
||||
snprintf(want, sizeof want, "%c ok\nok> ", (char)(32 + k));
|
||||
if (strcmp(say(line), want) != 0) break;
|
||||
/* the next line adds them all first, as it did when it was k-1 +s, so it takes no cell of its own */
|
||||
pfill(line, sizeof line - 32, k - 1u);
|
||||
for (at = 0; line[at]; at++) if (line[at] == 'P') line[at] = 'A';
|
||||
at = strlen(line);
|
||||
snprintf(line + at, sizeof line - at, "%u - 64 + EMIT\n", 7u * k);
|
||||
if (strcmp(say(line), "@ ok\nok> ") != 0) break;
|
||||
most = k;
|
||||
}
|
||||
printf(" %u values may wait on the stack while the next line is typed and interpreted\n", most);
|
||||
@@ -1220,13 +1245,13 @@ int main(void)
|
||||
const unsigned plain = (unsigned)(PORT - (OUT_W + OUT_CELLS));
|
||||
unsigned over = 0, worst = 0, at;
|
||||
for (k = most > 6 ? most - 6 : 0; k <= most + 3; k++) {
|
||||
char line[4 * V4_DATA_DEPTH + 16];
|
||||
size_t n_at = 0;
|
||||
char line[256];
|
||||
unsigned m;
|
||||
boot_bare();
|
||||
(void)pwords();
|
||||
for (m = 0; m < plain; m++) n.mem[OUT_W + OUT_CELLS + m] = 0;
|
||||
for (m = 0; m < k; m++) n_at += (size_t)snprintf(line + n_at, sizeof line - n_at, "1 ");
|
||||
snprintf(line + n_at, sizeof line - n_at, "\n");
|
||||
pfill(line, sizeof line - 2, k);
|
||||
strcat(line, "\n");
|
||||
(void)say(line);
|
||||
(void)say("WORDS\n");
|
||||
for (at = 0; at < plain; at++) if (n.mem[OUT_W + OUT_CELLS + at] != 0) { over++; worst = k; break; }
|
||||
@@ -1286,14 +1311,18 @@ int main(void)
|
||||
|
||||
/* .S works on the stack it is printing, so it needs some of it free */
|
||||
{
|
||||
char line[4 * V4_DATA_DEPTH + 16], want[8 * V4_DATA_DEPTH + 32];
|
||||
static char want[8 * V4_DATA_DEPTH + 32];
|
||||
char line[256];
|
||||
unsigned k, m, most = 0;
|
||||
for (k = 1; k < V4_DATA_DEPTH; k++) {
|
||||
size_t at = 0, wt;
|
||||
/* every depth near the bottom and the top, and every 61st between (the stack is 1024 deep, #189) */
|
||||
for (k = 1; k < V4_DATA_DEPTH; k = (k < 16u || k + 16u >= V4_DATA_DEPTH) ? k + 1u
|
||||
: (k + 61u + 16u < V4_DATA_DEPTH ? k + 61u : V4_DATA_DEPTH - 16u)) {
|
||||
size_t wt;
|
||||
boot_bare();
|
||||
for (m = 0; m < k; m++) at += (size_t)snprintf(line + at, sizeof line - at, "7 ");
|
||||
snprintf(line + at, sizeof line - at, "\n");
|
||||
if (strlen(line) > 80 || strcmp(say(line), " ok\nok> ") != 0) break;
|
||||
if (!pwords()) break;
|
||||
pfill(line, sizeof line - 2, k);
|
||||
strcat(line, "\n");
|
||||
if (strcmp(say(line), " ok\nok> ") != 0) break;
|
||||
wt = (size_t)snprintf(want, sizeof want, "<%u> ", k);
|
||||
for (m = 0; m < k; m++) wt += (size_t)snprintf(want + wt, sizeof want - wt, "7 ");
|
||||
snprintf(want + wt, sizeof want - wt, "\n ok\nok> ");
|
||||
|
||||
Reference in New Issue
Block a user