Note: None of this is implemented.
Metaprogramming enables fine-grained control over what program logic gets compiled, such as:
- Conditionally include or exclude certain code
- Algorithmically generate data or program logic
In effect, the metaprogramming facilities represent a additional, similar-looking language whose constructs are differentiated by being marked with #. This language manipulates regular program logic as if it were data.
Meta-conditionals are control flow blocks that are used to determine what logic gets compiled (as opposed to normal control flow blocks that determine what gets executed).
Meta-conditionals within generics or macros are evaluated when instantiated.
Meta variables are immutable and exist only at compile time. They hold typed, constant values, calculated from an expression.
imm #arrsize = 10
Note: Some meta-variables have their values set by the compiler, thereby providing information about the compile-time environment, such as the target platform and architecture. It is also possible to use a compiler option to pass in data to a program in one or more meta-variables.
#if may be used to determine whether or not to include specific program logic in the compiled program:
#if #target == "windows": ... Windows-specific logic ... #elif #target == "linux": ... Linux-specifc logic ...
#each enables collection-driven, repetitive generation of the same program logic.
#each #x in #table: ... some logic ...