move all error related state to a record

This commit is contained in:
Vitor Santos Costa 2016-09-20 22:52:34 -05:00
parent 6043125221
commit 124b2e9069
9 changed files with 547 additions and 424 deletions

View File

@ -11,7 +11,7 @@
* File: errors.c * * File: errors.c *
* Last Rev: * * Last Rev: *
* Mods: * * Mods: *
* Comments: Yap'S error handlers * * Comments: Yap's error handlers *
* * * *
*************************************************************************/ *************************************************************************/
@ -32,10 +32,9 @@
#endif #endif
#include "Foreign.h" #include "Foreign.h"
bool Yap_Warning(const char *s, ...) { bool Yap_Warning(const char *s, ...) {
CACHE_REGS CACHE_REGS
va_list ap; va_list ap;
PredEntry *pred; PredEntry *pred;
bool rc; bool rc;
Term ts[2]; Term ts[2];
@ -62,8 +61,7 @@ bool Yap_Warning(const char *s, ...) {
} else } else
return false; return false;
va_end(ap); va_end(ap);
if (pred->OpcodeOfPred == UNDEF_OPCODE|| if (pred->OpcodeOfPred == UNDEF_OPCODE || pred->OpcodeOfPred == FAIL_OPCODE) {
pred->OpcodeOfPred == FAIL_OPCODE) {
fprintf(stderr, "warning message: %s\n", tmpbuf); fprintf(stderr, "warning message: %s\n", tmpbuf);
LOCAL_DoingUndefp = false; LOCAL_DoingUndefp = false;
LOCAL_within_print_message = false; LOCAL_within_print_message = false;
@ -75,12 +73,27 @@ bool Yap_Warning(const char *s, ...) {
rc = Yap_execute_pred(pred, ts, true PASS_REGS); rc = Yap_execute_pred(pred, ts, true PASS_REGS);
return rc; return rc;
} }
void Yap_InitError(yap_error_number e, Term t, const char *msg) {
if (LOCAL_ActiveError.status) {
Yap_exit(1);
}
LOCAL_ActiveError.errorNo = e;
LOCAL_ActiveError.errorFile = NULL;
LOCAL_ActiveError.errorFunction = NULL;
LOCAL_ActiveError.errorLine = 0;
if (msg) {
LOCAL_Error_Size = strlen(msg);
strcpy(LOCAL_ActiveError.errorComment, msg);
} else {
LOCAL_Error_Size = 0;
}
}
bool Yap_PrintWarning(Term twarning) { bool Yap_PrintWarning(Term twarning) {
CACHE_REGS CACHE_REGS
PredEntry *pred = RepPredProp(PredPropByFunc( PredEntry *pred = RepPredProp(PredPropByFunc(
FunctorPrintMessage, PROLOG_MODULE)); // PROCEDURE_print_message2; FunctorPrintMessage, PROLOG_MODULE)); // PROCEDURE_print_message2;
Term cmod = ( CurrentModule == PROLOG_MODULE ? TermProlog : CurrentModule ); Term cmod = (CurrentModule == PROLOG_MODULE ? TermProlog : CurrentModule);
bool rc; bool rc;
Term ts[2]; Term ts[2];
@ -91,9 +104,7 @@ bool Yap_PrintWarning(Term twarning) {
} }
LOCAL_DoingUndefp = true; LOCAL_DoingUndefp = true;
LOCAL_within_print_message = true; LOCAL_within_print_message = true;
if (pred->OpcodeOfPred == UNDEF_OPCODE || if (pred->OpcodeOfPred == UNDEF_OPCODE || pred->OpcodeOfPred == FAIL_OPCODE) {
pred->OpcodeOfPred == FAIL_OPCODE
) {
fprintf(stderr, "warning message:\n"); fprintf(stderr, "warning message:\n");
Yap_DebugPlWrite(twarning); Yap_DebugPlWrite(twarning);
fprintf(stderr, "\n"); fprintf(stderr, "\n");
@ -105,19 +116,19 @@ bool Yap_PrintWarning(Term twarning) {
ts[1] = twarning; ts[1] = twarning;
ts[0] = MkAtomTerm(AtomWarning); ts[0] = MkAtomTerm(AtomWarning);
HB = B->cp_h = HR; HB = B->cp_h = HR;
B->cp_tr = TR; B->cp_tr = TR;
rc = Yap_execute_pred(pred, ts, true PASS_REGS); rc = Yap_execute_pred(pred, ts, true PASS_REGS);
LOCAL_within_print_message = false; LOCAL_within_print_message = false;
LOCAL_DoingUndefp = false; LOCAL_DoingUndefp = false;
return rc; return rc;
} }
bool Yap_HandleError__(const char *file, const char *function, int lineno, const char *s, ...) { bool Yap_HandleError__(const char *file, const char *function, int lineno,
const char *s, ...) {
CACHE_REGS CACHE_REGS
yap_error_number err = LOCAL_Error_TYPE; yap_error_number err = LOCAL_Error_TYPE;
const char *serr; const char *serr;
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_ErrorMessage) { if (LOCAL_ErrorMessage) {
serr = LOCAL_ErrorMessage; serr = LOCAL_ErrorMessage;
} else { } else {
@ -136,7 +147,8 @@ bool Yap_HandleError__(const char *file, const char *function, int lineno, const
} }
if (!Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE)) { if (!Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE)) {
/* crash in flames */ /* crash in flames */
Yap_Error__(file, function, lineno, RESOURCE_ERROR_AUXILIARY_STACK, ARG1, serr); Yap_Error__(file, function, lineno, RESOURCE_ERROR_AUXILIARY_STACK, ARG1,
serr);
return false; return false;
} }
return true; return true;
@ -153,10 +165,9 @@ bool Yap_HandleError__(const char *file, const char *function, int lineno, const
int Yap_SWIHandleError(const char *s, ...) { int Yap_SWIHandleError(const char *s, ...) {
CACHE_REGS CACHE_REGS
yap_error_number err = LOCAL_Error_TYPE; yap_error_number err = LOCAL_Error_TYPE;
char *serr; char *serr;
LOCAL_Error_TYPE = YAP_NO_ERROR;
if (LOCAL_ErrorMessage) { if (LOCAL_ErrorMessage) {
serr = LOCAL_ErrorMessage; serr = LOCAL_ErrorMessage;
} else { } else {
@ -193,28 +204,27 @@ int Yap_SWIHandleError(const char *s, ...) {
void Yap_RestartYap(int flag) { void Yap_RestartYap(int flag) {
CACHE_REGS CACHE_REGS
#if PUSH_REGS #if PUSH_REGS
restore_absmi_regs(&Yap_standard_regs); restore_absmi_regs(&Yap_standard_regs);
#endif #endif
siglongjmp(LOCAL_RestartEnv, 1); siglongjmp(LOCAL_RestartEnv, 1);
} }
static void error_exit_yap(int value) { static void error_exit_yap(int value) {
CACHE_REGS CACHE_REGS
if (!(LOCAL_PrologMode & BootMode)) { if (!(LOCAL_PrologMode & BootMode)) {
#if DEBUG #if DEBUG
#endif #endif
} }
fprintf(stderr, "\n Exiting ....\n"); fprintf(stderr, "\n Exiting ....\n");
#if HAVE_BACKTRACE #if HAVE_BACKTRACE
void *callstack[256]; void *callstack[256];
int i; int i;
int frames = backtrace(callstack, 256); int frames = backtrace(callstack, 256);
char** strs = backtrace_symbols(callstack, frames); char **strs = backtrace_symbols(callstack, frames);
fprintf(stderr, "Execution stack:\n"); fprintf(stderr, "Execution stack:\n");
for (i = 0; i < frames; ++i) { for (i = 0; i < frames; ++i) {
fprintf(stderr, " %s\n", strs[i]); fprintf(stderr, " %s\n", strs[i]);
} }
free(strs); free(strs);
#endif #endif
@ -243,45 +253,45 @@ static char tmpbuf[YAP_BUF_SIZE];
#undef E2 #undef E2
#undef END_ERRORS #undef END_ERRORS
#define BEGIN_ERROR_CLASSES() \ #define BEGIN_ERROR_CLASSES() \
static Term mkerrorct(yap_error_class_number c, Term *ts) { \ static Term mkerrorct(yap_error_class_number c, Term *ts) { \
switch (c) { switch (c) {
#define ECLASS(CL, A, B) \ #define ECLASS(CL, A, B) \
case CL: \ case CL: \
if (A == 0) \ if (A == 0) \
return MkAtomTerm(Yap_LookupAtom(A)); \ return MkAtomTerm(Yap_LookupAtom(A)); \
else { \ else { \
return Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom(A), B), B, ts); \ return Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom(A), B), B, ts); \
} }
#define END_ERROR_CLASSES() \ #define END_ERROR_CLASSES() \
} \ } \
} }
#define BEGIN_ERRORS() \ #define BEGIN_ERRORS() \
static Term mkerrort(yap_error_number e, Term *ts) { \ static Term mkerrort(yap_error_number e, Term *ts) { \
switch (e) { switch (e) {
#define E0(A, B) \ #define E0(A, B) \
case A: \ case A: \
return mkerrorct(B, ts); return mkerrorct(B, ts);
#define E(A, B, C) \ #define E(A, B, C) \
case A: \ case A: \
ts -= 1; \ ts -= 1; \
ts[0] = MkAtomTerm(Yap_LookupAtom(C)); \ ts[0] = MkAtomTerm(Yap_LookupAtom(C)); \
return mkerrorct(B, ts); return mkerrorct(B, ts);
#define E2(A, B, C, D) \ #define E2(A, B, C, D) \
case A: \ case A: \
ts -= 2; \ ts -= 2; \
ts[0] = MkAtomTerm(Yap_LookupAtom(C)); \ ts[0] = MkAtomTerm(Yap_LookupAtom(C)); \
ts[1] = MkAtomTerm(Yap_LookupAtom(D)); \ ts[1] = MkAtomTerm(Yap_LookupAtom(D)); \
return mkerrorct(B, ts); return mkerrorct(B, ts);
#define END_ERRORS() \ #define END_ERRORS() \
} \ } \
} }
#include "YapErrors.h" #include "YapErrors.h"
@ -322,10 +332,10 @@ static char tmpbuf[YAP_BUF_SIZE];
yamop *Yap_Error__(const char *file, const char *function, int lineno, yamop *Yap_Error__(const char *file, const char *function, int lineno,
yap_error_number type, Term where, ...) { yap_error_number type, Term where, ...) {
CACHE_REGS CACHE_REGS
va_list ap; va_list ap;
CELL nt[3]; CELL nt[3];
Functor fun; Functor fun;
Term error_t; Term error_t;
Term comment; Term comment;
char *format; char *format;
char s[MAXPATHLEN]; char s[MAXPATHLEN];
@ -336,15 +346,21 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
tmpbuf); tmpbuf);
Yap_RestartYap(1); Yap_RestartYap(1);
} }
LOCAL_ActiveError.errorNo = type;
LOCAL_ActiveError.errorClass = Yap_errorClass(LOCAL_ActiveError.errorNo);
LOCAL_ActiveError.errorLine = lineno;
LOCAL_ActiveError.errorFunction = function;
LOCAL_ActiveError.errorFile = file;
Yap_find_prolog_culprit(PASS_REGS1);
LOCAL_PrologMode |= InErrorMode; LOCAL_PrologMode |= InErrorMode;
LOCAL_Error_TYPE = YAP_NO_ERROR;
Yap_ClearExs(); Yap_ClearExs();
if (where == 0L) { if (where == 0L) {
where = TermNil; where = TermNil;
} }
// first, obtain current location // first, obtain current location
// sprintf(LOCAL_FileNameBuf, "%s:%d in C-function %s ", file, lineno, function); // sprintf(LOCAL_FileNameBuf, "%s:%d in C-function %s ", file, lineno,
// tf = MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)); // function);
// tf = MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf));
#if DEBUG_STRICT #if DEBUG_STRICT
if (Yap_heap_regs && !(LOCAL_PrologMode & BootMode)) if (Yap_heap_regs && !(LOCAL_PrologMode & BootMode))
fprintf(stderr, "***** Processing Error %d (%lx,%x) %s***\n", type, fprintf(stderr, "***** Processing Error %d (%lx,%x) %s***\n", type,
@ -416,14 +432,15 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
if (LOCAL_PrologMode & BootMode) { if (LOCAL_PrologMode & BootMode) {
/* crash in flames! */ /* crash in flames! */
fprintf(stderr, "%s:%d:0 YAP Fatal Error %d in function %s:\n %s exiting....\n", file, lineno, type, function, s); fprintf(stderr,
"%s:%d:0 YAP Fatal Error %d in function %s:\n %s exiting....\n",
file, lineno, type, function, s);
error_exit_yap(1); error_exit_yap(1);
} }
#ifdef DEBUG #ifdef DEBUG
// DumpActiveGoals( USES_REGS1 ); // DumpActiveGoals( USES_REGS1 );
#endif /* DEBUG */ #endif /* DEBUG */
if (!IsVarTerm(where) && if (!IsVarTerm(where) && IsApplTerm(where) &&
IsApplTerm(where) &&
FunctorOfTerm(where) == FunctorError) { FunctorOfTerm(where) == FunctorError) {
error_t = where; error_t = where;
P = (yamop *)FAILCODE; P = (yamop *)FAILCODE;
@ -440,16 +457,16 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
} else { } else {
Yap_detect_bug_location(P, FIND_PRED_FROM_ANYWHERE, YAP_BUF_SIZE); Yap_detect_bug_location(P, FIND_PRED_FROM_ANYWHERE, YAP_BUF_SIZE);
if (tmpbuf[0]) { if (tmpbuf[0]) {
fprintf(stderr, "%% Bug found while executing %s\n", tmpbuf); fprintf(stderr, "%% Bug found while executing %s\n", tmpbuf);
} }
#if HAVE_BACKTRACE #if HAVE_BACKTRACE
void *callstack[256]; void *callstack[256];
int i; int i;
int frames = backtrace(callstack, 256); int frames = backtrace(callstack, 256);
char** strs = backtrace_symbols(callstack, frames); char **strs = backtrace_symbols(callstack, frames);
fprintf(stderr, "Execution stack:\n"); fprintf(stderr, "Execution stack:\n");
for (i = 0; i < frames; ++i) { for (i = 0; i < frames; ++i) {
fprintf(stderr, " %s\n", strs[i]); fprintf(stderr, " %s\n", strs[i]);
} }
free(strs); free(strs);
#endif #endif
@ -496,27 +513,24 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
LOCAL_PrologMode &= ~InErrorMode; LOCAL_PrologMode &= ~InErrorMode;
return (P); return (P);
default: { default: {
LOCAL_PrologMode &= ~InErrorMode; LOCAL_PrologMode &= ~InErrorMode;
Term ts[3]; Term ts[3];
ts[2] = where; ts[2] = where;
nt[0] = mkerrort(type, ts + 2); nt[0] = mkerrort(type, ts + 2);
} }
} }
LOCAL_PrologMode &= ~InErrorMode; LOCAL_PrologMode &= ~InErrorMode;
if (type != ABORT_EVENT) { if (type != ABORT_EVENT) {
Term location; Term location;
/* This is used by some complex procedures to detect there was an error */ /* This is used by some complex procedures to detect there was an error */
if (IsAtomTerm(nt[0])) { if (IsAtomTerm(nt[0])) {
strncpy(LOCAL_ErrorSay, (char *) RepAtom(AtomOfTerm(nt[0]))->StrOfAE, strncpy(LOCAL_ErrorSay, (char *)RepAtom(AtomOfTerm(nt[0]))->StrOfAE,
MAX_ERROR_MSG_SIZE); MAX_ERROR_MSG_SIZE);
LOCAL_ErrorMessage = LOCAL_ErrorSay; LOCAL_ErrorMessage = LOCAL_ErrorSay;
} else { } else {
strncpy(LOCAL_ErrorSay, strncpy(LOCAL_ErrorSay,
(char *) RepAtom(NameOfFunctor(FunctorOfTerm(nt[0])))->StrOfAE, (char *)RepAtom(NameOfFunctor(FunctorOfTerm(nt[0])))->StrOfAE,
MAX_ERROR_MSG_SIZE); MAX_ERROR_MSG_SIZE);
LOCAL_ErrorMessage = LOCAL_ErrorSay; LOCAL_ErrorMessage = LOCAL_ErrorSay;
} }
@ -526,26 +540,26 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
case RESOURCE_ERROR_STACK: case RESOURCE_ERROR_STACK:
case RESOURCE_ERROR_TRAIL: case RESOURCE_ERROR_TRAIL:
comment = MkAtomTerm(Yap_LookupAtom(tmpbuf)); comment = MkAtomTerm(Yap_LookupAtom(tmpbuf));
default: default:
if (comment != TermNil) if (comment != TermNil)
nt[1] = MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("i")), comment), nt[1] = MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("i")), comment),
nt[1]); nt[1]);
if (file && function) { if (file && function) {
Term ts[3], t3; Term ts[3], t3;
ts[0] = MkAtomTerm(Yap_LookupAtom(file)); ts[0] = MkAtomTerm(Yap_LookupAtom(file));
ts[1] = MkIntegerTerm(lineno); ts[1] = MkIntegerTerm(lineno);
ts[2] = MkAtomTerm(Yap_LookupAtom(function)); ts[2] = MkAtomTerm(Yap_LookupAtom(function));
t3 = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("c"), 3), 3, ts); t3 = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("c"), 3), 3, ts);
nt[1] = nt[1] =
MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("c")), t3), nt[1]); MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("c")), t3), nt[1]);
} }
if ((location = Yap_pc_location(P, B, ENV)) != TermNil) { if ((location = Yap_pc_location(P, B, ENV)) != TermNil) {
nt[1] = MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("p")), location), nt[1] = MkPairTerm(
nt[1]); MkPairTerm(MkAtomTerm(Yap_LookupAtom("p")), location), nt[1]);
} }
if ((location = Yap_env_location(CP, B, ENV, 0)) != TermNil) { if ((location = Yap_env_location(CP, B, ENV, 0)) != TermNil) {
nt[1] = MkPairTerm(MkPairTerm(MkAtomTerm(Yap_LookupAtom("e")), location), nt[1] = MkPairTerm(
nt[1]); MkPairTerm(MkAtomTerm(Yap_LookupAtom("e")), location), nt[1]);
} }
} }
} }
@ -553,13 +567,13 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
LOCAL_Signals = 0; LOCAL_Signals = 0;
CalculateStackGap(PASS_REGS1); CalculateStackGap(PASS_REGS1);
#if DEBUG #if DEBUG
// DumpActiveGoals( PASS_REGS1 ); // DumpActiveGoals( PASS_REGS1 );
#endif #endif
/* wait if we we are in user code, /* wait if we we are in user code,
it's up to her to decide */ it's up to her to decide */
fun = FunctorError; fun = FunctorError;
error_t = Yap_MkApplTerm(fun, 2, nt); error_t = Yap_MkApplTerm(fun, 2, nt);
if (type == ABORT_EVENT) { if (type == ABORT_EVENT) {
error_t = MkAtomTerm(AtomDAbort); error_t = MkAtomTerm(AtomDAbort);
} else { } else {
@ -567,17 +581,14 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
} }
Yap_JumpToEnv(error_t); Yap_JumpToEnv(error_t);
P = (yamop *)FAILCODE; P = (yamop *)FAILCODE;
LOCAL_PrologMode &= ~InErrorMode; LOCAL_PrologMode &= ~InErrorMode;
return P; return P;
} }
static Int static Int is_boolean(USES_REGS1) {
is_boolean( USES_REGS1 )
{
Term t = Deref(ARG1); Term t = Deref(ARG1);
//Term Context = Deref(ARG2)Yap_Error(INSTANTIATION_ERROR, t, NULL);; // Term Context = Deref(ARG2)Yap_Error(INSTANTIATION_ERROR, t, NULL);;
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, t, NULL); Yap_Error(INSTANTIATION_ERROR, t, NULL);
return false; return false;
@ -585,25 +596,19 @@ is_boolean( USES_REGS1 )
return t == TermTrue || t == TermFalse; return t == TermTrue || t == TermFalse;
} }
static Int static Int is_atom(USES_REGS1) {
is_atom( USES_REGS1 )
{
Term t = Deref(ARG1); Term t = Deref(ARG1);
//Term Context = Deref(ARG2)Yap_Error(INSTANTIATION_ERROR, t, NULL);; // Term Context = Deref(ARG2)Yap_Error(INSTANTIATION_ERROR, t, NULL);;
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, t, NULL); Yap_Error(INSTANTIATION_ERROR, t, NULL);
return false; return false;
} }
return IsAtomTerm( t ); return IsAtomTerm(t);
} }
static Int is_callable(USES_REGS1) {
static Int
is_callable( USES_REGS1 )
{
Term G = Deref(ARG1); Term G = Deref(ARG1);
//Term Context = Deref(ARG2); // Term Context = Deref(ARG2);
while (true) { while (true) {
if (IsVarTerm(G)) { if (IsVarTerm(G)) {
Yap_Error(INSTANTIATION_ERROR, G, NULL); Yap_Error(INSTANTIATION_ERROR, G, NULL);
@ -615,7 +620,7 @@ is_callable( USES_REGS1 )
Yap_Error(TYPE_ERROR_CALLABLE, G, NULL); Yap_Error(TYPE_ERROR_CALLABLE, G, NULL);
} }
if (f == FunctorModule) { if (f == FunctorModule) {
Term tm = ArgOfTerm( 1, G); Term tm = ArgOfTerm(1, G);
if (IsVarTerm(tm)) { if (IsVarTerm(tm)) {
Yap_Error(INSTANTIATION_ERROR, G, NULL); Yap_Error(INSTANTIATION_ERROR, G, NULL);
return false; return false;
@ -624,7 +629,7 @@ is_callable( USES_REGS1 )
Yap_Error(TYPE_ERROR_CALLABLE, G, NULL); Yap_Error(TYPE_ERROR_CALLABLE, G, NULL);
return false; return false;
} }
G = ArgOfTerm( 2, G ); G = ArgOfTerm(2, G);
} else { } else {
return true; return true;
} }
@ -638,11 +643,9 @@ is_callable( USES_REGS1 )
return false; return false;
} }
static Int static Int is_predicate_indicator(USES_REGS1) {
is_predicate_indicator( USES_REGS1 )
{
Term G = Deref(ARG1); Term G = Deref(ARG1);
//Term Context = Deref(ARG2); // Term Context = Deref(ARG2);
Term mod = CurrentModule; Term mod = CurrentModule;
G = Yap_YapStripModule(G, &mod); G = Yap_YapStripModule(G, &mod);
@ -667,13 +670,85 @@ is_predicate_indicator( USES_REGS1 )
return false; return false;
} }
static Int close_error(USES_REGS1) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
return true;
}
void #undef BEGIN_ERROR_CLASSES
Yap_InitErrorPreds( void ) #undef ECLASS
{ #undef END_ERROR_CLASSES
#undef BEGIN_ERRORS
#undef E0
#undef E
#undef E2
#undef END_ERRORS
#define BEGIN_ERROR_CLASSES() typedef enum aux_class {
#define ECLASS(CL, A, B) CL##__,
#define END_ERROR_CLASSES() \
} \
aux_class_t;
#define BEGIN_ERRORS()
#define E0(X, Y)
#define E(X, Y, Z)
#define E2(X, Y, Z, W)
#define END_ERRORS()
#include <YapErrors.h>
#undef BEGIN_ERROR_CLASSES
#undef ECLASS
#undef END_ERROR_CLASSES
#undef BEGIN_ERRORS
#undef E0
#undef E
#undef E2
#undef END_ERRORS
#define BEGIN_ERROR_CLASSES() static const char *c_error_class_name[] = {
#define ECLASS(CL, A, B) A,
#define END_ERROR_CLASSES() \
NULL \
}
typedef struct c_error_info {
int class;
const char *name;
} c_error_t;
#define BEGIN_ERRORS() static struct c_error_info c_error_list[] = {
#define E0(X, Y) {Y##__, ""},
#define E(X, Y, Z) {Y##__, Z},
#define E2(X, Y, Z, W) {Y##__, Z " " W},
#define END_ERRORS() \
{ YAPC_NO_ERROR, "" } \
} \
;
#include <YapErrors.h>
yap_error_class_number Yap_errorClass(yap_error_number e) {
return c_error_list[e].class;
}
const char *Yap_errorName(yap_error_number e) { return c_error_list[e].name; }
const char *Yap_errorClassName(yap_error_class_number e) {
return c_error_class_name[e];
}
void Yap_InitErrorPreds(void) {
CACHE_REGS CACHE_REGS
Yap_InitCPred("is_boolean", 2, is_boolean, TestPredFlag); Yap_InitCPred("$close_error", 0, close_error, HiddenPredFlag);
Yap_InitCPred("is_boolean", 2, is_boolean, TestPredFlag);
Yap_InitCPred("is_callable", 2, is_callable, TestPredFlag); Yap_InitCPred("is_callable", 2, is_callable, TestPredFlag);
Yap_InitCPred("is_atom", 2, is_atom, TestPredFlag); Yap_InitCPred("is_atom", 2, is_atom, TestPredFlag);
Yap_InitCPred("is_predicate_indicator", 2, is_predicate_indicator, TestPredFlag); Yap_InitCPred("is_predicate_indicator", 2, is_predicate_indicator,
TestPredFlag);
} }

