klisp

an open source interpreter for the Kernel Programming Language.
git clone http://git.hanabi.in/repos/klisp.git
Log | Files | Refs | README

kerror.h (2619B)


      1 /*
      2 ** kerror.h
      3 ** Simple error notification and handling (TEMP)
      4 ** See Copyright Notice in klisp.h
      5 */
      6 
      7 
      8 #ifndef kerror_h
      9 #define kerror_h
     10 
     11 #include <stdbool.h>
     12 #include <errno.h>
     13 
     14 #include "klisp.h"
     15 #include "kstate.h"
     16 #include "kpair.h" /* for klist */
     17 
     18 TValue klispE_new(klisp_State *K, TValue who, TValue cont, TValue msg, 
     19                   TValue irritants);
     20 TValue klispE_new_with_errno_irritants(klisp_State *K, const char *service, 
     21                                        int errnum, TValue irritants);
     22 
     23 void klispE_free(klisp_State *K, Error *error);
     24 
     25 void klispE_throw_simple(klisp_State *K, char *msg);
     26 void klispE_throw_with_irritants(klisp_State *K, char *msg, TValue irritants);
     27 
     28 void klispE_throw_system_error_with_irritants(
     29     klisp_State *K, const char *service, int errnum, TValue irritants);
     30 
     31 /* the objects should be rooted */
     32 #define klispE_new_simple_with_errno_irritants(K__, service__, ...)     \
     33     ({                                                                  \
     34         int errnum__ = errno;                                           \
     35         TValue ls__ = klist(K__, __VA_ARGS__);                          \
     36         krooted_tvs_push(K__, ls__);                                    \
     37         TValue err__ = klispE_new_with_errno_irritants(K__, service__,	\
     38                                                        errnum__, ls__);	\
     39         krooted_tvs_pop(K__);                                           \
     40         err__;                                                          \
     41     })
     42 
     43 /* evaluates K__ more than once */
     44 /* the objects should be rooted */
     45 #define klispE_throw_simple_with_irritants(K__, msg__, ...) \
     46     { TValue ls__ = klist(K__, __VA_ARGS__);				\
     47         krooted_tvs_push(K__, ls__);                        \
     48         /* the pop is implicit in throw_with_irritants */   \
     49         klispE_throw_with_irritants(K__, msg__, ls__); }
     50 
     51 /* the objects should be rooted */
     52 #define klispE_throw_errno_with_irritants(K__, service__, ...)          \
     53     {                                                                   \
     54         int errnum__ = errno;                                           \
     55         TValue ls__ = klist(K__, __VA_ARGS__);                          \
     56         krooted_tvs_push(K__, ls__);                                    \
     57         klispE_throw_system_error_with_irritants(K__, service__, errnum__, ls__); \
     58     }
     59 
     60 #define klispE_throw_errno_simple(K__, service__)                       \
     61     klispE_throw_system_error_with_irritants(K__, service__, errno, KNIL);
     62 
     63 TValue klispE_describe_errno(klisp_State *K, const char *service, int errnum);
     64 
     65 #endif