Spec M9 — #rule (surface piece C) + lib/prelude.mc

Prerequisite: M7 closed (fixed point, golden recorded). This milestone changes stage0 and src/ (the mechanism costs twice), and ends with the fixed point re-verified.

Syntax (final; see docs/plan.md § Surface) #

#rule stmt: while ( expr $c ) block $b  =>  loop { if (!$c) break; $b }
#rule stmt: for ( stmt $init expr $cond ; expr $step ) block $b
    => { $init loop { if (!$cond) break; $b $step; } }
#rule stmt: ident $x += expr $e ;  =>  $x = $x + $e;
#rule stmt: ident $x ++ ;          =>  $x = $x + 1;

Semantics #

lib/prelude.mc #

#token "+=", "-=", "++", "--"; rules while, for, +=, -=, ++, --, until? (no), unless (no). Only what mc.mc itself will use. No struct in M9 — deferred to a possible M9.5 after measuring the cost; the plan called for it, but M6 showed that #define plus accessors work fine, and a real struct needs type $t and a layout, which is more than #rule delivers.

Stage0 (C) and src/ (.mc) #

Implement in stage0/parse.c (+ ast.c for gensym) and transliterate into src/parse.mc (+ ast.mc). Budget: ≤ 3000 lines in C (today 2500; target ≤ 2900). If it doesn't fit, cut --dump-rules first, then type $t.

Tests #

Edit this page