Clause

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

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