View File

@ -86,8 +86,6 @@ char* ScannerStack =NULL
struct scanner_extra_alloc* ScannerExtraBlocks =NULL struct scanner_extra_alloc* ScannerExtraBlocks =NULL
/// worker control information /// worker control information
/// pointer to an exception term, from throw
struct DB_TERM* BallTerm =NULL RestoreBallTerm(wid)
/// stack limit after which the stack is managed by C-code. /// stack limit after which the stack is managed by C-code.
Int CBorder =0 Int CBorder =0
@ -198,12 +196,12 @@ ADDR TrailBase void
ADDR TrailTop void ADDR TrailTop void
char* ErrorMessage void char* ErrorMessage void
Term Error_Term void Term Error_Term void
yap_error_number Error_TYPE void
const char* Error_File void /** error handling info, designed to be easy to pass to the foreign world */
const char* Error_Function void struct yap_error_descriptor ActiveError void
int Error_Lineno void /// pointer to an exception term, from throw
size_t Error_Size void struct DB_TERM* BallTerm =NULL
char ErrorSay[MAX_ERROR_MSG_SIZE] void
jmp_buf IOBotch void jmp_buf IOBotch void
TokEntry* tokptr void TokEntry* tokptr void
TokEntry* toktide void TokEntry* toktide void
@ -307,7 +305,7 @@ UInt exo_arg =0
struct scan_atoms* search_atoms void struct scan_atoms* search_atoms void
struct pred_entry* SearchPreds void struct pred_entry* SearchPreds void
// Slots /// Slots Status
yhandle_t CurSlot =0 yhandle_t CurSlot =0
yhandle_t FrozenHandles =0 yhandle_t FrozenHandles =0
yhandle_t NSlots =0 yhandle_t NSlots =0

