A from-scratch systems language that compiles straight to native x86-64.
Its own backend, linker, and source-level debugger. No LLVM, no VM, no managed runtime.
Documentation · Install · Examples · GitHub · Releases
Mettle compiles .mettle source to native x86-64. On Windows, mettle --build produces a PE executable using a built-in linker. On Linux, it produces ELF and links with the system toolchain.
- Static types, pointers, structs, enums, closures, and
defer/errdefer - Direct calls to C and OS APIs; a bundled stdlib for I/O, memory, math, and more
- Compile-time memory diagnostics: use-after-free, double free, leaks, and dangling pointers caught at compile time, with no annotations. Interprocedural and zero false positives. See borrow checker.
- AVX2 auto-vectorizer that beats
gcc -O3on several kernels, plus@simd/@simd!contracts (vectorize or fail the build) --explain: the compiler reports every optimization decision, why loops did or didn't vectorize, and flags regressions since your last build. Suggested fixes are verified by simulation before they're printed.--explain-jsonfor CI.- Optimization contracts:
@inline!and@noallocfail the build with the compiler's reason if the guarantee can't be met - Built-in source-level debugger: breakpoints, stepping, live variable read/write via
--debug-hooks. No gdb, no PDB, no DWARF. - GPU offload to NVIDIA: write
kernelfunctions and launch withdispatch K[grid, block](args). Native CUDA/PTX backend, nonvcc. See GPU offload. - Crash forensics: with
-s, faults report what the bad address is (null field access, freed heap block, etc.);--native-heapcatches use-after-free at the faulting instruction - Optional Tracy profiling, runtime timing, and debug stack traces
Windows is the most complete target (internal PE linker, Win32 GUI via std/ui). Linux supports builds, a libc-backed stdlib, and compiler development. See known limitations.
Save as hello.mettle:
import "std/io";
fn fib(n: int32) -> int64 {
if (n <= 1) { return n; }
var a: int64 = 0;
var b: int64 = 1;
var i: int32 = 2;
while (i <= n) {
var next = a + b;
a = b;
b = next;
i = i + 1;
}
return b;
}
fn main() -> int32 {
print("fib(10) = ");
print_int(fib(10));
newline();
return 0;
}
mettle --build hello.mettle -o hello
./hello # Windows: .\hello.exeLinux (x86-64)
curl -fsSL https://raw.githubusercontent.com/The-Mettle-Project/Mettle/main/install.sh | shWindows (x86-64), PowerShell
irm https://raw.githubusercontent.com/The-Mettle-Project/Mettle/main/install.ps1 | iexInstalls to ~/.mettle (Linux) or %LOCALAPPDATA%\Mettle (Windows) and updates user PATH. No root or admin required. Pin a release with --version v0.13.0 (Linux) or -Version v0.13.0 (Windows).
Windows (gcc or clang):
.\build.bat # default: gcc
.\build.bat clangLinux / macOS:
make # bin/mettle + bundled stdlib/ and runtime/
make install # optional: /usr/local/bin, stdlib, runtimeTypical release build:
./bin/mettle --build --release hello.mettle -o helloCommon flags: --release / -O, --explain, --debug-hooks, -d / -s / -g, --native-heap. Full list: mettle --help.
- Language reference
- Borrow checker
- Control flow
- GPU offload
- Compilation
- Imports
- Runtime model
- Standard library
- C interop
- Known limitations
mettle docs prints paths to these files next to the compiler binary.
src/ compiler (lexer through codegen, linker, diagnostics)
stdlib/ standard library
src/runtime/ optional helper objects (crash traces, atomics, ...)
tests/ regression tests; run_tests.ps1 on Windows
examples/ benchmarks and demos
tools/ ELF tests, benchmarks, fuzz scripts
mettle-syntax/ VS Code / Cursor extension
docs/ language and tooling reference
Runnable samples live under examples/. Benchmark suites pair Mettle, C, and Rust:
.\tools\benchmark\run-benchmarks.ps1Windows (primary CI: full test suite):
.\build.bat
.\tests\run_tests.ps1Linux (native ELF backend):
make -j"$(nproc)"
bash tools/test-elf-native.shThe mettle-syntax extension turns VS Code or Cursor into a full Mettle IDE: debugging on F5, go to definition, rename, completion, an interactive --explain dashboard, and compiler-backed diagnostics. Everything runs against the compiler in your workspace; no separate language server.
Apache-2.0. See LICENSE.