simplified
AtlasLang
A small language with a complete compiler: a lexer with spans, a Pratt parser with error recovery, a type checker with inference, SSA over dominance frontiers, an optimizer with legality preconditions, a graph-colouring register allocator, an x86-64-flavoured backend and a stack VM. Type anything and watch all of it.
The language, in full
let x = 1; // inferred int
let y: bool = x > 0; // annotated
x = x + 1; // assignment
if (y) { print(x); } else { print(0); }
while (x < 10) { x = x + 1; }
fn add(a: int, b: int): int { return a + b; }
print(add(x, 2));
// types: int, bool, str operators: + - * / % == != < <= > >= && || !
// comments: // line, /* block */AtlasLang source
Examples
Function shown in the IR panels
✓ No diagnostics. The program lexes, parses and type-checks.
halted
The program ran to completion.
157 instructions executed · first 156 traced
Output
22
1 / 156main:0 PUSH 2
Operand stack (top last)
2
Locals
Call stack
- main
IR — main
fn main(): void {
b0: ; entry
%0 = int 2 * 3
%1 = int 1 + %0
store @x, %1
store @n, 0
jump b1
b1: ; while.cond preds=b0,b6
%2 = load @n
%3 = bool %2 < 3
branch %3 ? b2 : b3
b2: ; while.body preds=b1
%4 = load @n
%5 = bool %4 == 1
branch %5 ? b4 : b5
b3: ; while.exit preds=b1
%12 = load @x
%13 = load @n
%14 = call add(%12, %13)
print %14
ret
b4: ; if.then preds=b2
%6 = load @x
%7 = int %6 + 10
store @x, %7
jump b6
b5: ; if.else preds=b2
%8 = load @x
%9 = int %8 + 1
store @x, %9
jump b6
b6: ; if.join preds=b4,b5
%10 = load @n
%11 = int %10 + 1
store @n, %11
jump b1
}Optimized SSA — 3 phis
fn main(): void {
b0: ; entry
jump b1
b1: ; while.cond preds=b0,b6
%15 = phi n [0 from b0, %11 from b6]
%16 = phi x [7 from b0, %17 from b6]
%3 = bool %15 < 3
branch %3 ? b2 : b3
b2: ; while.body preds=b1
%5 = bool %15 == 1
branch %5 ? b4 : b5
b3: ; while.exit preds=b1
%14 = call add(%16, %15)
print %14
ret
b4: ; if.then preds=b2
%7 = int %16 + 10
jump b6
b5: ; if.else preds=b2
%9 = int %16 + 1
jump b6
b6: ; if.join preds=b4,b5
%17 = phi x [%7 from b4, %9 from b5]
%11 = int %15 + 1
jump b1
}