A self-hosting programming language with a native compilation pipeline.
Version 1.0.0 — The language is complete. The compiler is self-hosting. Native compilation via LLVM is working.
Krypton is a dynamically typed language with clean syntax, 147 built-in functions, and a compiler written in itself. It compiles to C for broad compatibility, and to native machine code via LLVM for maximum performance — no GCC in the critical path.
jxt {
k "stdlib/math_utils.k"
}
func fibonacci(n) {
if n <= 1 { emit n }
emit toInt(fibonacci(n - 1)) + toInt(fibonacci(n - 2)) + ""
}
just run {
kp(fibonacci("10"))
kp(isPrime("17"))
}
- GCC (or any C99 compiler) — for all platforms
- LLVM / clang (optional) — for native compilation via
build_llvm.bat/make native
git clone https://github.com/t3m3d/krypton
cd krypton
chmod +x build.sh
./build.shThis bootstraps a native kcc binary from source in four steps:
- Compiles the C interpreter (
archive/c/run.c) with GCC - Uses that interpreter to compile the self-hosting compiler (
kompiler/compile.k) to C - Compiles the resulting C to a fast native
kccbinary - Builds the IR optimizer and LLVM backend
Or use make:
make # build everything
make run F=hello.k # compile + run a file
make test # run the test suitegit clone https://github.com/t3m3d/krypton
cd krypton
build_v100.bat
Requires TDM-GCC. For native LLVM compilation:
winget install LLVM.LLVM
build_llvm.bat hello.k
// hello.k
just run {
kp("Hello from Krypton!")
}
Linux / macOS:
./kcc hello.k > hello.c
gcc hello.c -o hello -lm
./helloWindows:
kcc_v100.exe hello.k > hello.c
gcc hello.c -o hello.exe -lm
hello.exe
Linux / macOS:
make native F=hello.kWindows:
.\build_llvm.bat hello.k
hello_llvm.exe
let x = "42"
let name = "Krypton"
const pi = "3.14159"
All values are strings at runtime. Arithmetic auto-detects numeric strings.
let x: int = "42"
let name: string = "Krypton"
func add(a: int, b: int) -> int {
emit toInt(a) + toInt(b) + ""
}
Annotations are parsed and discarded — they document intent for humans and future tooling.
func greet(name) {
emit "Hello, " + name + "!"
}
just run {
kp(greet("World"))
}
emit (or return) returns a value. just run is the program entry point.
jxt {
k "stdlib/result.k"
k "stdlib/math_utils.k"
c "windows.h"
}
k— Krypton module (full source inlined at compile time)c— C header (emits#includein generated C)t— alias forc(family initial)
The legacy import keyword still works.
// Assign anonymous functions to variables
let double = func(x) { emit toInt(x) * 2 + "" }
let add = func(a, b) { emit toInt(a) + toInt(b) + "" }
kp(double("5")) // 10
kp(add("3", "4")) // 7
// Pass as arguments to higher-order functions
func applyTwice(f, x) { emit f(f(x)) }
kp(applyTwice(double, "3")) // 12
// Assign anonymous functions to variables
let double = func(x) { emit toInt(x) * 2 + "" }
let add = func(a, b) { emit toInt(a) + toInt(b) + "" }
kp(double("5")) // 10
kp(add("3", "4")) // 7
// Pass to higher-order functions
func applyTwice(f, x) { emit f(f(x)) }
kp(applyTwice(double, "3")) // 12
struct Point {
let x
let y
}
let p = Point { x: "10", y: "20" }
kp(p.x)
p.x = "42"
let name = "Krypton"
kp(`Hello, {name}!`)
kp(`1 + 1 = {1 + 1}`)
// if / else if / else
if x > 10 { kp("big") } else if x > 5 { kp("medium") } else { kp("small") }
// while
while i < 10 { i += 1 }
// for-in (comma-separated lists)
for item in "a,b,c" { kp(item) }
// match
match color {
"red" { kp("warm") }
"blue" { kp("cool") }
else { kp("other") }
}
// try / catch / throw
try {
throw "something went wrong"
} catch e {
kp("caught: " + e)
}
let result = fadd("3.14", "2.72")
kp(fformat(result, "2")) // "5.86"
Float builtins: fadd, fsub, fmul, fdiv, fsqrt, ffloor, fceil, fround, fformat, flt, fgt, feq
source.k
│
├─ C backend (default):
│ kcc source.k > source.c
│ gcc source.c -o source.exe -lm
│
└─ LLVM native backend:
.\build_llvm.bat source.k
source.k → .kir → .kir (opt) → .ll → .o → source_llvm.exe
kcc_v098.exe --ir source.k > source.kir
Emits .kir — a stack-based intermediate representation, one instruction per line:
FUNC add 2
PARAM a
PARAM b
LOCAL result
LOAD a
BUILTIN toInt 1
LOAD b
BUILTIN toInt 1
ADD
PUSH ""
ADD
RETURN
END
optimize.exe source.kir > source_opt.kir
Six passes: dead code elimination, constant folding, strength reduction, STORE/LOAD elimination, empty jump removal, unused local removal.
35 modules in stdlib/:
| Module | Contents |
|---|---|
math_utils.k |
gcd, lcm, isPrime, fibonacci, factorial, sqrt, abs, power |
result.k |
ok/err/isOk/isErr/unwrap/unwrapErr/unwrapOr |
option.k |
optSome/optNone/isSome/isNone/optUnwrap |
json.k |
jsonStr/jsonBool/jsonArray/jsonObject/jsonNull |
float_utils.k |
floatAdd/floatMul/floatSqrt/floatFormat/pi() |
string_utils.k |
String manipulation helpers |
list_utils.k |
List processing functions |
| ... | 29 more modules |
krypton/
├── kompiler/
│ ├── compile.k # Self-hosting compiler (3,567 lines)
│ ├── optimize.k # IR optimizer (348 lines)
│ ├── llvm.k # LLVM IR backend (437 lines)
│ └── run.k # Interpreter (2,092 lines)
├── runtime/
│ └── krypton_runtime.c # C runtime for LLVM-compiled programs
├── stdlib/ # 35 standard library modules
├── examples/ # Example programs
├── algorithms/ # Classic algorithm implementations
├── tutorial/ # Progressive tutorial
├── tests/ # Test suite
├── assets/ # Icon and Windows resource
├── versions/ # Bootstrap chain binaries
├── Spec.md # Language specification
├── CHANGELOG.md # Full version history
└── LICENSE # Apache 2.0
kcc (C++) → v010 → v020 → v030 → v040 → v050 → v060
→ v070 → v071 → v072 → v075 → v077 → v080
→ v085 → v086 → v090 → v095 → v097 → v098
Each version compiled by the previous. The compiler has been self-hosting since v0.1.0.
Seven headers ship in headers/:
| Header | Contents |
|---|---|
windows.krh |
Win32 system info, registry, console |
stdio.krh |
C stdio — printf, fopen, fread |
math.krh |
libm — sin, cos, sqrt, pow |
string.krh |
C strings — strlen, strcpy, strstr |
winsock.krh |
TCP/UDP networking (Winsock2) |
process.krh |
Process and thread management |
fileio.krh |
Windows file I/O — CreateFile, ReadFile |
Usage: import "headers/windows.krh" then call functions directly.
I/O, strings, math, lists, maps, structs, floats, exceptions, line operations, system, type utilities, StringBuilder — see Spec.md for the full reference.
Krypton — Copyright 2026 t3m3d — Apache 2.0