The language reference describes Kairo as designed. The compiler (0.2.3) does not implement all of it yet, and the syntax and standard library may change before 1.0. See Implementation Status for what is not compiled yet.
Kairo
Kairo is an open-source, statically typed, compiled systems programming language with native bidirectional C++ interoperability. C++ projects can #include Kairo files directly. Kairo code calls C++ libraries without a binding layer. The compiler emits ABI-compatible object code that links with GCC, Clang, or MSVC output.
import std::io::println
ffi "c++" import "vector"
ffi "c" import "math.h"
fn main() {
var samples: cxx::std::vector<f64>
samples.push_back(4.0)
samples.push_back(9.0)
samples.push_back(16.0)
println(f"{samples.size()} samples")
for x in samples {
println(f"sqrt({x}) = {sqrt(x)}")
}
}
Why Kairo
Full control, less friction. Kairo gives you manual memory management, raw pointer access, struct layout control, and zero-cost abstractions, with a compiler that tracks lifetimes, promotes smart pointers, and catches null dereferences at compile time. You opt into safety by default and opt out explicitly when you need to.
C++ interop that works both ways. ffi "c++" imports C++ headers and makes every declaration available as a native Kairo symbol. The kcc driver lets C++ code #include "file.k" with no code generation step. Templates, concepts, classes, and smart pointers cross the boundary cleanly.
Zero-cost abstractions. Interfaces are structural and carry no vtable. Generics are monomorphized. Panic handling compiles to tagged returns and branches: no unwinding tables, no runtime. Virtual dispatch exists only when you write virtual.
At a Glance
import std::io::println
ffi "c" import "math.h"
struct Point {
var x: f64; var y: f64; // semi-colons are optional!
}
extend Point {
fn length(const self) -> f64 {
return sqrt(self.x * self.x + self.y * self.y) // C's sqrt, called directly
}
fn op +(const self, const other: Point) -> Point {
return Point { x: self.x + other.x, y: self.y + other.y }
}
}
enum Shape {
Circle { radius: f64 },
Rect { width: f64, height: f64 },
Empty,
}
interface HasArea { // structural: Shape satisfies it just by having area()
fn area(const self) -> f64
}
extend Shape {
fn area(const self) -> f64 {
match self {
case .Circle(var radius) { return 3.14159 * radius * radius }
case .Rect(var width, var height) { return width * height }
case .Empty { return 0.0 }
}
}
}
fn <T impl HasArea> describe(const item: T) -> string {
return f"area {item.area()}"
}
enum Setting { Port, Host, Timeout } // closed: only these three values exist
extend Setting {
fn name(const self) -> string {
match self {
case .Port { return "port" }
case .Host { return "host" }
case .Timeout { return "timeout" }
}
}
}
fn lookup(key: Setting) -> i32? {
match key { // every variant covered, so no default arm
case .Port { return 8080 }
case .Timeout { return 30 }
case .Host { return null }
}
}
struct Missing {
var key: Setting
fn op panic (const self) -> string { return f"{self.key.name()} is not set" }
}
fn require(key: Setting) panic -> i32 {
var value? = lookup(key)
if !value? {
panic Missing { key: key }
}
return value // narrowed: value is a plain i32 here
}
fn main() {
var a = Point { x: 3.0, y: 4.0 }
var b = Point { x: 1.0, y: 2.0 }
println(f"sum length: {(a + b).length()}")
println(describe(Shape::Rect { width: 2.0, height: 3.0 }))
try {
println(f"port: {require(.Port)}")
println(f"host: {require(.Host)}")
} catch e: Missing {
println(f"missing: {e.key.name()}")
}
}
Status
Kairo is in active development. Version 0.2.3 is the third self-hosted release: the compiler is written in Kairo, compiles itself, and cross-compiles to 48 targets, building each target's sysroot the first time you use it. Prebuilt packages exist for Linux, macOS, Windows, FreeBSD and NetBSD (see Installation). See Implementation Status for the gaps. The original C++ implementation, Stage 0, which transpiled Kairo to C++, is retired.
Language syntax and standard library APIs may change before 1.0. The documentation on this site reflects the current language design.
Next Steps
- Philosophy: understand the design principles
- Primitives: start with the type system
- Classes: objects, inheritance, virtual dispatch
- C/C++ Interop: calling C++ from Kairo and back
- Example: HTTP Server: a complete project walkthrough