summary_step6.1.md 1.7 KB

V3 step 6.1 — built-ins for self-hosting (done 2026-09-22)

Closes the first gap measured against the compiler's own sources (they use INC/DEC/CHR/ORD/VAL/HIGH/LEN/SIZE/TSIZE). Suite 99/99. LL(1)-clean, zero gm2 warnings.

What was missing

A scan of SymTab.mod/QbeGen.mod showed CHR, ORD, VAL, INC, DEC, ABS were not implemented (HIGH/LEN/SIZE/ TSIZE/NEW/DISPOSE already were). Without these, the compiler cannot compile itself.

Added (grammar Fact / Statement)

  • CHR(x) → CHAR (x integer-family, else 211).
  • ORD(x) → INTEGER (x char/bool/enum/int-family, else 211).
  • VAL(T, x) → value of type T: allowed when source and target share a storage class (int/char/bool/enum → w, pointers/ADDRESS → l, REAL → d); the operand passes through unchanged. Cross-class reinterprets are 230 (VAL is a cast, not a conversion). Covers the compiler's VAL(INTEGER|CARDINAL, …).
  • ABS(x) → |x| for integer or REAL; new QbeGen.AbsQ (compare + negate-select branch).
  • INC(v [,step]) / DEC(v [,step]) as statements over an integer designator (var, VAR param, or indexed/field element); default step 1.

Test

t_builtins → 42: ORD('A'), INC/DEC with and without a step, CHR back to '>', ABS(-3.5), VAL(INTEGER, 0) / VAL(CARDINAL, 1).

Next self-hosting gaps

  • The syslib port: rewrite FileIO on SysIO/Storage, ban the gm2-only imports (Environment, FileSysOp, SysClock, ProgramArgs, TextIO, RawIO, WholeIO, IOChan).
  • LONGINT/LONGCARD true 64-bit values (currently aliases to w) — the compiler uses them for file sizes/positions.
  • VAL/CAST across storage classes; FLOAT/TRUNC; CAP.