@tt: translate-time programs
@tt runs a program before C is emitted. It can compute, read files, and emit any C text or tokens.
A computed table
@tt
f square(n) = n * n
values := []
for i range(5)
values = push(values, str(square(i)))
emit("static const int squares[] = {" + join(values, ",") + "};")
f main
squares[4] != 16static const int squares[] = {0,1,4,9,16};
int main(void) {
return squares[4] != 16;
}Values are dynamic: integers, text, lists and booleans. Functions, loops and branches use the same indentation syntax as NanoC itself.
Quoting code
quote(...) captures tokens with $name holes, so you can generate declarations without string concatenation.
@tt
n := 42
emit(quote(int answer = $n;))
f main
answer != 42int answer = 42;
int main(void) {
return answer != 42;
}Context functions
| Function | Returns |
|---|---|
cycle() | Current one-based expansion cycle |
line() | Source line of the call |
file() | Input file spelling |
name() | Enclosing function name, or empty at file scope |
target() | Selected C standard, or c++17 |
Source transforms
rewrite(text) replaces the source and the pipeline repeats until the text stops changing; again() forces another pass. Counts are bounded by default; --max-passes 0 --max-steps 0 removes the limits.
Host effects
Native @tt can read and write files and run programs (write, mkdir, remove, run, exec, sh). --check validates expansion but refuses to execute those, so checking never changes your machine.
- Every builtin has a reference page with a verified example.
- The guide lesson walks through the pipeline.