Programming is Dead.
Long Live Programming.
x2c is a language for people who love to code.
x2c is a quirky little language that makes programming fun and a bit weird. It has legitimate applications, presumably, but is more about coding for the joy of it. Some users of x2c report heightened expressiveness, a sense of universality, with a touch of transcendence. Be sure to drink plenty of water.
x2c is C with batteries and without the bullshit.
It is a strict superset of C that compiles to C, keeping C’s
native performance, tooling, ecosystem, and portability while adding the
conveniences of a modern language. x2c extends C’s syntax with a few new
keywords, but the real magic is in the % and $ sigils, which let you write
code that combines static types, dynamic values, and compile-time computation.
x2c’s main features are summarized in the table on the right. Everything is optional and works with plain C as well. Hence, you can take existing C code and adopt x2c capabilities incrementally.
The compiler, library, and runtime are all written in x2c, with no third-party dependencies. You can read the source to learn the language, then change the language by editing the source. The repository counts give a sense of its size.
At this point, you may be wondering: why learn a new programming language, let alone create and release one, in a post-AI world? Fair question. Programming is not about making computers do things; it’s about helping brains think things. Now, more than ever, the best reason to code is to rewire your brain. So if programming is more than a career to you—if you code for love, power, or magic—try a bit of x2c.
Code is Love
Part of the pleasure of programming is finding a clear way to express an idea. We love C because it puts us close to the machine, with little between us and what it can do. But that closeness comes at a cost: even simple ideas can take a lot of housekeeping to express.
x2c keeps that directness and lets you focus on what your program does. Describe a whole configuration as readable, nested data. Work with text and collections through operations you can combine. Read a file without managing line buffers. Give your own types methods that feel as natural as the built-ins. C’s functions, libraries, and control remain within reach.
Nobody ever fell in love with boilerplate. x2c leaves more room for what you do love: turning an idea into code.
Explore the essentials: values, symbols, collections and literals, files, and methods.
Code is Power
Code becomes powerful when a few simple pieces open up many possibilities. Each capability becomes more useful through the others: collections give your types something to build on, iterators connect operations into flows, and imports bring C libraries into the same style of code.
With x2c, those combinations turn into working tools. Turn a stream of text into a ranked result. Build and query a search index. Send work to another thread and bring the answer back. Run a daily survey that reclaims working storage after each file and each day, without individual free calls. Substantial computations become compact enough that you can still see the idea running through them.
The pieces are small. What you build with them needn’t be.
Put the pieces together: collections, iteration, scopes, match, threads, exceptions, and packages.
Code is Magic
When you can change the language, repetition starts to look like an opportunity. A pattern you keep writing can become a construct you use. An idea that once needed a page of explanation can have a name, a syntax, and rules the compiler understands.
Give sets their own operators. Turn a locking convention into a statement that always releases the lock. Describe a family of values once and let Lisp generate the code that follows from it. Inside the finished program, use that same Lisp to make rules into data you can pass around and evaluate.
The compiler is written in x2c, too. Follow an idea far enough and you can change the tool you are thinking with, in the language you already use.
Explore the language itself: protocols, macros and compile-time Lisp, runtime Lisp, self-hosting, compiler inspection, and architecture.
Run your first x2c program.
Clone the repository, build the compiler from its checked-in C, and run one of the included examples. The compiler handles translation, native compilation, and execution.
See the build instructions for the self-hosting process, or use the portable executable to create a native installation.
git clone https://github.com/gwf/x2c.git
cd x2c
make build-safe
./builds/0/x2c run examples/foreach.x
Go further.
Read the docs to learn the language and look up its library. Browse the source to see how it works or make it your own.
Repository counts from make stats.
code / comment lines in the compiler source.
code / comment lines in the library source.
unit tests.
compiler fixtures.
showcase examples.
C libraries available as importable x2c packages.