123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- #ifndef ES_UTIL_H__
- #define ES_UTIL_H__
- #define BOOL(x) COMPL(NOT(x))
- #define IF(c) IIF(BOOL(c))
- #define CHECK_N(x, n, ...) n
- #define CHECK(...) CHECK_N(__VA_ARGS__, 0,)
- #define PROBE(x) x, 1,
- #define EAT(...)
- #define EXPAND(...) __VA_ARGS__
- #define WHEN(c) IF(c)(EXPAND, EAT)
- #define NOT(x) CHECK(PRIMITIVE_CAT(NOT_, x))
- #define NOT_0 PROBE(~)
- #define COMPL(b) PRIMITIVE_CAT(COMPL_, b)
- #define COMPL_0 1
- #define COMPL_1 0
- #define CAT(a, ...) PRIMITIVE_CAT(a, __VA_ARGS__)
- #define PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__
- #define IIF(c) PRIMITIVE_CAT(IIF_, c)
- #define IIF_0(t, ...) __VA_ARGS__
- #define IIF_1(t, ...) t
- #define DEC(x) PRIMITIVE_CAT(DEC_, x)
- #define DEC_0 0
- #define DEC_1 0
- #define DEC_2 1
- #define DEC_3 2
- #define DEC_4 3
- #define DEC_5 4
- #define DEC_6 5
- #define DEC_7 6
- #define DEC_8 7
- #define DEC_9 8
- #define DEC_10 9
- #define DEC_11 10
- #define DEC_12 11
- #define DEC_13 12
- #define DEC_14 13
- #define DEC_15 14
- #define DEC_16 15
- #define DEC_17 16
- #define DEC_18 17
- #define DEC_19 18
- #define DEC_20 19
- #define DEC_21 20
- #define DEC_22 21
- #define DEC_23 22
- #define DEC_24 23
- #define DEC_25 24
- #define DEC_26 25
- #define DEC_27 26
- #define DEC_28 27
- #define DEC_29 28
- #define DEC_30 29
- #define DEC_31 30
- #define DEC_32 31
- #define EMPTY()
- #define DEFER(id) id EMPTY()
- #define OBSTRUCT(...) __VA_ARGS__ DEFER(EMPTY)()
- #define EXPAND(...) __VA_ARGS__
- #define EVAL(...) EVAL1(EVAL1(EVAL1(__VA_ARGS__)))
- #define EVAL1(...) EVAL2(EVAL2(EVAL2(__VA_ARGS__)))
- #define EVAL2(...) EVAL3(EVAL3(EVAL3(__VA_ARGS__)))
- #define EVAL3(...) EVAL4(EVAL4(EVAL4(__VA_ARGS__)))
- #define EVAL4(...) EVAL5(EVAL5(EVAL5(__VA_ARGS__)))
- #define EVAL5(...) __VA_ARGS__
- #define REPEAT(count, macro, ...) \
- WHEN(count) \
- ( \
- OBSTRUCT(REPEAT_INDIRECT) () \
- ( \
- DEC(count), macro, __VA_ARGS__ \
- ) \
- OBSTRUCT(macro) \
- ( \
- DEC(count), __VA_ARGS__ \
- ) \
- )
- #define REPEAT_INDIRECT() REPEAT
- #endif
|