summary_lang-polish.md 2.2 KB

Step: language polish — enum literals + string equality

Tag v3-lang-polish. Suite 124/124; fixpoint OK (bootstrap/fixpoint.sh, image 2,070,109 bytes).

Enumerations usable everywhere

Previously an enumeration declaration parsed but use of any literal was error 230. Now:

  • Enum assigns each literal an ordinal 0, 1, … (QbeGen.IntStr → SymTab.SetSymVal) at declaration.
  • Design's constant branch accepts ClEnum and yields the ordinal as an immediate (GetSymVal + IsImm).
  • VAR/parameter declarations accept ClEnum; a designator of enum type loads/stores as a w.
  • Works in expressions, =/#/ordinal comparisons, CASE labels (labels are immediates), CONST initialisers, and as a value/parameter type (PROCEDURE Name(c : Color)).
  • OrdCheck/EqCheck already required the same enum type (no mixing distinct enums).

String equality = / #

  • SymTab.IsStrType/StrCompat: a string literal (ClStr) or a 1-D ARRAY OF CHAR is a "string" operand.
  • EqCheck now accepts two string-compatible operands (content equality); OrdCheck (< <= > >=) still rejects strings (213).
  • QbeGen.StrEq emits %t =w call $m2streq(l a, l b), negated with xor 1 for #.
  • shim.c: m2streq(a, b) — strcmp of the NUL-terminated contents.

Tests

  • t_enum.mod (exit 15): literal in comparison, CONST, CASE label, value parameter, ordinal ordering.
  • t_enumdecl.mod: was expect_fail "not supported yet"; now a run test (exit 0).
  • t_streq.mod (exit 15): ARRAY OF CHAR vs literal, literal vs literal, = and # (linked with the shim).

Still open (polish / next)

  • String concatenation +, LEN.
  • Strict 231 def/impl signature checks (types, not just arity).
  • UString whole-string assignment to a fixed array.
  • ProgramArgs / IOChan (shim m2argc/m2arg already exist).

Files

compiler/src/M2.atg (Enum ordinals; KindConst/VarDecl/Design ClEnum; the StrCompat branch in the rel codegen), compiler/src/SymTab.def/.mod (IsStrType/StrCompat, EqCheck), compiler/src/QbeGen.def/.mod (StrEq), runtime/syslib/shim.c (m2streq), compiler/run_tests.sh, compiler/tests/{t_enum,t_enumdecl,t_streq}.mod, docs/features.md.