Add macro M_GET_AT.

This commit is contained in:
Patrick Pelissier committed 2018-07-04 17:39:03 +02:00
1 parent e23616169b
commit 8dafe3b7a6
3 files changed
+26

No files matched your search

+14
View File
@@ -3920,6 +3920,20 @@ Keep the medium arguments of the argument list,
starting from the 'first'-th one and up to 'len' arguments.
first and len can be within [0..52].
##### M\_GET\_AT(array, index)
Return the index 'index' of the "array" 'array'.
array in this context is a list of arguments encapsulated with parenthesis,
and is not a true C array.
Return the pre-processing token corresponding to this value (meaning it is evaluated
at macro processing stage, not at compiler stage).
Example:
M_GET_AT((f_0,f_1,f_2),1)
##### M\_BOOL(cond)
Convert an integer or a symbol into 0 (if 0) or 1 (if not 0 or symbol unknown).
+9
View File
@@ -622,6 +622,15 @@
#define M_MID(first, len, ...) M_MIDI(M_KEEP,len, M_SKIP(first, __VA_ARGS__))
#define M_MIDI(f, ...) f(__VA_ARGS__)
/* Return the value of the "array" associated to the given index.
EXAMPLE: M_GET_AT((f_0,f_1,f_2),1) returns f_1
Can be chained with NARGS().
*/
#define M_GET_AT(array, index) M_GETI_AT0(M_C(M_RET_ARG,M_INC(index)), array)
#define M_GETI_AT0(func, array) func ( M_ID array , dummy )
/* Convert an integer or a symbol into 0 (if 0) or 1 (if not 0).
1 if symbol unknown */
#define M_TOBOOLI_0 1, 0,
+3
View File
@@ -120,6 +120,9 @@ static void test_return(void)
assert (M_RET_ARG2(0, 1, 0));
assert (M_RET_ARG3(0, 0, 1, 0));
assert (M_RET_ARG27(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0));
assert (M_GET_AT((0,1,0),1));
assert (M_GET_AT((1,0,0),0));
assert (M_GET_AT((0,0,0,1),3));
}
static void test_invert(void)