Elba — A modern, statically-typed programming language with multiple compilation backends
As someone deeply interested in programming languages, compilers, and full-stack systems (yes, that’s me: a student, TypeScript/Zig/Rust dev), I’m excited to introduce Elba — a project I’ve been working on that brings together clarity, performance, and tooling in one language.
Note: I have no intentions yet on making this into a full project. Although I would continue working on this.
🚀 What is Elba?
Elba is a statically-typed programming language designed for clarity, performance, and developer productivity.
It offers:
- Static type checking with type inference — so you get all the safety of static typing without always writing verbose annotations.
- Generics — write reusable, type-safe code.
- Union types, optional types (
T?
) for null safety — fewer runtime surprises. - A module system, first-class functions, rich arrays, structs with methods.
- Multiple backends: AST interpreter for quick prototyping, IR interpreter for faster execution, a C code generator, and an LLVM backend for native performance.
- A standard library covering math, strings, and more.
In short: think “modern language with the expressiveness of high-level code” + “compiled speed” + “tooling and REPL to iterate fast”.
✨ Why build Elba?
Because I believe we can push the boundaries of what a new language can offer. Specifically:
- Type safety meets productivity: We want the benefits of static typing (fewer bugs) without getting bogged down in ceremony.
- Multiple backend flexibility: Sometimes you just want a quick REPL or interpreter; other times you need native speed. Elba gives you both.
- For compiler / language-enthusiasts: If you love messing around with languages, building tooling, or exploring alternative type systems (hello Zig and Rust fans), this is a playground.
- Modern developer experience: REPL, error-reporting, benchmarking, IR visualization — all included.
🛠️ Getting Started
Prerequisites
- Zig (version 0.15.2 or later)
- (Optional) LLVM 20 for native backend
- (Optional) GCC or Clang for C code generation
Build from source
You can follow the setup on the README.md
or below:
git clone https://github.com/OwenBellowen/elba.git
cd elba
zig build
./zig-out/bin/elba --version
Quick Test
./zig-out/bin/elba examples/hello_world.elba
./zig-out/bin/elba repl
Full documentation and more examples live in the examples/
directory and the repo’s docs.
💡 Example code snippet
Here’s a small example showing Elba’s generics + optional types:
// examples/generic_example.elba
fn swap<T>(a: T?, b: T?): (T?, T?) {
return (b, a)
}
struct Pair<T> {
first: T,
second: T,
fn new(f: T, s: T): Pair<T> {
return Pair { first: f, second: s }
}
fn swap(self): Pair<T> {
return Pair.new(self.second, self.first)
}
}
fn main() {
let maybeNum: i64? = 42
let maybeNil: i64? = null
let (x, y) = swap(maybeNum, maybeNil)
print("x = {x}, y = {y}")
let p = Pair.new("hello", "world")
let p2 = p.swap()
print("swapped: {p2.first}, {p2.second}")
}
Top comments (0)