Modular C
Code unrolling
Synopsis:
#pragma CMOD foreach NAME = EL0 EL1 ....
#pragma CMOD done

This feature allows us to repeat code a fixed number of times such that at each copy ${NAME} is replace by the words EL0, EL1 etc. E.g to create a type generic maximum macro:

#pragma CMOD module max = proj◼max
#pragma CMOD composer —
#pragma CMOD declaration
#pragma CMOD foreach T = float double unsigned signed
inline
${T} max—${T}(${T} a, ${T} b) {
return a < b ? b ? a;
}
#pragma CMOD done
#define max(A, B) _Generic((A)+(B), \
default: max—double, \
float: max—float, \
unsigned:max—unsigned, \
signed: max—signed) \
((A), (B))

This creates four functions and a type generic interface macro.

The foreach directive is not limited to executable code. It unrolls every programming text:

#pragma CMOD foreach T = float double unsigned signed
struct pair—${T} { ${T} v; };
#pragma CMOD done
static double A[] = {
#pragma CMOD foreach X = 0 1 2 3 4 5 6 7 8 9
${X}*${X},
#pragma CMOD done
}

Here to declare four different types and to statically initialize an array with 10 different computed values.