diff options
Diffstat (limited to 'src/utils.h')
| -rw-r--r-- | src/utils.h | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/utils.h b/src/utils.h new file mode 100644 index 0000000..16679e4 --- /dev/null +++ b/src/utils.h | |||
| @@ -0,0 +1,37 @@ | |||
| 1 | #ifndef INCLUDED_UTILS_H | ||
| 2 | #define INCLUDED_UTILS_H | ||
| 3 | |||
| 4 | #include <stdlib.h> | ||
| 5 | #include <stdint.h> | ||
| 6 | #include <stdio.h> | ||
| 7 | #include <assert.h> | ||
| 8 | |||
| 9 | #define UNUSED(X) ((void) (X)) | ||
| 10 | #define UNREACHABLE() ASSERT (!"reached the unreachable...") | ||
| 11 | #define TODO(STR) fprintf (stderr, "%s:%d: warning: TODO "STR"\n", __FILE__, __LINE__) | ||
| 12 | // #define TODO(...) | ||
| 13 | #define REACHED(FMT, ...) fprintf (stderr, "%s:%d: info: %s: reached: "FMT"\n", __FILE__, __LINE__, __func__ __VA_OPT__(,) __VA_ARGS__) | ||
| 14 | |||
| 15 | #define ASSERT assert | ||
| 16 | #define REALLOC realloc | ||
| 17 | #define FREE free | ||
| 18 | |||
| 19 | #define DIE(FMT, ...) \ | ||
| 20 | ({ \ | ||
| 21 | fprintf (stderr, FMT "\n" __VA_OPT__(,) __VA_ARGS__); \ | ||
| 22 | exit (EXIT_FAILURE); \ | ||
| 23 | }) | ||
| 24 | |||
| 25 | #define ARRAY_LEN(array) (sizeof (array)/sizeof (*array)) | ||
| 26 | #define ARRAY_GET(array, index) \ | ||
| 27 | (ASSERT(index >= 0), ASSERT(index < ARRAY_LEN(array)), array[index]) | ||
| 28 | |||
| 29 | #define MIN(a, b) (((a) < (b)) ? (a) : (b)) | ||
| 30 | |||
| 31 | struct string_views { | ||
| 32 | struct string_view *items; | ||
| 33 | uint32_t count; | ||
| 34 | uint32_t capacity; | ||
| 35 | }; | ||
| 36 | |||
| 37 | #endif | ||
