v1.0.0 Released

Built for systems.

Reduce cognitive noise without reducing power. Krait combines the elegant, indentation-based readability of Python with the raw execution speed and control of C and Rust.

Uncompromised Architecture

Krait is fundamentally designed from the ground up to solve modern engineering hurdles, balancing performance with an unparalleled developer experience.

Zero-Cost Memory Safety

No garbage collector. Krait implements a strict compile-time Ownership Memory Model. Move semantics and auto-drop deallocations guarantee absolute memory safety without runtime overhead.

True Native Speed

Links directly to your native system toolchain. Utilizing an optimized LLVM-IR backend, Krait automatically applies link-time optimizations and -O3 passes for blazing-fast execution.

Vibe-Coder Ready

Engineered for AI-assisted workflows. Emits actionable, beautifully formatted diagnostics that clearly explain bugs and offer precise resolutions. Integrated krait fmt standardizes output effortlessly.

What You Can Create with Krait

Leverage true native compilation via LLVM and a zero-cost memory model to build performance-critical targets across the modern software stack.

Standalone CLI Tools

Scaffold instant command line setups using krait new project_name. Compile into compact, zero-dependency native binaries that launch immediately with no runtime overhead or heavy distribution containers.

Systems Core Engines

Construct underlying applications requiring absolute memory control and high-performance determinism. Enforce strict safety parameters utilizing compile-time move mechanics instead of relying on a garbage collector.

AI-Optimized Workflows

Deploy lightweight software components with clean, minimal punctuation that aligns perfectly with context windows. Read actionable compiler diagnostics engineered explicitly for LLM interaction and quick code refinement.

Syntactic Clarity, Bare-Metal Performance

Express production-ready program logic without cluttering your workspace with manual allocations or lifetime annotations.

examples/math_operations.kr
# Clean syntax, native types, and standard library imports
import math

# Compute operations cleanly with automatic type inference
set input_val = abs(0 - 42)
set output_pow = power(2, 10)

show input_val   # Output: 42
show output_pow  # Output: 1024
examples/control_flow.kr
# Define clear functions using standard indentation rules
make evaluate_bounds(value)
    when value < 0
        return 0 - 1
    when value > 100
        return 1
    return 0

set calculation = evaluate_bounds(150)
show calculation  # Output: 1

Architecture & Roadmap

With the release of v1.0.0, Krait's initial vision is fully realized, providing a robust foundation for systems programming.

Phase 1: Prototype Engine

Lexer, Parser, Abstract Syntax Tree generation, and a basic Tree-Walking Interpreter.

Phase 2: Compiler Backend

LLVM Text IR Generation, Native System Linking, and Advanced Compile-time Type Inference.

Phase 3: Ownership & Auto-Drop

Compile-time Move analysis and Scope-based stack deallocations to prevent memory leaks automatically.

Phase 4: Ecosystem & Tooling

Interactive REPL, built-in Project Manager, Actionable Diagnostics, standard math/io libraries, and unified code formatting.

Complete Toolchain

Interactive Shell (REPL)

A stand-alone interpreter for fast prototyping and instant calculation without the compilation toolchain.

Built-in Scaffolding

Run krait new project_name to instantly scaffold directories, or krait build for hardware executables.

VS Code Integration

Premium syntax highlighting and language support built directly into the official VS Code extension.

Try the Playground

Experiment with Krait directly in your browser before installing. No setup required.

Open Source Community

View the full compiler source code on GitHub. Contributions to the standard modules, core infrastructure, and ecosystem extensions are highly encouraged.

View GitHub

Krait Playground

Write, edit, and run Krait code directly in your browser. Experiment with the language in a simulated LLVM-IR compilation environment.

editor — test_math.kr
Compiler Output
krait> Press "Run Code" to compile...

Learn Krait

A comprehensive, progressive tutorial covering everything from your first line of code to mastering the zero-cost ownership memory model.

Getting Started

What is Krait?

Krait is a fast, memory-safe, compiled systems programming language designed under the philosophy "Reduce cognitive noise without reducing power." It combines the clean, indentation-based syntax of Python with the raw execution speed and compile-time memory safety of C and Rust.

