Fix LEAVE+LOOP hang, DEPTH off-by-one, division flavor, EVALUATE, WORD, ACCEPT

Six fixes for compliance test regressions introduced in Phases 7-8:

- LEAVE + +LOOP with step=0 caused infinite loop: the XOR termination
  check yields 0 when index=limit and step=0. Added SYSVAR_LEAVE_FLAG
  mechanism — LEAVE sets flag, +LOOP checks it, all loops clear on exit.

- DEPTH was off-by-one: `5440 SP@ -` pushed the literal before SP@
  read the stack pointer, making SP@ see one extra cell. Reordered to
  `SP@ 5440 SWAP -` so SP@ reads dsp before any literal push.

- */ and */MOD used FM/MOD (floored) but WAFER's / uses WASM i32.div_s
  (symmetric). Changed to SM/REM for consistency.

- EVALUATE didn't sync input buffer to WASM memory, breaking SOURCE
  and >IN manipulation inside evaluated strings. Added input-only sync
  (without touching STATE/BASE) and >IN readback after each token.

- WORD didn't skip leading spaces when delimiter != space, causing
  GN' and GS3 tests to read whitespace instead of content.

- Added ACCEPT stub returning 0 for non-interactive mode.

- Added bounds check in refresh_user_here to reject corrupted
  SYSVAR_HERE values beyond WASM memory size.

Core and Facility compliance suites now pass. Other suites have
pre-existing regressions from Phases 1-8 still under investigation.
This commit is contained in:
2026-04-07 20:30:16 +02:00
parent d0991c58f6
commit 8f2c70e6f4
4 changed files with 142 additions and 20 deletions
+5 -3
View File
@@ -7,8 +7,9 @@
\ ---------------------------------------------------------------
\ 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 5440 SP@ - 2 RSHIFT ;
: DEPTH SP@ 5440 SWAP - 2 RSHIFT ;
\ PICK ( xn..x0 n -- xn..x0 xn ) copy nth stack item
: PICK 1+ CELLS SP@ + @ ;
@@ -144,10 +145,11 @@
THEN ;
\ */ ( n1 n2 n3 -- n4 ) n1*n2/n3 with double intermediate
: */ >R M* R> FM/MOD SWAP DROP ;
\ Must use SM/REM (symmetric) to match WAFER's WASM i32.div_s semantics.
: */ >R M* R> SM/REM SWAP DROP ;
\ */MOD ( n1 n2 n3 -- rem quot )
: */MOD >R M* R> FM/MOD ;
: */MOD >R M* R> SM/REM ;
\ ---------------------------------------------------------------
\ Phase 4: HERE and ALIGNED