kairolang/kairo 是一个托管在 GitHub 上的开源项目,主要使用 C++ 编写,采用 Other 许可证,目前获得 386 个 Star、4 次 Fork。
仓库全名
kairolang/kairo
README 摘要
The Kairo Programming Language Kairo is a statically typed compiled general purpose language, built for systems programming and high-performance applications. Designed with native bi-directional C++ interoperability in mind. Kairo aims to combine the power and control of low-level languages with the safety and clarity of high-level design. The goals of Kairo Safe, and productive programming language. Allow for…
Kairo is a statically typed compiled general purpose language, built for systems programming and high-performance applications. Designed with native bi-directional C++ interoperability in mind. Kairo aims to combine the power and control of low-level languages with the safety and clarity of high-level design.
The goals of Kairo
Safe, and productive programming language.
Allow for low-level programming with fine-grained control.
Native bidirectional C and C++ interoperability.
Include a portable, well-structured standard library.
Encourage clear, maintainable, and reviewable code through strong, expressive semantics.
An alternative to C, C++ or work alongside them.
No runtime, no garbage collector, no hidden costs - safety through visibility, not restriction.
Current Status
The Stage 1 compiler, written in Kairo, is fully self hosted (November 2026). A release build is bootstrapped by the previous release, and having a seed kairo compiler is a strict requirement. There’s a lit suite of about 2,000 tests. Releases ship prebuilt for 14 host platforms, and every one of them cross-compiles to 48 targets out of the box: Linux (glibc 2.17 to 2.42, and musl) on up to 19 architectures, Windows, macOS, FreeBSD, NetBSD and WebAssembly.
Warning 警告
The documentation covers the language as Stage 1 implements it, and the status page lists what is not built yet. The compiler is not ready for production use. If you want to help with documentation, please reach out to us on Discord
Why Kairo?
Think of programming languages like making coffee
C and C++ hands you all the ingredients and equipment, every knob and button live. No recipe, no instructions. You’ll have to learn and make something, what you make is on you.
Rust provides you with all the ingredients, fancy equipment, and a precise recipe with every step measured. The coffee comes out reliably good, and the recipe catches mistakes before you brew.
Kairo gives you ingredients, equipment, and recipes, and the kitchen is wired into the C and C++ kitchens next door. Borrow their beans and machines, and send finished coffee back through the same door.
Design Rationale
We liked the simplicity of Python’s syntax but wanted more.
We wanted the performance and control of C and C++.
We admired Rust’s safety features but, at times, found them cumbersome.
We liked Rust’s Meta-programming and Trait system.
We liked Zig’s approach to interoperability.
We wanted a powerful module system.
We wanted a robust standard library.
We wanted a language that would work drop-in with any existing C or C++ codebases.
We wanted all; So we created Kairo.
Kairo is built to slot directly into C and C++ ecosystems, offering a fresh syntax and features, without abandoning decades of code.
Example
This builds today with the Stage 1 compiler. Grab a prebuilt release with the one-line installer, or build from source; see Getting Started.
C++ includes a .k file directly. There is no generated header and no binding layer:
//> packet.k
import std::io::println
pub enum <T> Frame {
Burst { base: T, count: i32 },
Code { status: i32 },
Idle,
}
pub class Batch {
pub var frames: [Frame<i32>; 3]
pub var tag: i32? = null
pub fn Batch(self, a: i32, b: i32) {
self.frames = [
.Burst { base: a, count: 3 },
.Code { status: b },
.Idle
]
self.tag = a + b
}
@copy // marks this class as copyable
pub fn Batch(self, const other: Self) = default
pub fn score(const self) -> i32 {
return match self.frames[1] {
case .Code(const status) => match status {
case 200..=299 => 50
default => 10
} default => 0
} + (self.tag ?? 0)
}
pub fn op [] (self, idx: usize) -> *Frame<i32> {
return &self.frames[idx]
}
// Destructor: runs when the owning scope ends, C++ or Kairo.
fn op finally (self) {
println("[Kairo] ~Batch()")
}
}
pub fn sum_burst(f: Frame<i32>) -> i32 {
return match f {
case .Burst(const base, const count) => base * count
default => 0
}
}
kcc is a drop-in replacement for clang++ that takes Clang’s arguments. kairo is the Kairo compiler driver.
Where Kairo Semantics Differ from C and C++
These are legal C and C++ calls. clang++ accepts all three. Kairo rejects them:
The C code to copy into buf.c
//> buf.h
#pragma once
#include <stddef.h>
void buf_reserve(size_t n);
The Kairo code to copy into buf.k
//> buf.k
ffi "c" import "buf.h"
ffi "c++" import "vector"
fn grow(a: u32, b: u64, s: i32) {
buf_reserve(a) // ok: lossless on every 32/64-bit target
buf_reserve(b) // error: narrows on 32-bit targets
buf_reserve(s) // error: signed -> unsigned is never implicit
}
fn first(v: cxx::std::vector<i32>?) -> i32 {
return v.at(0) // error: 'v' may be null here
}
Getting Started
Download a release:curl -fsSL https://kairolang.org/install.sh | sh (Linux, macOS, BSD) or irm https://kairolang.org/install.ps1 | iex (Windows PowerShell), or grab an archive from the releases page.
Build from source: see BUILD.md - covers the quick install script, manual setup, PATH configuration, the VSCode extension, and debugging.
Read The Full Post Here. TLDR: Lang design, Compiler, and Architecture are 100% human. No AI was used for the core logic or passes in the compiler and language design. Docs have AI usage; mostly used for polishing.
Acknowledgements
We want to thank all our contributors pushing Kairo forward.
评论