Forth 2012 compliance: 3→10 word sets passing (44→1 errors)

Major compliance push bringing WAFER from 3 to 10 passing Forth 2012
compliance test suites (Core, Core Extensions, Core Plus, Double,
Exception, Facility, Locals, Memory, Search Order, String).

Compiler/runtime fixes:
- DEFER: host function via pending_define, works inside colon defs
- COMPILE,: handle_pending_compile in execute_word for [...] sequences
- MARKER: full save/restore with pending_marker_restore mechanism
- IMMEDIATE: changed from XOR toggle to OR set per Forth 2012 spec
- ABORT": throw -2 via THROW, no message display when caught
- M*/: symmetric division to match WAFER's / behavior
- pending_define: single i32 flag → Vec<i32> queue for multi-action words
- Optimizer: prevent inlining words containing EXIT or ForthLocal ops
- +LOOP: corrected boundary check formula with AND step comparison
- REPEAT: accept bare BEGIN (unstructured IF...BEGIN...REPEAT)
- Auto-close unclosed IFs at ; for unstructured control flow
- _create_part_: use reserve_fn_index to preserve dictionary.latest()

Memory layout:
- Separate PICT_BUF and WORD_BUF regions to prevent PAD overlap
- Updated DEPTH hardcoded DATA_STACK_TOP in boot.fth

New word sets:
- [IF]/[ELSE]/[THEN]/[DEFINED]/[UNDEFINED]: conditional compilation
- UNESCAPE/SUBSTITUTE/REPLACES: string substitution (host functions)
- Locals {: syntax: parser, ForthLocalGet/Set IR ops, WASM local codegen
- ENVIRONMENT? support for #LOCALS (returns 16)
- N>R/NR>/SYNONYM: programming-tools extensions
- Search Order: ONLY, ALSO, PREVIOUS, DEFINITIONS, FORTH,
  FORTH-WORDLIST, GET-ORDER, SET-ORDER, GET-CURRENT, SET-CURRENT,
  WORDLIST, SEARCH-WORDLIST with full multi-wordlist dictionary support
  via Arc<Mutex> shared state for immediate effect from compiled code

Remaining: 1 cascade error in Programming-Tools from CS-PICK/CS-ROLL
(unstructured control-flow stack manipulation, requires flat IR).
This commit is contained in:
2026-04-09 10:10:24 +02:00
parent 3bef345e86
commit 52698cd409
7 changed files with 1278 additions and 124 deletions
+5 -5
View File
@@ -8,8 +8,8 @@
\ DEPTH ( -- n ) number of items on the data stack
\ SP@ must come first so it reads the dsp before DEPTH's own literal push.
\ DATA_STACK_TOP = 5440, uses arithmetic right shift for / 4
: DEPTH SP@ 5440 SWAP - 2 RSHIFT ;
\ DATA_STACK_TOP = 5632 (0x1600), uses arithmetic right shift for / 4
: DEPTH SP@ 5632 SWAP - 2 RSHIFT ;
\ PICK ( xn..x0 n -- xn..x0 xn ) copy nth stack item
: PICK 1+ CELLS SP@ + @ ;
@@ -188,10 +188,10 @@
: SPACES 0 ?DO SPACE LOOP ;
\ Pictured numeric output constants
\ PAD_BASE = 0x0440, PAD_SIZE = 256, SYSVAR_HLD = 28
\ PICT_BUF_TOP = 0x05C0 = 1472, SYSVAR_HLD = 28
\ <# ( -- ) begin pictured numeric output
: <# 1344 28 ! ;
: <# 1472 28 ! ;
\ HOLD ( char -- ) add character to pictured output
: HOLD 28 @ 1- DUP 28 ! C! ;
@@ -220,7 +220,7 @@
: #S BEGIN # 2DUP OR 0= UNTIL ;
\ #> ( ud -- c-addr u ) end pictured output, return string
: #> 2DROP 28 @ 1344 OVER - ;
: #> 2DROP 28 @ 1472 OVER - ;
\ Formatted output built on pictured numeric output