debug exc

This commit is contained in:
Vítor Santos Costa 2018-04-09 02:00:51 +01:00
parent 7ce963b63c
commit 2d19db5fce
20 changed files with 581 additions and 503 deletions

View File

@ -916,7 +916,6 @@ static int interrupt_dexecute(USES_REGS1) {
static void undef_goal(USES_REGS1) { static void undef_goal(USES_REGS1) {
PredEntry *pe = PredFromDefCode(P); PredEntry *pe = PredFromDefCode(P);
BEGD(d0); BEGD(d0);
/* avoid trouble with undefined dynamic procedures */ /* avoid trouble with undefined dynamic procedures */
/* I assume they were not locked beforehand */ /* I assume they were not locked beforehand */

View File

@ -1699,6 +1699,9 @@ bool Yap_addclause(Term t, yamop *cp, Term tmode, Term mod, Term *t4ref)
Term tf; Term tf;
int mode; int mode;
if (tmode == 0) {
tmode = TermConsult;
}
if (tmode == TermConsult) { if (tmode == TermConsult) {
mode = consult; mode = consult;
} else if (tmode == TermReconsult) { } else if (tmode == TermReconsult) {

View File

@ -32,26 +32,29 @@
#endif #endif
#include "Foreign.h" #include "Foreign.h"
#define set_key_b(k, ks, q, i, t) \ #define set_key_b(k, ks, q, i, t) \
if (strcmp(ks,q) == 0) \ if (strcmp(ks, q) == 0) { \
{ i->k = t == TermTrue ? true : \ i->k = t == TermTrue ? true : false; \
false; \ return i->k || t == TermFalse; \
return i->k || t == TermFalse; } \ }
#define set_key_i(k, ks, q, i, t) \ #define set_key_i(k, ks, q, i, t) \
if (strcmp(ks,q) == 0) \ if (strcmp(ks, q) == 0) { \
{ i->k = IsIntegerTerm(t) ? IntegerOfTerm(t) : \ i->k = IsIntegerTerm(t) ? IntegerOfTerm(t) : 0; \
0; \ return IsIntegerTerm(t); \
return IsIntegerTerm(t); } }
#define set_key_s(k, ks, q, i, t) \ #define set_key_s(k, ks, q, i, t) \
if (strcmp(ks,q) == 0) \ if (strcmp(ks, q) == 0) { \
{ const char *s = IsAtomTerm(t) ? RepAtom(AtomOfTerm(t))->StrOfAE : \ const char *s = IsAtomTerm(t) ? RepAtom(AtomOfTerm(t))->StrOfAE \
IsStringTerm(t) ? StringOfTerm(t) : \ : IsStringTerm(t) ? StringOfTerm(t) : NULL; \
NULL; \ if (s) { \
if (s) { char *tmp = malloc(strlen(s)+1); strcpy(tmp,s); i->k = tmp; } \ char *tmp = malloc(strlen(s) + 1); \
return i->k != NULL; } \ strcpy(tmp, s); \
i->k = tmp; \
} \
return i->k != NULL; \
}
static bool setErr(const char *q, yap_error_descriptor_t *i, Term t) { static bool setErr(const char *q, yap_error_descriptor_t *i, Term t) {
set_key_i(errorNo, "errorNo", q, i, t); set_key_i(errorNo, "errorNo", q, i, t);
@ -83,16 +86,19 @@ static bool setErr(const char *q, yap_error_descriptor_t *i, Term t) {
} }
#define query_key_b(k, ks, q, i) \ #define query_key_b(k, ks, q, i) \
if (strcmp(ks,q) == 0) \ if (strcmp(ks, q) == 0) { \
{ return i->k ? TermTrue : TermFalse; } \ return i->k ? TermTrue : TermFalse; \
}
#define query_key_i(k, ks, q, i) \ #define query_key_i(k, ks, q, i) \
if (strcmp(ks,q) == 0) \ if (strcmp(ks, q) == 0) { \
{ return MkIntegerTerm(i->k); } return MkIntegerTerm(i->k); \
}
#define query_key_s(k, ks, q, i) \ #define query_key_s(k, ks, q, i) \
if (strcmp(ks,q) == 0) \ if (strcmp(ks, q) == 0) { \
{ return ( i->k && i->k[0] ? MkStringTerm(i->k) : TermEmptyAtom ); } return (i->k && i->k[0] ? MkStringTerm(i->k) : TermNil); \
}
static Term queryErr(const char *q, yap_error_descriptor_t *i) { static Term queryErr(const char *q, yap_error_descriptor_t *i) {
query_key_i(errorNo, "errorNo", q, i); query_key_i(errorNo, "errorNo", q, i);
@ -123,21 +129,16 @@ static Term queryErr(const char *q, yap_error_descriptor_t *i) {
return TermNil; return TermNil;
} }
static void print_key_b(const char *key, bool v) static void print_key_b(const char *key, bool v) {
{
const char *b = v ? "true" : "false"; const char *b = v ? "true" : "false";
fprintf(stderr, "%s: %s\n", key, b); fprintf(stderr, "%s: %s\n", key, b);
} }
static void print_key_i(const char *key, YAP_Int v) static void print_key_i(const char *key, YAP_Int v) {
{
fprintf(stderr, "%s: " Int_FORMAT "\n", key, v); fprintf(stderr, "%s: " Int_FORMAT "\n", key, v);
} }
static void print_key_s(const char *key, const char *v) {
static void print_key_s(const char *key, const char *v)
{
fprintf(stderr, "%s: %s\n", key, v); fprintf(stderr, "%s: %s\n", key, v);
} }
@ -175,9 +176,7 @@ static void printErr(yap_error_descriptor_t *i) {
} }
} }
static YAP_Term add_key_b(const char *key, bool v, YAP_Term o0) {
static YAP_Term add_key_b(const char *key, bool v, YAP_Term o0)
{
YAP_Term tkv[2]; YAP_Term tkv[2];
tkv[1] = v ? TermTrue : TermFalse; tkv[1] = v ? TermTrue : TermFalse;
tkv[0] = MkStringTerm(key); tkv[0] = MkStringTerm(key);
@ -185,18 +184,14 @@ static YAP_Term add_key_b(const char *key, bool v, YAP_Term o0)
return MkPairTerm(node, o0); return MkPairTerm(node, o0);
} }
static YAP_Term add_key_i(const char *key, YAP_Int v, YAP_Term o0) static YAP_Term add_key_i(const char *key, YAP_Int v, YAP_Term o0) {
{
YAP_Term tkv[2]; YAP_Term tkv[2];
tkv[1] = MkIntegerTerm(v), tkv[0] = MkStringTerm(key); tkv[1] = MkIntegerTerm(v), tkv[0] = MkStringTerm(key);
Term node = Yap_MkApplTerm(FunctorEq, 2, tkv); Term node = Yap_MkApplTerm(FunctorEq, 2, tkv);
return MkPairTerm(node, o0); return MkPairTerm(node, o0);
} }
static YAP_Term add_key_s(const char *key, const char *v, YAP_Term o0) {
static YAP_Term add_key_s(const char *key, const char *v, YAP_Term o0)
{
Term tkv[2]; Term tkv[2];
if (!v || v[0] == '\0') if (!v || v[0] == '\0')
return o0; return o0;
@ -238,10 +233,8 @@ static Term err2list(yap_error_descriptor_t *i) {
o = add_key_i("errorMsgLen", i->errorMsgLen, o); o = add_key_i("errorMsgLen", i->errorMsgLen, o);
} }
return o; return o;
} }
bool Yap_Warning(const char *s, ...) { bool Yap_Warning(const char *s, ...) {
CACHE_REGS CACHE_REGS
va_list ap; va_list ap;
@ -254,7 +247,8 @@ bool Yap_Warning(const char *s, ...) {
LOCAL_DoingUndefp = true; LOCAL_DoingUndefp = true;
if (LOCAL_PrologMode & InErrorMode && (err = LOCAL_ActiveError->errorNo)) { if (LOCAL_PrologMode & InErrorMode && (err = LOCAL_ActiveError->errorNo)) {
fprintf(stderr, "%% Warning %s WITHIN ERROR %s %s\n", s, Yap_errorClassName( Yap_errorClass(err)), Yap_errorName(err)); fprintf(stderr, "%% Warning %s WITHIN ERROR %s %s\n", s,
Yap_errorClassName(Yap_errorClass(err)), Yap_errorName(err));
Yap_RestartYap(1); Yap_RestartYap(1);
} }
LOCAL_PrologMode |= InErrorMode; LOCAL_PrologMode |= InErrorMode;
@ -289,7 +283,8 @@ bool Yap_Warning(const char *s, ...) {
return rc; return rc;
} }
void Yap_InitError__(const char *file, const char *function, int lineno, yap_error_number e, Term t, ...) { void Yap_InitError__(const char *file, const char *function, int lineno,
yap_error_number e, Term t, ...) {
CACHE_REGS CACHE_REGS
va_list ap; va_list ap;
va_start(ap, t); va_start(ap, t);
@ -331,7 +326,8 @@ bool Yap_PrintWarning(Term twarning) {
Term ts[2]; Term ts[2];
if (LOCAL_PrologMode & InErrorMode) { if (LOCAL_PrologMode & InErrorMode) {
fprintf(stderr, "%% ERROR WITHIN ERROR while processing warning: %s\n", Yap_TermToBuffer(twarning, LOCAL_encoding, 0)); fprintf(stderr, "%% ERROR WITHIN ERROR while processing warning: %s\n",
Yap_TermToBuffer(twarning, ENC_ISO_UTF8,Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f));
Yap_RestartYap(1); Yap_RestartYap(1);
} }
LOCAL_PrologMode |= InErrorMode; LOCAL_PrologMode |= InErrorMode;
@ -379,7 +375,8 @@ bool Yap_HandleError__(const char *file, const char *function, int lineno,
switch (err) { switch (err) {
case RESOURCE_ERROR_STACK: case RESOURCE_ERROR_STACK:
if (!Yap_gc(arity, ENV, gc_P(P, CP))) { if (!Yap_gc(arity, ENV, gc_P(P, CP))) {
Yap_Error__(false, file, function, lineno, RESOURCE_ERROR_STACK, ARG1, serr); Yap_Error__(false, file, function, lineno, RESOURCE_ERROR_STACK, ARG1,
serr);
return false; return false;
} }
return true; return true;
@ -389,14 +386,15 @@ bool Yap_HandleError__(const char *file, const char *function, int lineno,
} }
if (!Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE)) { if (!Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE)) {
/* crash in flames */ /* crash in flames */
Yap_Error__(false, file, function, lineno, RESOURCE_ERROR_AUXILIARY_STACK, ARG1, Yap_Error__(false, file, function, lineno, RESOURCE_ERROR_AUXILIARY_STACK,
serr); ARG1, serr);
return false; return false;
} }
return true; return true;
case RESOURCE_ERROR_HEAP: case RESOURCE_ERROR_HEAP:
if (!Yap_growheap(FALSE, 0, NULL)) { if (!Yap_growheap(FALSE, 0, NULL)) {
Yap_Error__(false, file, function, lineno, RESOURCE_ERROR_HEAP, ARG2, serr); Yap_Error__(false, file, function, lineno, RESOURCE_ERROR_HEAP, ARG2,
serr);
return false; return false;
} }
default: default:
@ -501,7 +499,7 @@ static char tmpbuf[YAP_BUF_SIZE];
#define ECLASS(CL, A, B) \ #define ECLASS(CL, A, B) \
case CL: \ case CL: \
return Yap_LookupAtom(A); \ return Yap_LookupAtom(A);
#define END_ERROR_CLASSES() \ #define END_ERROR_CLASSES() \
} \ } \
@ -517,21 +515,22 @@ static char tmpbuf[YAP_BUF_SIZE];
Term ft[2]; \ Term ft[2]; \
ft[0] = MkAtomTerm(mkerrorct(B)); \ ft[0] = MkAtomTerm(mkerrorct(B)); \
ft[1] = info; \ ft[1] = info; \
return Yap_MkApplTerm(FunctorError,2,ft); } return Yap_MkApplTerm(FunctorError, 2, ft); \
}
#define E(A, B, C) \ #define E(A, B, C) \
case A: \ case A: { \
{ Term ft[2], nt[2]; \ Term ft[2], nt[2]; \
nt[0] = MkAtomTerm(Yap_LookupAtom(C)); \ nt[0] = MkAtomTerm(Yap_LookupAtom(C)); \
nt[1] = MkVarTerm(); \ nt[1] = MkVarTerm(); \
Yap_unify(nt[1], culprit); \ Yap_unify(nt[1], culprit); \
ft[0] = Yap_MkApplTerm(Yap_MkFunctor(mkerrorct(B), 2), 2, nt); \ ft[0] = Yap_MkApplTerm(Yap_MkFunctor(mkerrorct(B), 2), 2, nt); \
ft[1] = info; \ ft[1] = info; \
return Yap_MkApplTerm(FunctorError,2,ft); } return Yap_MkApplTerm(FunctorError, 2, ft); \
}
#define E2(A, B, C, D) \ #define E2(A, B, C, D) \
case A: \ case A: { \
{ \
Term ft[2], nt[3]; \ Term ft[2], nt[3]; \
nt[0] = MkAtomTerm(Yap_LookupAtom(C)); \ nt[0] = MkAtomTerm(Yap_LookupAtom(C)); \
nt[1] = MkAtomTerm(Yap_LookupAtom(D)); \ nt[1] = MkAtomTerm(Yap_LookupAtom(D)); \
@ -565,8 +564,6 @@ void Yap_pushErrorContext(yap_error_descriptor_t *new_error) {
/* } */ /* } */
yap_error_descriptor_t *Yap_popErrorContext(bool pass) { yap_error_descriptor_t *Yap_popErrorContext(bool pass) {
if (pass && LOCAL_ActiveError->top_error->errorNo == YAP_NO_ERROR && if (pass && LOCAL_ActiveError->top_error->errorNo == YAP_NO_ERROR &&
LOCAL_ActiveError->errorNo != YAP_NO_ERROR) LOCAL_ActiveError->errorNo != YAP_NO_ERROR)
@ -638,8 +635,8 @@ void Yap_ThrowError__(const char *file, const char *function, int lineno,
* *
* + i=i(Comment): an user-written comment on this bug. * + i=i(Comment): an user-written comment on this bug.
*/ */
yamop *Yap_Error__(bool throw, const char *file, const char *function, int lineno, yamop *Yap_Error__(bool throw, const char *file, const char *function,
yap_error_number type, Term where, ...) { int lineno, yap_error_number type, Term where, ...) {
CACHE_REGS CACHE_REGS
va_list ap; va_list ap;
char *fmt; char *fmt;
@ -648,13 +645,21 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function, int linen
/* disallow recursive error handling */ /* disallow recursive error handling */
if (LOCAL_PrologMode & InErrorMode && (err = LOCAL_ActiveError->errorNo)) { if (LOCAL_PrologMode & InErrorMode && (err = LOCAL_ActiveError->errorNo)) {
fprintf(stderr, "%% ERROR %s %s WITHIN ERROR %s %s\n", Yap_errorClassName( Yap_errorClass(type)), Yap_errorName(type), Yap_errorClassName( Yap_errorClass(err)), Yap_errorName(err)); fprintf(stderr, "%% ERROR %s %s WITHIN ERROR %s %s\n",
Yap_errorClassName(Yap_errorClass(type)), Yap_errorName(type),
Yap_errorClassName(Yap_errorClass(err)), Yap_errorName(err));
Yap_RestartYap(1); Yap_RestartYap(1);
} }
if (LOCAL_DoingUndefp && type == EVALUATION_ERROR_UNDEFINED) { if (LOCAL_DoingUndefp && type == EVALUATION_ERROR_UNDEFINED) {
P = FAILCODE; P = FAILCODE;
CalculateStackGap(PASS_REGS1); CalculateStackGap(PASS_REGS1);
return P; return P;
}
if (where == 0L || where == TermNil) {
LOCAL_ActiveError->culprit = NULL;
} else {
LOCAL_ActiveError->culprit = Yap_TermToBuffer(
where, ENC_ISO_UTF8, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f);
} }
LOCAL_ActiveError->errorNo = type; LOCAL_ActiveError->errorNo = type;
LOCAL_ActiveError->errorAsText = Yap_errorName(type); LOCAL_ActiveError->errorAsText = Yap_errorName(type);
@ -682,15 +687,8 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function, int linen
if (type == INTERRUPT_EVENT) { if (type == INTERRUPT_EVENT) {
fprintf(stderr, "%% YAP exiting: cannot handle signal %d\n", fprintf(stderr, "%% YAP exiting: cannot handle signal %d\n",
(int)IntOfTerm(where)); (int)IntOfTerm(where));
LOCAL_PrologMode &= ~InErrorMode;
Yap_exit(1); Yap_exit(1);
} }
if (where == 0L || where == TermNil) {
LOCAL_ActiveError->culprit = NULL;
} else {
LOCAL_ActiveError->culprit = Yap_TermToBuffer(where, LOCAL_encoding, Quote_illegal_f | Handle_vars_f);
}
va_start(ap, where); va_start(ap, where);
fmt = va_arg(ap, char *); fmt = va_arg(ap, char *);
if (fmt != NULL) { if (fmt != NULL) {
@ -921,16 +919,15 @@ const char *Yap_errorClassName(yap_error_class_number e) {
yap_error_descriptor_t *Yap_GetException(void) { yap_error_descriptor_t *Yap_GetException(void) {
CACHE_REGS CACHE_REGS
if (LOCAL_ActiveError->errorNo != YAP_NO_ERROR) { if (LOCAL_ActiveError->errorNo != YAP_NO_ERROR) {
yap_error_descriptor_t *t = LOCAL_ActiveError, *nt = malloc(sizeof(yap_error_descriptor_t)); yap_error_descriptor_t *t = LOCAL_ActiveError,
*nt = malloc(sizeof(yap_error_descriptor_t));
memcpy(nt, t, sizeof(yap_error_descriptor_t)); memcpy(nt, t, sizeof(yap_error_descriptor_t));
return t; return nt;
} }
return 0; return 0;
} }
void Yap_PrintException(void) { void Yap_PrintException(void) { printErr(LOCAL_ActiveError); }
printErr(LOCAL_ActiveError);
}
bool Yap_RaiseException(void) { bool Yap_RaiseException(void) {
if (LOCAL_ActiveError->errorNo == YAP_NO_ERROR) if (LOCAL_ActiveError->errorNo == YAP_NO_ERROR)
@ -950,11 +947,12 @@ bool Yap_ResetException(yap_error_descriptor_t *i) {
static Int reset_exception(USES_REGS1) { return Yap_ResetException(worker_id); } static Int reset_exception(USES_REGS1) { return Yap_ResetException(worker_id); }
Term MkErrorTerm(yap_error_descriptor_t *t) Term MkErrorTerm(yap_error_descriptor_t *t) {
{
if (t->errorNo == THROW_EVENT) if (t->errorNo == THROW_EVENT)
return t->errorRawTerm; return t->errorRawTerm;
return mkerrort(t->errorNo, Yap_BufferToTerm(t->culprit, TermNil), err2list(t)); return mkerrort(t->errorNo,
Yap_BufferToTerm(t->culprit, TermNil),
err2list(t));
} }
static Int read_exception(USES_REGS1) { static Int read_exception(USES_REGS1) {
@ -972,7 +970,7 @@ static Int query_exception(USES_REGS1) {
query = RepAtom(AtomOfTerm(t))->StrOfAE; query = RepAtom(AtomOfTerm(t))->StrOfAE;
if (IsStringTerm(t)) if (IsStringTerm(t))
query = StringOfTerm(t); query = StringOfTerm(t);
if (!IsAddressTerm(Deref(ARG1))) if (!IsAddressTerm(Deref(ARG2)))
return false; return false;
yap_error_descriptor_t *y = AddressOfTerm(Deref(ARG2)); yap_error_descriptor_t *y = AddressOfTerm(Deref(ARG2));
Term t3 = Deref(ARG3); Term t3 = Deref(ARG3);
@ -985,20 +983,17 @@ static Int query_exception(USES_REGS1) {
} }
} }
static Int drop_exception(USES_REGS1) { static Int drop_exception(USES_REGS1) {
yap_error_descriptor_t *t = AddressOfTerm(Deref(ARG1)); yap_error_descriptor_t *t = AddressOfTerm(Deref(ARG1));
free(t); free(t);
return true; return true;
} }
static Int new_exception(USES_REGS1) { static Int new_exception(USES_REGS1) {
Term t = MkSysError(malloc(sizeof(yap_error_descriptor_t))); Term t = MkSysError(malloc(sizeof(yap_error_descriptor_t)));
return Yap_unify(ARG1, t); return Yap_unify(ARG1, t);
} }
static Int get_exception(USES_REGS1) { static Int get_exception(USES_REGS1) {
yap_error_descriptor_t *i; yap_error_descriptor_t *i;
Term t; Term t;
@ -1007,9 +1002,13 @@ static Int get_exception(USES_REGS1) {
if (i && i->errorNo != YAP_NO_ERROR) { if (i && i->errorNo != YAP_NO_ERROR) {
if (i->errorNo == THROW_EVENT) if (i->errorNo == THROW_EVENT)
t = i->errorRawTerm; t = i->errorRawTerm;
else else if (i->culprit != NULL) {
t = mkerrort(i->errorNo, Yap_BufferToTerm(i->culprit, TermNil), MkSysError(i)); t = mkerrort(i->errorNo, Yap_BufferToTerm(i->culprit,TermNil),
Yap_ResetException(i); MkSysError(i));
} else {
t = mkerrort(i->errorNo, TermNil, MkSysError(i));
}
Yap_ResetException(LOCAL_ActiveError);
LOCAL_CommittedError = NULL; LOCAL_CommittedError = NULL;
Int rc = Yap_unify(t, ARG1); Int rc = Yap_unify(t, ARG1);
return rc; return rc;
@ -1017,40 +1016,90 @@ static Int get_exception(USES_REGS1) {
return false; return false;
} }
yap_error_descriptor_t *Yap_UserError(Term t, yap_error_descriptor_t *i) {
Term t1, t2;
t1 = ArgOfTerm(1, t);
t2 = ArgOfTerm(2, t);
char ename[65];
yap_error_descriptor_t *Yap_UserError( Term t, Term t1, yap_error_descriptor_t *i) {
Term t2;
Functor f = FunctorOfTerm(t);
LOCAL_ActiveError->culprit = Yap_TermToBuffer(ArgOfTerm(1, t), LOCAL_encoding, 0);
if (ArityOfFunctor(f) == 2) {
LOCAL_ActiveError->errorGoal = Yap_TermToBuffer(ArgOfTerm(2, t), LOCAL_encoding, 0);
}
Yap_prolog_add_culprit(LOCAL_ActiveError PASS_REGS);
// LOCAL_Error_TYPE = ERROR_EVENT; // LOCAL_Error_TYPE = ERROR_EVENT;
if (IsApplTerm(t1) && IsAtomTerm((t2 = ArgOfTerm(1, t1)))) {
LOCAL_ActiveError->errorAsText = RepAtom(AtomOfTerm(t2))->StrOfAE;
LOCAL_ActiveError->classAsText = RepAtom(NameOfFunctor(FunctorOfTerm(t1)))->StrOfAE;
} else if (IsAtomTerm(t1)) {
LOCAL_ActiveError->errorAsText = RepAtom(AtomOfTerm(t1))->StrOfAE;
LOCAL_ActiveError->classAsText = NULL;
}
LOCAL_ActiveError->errorNo = USER_EVENT; LOCAL_ActiveError->errorNo = USER_EVENT;
LOCAL_ActiveError->errorClass = EVENT; LOCAL_ActiveError->errorClass = EVENT;
if (IsApplTerm(t1)) {
Functor f1 = FunctorOfTerm(t1);
arity_t a1 = ArityOfFunctor(f1);
LOCAL_ActiveError->culprit =
Yap_TermToBuffer(ArgOfTerm(a1, t1), ENC_ISO_UTF8, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f);
if (a1 == 1) {
return NULL;
} else {
Term ti;
if (!IsAtomTerm((ti = ArgOfTerm(1, t1))))
return NULL;
strncpy(ename, RepAtom(AtomOfTerm(ti))->StrOfAE, 64);
}
if (a1 == 3) {
Term ti;
if (!IsAtomTerm((ti = ArgOfTerm(2, t1))))
return NULL;
strncat(ename, " ", 64);
strncat(ename, RepAtom(AtomOfTerm(ti))->StrOfAE, 64);
} else if (a1 > 3) {
return NULL;
}
LOCAL_ActiveError->errorAsText = ename;
LOCAL_ActiveError->classAsText = RepAtom(NameOfFunctor(f1))->StrOfAE;
int j; int j;
for (j = 0; j < sizeof(c_error_list) / sizeof(struct c_error_info); j++) { for (j = 0; j < sizeof(c_error_list) / sizeof(struct c_error_info); j++) {
if (!strcmp(c_error_list[j].name, LOCAL_ActiveError->errorAsText) && if (!strcmp(c_error_list[j].name, LOCAL_ActiveError->errorAsText) &&
(c_error_list[j].class == 0 || (c_error_list[j].class == 0 ||
!strcmp(LOCAL_ActiveError->classAsText,c_error_class_name[c_error_list[j].class]))) !strcmp(LOCAL_ActiveError->classAsText,
{ c_error_class_name[c_error_list[j].class]))) {
if (c_error_list[j].class != PERMISSION_ERROR ||
(t1 = ArgOfTerm(2, t1) && IsAtomTerm(t1) &&
!strcmp(c_error_list[j].name,
RepAtom(AtomOfTerm(t1))->StrOfAE))) {
LOCAL_ActiveError->errorNo = j; LOCAL_ActiveError->errorNo = j;
LOCAL_ActiveError->errorClass = c_error_list[j].class; LOCAL_ActiveError->errorClass = c_error_list[j].class;
break; break;
} }
} }
Yap_prolog_add_culprit(LOCAL_ActiveError PASS_REGS1); }
return } else if (IsAtomTerm(t1)) {
LOCAL_ActiveError; const char *err = RepAtom(AtomOfTerm(t1))->StrOfAE;
if (!strcmp(err, "instantiation_error")) {
LOCAL_ActiveError->errorClass = INSTANTIATION_ERROR_CLASS;
LOCAL_ActiveError->classAsText = "instantiation_error";
LOCAL_ActiveError->errorAsText = "instantiation_error";
LOCAL_ActiveError->errorNo = INSTANTIATION_ERROR;
} else if (!strcmp(err, "uninstantiation_error")) {
LOCAL_ActiveError->errorClass = UNINSTANTIATION_ERROR_CLASS;
LOCAL_ActiveError->classAsText = "uninstantiation_error";
LOCAL_ActiveError->errorAsText = "uninstantiation_error";
LOCAL_ActiveError->errorNo = UNINSTANTIATION_ERROR;
}
}
while (IsPairTerm(t2)) {
Term hd = HeadOfTerm(t2);
if (IsPairTerm(hd)) {
Term hdhd = HeadOfTerm(hd);
Term hdtl = TailOfTerm(hd);
if (hdhd == Termg) {
Term n = ArgOfTerm(1,hdtl);
LOCAL_ActiveError->errorGoal = Yap_TermToBuffer(n, ENC_ISO_UTF8, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f);
}
}
t2 = TailOfTerm(t2);
}
Yap_prolog_add_culprit(LOCAL_ActiveError PASS_REGS);
{
char *errs = malloc(strlen(LOCAL_ActiveError->errorAsText)+1);
strcpy(errs, LOCAL_ActiveError->errorAsText);
LOCAL_ActiveError->errorAsText = errs;
}
return LOCAL_ActiveError;
} }
static Int is_boolean(USES_REGS1) { static Int is_boolean(USES_REGS1) {

View File

@ -2055,15 +2055,12 @@ bool Yap_JumpToEnv(void) {
/* This does very nasty stuff!!!!! */ /* This does very nasty stuff!!!!! */
static Int jump_env(USES_REGS1) { static Int jump_env(USES_REGS1) {
Term t = Deref(ARG1), t0 = t, t1; Term t = Deref(ARG1), t0 = t;
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, t, "throw ball must be bound"); Yap_Error(INSTANTIATION_ERROR, t, "throw ball must be bound");
return false; return false;
} else if (IsApplTerm(t) && FunctorOfTerm(t) == FunctorError } else if (IsApplTerm(t) && FunctorOfTerm(t) == FunctorError) {
&& (t1 = ArgOfTerm(1, t)) LOCAL_ActiveError = Yap_UserError(t0, LOCAL_ActiveError);
&& IsPairTerm((t = ArgOfTerm(2, t)))
&& IsApplTerm((t = HeadOfTerm(t)))) {
LOCAL_ActiveError = Yap_UserError(t, t1, LOCAL_ActiveError);
} else { } else {
LOCAL_Error_TYPE = THROW_EVENT; LOCAL_Error_TYPE = THROW_EVENT;
LOCAL_ActiveError->errorAsText = NULL; LOCAL_ActiveError->errorAsText = NULL;

View File

@ -165,8 +165,10 @@ The following is the list of the declarations of the predefined operators:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:-op(1200,fx,['?-', ':-']). :-op(1200,fx,['?-', ':-']).
:-op(1200,xfx,[':-','-->']). :-op(1200,xfx,[':-','-->']).
:-op(1150,fx,[block,dynamic,mode,public,multifile,meta_predicate, :-op(1150,fx,[block,
sequential,table,initialization]). discontiguous,dynamic,
initialization,mode,multifile,meta_predicate,
public,sequential,table]).
:-op(1100,xfy,[';','|']). :-op(1100,xfy,[';','|']).
:-op(1050,xfy,->). :-op(1050,xfy,->).
:-op(1000,xfy,','). :-op(1000,xfy,',').

View File

@ -1165,7 +1165,11 @@ yap_error_descriptor_t * set_clause_info(yap_error_descriptor_t *t, yamop *cod
} }
return t; return t;
} else { } else {
return NULL; t->prologPredFirstLine = 0;
t->prologPredLine = t->errorLine;
t->prologPredLastLine = 0;
t->prologPredFile = t->errorFile;
return t;
} }
} }
@ -1203,22 +1207,32 @@ yap_error_descriptor_t * Yap_prolog_add_culprit(yap_error_descriptor_t *t PASS_R
} else { } else {
CELL *curENV = ENV; CELL *curENV = ENV;
yamop *curCP = CP; yamop *curCP = CP;
choiceptr curB;
PredEntry *pe = EnvPreg(curCP); PredEntry *pe = EnvPreg(curCP);
while (curCP != YESCODE) { while (curCP != YESCODE && curB) {
if (curENV < (CELL *)curB) {
pe = EnvPreg(curCP);
curENV = (CELL *)(curENV[E_E]); curENV = (CELL *)(curENV[E_E]);
if (curENV < ASP || curENV >= LCL0) { if (curENV < ASP || curENV >= LCL0) {
break; break;
} }
pe = EnvPreg(curCP); curCP = (yamop *)curENV[E_CP];
if (pe == NULL) { if (pe == NULL) {
pe = PredMetaCall; pe = PredMetaCall;
} }
if (pe->ModuleOfPred) if (pe->ModuleOfPred || !(pe->PredFlags & HiddenPredFlag))
return set_clause_info(t, curCP, pe); return set_clause_info(t, curCP, pe);
} else {
pe = curB->cp_ap->y_u.Otapl.p;
if (pe && (pe->ModuleOfPred || !(pe->PredFlags & HiddenPredFlag)))
return set_clause_info(t, curB->cp_ap, pe);
curB = curB->cp_b;
}
}
curCP = (yamop *)(curENV[E_CP]); curCP = (yamop *)(curENV[E_CP]);
} }
}
return NULL; return NULL;
} }

View File

@ -1756,7 +1756,7 @@ p_new_mutex(void)
p_with_mutex( USES_REGS1 ) p_with_mutex( USES_REGS1 )
{ {
Int mut; Int mut;
Term t1 = Deref(ARG1), excep; Term t1 = Deref(ARG1);
Int rc = FALSE; Int rc = FALSE;
Int creeping = Yap_get_signal(YAP_CREEP_SIGNAL); Int creeping = Yap_get_signal(YAP_CREEP_SIGNAL);
PredEntry *pe; PredEntry *pe;
@ -1813,11 +1813,11 @@ p_new_mutex(void)
} }
end: end:
ARG1 = MkIntegerTerm(mut); ARG1 = MkIntegerTerm(mut);
excep = Yap_GetException(); yap_error_descriptor_t *err = Yap_GetException();
if (creeping) { if (creeping) {
Yap_signal( YAP_CREEP_SIGNAL ); Yap_signal( YAP_CREEP_SIGNAL );
} else if ( excep != 0) { } else if ( err ) {
LOCAL_ActiveError->errorNo = IntegerOfTerm(excep); LOCAL_ActiveError->errorNo = err->errorNo;
return Yap_JumpToEnv(); return Yap_JumpToEnv();
} }
return rc; return rc;

View File

@ -1258,6 +1258,8 @@ char *Yap_TermToBuffer(Term t, encoding_t enc, int flags) {
if (sno < 0) if (sno < 0)
return NULL; return NULL;
if (t == 0)
return NULL;
if (enc) if (enc)
GLOBAL_Stream[sno].encoding = enc; GLOBAL_Stream[sno].encoding = enc;
else else

View File

@ -203,10 +203,11 @@ static void consult(const char *b_file USES_REGS) {
} else { } else {
YAP_CompileClause(t); YAP_CompileClause(t);
} }
Term terr; yap_error_descriptor_t *errd;
Yap_PrintException(); if ((errd = Yap_GetException())) {
if ((terr = Yap_GetException())) fprintf(stderr, "%s:%ld:0: Error %s %s Found\n", errd->errorFile, (long int) errd->errorLine, errd->classAsText,
fprintf(stderr,"Exception Found\n"); errd->errorAsText);
}
} while (t != TermEof); } while (t != TermEof);
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
YAP_EndConsult(c_stream, &osno, full); YAP_EndConsult(c_stream, &osno, full);

View File

@ -646,7 +646,6 @@ bool YAPQuery::next() {
CACHE_REGS CACHE_REGS
bool result = false; bool result = false;
sigjmp_buf buf, *oldp = LOCAL_RestartEnv; sigjmp_buf buf, *oldp = LOCAL_RestartEnv;
Term terr;
e = nullptr; e = nullptr;
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
if (!q_open) if (!q_open)

View File

@ -171,6 +171,7 @@ A Full N "full"
A Functor N "functor" A Functor N "functor"
A GT N ">" A GT N ">"
A GVar N "var" A GVar N "var"
A g N "g"
A Gc F "$gc" A Gc F "$gc"
A GcMargin F "$gc_margin" A GcMargin F "$gc_margin"
A GcTrace F "$gc_trace" A GcTrace F "$gc_trace"
@ -429,6 +430,7 @@ A User N "user"
A UserErr N "user_error" A UserErr N "user_error"
A UserIn N "user_input" A UserIn N "user_input"
A UserOut N "user_output" A UserOut N "user_output"
A UTF8 N "utf8"
A DollarVar N "$VAR" A DollarVar N "$VAR"
A VBar N "|" A VBar N "|"
A VarBranches N "var_branches" A VarBranches N "var_branches"
@ -504,6 +506,7 @@ F Dot9 Dot 9
F DoubleArrow DoubleArrow 2 F DoubleArrow DoubleArrow 2
F DoubleSlash DoubleSlash 2 F DoubleSlash DoubleSlash 2
F EmptySquareBrackets EmptySquareBrackets 2 F EmptySquareBrackets EmptySquareBrackets 2
F Encoding Encoding 1
F Eq Eq 2 F Eq Eq 2
F Error Error 2 F Error Error 2
F EvaluationError EvaluationError 1 F EvaluationError EvaluationError 1

View File

@ -1615,7 +1615,7 @@ INLINE_ONLY inline EXTERN Term MkSysError(yap_error_descriptor_t *i) {
Term et = MkAddressTerm(i); Term et = MkAddressTerm(i);
return Yap_MkApplTerm( FunctorException, 1, &et); return Yap_MkApplTerm( FunctorException, 1, &et);
} }
yap_error_descriptor_t *Yap_UserError( Term t, Term t1, yap_error_descriptor_t *i); yap_error_descriptor_t *Yap_UserError( Term t, yap_error_descriptor_t *i);
extern bool Yap_RaiseException(void); extern bool Yap_RaiseException(void);

View File

@ -166,6 +166,7 @@
AtomFunctor = Yap_LookupAtom("functor"); TermFunctor = MkAtomTerm(AtomFunctor); AtomFunctor = Yap_LookupAtom("functor"); TermFunctor = MkAtomTerm(AtomFunctor);
AtomGT = Yap_LookupAtom(">"); TermGT = MkAtomTerm(AtomGT); AtomGT = Yap_LookupAtom(">"); TermGT = MkAtomTerm(AtomGT);
AtomGVar = Yap_LookupAtom("var"); TermGVar = MkAtomTerm(AtomGVar); AtomGVar = Yap_LookupAtom("var"); TermGVar = MkAtomTerm(AtomGVar);
Atomg = Yap_LookupAtom("g"); Termg = MkAtomTerm(Atomg);
AtomGc = Yap_FullLookupAtom("$gc"); TermGc = MkAtomTerm(AtomGc); AtomGc = Yap_FullLookupAtom("$gc"); TermGc = MkAtomTerm(AtomGc);
AtomGcMargin = Yap_FullLookupAtom("$gc_margin"); TermGcMargin = MkAtomTerm(AtomGcMargin); AtomGcMargin = Yap_FullLookupAtom("$gc_margin"); TermGcMargin = MkAtomTerm(AtomGcMargin);
AtomGcTrace = Yap_FullLookupAtom("$gc_trace"); TermGcTrace = MkAtomTerm(AtomGcTrace); AtomGcTrace = Yap_FullLookupAtom("$gc_trace"); TermGcTrace = MkAtomTerm(AtomGcTrace);
@ -424,6 +425,7 @@
AtomUserErr = Yap_LookupAtom("user_error"); TermUserErr = MkAtomTerm(AtomUserErr); AtomUserErr = Yap_LookupAtom("user_error"); TermUserErr = MkAtomTerm(AtomUserErr);
AtomUserIn = Yap_LookupAtom("user_input"); TermUserIn = MkAtomTerm(AtomUserIn); AtomUserIn = Yap_LookupAtom("user_input"); TermUserIn = MkAtomTerm(AtomUserIn);
AtomUserOut = Yap_LookupAtom("user_output"); TermUserOut = MkAtomTerm(AtomUserOut); AtomUserOut = Yap_LookupAtom("user_output"); TermUserOut = MkAtomTerm(AtomUserOut);
AtomUTF8 = Yap_LookupAtom("utf8"); TermUTF8 = MkAtomTerm(AtomUTF8);
AtomDollarVar = Yap_LookupAtom("$VAR"); TermDollarVar = MkAtomTerm(AtomDollarVar); AtomDollarVar = Yap_LookupAtom("$VAR"); TermDollarVar = MkAtomTerm(AtomDollarVar);
AtomVBar = Yap_LookupAtom("|"); TermVBar = MkAtomTerm(AtomVBar); AtomVBar = Yap_LookupAtom("|"); TermVBar = MkAtomTerm(AtomVBar);
AtomVarBranches = Yap_LookupAtom("var_branches"); TermVarBranches = MkAtomTerm(AtomVarBranches); AtomVarBranches = Yap_LookupAtom("var_branches"); TermVarBranches = MkAtomTerm(AtomVarBranches);
@ -499,6 +501,7 @@
FunctorDoubleArrow = Yap_MkFunctor(AtomDoubleArrow,2); FunctorDoubleArrow = Yap_MkFunctor(AtomDoubleArrow,2);
FunctorDoubleSlash = Yap_MkFunctor(AtomDoubleSlash,2); FunctorDoubleSlash = Yap_MkFunctor(AtomDoubleSlash,2);
FunctorEmptySquareBrackets = Yap_MkFunctor(AtomEmptySquareBrackets,2); FunctorEmptySquareBrackets = Yap_MkFunctor(AtomEmptySquareBrackets,2);
FunctorEncoding = Yap_MkFunctor(AtomEncoding,1);
FunctorEq = Yap_MkFunctor(AtomEq,2); FunctorEq = Yap_MkFunctor(AtomEq,2);
FunctorError = Yap_MkFunctor(AtomError,2); FunctorError = Yap_MkFunctor(AtomError,2);
FunctorEvaluationError = Yap_MkFunctor(AtomEvaluationError,1); FunctorEvaluationError = Yap_MkFunctor(AtomEvaluationError,1);

View File

@ -166,6 +166,7 @@
AtomFunctor = AtomAdjust(AtomFunctor); TermFunctor = MkAtomTerm(AtomFunctor); AtomFunctor = AtomAdjust(AtomFunctor); TermFunctor = MkAtomTerm(AtomFunctor);
AtomGT = AtomAdjust(AtomGT); TermGT = MkAtomTerm(AtomGT); AtomGT = AtomAdjust(AtomGT); TermGT = MkAtomTerm(AtomGT);
AtomGVar = AtomAdjust(AtomGVar); TermGVar = MkAtomTerm(AtomGVar); AtomGVar = AtomAdjust(AtomGVar); TermGVar = MkAtomTerm(AtomGVar);
Atomg = AtomAdjust(Atomg); Termg = MkAtomTerm(Atomg);
AtomGc = AtomAdjust(AtomGc); TermGc = MkAtomTerm(AtomGc); AtomGc = AtomAdjust(AtomGc); TermGc = MkAtomTerm(AtomGc);
AtomGcMargin = AtomAdjust(AtomGcMargin); TermGcMargin = MkAtomTerm(AtomGcMargin); AtomGcMargin = AtomAdjust(AtomGcMargin); TermGcMargin = MkAtomTerm(AtomGcMargin);
AtomGcTrace = AtomAdjust(AtomGcTrace); TermGcTrace = MkAtomTerm(AtomGcTrace); AtomGcTrace = AtomAdjust(AtomGcTrace); TermGcTrace = MkAtomTerm(AtomGcTrace);
@ -424,6 +425,7 @@
AtomUserErr = AtomAdjust(AtomUserErr); TermUserErr = MkAtomTerm(AtomUserErr); AtomUserErr = AtomAdjust(AtomUserErr); TermUserErr = MkAtomTerm(AtomUserErr);
AtomUserIn = AtomAdjust(AtomUserIn); TermUserIn = MkAtomTerm(AtomUserIn); AtomUserIn = AtomAdjust(AtomUserIn); TermUserIn = MkAtomTerm(AtomUserIn);
AtomUserOut = AtomAdjust(AtomUserOut); TermUserOut = MkAtomTerm(AtomUserOut); AtomUserOut = AtomAdjust(AtomUserOut); TermUserOut = MkAtomTerm(AtomUserOut);
AtomUTF8 = AtomAdjust(AtomUTF8); TermUTF8 = MkAtomTerm(AtomUTF8);
AtomDollarVar = AtomAdjust(AtomDollarVar); TermDollarVar = MkAtomTerm(AtomDollarVar); AtomDollarVar = AtomAdjust(AtomDollarVar); TermDollarVar = MkAtomTerm(AtomDollarVar);
AtomVBar = AtomAdjust(AtomVBar); TermVBar = MkAtomTerm(AtomVBar); AtomVBar = AtomAdjust(AtomVBar); TermVBar = MkAtomTerm(AtomVBar);
AtomVarBranches = AtomAdjust(AtomVarBranches); TermVarBranches = MkAtomTerm(AtomVarBranches); AtomVarBranches = AtomAdjust(AtomVarBranches); TermVarBranches = MkAtomTerm(AtomVarBranches);
@ -499,6 +501,7 @@
FunctorDoubleArrow = FuncAdjust(FunctorDoubleArrow); FunctorDoubleArrow = FuncAdjust(FunctorDoubleArrow);
FunctorDoubleSlash = FuncAdjust(FunctorDoubleSlash); FunctorDoubleSlash = FuncAdjust(FunctorDoubleSlash);
FunctorEmptySquareBrackets = FuncAdjust(FunctorEmptySquareBrackets); FunctorEmptySquareBrackets = FuncAdjust(FunctorEmptySquareBrackets);
FunctorEncoding = FuncAdjust(FunctorEncoding);
FunctorEq = FuncAdjust(FunctorEq); FunctorEq = FuncAdjust(FunctorEq);
FunctorError = FuncAdjust(FunctorError); FunctorError = FuncAdjust(FunctorError);
FunctorEvaluationError = FuncAdjust(FunctorEvaluationError); FunctorEvaluationError = FuncAdjust(FunctorEvaluationError);

View File

@ -166,6 +166,7 @@ X_API EXTERNAL Atom AtomFull; X_API EXTERNAL Term TermFull;
X_API EXTERNAL Atom AtomFunctor; X_API EXTERNAL Term TermFunctor; X_API EXTERNAL Atom AtomFunctor; X_API EXTERNAL Term TermFunctor;
X_API EXTERNAL Atom AtomGT; X_API EXTERNAL Term TermGT; X_API EXTERNAL Atom AtomGT; X_API EXTERNAL Term TermGT;
X_API EXTERNAL Atom AtomGVar; X_API EXTERNAL Term TermGVar; X_API EXTERNAL Atom AtomGVar; X_API EXTERNAL Term TermGVar;
X_API EXTERNAL Atom Atomg; X_API EXTERNAL Term Termg;
X_API EXTERNAL Atom AtomGc; X_API EXTERNAL Term TermGc; X_API EXTERNAL Atom AtomGc; X_API EXTERNAL Term TermGc;
X_API EXTERNAL Atom AtomGcMargin; X_API EXTERNAL Term TermGcMargin; X_API EXTERNAL Atom AtomGcMargin; X_API EXTERNAL Term TermGcMargin;
X_API EXTERNAL Atom AtomGcTrace; X_API EXTERNAL Term TermGcTrace; X_API EXTERNAL Atom AtomGcTrace; X_API EXTERNAL Term TermGcTrace;
@ -424,6 +425,7 @@ X_API EXTERNAL Atom AtomUser; X_API EXTERNAL Term TermUser;
X_API EXTERNAL Atom AtomUserErr; X_API EXTERNAL Term TermUserErr; X_API EXTERNAL Atom AtomUserErr; X_API EXTERNAL Term TermUserErr;
X_API EXTERNAL Atom AtomUserIn; X_API EXTERNAL Term TermUserIn; X_API EXTERNAL Atom AtomUserIn; X_API EXTERNAL Term TermUserIn;
X_API EXTERNAL Atom AtomUserOut; X_API EXTERNAL Term TermUserOut; X_API EXTERNAL Atom AtomUserOut; X_API EXTERNAL Term TermUserOut;
X_API EXTERNAL Atom AtomUTF8; X_API EXTERNAL Term TermUTF8;
X_API EXTERNAL Atom AtomDollarVar; X_API EXTERNAL Term TermDollarVar; X_API EXTERNAL Atom AtomDollarVar; X_API EXTERNAL Term TermDollarVar;
X_API EXTERNAL Atom AtomVBar; X_API EXTERNAL Term TermVBar; X_API EXTERNAL Atom AtomVBar; X_API EXTERNAL Term TermVBar;
X_API EXTERNAL Atom AtomVarBranches; X_API EXTERNAL Term TermVarBranches; X_API EXTERNAL Atom AtomVarBranches; X_API EXTERNAL Term TermVarBranches;
@ -556,6 +558,8 @@ X_API EXTERNAL Functor FunctorDoubleSlash;
X_API EXTERNAL Functor FunctorEmptySquareBrackets; X_API EXTERNAL Functor FunctorEmptySquareBrackets;
X_API EXTERNAL Functor FunctorEncoding;
X_API EXTERNAL Functor FunctorEq; X_API EXTERNAL Functor FunctorEq;
X_API EXTERNAL Functor FunctorError; X_API EXTERNAL Functor FunctorError;

View File

@ -415,6 +415,7 @@ A User N "user"
A UserErr N "user_error" A UserErr N "user_error"
A UserIn N "user_input" A UserIn N "user_input"
A UserOut N "user_output" A UserOut N "user_output"
A UTF8 N "utf8"
A DollarVar N "$VAR" A DollarVar N "$VAR"
A VBar N "|" A VBar N "|"
A VarBranches N "var_branches" A VarBranches N "var_branches"
@ -490,6 +491,7 @@ F Dot9 Dot 9
F DoubleSlash DoubleSlash 2 F DoubleSlash DoubleSlash 2
F EmptySquareBrackets EmptySquareBrackets 2 F EmptySquareBrackets EmptySquareBrackets 2
F EmptyCurlyBrackets EmptyCurlyBrackets 2 F EmptyCurlyBrackets EmptyCurlyBrackets 2
F Encoding Encoding 1
F Eq Eq 2 F Eq Eq 2
F Error Error 2 F Error Error 2
F EvaluationError EvaluationError 1 F EvaluationError EvaluationError 1

View File

@ -63,12 +63,12 @@ system_error(Type,Goal) :-
'$do_error'(Type,Goal) :- '$do_error'(Type,Goal) :-
throw(error(Type, [error(Goal)])). throw(error(Type, [[g|g(Goal)]])).
/** /**
* @pred system_error( +Error, +Cause, +Culprit) * @pred system_error( +Error, +Cause, +Culprit)
* *
* Generate a system error _Error_, informing the source goal _Cause_ and a possible _Culprit_. * Generate a system error _Error_, informing the source goal _Cause_
* *
* *
* ~~~~~~~~~~ * ~~~~~~~~~~
@ -76,9 +76,8 @@ system_error(Type,Goal) :-
* *
* *
*/ */
system_error(Type,Goal,Culprit) :- system_error(Type,Goal) :-
ancestor_location(Goal, Culprit), hrow(error(Type, [[g|g(Goal)]])).
throw(error(Type, [error(Goal, Culprit)])).
'$do_pi_error'(type_error(callable,Name/0),Message) :- !, '$do_pi_error'(type_error(callable,Name/0),Message) :- !,
'$do_error'(type_error(callable,Name),Message). '$do_error'(type_error(callable,Name),Message).
@ -132,7 +131,7 @@ system_error(Type,Goal,Culprit) :-
functor(Error, Severity, _), functor(Error, Severity, _),
print_message(Severity, Error), !. print_message(Severity, Error), !.
%'$process_error'(error(Msg, Where), _) :- %'$process_error'(error(Msg, Where), _) :-
% Print_message(error,error(Msg, [g|Where])), !. % Print_message(error,error(Msg, [g|fWhere])), !.
'$process_error'(Throw, _) :- '$process_error'(Throw, _) :-
print_message(error,error(unhandled_exception,Throw)). print_message(error,error(unhandled_exception,Throw)).

View File

@ -213,7 +213,7 @@ compose_message( loaded(included,AbsFileName,Mod,Time,Space), _Level) --> !,
compose_message( loaded(What,AbsoluteFileName,Mod,Time,Space), _Level) --> !, compose_message( loaded(What,AbsoluteFileName,Mod,Time,Space), _Level) --> !,
[ '~a ~a in module ~a, ~d msec ~d bytes' - [ '~a ~a in module ~a, ~d msec ~d bytes' -
[What, AbsoluteFileName,Mod,Time,Space] ]. [What, AbsoluteFileName,Mod,Time,Space] ].
compose_message(error(signal(SIG,_), _), _) --> compose_message(signal(SIG,_), _) -->
!, !,
[ 'UNEXPECTED SIGNAL: ~a' - [SIG] ]. [ 'UNEXPECTED SIGNAL: ~a' - [SIG] ].
compose_message(trace_command(C), _Leve) --> compose_message(trace_command(C), _Leve) -->
@ -232,21 +232,18 @@ compose_message(yes, _Level) --> !,
[ 'yes'- [] ]. [ 'yes'- [] ].
compose_message(error(E, exception(Exc)), Level) --> compose_message(error(E, exception(Exc)), Level) -->
{ '$show_consult_level'(LC) }, { '$show_consult_level'(LC) },
location( Exc, Level, LC), location(error(E, exception(Exc)), Level, LC),
main_message( Exc, Level, LC ), main_message(error(E, exception(Exc)) , Level, LC ),
c_goal( Exc, Level ), c_goal( Exc, Level ),
caller( Exc, Level ), caller( Exc, Level ),
extra_info( Exc, Level ), extra_info( Exc, Level ),
!, !,
[nl,nl]. [nl,nl].
compose_message(error(E,[I|Is]), Level) --> compose_message(error(E,[I|Is]), Level) -->
{ Level == error -> true ; Level == warning }, { translate_info([I|Is], In) },
{ '$show_consult_level'(LC), compose_message( e(E, In), Level),
translate_info([I|Is], In))
},
compose_message( e(Err, In), Level),
[nl,nl]. [nl,nl].
compose_message(Throw), _Leve) --> compose_message(Throw, _Leve) -->
!, !,
[ 'UNHANDLED EXCEPTION - message ~w unknown' - [Throw] ]. [ 'UNHANDLED EXCEPTION - message ~w unknown' - [Throw] ].
@ -254,7 +251,7 @@ translate_info([I1|I2],exception(R) ) :-
!, !,
'$new_exception'(R), '$new_exception'(R),
tinfo(R, [I1|I2], []). tinfo(R, [I1|I2], []).
translate_info(E, none ). translate_info(_E, none ).
tinfo(_Reg) --> tinfo(_Reg) -->
!. !.
@ -263,7 +260,12 @@ tinfo(Reg) -->
tinfo(Reg). tinfo(Reg).
addinfo( Desc) --> addinfo( Desc) -->
( [[p|p(M,Na,Ar,File,FilePos)]] ( ;
[[p]]
->
[]
;
[[p|p(M,Na,Ar,File,FilePos)]]
-> ->
{ {
'$query_exception'(prologPredFile, Desc, File), '$query_exception'(prologPredFile, Desc, File),
@ -273,7 +275,11 @@ addinfo( Desc) -->
'$query_exception'(prologPredArity, Desc, Ar) '$query_exception'(prologPredArity, Desc, Ar)
} }
; ;
[e|p(M,Na,Ar,File,FilePos)], Desc) [[e]]
->
[]
;
[[e|p(M,Na,Ar,File,FilePos)]]
-> ->
{ {
'$query_exception'(prologPredFile, Desc, File), '$query_exception'(prologPredFile, Desc, File),
@ -291,11 +297,15 @@ addinfo( Desc) -->
'$query_exception'(errorLine, Desc, Line) '$query_exception'(errorLine, Desc, Line)
} }
; ;
[[g|g(Call)] [[g|g(Call)]]
-> ->
{ {
'$query_exception'(errorGoal, Desc, Call) '$query_exception'(errorGoal, Desc, Call)
} }
;
[[h|p(M,Na,Ar,File,FilePos)g)](_)]]
->
[]
). ).
@ -306,16 +316,6 @@ location(error(syntax_error(_),info(between(_,LN,_), FileName, _ChrPos, _Err)),
location(error(style_check(style_check(_,LN,FileName,_ ) ),_), _ , _) --> location(error(style_check(style_check(_,LN,FileName,_ ) ),_), _ , _) -->
!, !,
[ '~a:~d:0 ' - [FileName,LN] ] . [ '~a:~d:0 ' - [FileName,LN] ] .
location( error(_,exception(Desc)), Level, LC ) -->
{ source_location(F0, L),
stream_property(_Stream, alias(loop_stream)),
!,
'$query_exception'(prologPredModule, Desc, M),
'$query_exception'(prologPredName, Desc, Na),
'$query_exception'(prologPredArity, Desc, Ar)
},
display_consulting( F0, Level, LC ),
[ '~a:~d:0 ~a in ~a:~q/~d:'-[F0, L,Level,M,Na,Ar] ].
location( error(_,exception(Desc)), Level, LC ) --> location( error(_,exception(Desc)), Level, LC ) -->
{ '$query_exception'(prologPredFile, Desc, File), { '$query_exception'(prologPredFile, Desc, File),
'$query_exception'(prologPredLine, Desc, FilePos), '$query_exception'(prologPredLine, Desc, FilePos),
@ -324,7 +324,7 @@ location( error(_,exception(Desc)), Level, LC ) -->
'$query_exception'(prologPredArity, Desc, Ar) '$query_exception'(prologPredArity, Desc, Ar)
}, },
display_consulting( File, Level, LC ), display_consulting( File, Level, LC ),
[ '~a:~d:0 ~a in ~a:~q/~d:'-[File, FilePos,Level,M,Na,Ar] ]. [ '~s:~d:0 ~a in ~s:~s/~d:'-[File, FilePos,Level,M,Na,Ar] ].
%message(loaded(Past,AbsoluteFileName,user,Msec,Bytes), Prefix, Suffix) :- !, %message(loaded(Past,AbsoluteFileName,user,Msec,Bytes), Prefix, Suffix) :- !,
main_message(error(Msg,In), _, _) --> {var(In)}, !, main_message(error(Msg,In), _, _) --> {var(In)}, !,
@ -806,8 +806,8 @@ print_lines( S, Prefixes, Key) -->
!, !,
{ nl(S), { nl(S),
Prefixes = [PrefixS - Cmds|More], Prefixes = [PrefixS - Cmds|More],
format(S, PrefixS, Cmds) format(S, PrefixS, []Cmds)
}, }
{ {
More == [] More == []
-> ->

View File

@ -32,8 +32,6 @@
] ]
). ).
:- op(1150, fx, [multifile,discontiguous]).
'$log_upd'(1). '$log_upd'(1).
/** /**

View File

@ -212,10 +212,10 @@
( exists('~/.prologrc') -> [-'~/.prologrc'] ; true ), ( exists('~/.prologrc') -> [-'~/.prologrc'] ; true ),
( exists('~/prolog.ini') -> [-'~/prolog.ini'] ; true ))). ( exists('~/prolog.ini') -> [-'~/prolog.ini'] ; true ))).
% die on signal default. % % die on signal default. %
'$signal_def'(sig_usr1, throw(error(signal(usr1,[]),true))). '$signal_def'(sig_usr1, throw(signal(usr1,[]))).
'$signal_def'(sig_usr2, throw(error(signal(usr2,[]),true))). '$signal_def'(sig_usr2, throw(signal(usr2,[]))).
'$signal_def'(sig_pipe, throw(error(signal(pipe,[]),true))). '$signal_def'(sig_pipe, throw(signal(pipe,[]))).
'$signal_def'(sig_fpe, throw(error(signal(fpe,[]),true))). '$signal_def'(sig_fpe, throw(signal(fpe,[]))).
% ignore sig_alarm by default % % ignore sig_alarm by default %
'$signal_def'(sig_alarm, true). '$signal_def'(sig_alarm, true).