A compiler small enough to read, written in itself.

mc compiles a schoolbook-C language — seven types, one opaque pointer, loop and if — into Mach-O for AArch64. A 2,846-line C23 seed is compiled by clang exactly once; after that mc compiles its own source, writes and signs the executable itself, and reaches a fixed point where one generation is byte-identical to the next. Everything the core leaves out — while, for, +=, a second backend, a whole object model — you teach it from ordinary mc source.

The whole idea, in one file

The core has no while. This program adds one, then uses it — the dotted underline marks every word that came from the surface rather than the core.

#include <sys>

// a statement the core does not have, taught in two lines
#rule stmt: while ( expr $c ) block $b
    => loop { if (!$c) break; $b }

i64 main(i64 argc, uptr argv) {
    i64 i = 0;
    while (i < 3) {
        write(1, "mc\n", 3);
        i = i + 1;
    }
    return 0;
}