Add Bocfel interpreter
[projects/chimara/chimara.git] / interpreters / bocfel / util.h
1 #ifndef ZTERP_UTIL_H
2 #define ZTERP_UTIL_H
3
4 #ifdef ZTERP_GLK
5 #include <glk.h>
6 #endif
7
8 #if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 7))
9 #define znoreturn               __attribute__((__noreturn__))
10 #define zprintflike(f, a)       __attribute__((__format__(__printf__, f, a)))
11 #else
12 #define znoreturn
13 #define zprintflike(f, a)
14 #endif
15
16 #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1))
17 #define zexternally_visible     __attribute__((__externally_visible__))
18 #else
19 #define zexternally_visible
20 #endif
21
22 #ifndef ZTERP_NO_SAFETY_CHECKS
23 extern unsigned long zassert_pc;
24 #define ZPC(pc)         do { zassert_pc = pc; } while(0)
25
26 zprintflike(1, 2)
27 znoreturn
28 void assert_fail(const char *, ...);
29 #define ZASSERT(expr, ...) do { if(!(expr)) assert_fail(__VA_ARGS__); } while(0)
30 #else
31 #define ZPC(pc)                 ((void)0)
32 #define ZASSERT(expr, ...)      ((void)0)
33 #endif
34
35 zprintflike(1, 2)
36 void warning(const char *, ...);
37
38 zprintflike(1, 2)
39 znoreturn
40 void die(const char *, ...);
41
42 char *xstrdup(const char *);
43 int process_arguments(int, char **);
44
45 /* Somewhat ugly hack to get around the fact that some Glk functions may
46  * not exist.  These function calls should all be guarded (e.g.
47  * if(have_unicode), with have_unicode being set iff GLK_MODULE_UNICODE
48  * is defined) so they will never be called if the Glk implementation
49  * being used does not support them, but they must at least exist to
50  * prevent link errors.
51  */
52 #ifdef ZTERP_GLK
53 #ifndef GLK_MODULE_UNICODE
54 #define glk_put_char_uni(...)           die("bug %s:%d: glk_put_char_uni() called with no unicode", __FILE__, __LINE__)
55 #define glk_put_string_uni(...)         die("bug %s:%d: glk_put_string_uni() called with no unicode", __FILE__, __LINE__)
56 #define glk_request_char_event_uni(...) die("bug %s:%d: glk_request_char_event_uni() called with no unicode", __FILE__, __LINE__)
57 #define glk_request_line_event_uni(...) die("bug %s:%d: glk_request_line_event_uni() called with no unicode", __FILE__, __LINE__)
58 #endif
59 #ifndef GLK_MODULE_LINE_ECHO
60 #define glk_set_echo_line_event(...)    die("bug: %s %d: glk_set_echo_line_event() called with no line echo", __FILE__, __LINE__)
61 #endif
62 #endif
63
64 #endif