hobbes
a language, embedded compiler, and runtime for efficient dynamic expression evaluation, data storage and analysis
preprocessor.H
Go to the documentation of this file.
1 /*
2  * preprocessor : very basic preprocessor metaprogramming
3  */
4 
5 #ifndef HOBBES_LANG_PREPROCESSOR_HPP_INCLUDED
6 #define HOBBES_LANG_PREPROCESSOR_HPP_INCLUDED
7 
8 namespace hobbes {
9 
10 #define _HOBPP_FIRST(a, ...) a
11 #define _HOBPP_SECOND(a, b, ...) b
12 #define _HOBPP_CAT(a,b) a ## b
13 #define _HOBPP_IS_PROBE(...) _HOBPP_SECOND(__VA_ARGS__, 0)
14 #define _HOBPP_PROBE() ~, 1
15 #define _HOBPP_NOT(x) _HOBPP_IS_PROBE(_HOBPP_CAT(_HOBPP__NOT_, x))
16 #define _HOBPP__NOT_0 _HOBPP_PROBE()
17 #define _HOBPP_BOOL(x) _HOBPP_NOT(_HOBPP_NOT(x))
18 #define _HOBPP_IF_ELSE(condition) _HOBPP__IF_ELSE(_HOBPP_BOOL(condition))
19 #define _HOBPP__IF_ELSE(condition) _HOBPP_CAT(_HOBPP__IF_, condition)
20 #define _HOBPP__IF_1(...) __VA_ARGS__ _HOBPP__IF_1_ELSE
21 #define _HOBPP__IF_0(...) _HOBPP__IF_0_ELSE
22 #define _HOBPP__IF_1_ELSE(...)
23 #define _HOBPP__IF_0_ELSE(...) __VA_ARGS__
24 #define _HOBPP_EMPTY()
25 #define _HOBPP_EVAL(...) _HOBPP_EVAL256(__VA_ARGS__)
26 #define _HOBPP_EVAL256(...) _HOBPP_EVAL128(_HOBPP_EVAL128(__VA_ARGS__))
27 #define _HOBPP_EVAL128(...) _HOBPP_EVAL64(_HOBPP_EVAL64(__VA_ARGS__))
28 #define _HOBPP_EVAL64(...) _HOBPP_EVAL32(_HOBPP_EVAL32(__VA_ARGS__))
29 #define _HOBPP_EVAL32(...) _HOBPP_EVAL16(_HOBPP_EVAL16(__VA_ARGS__))
30 #define _HOBPP_EVAL16(...) _HOBPP_EVAL8(_HOBPP_EVAL8(__VA_ARGS__))
31 #define _HOBPP_EVAL8(...) _HOBPP_EVAL4(_HOBPP_EVAL4(__VA_ARGS__))
32 #define _HOBPP_EVAL4(...) _HOBPP_EVAL2(_HOBPP_EVAL2(__VA_ARGS__))
33 #define _HOBPP_EVAL2(...) _HOBPP_EVAL1(_HOBPP_EVAL1(__VA_ARGS__))
34 #define _HOBPP_EVAL1(...) __VA_ARGS__
35 #define _HOBPP_DEFER2(m) m _HOBPP_EMPTY _HOBPP_EMPTY()()
36 #define _HOBPP_HAS_PARGS(...) _HOBPP_BOOL(_HOBPP_FIRST(_HOBPP__EOAP_ __VA_ARGS__)())
37 #define _HOBPP__EOAP_(...) _HOBPP_BOOL(_HOBPP_FIRST(_HOBPP__EOA_ __VA_ARGS__)())
38 #define _HOBPP__EOA_() 0
39 #define _HOBPP_MAP(f, VS...) _HOBPP_EVAL(_HOBPP_MAPP(f, VS))
40 #define _HOBPP_MAPP(f, H, T...) \
41  f H \
42  _HOBPP_IF_ELSE(_HOBPP_HAS_PARGS(T))( \
43  _HOBPP_DEFER2(_HOBPP__MAPP)()(f, T) \
44  )( \
45  )
46 #define _HOBPP__MAPP() _HOBPP_MAPP
47 
48 }
49 
50 #endif
51 
Definition: boot.H:7