summary_step7.1.md 2.1 KB

V3 step 7.1 — self-hosted syslib: SysShim + FileIO (done 2026-09-22)

Follows the step-7 analysis. Rather than force one FileIO under two ABIs (host gm2 NUL-terminated strings vs V3 length-prefixed descriptors), this lands the self-hosted syslib the stage-2 compiler will link: runtime/syslib/SysShim + runtime/syslib/FileIO — V3-only, descriptor-aware, over the existing C shim. Suite 103/103.

runtime/syslib/SysShim

Descriptor-aware externals over shim.c: fopenread/fopenwrite (→ ADDRESS), fclose, fread (bulk, sets the buffer's length), fputc, fputs, fwriteln, fwriteintw, stdout/stderr (→ ADDRESS), arg (argv via /proc/self/cmdline). Statement-like operations are proper procedures (V3's 233 forbids function-as-statement); value-returning ones are functions.

runtime/syslib/FileIO

The compiler's FileIO subset, reimplemented over SysShim only: File = ADDRESS; Open/Close/ReadBytes/Write/WriteLn/ WriteString/WriteInt/WriteCard/NextParameter, plus SLENGTH/Assign/Extract/Concat/Compare and the classic constants. This is the stage-2 counterpart of the host FileIO used to bootstrap; the stage-1 gm2 build keeps the host library (the standard bootstrap split, as Blaise does with FPC).

Test

FioProg → 42: writes "hello\n" via the self-hosted FileIO, opens it for read, ReadBytes (which sets the buffer's length), and checks buf[0] = 'h' and length 6. Harness links shim.c.

Stage-2 port items found (Redux / ABI)

Compiling the compiler's own sources with V3 will also need:

  • Redux cleanups in those sources: 0C/15C/177C octal char-code literals → CHR(n) (V3 has no C suffix), and &/~/<> → AND/NOT/#.
  • A DEFINITION MODULE FOR "C" + EXPORT UNQUALIFIED V3 dialect only if a single FFI definition must also compile under gm2 (not needed for the current split).

Files

runtime/syslib/SysShim.def|.mod, runtime/syslib/FileIO.def|.mod, compiler/tests/fio_prog.mod, compiler/run_tests.sh. Step 7 remains "in progress": the compiler-source Redux sweep and the FileIO selection between stages are the remaining tasks.