2022-01-24 03:28:16 +00:00
|
|
|
#ifndef LAIKA_ERROR_H
|
|
|
|
#define LAIKA_ERROR_H
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
|
2022-01-31 21:54:39 +00:00
|
|
|
#include "laika.h"
|
|
|
|
|
2022-01-24 03:28:16 +00:00
|
|
|
/* defines errorstack size */
|
|
|
|
#define LAIKA_MAXERRORS 32
|
|
|
|
|
|
|
|
/* DO NOT RETURN/GOTO/BREAK or otherwise skip LAIKA_TRYEND */
|
|
|
|
#define LAIKA_TRY if (setjmp(eLaika_errStack[++eLaika_errIndx]) == 0) {
|
|
|
|
#define LAIKA_CATCH } else {
|
|
|
|
#define LAIKA_TRYEND } --eLaika_errIndx;
|
|
|
|
|
|
|
|
/* if eLaika_errIndx is >= 0, we have a safe spot to jump too if an error is thrown */
|
|
|
|
#define LAIKA_ISPROTECTED (eLaika_errIndx >= 0)
|
|
|
|
|
2022-01-24 15:51:29 +00:00
|
|
|
/* LAIKA_ERROR(printf args):
|
2022-01-24 03:28:16 +00:00
|
|
|
if called after a LAIKA_TRY block will jump to the previous LAIKA_CATCH/LAIKA_TRYEND block,
|
|
|
|
otherwise program is exit()'d. if DEBUG is defined printf is called with passed args, else
|
|
|
|
arguments are ignored.
|
|
|
|
*/
|
|
|
|
#ifndef DEBUG
|
2022-02-10 22:56:40 +00:00
|
|
|
#define LAIKA_ERROR(...) do { \
|
2022-01-24 03:28:16 +00:00
|
|
|
if (LAIKA_ISPROTECTED) \
|
|
|
|
longjmp(eLaika_errStack[eLaika_errIndx], 1); \
|
|
|
|
else \
|
|
|
|
exit(1); \
|
2022-02-10 22:56:40 +00:00
|
|
|
} while(0);
|
2022-03-28 19:02:33 +00:00
|
|
|
#define LAIKA_WARN(...) ((void)0) /* no op */
|
2022-01-24 03:28:16 +00:00
|
|
|
#else
|
2022-02-10 22:56:40 +00:00
|
|
|
#define LAIKA_ERROR(...) do { \
|
2022-01-24 03:28:16 +00:00
|
|
|
printf("[ERROR] : " __VA_ARGS__); \
|
|
|
|
if (LAIKA_ISPROTECTED) \
|
|
|
|
longjmp(eLaika_errStack[eLaika_errIndx], 1); \
|
|
|
|
else \
|
|
|
|
exit(1); \
|
2022-02-10 22:56:40 +00:00
|
|
|
} while(0);
|
2022-01-24 03:28:16 +00:00
|
|
|
|
2022-01-24 15:51:29 +00:00
|
|
|
#define LAIKA_WARN(...) \
|
2022-01-24 03:28:16 +00:00
|
|
|
printf("[WARN] : " __VA_ARGS__);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
extern int eLaika_errIndx;
|
|
|
|
extern jmp_buf eLaika_errStack[LAIKA_MAXERRORS];
|
|
|
|
|
|
|
|
#endif
|