except.h
Go to the documentation of this file.00001
00038 #ifndef MWARE_EXCEPT_H
00039 #define MWARE_EXCEPT_H
00040
00041 #include <cfg/debug.h>
00042
00043 #include <setjmp.h>
00044
00045 #define EXCEPT_CONTEXTS 8
00046
00056 extern jmp_buf except_stack[EXCEPT_CONTEXTS];
00057 extern int except_top;
00058
00059 #define PUSH_EXCEPT (ASSERT(except_top < EXCEPT_CONTEXTS), setjmp(except_stack[except_top++]))
00060 #define POP_EXCEPT (ASSERT(except_top > 0), --except_top)
00061 #define DO_EXCEPT (ASSERT(except_top > 0), longjmp(except_stack[--except_top], true))
00062
00113 #define TRY if (PUSH_EXCEPT) { {
00114 #define TRY_END } POP_EXCEPT; }
00115 #define CATCH } POP_EXCEPT; } else {
00116 #define CATCH_END }
00117 #define THROW DO_EXCEPT
00118
00119
00120 #define EXCEPT_DEFINE \
00121 jmp_buf except_stack[EXCEPT_CONTEXTS]; \
00122 int except_top;
00123
00124 #endif