Goal: remove gm2-only imports from the compiler sources (FileIO on
SysIO/Storage). Attempting it exposed a fundamental bootstrap
conflict; this step lands the enablers, the measuring gate, and the
analysis that fixes the plan. Suite 102/102.
PROCEDURE P(a : ARRAY OF T)).
Previously 230; now supported (passed as a descriptor address,
no copy — same representation as VAR). Needed because the
compiler's own sources use value open arrays pervasively
(WriteString(s : ARRAY OF CHAR), etc.). Assignable gained
fixed-1D-array → open-formal compatibility. Tests: t_valopen
→ 15, t_openformal promoted to a run test.run_tests.sh: fails if SymTab/QbeGen/
driver/parser/scanner import Environment, FileSysOp, TextIO,
RawIO, WholeIO, IOChan, ProgramArgs. They do not. Only
FileIO remains (excluded, pending).FileIO is compiled twice, by two different compilers with two
different ABIs:
ARRAY OF CHAR is a NUL-terminated
C buffer; foreign procedures are declared
DEFINITION MODULE FOR "C" … EXPORT UNQUALIFIED name; … (verified
against the gm2 testsuite examples/callingC).ARRAY OF CHAR is our length-prefixed
descriptor (LONGCARD count + bytes), and foreign procedures
use PROCEDURE … ; EXTERNAL; (gm2 rejects that spelling).So one FileIO source cannot pass strings to one shim: gm2 hands the
shim a char* (NUL-terminated), V3 hands it a descriptor pointer.
The runtime/syslib shim's string functions (m2write, m2puts, …)
read the V3 descriptor layout, so they work for V3 programs but not
for gm2-compiled FileIO.
Make the foreign-call boundary NUL-terminated for both:
ARRAY OF
CHAR actual is passed to an EXTERNAL procedure (internal strings
stay length-prefixed — only the boundary copy gets a NUL).strlen-based (no count
header), so gm2 and V3 both work.runtime/syslib/SysShim.def (gm2 FOR "C" /
UNQUALIFIED) binds the raw shim, and V3 gains support for
DEFINITION MODULE FOR "C" + EXPORT UNQUALIFIED (its foreign
dialect), so the same SysShim.def compiles under both.FileIO is rewritten over SysShim (+ Storage), and the
gate is extended to cover it.EXTERNAL FFI spelling for gm2 is
DEFINITION MODULE FOR "C"; our PROCEDURE …; EXTERNAL; is
V3-only. This is the concrete grammar addition V3 needs next.l) handles, already the convention (step 5.4),
apply to any host resource.compiler/src/M2.atg (value open arrays), compiler/src/SymTab.mod
(assignability), compiler/run_tests.sh (gate), t_valopen,
t_openformal. Build/FileIO unchanged (restored gm2-hosted).