ExitCode + finalization execution + Halt semantics (unblocks the erroru test family)
- Type: feature (Track A core — Halt lowering, program epilogue, init/final ordering; the ExitCode symbol itself could live in builtinheap once the codegen reads it)
- Status: backlog
- Opened: 2026-07-14
- Found by: Track B FPC-conformance burn-down. Filed under A because every piece is codegen/parser, not RTL surface.
What FPC does (and the testsuite's erroru.pp depends on, in order)
ExitCode: Longintis a writable global in System scope.Halt(n)setsExitCode := n, then runs unit finalization sections (reverse init order), then terminates withExitCode.Halt(no arg) = terminate with currentExitCode; normal program end also exits withExitCode.- A finalization section may WRITE
ExitCode(erroru'serror_unit_exitchecks the recorded exit code against the accepted/required error number and then zeroes it, turning an expectedhalt(100)into process exit 0 — that is how everyaccept_error/require_errortest passes).
pxx today
- No
ExitCodesymbol at all (pascal26: undefined variable (exitcode)). initializationsections compile into__init_<unit>procs and run before main (ParseInitializationSection, parser.inc);finalizationbodies are token-skipped and never executed ({ 'finalization' + its body are skipped }).Halt(n)lowers straight to the exit syscall — no finalization pass.
Scope sketch
- Parse finalization like initialization into
__fini_<unit>procs; run them reverse-order from a common exit stub. - Route Halt(n) / Halt / falling-off-main through that stub: store n (if given) to ExitCode, run finis, exit(ExitCode). Guard against recursive Halt from inside a finalization (FPC keeps going with the new code).
erroru.ppadditionally wantserroraddr: Pointer(nil-able) andGetFPCHeapStatus/TFPCHeapstatus— stub-able, but out of scope here; the finalization/ExitCode machinery is the load-bearing part.
Unblocks (conformance skip list)
tstring2.pp, tstring5.pp, texception3.pp, tobject1.pp (partly — also
needs constructor fail), and every future erroru-using test the curated
categories pick up.