15 #define AJK_CAT(a, ...) AJK_PRIMITIVE_CAT(a, __VA_ARGS__)
16 #define AJK_PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__
18 #define AJK_COMPL(b) AJK_PRIMITIVE_CAT(AJK_COMPL_, b)
22 #define AJK_BITAND(x) AJK_PRIMITIVE_CAT(AJK_BITAND_, x)
23 #define AJK_BITAND_0(y) 0
24 #define AJK_BITAND_1(y) y
26 #define AJK_INC(x) AJK_PRIMITIVE_CAT(AJK_INC_, x)
39 #define AJK_DEC(x) AJK_PRIMITIVE_CAT(AJK_DEC_, x)
52 #define AJK_CHECK_N(x, n, ...) n
53 #define AJK_CHECK(...) AJK_CHECK_N(__VA_ARGS__, 0,)
54 #define AJK_PROBE(x) x, 1,
56 #define AJK_IS_PAREN(x) AJK_CHECK(AJK_IS_PAREN_PROBE x)
57 #define AJK_IS_PAREN_PROBE(...) AJK_PROBE(~)
59 #define AJK_NOT(x) AJK_CHECK(AJK_PRIMITIVE_CAT(AJK_NOT_, x))
60 #define AJK_NOT_0 AJK_PROBE(~)
62 #define AJK_COMPL(b) AJK_PRIMITIVE_CAT(AJK_COMPL_, b)
66 #define AJK_BOOL(x) AJK_COMPL(AJK_NOT(x))
68 #define AJK_IIF(c) AJK_PRIMITIVE_CAT(AJK_IIF_, c)
69 #define AJK_IIF_0(t, ...) __VA_ARGS__
70 #define AJK_IIF_1(t, ...) t
72 #define AJK_IF(c) AJK_IIF(AJK_BOOL(c))
75 #define AJK_EXPAND(...) __VA_ARGS__
76 #define AJK_WHEN(c) AJK_IF(c)(AJK_EXPAND, AJK_EAT)
79 #define AJK_DEFER(id) id AJK_EMPTY()
80 #define AJK_OBSTRUCT(id) id AJK_DEFER(AJK_EMPTY)()
82 #define AJK_EVAL(...) AJK_EVAL1(AJK_EVAL1(AJK_EVAL1(__VA_ARGS__)))
83 #define AJK_EVAL1(...) AJK_EVAL2(AJK_EVAL2(AJK_EVAL2(__VA_ARGS__)))
84 #define AJK_EVAL2(...) AJK_EVAL3(AJK_EVAL3(AJK_EVAL3(__VA_ARGS__)))
85 #define AJK_EVAL3(...) AJK_EVAL4(AJK_EVAL4(AJK_EVAL4(__VA_ARGS__)))
86 #define AJK_EVAL4(...) AJK_EVAL5(AJK_EVAL5(AJK_EVAL5(__VA_ARGS__)))
87 #define AJK_EVAL5(...) __VA_ARGS__
89 #define AJK_REPEAT(AJK_count, AJK_macro, ...) \
92 AJK_OBSTRUCT(AJK_REPEAT_INDIRECT) () \
94 AJK_DEC(AJK_count), AJK_macro, __VA_ARGS__ \
96 AJK_OBSTRUCT(AJK_macro) \
98 AJK_DEC(AJK_count), __VA_ARGS__ \
101 #define AJK_REPEAT_INDIRECT() AJK_REPEAT
103 #define AJK_WHILE(AJK_pred, AJK_op, ...) \
104 IF(AJK_pred(__VA_ARGS__)) \
106 AJK_OBSTRUCT(AJK_WHILE_INDIRECT) () \
108 AJK_pred, AJK_op, AJK_op(__VA_ARGS__) \
112 #define AJK_WHILE_INDIRECT() AJK_WHILE
114 #define AJK_PRIMITIVE_COMPARE(x, y) AJK_IS_PAREN \
116 AJK_COMPARE_ ## x ( AJK_COMPARE_ ## y) (()) \
119 #define AJK_IS_COMPARABLE(x) AJK_IS_PAREN( AJK_CAT(AJK_COMPARE_, x) (()) )
121 #define AJK_NOT_EQUAL(x, y) \
122 AJK_IIF(AJK_BITAND(AJK_IS_COMPARABLE(x))(AJK_IS_COMPARABLE(y)) ) \
124 AJK_PRIMITIVE_COMPARE, \
128 #define AJK_EQUAL(x, y) AJK_COMPL(AJK_NOT_EQUAL(x, y))
131 #define AJK_COMMA() ,
133 #define AJK_COMMA_IF(n) AJK_IF(n)(AJK_COMMA, AJK_EAT)()
136 #define AJK_COMMA_VAR(AJK_count, AJK_v) AJK_COMMA_IF(AJK_count) AJK_v ## AJK_count
138 #define AJK_MAKE_LIST(AJK_v, AJK_count) AJK_EVAL(AJK_REPEAT(AJK_count, AJK_COMMA_VAR, AJK_v))
140 #define AJK_FUN(AJK_count, AJK_v, AJK_args, AJK_body) AJK_v ## AJK_count (AJK_args) { AJK_body(AJK_count) }
141 #define AJK_MAKE_FUNS(AJK_v, AJK_args, AJK_count, AJK_body) AJK_EVAL(AJK_REPEAT(AJK_count, AJK_FUN, AJK_v, AJK_args, AJK_body))
142 #ifdef AJK_TEST_MACRO_LOGIC
144 #define BODY(AJKindex) some(C, statement); contaning(a, test[AJKindex]);
145 #define ZERO_TIMES_TEST 0
146 #define THREE_TIMES_TEST 3
147 blank >
AJK_MAKE_LIST(VARIABLE_, ZERO_TIMES_TEST) < because zero repeats
148 Make 3 comma separated indexed variables :
AJK_MAKE_LIST(VARIABLE_, THREE_TIMES_TEST)
149 Make 3 bogus
function bodies