# PBXB64 V4 validation

Validated package version: `0.50.0-z64 (Release V4)`.

## Validation environment

```text
Host: Windows 11 (x64)
Toolchain: x86_64-w64-mingw32-gcc 15.2.0 (ucrt-posix-seh)
```

## Test lane results

```text
Assembly (-S):  244/244 passed (expected fails: 0, regressions: 0)
Link+Run (PB):  50/50 passed (expected: 0) [includes 14 container/callback tests]
Link+Run (B64): 13/13 passed (expected: 0)
C Compile (-S): 84/84 passed (expected fails: 20) [c_hlib library files without main()]
Link+Run (C):   2/2 passed
```

All lanes pass with 0 unexpected fails and 0 regressions. The 20 C Compile expected fails are c_hlib `.c` files (`c_hlib_arr.c`, `c_hlib_dtre.c`, `c_hlib_tri.c`, etc.) and their associated test harnesses (`test_*.c`) — these are compiled by MinGW as part of the build, not by PBXB64's C frontend, so they correctly fail the `-S` test.

### Z65 Native H-Lib Container Types

All 10 container type families are now implemented as first-class PB types:

| Family | Type keyword | Variant count | Methods | Status |
|--------|-------------|---------------|---------|--------|
| Arr | `LNARR` (etc.) | 14 | New/Final/Count/Add/Get/Set/Ins/Del/Swap/Reverse/Sort/IndexOf/Contains/Slice/Clone/Fill/ToArray/PushFirst/PushLast/PopFirst/PopLast/PeekFirst/PeekLast | P |
| Stk | `LNSTK` (etc.) | 13 | New/Final/Validate/Clear/Count/Push/Pop/Peek/Top/Empty/ToArray | P |
| Que | `LNQUE` (etc.) | 13 | New/Final/Validate/Clear/Count/Push/Pop/Peek/Front/Back/Empty/ToStk | P |
| Lst | `LNLST` (etc.) | 13 | New/Final/Validate/Clear/Count/Add/PushFirst/PushLast/PopFirst/PopLast/PeekFirst/PeekLast/Del/DelFirst/DelLast/First/Last/Next/Prev/Get/Set/IndexOf/Contains/ToArray/Clone | P |
| Str | `SSSTR` (etc.) | 2 | New/Final/Count/Capacity/Clear/Set/Get/CStr/Append/Insert/Delete/SubStr/Compare/Upper/Lower/Trim/PadLeft/PadRight/Replace/Split/StartsWith/EndsWith/Clone | P |
| 2D | `LN2D` | 1 | New/Final/Validate/Count/Set/Get/SetRow/GetRow/Width/Height/InBounds/Clear/Clone | P |
| Hsh | `LNHSH` (etc.) | 25 | New/Final/Validate/Count/Clear/Set/Get/Del/Contains/Keys/First/Next/Prev/GetKey/GetVal/Clone | P |
| Tre | `LNTRE` (etc.) | 25 | New/Final/Validate/Count/Clear/Set/Get/Got/Del/First/Next/Last/Prev/GetKey/GetVal/SetVal/Clone/ToArray | P |
| DTre | `WSDTRE` | 1 | New/Final/Count/Clear/Set/Get/Del/First/Last/Next/Prev | P |
| Tri | `SSTRI` | 1 | New/Final/Count/Clear/Set/Get/Del/StartsWith/EndsWith/Keys | P |

12 test files in `examples/basic/Container_*_Tests.pb` all pass at exit=0. Phase 7 adds UDT payloads for Arr, Lst, Long-keyed Hsh and Long-keyed Tre via `Container_UDT_Arr.pb`, `Container_UDT_Lst.pb`, `Container_UDT_Hsh.pb` and `Container_UDT_Tre.pb`.

### Z68 H-Lib Phase 8 — C-frontend parity

The C frontend can now use native H-Lib containers from C source via `core/include/c17/pbxb64/hlib.h`. `examples/c/c_hlib_lnarr.c` creates a `LnArr`, pushes/sets/gets values, checks count/contains, and returns 0 on success. The C Link+Run lane is now **2/2**.

### Z69 H-Lib Phase 9 — SortUsing callbacks + CODEPTR

`CODEPTR(FunctionName)` now returns the real address of a PB function, enabling `Arr.SortUsing CODEPTR(Comparator)`. The backend emits `lea reg, [rip + symbol]` for the function address. `c_hlib_arr.c` gained `c_hlib_<prefix>arr_sort_using` wrappers with a context-passing comparator. The PB Link+Run lane grew to **50/50**. The old `c_hlib_arr_qsort_impl` also had a fixed-global-pivot bug that hung for arrays with 4+ elements; it was rewritten as a correct recursive quicksort.

### Z64 bug sweep (25 bugs fixed)

All 25 compiler bugs documented in `ToDo.md` during Z64 are fixed. Detailed changelog in AGENTS.md.

### Z61 backend fixes

1. **Win64 multi-arg call ABI (5+ args)** — the caller's argument setup order was wrong: 5th+ stack args were being pushed *before* reserving the 32-byte shadow space, leaving them at `rbp+48+` in the callee instead of the canonical `rbp+16`. Reordered the call sequence to reserve shadow first, then push 5th+ args. Updated `IR_VALUE_PARAM` for `value.id >= 4` to emit `MOPERAND_MEM_INDIRECT` reading from `rbp+16+8*(id-4)`. Extended `regalloc` spill materialization and `IR_OP_LOAD`/`IR_OP_STORE` to accept the new address kind.

