C with batteries, without bullshit.
x2c extends C with dynamic values, collections, pattern matching, scoped allocation, exceptions, threads, and Lisp. It compiles to C and works with C libraries and native build tools. You can use the added features where they help and keep ordinary C elsewhere. The C compatibility notes describe the cases that need source changes.
Two characters introduce much of the added syntax. % starts literals for
lists, maps, arrays, and strings: %(list), %{}, %[], and %"text".
$ inserts expressions into literals and introduces compile-time Lisp.
These forms let you combine C code, structured data, and code generation
in the same program.
The compiler and runtime are written in x2c. Their source shows how the language is used in a substantial program, including how Lisp and macros help implement the compiler. You can study it, change it, and rebuild the language yourself.
The book covers the language, standard library, and compiler internals. The examples provide runnable introductions, and packages add optional C libraries.
- The website landing page is the short introduction and includes the installation instructions. Building the compiler covers the self-host stages behind them.
- The language guide covers values and
Var, protocols, compile-time macros, symbols and atoms, collections, pattern matching, iteration, scopes and lifetime, contexts and threads, exceptions, and idioms. - Language reference and compiler options - implemented syntax with its stated limitations, and every command-line flag.
- Standard library overview - values and
operations. Architecture and the
implementation map explain how a
.xfile becomes C and where each feature is implemented.
You need a GCC- or Clang-compatible C compiler, an archiver (ar), GNU Make,
and Python 3. From the repository directory:
make build-safe
./x2c run examples/foreach.xAfter the build, ./x2c runs the working compiler through the repository
link. run compiles and runs the example in one step. Try another file from the
example guide the same way.
To keep an executable:
./x2c build examples/foreach.x
./a.outUse --output foreach if you want to choose its name.
To use x2c outside the checkout, install it into a dedicated prefix and put
its bin on PATH; x2c env shows what the compiler resolved:
make install PREFIX="$HOME/.local/x2c"
export PATH="$HOME/.local/x2c/bin:$PATH"
x2c envInstall a native compiler describes the prefix layout, packages, and the developer workflow.
To build and check all curated examples, then try the Lisp shell from the repository root:
make examples
./examples/build/programs-lisp/lispThe last command opens the interactive Lisp shell; press Ctrl-D to exit.
To build all optional packages and their examples, then try an animated Game of Life from the repository root:
make packages
./packages/termbox2/builds/game-of-lifemake packages reports missing build prerequisites before compiling. Run
make configure-packages to get that report separately.
The first build prepares pinned dependencies and builds the example executables without running tests or requiring Expect. Game of Life starts each cell alive with 50% probability; press any key to quit. To build just one package instead, follow its build instructions.
For help:
./x2c --help
./x2c help buildThe command-line guide covers translation to C, build options, and integration with your own build system. Building the compiler explains self-hosting and repository checks.
The language shootout compares fourteen programs with C and Python references, including execution time and source size. In the September 6, 2026 local run, all fourteen x2c programs were faster than the saved Python references. The median x2c/C time ratio was 1.04; individual results vary substantially. CSV parsing was 2.35 times faster than Python, and binary trees was 1.68 times faster.
See the table, source programs, and measurement details before drawing broader conclusions. Run the x2c comparisons from the repository root with:
make shoot-runThe Cosmopolitan executable is an experiment for fun only: a minimal compiler bootstrap, not a substitute for the full repository. It omits the examples, book, and optional packages. Use the full repository for normal development. See the experiment's instructions to try it.
src/- the translator and native compiler driver.lib/- runtime values, collections, matching, iteration, IO, contexts, native threads, scopes, dispatch, and diagnostics support.unittest/- the executable unit harness and compiler phase fixtures.bootstrap/- generated C sources used to build the compiler from a fresh checkout.builds/- staged self-hosted toolchains; stage 0 drives development.docs/- the user-facing book: language guide, reference, library, and compiler internals.agents/- agent-facing documentation (philosophy, workflow, style, debugging, generated inventory) and project skills inagents/skills/.plans/- active plans and archived execution logs.examples/- runnable language examples, larger programs, and the language shootout.packages/- optional adapters for third-party C libraries.site/- the public pages, rendered with the book bymake site-build.
The architecture and
build guide explain the compiler and its
self-hosting stages. Change the .x sources rather than generated bootstrap
C. The development guide covers repository
builds, tests, and generated files; AGENTS.md contains instructions
for coding agents. The current contribution policy is in
CONTRIBUTING.md.
x2c is experimental and actively developed. It compiles itself four times and compares the generated C and headers each time. Runtime tests and compiler fixtures check behavior and generated output. The language reference documents supported behavior and known limitations.
The canonical project site is x2c-lang.dev. The source is available under the Apache License 2.0. You can fork it. You do not get support, a roadmap, a release schedule, a vote on the design, or a Discord.
I develop x2c according to my own priorities. File a bug if you like; I read them and fix the ones that interest me. The project is not accepting external code contributions - see CONTRIBUTING.md - so you are better off forking.
See THIRD_PARTY.md for the current license inventory and notices. x2c is founder-led under the authority described in GOVERNANCE.md; the trademark, security, and support policies explain the terms for using the name, reporting vulnerabilities, and asking for help.