Code-generation via textual macros can be very useful, but it also has a number of downsides. CPPO implements a fairly complete macro language, but its downside is that it is an additional (build-time) dependency to projects.
µCPPO attempts to alleviate this by being a single file dependency that is meant to be vendored into one's build. The idea is similar to the stb suite of single-file header libraries.
- No external dependencies
- Single file for easy embedding
- µCPPO files should remain valid CPPO files
- 80% of the usecases of CPPO at 20% of the cost
- Compatibility with the oldest supported compiler version that dune supports
- Conservative language subset to avoid breaking in future OCaml versions
- Implement the whole CPPO language
- Support CPPO files unchanged
- Have complete CLI parsing
- Fancy error handling
The main intended usage is within Dune, to allow for features that can't natively done with Dune itself:
Create a mucppo
folder with this dune
file:
(executable
(name mucppo))
Copy mucppo.ml
into it.
Then preprocess the files that need CPPO like so:
(rule
(action (with-stdout-to compat.ml
(run ./mucppo/mucppo.exe compat.pp.ml))))
- OCaml version comparison:
#if OCAML_VERSION >= (major, minor, patch)
- Inclusion of other files:
#include
Unless otherwise stated, other features are not implemented. Notably, macros and macros with arguments are unlikely to ever get implemented, as they are rarely used and make codebases hard to read.
As µCPPO is meant to be vendored into projects, the code is public domain in as far as possible under international law. Therefore it is under CC0 to facilitate relicensing and reuse.