Unlike Python, Krait compiles to native machine code via an LLVM-IR backend — meaning your code runs at the same speed as hand-written C. Unlike Rust, Krait hides lifetime annotations and borrow-checker complexity behind an implicit, zero-noise ownership model.

Installation

You do not need Cargo, Rust, or any build toolchain to install Krait. Install the pre-compiled binary directly via automated inline scripts:

Windows (PowerShell)
irm https://raw.githubusercontent.com/skiLLM-Labs/Krait/refs/heads/main/install.ps1 | iex
Windows (Command Prompt)
curl -sL https://raw.githubusercontent.com/skiLLM-Labs/Krait/refs/heads/main/install.bat | cmd
macOS / Linux (Bash)
curl -fsSL https://raw.githubusercontent.com/skiLLM-Labs/Krait/refs/heads/main/install.sh | bash
Note: The Krait Interpreter (krait run) is completely standalone. However, using krait build to generate optimized native executables requires clang to be installed on your system PATH.

Hello World

Create a file called hello.kr and add the following code:

hello.kr
import io

# Print "Hi" using ASCII codes
putchar(72)   # H
putchar(105)  # i
putchar(10)   # newline

Run it with the interpreter:

Terminal
$ krait run hello.kr
Hi

Or compile it to a native binary:

Terminal
$ krait build hello.kr
$ ./hello
Hi

Project Scaffolding

For larger projects, use the built-in scaffolding tool:

Terminal
$ krait new my_app
$ cd my_app
$ krait run src/main.kr

This creates the following directory structure:

Project Structure
my_app/
├── krait.toml       # Package metadata and dependencies
└── src/
    └── main.kr      # Code entry point

The Interactive REPL

Krait ships with a full interactive shell for fast prototyping. Just run krait with no arguments:

Terminal
$ krait
Krait 1.0.0 Interactive Shell
Type 'exit' to quit.

>>> set greeting = "Hello, Krait!"
>>> show greeting
"Hello, Krait!"

Variables & Types

The set Keyword

All variables in Krait are declared using the set keyword. Unlike most systems languages, you never write explicit type annotations — the compiler infers them statically at compile time from the value assigned.

variables.kr
# Implicit type inference — clean and noise-free
set age = 21          # Infers Int (64-bit signed)
set price = 19.99     # Infers Float (64-bit)
set name = "Alice"    # Infers Str (UTF-8)
set active = true     # Infers Bool

Primitive Types

Krait is a statically typed language — every variable's type is fixed at compile time. The compiler supports five primitive types:

Type Description Example
Int 64-bit signed integer 42, 0 - 5
Float 64-bit floating-point number 3.14, 1.0
Str UTF-8 encoded string literal "hello", "Krait"
Bool Boolean truth value true, false
Void Absence of a value Implicit in side-effect functions

Reassignment Rules

Once a variable has been declared with a specific type, its type is permanently fixed. You can reassign it to a new value of the same type, but attempting to change its type will trigger a compile-time error:

reassignment.kr
set age = 21       # Int
set age = 22       # ✓ Valid: still an Int

# set age = "twenty"  ← COMPILE ERROR!
# Cannot reassign Int variable to Str.

There is no implicit type coercion in Krait. Integer and float operations cannot be mixed. This strictness eliminates an entire class of subtle numeric bugs at compile time.

Functions

The make Keyword

Functions are defined using the make keyword followed by the function name, parameters in parentheses, and an indented body block. Parameter types and return types are inferred from usage — you never write type annotations on function signatures.

functions.kr
make calculate_area(width, height)
    return width * height

set area = calculate_area(10, 5)
show area  # 50

Return Values

Functions return values using the return keyword. If no return is provided, the function returns Void implicitly. Early returns are fully supported and are a key pattern for conditional logic.

Recursion

Krait compiles recursive function calls efficiently. The classic Fibonacci example demonstrates recursion with conditional branching:

fibonacci.kr
make fib(n)
    when n < 2
        return n
    return fib(n - 1) + fib(n - 2)

set result = fib(10)
show result # 55

Real-World Example: Calculator

Here's a more complex example showing multiple functions, conditional dispatch, and standard library usage:

calculator.kr
import math

