move all error related state to a record
This commit is contained in:
@@ -36,33 +36,40 @@
|
||||
|
||||
#include "YapErrors.h"
|
||||
|
||||
struct yami *Yap_Error__(const char *file, const char *function, int lineno, yap_error_number err,YAP_Term wheret, ...);
|
||||
#define MAX_ERROR_MSG_SIZE 10
|
||||
|
||||
#define Yap_NilError( id, ...) Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, TermNil, __VA_ARGS__)
|
||||
struct yami *Yap_Error__(const char *file, const char *function, int lineno,
|
||||
yap_error_number err, YAP_Term wheret, ...);
|
||||
|
||||
#define Yap_Error( id, inp, ...) Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, inp, __VA_ARGS__)
|
||||
#define Yap_NilError(id, ...) \
|
||||
Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, TermNil, __VA_ARGS__)
|
||||
|
||||
#define Yap_Error(id, inp, ...) \
|
||||
Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, inp, __VA_ARGS__)
|
||||
|
||||
#ifdef YAP_TERM_H
|
||||
/**
|
||||
* make sure next argument is a bound instance of type
|
||||
/**
|
||||
* make sure next argument is a bound instance of type
|
||||
* atom.
|
||||
*/
|
||||
#define Yap_ensure_atom( T0, TF ) { if ( (TF = Yap_ensure_atom__(__FILE__, __FUNCTION__, __LINE__, T0 ) == 0L ) return false; }
|
||||
#define Yap_ensure_atom(T0, TF) \
|
||||
{ if ( (TF = Yap_ensure_atom__(__FILE__, __FUNCTION__, __LINE__, T0 ) == 0L ) return false; \
|
||||
}
|
||||
|
||||
INLINE_ONLY extern inline Term
|
||||
Yap_ensure_atom__( const char *fu, const char *fi, int line, Term in )
|
||||
{
|
||||
INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
|
||||
int line, Term in) {
|
||||
Term t = Deref(in);
|
||||
//Term Context = Deref(ARG2);
|
||||
// Term Context = Deref(ARG2);
|
||||
if (!IsVarTerm(t) && IsAtomTerm(t))
|
||||
return t;
|
||||
if (IsVarTerm(t)) {
|
||||
Yap_Error__(fu, fi, line, INSTANTIATION_ERROR, t, NULL);
|
||||
} else {
|
||||
if ( IsAtomTerm(t) ) return t ;
|
||||
Yap_Error__(fu, fi, line, TYPE_ERROR_ATOM, t, NULL);
|
||||
return 0L;
|
||||
}
|
||||
if (IsAtomTerm(t))
|
||||
return t;
|
||||
Yap_Error__(fu, fi, line, TYPE_ERROR_ATOM, t, NULL);
|
||||
return 0L;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -74,7 +81,7 @@ Yap_ensure_atom__( const char *fu, const char *fi, int line, Term in )
|
||||
goto LAB; \
|
||||
}
|
||||
|
||||
#define LOCAL_ERROR(t, v) \
|
||||
#define LOCAL_ERROR(t, v) \
|
||||
if (HR + (v) > ASP - 1024) { \
|
||||
LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \
|
||||
LOCAL_Error_Term = t; \
|
||||
@@ -82,7 +89,7 @@ Yap_ensure_atom__( const char *fu, const char *fi, int line, Term in )
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
#define LOCAL_TERM_ERROR(t, v) \
|
||||
#define LOCAL_TERM_ERROR(t, v) \
|
||||
if (HR + (v) > ASP - 1024) { \
|
||||
LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \
|
||||
LOCAL_Error_Term = t; \
|
||||
@@ -138,4 +145,67 @@ Yap_ensure_atom__( const char *fu, const char *fi, int line, Term in )
|
||||
goto LAB; \
|
||||
}
|
||||
|
||||
/**
|
||||
* Error stages since it was initially processed.
|
||||
*
|
||||
* Notice that some of the stages may be active simultaneouly.
|
||||
*/
|
||||
typedef enum yap_error_status {
|
||||
/// where we like to be
|
||||
YAP_NO_ERROR_STATUS = 0x0,
|
||||
/// Prolog discovered the problem
|
||||
YAP_ERROR_INITIATED_IN_PROLOG = 0x1,
|
||||
/// The problem was found before the system can cope
|
||||
YAP_ERROR_INITIATED_IN_BOOT = 0x2,
|
||||
/// C-helper like must_ found out the problem
|
||||
YAP_ERROR_INITIATED_IN_HELPER = 0x4,
|
||||
/// C-builtin crashed
|
||||
YAP_ERROR_INITIATED_IN_SYSTEM_C = 0x8,
|
||||
/// user code crashed
|
||||
YAP_ERROR_INITIATED_IN_USER_C = 0x10,
|
||||
/// ok, we put a throw to be dispatched
|
||||
YAP_THROW_THROWN = 0x20,
|
||||
/// someone caught it
|
||||
YAP_THROW_CAUGHT = 0x40,
|
||||
/// error became an exception (usually SWIG bridge)
|
||||
YAP_ERROR_EXPORTED_TO_CXX = 0x80,
|
||||
/// handle error in Prolog
|
||||
YAP_ERROR_BEING_PROCESSED_IN_PROLOG = 0x100
|
||||
/// go back t
|
||||
} yap_error_stage_t;
|
||||
|
||||
/// all we need to know about an error/throw
|
||||
typedef struct yap_error_descriptor {
|
||||
enum yap_error_status status;
|
||||
yap_error_class_number errorClass;
|
||||
yap_error_number errorNo;
|
||||
YAP_Int errorLine;
|
||||
const char *errorFunction;
|
||||
const char *errorFile;
|
||||
YAP_Int prologPredCl;
|
||||
YAP_UInt prologPredLine;
|
||||
YAP_UInt prologPredFirstLine;
|
||||
YAP_UInt prologPredLastLine;
|
||||
YAP_Atom prologPredName;
|
||||
YAP_UInt prologPredArity;
|
||||
YAP_Term prologPredModule;
|
||||
YAP_Atom prologPredFile;
|
||||
struct DB_TERM *errorTerm;
|
||||
char errorComment[MAX_ERROR_MSG_SIZE];
|
||||
size_t errorMsgLen;
|
||||
} yap_error_descriptor_t;
|
||||
|
||||
/// compatibility with existing code..
|
||||
#define LOCAL_Error_TYPE LOCAL_ActiveError.errorNo
|
||||
#define LOCAL_Error_File LOCAL_ActiveError.errorFile
|
||||
#define LOCAL_Error_Function LOCAL_ActiveError.errorFunction
|
||||
#define LOCAL_Error_Lineno LOCAL_ActiveError.errorLine
|
||||
#define LOCAL_Error_Size LOCAL_ActiveError.errorMsgLen
|
||||
#define LOCAL_ErrorSay LOCAL_ActiveError.errorComment
|
||||
|
||||
extern bool Yap_find_prolog_culprit();
|
||||
extern yap_error_class_number Yap_errorClass(yap_error_number e);
|
||||
extern const char *Yap_errorName(yap_error_number e);
|
||||
extern const char *Yap_errorClassName(yap_error_class_number e);
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user