1 // Built-in utility functions
11 #define streq(a, b) (((a) == NULL && (b) == NULL) || (((a) == NULL) == ((b) == NULL) && strcmp(a, b) == 0))
12 #define starts_with(line, prefix) (strncmp(line, prefix, strlen(prefix)) == 0)
13 #define ends_with(line, suffix) \
14 (strlen(line) >= strlen(suffix) && strcmp(line + strlen(line) - strlen(suffix), suffix) == 0)
15 #define new(t, ...) ((t *)memcpy(GC_MALLOC(sizeof(t)), &(t){__VA_ARGS__}, sizeof(t)))
16 #define heap(x) (__typeof(x) *)memcpy(GC_MALLOC(sizeof(x)), (__typeof(x)[1]){x}, sizeof(x))
17 #define stack(x) (__typeof(x) *)((__typeof(x)[1]){x})
18 #define check_initialized(var, init_var, name) \
20 if (!init_var) fail("The variable " name " is being accessed before it has been initialized!"); \
24 #define WHEN(type, subj, var, body) \
32 #define public __attribute__((visibility("default")))
36 #define PUREFUNC __attribute__((pure))
40 #define CONSTFUNC __attribute__((const))
44 #define INLINE inline __attribute__((always_inline))
48 #define likely(x) (__builtin_expect(!!(x), 1))
52 #define unlikely(x) (__builtin_expect(!!(x), 0))
55 // GCC lets you define macro-like functions which are always inlined and never
56 // compiled using this combination of flags. See: https://gcc.gnu.org/onlinedocs/gcc/Inline.html
59 #define MACROLIKE static inline __attribute__((gnu_inline, always_inline))
61 #define MACROLIKE extern inline __attribute__((gnu_inline, always_inline))