make calculate(op, a, b)
    when op == 1
        return a + b
    when op == 2
        return a - b
    when op == 3
        return a * b
    when op == 4
        return a / b
    when op == 5
        return power(a, b)
    when op == 6
        return abs(a)
    return 0

set r1 = calculate(1, 120, 80)
show r1  # 200
set r2 = calculate(5, 3, 6)
show r2  # 729

Control Flow

Conditionals: when

Krait uses the when keyword for conditional branching. The condition expression must evaluate to a Bool type. There is no else or elif keyword — instead, use sequential when checks or early return statements to structure your logic.

conditionals.kr
make sign_of(n)
    when n < 0
        return 0 - 1
    when n > 0
        return 1
    return 0

show sign_of(42)     # 1
show sign_of(0 - 7)  # -1
show sign_of(0)      # 0
Why no else? Krait's design philosophy prioritizes explicitness. Sequential when checks make every branch visually distinct and independently readable — reducing cognitive noise in complex conditional trees.

Loops: repeat

The repeat block executes its body a specific number of times. The syntax is repeat N times where N is any integer expression. There is no for or while keyword.

loops.kr
make power(base, exp)
    set result = 1
    repeat exp times
        set result = result * base
    return result

show power(2, 10) # 1024
show power(3, 6)  # 729

The compiler generates optimal LLVM loop structures with duplicate alloca elimination for clean variable reassignment inside nested loop scopes.

Structs

Defining Structs

Custom data structures in Krait are defined using make followed by the struct name (no parentheses) and an indented list of fields with their default values:

structs.kr
make Point
    x = 0
    y = 0

Instantiation with new

Create struct instances using the new keyword. This allocates the struct on the heap and returns a pointer to it. The pointer is managed by Krait's ownership system (see Chapter 7).

struct_usage.kr
make Point
    x = 0
    y = 0

set p = new Point
set p.x = 100
set p.y = 200
show p.x  # 100
show p.y  # 200

Field Access

Read and write field values using the dot (.) operator. Field types are inferred from their default values in the struct definition. Once a field has a type, it follows the same strict reassignment rules as variables.

Heap vs. Stack: Primitives (Int, Float, Bool, Str) are stored on the stack and copied by value. Struct instances created with new live on the heap and are subject to ownership rules.

Modules & Imports

The import Statement

Krait supports a modern module system for code organization. The import module_name command looks up the file lib/module_name.kr relative to the build path. The compiler parses the imported module's AST and merges it into your application namespace before semantic analysis or LLVM-IR generation.

imports.kr
import math
import io

# Use functions from lib/math.kr
set p = power(2, 8)
show p  # 256

# Use functions from lib/io.kr
putchar(75)  # Prints "K"
putchar(10)  # Newline

Standard Library: math

The math module provides high-performance, pure Krait math functions:

  • abs(n) — Returns the absolute value of integer n
  • power(base, exp) — Computes base^exp using an optimized native loop

Standard Library: io

The io module exposes system I/O through the C FFI:

  • putchar(char_code) — Writes a single character to stdout by its ASCII integer code

Standard Library Source

Krait's standard library is itself written in Krait (with FFI where needed). Here is the complete math module source:

lib/math.kr
# Krait Standard Math Module

make abs(n)
    when n < 0
        return 0 - n
    return n

make power(base, exp)
    set result = 1
    repeat exp times
        set result = result * base
    return result

And the io module — a single FFI extern declaration:

lib/io.kr
extern make putchar(c)

Memory & Ownership

The Core Problem

High-performance languages manage memory in one of three ways:

  1. Manual Allocation (C/C++) — Fast, but prone to memory leaks, double-frees, and use-after-free segfaults.
  2. Garbage Collection (Python/Java/Go) — Safe, but introduces runtime overhead, high memory usage, and unpredictable "stop-the-world" pauses.
  3. Static Borrow Checker (Rust) — Safe and fast, but adds complex syntax, lifetime annotations, and high cognitive noise.

Krait's solution: A clean, zero-noise compile-time ownership tracker. The compiler enforces strict safety during compilation and inserts deallocation code automatically — hiding the complexity entirely from the programmer.

The Three Rules of Ownership

1
Owner Scope

