Kraken Language
API Reference
A high-performance systems language with strict type safety, manual memory management, and zero-cost abstractions.
Quick Start
Install LLVM 18
Kraken requires LLVM 18 for compilation. Install via Homebrew on macOS or your system package manager.
Build the Compiler
Clone the repo and build with Cargo. The compiler outputs native binaries with zero runtime overhead.
Write Your First Program
Create a .kr file and compile it. Kraken's syntax is clean and familiar to C/Rust developers.
fn main() {
print("Hello, Kraken!")
}
# Build and run
$ cargo run -p kraken -- build hello.kr
$ ./build/hello
Hello, Kraken!
API Overview
Kraken provides a carefully designed set of types and containers for systems programming. Each component is built for performance and safety.
Primitives like int, float, bool, string, and bytes with strict type safety.
Dynamic arrays (Vec*) and hash maps (Map*) with heap-allocated storage.
Memory management, leak detection, and FFI for C interoperability.
io, fs, time, math, and other essential modules.
Standard Types
true and false.
i8*.
String & Bytes Indexing
Both string and bytes support byte-level indexing, returning an int in the range 0–255.
fn main() {
let s: string = "hello"
let first: int = s[0] // 104 ('h')
let b: bytes = cstr(s)
let byte: int = b[1] // 101 ('e')
}
VecInt
A dynamic array of int values with automatic memory management and efficient operations.
Creates a new, empty VecInt with no initial capacity. Memory is allocated on the heap and grows automatically as elements are added.
let numbers: VecInt = vec_int_new()
Appends an integer to the end of the vector. The vector's capacity is automatically increased if needed.
| Parameter | Type | Description |
|---|---|---|
| v | VecInt | The vector to modify |
| value | int | The integer value to append |
Returns the integer at the specified index. Traps if the index is out of bounds.
| Parameter | Type | Description |
|---|---|---|
| v | VecInt | The vector to read from |
| index | int | Zero-based index of the element |
Returns the number of elements currently stored in the vector.
Deallocates the vector's memory. Must be called when the vector is no longer needed to prevent memory leaks.
_free function when done with heap-allocated containers.Complete Example
fn main() {
// Create a new vector
let nums: VecInt = vec_int_new()
// Add some values
vec_int_push(nums, 10)
vec_int_push(nums, 20)
vec_int_push(nums, 30)
// Print length
print_int(vec_int_len(nums)) // 3
// Access elements
let first: int = vec_int_get(nums, 0)
print_int(first) // 10
// Always free when done!
vec_int_free(nums)
}
C-String Helpers
Functions for converting between Kraken strings and raw byte buffers at the C/FFI boundary.
Converts a Kraken string to a raw byte pointer (i8*) for passing to C APIs or system calls.
Converts a raw byte pointer back to a Kraken string. Will trap (abort) if the pointer is null.
from_cstr. Passing a null pointer will cause the program to abort.