Around all of it

AtlasLang

Build the whole thing, one stage at a time, from `print(1 + 2)` to a typed language with a bytecode VM, an SSA optimizer and a language server.

AtlasLang: The Whole Thing
▶ lab

From `print(1 + 2);` to a typed language with a bytecode VM, an SSA optimizer and a register allocator — twelve representations, all of them produced by a compiler in this repository that you can type into.

Q · What does it actually take to build a working language, end to end?
AtlasLang: The Lexer
▶ lab

Characters to tokens by maximal munch, with a half-open byte range on every token — and one hazard, `123abc`, that our lexer reports instead of silently splitting into two tokens and producing a parse error three lines away.

Q · How does AtlasLang decide where one token ends and the next begins?
AtlasLang: The Parser
▶ lab

Recursive descent for statements and Pratt parsing for expressions, in one file, so you can read the two techniques next to each other — plus panic-mode recovery that synchronizes on `;` and statement keywords instead of stopping at the first error.

Q · How does AtlasLang turn a flat token list into a tree, and how does it keep going after a syntax error?
AtlasLang: Evaluating the Tree Directly
▶ lab

The shortest path from a parsed program to a running one is to walk the tree and evaluate as you go. It is where most languages start, it is the version whose correctness is easiest to argue, and it is the version AtlasLang deliberately did not ship — for reasons worth knowing.

Q · What is the least machinery that will actually run a parsed program?
AtlasLang: Scopes, Shadowing and a Real Bug
▶ lab

An inner `let x` must not disturb an outer one. Our lowering keys storage slots by the resolved symbol rather than by the source name — because an earlier version keyed them by name, and the outer `x` was silently overwritten.

Q · What actually goes wrong if a compiler tracks variables by their names?
AtlasLang: Three Types and One Honest Limitation
▶ lab

`int`, `bool`, `str`; annotations optional on `let` and inferred from the initializer, required on parameters and returns. And a definite-return analysis so conservative it rejects `while (true) { return 1; }` — which is the cleanest example of soundness without completeness you will find.

Q · What can AtlasLang prove before running, and where does it give up on purpose?
AtlasLang: Bytecode and the Stack Machine
▶ lab

Twenty-three opcodes and an operand stack. A three-address instruction `%d = a op b` becomes "push a, push b, op", and every virtual register becomes a numbered local slot — which is the whole translation, and the whole argument for having had an IR first.

Q · What does an instruction set look like when you get to design it, and how does three-address IR become one?
AtlasLang: Eight Passes and Two Guards
▶ lab

Eight transformations over SSA, run to a fixed point, each carrying its legality precondition as data rather than as a comment. Two predicates do all the safety work: a `print` is never removed, and `x / 0` is never folded.

Q · Which optimizations does AtlasLang actually perform, and what stops each one from being a bug?
AtlasLang: What a Language Owes Its Users
▶ lab

A working compiler is the smaller half. Once people write programs in your language they need diagnostics that point at the mistake, a formatter that ends the argument, highlighting that is right about their code, and eventually a language server — because everything they use is going to want one.

Q · The compiler works. What else does a language need before anyone can use it?