Every heap-allocated struct instance (created via new) is owned by exactly one variable at any point in time.

2
Move Semantics

Assigning a struct variable to another variable transfers (moves) ownership. The original variable becomes immediately invalid and cannot be used again.

3
Auto-Drop

When a variable owning a heap resource exits its declared scope, the compiler automatically inserts a native free instruction to deallocate the memory.

Move Semantics in Action

When you assign a struct variable to another, the underlying heap pointer is transferred — not copied:

ownership.kr
make Point
    x = 0
    y = 0

# p1 owns the Point allocation
set p1 = new Point
set p1.x = 100

# Ownership moves from p1 → p2
set p2 = p1

show p2.x  # 100 ✓ (p2 now owns it)

Compile-Time Safety

If you attempt to access a moved variable, the Krait compiler catches this at compile time — not at runtime:

ownership_error.kr
set p1 = new Point
set p2 = p1  # Ownership moved to p2

show p1.x    # ❌ COMPILE ERROR!

The compiler emits a clear, actionable diagnostic:

Compiler Output
 [KRAiT OWNERSHiP ERROR]
 Variable: 'p1'
 Issue   : The variable 'p1' was moved and is
           no longer valid in this scope.

 How to resolve:
 1. Avoid using 'p1' after it has been moved.
 2. Duplicate the data or reorganize your code
    to assign only when done using 'p1'.

Auto-Drop in Action

You never call free manually. The compiler tracks the lifetime of heap owners and automatically inserts native @free calls when a variable goes out of scope:

auto_drop.kr
make create_and_use()
    set temp = new Point
    set temp.x = 42
    return temp.x
    # temp is automatically freed here!
    # Compiler inserts: free(temp)

show create_and_use() # 42

This guarantees: zero memory leaks (freed immediately when unneeded), zero double-frees (compiler invalidates moved variables), and optimal memory layouts (clean register utilization, minimal heap fragmentation).

Documentation

Complete language reference, standard library API, memory model specification, and tooling guide. Designed for both humans and LLMs.

Keywords Reference

Krait has a minimal set of reserved keywords. Every keyword has exactly one purpose, eliminating ambiguity for both human readers and LLMs.

Keyword Purpose Context
set Declare or reassign a variable set x = 42
make Define a function or struct make add(a, b)
when Conditional branch (must eval to Bool) when x > 0
repeat Loop a fixed number of times repeat 10 times
times Loop count terminator repeat n times
return Return a value from a function return result
show Print an integer value to stdout show x
import Import a module from lib/ import math
extern Declare a foreign C function (FFI) extern make putchar(c)
new Heap-allocate a struct instance set p = new Point
true Boolean literal (true) set flag = true
false Boolean literal (false) set flag = false

Formatting Rules

  • No curly braces ({}) — Block scopes are defined entirely by indentation.
  • No semicolons (;) — Line endings are delimited by newlines.
  • Indentation — Use spaces (typically 4). Mixing tabs and spaces triggers syntax errors.
  • Comments — Start with # and extend to end of line.

Type System

Krait is statically typed with implicit compile-time type inference. You never write type annotations — the compiler deduces all types from assignments and expressions.

Primitive Types

Type Size Description Literals Storage
Int 64-bit Signed integer 42, 0, 0 - 5 Stack
Float 64-bit IEEE 754 double 3.14, 1.0 Stack
Str Variable UTF-8 string "hello" Stack (ptr)
Bool 1-bit Truth value true, false Stack
Void 0 No value Implicit N/A

Type Inference Rules

  • Variable types are inferred from their first assignment.
  • Function parameter types are inferred from usage within the function body.
  • Return types are inferred from return expressions.
  • No implicit coercionInt and Float cannot be mixed in operations.
  • Struct field types are inferred from their default values in the struct definition.

User-Defined Types (Structs)

Structs are the only user-defined type. They are always heap-allocated via new and managed by the ownership system. Stack-based structs are not supported.

Operators

Arithmetic Operators

Operator Operation Operand Types Result Type
+ Addition Int + Int, Float + Float Same as operands
- Subtraction Int - Int, Float - Float Same as operands
* Multiplication Int * Int, Float * Float Same as operands
/ Division Int / Int, Float / Float Same as operands

