# E02-S02: run the C128 lexer over every fixture in x128 and compare its token # dump with tests/lexer/golden/*.tokens (which the host reference lexer must # also reproduce; build-lexer-test.ps1 checks that first). [CmdletBinding()] param([int]$Port = 6532, [int]$TimeoutSeconds = 180) $ErrorActionPreference = "Stop" $project = Split-Path $PSScriptRoot -Parent Import-Module (Join-Path $PSScriptRoot "lib\Nova128Test.psm1") -Force . (Join-Path $project "tests\lexer\reference-lexer.ps1") & (Join-Path $PSScriptRoot "build-lexer-test.ps1") $out = Join-Path $project "build\lexer-test" $disk = Join-Path $out "lexer-test.d81" $screenshot = Join-Path $out "lexer-test-vicii.png" $names = @("minimal", "decls", "arrays", "exprs", "forward", "nulls", "stmts", "tokens", "errors", "badchar") $session = Start-Nova128X128 -Autostart $disk -Drive8Image $disk -Port $Port -Screenshot $screenshot try { $mb = Wait-Nova128Mailbox $session -TimeoutSeconds $TimeoutSeconds $address = $mb[8] + 256 * $mb[9] $length = $mb[10] + 256 * $mb[11] $dump = Read-Nova128Memory $session $address $length } finally { Stop-Nova128X128 $session } [IO.File]::WriteAllBytes((Join-Path $out "lexer-dump.bin"), $dump) $fixtures = ConvertFrom-TokenDump $dump $failures = @() if ($mb[3] -ne 0xA5) { $failures += "C128 reported FAIL (code `$" + $mb[4].ToString("X2") + ")" } if ($fixtures.Count -ne $names.Count) { $failures += "dump holds $($fixtures.Count) fixtures, expected $($names.Count)" } for ($i = 0; $i -lt $names.Count; $i++) { $name = $names[$i] $golden = (Get-Content -LiteralPath (Join-Path $project "tests\lexer\golden\$name.tokens")) | Where-Object { $_ -ne "" } $entry = $fixtures[$i] if ($null -eq $entry) { $failures += "${name}: missing from dump"; continue } if ($entry.Load -ne 0) { $failures += "${name}: src_load returned $($entry.Load)"; continue } $got = @($entry.Tokens) $diff = Compare-Object -ReferenceObject $golden -DifferenceObject $got -SyncWindow 0 if ($diff) { $first = 0 while ($first -lt [Math]::Min($golden.Count, $got.Count) -and $golden[$first] -eq $got[$first]) { $first++ } $failures += ("{0}: token {1} differs: golden '{2}' vs C128 '{3}' ({4} vs {5} tokens)" -f $name, ($first + 1), $golden[$first], $got[$first], $golden.Count, $got.Count) Write-Host (" {0,-8} {1,4} tokens FAIL" -f $name, $got.Count) } else { Write-Host (" {0,-8} {1,4} tokens match" -f $name, $got.Count) } } if ($failures) { throw ("lexer verification failed:`n " + ($failures -join "`n ")) } Write-Host ("verified C128 lexer: {0} fixtures, {1} dump bytes, all tokens match golden files" -f $names.Count, $length) Write-Host "screenshot: $screenshot"