aboutsummaryrefslogtreecommitdiff
path: root/lib/cbit/misc.h
blob: 3be6dc4b48f61aee66bdd818fd6bb1accccbde24 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once

#define UNUSED_STATIC_INLINE __attribute__((unused)) static inline

#define LET_LOOP__(expr, ctr) \
    if (0) \
       __done_##ctr: continue; \
    else if (0) \
       __break_##ctr: break; \
    else \
        for (expr; ;) \
            if (1) \
                goto __body_##ctr; \
            else \
                for (;;) \
                    if (1) \
                        goto __break_##ctr; \
                    else \
                        for (;;) \
                            if (1) \
                                goto __done_##ctr; \
                            else \
                                __body_##ctr:

#define LET_LOOP_(expr, ctr) LET_LOOP__(expr, ctr)
#define LET_LOOP(expr) LET_LOOP_(expr, __COUNTER__)

#define LET__(expr, ctr) \
    if (0) \
      __done_##ctr:; \
    else \
        for (expr; ;) \
            if (1) \
                goto __body_##ctr; \
            else \
                for (;;) \
                    if (1) \
                        goto __done_##ctr; \
                    else \
                        __body_##ctr:

#define LET_(expr, ctr) LET__(expr, ctr)
#define LET(expr) LET_(expr, __COUNTER__)

/* XXX */
#define safe_mul(a, b) ((a) * (b))
#define safe_add(a, b) ((a) + (b))