2. **`IR_OP_REM` correctness** — peephole passes 3 and 9 were removing the dividend load (`mov rax, 100` before `cqo; idiv r11`) because RAX appeared to have no read after the load. The reads by `CQO` (implicit RAX) and `IDIV`/`DIV` (implicit `RDX:RAX`) were not being recognized. Extended `peephole_reg_read_by` and `pass3_dead_regs` to recognize these implicit reads. Result: `100%5=0`, `100%7=2`, `17%5=2` (all correct).

3. **New B64 regressions**:
   - `six_args.b64` — `1+2+3+4+5+6=21` (2 stack args)
   - `seven_args.b64` — `1+2+3+4+5+6+7=28` (3 stack args)
   - `div_rem.b64` upgraded to test both `81/3=27` and the three REM cases above
   - `five_args.b64` upgraded from `0` for 5th arg to `5` (now `1+2+3+4+5=15`)

### Z60 limitation sweep (4 subagent tracks)

1. **B64 examples (10 new files)** — `call.b64`, `if_else.b64`, `loop_control.b64`, `params.b64`, `five_args.b64`, `div_rem.b64`, `shift_count.b64`, `global_data.b64`, `global_expr.b64`, `call_add.b64`. B64 link+run: **1/11 → 11/11**.

2. **PB Link+Run fixes**:
   - `pointer_struct_array.pb` — fixed RHS array element read in `pb_frontend_expr_parser.c:212` (GEP+load when `has_slot`).
   - `v12_pb_features.pb` — moved `bestof_str_i64` bytecode to `runtime_intrinsics_data.c` and added registration (with 4 heap relocations).
   - Link+Run (PB): **6/6 with 1 expected (float_ops.pb only)**.

3. **Runtime stubs (Win32)** — replaced 14 no-op stubs in `c_runtime_sys.c:189-202` with real Win32 calls via `LoadLibraryA`/`GetProcAddress`. DISPLAY (comdlg32), DISPLAY BROWSE (shell32), MENU (user32), FONT (gdi32), ACCEL (user32).

4. **C compile expected-fails cleanup** — removed non-existent `x64_native_db.c` and `x86_template_encoder.c`. Fixed `runtime_xthread.c` by stripping a UTF-8 BOM from `core/include/c17/windows.h` (was emitting 3 unknown bytes to the lexer) and adding 4 missing Win32 decls. C compile: **63/63 with 0 expected fails**.

5. **float_ops.pb** (follow-up) — was the only remaining expected-fail after the sweep. Test now passes for real (exit=0) after the Z60 frontend work incidentally improved float IR handling. Removed from `$ExpectedLinkFails`. Link+Run (PB): **6/6 with 0 expected fails**.

### Z60 handler improvements (from prior sweeps)

- `pb_try_eval_expr()`: silent expression evaluator that falls back to `pb_find_var()` for identifiers, `pb_parse_i64_sv()` for integers, and quoted-string parsing for string literals — never emits diagnostics.
- DIALOG SHOW MODAL/END: real handler using `pb_find_var` + `ir_builder_emit_call`
- CONTROL ADD: real handler with class_text as string literal + `pb_try_eval_expr` for coordinates
- TCP/UDP/HOST: real handlers with `pb_try_eval_expr` for all args
- THREAD/XTHREAD: real handlers with thread-parameter parsing + `pb_try_eval_expr`
- COMM: real handler with multi-arg parsing + `pb_try_eval_expr`
- REGISTER KEY/SET/GET/CLOSE/DELETE: real handler with `pb_try_eval_expr`
- MOUSEPTR: real handler + `bestof_mouseptr` runtime (LoadCursor/SetCursor)
- PROCESS GET/SET PRIORITY: real handler + bestof_process_* runtime
- GUI NEW/MESSAGE LOOP: real handler using `bestof_graphics_create_window`
- XPRINT/LPRINT: real handlers with command dispatch + console fallback
- DISPLAY/FONT/ACCEL/MENU: real Win32 runtimes (comdlg32/user32/gdi32/shell32)
- GRAPHIC: all blocks use `pb_try_eval_expr` + direct kind checks (no `pb_value_require_*`)
- `LOCAL a, b, c AS LONG`: comma-split for shared-AS declarations
- `pb_parse_type_text`: truncate at comma for multi-variable declarations
- SPLIT delimiter extraction: fixed missing assignment when no USING clause
- ASM inline: stubbed to return ok instead of error
- `#COMPILE GUI`: handled like `#COMPILE EXE`

## Version validation

```text
PBXB64.exe --version
PBXB64 version 0.50.0-z64
```
answer.b64          PASS
call.b64            PASS
call_add.b64        PASS
comprehensive.b64   PASS
div_rem.b64         PASS
five_args.b64       PASS
global_data.b64     PASS
global_expr.b64     PASS
hello.b64           PASS
if_else.b64         PASS
loop_control.b64    PASS
params.b64          PASS
shift_count.b64     PASS
simple.b64          PASS
```

Result: **14/14 PASS**.

## Global initializer validation

Object inspection confirmed emitted bytes for B64 global data:

```text
global_data.b64: .data  = 2a 00 00 00 00 00 00 00
global_expr.b64: .rdata = 2a 00 00 00 00 00 00 00
```

Result: **PASS**.

## Windows lanes not executed in this container

The following are wired and should be run on a Windows/MinGW host:

```text
mingw32-make -f Makefile.mingw clean && mingw32-make -f Makefile.mingw -j4
mingw32-make -f Makefile.mingw smoke
coreuild_mingw64.bat clean && coreuild_mingw64.bat
core
un_pb_tests.ps1 -SkipBuild
```

They could not be executed here because the required Windows cross-toolchain/runtime was not installed.
