feat(v4): v3's whole POST, Task 8 round -- the rules, and v4 where the rulings put it (#189)
v3's whole POST on v4 at 983 of 1010 (the table's own count with its drops), from 850.
What remains is capacity ("Dictionary full", the 100-900-deep stacks): next, as ruled.
Found and fixed under the rulings (docs/v4.0.0/POST-PARITY.md):
- IS and DEFER@ refuse a word DEFER did not make, as v3: error 22, "Not deferred".
v4's IS stored into any word -- POST's `42 IS DUP` broke DUP for every case after it.
DEFER marks its word with flag 128 (dict.f18).
- SMUDGE and HIDDEN are compile-only, as v3's table: at the prompt v4's hid the newest word.
- Q./ by zero gives 0 and no error (ruled: v3's table); error 11 retired. The ROM's,
the test's reference and its hand-assembled copy changed alike.
- FENCE is v3's: it protects what is defined so far. The variable is (FENCE).
- The line's length is (#SRC), no longer SPAN: an EXPECT in a line cut the rest of
the line off, and 0 EXPECT could not leave SPAN 0 (FORTH-83).
- POST gains V4_POST_HEAD: the values left and how the output begins -- the form of a
printout whose values are the run's own (TOP-WORDS, WORD-ENTROPY).
post_all_rules.py: the rest of the whole table where it is not taken as v3 ran it --
v4's units for the cases that wrote through HERE as a byte address (CMOVE>, BLANK,
ERASE, FILL wrote into the system's code), the standard's results (COMPARE, SEARCH,
BASE output, THRU, >BODY with FIND's address), v3's descriptions where v3 printed
otherwise, and the cases dropped with their reasons (SP@/SP! by D-2, DABS/DMIN
underflow, CMOVE>.bounds, THRU.negative_end).
make -C v4 test: all v4 tests passed (both widths, mesh-boot, inference).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017RzZgrf7V7Zk2iczBXDRbm
This commit is contained in:
+4
-2
@@ -66,7 +66,8 @@
|
||||
#define HOTVARS (XVARS - 35) /* (HOT): the hot-words cache (#189 Phase 7): its count, the kernel's next slot to take when it is full, the lookup's index, then 32 xts */
|
||||
#define HOT_SIZE 32
|
||||
#define QBASE (HOTVARS - 40) /* the Q words' and DUMP's scratch cells, 39 in all */
|
||||
#define BVARS (QBASE - 16) /* blocks.f18: 6 cells not used now, then SCR BLK (SRC) (SRC-HOOK) */
|
||||
#define BVARS (QBASE - 16) /* blocks.f18: 5 cells not used now, then (#SRC) SCR BLK (SRC) (SRC-HOOK) */
|
||||
#define SRC_LEN (BVARS + 5) /* (#SRC): the length of the text being interpreted (SPAN is EXPECT's count, FORTH-83) */
|
||||
#define SCR (BVARS + 6)
|
||||
#define BLK (BVARS + 7)
|
||||
#define SRC (BVARS + 8)
|
||||
@@ -299,6 +300,7 @@ static unsigned host_branch_slots(void)
|
||||
X("SCR", SCR) \
|
||||
X("BLK", BLK) \
|
||||
X("(SRC)", SRC) \
|
||||
X("(#SRC)", SRC_LEN) \
|
||||
X("(SRC-HOOK)", SRC_HOOK) \
|
||||
X("(LINE-STATUS)", LINE_STATUS) \
|
||||
X("(PORT)", PORT) \
|
||||
@@ -370,7 +372,7 @@ static unsigned host_branch_slots(void)
|
||||
X("N-17", V4_CELL_BITS - 17) \
|
||||
X("MAX-INT", (v4_cell)(V4_MSB - 1u)) \
|
||||
X("HLD", HLD) \
|
||||
X("FENCE", FENCE) \
|
||||
X("(FENCE)", FENCE) \
|
||||
X("CONTEXT", CONTEXT) \
|
||||
X("CURRENT", CURRENT) \
|
||||
X("VOC-LINK", VOC_LINK) \
|
||||
|
||||
@@ -805,16 +805,14 @@ static void build(void)
|
||||
* OV: drop drop drop pop pop drop drop
|
||||
* QS 4 + b! @b -if OVP drop 0 MSB ; OVP: drop -1 MAXHI ;
|
||||
* DIV: (UQ/) QS 4 + b! @b -if L3 drop DNEGATE ; L3: drop ;
|
||||
* ZERO: drop drop drop NODE-ERROR b! -1 !b
|
||||
* over over OR if Z0 drop -if ZP drop drop 0 MSB ;
|
||||
* ZP: drop drop -1 MAXHI ; Z0: drop ;
|
||||
* ZERO: drop drop drop drop drop 0 0 ; by zero: 0 (ruled 2026-11-14)
|
||||
* MSB and MAXHI are the high cells of Q min and Q max. Clobbers A and B. */
|
||||
#define SWAP_INLINE() do { O(OVER); O(PUSH); O(PUSH); O(DROP); O(RPOP); O(RPOP); } while (0)
|
||||
#define SUB_INLINE() do { O(PUSH); O(INV); O(RPOP); O(ADD); O(INV); } while (0)
|
||||
#define FWD(op) v4_asm_branch_fwd(&as, V4_OP_##op)
|
||||
#define HERE_(r) v4_asm_resolve(&as, (r), v4_asm_label(&as))
|
||||
{
|
||||
v4_asm_ref zero, l1, l2, chk, chk2, same, noov1, ov1, ov2, ovp, l3, z0, zp;
|
||||
v4_asm_ref zero, l1, l2, chk, chk2, same, noov1, ov1, ov2, ovp, l3;
|
||||
v4_asm_ref d1, d2, d3;
|
||||
v4_cell l_div, l_noov, l_ov;
|
||||
|
||||
@@ -853,14 +851,8 @@ static void build(void)
|
||||
CALL(w_uqdiv); LIT(QS + 4); O(BANG_B); O(FETCH_B); l3 = FWD(MINUS_IF);
|
||||
O(DROP); CALL(w_dnegate); O(SEMI);
|
||||
HERE_(l3); O(DROP); O(SEMI);
|
||||
HERE_(zero);
|
||||
O(DROP); O(DROP); O(DROP);
|
||||
LIT(NODE_ERROR); O(BANG_B); LIT(-1); O(STORE_B);
|
||||
O(OVER); O(OVER); CALL(w_or); z0 = FWD(IF);
|
||||
O(DROP); zp = FWD(MINUS_IF);
|
||||
O(DROP); O(DROP); LIT(0); LIT((v4_cell)V4_MSB); O(SEMI);
|
||||
HERE_(zp); O(DROP); O(DROP); LIT(-1); LIT((v4_cell)(MAXU >> 1)); O(SEMI);
|
||||
HERE_(z0); O(DROP); O(SEMI);
|
||||
HERE_(zero); /* by zero: 0, no error (v3's table, ruled 2026-11-14) */
|
||||
O(DROP); O(DROP); O(DROP); O(DROP); O(DROP); LIT(0); LIT(0); O(SEMI);
|
||||
|
||||
v4_asm_resolve(&as, d1, l_div);
|
||||
v4_asm_resolve(&as, d2, l_div);
|
||||
@@ -1867,8 +1859,8 @@ static uint64_t v3_q48_mul(uint64_t a, uint64_t b)
|
||||
/* Reference Q./ (D-11), by a different method from the FORTH: magnitudes
|
||||
* in 16-bit limbs, |a| * 2^16 divided by |b| one bit at a time, then the
|
||||
* sign applied (rounding toward zero) and the result saturated to Q max or
|
||||
* Q min. Division by zero gives Q max / Q min by the dividend's sign, 0 for
|
||||
* 0 / 0, and *err = 1. */
|
||||
* Q min. Division by zero gives 0 and no error (v3's table, ruled
|
||||
* 2026-11-14). */
|
||||
static void qdiv_ref(v4_ucell al, v4_ucell ah, v4_ucell bl, v4_ucell bh,
|
||||
v4_ucell *rl, v4_ucell *rh, int *err)
|
||||
{
|
||||
@@ -1877,11 +1869,8 @@ static void qdiv_ref(v4_ucell al, v4_ucell ah, v4_ucell bl, v4_ucell bh,
|
||||
unsigned i, k;
|
||||
|
||||
*err = 0;
|
||||
if (bl == 0 && bh == 0) {
|
||||
*err = 1;
|
||||
if (al == 0 && ah == 0) { *rl = 0; *rh = 0; }
|
||||
else if (ah & V4_MSB) { *rl = 0; *rh = V4_MSB; }
|
||||
else { *rl = MAXU; *rh = MAXU >> 1; }
|
||||
if (bl == 0 && bh == 0) { /* 0, no error: v3's table (ruled 2026-11-14) */
|
||||
*rl = 0; *rh = 0;
|
||||
return;
|
||||
}
|
||||
q_to_limbs(al, ah, a, &an);
|
||||
|
||||
@@ -103,6 +103,7 @@ static int interpret_with(const char *line, unsigned depth, unsigned rdepth)
|
||||
unsigned len = (unsigned)strlen(line), i;
|
||||
put_bytes(TIB, line, len + 1u);
|
||||
n.mem[SPAN] = (v4_cell)len;
|
||||
n.mem[SRC_LEN] = (v4_cell)len;
|
||||
n.mem[TO_IN] = 0;
|
||||
n.mem[NODE_ERROR] = 0;
|
||||
v4_dstack_reset(&n.ds);
|
||||
@@ -132,7 +133,7 @@ static v4_cell one(const char *line)
|
||||
/* the line is abandoned: NODE-ERROR set, not compiling, the rest of it skipped */
|
||||
static int abandoned(const char *line)
|
||||
{
|
||||
return interpret(line) && err() && n.mem[STATE] == 0 && n.mem[TO_IN] == n.mem[SPAN];
|
||||
return interpret(line) && err() && n.mem[STATE] == 0 && n.mem[TO_IN] == n.mem[SRC_LEN];
|
||||
}
|
||||
|
||||
typedef struct { const char *defs, *expr; unsigned nres; v4_cell want[4]; int v3; } programme;
|
||||
|
||||
@@ -66,6 +66,7 @@ static void set_line(const char *s)
|
||||
unsigned len = (unsigned)strlen(s);
|
||||
put_bytes(TIB, s, len + 1u);
|
||||
n.mem[SPAN] = (v4_cell)len;
|
||||
n.mem[SRC_LEN] = (v4_cell)len;
|
||||
n.mem[TO_IN] = 0;
|
||||
}
|
||||
static v4_cell W(const char *name)
|
||||
|
||||
@@ -74,6 +74,7 @@ static void set_line(const char *s)
|
||||
unsigned len = (unsigned)strlen(s);
|
||||
put_bytes(TIB, s, len + 1u);
|
||||
n.mem[SPAN] = (v4_cell)len;
|
||||
n.mem[SRC_LEN] = (v4_cell)len;
|
||||
n.mem[TO_IN] = 0;
|
||||
}
|
||||
|
||||
@@ -316,7 +317,7 @@ int main(void)
|
||||
k = n.input_len - n.input_pos;
|
||||
CHECK(k == (i < t ? 0u : i + 1u - t), "EXPECT leaves %u unread [%u,%u]", k, t, i);
|
||||
}
|
||||
/* no action for n <= 0: nothing read, nothing stored, SPAN as it was, no error */
|
||||
/* for n <= 0 nothing is read or stored, no error, and SPAN is 0: FORTH-83, the count received (ruled 2026-11-14) */
|
||||
{
|
||||
static const v4_cell none[] = { 0, -1, -100, (v4_cell)V4_MSB };
|
||||
for (i = 0; i < 4; i++) {
|
||||
@@ -324,8 +325,8 @@ int main(void)
|
||||
v4_node_console_input_attach(&n, CONSOLE_RX, CONSOLE_ST);
|
||||
(void)v4_node_console_feed(&n, "abc\n", 4);
|
||||
n.mem[SPAN] = 5;
|
||||
CHECK(run("EXPECT", 2, SBUF, none[i], 0) && clean() && !err() && n.mem[SPAN] == 5
|
||||
&& n.input_len - n.input_pos == 4 && byte_at(SBUF) == 0x2A, "EXPECT takes no action for n <= 0 [%u]", i);
|
||||
CHECK(run("EXPECT", 2, SBUF, none[i], 0) && clean() && !err() && n.mem[SPAN] == 0
|
||||
&& n.input_len - n.input_pos == 4 && byte_at(SBUF) == 0x2A, "EXPECT reads nothing for n <= 0, and SPAN is 0 [%u]", i);
|
||||
}
|
||||
v4_node_console_input_attach(&n, CONSOLE_RX, CONSOLE_ST);
|
||||
}
|
||||
@@ -335,8 +336,8 @@ int main(void)
|
||||
n.mem[TO_IN] = 77;
|
||||
CHECK(v4_node_console_feed(&n, " 12 34 +\nnext line\n", 20) == 20, "fed");
|
||||
CHECK(run("QUERY", 0, 0, 0, 0) && clean() && !err(), "QUERY returns");
|
||||
CHECK(n.mem[SPAN] == 9 && n.mem[TO_IN] == 0 && bytes_are(TIB, " 12 34 +\0", 10), "QUERY fills TIB, sets SPAN and zeroes >IN");
|
||||
CHECK(run("SOURCE", 0, 0, 0, 0) && pop() == 9 && pop() == TIB && clean(), "SOURCE is TIB and SPAN @");
|
||||
CHECK(n.mem[SPAN] == 9 && n.mem[SRC_LEN] == 9 && n.mem[TO_IN] == 0 && bytes_are(TIB, " 12 34 +\0", 10), "QUERY fills TIB, sets SPAN and the line's length, and zeroes >IN");
|
||||
CHECK(run("SOURCE", 0, 0, 0, 0) && pop() == 9 && pop() == TIB && clean(), "SOURCE is TIB and the line's length");
|
||||
CHECK(run("QUERY", 0, 0, 0, 0) && clean() && n.mem[SPAN] == 9 && bytes_are(TIB, "next line\0", 10), "the next QUERY reads the next line");
|
||||
{
|
||||
static char longline[200];
|
||||
@@ -349,8 +350,8 @@ int main(void)
|
||||
CHECK(run("QUERY", 0, 0, 0, 0) && clean() && n.mem[SPAN] == 70 && bytes_are(TIB, longline + 80, 70), "the rest of the line is the next QUERY's");
|
||||
v4_node_console_input_attach(&n, CONSOLE_RX, CONSOLE_ST);
|
||||
}
|
||||
n.mem[SPAN] = -5;
|
||||
CHECK(run("SOURCE", 0, 0, 0, 0) && pop() == 0 && pop() == TIB && clean(), "SOURCE reads a negative SPAN as 0");
|
||||
n.mem[SRC_LEN] = -5;
|
||||
CHECK(run("SOURCE", 0, 0, 0, 0) && pop() == 0 && pop() == TIB && clean(), "SOURCE reads a negative length as 0");
|
||||
|
||||
/* ---- WORD ---- */
|
||||
|
||||
@@ -417,8 +418,8 @@ int main(void)
|
||||
set_line("abc def");
|
||||
n.mem[TO_IN] = -3;
|
||||
CHECK(run("WORD", 1, 32, 0, 0) && word_is(pop(), "abc", ' ') && clean(), "a negative >IN reads as 0");
|
||||
n.mem[SPAN] = -3; n.mem[TO_IN] = 0;
|
||||
CHECK(run("WORD", 1, 32, 0, 0) && word_is(pop(), "", 0) && clean() && n.mem[TO_IN] == 0, "a negative SPAN reads as an empty line");
|
||||
n.mem[SRC_LEN] = -3; n.mem[TO_IN] = 0;
|
||||
CHECK(run("WORD", 1, 32, 0, 0) && word_is(pop(), "", 0) && clean() && n.mem[TO_IN] == 0, "a negative length reads as an empty line");
|
||||
|
||||
/* ---- the comment words ---- */
|
||||
set_line("skip this ) kept ( and ) too");
|
||||
|
||||
@@ -697,8 +697,8 @@ static const transcript script[] = {
|
||||
{ "1 Q.FROM-INT 2 Q.FROM-INT Q./ Q.LOG Q.PRINT\n", "-0.69314 ok\nok> ", 0 },
|
||||
{ "-1 Q.FROM-INT 3 Q.FROM-INT Q./ -1 Q.FROM-INT 7 Q.FROM-INT Q./ Q.* . .\n", "0 3120 ok\nok> ", 0 },
|
||||
{ "-4 Q.FROM-INT Q.SIN . . 4 Q.FROM-INT Q.COS . .\n", "0 49598 -1 -42838 ok\nok> ", 0 },
|
||||
{ "Q.0 Q.0 Q./ 65 EMIT\nDEPTH .\n", "Division by zero\n ERROR\nok> 2 ok\nok> ", 0 },
|
||||
{ "7 Q.1 Q.0 Q./ 65 EMIT\nDEPTH .\n", "Division by zero\n ERROR\nok> 3 ok\nok> ", 0 },
|
||||
{ "Q.0 Q.0 Q./ 65 EMIT\nDEPTH .\n", "A ok\nok> 2 ok\nok> ", 0 }, /* by zero: 0, no error (v3's table, ruled 2026-11-14) */
|
||||
{ "7 Q.1 Q.0 Q./ 65 EMIT\nDEPTH .\n", "A ok\nok> 3 ok\nok> ", 0 },
|
||||
{ "7 -4 Q.FROM-INT Q.SQRT 65 EMIT\nDEPTH . . . .\n", "Argument out of range\n ERROR\nok> 3 0 0 7 ok\nok> ", 0 },
|
||||
{ "Q.0 Q.LOG 65 EMIT\n-1 Q.FROM-INT Q.LOG\n", "Argument out of range\n ERROR\nok> Argument out of range\n ERROR\nok> ", 0 },
|
||||
{ "7 PAD -1 DUMP 65 EMIT\n.S\n", "Negative count\n ERROR\nok> <1> 7 \n ok\nok> ", 0 },
|
||||
@@ -1320,7 +1320,7 @@ int main(void)
|
||||
v4_cell dp0 = n.mem[DP], latest0 = n.mem[LATEST];
|
||||
CHECK(is(say(": F1 1 ; VARIABLE F2 : F3 F1 F2 ;\n"), " ok\nok> ") && n.mem[DP] > dp0, "three words");
|
||||
CHECK(is(say("FORGET F1\n"), " ok\nok> ") && n.mem[DP] == dp0 && n.mem[LATEST] == latest0, "FORGET of the first puts HERE and LATEST back where they were");
|
||||
CHECK(is(say(": G1 65 EMIT ; : G2 66 EMIT ;\n"), " ok\nok> ") && is(say("HERE FENCE ! : G3 67 EMIT ;\n"), " ok\nok> "), "two words, the fence, and a third");
|
||||
CHECK(is(say(": G1 65 EMIT ; : G2 66 EMIT ;\n"), " ok\nok> ") && is(say("FENCE : G3 67 EMIT ;\n"), " ok\nok> "), "two words, the fence, and a third");
|
||||
CHECK(is(say("FORGET G2\n"), "Protected word\n ERROR\nok> ") && is(say("G1 G2 G3\n"), "ABC ok\nok> "), "a word below the fence cannot be forgotten");
|
||||
CHECK(is(say("FORGET G3 G1 G2\n"), "AB ok\nok> ") && is(say("G3\n"), "UNKNOWN WORD: 'G3'\n ERROR\nok> "), "one above it can");
|
||||
}
|
||||
|
||||
@@ -67,9 +67,9 @@ static const math_case cases[] = {
|
||||
{ 4, 4, {1, 0, 1, 0}, 2, {0, 0}, 0 },
|
||||
{ 5, 4, {65536, 0, 196608, 0}, 2, {21845, 0}, 0 },
|
||||
{ 5, 4, {-491520, -1, 131072, 0}, 2, {-245760, -1}, 0 },
|
||||
{ 5, 4, {65536, 0, 0, 0}, 2, {-1, X}, 11 },
|
||||
{ 5, 4, {-65536, -1, 0, 0}, 2, {0, M}, 11 },
|
||||
{ 5, 4, {0, 0, 0, 0}, 2, {0, 0}, 11 },
|
||||
{ 5, 4, {65536, 0, 0, 0}, 2, {0, 0}, 0 }, /* Q./ by zero: 0, no error (v3's table, ruled 2026-11-14) */
|
||||
{ 5, 4, {-65536, -1, 0, 0}, 2, {0, 0}, 0 },
|
||||
{ 5, 4, {0, 0, 0, 0}, 2, {0, 0}, 0 },
|
||||
{ 5, 4, {0, 1, 1, 0}, 2, {0, 65536}, 0 },
|
||||
{ 5, 4, {-1, X, 32768, 0}, 2, {-1, X}, 0 },
|
||||
{ 5, 4, {M, -1, -65536, -1}, 2, {M, 0}, 0 },
|
||||
|
||||
@@ -116,6 +116,10 @@ int main(void)
|
||||
|
||||
/* ---- the boot ---- */
|
||||
CHECK(v4_mesh_boot(&ms) == 1, "the boot: %s", said);
|
||||
{ /* POST's tally, shown: for runs of other tables (mkpost --all) */
|
||||
const char *t = strstr(said, "PARITY:V4_POST ");
|
||||
if (t) printf(" %.*s\n", (int)(strchr(t, '\n') ? strchr(t, '\n') - t : 40), t);
|
||||
}
|
||||
CHECK(strstr(said, "PARITY:V4_ROM ") != 0, "the ROM assembled the nucleus, and said so");
|
||||
CHECK(strstr(said, "PARITY:V4_CAPSULE name=v4:forth79.4th ") && strstr(said, "PARITY:V4_CAPSULE name=v4:centre.4th ")
|
||||
&& strstr(said, "PARITY:V4_CAPSULE name=v4:hera.4th "), "FORTH-79 and the kernel's capsules, each with its parity line");
|
||||
|
||||
Reference in New Issue
Block a user