kinglet.lang

reference compiler · v0 in progress

A natively-compiled language exploring the C++ proposals that deserved a second life. Familiar semantics, distilled — proposal-inspired, not proposal-compatible.

$ curl -fsSL https://raw.githubusercontent.com/kinglet-lang/bootstrap/canon/scripts/install.sh | sh

macOS arm64  ·  Linux x64  ·  Windows x64  ·  installs to ~/.kinglet

about

The proposals that didn’t make it.

Kinglet takes the WG21 proposals that C++ deferred or rejected and gives them a second life — adapting syntax and semantics wherever adaptation makes the language smaller, clearer, or more coherent. It is proposal-inspired, not proposal-compatible.

Familiar territory underneath: structs, enums, monomorphized generics, pattern matching, and expression functions. The reference compiler is written in C++ — a handwritten lexer and parser, a type checker, a KIR middle-end, and an LLVM native backend.

It is early. The reference compiler is what you install today; a self-hosting native toolchain is the goal.

syntax

Familiar, with a few second lives.

C++-ish at the surface — braces, value semantics, fixed-width integers. Underneath sit the proposals that didn’t make it: concepts, uniform function call, tagged enums with pattern matching, nullable types with coalescing, and a pipe operator.

familiar.kl structs, monomorphized generics, expression functions
using io;

struct Box<T> {
  T value;
}

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

int main() {
  Box<int> bi { 42 };
  io::out("{}\n", identity<int>(99));
  return 0;
}
match.kl tagged enums + postfix pattern matching (P2688-style)
enum Shape {
  Circle(float),
  Rect(float, float),
  None,
}

float area(Shape s) {
  return s match {
    Shape::Circle(let r)      => 3.14 * r * r,
    Shape::Rect(let w, let h) => w * h,
    Shape::None               => 0.0,
  };
}
concepts.kl concepts + uniform function call syntax
concept Printable<T> {
  string to_string(T value);
}

string to_string(int v) {
  return "n";
}

int main() {
  int n = 42;
  string s = n.to_string();   // uniform function call
  return s.len();
}
errors.kl nullable T?, coalesce ?:, unwrap ?, try / catch
int? parse_int(string s) {
  return int(s)? * 10;
}

int main() {
  int? a = int("123") ?: -1;

  int n;
  try {
    n = int("bad")?;
  } catch (let ex: CastError) {
    n = -99;
  }
  return n;
}
types int · int8 16 32 64 · uint8 16 32 64 · float · float32 64 · double · bool · string · byte · char · void · auto
operators + - * / %   == != < > <= >=   && || !   & | ^ ~ << >>   |> pipe   ?: coalesce   ? unwrap   ::   =>
keywords if else for while guard · match let when · try catch · struct enum concept · using namespace pub import export · const · spawn select

Every snippet above is lifted from the compiler’s runnable test suite — nothing invented.

install

A few more knobs.

ecosystem

The four repositories.