Comparison Operators

Operator Operation Result
< Less than Bool
> Greater than Bool
== Equal to Bool
!= Not equal to Bool

Assignment Operator

The = operator is used exclusively with the set keyword for variable assignment and field mutation. It is not an expression — it cannot be used inline or chained.

Note: There is no unary minus operator. To represent negative numbers, use the subtraction pattern: 0 - n. For example, set x = 0 - 42 assigns -42 to x.

Standard Library

Krait ships with modular standard library components in the lib/ directory. Import them with import module_name.

import math

Pure Krait mathematical functions. No FFI — compiles to optimal native loops.

Function Signature Description Example
abs abs(n) → Int Absolute value of n abs(0 - 42)42
power power(base, exp) → Int Computes baseexp power(2, 10)1024

Source: lib/math.kr

lib/math.kr
# Krait Standard Math Module

make abs(n)
    when n < 0
        return 0 - n
    return n

make power(base, exp)
    set result = 1
    repeat exp times
        set result = result * base
    return result

import io

System I/O functions exposed via the C Foreign Function Interface.

Function Signature Description Example
putchar putchar(c) → Void Write ASCII char to stdout putchar(72) → prints H

Source: lib/io.kr

lib/io.kr
extern make putchar(c)

Memory Model

Krait implements a compile-time Ownership Memory Model inspired by Rust, but without explicit lifetime annotations or borrow-checking syntax. The compiler enforces three invariants at compile time and auto-generates all deallocation code.

Rule 1: Owner Scope

Every heap-allocated struct instance (created via new) has exactly one owner — the variable it is assigned to. Ownership is established at the point of assignment.

Rule 2: Move Semantics

When a struct variable is assigned to another variable (set b = a), ownership of the underlying heap pointer transfers to the new variable. The original variable is immediately invalidated by the compiler's semantic analyzer. Any subsequent access to the moved variable triggers a compile-time error.

Stack vs. Heap: Move semantics only apply to heap-allocated structs. Primitives (Int, Float, Bool, Str) are copied by value on the stack — assigning one primitive variable to another creates an independent copy.

Rule 3: Auto-Drop

When a variable owning a heap resource exits its declared scope (end of a function, end of a conditional block), the compiler automatically inserts a native @free LLVM instruction to deallocate the memory. This happens at compile time — there is zero runtime overhead for tracking or collecting garbage.

Compiler Implementation

Behind the scenes, the Krait compiler translates ownership-managed code to optimized LLVM-IR equivalent to the following C logic:

Equivalent C (generated by compiler)
// What the compiler generates for auto-drop:
int64_t create_and_use() {
    Point* temp = (Point*)malloc(sizeof(Point));
    temp->x = 42;
    int64_t ret_val = temp->x;

    // Auto-Drop generated by Krait compiler!
    free(temp);

    return ret_val;
}

Safety Guarantees

  • Zero Memory Leaks — Memory is returned to the OS immediately when no longer needed.
  • Zero Double-Frees — Moved variables are invalidated; a pointer is never freed twice.
  • Zero Use-After-Free — Accessing a moved variable is a compile-time error, not a runtime crash.
  • No GC Pauses — No garbage collector means no unpredictable stop-the-world pauses.

Foreign Function Interface (FFI)

Krait supports directly importing and invoking native C functions using the extern keyword. This enables ultra-fast system integration without runtime performance bottlenecks.

Syntax

ffi_syntax.kr
extern make external_function_name(param1, param2)

Example: Calling C's putchar

ffi_example.kr
extern make putchar(char_code)

make print_hi()
    putchar(72)   # 'H'
    putchar(105)  # 'i'
    putchar(10)   # '\n'

print_hi()

The extern declaration tells the compiler that the function's implementation will be provided by the system linker at link time. The LLVM-IR backend emits a standard declare directive for the extern function, and the native linker resolves it against libc or any linked shared library.

CLI & Tooling

The krait executable provides all tools needed to scaffold, check, run, format, and compile code.

