On this page

0014. Carry M2 types into the temporary C backend

Context

M2 adds four static types and value-producing if before M3 replaces the AST-to-C path (ADR-0011). The emitter needs expression types for hoisted temporaries and printing. String views must preserve embedded NUL bytes.

Decision

Keep the AST plain. The checker returns function signatures and expression types/fallthrough keyed by source spans, consumed by the temporary emitter. Keep separate name-based scope stacks in resolution and types as planned.

Represent str as a pointer/byte-length pair referencing static literal bytes, passed and returned by value. Equality compares byte contents; there is no allocation or string construction. i64, bool and unit retain the bootstrap integer representation; unit is zero and is not printable.

Lower if through hoisted temporaries, omitting assignments on paths that return, break or continue. Its plain else block uses an expression wrapper. Blocks supply their final expression's value even with a trailing semicolon; function bodies still require explicit non-unit returns. Loops conservatively may finish for return-path analysis. Snapshot local reads because branches can now assign before a later operand or argument is evaluated. Source-loop labels preserve break/continue targets when an inner while's condition contains an if-expression controlling its enclosing loop.

Alternatives considered

Consequences

All four compile commands share one checked front end. The M1 program goldens keep their output. M3 replaces the span table and duplicated scope walks with IR IDs; M5 supplies constructed strings and their memory model.