diff --git a/AGENTS.md b/AGENTS.md index e23523d..162daa9 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -36,6 +36,7 @@ r8forge_examples_test # 16 个 example + asm/test.r8asm, r8forge_macro_docs_test # 48 macros in 22 files r8forge_synth_test examples/full_add.r8asm # all eight combinations ok r8forge_derive verify_loop.r8asm -1 0=5 # out 5 0 +powershell -File tests\widths.ps1 # 位宽矩阵:每个位宽一套工具链 + 断言(约 20 分钟) ``` `asm/test.r8asm` 的纸带**必须留在 65536 条指令以下**(ROT-8-viz 的 `INS_SIZE`),所以里面 diff --git a/tests/widths.ps1 b/tests/widths.ps1 index 4dd68ae..1f62b61 100644 --- a/tests/widths.ps1 +++ b/tests/widths.ps1 @@ -1,48 +1,62 @@ -# Build the toolchain at a set of cell widths and run what is meaningful there. +# Build the toolchain at a set of cell widths and *check* what should hold there. # -# powershell -File tests\widths.ps1 # 1,2,7,8,11,16,17,31,32 -# powershell -File tests\widths.ps1 -Widths 8,11,32 # just these +# powershell -File tests\widths.ps1 # 7,8,11,16,17,31,32 +# powershell -File tests\widths.ps1 -Widths 11,16,32 # -# Per width: configure with -DR8FORGE_CELL_SIZE, build, run the `widthfree` ctest -# label (bit level slices, the synthesizer, the looping demo and the macro comment -# format -- all true at any width), then try one calculator session. The 11 bit -# baseline (byte_ops, examples, the flagship tape) only means anything at the -# default geometry, so it is not part of this script. -# -# Native commands report through $LASTEXITCODE, and their stderr must not be piped -# into the output stream: PowerShell turns that into an ErrorRecord. +# Per width, this asserts: +# * the `widthfree` ctest label passes (bit level slices, the synthesizer, the +# looping demo, the macro comment format); +# * examples/calc.r8asm assembles and `12 34 + .` prints D digits, where +# D = floor(W * 30103 / 100000) + 1 -- the same formula the library uses. A +# width that silently did not take effect fails this, because it would print +# four digits; +# * if the reference machine is built next door, it prints the same thing +# (`rot8_test --cell `), which is the three way check. +# Widths under 7 cannot hold '0' (48) in a cell, so they get the library tests +# only. +# A comma separated string rather than [int[]]: `powershell -File ... -Widths 11,16` +# binds as one string, and 11,16 would quietly become 1116. param( - [int[]]$Widths = @(1, 2, 7, 8, 11, 16, 17, 31, 32), + [string]$Widths = "7,8,11,16,17,31,32", [string]$CMake = "C:/Program Files/Microsoft Visual Studio/18/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/CMake/bin/cmake.exe" ) $ErrorActionPreference = "Continue" $root = Split-Path -Parent $PSScriptRoot $ctest = Join-Path (Split-Path $CMake) "ctest.exe" +$viz = Join-Path $root "..\ROT-8-viz\build\Release\rot8_test.exe" $failed = @() -foreach ($w in $Widths) { +foreach ($w in ($Widths.Split(",") | ForEach-Object { [int]$_.Trim() })) { $dir = Join-Path $root "build$w" - Write-Host "=== cell $w" + $d = [int][math]::Floor($w * 0.30103) + 1 + $nums = @(62, 32) + (@(48) * ($d - 2)) + @(52, 54) + @(10) + $want = "out " + ($nums -join " ") + Write-Host "=== cell $w (D = $d)" + & $CMake -S $root -B $dir "-DR8FORGE_CELL_SIZE=$w" 2>$null | Out-Null & $CMake --build $dir --config Release 2>$null | Out-Null - & $ctest --test-dir $dir -C Release -L widthfree 2>$null | Out-Null if ($LASTEXITCODE -ne 0) { Write-Host " widthfree tests FAILED"; $failed += $w } else { Write-Host " widthfree tests ok" } - # Tape lengths are the honest evidence that the width took effect: the - # flagship is full of %rep _CELL_SIZE, so it must grow with the width. $r8 = Join-Path $dir "Release\r8forge.exe" - $flagship = (& $r8 "asm/test.r8asm" --quiet 2>$null | Out-String).Length - Write-Host (" flagship tape: $flagship chars (11 bit: 64513)") - $derive = Join-Path $dir "Release\r8forge_derive.exe" - $calc = (& $r8 "examples/calc.r8asm" --quiet 2>$null | Out-String).Length - $out = & $derive "examples/calc.r8asm" 0 -i "12 34 + ." 2>$null | Out-String - if ($LASTEXITCODE -eq 0) { - Write-Host (" calc: $calc chars" + $(if ($calc -gt 65536) { " (over the viz limit)" } else { "" })) - Write-Host (" calc run: " + ($out.Trim() -replace '\s+', ' ')) - } else { Write-Host " calc: does not run at this width" } + $tape = (& $r8 "examples/calc.r8asm" --quiet 2>$null | Out-String).TrimEnd("`r", "`n") + Write-Host (" calc tape: " + $tape.Length + " chars") + + $got = (& $derive "examples/calc.r8asm" 0 -i "12 34 + ." 2>$null | Out-String).Trim() + if ($got -ne $want) { Write-Host " calc FAILED: want '$want' got '$got'"; $failed += $w } + else { Write-Host " calc ok: $want" } + + if (Test-Path $viz) { + $tmp = Join-Path $env:TEMP "calc$w.rot8" + [System.IO.File]::WriteAllText($tmp, $tape, (New-Object System.Text.UTF8Encoding($false))) + $serial = (& $viz "--cell" $w "--input" "12 34 + ." $tmp 2>$null | Out-String).Trim() + $wantSerial = "> " + ("0" * ($d - 2)) + "46" + if ($serial -ne $wantSerial) { Write-Host " viz FAILED: want '$wantSerial' got '$serial'"; $failed += $w } + else { Write-Host " viz ok: $wantSerial" } + Remove-Item $tmp -ErrorAction SilentlyContinue + } Remove-Item -Recurse -Force $dir }