Skip to content

kinglet-lang/bootstrap

Repository files navigation

Bootstrap (Ref) — C++ reference compiler for Kinglet: lexer, parser, checker, KIR middle-end, and LLVM native backend (enable_llvm=true). Language design, ADRs, self-host tests, and kinglet build live in kinglet-lang/kinglet; this repo is the bootstrap stage used until v0 native execution ships.

Kinglet

A natively-compiled language exploring the C++ proposals that deserved a second life.

Version CI License

Note

Familiar semantics. Curated ideas from WG21 proposals that were deferred or rejected. Kinglet is proposal-inspired, not proposal-compatible: it adapts syntax and semantics when that makes the language smaller, clearer, or more coherent.

Install

Download the latest release for your platform from Releases:

Platform Archive
Windows x64 kinglet-windows-x64.tar.gz
Linux x64 kinglet-linux-x64.tar.gz
macOS ARM64 kinglet-macos-arm64.tar.gz

Extract and add the directory to your PATH:

tar xzf kinglet-<platform>.tar.gz
# Add the extracted directory to PATH once (contains kinglet and a klet alias).

Release archives ship one kinglet binary. klet is a hard link (Windows/macOS/Linux) or symlink (Unix) to the same file — klet buildkinglet build. Only one directory needs to be on PATH. Do not use klet.cmd; if present from an older package, delete it and re-run scripts/stage-klet-alias.ps1 dist.

Editor extensions live in kinglet-lang/lsp (planned separate repo).

Build

gn gen out/Release --args='is_debug=false'
ninja -C out/Release
./out/Release/kinglet [--tokens | --ast | --ir | --native <out>] <file.kl>

Quick Example

using io;

struct Point {
  int x;
  int y;
}

struct Box<T> {
  T value;
}

T identity<T>(T x) => x;

int distance_sq(Point a, Point b) {
  int dx = a.x - b.x;
  int dy = a.y - b.y;
  return dx * dx + dy * dy;
}

int main() {
  Point origin { 0, 0 };
  Point target { 3, 4 };
  io::out("{}\n", distance_sq(origin, target)); // 25

  Box<int> bi { 42 };
  Box<string> bs { "hello" };
  io::out("{}\n", bi.value);            // 42
  io::out("{}\n", identity<string>("world")); // world

  // Mutation
  target.x = 6;
  target.y = 8;
  io::out("{}\n", distance_sq(origin, target)); // 100

  return 0;
}

Syntax

// Types
int x = 42;
double pi = 3.14;
string name = "kinglet";
bool flag = true;

// Dynamic arrays
int[] xs = [1, 2, 3];
xs[1] = 20;
int first = xs[0];

// Structs & Enums
struct Vec2 { int x; int y; }
enum Color { Red, Green, Blue, }
Vec2 v { 1, 2 };
Color c = Color::Red;

// Generics (monomorphized)
struct Pair<A, B> { A first; B second; }
T identity<T>(T x) => x;
Pair<int, string> p { 1, "one" };
int n = identity<int>(42);

// Control flow
if x > 0 { ... } else { ... }
while count > 0 { ... }
for (int i = 0; i < 10; i = i + 1) { ... }

// Pattern matching (P2688R5-style postfix match)
string r = value match {
  0 => "zero",
  1 => "one",
  let x if x > 50 => "big",
  _ => "other",
};

// I/O
using io;
io::out("{} + {} = {}\n", 1, 2, 3);
string line = io::in("prompt> ");

// Functions
int add(int a, int b) => a + b;
int factorial(int n) {
  if n <= 1 { return 1; }
  return n * factorial(n - 1);
}

Operators

+ - * / % == != < > <= >= && || ! ~

About

Kinglet bootstrap compiler (C++20): reference stage-zero, targeting native code via KIR + LLVM

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors