Welcome to Kairo
Warning

The language reference describes Stage 1 Kairo, not the Stage 0 compiler. Stage 1 is still under development and the syntax and standard library may change before 1.0. The Stage 0 compiler is stable and can be used to build Kairo programs, but it does not yet support all Stage 1 features. 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. The Stage 1 compiler, written in Kairo, is the in-progress alpha compiler, and it cross-compiles to every curated sysroot target. See Implementation Status for the gaps. Stage 0, the original C++ implementation that transpiled Kairo to C++, is frozen and only kept to bootstrap Stage 1.

Language syntax and standard library APIs may change before 1.0. The documentation on this site reflects the current language design.


Next Steps