Command Action Example
krait Start the Interactive Shell (REPL) $ krait
krait new <name> Scaffold a new project directory $ krait new my_app
krait run <file> Interpret and execute a .kr file $ krait run main.kr
krait check <file> Run type-checking and ownership analysis $ krait check main.kr
krait fmt <file> Auto-format indentation and code $ krait fmt main.kr
krait build <file> Compile to optimized native executable $ krait build main.kr

Build Pipeline

When you compile with krait build, the compiler performs the following optimized steps:

  1. Lexing & Parsing — Source tokenization and AST generation.
  2. Import Resolution — Recursive merging of imported module ASTs.
  3. Semantic Analysis — Full type checking, ownership validation, and move tracking.
  4. LLVM-IR Generation — Structured intermediate representation output.
  5. Native Linking — Invokes clang with maximum optimizations:
    • -O3 — Maximum loop unrolling, register allocation, and execution optimization.
    • -flto — Link-Time Optimization across the whole binary.
    • -march=x86-64-v2 — Broad hardware instruction-set optimization.

Interpreter vs. Compiler

Feature krait run (Interpreter) krait build (Compiler)
Speed Moderate (tree-walking) Native machine speed
Requires clang No Yes
Output Direct execution Native binary executable
Use case Prototyping, scripting Production, deployment

LLM Prompting Guide

Krait's syntax and strict static typing are explicitly designed to be LLM-Friendly. The compiler outputs clear, structured diagnostics that autonomous coding models can read and resolve immediately. Use the following prompt blueprint to get LLMs to generate correct Krait code on the first try:

System Prompt Template
You are an expert compiler engineer and senior
developer in Krait (v1.0.0). Generate valid Krait
source code matching these rules:

1. FORMATTING:
   - Use spaces for indentation (4 spaces).
   - No curly braces {} or semicolons ;.
   - Comments start with #.

2. VARIABLES & TYPES:
   - Declare with: set var = expr
   - Struct fields: set obj.field = value
   - No type coercion (strongly typed).
   - Heap structs: set p = new StructName

3. FUNCTIONS & CONTROL FLOW:
   - Functions: make name(param1, param2)
   - Conditionals: when condition (Bool only)
   - No else/elif. Use multiple when blocks.
   - Loops: repeat count times
   - No for/while keywords.

4. OUTPUT & MEMORY:
   - show prints integer values.
   - For text: import io, use putchar(ASCII).
   - Struct assignment moves ownership.
   - Never use a variable after moving it.

5. LIBRARIES:
   - import math → abs(n), power(base, exp)
   - import io   → putchar(char_code)

Key Rules for Code Generators

  • Negative numbers: Use 0 - n pattern. There is no unary minus.
  • String output: There is no print function. Use putchar with ASCII codes for character-by-character text output.
  • No else: Structure conditional logic with multiple when blocks and early return statements.
  • Ownership: After set b = a (where a is a struct), never reference a again.
  • Indentation is semantic: Incorrect indentation changes program structure and causes compile errors.

Download Krait

Get started with Krait using one-line installation commands or download pre-compiled executables for your platform.

Installation Commands

Copy and paste the command matching your command shell to install Krait instantly. Commands are formatted sequentially for readability.

Windows PowerShell

irm https://raw.githubusercontent.com/skiLLM-Labs/Krait/refs/heads/main/install.ps1 | iex

Windows Command Prompt

curl -sL https://raw.githubusercontent.com/skiLLM-Labs/Krait/refs/heads/main/install.bat | cmd

macOS / Linux Bash

curl -fsSL https://raw.githubusercontent.com/skiLLM-Labs/Krait/refs/heads/main/install.sh | bash

Download Executable

Download pre-compiled binaries directly. Operating systems feature two dedicated download streams optimized for explicit processor architecture types.

Windows

Pre-compiled executable files targeting Windows operating systems.

macOS

Native targets accommodating both legacy Intel configurations and Apple Silicon systems.

Linux

Statically built distro-agnostic components eliminating external environment dynamic linking issues.

Note: To use krait build for native compilation, you'll need clang installed on your system. The interpreter (krait run) works standalone.

Next Steps

Getting Started

Head to the Learn section to write your first Krait program with step-by-step tutorials.

Try the Playground

Experiment with Krait directly in your browser before installing. No setup required.

Source Code

View the full compiler source on GitHub and contribute to Krait.