Skip to content

Repository files navigation

Ember

A small, fast, bytecode-compiled programming language implemented from scratch in modern C++20 — lexer, Pratt parser, single-pass compiler, stack VM with closures, and a precise mark-sweep garbage collector. Verified by differential fuzzing against a Python reference and benchmarked with Google Benchmark.

let fib = fn(n) { if n < 2 { return n } return fib(n-1) + fib(n-2) }

print(fib(30)) // 832040

let make_counter = fn() { let c = 0 return fn() { c = c + 1 return c } }

let next = make_counter()

print(next()) print(next()) // 1 2

Quickstart

git clone https://github.com//ember && cd ember

cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release && cmake --build build

./build/ember examples/fib.ember # run a file

./build/ember # start the REPL

./build/ember --dump examples/fib.ember # inspect bytecode

Why it's interesting

  • Real closures with open/closed upvalues (not just first-class functions)
  • Precise mark-sweep GC with a self-tuning trigger; ASan/UBSan clean under stress-GC
  • Computed-goto dispatch — ~10–15% faster than a switch loop, ~3x over a tree-walker
  • Differential fuzzing: 100K+ random programs byte-identical to a Python reference

Benchmarks (Release, GCC 13, i7-1260P)

Workload Time Note
fib(30) 41 ms recursion through real call frames
1e6-iteration loop 8.7 ms integer arithmetic
100K closure allocations 12.4 ms GC churn
GC pause p99 (1M-object heap) 1.42 ms HDR histogram

Architecture

source -> Lexer -> Pratt Parser -> Compiler -> Bytecode Chunk -> Stack VM

(tokens) (AST) (single pass) (flat uint8) (computed goto)

precise mark-sweep GC

Docs

License

MIT — see LICENSE.

About

A tiny dynamically-typed language that runs its own bytecode. C++20 lexer, Pratt parser, stack VM, tri-color mark sweep GC

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages