# SPDX-License-Identifier: LicenseRef-Starship-1.0 # Copyright (c) 2023-2026 Robert A. James """post_all_rules.py -- v3's whole POST on v4: where a case is not taken as v3 ran it (#189 Phase 7, Task 8). mkpost.py --all takes every case of v3's whole POST, v3 the reference, with post79_rules.py's rules for the Required set. These are the rest, in post79_rules.STANDARD's shape: `text` if the line changes, then `error`, or `stack` and `out`, or `depth`; `why` the reason. None drops a case (DROPPED gives why). The authority, ruled by Captain Bob 2026-11-14 (docs/v4.0.0/POST-PARITY.md; the texts in docs/reference/standards/): FORTH-79, then FORTH-83, then ANS Forth 1994, then v3 -- held to its own table where v3 does not do what the table says -- only for words no standard defines. Where a case's output names v3's own words, its form is kept with v4's values. Every expectation here is worked from that authority, not taken from what v4 prints. """ D1 = "v3's address unit is a byte in 8-byte cells; v4's is a cell (D-1): the case in v4's units, a byte address 4 * a cell's" D83 = "FORTH-83 ('number'): a double is stored with its high cell at the lower address (ruled 2026-11-14)" D79 = "FORTH-79: a double on the stack has its high cell on top; the case's double was written low-cell-last" ANS_MPLUS = "ANS Forth 8.6.1.1830 M+ ( d1 n -- d2 ); v3's results, and its descriptions, are not" ANS_2R = "ANS Forth 6.2.0340 2>R: 'Interpretation semantics for this word are undefined' -- the case run inside a definition" V3TABLE = "v3's own word: v3 raises an error its table says it does not (ruled: v3's table, not v3's bugs)" DAMAGE = "v3's case in v3's units, run in v4's, writes into the system's code (FILL at a cell address taken as a byte address)" DAMAGE_W = "v3's case in v3's units, run in v4's, writes into the system's code (HERE, a cell address, taken as a byte address)" ANS_RF = "ANS Forth 6.1.0580 >R: 'Interpretation semantics for this word are undefined' -- the case run inside a definition" V3ADDR = "the case leaves an address on the stack (HERE's, or S\"'s), a different number on each machine: the case without it" ANS_CMP = "ANS Forth 17.6.1.0935 COMPARE and 17.6.1.2191 SEARCH, as their descriptions have them; v3's case compares S\"'s string with HERE taken as a length. In a definition, as ANS 11.6.1.2165 S\" keeps one interpreted string only" V3OWN_DESC = "v3's own word, as its table's description has it; v3's case leaves HERE on the stack" F79BASE = "FORTH-79 BASE: numbers are converted in and out in BASE -- after 16 BASE ! the line's 255 is hexadecimal and is printed 255; v3 printed it in decimal" F83THRU = "FORTH-83 THRU loads n1 through n2: with n2 below n1 there is none to load, and no error" V3INT = "v3's own word: v3 prints a value of its own machine (its DictEntry); the case as its description has it" ANS_BODY = "FORTH-83 >BODY takes a compilation address -- FORTH-79's FIND gives one; FORTH-79's ' gives the parameter field already, so v3's ' xxx >BODY goes one too far. v3 prints an address: the case shows >BODY's field is ''s (and VARIABLE's)" ORDERF = "ANS Forth 16.6.2.1985 ORDER: the form is the system's; v3 names FORTH '(FIND)' -- v4's form with v4's names" V3RUN = "v3 prints a number its table's description does not ask for; the description's value" QD = "Q48.16 on v4 is a double, low cell then high (ruled 2026-11-14): its raw value printed with D." INFHIST = "the value comes of the run's own history, the same on no two runs or machines: the case as its description has it ('no error')" DECAY = "v3's own word: the build's DECAY_RATE_PER_US_Q16, 1 by default (v3/Makefile, Kconfig.physics); the v3 that made the table was built with 0" FORM = "v3's own word, its output v3's own words and counts: the form kept, v4's values (ruled 2026-11-14) -- they come of the run's history, so the printout's head is compared" 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}, "C,.zero": {"text": "ALIGN HERE 4 * 0 C, C@ . CR", "stack": [], "out": "0 \n", "why": D1}, "2,.roundtrip": {"text": "12345 67890 2, HERE 2 - 2@ . . CR", "stack": [], "out": "67890 12345 \n", "why": D1}, "2,.save-and-verify": {"text": "12345 67890 2, HERE 2 - 2@ 67890 = SWAP 12345 = AND . CR", "stack": [], "out": "-1 \n", "why": D1}, "-!.basic": {"stack": [], "out": "7 \n", "why": V3TABLE}, "-!.by_zero": {"stack": [], "out": "42 \n", "why": V3TABLE}, "-!.negative": {"stack": [], "out": "15 \n", "why": V3TABLE}, "2!.basic": {"text": "11 22 HERE 2! HERE @ . HERE 1 + @ . CR", "stack": [], "out": "22 11 \n", "why": D1 + "; " + D83}, "2!.zeros": {"text": "0 0 HERE 2! HERE @ . HERE 1 + @ . CR", "stack": [], "out": "0 0 \n", "why": D1 + "; " + D83}, "2!.negative": {"text": "-1 -2 HERE 2! HERE @ . HERE 1 + @ . CR", "stack": [], "out": "-2 -1 \n", "why": D1 + "; " + D83}, "ERASE.basic": {"text": "HERE 4 * 4 65 FILL HERE 4 * 4 ERASE HERE 4 * C@ . HERE 4 * 3 + C@ . CR", "stack": [], "out": "0 0 \n", "why": D1 + "; " + DAMAGE}, "ERASE.zero_n": {"text": "HERE 4 * 0 ERASE", "stack": [], "out": "", "why": D1}, "FILL.zero_n": {"text": "HERE 4 * 0 88 FILL", "stack": [], "out": "", "why": D1}, "MOVE.zero_n": {"text": "HERE HERE 1 + 0 MOVE", "stack": [], "out": "", "why": D1}, "HERE.after_comma~2": {"stack": [0], "out": "", "why": "v3 raises an error its table says it does not: HERE moves by 1 CELLS, so the flag is -1 and 0 -1 / is 0 (ruled: v3's table)"}, # ---- string_words: the cases that write through HERE, in v4's byte units ---- "CMOVE>.basic": {"text": ": PTCM S\" Test\" HERE 4 * 10 + SWAP CMOVE> ; PTCM HERE 4 * 10 + 4 TYPE CR", "stack": [], "out": "Test\n", "why": D1 + "; " + DAMAGE_W + "; " + ANS_RF + " (v3's DUP >R left the count on the return stack)"}, "CMOVE>.overlap": {"text": "HERE 4 * DUP 1+ 5 CMOVE>", "stack": [], "out": "", "why": D1 + "; " + DAMAGE_W}, "CMOVE>.bounds": None, "SP@.depth_effect": None, "SP@.empty_stack": None, "SP@.multiple_items": None, "SP!.basic_restore": None, "STACK_MGMT.sp_round_trip": None, "STACK_MGMT.depth_preservation": None, "DABS.one_item": None, "DMIN.three_items": None, "BLANK.basic": {"text": "HERE 4 * 5 BLANK HERE 4 * 5 TYPE CR", "stack": [], "out": " \n", "why": D1 + "; " + DAMAGE_W}, # ---- string_words: from their descriptions; no address left behind ---- "COMPARE.equal": {"text": ': PTC1 S" Test" S" Test" COMPARE . ; PTC1 CR', "stack": [], "out": "0 \n", "why": ANS_CMP}, "COMPARE.less": {"text": ': PTC2 S" Test1" S" Test2" COMPARE . ; PTC2 CR', "stack": [], "out": "-1 \n", "why": ANS_CMP}, "COMPARE.greater": {"text": ': PTC3 S" Test2" S" Test1" COMPARE . ; PTC3 CR', "stack": [], "out": "1 \n", "why": ANS_CMP}, "COMPARE.different_lengths": {"text": ': PTC4 S" Test" S" Testing" COMPARE . ; PTC4 CR', "stack": [], "out": "-1 \n", "why": ANS_CMP}, "SEARCH.found": {"text": ': PTS1 S" Testing" S" Test" SEARCH . . DROP ; PTS1 CR', "stack": [], "out": "-1 7 \n", "why": ANS_CMP}, "SEARCH.not_found": {"text": ': PTS2 S" Testing" S" Xyz" SEARCH . . DROP ; PTS2 CR', "stack": [], "out": "0 7 \n", "why": ANS_CMP}, "SEARCH.empty_pattern": {"text": ': PTS3 S" Test" HERE 4 * 0 SEARCH . . DROP ; PTS3 CR', "stack": [], "out": "-1 4 \n", "why": ANS_CMP + "; " + D1}, "SEARCH.empty_string": {"text": ': PTS4 HERE 4 * 0 S" Test" SEARCH . . DROP ; PTS4 CR', "stack": [], "out": "0 0 \n", "why": ANS_CMP + "; " + D1}, "SCAN.basic": {"text": 'S" Test,Data" BL SCAN TYPE CR', "stack": [], "out": "\n", "why": V3OWN_DESC}, "SCAN.not_found": {"text": 'S" TestData" BL SCAN TYPE CR', "stack": [], "out": "\n", "why": V3OWN_DESC}, "SCAN.all_delims": {"text": 'S" " BL SCAN TYPE CR', "stack": [], "out": " \n", "why": V3OWN_DESC}, "SKIP.basic": {"text": 'S" Test" BL SKIP TYPE CR', "stack": [], "out": "Test\n", "why": V3OWN_DESC}, "SKIP.no_delims": {"text": 'S" Test" BL SKIP TYPE CR', "stack": [], "out": "Test\n", "why": V3OWN_DESC}, "SKIP.all_delims": {"text": 'S" " BL SKIP TYPE CR', "stack": [], "out": "\n", "why": V3OWN_DESC}, "BL.in_scan": {"text": 'S" a b" BL SCAN SWAP DROP . CR', "stack": [], "out": "2 \n", "why": V3OWN_DESC}, 'S".interpret_len': {"text": 'S" hello" . DROP CR', "stack": [], "out": "5 \n", "why": V3ADDR}, 'S".empty': {"text": 'S" " . DROP CR', "stack": [], "out": "0 \n", "why": V3ADDR}, # ---- io_words ---- "BASE_OUTPUT.hex": {"stack": [], "out": "255 \n", "why": F79BASE}, "BASE_OUTPUT.octal": {"stack": [], "out": "64 \n", "why": F79BASE}, "BASE_OUTPUT.binary": {"stack": [], "out": "101 \n", "why": F79BASE + " (5 is read before BASE changes)"}, "BASE_OUTPUT.base_restore": {"stack": [], "out": "FF \n", "why": F79BASE + " (255 is read in decimal)"}, # ---- block_words ---- "FLUSH.dirty_blocks": {"text": "1 BLOCK DROP UPDATE FLUSH", "stack": [], "out": "", "why": V3ADDR + " (BLOCK's)"}, "THRU.zero_end": {"stack": [], "out": "", "why": F83THRU}, "THRU.negative_end": None, # ---- dictionary_words ---- "C,.basic~2": {"text": "ALIGN HERE 4 * 65 C, C@ . CR", "stack": [], "out": "65 \n", "why": D1}, "C,.zero~2": {"text": "ALIGN HERE 4 * 0 C, C@ . CR", "stack": [], "out": "0 \n", "why": D1}, "C,.high_byte": {"text": "ALIGN HERE 4 * 255 C, C@ . CR", "stack": [], "out": "255 \n", "why": D1}, "C,.truncation": {"text": "ALIGN HERE 4 * 256 C, C@ . CR", "stack": [], "out": "0 \n", "why": D1}, "C,.negative": {"text": "ALIGN HERE 4 * -1 C, C@ . CR", "stack": [], "out": "255 \n", "why": D1}, "C,.multiple": {"text": "ALIGN HERE 4 * 65 C, 66 C, DUP C@ . 1+ C@ . CR", "stack": [], "out": "65 66 \n", "why": D1}, "LATEST.stability": {"text": "LATEST DUP LATEST = . DROP CR", "stack": [], "out": "-1 \n", "why": V3ADDR + " (LATEST's)"}, "COMPILATION.pad_isolation": {"text": "PAD 4 / 999 OVER ! HERE 42 , PAD 4 / @ 999 = . DROP DROP CR", "stack": [], "out": "-1 \n", "why": D1 + " (PAD is a byte address, ! takes a cell's); " + V3ADDR}, # ---- dictionary_manipulation_words ---- "LATEST.basic~2": {"text": "LATEST 0<> . CR", "stack": [], "out": "-1 \n", "why": V3INT}, "LATEST.after_def": {"text": ": test7 46 ; LATEST ' test7 = . CR", "stack": [], "out": "-1 \n", "why": V3INT}, "LATEST.after_forget": {"text": "LATEST CREATE test8 FORGET test8 LATEST = . CR", "stack": [], "out": "-1 \n", "why": V3INT}, ">BODY.basic": {"text": "CREATE test9 FIND test9 >BODY ' test9 = . CR", "stack": [], "out": "-1 \n", "why": ANS_BODY}, ">BODY.variable": {"text": "VARIABLE var1 FIND var1 >BODY var1 = . CR", "stack": [], "out": "-1 \n", "why": ANS_BODY}, # ---- vocabulary_words ---- "ORDER.basic": {"stack": [], "out": "Search order: FORTH \nCurrent: FORTH\n", "why": ORDERF}, "ORDER.multiple": {"stack": [], "out": "Search order: TEST-VOC9 FORTH\nCurrent: TEST-VOC9\n", "why": ORDERF}, "ORDER.after_forth": {"stack": [], "out": "Search order: FORTH \nCurrent: FORTH\n", "why": ORDERF}, # ---- physics_freeze_words ---- "FREEZE-WORD.basic": {"stack": [], "out": "-1 \n", "why": V3RUN}, "UNFREEZE-WORD.basic": {"stack": [], "out": "0 \n", "why": V3RUN}, "FROZEN?.not_frozen": {"stack": [], "out": "0 \n", "why": V3RUN}, "FROZEN?.not_found": {"stack": [], "out": "0 \n", "why": V3RUN}, "HEAT!.basic": {"stack": [], "out": "999 \n", "why": V3RUN}, "HEAT@.of_fresh_word": {"stack": [], "out": "0 \n", "why": V3RUN}, "DECAY-RATE@.basic": {"stack": [], "out": "1 \n", "why": DECAY}, # ---- inference_words ---- "Q.VARIANCE.three_cells": {"text": "100 HERE ! 200 HERE 1 + ! 300 HERE 2 + ! HERE 3 Q.VARIANCE Q.TO-INT . CR", "stack": [], "out": "6666 \n", "why": D1}, "INFER-DECAY-SLOPE.three_cells": {"text": "300 HERE ! 200 HERE 1 + ! 100 HERE 2 + ! HERE 3 INFER-DECAY-SLOPE Q.TO-INT . CR", "stack": [], "out": "0 \n", "why": D1}, "INFER-VARIANCE@.after_run": {"text": "INFER-RUN INFER-VARIANCE@ Q.TO-INT DROP CR", "stack": [], "out": "\n", "why": INFHIST}, "INFER-WINDOW@.after_run": {"text": "INFER-RUN INFER-WINDOW@ DROP CR", "stack": [], "out": "\n", "why": INFHIST}, "INFER-EARLY-EXIT@.after_run": {"text": "INFER-RUN INFER-EARLY-EXIT@ DUP 0= SWAP 1 = OR . CR", "stack": [], "out": "-1 \n", "why": INFHIST + " (0 or 1)"}, # ---- q48_words ---- "Q.1.raw_value": {"text": "Q.1 D. CR", "stack": [], "out": "65536 \n", "why": QD}, "Q.0.raw_value": {"text": "Q.0 D. CR", "stack": [], "out": "0 \n", "why": QD}, "Q.SCALE.raw_value": {"text": "Q.SCALE D. CR", "stack": [], "out": "65536 \n", "why": QD}, # ---- stress: >R at the prompt ---- "RETURN_STACK.basic_to_r": {"text": ": PTRS1 1 2 3 >R >R >R R> R> R> + + . ; PTRS1 CR", "stack": [], "out": "6 \n", "why": ANS_RF}, "RETURN_STACK.r_fetch": {"text": ": PTRS2 42 >R R@ . R> DROP ; PTRS2 CR", "stack": [], "out": "42 \n", "why": ANS_RF}, # ---- starforth_words: v3's printouts, their form ---- "WORD-ENTROPY.display_all": {"head": WE_HEAD, "why": FORM}, "WORD-ENTROPY.after_execution": {"head": WE_HEAD, "why": FORM}, "WORD-ENTROPY.stack_preserved": {"head": WE_HEAD, "why": FORM}, "TOP-WORDS.display_top5": {"head": TOPHEAD(5), "why": FORM}, "TOP-WORDS.display_top10": {"head": TOPHEAD(10), "why": FORM}, "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}, "M+.negative": {"stack": [], "out": "-100 50 \n", "why": ANS_MPLUS}, "M+.both_negative": {"stack": [], "out": "-101 -200 \n", "why": ANS_MPLUS}, "M/MOD.basic": {"text": "1000 0 100 M/MOD . . CR", "stack": [], "out": "10 0 \n", "why": D79 + " (1000 / 100)"}, "M/MOD.with_remainder": {"text": "1234 0 100 M/MOD . . CR", "stack": [], "out": "12 34 \n", "why": D79 + " (1234 / 100)"}, "M/MOD.double_dividend": {"stack": [], "out": "500 1 \n", "why": "its description: 5001 / 10 is 500 remainder 1; v3 prints otherwise"}, "M/MOD.by_one": {"text": "42 0 1 M/MOD . . CR", "stack": [], "out": "42 0 \n", "why": D79 + " (42 / 1)"}, "M/MOD.negative_dividend": {"text": "-1000 -1 100 M/MOD . . CR", "stack": [], "out": "-10 0 \n", "why": D79 + " (-1000 / 100)"}, # ---- double_words: 2>R 2R> 2R@ (ANS, compile-only) ---- "2>R.roundtrip": {"text": ": PT2R1 10 20 2>R 2R> . . ; PT2R1 CR", "stack": [], "out": "20 10 \n", "why": ANS_2R}, "2>R.depth_after": {"text": ": PT2R2 1 2 2>R DEPTH . 2R> DROP DROP ; PT2R2 CR", "stack": [], "out": "0 \n", "why": ANS_2R}, "2R>.roundtrip": {"text": ": PT2R3 5 6 2>R 2R> . . ; PT2R3 CR", "stack": [], "out": "6 5 \n", "why": ANS_2R}, "2R>.depth": {"text": ": PT2R4 9 8 2>R 2R> DEPTH . ; PT2R4 CR", "stack": [9, 8], "out": "2 \n", "why": ANS_2R}, "2R@.peek": {"text": ": PT2R5 3 4 2>R 2R@ . . 2R> DROP DROP ; PT2R5 CR", "stack": [], "out": "4 3 \n", "why": ANS_2R}, "2R@.non_destructive": {"text": ": PT2R6 7 8 2>R 2R@ DROP DROP 2R> . . ; PT2R6 CR", "stack": [], "out": "8 7 \n", "why": ANS_2R}, } DROPPED = { "SP@.depth_effect": 'SP@ and SP! are no standard\'s; no stack pointer is visible to code (DECOMPOSITION.md D-2), ruled to stand (Captain Bob, 2026-11-14: "D-2 for SP@").', "SP@.empty_stack": 'SP@ and SP! are no standard\'s; no stack pointer is visible to code (DECOMPOSITION.md D-2), ruled to stand (Captain Bob, 2026-11-14: "D-2 for SP@").', "SP@.multiple_items": 'SP@ and SP! are no standard\'s; no stack pointer is visible to code (DECOMPOSITION.md D-2), ruled to stand (Captain Bob, 2026-11-14: "D-2 for SP@").', "SP!.basic_restore": 'SP@ and SP! are no standard\'s; no stack pointer is visible to code (DECOMPOSITION.md D-2), ruled to stand (Captain Bob, 2026-11-14: "D-2 for SP@").', "STACK_MGMT.sp_round_trip": 'SP@ and SP! are no standard\'s; no stack pointer is visible to code (DECOMPOSITION.md D-2), ruled to stand (Captain Bob, 2026-11-14: "D-2 for SP@").', "STACK_MGMT.depth_preservation": 'SP@ and SP! are no standard\'s; no stack pointer is visible to code (DECOMPOSITION.md D-2), ruled to stand (Captain Bob, 2026-11-14: "D-2 for SP@").', "DABS.one_item": 'ANS Forth 8.6.1.1160 DABS / 8.6.1.1220 DMIN: given too few values, stack underflow is an ambiguous condition (ANS 4.1.2); no standard asks for an error.', "DMIN.three_items": 'ANS Forth 8.6.1.1160 DABS / 8.6.1.1220 DMIN: given too few values, stack underflow is an ambiguous condition (ANS 4.1.2); no standard asks for an error.', "THRU.negative_end": "FORTH-83 THRU takes block numbers, unsigned: -3 is not one (ANS 15.6.2.2280: an ambiguous condition); " "v3's error is its own, which no standard asks for.", "CMOVE>.bounds": "ANS Forth 17.6.1.0920 CMOVE> raises no error for a count past a buffer; 1000 bytes at PAD (84 bytes " "or more) is in v4's memory and writes over what the system keeps above PAD. v3's error is v3's own " "bounds check, which no standard asks for; there is nothing to expect.", }