|
- # E02-S02: build the lexer test PRG and a fresh D81 holding the fixtures.
- # The host reference lexer must reproduce tests/lexer/golden/*.tokens exactly;
- # -UpdateGolden rewrites them instead (review the diff before committing).
- [CmdletBinding()]
- param([switch]$UpdateGolden)
-
- $ErrorActionPreference = "Stop"
- $project = Split-Path $PSScriptRoot -Parent
- Import-Module (Join-Path $PSScriptRoot "lib\Nova128Test.psm1") -Force
- . (Join-Path $project "tests\lexer\reference-lexer.ps1")
-
- $out = Join-Path $project "build\lexer-test"
- $golden = Join-Path $project "tests\lexer\golden"
- New-Item -ItemType Directory -Force -Path $out, $golden | Out-Null
-
- # Order must match the FIXTURE list in tests/lexer/lexer-test.s.
- $grammar = Join-Path $project "tests\grammar"
- $fixtures = [ordered]@{
- "minimal.n8" = Join-Path $grammar "accepted\minimal.n8"
- "decls.n8" = Join-Path $grammar "accepted\decls.n8"
- "arrays.n8" = Join-Path $grammar "accepted\arrays.n8"
- "exprs.n8" = Join-Path $grammar "accepted\exprs.n8"
- "forward.n8" = Join-Path $grammar "accepted\forward.n8"
- "nulls.n8" = Join-Path $grammar "accepted\nulls.n8"
- "stmts.n8" = Join-Path $grammar "accepted\stmts.n8"
- "tokens.n8" = Join-Path $project "tests\lexer\tokens.n8"
- "errors.n8" = Join-Path $project "tests\lexer\errors.n8"
- "badchar.n8" = Join-Path $grammar "rejected\bad_char.n8"
- }
-
- $link = Invoke-Nova128Link -Name "lexer-test" -BuildDir $out `
- -Config (Join-Path $project "cfg\compiler.cfg") -Sources @(
- (Join-Path $project "src\compiler\mmu.s"),
- (Join-Path $project "src\compiler\diskio.s"),
- (Join-Path $project "src\compiler\source.s"),
- (Join-Path $project "src\compiler\lexer.s"),
- (Join-Path $project "tests\lexer\lexer-test.s"))
- if ((Get-Nova128Label $link.Labels "test_entry") -ne 0x1C0D) { throw "test_entry is not at `$1C0D" }
-
- $files = @(@{ Name = "lexer-test"; Path = $link.Program; Type = "prg" })
- $mismatch = @()
- foreach ($name in $fixtures.Keys) {
- $bytes = ConvertTo-Nova128Petscii (Get-Content -Raw -LiteralPath $fixtures[$name])
- $pet = Join-Path $out ($name -replace '\.n8$', '.pet')
- [IO.File]::WriteAllBytes($pet, $bytes)
- $files += @{ Name = $name; Path = $pet; Type = "seq" }
-
- $tokens = (Get-ReferenceTokens $bytes) -join "`n"
- $goldenPath = Join-Path $golden ($name -replace '\.n8$', '.tokens')
- if ($UpdateGolden) {
- [IO.File]::WriteAllText($goldenPath, $tokens + "`n")
- } elseif (-not (Test-Path -LiteralPath $goldenPath)) {
- $mismatch += "$name (no golden file; run with -UpdateGolden and review)"
- } elseif (([IO.File]::ReadAllText($goldenPath).TrimEnd("`n")) -ne $tokens) {
- $mismatch += "$name (reference lexer differs from golden)"
- }
- }
- if ($mismatch) { throw ("golden check failed:`n " + ($mismatch -join "`n ")) }
-
- $disk = Join-Path $out "lexer-test.d81"
- New-Nova128Disk -Path $disk -Files $files
- Write-Host ("built {0}" -f $link.Program)
- Write-Host ("disk {0} ({1} fixtures); reference lexer matches golden files" -f $disk, $fixtures.Count)
|