Skip to content
MorglodPublic

About

mox programming language

Topics

Resources

Stars

114 stars

Watchers

0 watching

Forks

Repository files navigation

This is release repository. Development is going on closed source for now.

mox

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

  • Compile time code execution and code generation
  • Interpreter based type checking, ast and types are first class
  • Fast compilation (20-30x faster than clang, 0.5-1 mil LOC/sec vs 28k LOC/sec)
  • Hygyenic macros
  • Generics, polymorphism and function overloading
  • 3 backends supported: fast x86_64 JIT, LLVM, C
  • Cyclic module imports
  • DWARF debug symbols

JIT backend is x86_64 targetted, but llvm and C backend could emit for any platform

Windows / Linux x86_64 tested

Getting started

To know language better, you can read tutorials or ./by_example.mox

Compilation speed comparison

Download link

Prerequisites

Zip archive already contains both versions of compiler and base modules.

For highlighting you can use C or Go or Rust for now

Later smaller version without LLVM backend will be added (few megabytes)

CLI

There are compatability flags like -O0, -O3, -g, -o
But mostly CLI arguments are verbose

Compiler emits obj file on JIT and LLVM backends, but by default runs external linker too

mox help
mox ./hello.mox
mox compile="./hello.mox" backend=llvm
mox ./hello.mox -O3 -o=./hello
mox ./hello.mox linker=false
mox ./hello.mox linker="g++ -o :MOX_LINKER_OUT:"

Some feature highlights

Builtin 3d math with swizzling:

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

Compile time code execution:

Which works for externally linked functions too

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

#run puts("this message will be printed at compilation time");

// this constant will be baked from env variable at compilation time, not at runtime
const SOME_COMPTIME_FLAG := #run os_get_env("PUBLIC_URL");

fn main() {
    build_version := #run os_exec_output("git rev-parse HEAD");
}

Code generation and ast manipulation:

fn make_config($path: []u8): __ast_ptr {
    sb := #temp_string_builder();
    for (line : split_iterator(fs_read_file_full($path), "\n")) {
        eq := index_of(line, "=");
        if (eq < 0) { continue; }
        format(sb, "const {} : i32 = {};\n", .{ slice(line, 0, eq), slice(line, eq + 1, line.len) });
    }
    return __compiler_parse(finalize(sb));
}

#run #land_ast make_config("./config.txt"); // const width : i32 = 800; ...

Type manipulation:

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

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

Planned

  • Union macros and struct fields offsets
  • Inline assembler
  • llvm-jit double backend for fast compile time execution
  • Better compile time debugging and function introspection
  • Web target
  • Hook compiler from user space

About

mox programming language

Topics

Resources

Stars

114 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages