The x2c Book
x2c extends C with dynamic values, collections, and compile-time code generation. Use the features you need; keep ordinary C where it already works. C headers, libraries, data layout, expressions, and native tools remain available. x2c compiles to C, and its compiler and runtime are written in x2c.
This book explains how to use x2c and specifies its language and library. For a short introduction and installation instructions, follow the links above.
What x2c adds
Start with C types and calls, then add what the program needs:
Varholds dynamic values;String,List,Array, andMaphold text and collections.FuncandLisplet programs call and evaluate code.Itertraverses values, andMatchtakes structured data apart.Scopemanages allocation lifetimes;ContextandThreadisolate runtime state;Errorrecords and propagates failures.translateproduces C for an existing build.build,run, andbootstrapalso handle native compilation and execution.- Protocols adapt concrete types to explicitly adopted interfaces. Macros generate parsed, typed source at compile time.
Using one feature does not require converting the rest of the program to a new object model.
Reading the book
If you know C, most source will look familiar. The guide concentrates on the places where x2c replaces work you would otherwise do by hand: tagged unions, adapters, repeated declarations, collection allocation, traversal, cleanup, and pattern matching.
- The language guide shows how to use x2c and when its features help.
- The language reference states exact syntax and semantics.
- The standard library describes the available modules and links to their API reference, generated from the source.
- Compiler architecture explains the self-hosting implementation for readers who want to study or contribute to it.
The book describes implemented behavior. Its x2c samples are translated and
checked for valid C syntax. make examples also runs the showcase programs
and checks their output.