Mox

Mox is a statically typed, data oriented, low level programming language for software and games.

Download · Showcase · GitHub

Hello world

import "std.mox";

#linkc fn main(): i32 {
    println("hello {}!", .{ "world"; });
    return 0;
}

Compile time code execution

Any code can run at compile time, including external C calls. The result is baked into the binary as a constant.

#linkc fn puts(str: *u8): void;

#run puts("printed while compiling");

const BUILD_URL := #run os_get_env("PUBLIC_URL");

More patterns on the showcase page.

Code generation

Build code from a string and insert it into the module.

fn per_platform_import($path: []u8): __ast_ptr {
    platform := "";

    switch (MOX_OS) {
        case .Windows:
            platform = "win";
        case .Linux:
            platform = "sysv";
        case:
            platform = "unknown";
    }

    code := #format_temp("import \"{}_{}\";", .{ $path; platform; });
    return __compiler_parse(code);
}

#run #land_ast per_platform_import("module/path");

Types are values

A type is a real pointer to its data inside the compiler. Cast it to *MoxType and read its fields like any struct. AST nodes work the same way.

fn alloc($T: __type_ptr): *$T {
    size := $T.cast(*MoxType).size;
    return malloc(size).cast(*$T);
}

fn main() {
    x: *i32 = alloc(i32);
}

Comptime data in runtime

Read a resource at compile time and bake its bytes into the binary as a constant. No asset loader at startup, no file paths to ship.

const FONT_BYTES := #run fs_read_file_full("./assets/font.ttf");

fn render_text() {
    load_font_from_memory(FONT_BYTES);
    // ...
}

Or fill a table at compile time and read it at runtime. Longer example on GitHub.

struct Command {
    name: []u8;
    run: *fn (x: i32): i32;
};

commands: [16]Command = 0; #no_comptime_reset
commands_len: i32 = 0;     #no_comptime_reset

fn register(name: []u8, run: *fn (x: i32): i32) {
    commands[commands_len].name = name;
    commands[commands_len].run = run;
    commands_len = commands_len + 1;
}

fn double(x: i32): i32 { return x * 2; }
fn square(x: i32): i32 { return x * x; }

#run {
    register("double", double);
    register("square", square);
}

#linkc fn main(): i32 {
    return commands[1].run(commands_len); // square(2) == 4
}

Batteries included

Vectors with swizzling and overloaded operators are built into the language.

fn add_scaled(a: [4]f32, b: [4]f32): [3]f32 {
    return (a + b).xyy * 2.0f;
}

The math.mox module ships with the compiler:

Plus the usual sqrt, sin/cos/tan, pow, exp, log, floor/ceil/round. See modules/math.mox.

Vendored libraries come with prebuilt binaries for Windows and Linux. raylib and SDL3 work out of the box, no system install:

import "std.mox";
import "vendor/raylib.mox";

#linkc fn main(): i32 {
    InitWindow(800, 600, "hello");
    defer CloseWindow();

    while (!WindowShouldClose()) {
        BeginDrawing();
        ClearBackground(Color.{ 24, 24, 24, 255 });
        EndDrawing();
    }

    return 0;
}

The raylib DLLs are copied to the output directory on build. Full example.

Generics

One syntax for generics, polymorphism and overloading.

fn max($T: __type_ptr, a: $T, b: $T): $T {
    if (a > b) return a;
    return b;
}

fn main() {
    i: i32 = max(i32, 1, 2);
    f: f32 = max(f32, 1.0f, 2.5f);
}

Compilation speed

200k simple functions, emitting an executable:

CompilerTimevs mox
mox jit0.499 sec1.0x
mox llvm8.8 sec17.6x
clang 19.1.313.3 sec26.7x
odin dev-2026-0813.8 sec27.7x
rustc 1.96.133.9 sec67.9x

25k generics over 8 types, emitting an executable:

CompilerTimevs mox
mox jit1.24 sec1.0x
mox llvm15.48 sec12.5x
clang++ 19.1.339.64 sec32.0x
rustc 1.96.143.56 sec35.1x
odin dev-2026-0859.09 sec47.7x

Full benchmark

C performance

Mox-compiled code runs at C speed. The rapidhash benchmark matches the C reference on throughput.

Rapidhash benchmark