Erlang/OTP 29, compiled to native code
Clause is an ahead-of-time compiler for Erlang. It preprocesses, parses and analyzes Erlang source, compiles it through LLVM and links native executables with its own runtime: lightweight processes, message passing and per-process garbage collection.
Work in progress: a growing subset of Erlang compiles and runs today. The documentation lists what works and where Clause differs from Erlang/OTP.
Features
OTP 29
Modern Erlang syntax
Preprocessor and parser for Erlang/OTP 29: macros, records, native records, maps, bitstrings, comprehensions, maybe and type specifications.
LLVM
LLVM backend
Compiles to verified LLVM IR, bitcode or native objects at O0, O2 or Os, with type-specialized function variants.
clau -o app
Native executables
Links Erlang modules and the runtime into a standalone program with Clang, in one command.
spawn · send · receive
Erlang processes
Processes on scheduler worker threads with selective receive, timeouts, links, monitors, registered names and exit signals.
Per-process GC
Isolated memory
Every process owns its heap, collected by a copying garbage collector in the classic ERTS design.
7 targets
Cross-platform
Native execution validated on Windows x64; objects checked for Linux x86, x64, ARM and AArch64, Windows x86 and x64, and Apple Silicon.
Feature details
Frontend
- Preprocessing: macros, includes, include_lib, conditional compilation and language features
- Erlang/OTP 29 syntax: expressions, patterns, records, bitstrings, types and specifications, control flow and comprehensions
- Syntax checking, expanded source output and an indented syntax tree view
- Source diagnostics across multiple input files
Compiler
- Semantic analysis: subset checks, variable bindings, call resolution, declared and inferred types
- LLVM O0, O2 and Os; per-module objects, IR and bitcode; IR snapshots annotated with Erlang source
- Type reports: source annotated with inferred function signatures
- Proper tail calls for local, remote and mutually recursive calls
- One explicit notimpl message for legal Erlang that needs a feature not implemented yet
Runtime
- LLVM-free C++23 runtime library linked into every program
- Arbitrary-precision integers, floats, atoms, tuples, lists, maps, bitstrings, records, funs, pids, ports and references
- Processes, messages, selective receive, links, monitors and registered names on scheduler workers
- Per-process heaps with a copying garbage collector and off-heap binaries
- Ports for standard I/O, files, subprocesses and sockets
- Exceptions with try, catch and after, and stack traces
- io:format with OTP's ~p pretty printing; subsets of lists, maps, file and io
Projects and tooling
- TOML projects with named targets, source discovery and per-target options
- Annotated starter projects with clau --new-project
- One clau command from Erlang source to a native executable
- Behavior checked against outputs of the reference Erlang/OTP
Clause