CHERIoT RTOS
A compartmentalised RTOS for CHERIoT hardware
Toggle main menu visibility
Loading...
Searching...
No Matches
sdk
include
__macro_map.h
1
/*
2
* Created by William Swanson in 2012.
3
*
4
* I, William Swanson, dedicate this work to the public domain.
5
* I waive all rights to the work worldwide under copyright law,
6
* including all related and neighboring rights,
7
* to the extent allowed by law.
8
*
9
* You can copy, modify, distribute and perform the work,
10
* even for commercial purposes, all without asking permission.
11
*/
12
/*
13
* The CHERIoT import is taken from https://github.com/swansontec/map-macro,
14
* specifically, the commit with SHA-1 033a3e7f151c9f3e1baabfe3868a3a8ef2bb0304
15
* and lightly modified as follows:
16
* - Added CHERIOT_ prefix to all macros to avoid namespace pollution
17
* - Used pragma once instead of include guards
18
* - Formatted to fit local conventions
19
* - Removed the MAP_UD_I and MAP_LIST_UD_I variants (and the MAP_INC* helpers)
20
*/
21
22
#pragma once
23
24
#define CHERIOT_EVAL0(...) __VA_ARGS__
25
#define CHERIOT_EVAL1(...) \
26
CHERIOT_EVAL0(CHERIOT_EVAL0(CHERIOT_EVAL0(__VA_ARGS__)))
27
#define CHERIOT_EVAL2(...) \
28
CHERIOT_EVAL1(CHERIOT_EVAL1(CHERIOT_EVAL1(__VA_ARGS__)))
29
#define CHERIOT_EVAL3(...) \
30
CHERIOT_EVAL2(CHERIOT_EVAL2(CHERIOT_EVAL2(__VA_ARGS__)))
31
#define CHERIOT_EVAL4(...) \
32
CHERIOT_EVAL3(CHERIOT_EVAL3(CHERIOT_EVAL3(__VA_ARGS__)))
33
#define CHERIOT_EVAL(...) \
34
CHERIOT_EVAL4(CHERIOT_EVAL4(CHERIOT_EVAL4(__VA_ARGS__)))
35
36
#define CHERIOT_MAP_END(...)
37
#define CHERIOT_MAP_OUT
38
#define CHERIOT_MAP_COMMA ,
39
40
#define CHERIOT_MAP_GET_END2() 0, CHERIOT_MAP_END
41
#define CHERIOT_MAP_GET_END1(...) CHERIOT_MAP_GET_END2
42
#define CHERIOT_MAP_GET_END(...) CHERIOT_MAP_GET_END1
43
#define CHERIOT_MAP_NEXT0(test, next, ...) next CHERIOT_MAP_OUT
44
#define CHERIOT_MAP_NEXT1(test, next) CHERIOT_MAP_NEXT0(test, next, 0)
45
#define CHERIOT_MAP_NEXT(test, next) \
46
CHERIOT_MAP_NEXT1(CHERIOT_MAP_GET_END test, next)
47
48
#define CHERIOT_MAP0(f, x, peek, ...) \
49
f(x) CHERIOT_MAP_NEXT(peek, CHERIOT_MAP1)(f, peek, __VA_ARGS__)
50
#define CHERIOT_MAP1(f, x, peek, ...) \
51
f(x) CHERIOT_MAP_NEXT(peek, CHERIOT_MAP0)(f, peek, __VA_ARGS__)
52
53
#define CHERIOT_MAP0_UD(f, ud, x, peek, ...) \
54
f(x, ud) CHERIOT_MAP_NEXT(peek, CHERIOT_MAP1_UD)(f, ud, peek, __VA_ARGS__)
55
#define CHERIOT_MAP1_UD(f, ud, x, peek, ...) \
56
f(x, ud) CHERIOT_MAP_NEXT(peek, CHERIOT_MAP0_UD)(f, ud, peek, __VA_ARGS__)
57
58
#define CHERIOT_MAP_LIST_NEXT1(test, next) \
59
CHERIOT_MAP_NEXT0(test, CHERIOT_MAP_COMMA next, 0)
60
#define CHERIOT_MAP_LIST_NEXT(test, next) \
61
CHERIOT_MAP_LIST_NEXT1(CHERIOT_MAP_GET_END test, next)
62
63
#define CHERIOT_MAP_LIST0(f, x, peek, ...) \
64
f(x) CHERIOT_MAP_LIST_NEXT(peek, CHERIOT_MAP_LIST1)(f, peek, __VA_ARGS__)
65
#define CHERIOT_MAP_LIST1(f, x, peek, ...) \
66
f(x) CHERIOT_MAP_LIST_NEXT(peek, CHERIOT_MAP_LIST0)(f, peek, __VA_ARGS__)
67
68
#define CHERIOT_MAP_LIST0_UD(f, ud, x, peek, ...) \
69
f(x, ud) CHERIOT_MAP_LIST_NEXT(peek, CHERIOT_MAP_LIST1_UD)( \
70
f, ud, peek, __VA_ARGS__)
71
#define CHERIOT_MAP_LIST1_UD(f, ud, x, peek, ...) \
72
f(x, ud) CHERIOT_MAP_LIST_NEXT(peek, CHERIOT_MAP_LIST0_UD)( \
73
f, ud, peek, __VA_ARGS__)
74
75
/**
76
* Applies the function macro `f` to each of the remaining parameters.
77
*/
78
#define CHERIOT_MAP(f, ...) \
79
CHERIOT_EVAL(CHERIOT_MAP1(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
80
81
/**
82
* Applies the function macro `f` to each of the remaining parameters and passes
83
* userdata as the second parameter to each invocation, e.g. MAP_UD(f, x, a, b,
84
* c) evaluates to f(a, x) f(b, x) f(c, x)
85
*/
86
#define CHERIOT_MAP_UD(f, ud, ...) \
87
CHERIOT_EVAL(CHERIOT_MAP1_UD(f, ud, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
88
89
/**
90
* Applies the function macro `f` to each of the remaining parameters and
91
* inserts commas between the results.
92
*/
93
#define CHERIOT_MAP_LIST(f, ...) \
94
CHERIOT_EVAL(CHERIOT_MAP_LIST1(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
95
96
/**
97
* Applies the function macro `f` to each of the remaining parameters, inserts
98
* commas between the results, and passes userdata as the second parameter to
99
* each invocation, e.g. MAP_LIST_UD(f, x, a, b, c) evaluates to f(a, x), f(b,
100
* x), f(c, x)
101
*/
102
#define CHERIOT_MAP_LIST_UD(f, ud, ...) \
103
CHERIOT_EVAL( \
104
CHERIOT_MAP_LIST1_UD(f, ud, __VA_ARGS__, ()()(), ()()(), ()()(), 0))
Generated by
1.18.0