Spec M1 — lexer, token table, Pratt, AST, dumps, constant-expression codegen

Scope: i64 main() { return 40 + 2; } compiles to .o, links and exits with 42. All of the front-end infrastructure and the back-end skeleton are born here in their final shape. Out of scope (M2+): variables, parameters, calls, if/loop, memory, globals, strings, #include.

Read all of docs/plan.md first. Files: stage0/lex.c, stage0/ast.c, stage0/parse.c, stage0/gen_arm64.c, stage0/main.c (rewrite; remove m0/m05), stage0/mc.h (extend), scripts/test.sh, tests/001-return42.mc, tests/002-arith.mc, tests/003-infix.mc. arena.c and macho.c already exist — use sec_new/sym_new/reloc_add/macho_write as they are.

CLI (main.c) #

mc0 [--dump-tokens|--dump-ast|--dump-asm] input.mc [-o output.o]. Default for -o: out.o. Errors: file:line: message on stderr, exit 1 (use die2; add helper err_at(line, msg)).

Lexer (lex.c) #

AST (ast.c) #

Parser (parse.c) #

Codegen (gen_arm64.c) #

Tests #

Acceptance (run for real and report the output) #

make stage0 && make stage0-san && make budget && make test green; build/mc0 --dump-tokens tests/001-return42.mc, --dump-ast, --dump-asm with stable output (run twice and diff).

Edit this page