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:
@@ -51,7 +51,10 @@ def judge(case):
|
||||
tail = out.split('POST: PASSED', 1)[-1][-160:].replace('\n', '|')
|
||||
return 'depthsweep: FAIL %s at %d: %s: ...%s' % (name, k, why, tail)
|
||||
|
||||
def vals(k): return ' '.join(['1'] * k)
|
||||
def vals(k):
|
||||
# a word that leaves k values: typed as k numbers, a line for a stack 1024 deep would be longer than a line
|
||||
# may be (#189 Phase 7: the host node's data stack is v3's 1024)
|
||||
return ': V %d 0 DO 1 LOOP ; V' % k
|
||||
|
||||
# The stack shallow, and then every depth from well below where anything
|
||||
# changes to past its end. An error empties the stack, and a wait that a
|
||||
|
||||
+54
-13
@@ -148,7 +148,11 @@ def parse_braces(toks, i):
|
||||
|
||||
def read_module(path):
|
||||
"""Yields (word, case name, input, should_error) for every implemented case."""
|
||||
toks = tokens(open(path, encoding="utf-8", errors="replace").read())
|
||||
source = open(path, encoding="utf-8", errors="replace").read()
|
||||
# a module's own #defines: mama_forth_words_test.c marks its cases MAMA_IMPLEMENTED, which is 0 -- v3's POST
|
||||
# skips them, and so must this (it took any value but a literal 0 as implemented, #189 Phase 7)
|
||||
defines = dict(re.findall(r'^\s*#\s*define\s+(\w+)\s+(\S+)', source, re.M))
|
||||
toks = tokens(source)
|
||||
for i, t in enumerate(toks):
|
||||
if t != ("word", "WordTestSuite"):
|
||||
continue
|
||||
@@ -166,7 +170,8 @@ def read_module(path):
|
||||
if not isinstance(case, list) or len(case) < 6 or not isinstance(case[0], tuple):
|
||||
continue
|
||||
name, text = case[0][1], case[1][1]
|
||||
should_error, implemented = case[4] != "0", case[5] != "0"
|
||||
flag = case[5][1] if isinstance(case[5], tuple) else case[5]
|
||||
should_error, implemented = case[4] != "0", defines.get(flag, flag) != "0"
|
||||
if implemented:
|
||||
yield word, name, text, should_error
|
||||
|
||||
@@ -205,7 +210,19 @@ def atoms(text):
|
||||
else:
|
||||
out.append(word)
|
||||
i = j
|
||||
return out
|
||||
# a word that takes the next word from the input stays on a line with it: cut between them, the word finds
|
||||
# the line's end -- ': T20 20 ;' cut after the ':' is "Name missing" (#189 Phase 7, v3's whole POST)
|
||||
joined = []
|
||||
for piece in out:
|
||||
if joined and joined[-1].split()[-1].upper() in PARSES_NEXT and len(joined[-1].split()) == 1:
|
||||
joined[-1] += " " + piece
|
||||
else:
|
||||
joined.append(piece)
|
||||
return joined
|
||||
|
||||
|
||||
PARSES_NEXT = {":", "CREATE", "VARIABLE", "2VARIABLE", "CONSTANT", "2CONSTANT", "VOCABULARY", "FORGET", "'", "[']",
|
||||
"[COMPILE]", "POSTPONE", "IS", "DEFER", "DEFER@", "FIND", "CHAR", "[CHAR]"}
|
||||
|
||||
|
||||
def pack(prefix, pieces, width=LINE_MAX):
|
||||
@@ -443,6 +460,8 @@ def main():
|
||||
text = "\n".join(report) + "\n"
|
||||
if not args.all:
|
||||
write_doc(cases, results, left_out, disagreements, untested, total, applied, dropped)
|
||||
elif not args.only:
|
||||
write_doc(cases, results, left_out, disagreements, untested, total, applied, dropped, whole=True)
|
||||
if args.report:
|
||||
open(args.report, "w").write(text)
|
||||
sys.stdout.write(text)
|
||||
@@ -459,11 +478,22 @@ def c_string(text):
|
||||
return '"' + "".join(out) + '"'
|
||||
|
||||
|
||||
PHYSICS = os.path.join(ROOT, "capsules", "v4", "physics.4th")
|
||||
|
||||
|
||||
def kernel_words():
|
||||
"""The words capsules/v4/physics.4th defines: they ask the kernel (port 0), so a node with no kernel -- the
|
||||
hosted product -- has none of them, and a case of one is marked V4_POST_KERNEL (#189 Phase 7)."""
|
||||
text = open(PHYSICS).read()
|
||||
return {m.group(1) for m in re.finditer(r'(?:^|\s)(?::|KERNEL-WORD|CONSTANT|VARIABLE|CREATE)\s+(\S+)', text)}
|
||||
|
||||
|
||||
def write_table(table):
|
||||
kernel = kernel_words()
|
||||
with open(OUTPUT, "w", encoding="ascii") as out:
|
||||
out.write("/* post_cases.c -- POST's cases for the FORTH-79 Required Word Set on v4.\n"
|
||||
" * Generated by v4/tools/mkpost.py from v3's POST cases: do not edit.\n"
|
||||
" * docs/v4.0.0/NUCLEUS.md section 6; docs/v4.0.0/POST79.md lists every case\n"
|
||||
out.write("/* post_cases.c -- POST's cases on v4: v3's whole POST (#189 Phase 7).\n"
|
||||
" * Generated by v4/tools/mkpost.py --all from v3's POST cases: do not edit.\n"
|
||||
" * docs/v4.0.0/NUCLEUS.md section 6; docs/v4.0.0/POST.md lists every case\n"
|
||||
" * that is not v3's own with v3's result.\n */\n"
|
||||
'#include "v4/post.h"\n\n')
|
||||
for k, (label, lines, want) in enumerate(table):
|
||||
@@ -472,13 +502,15 @@ def write_table(table):
|
||||
out.write("static const long long s%d[] = { %s };\n" % (k, ", ".join("%dLL" % v if v != -9223372036854775808 else "(-9223372036854775807LL - 1)" for v in want["stack"])))
|
||||
out.write("\nconst v4_post_case v4_post_cases[] = {\n")
|
||||
for k, (label, lines, want) in enumerate(table):
|
||||
expect = want["expect"] + (" | V4_POST_KERNEL" if label.rsplit(".", 1)[0] in kernel else "")
|
||||
out.write(" { %s, l%d, %du, %s, %s, %du, %s, %du },\n"
|
||||
% (c_string(label), k, len(lines), want["expect"], ("s%d" % k) if want["stack"] else "0", want["depth"],
|
||||
% (c_string(label), k, len(lines), expect, ("s%d" % k) if want["stack"] else "0", want["depth"],
|
||||
c_string(want["out"]), len(want["out"].encode("latin-1", errors="replace"))))
|
||||
out.write("};\n\nconst unsigned v4_post_case_count = %du;\n" % len(table))
|
||||
|
||||
|
||||
DOC = os.path.join(ROOT, "docs", "v4.0.0", "POST79.md")
|
||||
DOC_ALL = os.path.join(ROOT, "docs", "v4.0.0", "POST.md")
|
||||
|
||||
|
||||
def code(text):
|
||||
@@ -496,14 +528,23 @@ def expects(rule):
|
||||
"`%s`" % rule["out"].replace("\n", "\\n") if rule.get("out") else "nothing")
|
||||
|
||||
|
||||
def write_doc(cases, results, left_out, disagreements, untested, total, applied, dropped):
|
||||
def write_doc(cases, results, left_out, disagreements, untested, total, applied, dropped, whole=False):
|
||||
by_label = {c["label"]: (c, r) for c, r in zip(cases, results)}
|
||||
out = ["# POST for the FORTH-79 Required Word Set: where it departs from v3", "",
|
||||
"Written by `v4/tools/mkpost.py` from `v4/tools/post79_rules.py`; do not edit.",
|
||||
"Design: `NUCLEUS.md` section 6. The cases are `v4/system/post_cases.c`.", "",
|
||||
if whole:
|
||||
out = ["# POST: v3's whole POST on v4, where it departs from v3", "",
|
||||
"Written by `v4/tools/mkpost.py --all` from `v4/tools/post79_rules.py` and",
|
||||
"`v4/tools/post_all_rules.py`; do not edit. The rulings: `POST-PARITY.md` (#189 Phase 7:",
|
||||
"the standard first -- FORTH-79, FORTH-83, ANS 1994 -- then v3's table, not v3's bugs).",
|
||||
"The cases are `v4/system/post_cases.c`; those of the words `capsules/v4/physics.4th` defines",
|
||||
"need the kernel and are not run by the hosted product.", ""]
|
||||
else:
|
||||
out = ["# POST for the FORTH-79 Required Word Set: where it departs from v3", "",
|
||||
"Written by `v4/tools/mkpost.py` from `v4/tools/post79_rules.py`; do not edit.",
|
||||
"Design: `NUCLEUS.md` section 6. The cases are `v4/system/post_cases.c`.", ""]
|
||||
out += [
|
||||
"POST runs %d cases. %d are v3's, with what the hosted v3 binary did as the" % (total, len(cases) - applied["address"] - applied["standard"]),
|
||||
"expected result. This file lists every other case, and why.", "",
|
||||
"## 1. Rewritten for FORTH-79 (%d)" % (applied["standard"] - dropped), "",
|
||||
("## 1. Rewritten: the standard's result, or v3's table's (%d)" if whole else "## 1. Rewritten for FORTH-79 (%d)") % (applied["standard"] - dropped), "",
|
||||
"v3 departs from the standard, or the case is written for v3's machine. v4",
|
||||
"follows the standard (standing ruling), so the expected result is the",
|
||||
"standard's and not v3's.", "",
|
||||
@@ -538,7 +579,7 @@ def write_doc(cases, results, left_out, disagreements, untested, total, applied,
|
||||
"## 6. Where v3 did not do what its own table expects (%d)" % len(disagreements), "",
|
||||
"POST expects what v3 did, unless section 1 says otherwise.", "", "| Case | |", "|---|---|"]
|
||||
out += ["| `%s` | %s |" % item for item in disagreements]
|
||||
open(DOC, "w").write("\n".join(out) + "\n")
|
||||
open(DOC_ALL if whole else DOC, "w").write("\n".join(out) + "\n")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -40,6 +40,16 @@ FORM = "v3's own word, its output v3's own words and counts: the form kept, v4's
|
||||
WE_HEAD = "Word Usage Statistics (Execution Heat Counts):\n=============================================\n"
|
||||
def TOPHEAD(n): return "Top %d most frequently used words:\n==================================\n" % n
|
||||
|
||||
MINMAX = ("FORTH-79 VARIABLE is a defining word: run inside INIT-MINMAX it takes its name from the input then -- "
|
||||
"'42', then 'UPDATE-MINMAX' -- and a word named 42 hides the number from every case after it (42 U. printed "
|
||||
"an address). v3's table says the case runs (TEST_NORMAL, 'Min/Max tracker'): written as meant, the variables "
|
||||
"made outside, named so as not to hide MIN and MAX")
|
||||
|
||||
F79NAME = "FORTH-79: a name is up to 31 characters -- 26 is no error; v3's table expects one, v3 raised none (the standard first)"
|
||||
V3TABLE_RUN = "v3's table says the case runs (TEST_NORMAL); v3 raised an error it does not say"
|
||||
ARRAY = ("v3's table says the case runs (TEST_NORMAL, 'Array sum program'), but as written ': ARRAY 5 CELLS ALLOT ;' "
|
||||
"names nothing and 'ARRAY NUMS' is an unknown word in any FORTH: written as meant, NUMS made by CREATE")
|
||||
|
||||
STANDARD = {
|
||||
# ---- memory_words ----
|
||||
"C,.basic": {"text": "ALIGN HERE 4 * 65 C, C@ . CR", "stack": [], "out": "65 \n", "why": D1},
|
||||
@@ -153,6 +163,18 @@ STANDARD = {
|
||||
"TOP-WORDS.after_reset": {"head": TOPHEAD(5), "why": FORM},
|
||||
"TOP-WORDS.single_word": {"head": TOPHEAD(1), "why": FORM},
|
||||
"TOP-WORDS.large_count": {"head": TOPHEAD(100), "why": FORM},
|
||||
# ---- integration ----
|
||||
"DATA_STRUCTURES.stack_min_max": {"text": "VARIABLE TMIN 2147483647 TMIN ! VARIABLE TMAX -2147483648 TMAX ! "
|
||||
": UPDATE-MINMAX ( n -- ) DUP TMIN @ < IF DUP TMIN ! ELSE DROP THEN "
|
||||
"DUP TMAX @ > IF DUP TMAX ! ELSE DROP THEN ; "
|
||||
"42 UPDATE-MINMAX 17 UPDATE-MINMAX 99 UPDATE-MINMAX TMIN @ . TMAX @ . CR",
|
||||
"stack": [], "out": "17 42 \n", "why": MINMAX + " -- and run as FORTH runs it: UPDATE-MINMAX's ELSE DROP drops n when it is no new minimum, so 99 never reaches the maximum's test, which takes the 42 the first call left"},
|
||||
"CREATE.long_name": {"stack": [], "out": "", "why": F79NAME},
|
||||
"DICT_PRESSURE.many_defs": {"stack": [], "out": "20 \n", "why": V3TABLE_RUN},
|
||||
"COMPLETE_PROGRAMS.array_sum": {"text": "CREATE NUMS 5 CELLS ALLOT : STORE-NUMS 10 NUMS 0 CELLS + ! 20 NUMS 1 CELLS + ! "
|
||||
"30 NUMS 2 CELLS + ! 40 NUMS 3 CELLS + ! 50 NUMS 4 CELLS + ! ; "
|
||||
": SUM-NUMS 0 5 0 DO NUMS I CELLS + @ + LOOP ; STORE-NUMS SUM-NUMS . CR",
|
||||
"stack": [], "out": "150 \n", "why": ARRAY},
|
||||
# ---- mixed_arithmetic_words: M+ (ANS); M/MOD (v3's own; the double written as FORTH-79 has it) ----
|
||||
"M+.basic": {"stack": [], "out": "100 200 \n", "why": ANS_MPLUS},
|
||||
"M+.overflow": {"stack": [], "out": "2147483647 1 \n", "why": ANS_MPLUS},
|
||||
|
||||
Reference in New Issue
Block a user