Version 0.8.11 Released

Kraken Language
API Reference

A high-performance systems language with strict type safety, manual memory management, and zero-cost abstractions.

Quick Start

1

Install LLVM 18

Kraken requires LLVM 18 for compilation. Install via Homebrew on macOS or your system package manager.

2

Build the Compiler

Clone the repo and build with Cargo. The compiler outputs native binaries with zero runtime overhead.

3

Write Your First Program

Create a .kr file and compile it. Kraken's syntax is clean and familiar to C/Rust developers.

hello.kr
fn main() {
    print("Hello, Kraken!")
}
Terminal
# 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.

Standard Types

Type Safety
Kraken enforces strict type safety at compile time. Implicit conversions are not allowed—use explicit casts when needed.
int 64-bit signed integer. Primary numeric type for general computation.
float 64-bit IEEE 754 floating-point number for decimal operations.
bool Boolean type with values true and false.
string C-string text for libc/FFI boundary. Lowered to i8*.
bytes Raw buffers and opaque handles. Used for malloc pointers, FILE*, etc.

String & Bytes Indexing

Both string and bytes support byte-level indexing, returning an int in the range 0–255.

indexing.kr
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.

vec_int_new() -> VecInt
Stable

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()
vec_int_push(v: VecInt, value: int) -> void
Stable

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
vec_int_get(v: VecInt, index: int) -> int
Bounds Check

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
Bounds Checking
This function performs runtime bounds checking and will trap (abort) if the index is negative or >= length.
vec_int_len(v: VecInt) -> int
Stable

Returns the number of elements currently stored in the vector.

vec_int_free(v: VecInt) -> void
Required

Deallocates the vector's memory. Must be called when the vector is no longer needed to prevent memory leaks.

Memory Management
Kraken uses manual memory management. Always call the corresponding _free function when done with heap-allocated containers.

Complete Example

vec_demo.kr
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.

cstr(s: string) -> bytes
Stable

Converts a Kraken string to a raw byte pointer (i8*) for passing to C APIs or system calls.

from_cstr(b: bytes) -> string
Traps on null

Converts a raw byte pointer back to a Kraken string. Will trap (abort) if the pointer is null.

Null Safety
Always verify that byte pointers are non-null before calling from_cstr. Passing a null pointer will cause the program to abort.
VecInt
Containers › VecInt
vec_int_push
Containers › VecInt › vec_int_push
string
Core Types › Primitives › string