blob: e1e297f7a4b65829d37029be55d24f7f63601dfd [file] [log] [blame]
swissChilib71e0272020-08-08 15:56:14 -07001#pragma once
2
3#include <stdint.h>
4#include <string.h>
5
6#define __FILENAME__ \
7 (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 \
8 : strrchr(__FILE__, '\\') ? strrchr(__FILE__, '\\') + 1 : __FILE__)
9
10
11#define ASSERT(message, body) \
12 { \
swissChilic6b4f7e2020-08-09 16:36:36 -070013 if (!(body)) \
swissChilib71e0272020-08-08 15:56:14 -070014 THROW("Assert failed: " message " [" #body "]"); \
15 }
16
17#define MAX_CATCH_LEN 32
18
19typedef void (* handle_t)(intptr_t);
20
21typedef struct
22{
23 handle_t fn;
24 intptr_t arg;
25} catch_t;
26
27extern catch_t g_catch[MAX_CATCH_LEN];
28extern unsigned g_catch_len;
29
30void throw_(const char *msg, const char *file, unsigned int line);
31void catch_(handle_t hdl, intptr_t arg);
32
33#define THROW(msg) throw_(msg, __FILENAME__, __LINE__)
34#define CATCH(fn, arg) catch_((handle_t) fn, (intptr_t) arg)