View File

@ -48,7 +48,7 @@
#define HeapLim Yap_heap_regs->HeapLim_ #define HeapLim Yap_heap_regs->HeapLim_
#define FreeBlocks Yap_heap_regs->FreeBlocks_ #define FreeBlocks Yap_heap_regs->FreeBlocks_
#if defined(YAPOR) || defined(THREADS) #if defined(YAPOR) || defined(THREADS)
#define fFreeBlocksLock Yap_heap_regs->FreeBlocksLock_ #define FreeBlocksLock Yap_heap_regs->FreeBlocksLock_
#define HeapUsedLock Yap_heap_regs->HeapUsedLock_ #define HeapUsedLock Yap_heap_regs->HeapUsedLock_
#define HeapTopLock Yap_heap_regs->HeapTopLock_ #define HeapTopLock Yap_heap_regs->HeapTopLock_
#define HeapTopOwner Yap_heap_regs->HeapTopOwner_ #define HeapTopOwner Yap_heap_regs->HeapTopOwner_

View File

@ -133,9 +133,6 @@
#define REMOTE_ScannerExtraBlocks(wid) REMOTE(wid)->ScannerExtraBlocks_ #define REMOTE_ScannerExtraBlocks(wid) REMOTE(wid)->ScannerExtraBlocks_
#define LOCAL_BallTerm LOCAL->BallTerm_
#define REMOTE_BallTerm(wid) REMOTE(wid)->BallTerm_
#define LOCAL_CBorder LOCAL->CBorder_ #define LOCAL_CBorder LOCAL->CBorder_
#define REMOTE_CBorder(wid) REMOTE(wid)->CBorder_ #define REMOTE_CBorder(wid) REMOTE(wid)->CBorder_
@ -295,18 +292,12 @@
#define REMOTE_ErrorMessage(wid) REMOTE(wid)->ErrorMessage_ #define REMOTE_ErrorMessage(wid) REMOTE(wid)->ErrorMessage_
#define LOCAL_Error_Term LOCAL->Error_Term_ #define LOCAL_Error_Term LOCAL->Error_Term_
#define REMOTE_Error_Term(wid) REMOTE(wid)->Error_Term_ #define REMOTE_Error_Term(wid) REMOTE(wid)->Error_Term_
#define LOCAL_Error_TYPE LOCAL->Error_TYPE_
#define REMOTE_Error_TYPE(wid) REMOTE(wid)->Error_TYPE_ #define LOCAL_ActiveError LOCAL->ActiveError_
#define LOCAL_Error_File LOCAL->Error_File_ #define REMOTE_ActiveError(wid) REMOTE(wid)->ActiveError_
#define REMOTE_Error_File(wid) REMOTE(wid)->Error_File_
#define LOCAL_Error_Function LOCAL->Error_Function_ #define LOCAL_BallTerm LOCAL->BallTerm_
#define REMOTE_Error_Function(wid) REMOTE(wid)->Error_Function_ #define REMOTE_BallTerm(wid) REMOTE(wid)->BallTerm_
#define LOCAL_Error_Lineno LOCAL->Error_Lineno_
#define REMOTE_Error_Lineno(wid) REMOTE(wid)->Error_Lineno_
#define LOCAL_Error_Size LOCAL->Error_Size_
#define REMOTE_Error_Size(wid) REMOTE(wid)->Error_Size_
#define LOCAL_ErrorSay LOCAL->ErrorSay_
#define REMOTE_ErrorSay(wid) REMOTE(wid)->ErrorSay_
#define LOCAL_IOBotch LOCAL->IOBotch_ #define LOCAL_IOBotch LOCAL->IOBotch_
#define REMOTE_IOBotch(wid) REMOTE(wid)->IOBotch_ #define REMOTE_IOBotch(wid) REMOTE(wid)->IOBotch_
#define LOCAL_tokptr LOCAL->tokptr_ #define LOCAL_tokptr LOCAL->tokptr_

