diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-14 17:00:15 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-14 17:00:15 -0400 |
| commit | 938b9b96e20d7233492dbdb2fbb396ffebb51b96 (patch) | |
| tree | 8235dac9ae352f1b708d12a491acd6650720cefc /src/stdlib/mapmacro.h | |
| parent | c3cec08ce94b25eb19588d333c738a24e96abac4 (diff) | |
Reworking of stack traces (back to using addr2line) for compatibility
and improved output quality
Diffstat (limited to 'src/stdlib/mapmacro.h')
| -rw-r--r-- | src/stdlib/mapmacro.h | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/stdlib/mapmacro.h b/src/stdlib/mapmacro.h new file mode 100644 index 00000000..5ed7a4b7 --- /dev/null +++ b/src/stdlib/mapmacro.h @@ -0,0 +1,29 @@ +#pragma once + +// This file defines a MAP_LIST(fn, ...) function that applies a function to +// every one of the varargs. +// For example: baz(MAP_LIST(foo, 1, "x")) -> baz(foo(1), foo("x")) + +#define EVAL0(...) __VA_ARGS__ +#define EVAL1(...) EVAL0(EVAL0(EVAL0(__VA_ARGS__))) +#define EVAL2(...) EVAL1(EVAL1(EVAL1(__VA_ARGS__))) +#define EVAL3(...) EVAL2(EVAL2(EVAL2(__VA_ARGS__))) +#define EVAL4(...) EVAL3(EVAL3(EVAL3(__VA_ARGS__))) +#define EVAL(...) EVAL4(EVAL4(EVAL4(__VA_ARGS__))) + +#define MAP_END(...) +#define MAP_OUT +#define MAP_COMMA , + +#define MAP_GET_END2() 0, MAP_END +#define MAP_GET_END1(...) MAP_GET_END2 +#define MAP_GET_END(...) MAP_GET_END1 +#define MAP_NEXT0(test, next, ...) next MAP_OUT + +#define MAP_LIST_NEXT1(test, next) MAP_NEXT0(test, MAP_COMMA next, 0) +#define MAP_LIST_NEXT(test, next) MAP_LIST_NEXT1(MAP_GET_END test, next) + +#define MAP_LIST0(f, x, peek, ...) f(x) MAP_LIST_NEXT(peek, MAP_LIST1)(f, peek, __VA_ARGS__) +#define MAP_LIST1(f, x, peek, ...) f(x) MAP_LIST_NEXT(peek, MAP_LIST0)(f, peek, __VA_ARGS__) + +#define MAP_LIST(f, ...) EVAL(MAP_LIST1(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) |
