The Kinglet programming language

A native language with explicit boundaries.

shape.kl
using io;

enum Shape {
  Circle(float),
  Rect(float, float),
}

float area(Shape s) {
  return s match {
    Shape::Circle(let r) => 3.14 * r * r,
    Shape::Rect(let w, let h) => w * h,
  };
}

int main() {
  Shape c = Shape::Circle(1.0);
  io::out.line(area(c));
  return 0;
}

Language

Four system concerns, expressed in the static structure.

Kinglet makes four questions visible in the program: what the code can do, who owns a resource, how an operation can fail, and whether every state has been handled.

Capability

Concepts describe the operations code requires. Concrete types are checked at compile time and specialized through monomorphization.

Ownership

Scalars, shared values, and resources follow distinct transfer rules. Resources use moves and explicit borrows to express lifetime responsibility.

Fallibility

Fallible conversions produce T?; ?: supplies a fallback, postfix ? propagates failure, and try / catch defines recovery.

Exhaustiveness

Postfix match destructures enums, structs, and arrays. The compiler checks state coverage for enums, booleans, and optionals.

In code

Failure is a value.

Nullable types, propagation with ?, and try / catch make error paths visible instead of implicit.

Explore the syntax →
read.kl
using io;

int? parse(string s) {
  return int(s)? * 10;
}

int main() {
  int? a = parse("42") ?: -1;
  io::out.line("a = {}", a);

  int n;
  try {
    n = int("bad")?;
  } catch (let ex: CastError) {
    n = -99;
  }
  io::out.line("n = {}", n);
  return 0;
}

Toolchain

One compiler, from source to a native executable.

The bootstrap compiler covers parsing, semantic checking, Kinglet IR, LLVM lowering, a small runtime, and the command-line driver — all in one binary.

01 · Source.kl
02 · CheckTypes & semantics
03 · LowerKinglet IR
04 · EmitNative binary

Get started

Install the toolchain and build your first program.

sh
curl -fsSL https://kinglet-lang.org/install.sh | sh