Skip to content

Self-hosting progress — compiling Wyn with Wyn

The ultimate test of a programming language is whether it can compile itself. We're not there yet, but we're closer than you might think.

What works today

The self-hosted compiler has three components, all written in Wyn:

  1. Lexer (lexer.wyn) — tokenizes Wyn source code. Complete.
  2. Parser (parser.wyn) — recursive descent parser that builds a flat AST. Complete.
  3. Codegen (codegen.wyn) — takes the AST and emits C source code. Partial.

The codegen handles: integer/string/bool literals, identifiers, binary and unary operators, function calls, return statements, variable declarations, if statements, and while loops.

The bootstrap test

We have an end-to-end test that:

  1. Parses fn main() -> int { return 42 } using the Wyn parser
  2. Generates C code using the Wyn codegen
  3. Compiles the C with the system compiler
  4. Runs the binary and verifies it returns 42

This test passes. It's a small program, but it proves the pipeline works.

What's missing

To compile a real Wyn program (not just return 42), we need:

  • String support in codegen — string literals, concatenation, interpolation
  • For loops — the codegen handles while but not for..in
  • Struct support — struct definitions and field access
  • Module callsprintln(), File.read(), etc.

Each of these is a few hundred lines of Wyn code. The hard part (parser, AST representation, C emission framework) is done.

Why self-hosting matters

Self-hosting isn't just a flex. It proves:

  • The language is expressive enough for complex programs (a compiler is complex)
  • The standard library works for real I/O (reading files, writing output)
  • The type system handles real-world patterns (recursive data structures, generics)
  • The tooling works (you need a working compiler to compile the compiler)

Every bug we find while self-hosting is a bug our users would have found. Dogfooding at its most literal.

Timeline

We're targeting the wyncc hello.wyn milestone — the self-hosted compiler compiling a simple but real program — for v1.9. Full self-hosting (the compiler compiling itself) is a v2.0 goal.

If you want to follow along, the code is in wyn/self-hosted/src/. PRs welcome.

MIT License