blob: 1540ff99e0ccdd779b9cfb9b295bfd8b6a8ef3bd [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);
swissChili4bccd442020-08-11 13:55:10 -070031void unwind();
swissChilib71e0272020-08-08 15:56:14 -070032void catch_(handle_t hdl, intptr_t arg);
33
34#define THROW(msg) throw_(msg, __FILENAME__, __LINE__)
35#define CATCH(fn, arg) catch_((handle_t) fn, (intptr_t) arg)