View File

@ -1,279 +1,277 @@
/* This file, hlocals.h, was generated automatically by "yap -L misc/buildlocalglobal" /* This file, hlocals.h, was generated automatically by "yap -L
please do not update, update H/LOCALS instead */ misc/buildlocalglobal"
please do not update, update H/LOCALS instead */
// Stuff that must be considered local to a thread or worker // Stuff that must be considered local to a thread or worker
typedef struct worker_local { typedef struct worker_local {
// Streams // Streams
int c_input_stream_; int c_input_stream_;
int c_output_stream_; int c_output_stream_;
int c_error_stream_; int c_error_stream_;
bool sockets_io_; bool sockets_io_;
bool within_print_message_; bool within_print_message_;
// //
// Used by the prompts to check if they are after a newline, and then a // Used by the prompts to check if they are after a newline, and then a
// prompt should be output, or if we are in the middle of a line. // prompt should be output, or if we are in the middle of a line.
// //
bool newline_; bool newline_;
Atom AtPrompt_; Atom AtPrompt_;
char Prompt_[MAX_PROMPT+1]; char Prompt_[MAX_PROMPT + 1];
encoding_t encoding_; encoding_t encoding_;
bool quasi_quotations_; bool quasi_quotations_;
UInt default_priority_; UInt default_priority_;
bool eot_before_eof_; bool eot_before_eof_;
UInt max_depth_; UInt max_depth_;
UInt max_list_; UInt max_list_;
UInt max_write_args_; UInt max_write_args_;
// Restore info // Restore info
CELL* OldASP_; CELL *OldASP_;
CELL* OldLCL0_; CELL *OldLCL0_;
tr_fr_ptr OldTR_; tr_fr_ptr OldTR_;
CELL* OldGlobalBase_; CELL *OldGlobalBase_;
CELL* OldH_; CELL *OldH_;
CELL* OldH0_; CELL *OldH0_;
ADDR OldTrailBase_; ADDR OldTrailBase_;
ADDR OldTrailTop_; ADDR OldTrailTop_;
ADDR OldHeapBase_; ADDR OldHeapBase_;
ADDR OldHeapTop_; ADDR OldHeapTop_;
Int ClDiff_; Int ClDiff_;
Int GDiff_; Int GDiff_;
Int HDiff_; Int HDiff_;
Int GDiff0_; Int GDiff0_;
CELL* GSplit_; CELL *GSplit_;
Int LDiff_; Int LDiff_;
Int TrDiff_; Int TrDiff_;
Int XDiff_; Int XDiff_;
Int DelayDiff_; Int DelayDiff_;
Int BaseDiff_; Int BaseDiff_;
// Reduction counters // Reduction counters
YAP_ULONG_LONG ReductionsCounter_; YAP_ULONG_LONG ReductionsCounter_;
YAP_ULONG_LONG PredEntriesCounter_; YAP_ULONG_LONG PredEntriesCounter_;
YAP_ULONG_LONG RetriesCounter_; YAP_ULONG_LONG RetriesCounter_;
int ReductionsCounterOn_; int ReductionsCounterOn_;
int PredEntriesCounterOn_; int PredEntriesCounterOn_;
int RetriesCounterOn_; int RetriesCounterOn_;
// support for consulting files // support for consulting files
/* current consult stack */ /* current consult stack */
union CONSULT_OBJ* ConsultSp_; union CONSULT_OBJ *ConsultSp_;
/* current maximum number of cells in consult stack */ /* current maximum number of cells in consult stack */
UInt ConsultCapacity_; UInt ConsultCapacity_;
/* top of consult stack */ /* top of consult stack */
union CONSULT_OBJ* ConsultBase_; union CONSULT_OBJ *ConsultBase_;
/* low-water mark for consult */ /* low-water mark for consult */
union CONSULT_OBJ* ConsultLow_; union CONSULT_OBJ *ConsultLow_;
Term VarNames_; Term VarNames_;
Atom SourceFileName_; Atom SourceFileName_;
UInt SourceFileLineno_; UInt SourceFileLineno_;
//global variables // global variables
Term GlobalArena_; Term GlobalArena_;
UInt GlobalArenaOverflows_; UInt GlobalArenaOverflows_;
Int ArenaOverflows_; Int ArenaOverflows_;
Int DepthArenas_; Int DepthArenas_;
int ArithError_; int ArithError_;
struct pred_entry* LastAssertedPred_; struct pred_entry *LastAssertedPred_;
struct pred_entry* TmpPred_; struct pred_entry *TmpPred_;
char* ScannerStack_; char *ScannerStack_;
struct scanner_extra_alloc* ScannerExtraBlocks_; struct scanner_extra_alloc *ScannerExtraBlocks_;
/// worker control information /// worker control information
/// pointer to an exception term, from throw /// stack limit after which the stack is managed by C-code.
struct DB_TERM* BallTerm_; Int CBorder_;
/// stack limit after which the stack is managed by C-code. /// max number of signals (uint64_t)
Int CBorder_; UInt MaxActiveSignals_;
/// max number of signals (uint64_t) /// actual life signals
UInt MaxActiveSignals_; uint64_t Signals_;
/// actual life signals /// indexing help data?
uint64_t Signals_; UInt IPredArity_;
/// indexing help data? yamop *ProfEnd_;
UInt IPredArity_; int DoingUndefp_;
yamop* ProfEnd_; Int StartCharCount_;
int DoingUndefp_; Int StartLineCount_;
Int StartCharCount_; Int StartLinePos_;
Int StartLineCount_; scratch_block ScratchPad_;
Int StartLinePos_; #ifdef COROUTINING
scratch_block ScratchPad_; Term WokenGoals_;
#ifdef COROUTINING Term AttsMutableList_;
Term WokenGoals_;
Term AttsMutableList_;
#endif #endif
// gc_stuff // gc_stuff
Term GcGeneration_; Term GcGeneration_;
Term GcPhase_; Term GcPhase_;
UInt GcCurrentPhase_; UInt GcCurrentPhase_;
UInt GcCalls_; UInt GcCalls_;
Int TotGcTime_; Int TotGcTime_;
YAP_ULONG_LONG TotGcRecovered_; YAP_ULONG_LONG TotGcRecovered_;
Int LastGcTime_; Int LastGcTime_;
Int LastSSTime_; Int LastSSTime_;
CELL* OpenArray_; CELL *OpenArray_;
/* in a single gc */ /* in a single gc */
Int total_marked_; Int total_marked_;
Int total_oldies_; Int total_oldies_;
struct choicept* current_B_; struct choicept *current_B_;
CELL* prev_HB_; CELL *prev_HB_;
CELL* HGEN_; CELL *HGEN_;
CELL** iptop_; CELL **iptop_;
#if defined(GC_NO_TAGS) #if defined(GC_NO_TAGS)
char* bp_; char *bp_;
#endif #endif
tr_fr_ptr sTR_; tr_fr_ptr sTR_;
tr_fr_ptr sTR0_; tr_fr_ptr sTR0_;
tr_fr_ptr new_TR_; tr_fr_ptr new_TR_;
struct gc_mark_continuation* cont_top0_; struct gc_mark_continuation *cont_top0_;
struct gc_mark_continuation* cont_top_; struct gc_mark_continuation *cont_top_;
int discard_trail_entries_; int discard_trail_entries_;
gc_ma_hash_entry gc_ma_hash_table_[GC_MAVARS_HASH_SIZE]; gc_ma_hash_entry gc_ma_hash_table_[GC_MAVARS_HASH_SIZE];
gc_ma_hash_entry* gc_ma_h_top_; gc_ma_hash_entry *gc_ma_h_top_;
gc_ma_hash_entry* gc_ma_h_list_; gc_ma_hash_entry *gc_ma_h_list_;
UInt gc_timestamp_; UInt gc_timestamp_;
ADDR db_vec_; ADDR db_vec_;
ADDR db_vec0_; ADDR db_vec0_;
struct RB_red_blk_node* db_root_; struct RB_red_blk_node *db_root_;
struct RB_red_blk_node* db_nil_; struct RB_red_blk_node *db_nil_;
sigjmp_buf gc_restore_; sigjmp_buf gc_restore_;
CELL* extra_gc_cells_; CELL *extra_gc_cells_;
CELL* extra_gc_cells_base_; CELL *extra_gc_cells_base_;
CELL* extra_gc_cells_top_; CELL *extra_gc_cells_top_;
UInt extra_gc_cells_size_; UInt extra_gc_cells_size_;
struct array_entry* DynamicArrays_; struct array_entry *DynamicArrays_;
struct static_array_entry* StaticArrays_; struct static_array_entry *StaticArrays_;
struct global_entry* GlobalVariables_; struct global_entry *GlobalVariables_;
int AllowRestart_; int AllowRestart_;
// Thread Local Area for Fast Storage of Intermediate Compiled Code // Thread Local Area for Fast Storage of Intermediate Compiled Code
struct mem_blk* CMemFirstBlock_; struct mem_blk *CMemFirstBlock_;
UInt CMemFirstBlockSz_; UInt CMemFirstBlockSz_;
// Variable used by the compiler to store number of permanent vars in a clause // Variable used by the compiler to store number of permanent vars in a clause
int nperm_; int nperm_;
// Thread Local Area for Labels // Thread Local Area for Labels
Int* LabelFirstArray_; Int *LabelFirstArray_;
UInt LabelFirstArraySz_; UInt LabelFirstArraySz_;
// Thread Local Area for SWI-Prolog emulation routines. // Thread Local Area for SWI-Prolog emulation routines.
// struct PL_local_data* PL_local_data_p =Yap_InitThreadIO(wid) // struct PL_local_data* PL_local_data_p
// =Yap_InitThreadIO(wid)
#ifdef THREADS #ifdef THREADS
struct thandle ThreadHandle_; struct thandle ThreadHandle_;
#endif /* THREADS */ #endif /* THREADS */
#if defined(YAPOR) || defined(TABLING) #if defined(YAPOR) || defined(TABLING)
struct local_optyap_data optyap_data_; struct local_optyap_data optyap_data_;
UInt TabMode_; UInt TabMode_;
#endif /* YAPOR || TABLING */ #endif /* YAPOR || TABLING */
int InterruptsDisabled_; int InterruptsDisabled_;
struct open_query_struct* execution_; struct open_query_struct *execution_;
#if LOW_LEVEL_TRACER #if LOW_LEVEL_TRACER
Int total_choicepoints_; Int total_choicepoints_;
#endif #endif
int consult_level_; int consult_level_;
// Variables related to memory allocation // Variables related to memory allocation
ADDR LocalBase_; ADDR LocalBase_;
ADDR GlobalBase_; ADDR GlobalBase_;
ADDR TrailBase_; ADDR TrailBase_;
ADDR TrailTop_; ADDR TrailTop_;
char* ErrorMessage_; char *ErrorMessage_;
Term Error_Term_; Term Error_Term_;
yap_error_number Error_TYPE_; /** error handling info, designed to be easy to pass to the foreign world */
const char* Error_File_; struct yap_error_descriptor ActiveError_;
const char* Error_Function_; /// pointer to an exception term, from throw
int Error_Lineno_; struct DB_TERM *BallTerm_;
size_t Error_Size_; jmp_buf IOBotch_;
char ErrorSay_[MAX_ERROR_MSG_SIZE]; TokEntry *tokptr_;
jmp_buf IOBotch_; TokEntry *toktide_;
TokEntry* tokptr_; VarEntry *VarTable_;
TokEntry* toktide_; VarEntry *AnonVarTable_;
VarEntry* VarTable_; Term Comments_;
VarEntry* AnonVarTable_; CELL *CommentsTail_;
Term Comments_; CELL *CommentsNextChar_;
CELL* CommentsTail_; wchar_t *CommentsBuff_;
CELL* CommentsNextChar_; size_t CommentsBuffPos_;
wchar_t* CommentsBuff_; size_t CommentsBuffLim_;
size_t CommentsBuffPos_; sigjmp_buf RestartEnv_;
size_t CommentsBuffLim_; char FileNameBuf_[YAP_FILENAME_MAX + 1];
sigjmp_buf RestartEnv_; char FileNameBuf2_[YAP_FILENAME_MAX + 1];
char FileNameBuf_[YAP_FILENAME_MAX]; // Prolog State
char FileNameBuf2_[YAP_FILENAME_MAX]; UInt BreakLevel_;
// Prolog State Int PrologMode_;
UInt BreakLevel_; int CritLocks_;
Int PrologMode_; // Prolog execution and state flags
int CritLocks_; union flagTerm *Flags_;
// Prolog execution and state flags UInt flagCount_;
union flagTerm* Flags_; // analyst.c
UInt flagCount_;
//analyst.c
/* used to find out how many instructions of each kind are executed */ /* used to find out how many instructions of each kind are executed */
#ifdef ANALYST #ifdef ANALYST
YAP_ULONG_LONG opcount_[_std_top+1]; YAP_ULONG_LONG opcount_[_std_top + 1];
YAP_ULONG_LONG 2opcount[_std_top+1][_std_top+1]_; YAP_ULONG_LONG 2opcount [_std_top + 1][_std_top + 1] _;
#endif /* ANALYST */ #endif /* ANALYST */
//dbase.c // dbase.c
struct db_globs* s_dbg_; struct db_globs *s_dbg_;
//eval.c // eval.c
yap_error_number matherror_; yap_error_number matherror_;
Term mathtt_; Term mathtt_;
char* mathstring_; char *mathstring_;
yap_error_number CurrentError_; yap_error_number CurrentError_;
//grow.c // grow.c
int heap_overflows_; int heap_overflows_;
Int total_heap_overflow_time_; Int total_heap_overflow_time_;
int stack_overflows_; int stack_overflows_;
Int total_stack_overflow_time_; Int total_stack_overflow_time_;
int delay_overflows_; int delay_overflows_;
Int total_delay_overflow_time_; Int total_delay_overflow_time_;
int trail_overflows_; int trail_overflows_;
Int total_trail_overflow_time_; Int total_trail_overflow_time_;
int atom_table_overflows_; int atom_table_overflows_;
Int total_atom_table_overflow_time_; Int total_atom_table_overflow_time_;
//load_dyld // load_dyld
#ifdef LOAD_DYLD #ifdef LOAD_DYLD
int dl_errno_; int dl_errno_;
#endif #endif
//tracer.c // tracer.c
#ifdef LOW_LEVEL_TRACER #ifdef LOW_LEVEL_TRACER
int do_trace_primitives_; int do_trace_primitives_;
#endif #endif
//quick loader // quick loader
struct export_atom_hash_entry_struct *ExportAtomHashChain_; struct export_atom_hash_entry_struct *ExportAtomHashChain_;
UInt ExportAtomHashTableSize_; UInt ExportAtomHashTableSize_;
UInt ExportAtomHashTableNum_; UInt ExportAtomHashTableNum_;
struct export_functor_hash_entry_struct *ExportFunctorHashChain_; struct export_functor_hash_entry_struct *ExportFunctorHashChain_;
UInt ExportFunctorHashTableSize_; UInt ExportFunctorHashTableSize_;
UInt ExportFunctorHashTableNum_; UInt ExportFunctorHashTableNum_;
struct export_pred_entry_hash_entry_struct *ExportPredEntryHashChain_; struct export_pred_entry_hash_entry_struct *ExportPredEntryHashChain_;
UInt ExportPredEntryHashTableSize_; UInt ExportPredEntryHashTableSize_;
UInt ExportPredEntryHashTableNum_; UInt ExportPredEntryHashTableNum_;
struct export_dbref_hash_entry_struct *ExportDBRefHashChain_; struct export_dbref_hash_entry_struct *ExportDBRefHashChain_;
UInt ExportDBRefHashTableSize_; UInt ExportDBRefHashTableSize_;
UInt ExportDBRefHashTableNum_; UInt ExportDBRefHashTableNum_;
struct import_atom_hash_entry_struct **ImportAtomHashChain_; struct import_atom_hash_entry_struct **ImportAtomHashChain_;
UInt ImportAtomHashTableSize_; UInt ImportAtomHashTableSize_;
UInt ImportAtomHashTableNum_; UInt ImportAtomHashTableNum_;
struct import_functor_hash_entry_struct **ImportFunctorHashChain_; struct import_functor_hash_entry_struct **ImportFunctorHashChain_;
UInt ImportFunctorHashTableSize_; UInt ImportFunctorHashTableSize_;
UInt ImportFunctorHashTableNum_; UInt ImportFunctorHashTableNum_;
struct import_opcode_hash_entry_struct **ImportOPCODEHashChain_; struct import_opcode_hash_entry_struct **ImportOPCODEHashChain_;
UInt ImportOPCODEHashTableSize_; UInt ImportOPCODEHashTableSize_;
struct import_pred_entry_hash_entry_struct **ImportPredEntryHashChain_; struct import_pred_entry_hash_entry_struct **ImportPredEntryHashChain_;
UInt ImportPredEntryHashTableSize_; UInt ImportPredEntryHashTableSize_;
UInt ImportPredEntryHashTableNum_; UInt ImportPredEntryHashTableNum_;
struct import_dbref_hash_entry_struct **ImportDBRefHashChain_; struct import_dbref_hash_entry_struct **ImportDBRefHashChain_;
UInt ImportDBRefHashTableSize_; UInt ImportDBRefHashTableSize_;
UInt ImportDBRefHashTableNum_; UInt ImportDBRefHashTableNum_;
yamop *ImportFAILCODE_; yamop *ImportFAILCODE_;
// exo indexing // exo indexing
UInt ibnds_[256]; UInt ibnds_[256];
struct index_t* exo_it_; struct index_t *exo_it_;
CELL* exo_base_; CELL *exo_base_;
UInt exo_arity_; UInt exo_arity_;
UInt exo_arg_; UInt exo_arg_;
// atom completion // atom completion
struct scan_atoms* search_atoms_; struct scan_atoms *search_atoms_;
struct pred_entry* SearchPreds_; struct pred_entry *SearchPreds_;
// Slots /// Slots Status
yhandle_t CurSlot_; yhandle_t CurSlot_;
yhandle_t FrozenHandles_; yhandle_t FrozenHandles_;
yhandle_t NSlots_; yhandle_t NSlots_;
CELL* SlotBase_; CELL *SlotBase_;
// Mutexes // Mutexes
struct swi_mutex* Mutexes_; struct swi_mutex *Mutexes_;
Term SourceModule_; Term SourceModule_;
Term Including_; Term Including_;
size_t MAX_SIZE_; size_t MAX_SIZE_;
/* last call to walltime. */ /* last call to walltime. */
uint64_t LastWTime_; uint64_t LastWTime_;
} w_local; } w_local;

