aboutsummaryrefslogtreecommitdiff
path: root/src/utils.h
blob: 16679e410c25a8a9f43aa369607ec3a0eb0157b9 (plain)
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
#ifndef INCLUDED_UTILS_H
#define INCLUDED_UTILS_H

#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <assert.h>

#define UNUSED(X) ((void) (X))
#define UNREACHABLE() ASSERT (!"reached the unreachable...")
#define TODO(STR) fprintf (stderr, "%s:%d: warning: TODO "STR"\n", __FILE__, __LINE__)
// #define TODO(...)
#define REACHED(FMT, ...) fprintf (stderr, "%s:%d: info: %s: reached: "FMT"\n", __FILE__, __LINE__, __func__ __VA_OPT__(,) __VA_ARGS__)

#define ASSERT assert
#define REALLOC realloc
#define FREE free

#define DIE(FMT, ...)                                           \
  ({                                                            \
    fprintf (stderr, FMT "\n" __VA_OPT__(,) __VA_ARGS__);       \
    exit (EXIT_FAILURE);                                        \
  })

#define ARRAY_LEN(array) (sizeof (array)/sizeof (*array))
#define ARRAY_GET(array, index) \
    (ASSERT(index >= 0), ASSERT(index < ARRAY_LEN(array)), array[index])

#define MIN(a, b) (((a) < (b)) ? (a) : (b))

struct string_views {
  struct string_view *items;
  uint32_t            count;
  uint32_t            capacity;
};

#endif