Features

Everything Krypton ships, organized so you can skim or dive in.

Native compilation pipeline

The default kcc.sh source.k invocation produces a native binary using a Krypton-only emitter. No C compiler or linker is invoked at user-call time on any of the three supported platforms.

source.k
    │
    ├─ Linux x86_64    source.k → .kir → optimize.k → elf.k → ELF binary
    │                   (direct syscalls, no libc, no linker)
    │
    ├─ Windows x86_64  source.k → .kir → optimize.k → x64.k → PE/COFF
    │                   (kernel32-only, ships krypton_rt.dll)
    │
    └─ macOS arm64     source.k → .kir → macho_arm64_self.k → Mach-O
                        (ad-hoc SHA-256 code signing, no clang/ld/codesign)

Each backend is written in Krypton itself — hand-rolled instruction encoding, Krypton-only string runtime, no LLVM, no GCC.

Language

Functions

func add(a, b) {
    emit a + b
}

Control flow

if x > 10 { kp("big") }
while i < 10 { i += 1 }
for item in "a,b,c" { kp(item) }

Structs

struct Point { let x; let y }
let p = Point { x: "10", y: "20" }
kp(p.x)

String interpolation

let name = "Krypton"
kp(`Hello, {name}!`)
kp(`1 + 1 = {1 + 1}`)

Pattern matching

match color {
    "red"  { kp("warm") }
    "blue" { kp("cool") }
    else   { kp("other") }
}

Try / catch / throw

try {
    throw "oops"
} catch e {
    kp("caught: " + e)
}

First-class lambdas

let dbl = func(x) { emit x * 2 }
func apply(f, x) { emit f(x) }
kp(apply(dbl, 5))   // 10

Booleans & truthiness

kp(true)         // "true"
if "0"     { } // never runs
if "hi"    { } // runs

Standard library

~150 built-in functions plus 36 stdlib modules, covering everything a real program needs:

I/O
print, kp, printErr, readFile, writeFile, arg, argCount, exit
Strings
len, substring, contains, startsWith, endsWith, replace, trim, toUpper, toLower, reverse, repeat
Numbers
toInt, parseInt, abs, pow, range, plus 64-bit + float ops
Lists & maps
split, length, sort, unique, slice, every, mapGet, mapSet, keys, values
Structs & env
structNew, getField, setField, hasField, structFields, envNew, envSet, envGet
StringBuilder
sbNew, sbAppend, sbToString — for efficient assembly without repeated concat
Modules
result, option, json, math_utils, list_utils, csv, queue, stack, set, sort, …
Algorithms
35 reference implementations — sorts, DP, graph, KMP, Dijkstra, union-find, …

Native performance

Direct syscalls (Linux)

The Linux backend issues SYS_write, SYS_mmap, and SYS_exit directly. No libc means no startup cost — hello.k compiles to a 2.6 KB static ELF.

Kernel32-only (Windows)

The Windows backend uses only kernel32.dll via a thin krypton_rt.dll shim — no MSVCRT, no .NET, no installer dependencies.

Smart-int values

Small integers live unboxed in registers; string pointers live above the 0x40000000 heap base. The runtime dispatches by value range, so 1 + 2 is two instructions.

Bump allocator

Heap is a single mmap’d region with a bump pointer. Allocation is one ADD; no malloc, no free-list traversal. Programs trade memory ceiling for predictable allocation cost.

Tooling

kcc

The compiler driver. kcc source.k emits a native binary by default. Opt-in flags: --c, --llvm, --ir.

VS Code extension

Syntax highlighting, bracket matching, comment toggling, code folding for .k files. Ships as a prebuilt .vsix in the repo.

build.sh / bootstrap.bat

One command, three platforms. Copies the prebuilt seed, smoke-tests via examples/fibonacci.k, and you’re done. ./build.sh test runs the full 38-test suite.

Header bindings (FFI)

29 .krh headers ship in headers/ — C stdlib, POSIX (unistd, pthread, sockets), and Windows API. import "headers/stdio.krh" gives you printf via the C-emit pipeline.

Platform support

Platform Backend Output Install
Linux x86_64 elf.k Static ELF, direct syscalls, no libc ./build.sh
Windows x86_64 x64.k PE/COFF, kernel32 only via krypton_rt.dll bootstrap.bat
macOS arm64 macho_arm64_self.k Mach-O with ad-hoc SHA-256 codesign ./build.sh
Linux ARM64 C path Via gcc/clang (native ARM64 backend planned) ./build.sh

Try it

Clone the repo and the build script does the rest — no external compiler required.

View on GitHub Browse Examples