View File

@ -76,8 +76,6 @@ static void InitWorker(int wid) {
REMOTE_ScannerExtraBlocks(wid) = NULL; REMOTE_ScannerExtraBlocks(wid) = NULL;
REMOTE_BallTerm(wid) = NULL;
REMOTE_CBorder(wid) = 0; REMOTE_CBorder(wid) = 0;
REMOTE_MaxActiveSignals(wid) = 64L; REMOTE_MaxActiveSignals(wid) = 64L;
@ -171,9 +169,7 @@ static void InitWorker(int wid) {
REMOTE_BallTerm(wid) = NULL;

View File

@ -76,8 +76,6 @@ static void RestoreWorker(int wid USES_REGS) {
RestoreBallTerm(wid);
@ -192,8 +190,6 @@ static void RestoreWorker(int wid USES_REGS) {

View File

@ -36,33 +36,40 @@
#include "YapErrors.h" #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 #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. * 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 INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
Yap_ensure_atom__( const char *fu, const char *fi, int line, Term in ) int line, Term in) {
{
Term t = Deref(in); Term t = Deref(in);
//Term Context = Deref(ARG2); // Term Context = Deref(ARG2);
if (!IsVarTerm(t) && IsAtomTerm(t)) if (!IsVarTerm(t) && IsAtomTerm(t))
return t; return t;
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error__(fu, fi, line, INSTANTIATION_ERROR, t, NULL); Yap_Error__(fu, fi, line, INSTANTIATION_ERROR, t, NULL);
} else { } else {
if ( IsAtomTerm(t) ) return t ; if (IsAtomTerm(t))
Yap_Error__(fu, fi, line, TYPE_ERROR_ATOM, t, NULL); return t;
return 0L; Yap_Error__(fu, fi, line, TYPE_ERROR_ATOM, t, NULL);
} return 0L;
}
#endif #endif
@ -74,7 +81,7 @@ Yap_ensure_atom__( const char *fu, const char *fi, int line, Term in )
goto LAB; \ goto LAB; \
} }
#define LOCAL_ERROR(t, v) \ #define LOCAL_ERROR(t, v) \
if (HR + (v) > ASP - 1024) { \ if (HR + (v) > ASP - 1024) { \
LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \ LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \
LOCAL_Error_Term = t; \ LOCAL_Error_Term = t; \
@ -82,7 +89,7 @@ Yap_ensure_atom__( const char *fu, const char *fi, int line, Term in )
return NULL; \ return NULL; \
} }
#define LOCAL_TERM_ERROR(t, v) \ #define LOCAL_TERM_ERROR(t, v) \
if (HR + (v) > ASP - 1024) { \ if (HR + (v) > ASP - 1024) { \
LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \ LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \
LOCAL_Error_Term = t; \ LOCAL_Error_Term = t; \
@ -138,4 +145,67 @@ Yap_ensure_atom__( const char *fu, const char *fi, int line, Term in )
goto LAB; \ 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 #endif

View File

@ -1,7 +1,6 @@
/// ///
/// @file YapErrors.h /// @file YapErrors.h
/// /// /// @adddtogroup YapError
/// @adddtogroup YapError
/// ///
/// The file YapErrors.h contains a list with all the error classes known /// The file YapErrors.h contains a list with all the error classes known
/// internally to the YAP system. /// internally to the YAP system.