pelagos · the open sea
Pelago
A self-hosting systems language.
Native code. No GC. No runtime.
fn main() {
print("Hello, world")
}
Hello, worldWhat it is
Pelago compiles to native code with its own backend. There is no garbage collector and no runtime to ship. Memory is safe through value semantics, not a borrow checker, and the syntax is braces and newlines with a TypeScript-like feel.
Value semantics
Values are read-only by default.
See itinoutandsinkare written at the call site as well, so a call shows what it changes or consumes.No exceptions, no null
Errors are
See itresultvalues, absence isoption, and?passes either one up.One
switchEnums, lists and guards go through one pattern match, and exhaustiveness is checked.
See itOverflow traps
Integer overflow stops the program instead of wrapping. The native backend keeps that exact behaviour and still measures against C.
BenchmarksIts own backend
x86-64 for Linux and Windows and AArch64, with no linker and no libc. The compiler is a single tool with a formatter and a language server inside.
Read the designSelf-hosting is the goal
The stage 0 compiler is written in Rust with no dependencies. The plan is to rewrite it in Pelago itself.
Source
A small program
This is real code from the repository. It type checks, runs in the interpreter and builds to a native executable. The website checks every example the same way before it is published.
#name and #(expr) put values into strings, //~ starts a doc comment, and for i of 1..=n loops over an inclusive range.
//~ Sum the squares of 1 to n.
fn sum_squares(n: int) -> int {
var total = 0
for i of 1..=n {
total += i * i
}
return total
}
fn main() {
const n = 10
print("sum of squares up to #n: #(sum_squares(n))")
}
sum of squares up to 10: 385Where it stands
Early, and honest about it. The stage 0 compiler handles the whole language: it checks types and value semantics, runs programs in an IR interpreter and builds native executables. A formatter and a language server exist. It is not yet rewritten in Pelago, real threads and async suspension are still open, and there are no prebuilt downloads yet, so you build from source.
Pelago is open source under MIT OR Apache-2.0.