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,113 +32,114 @@
#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);
set_key_i(errorClass, "errorClass", q, i, t); set_key_i(errorClass, "errorClass", q, i, t);
set_key_s(errorAsText, "errorAsText", q, i, t); set_key_s(errorAsText, "errorAsText", q, i, t);
set_key_s( errorGoal, "errorGoal", q, i, t); set_key_s(errorGoal, "errorGoal", q, i, t);
set_key_s( classAsText, "classAsText", q, i, t); set_key_s(classAsText, "classAsText", q, i, t);
set_key_i( errorLine, "errorLine", q, i , t); set_key_i(errorLine, "errorLine", q, i, t);
set_key_s( errorFunction, "errorFunction", q, i, t); set_key_s(errorFunction, "errorFunction", q, i, t);
set_key_s( errorFile, "errorFile", q, i, t); set_key_s(errorFile, "errorFile", q, i, t);
set_key_i( prologPredLine, "prologPredLine", q, i, t); set_key_i(prologPredLine, "prologPredLine", q, i, t);
set_key_i( prologPredFirstLine, "prologPredFirstLine", q, i, t); set_key_i(prologPredFirstLine, "prologPredFirstLine", q, i, t);
set_key_i( prologPredLastLine, "prologPredLastLine", q, i, t); set_key_i(prologPredLastLine, "prologPredLastLine", q, i, t);
set_key_s( prologPredName, "prologPredName", q, i, t); set_key_s(prologPredName, "prologPredName", q, i, t);
set_key_i( prologPredArity, "prologPredArity", q, i, t); set_key_i(prologPredArity, "prologPredArity", q, i, t);
set_key_s( prologPredModule, "prologPredModule", q, i, t); set_key_s(prologPredModule, "prologPredModule", q, i, t);
set_key_s( prologPredFile, "prologPredFile", q, i, t); set_key_s(prologPredFile, "prologPredFile", q, i, t);
set_key_i( prologParserPos, "prologParserPos", q, i, t); set_key_i(prologParserPos, "prologParserPos", q, i, t);
set_key_i( prologParserLine, "prologParserLine", q, i, t); set_key_i(prologParserLine, "prologParserLine", q, i, t);
set_key_i( prologParserFirstLine, "prologParserFirstLine", q, i, t); set_key_i(prologParserFirstLine, "prologParserFirstLine", q, i, t);
set_key_i( prologParserLastLine, "prologParserLastLine", q, i, t); set_key_i(prologParserLastLine, "prologParserLastLine", q, i, t);
set_key_s( prologParserText, "prologParserText", q, i, t); set_key_s(prologParserText, "prologParserText", q, i, t);
set_key_s( prologParserFile, "prologParserFile", q, i, t); set_key_s(prologParserFile, "prologParserFile", q, i, t);
set_key_b( prologConsulting, "prologConsulting", q, i, t); set_key_b(prologConsulting, "prologConsulting", q, i, t);
set_key_s( culprit, "culprit", q, i, t); set_key_s(culprit, "culprit", q, i, t);
set_key_s( errorMsg, "errorMsg", q, i, t); set_key_s(errorMsg, "errorMsg", q, i, t);
set_key_i( errorMsgLen, "errorMsgLen", q, i, t); set_key_i(errorMsgLen, "errorMsgLen", q, i, t);
return false; return false;
} }
#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);
query_key_i(errorClass, "errorClass", q, i); query_key_i(errorClass, "errorClass", q, i);
query_key_s(errorAsText, "errorAsText", q, i); query_key_s(errorAsText, "errorAsText", q, i);
query_key_s( errorGoal, "errorGoal", q, i); query_key_s(errorGoal, "errorGoal", q, i);
query_key_s( classAsText, "classAsText", q, i); query_key_s(classAsText, "classAsText", q, i);
query_key_i( errorLine, "errorLine", q, i ); query_key_i(errorLine, "errorLine", q, i);
query_key_s( errorFunction, "errorFunction", q, i); query_key_s(errorFunction, "errorFunction", q, i);
query_key_s( errorFile, "errorFile", q, i); query_key_s(errorFile, "errorFile", q, i);
query_key_i( prologPredLine, "prologPredLine", q, i); query_key_i(prologPredLine, "prologPredLine", q, i);
query_key_i( prologPredFirstLine, "prologPredFirstLine", q, i); query_key_i(prologPredFirstLine, "prologPredFirstLine", q, i);
query_key_i( prologPredLastLine, "prologPredLastLine", q, i); query_key_i(prologPredLastLine, "prologPredLastLine", q, i);
query_key_s( prologPredName, "prologPredName", q, i); query_key_s(prologPredName, "prologPredName", q, i);
query_key_i( prologPredArity, "prologPredArity", q, i); query_key_i(prologPredArity, "prologPredArity", q, i);
query_key_s( prologPredModule, "prologPredModule", q, i); query_key_s(prologPredModule, "prologPredModule", q, i);
query_key_s( prologPredFile, "prologPredFile", q, i); query_key_s(prologPredFile, "prologPredFile", q, i);
query_key_i( prologParserPos, "prologParserPos", q, i); query_key_i(prologParserPos, "prologParserPos", q, i);
query_key_i( prologParserLine, "prologParserLine", q, i); query_key_i(prologParserLine, "prologParserLine", q, i);
query_key_i( prologParserFirstLine, "prologParserFirstLine", q, i); query_key_i(prologParserFirstLine, "prologParserFirstLine", q, i);
query_key_i( prologParserLastLine, "prologParserLastLine", q, i); query_key_i(prologParserLastLine, "prologParserLastLine", q, i);
query_key_s( prologParserText, "prologParserText", q, i); query_key_s(prologParserText, "prologParserText", q, i);
query_key_s( prologParserFile, "prologParserFile", q, i); query_key_s(prologParserFile, "prologParserFile", q, i);
query_key_b( prologConsulting, "prologConsulting", q, i); query_key_b(prologConsulting, "prologConsulting", q, i);
query_key_s( culprit, "culprit", q, i); query_key_s(culprit, "culprit", q, i);
query_key_s( errorMsg, "errorMsg", q, i); query_key_s(errorMsg, "errorMsg", q, i);
query_key_i( errorMsgLen, "errorMsgLen", q, i); query_key_i(errorMsgLen, "errorMsgLen", q, 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) {
fprintf(stderr, "%s: %s\n", key, v);
static void print_key_s(const char *key, const char *v)
{
fprintf(stderr,"%s: %s\n", key, v);
} }
static void printErr(yap_error_descriptor_t *i) { static void printErr(yap_error_descriptor_t *i) {
@ -146,62 +147,56 @@ static void printErr(yap_error_descriptor_t *i) {
if (i->errorNo == YAP_NO_ERROR) { if (i->errorNo == YAP_NO_ERROR) {
return; return;
} }
print_key_i( "errorNo", i->errorNo ); print_key_i("errorNo", i->errorNo);
print_key_i("errorClass", i->errorClass); print_key_i("errorClass", i->errorClass);
print_key_s("errorAsText", i->errorAsText); print_key_s("errorAsText", i->errorAsText);
print_key_s( "errorGoal", i->errorGoal); print_key_s("errorGoal", i->errorGoal);
print_key_s( "classAsText", i->classAsText); print_key_s("classAsText", i->classAsText);
print_key_i( "errorLineq", i->errorLine ); print_key_i("errorLineq", i->errorLine);
print_key_s( "errorFunction", i->errorFunction); print_key_s("errorFunction", i->errorFunction);
print_key_s( "errorFile", i->errorFile); print_key_s("errorFile", i->errorFile);
print_key_i( "prologPredLine", i->prologPredLine); print_key_i("prologPredLine", i->prologPredLine);
print_key_i( "prologPredFirstLine", i->prologPredFirstLine); print_key_i("prologPredFirstLine", i->prologPredFirstLine);
print_key_i( "prologPredLastLine", i->prologPredLastLine); print_key_i("prologPredLastLine", i->prologPredLastLine);
print_key_s( "prologPredName", i->prologPredName); print_key_s("prologPredName", i->prologPredName);
print_key_i( "prologPredArity", i->prologPredArity); print_key_i("prologPredArity", i->prologPredArity);
print_key_s( "prologPredModule", i->prologPredModule); print_key_s("prologPredModule", i->prologPredModule);
print_key_s( "prologPredFile", i->prologPredFile); print_key_s("prologPredFile", i->prologPredFile);
print_key_i( "prologParserPos", i->prologParserPos); print_key_i("prologParserPos", i->prologParserPos);
print_key_i( "prologParserLine", i->prologParserLine); print_key_i("prologParserLine", i->prologParserLine);
print_key_i( "prologParserFirstLine", i->prologParserFirstLine); print_key_i("prologParserFirstLine", i->prologParserFirstLine);
print_key_i( "prologParserLastLine", i->prologParserLastLine); print_key_i("prologParserLastLine", i->prologParserLastLine);
print_key_s( "prologParserText", i->prologParserText); print_key_s("prologParserText", i->prologParserText);
print_key_s( "prologParserFile", i->prologParserFile); print_key_s("prologParserFile", i->prologParserFile);
print_key_b( "prologConsulting", i->prologConsulting); print_key_b("prologConsulting", i->prologConsulting);
print_key_s( "culprit", i->culprit); print_key_s("culprit", i->culprit);
if (i->errorMsgLen) { if (i->errorMsgLen) {
print_key_s( "errorMsg", i->errorMsg); print_key_s("errorMsg", i->errorMsg);
print_key_i( "errorMsgLen", i->errorMsgLen); print_key_i("errorMsgLen", i->errorMsgLen);
} }
} }
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);
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_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;
tkv[1] = MkStringTerm(v), tkv[0] = MkStringTerm(key); tkv[1] = MkStringTerm(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);
} }
@ -210,38 +205,36 @@ static Term err2list(yap_error_descriptor_t *i) {
if (i->errorNo == YAP_NO_ERROR) { if (i->errorNo == YAP_NO_ERROR) {
return o; return o;
} }
o = add_key_i( "errorNo", i->errorNo, o ); o = add_key_i("errorNo", i->errorNo, o);
o = add_key_i("errorClass", i->errorClass, o); o = add_key_i("errorClass", i->errorClass, o);
o = add_key_s("errorAsText", i->errorAsText, o); o = add_key_s("errorAsText", i->errorAsText, o);
o = add_key_s( "errorGoal", i->errorGoal, o); o = add_key_s("errorGoal", i->errorGoal, o);
o = add_key_s( "classAsText", i->classAsText, o); o = add_key_s("classAsText", i->classAsText, o);
o = add_key_i( "errorLineq", i->errorLine, o ); o = add_key_i("errorLineq", i->errorLine, o);
o = add_key_s( "errorFunction", i->errorFunction, o); o = add_key_s("errorFunction", i->errorFunction, o);
o = add_key_s( "errorFile", i->errorFile, o); o = add_key_s("errorFile", i->errorFile, o);
o = add_key_i( "prologPredLine", i->prologPredLine, o); o = add_key_i("prologPredLine", i->prologPredLine, o);
o = add_key_i( "prologPredFirstLine", i->prologPredFirstLine, o); o = add_key_i("prologPredFirstLine", i->prologPredFirstLine, o);
o = add_key_i( "prologPredLastLine", i->prologPredLastLine, o); o = add_key_i("prologPredLastLine", i->prologPredLastLine, o);
o = add_key_s( "prologPredName", i->prologPredName, o); o = add_key_s("prologPredName", i->prologPredName, o);
o = add_key_i( "prologPredArity", i->prologPredArity, o); o = add_key_i("prologPredArity", i->prologPredArity, o);
o = add_key_s( "prologPredModule", i->prologPredModule, o); o = add_key_s("prologPredModule", i->prologPredModule, o);
o = add_key_s( "prologPredFile", i->prologPredFile, o); o = add_key_s("prologPredFile", i->prologPredFile, o);
o = add_key_i( "prologParserPos", i->prologParserPos, o); o = add_key_i("prologParserPos", i->prologParserPos, o);
o = add_key_i( "prologParserLine", i->prologParserLine, o); o = add_key_i("prologParserLine", i->prologParserLine, o);
o = add_key_i( "prologParserFirstLine", i->prologParserFirstLine, o); o = add_key_i("prologParserFirstLine", i->prologParserFirstLine, o);
o = add_key_i( "prologParserLastLine", i->prologParserLastLine, o); o = add_key_i("prologParserLastLine", i->prologParserLastLine, o);
o = add_key_s( "prologParserText", i->prologParserText, o); o = add_key_s("prologParserText", i->prologParserText, o);
o = add_key_s( "prologParserFile", i->prologParserFile, o); o = add_key_s("prologParserFile", i->prologParserFile, o);
o = add_key_b( "prologConsulting", i->prologConsulting, o); o = add_key_b("prologConsulting", i->prologConsulting, o);
o = add_key_s( "culprit", i->culprit, o); o = add_key_s("culprit", i->culprit, o);
if (i->errorMsgLen) { if (i->errorMsgLen) {
o = add_key_s( "errorMsg", i->errorMsg, o); o = add_key_s("errorMsg", i->errorMsg, o);
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,29 +515,30 @@ 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)); \
nt[2] = MkVarTerm(); \ nt[2] = MkVarTerm(); \
Yap_unify(nt[2], culprit); \ Yap_unify(nt[2], culprit); \
ft[0] = Yap_MkApplTerm(Yap_MkFunctor(mkerrorct(B),3), 3, nt); \ ft[0] = Yap_MkApplTerm(Yap_MkFunctor(mkerrorct(B), 3), 3, nt); \
ft[1] = info; \ ft[1] = info; \
return Yap_MkApplTerm(FunctorError,2,ft); \ return Yap_MkApplTerm(FunctorError, 2, ft); \
} }
#define END_ERRORS() \ #define END_ERRORS() \
@ -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,7 +645,9 @@ 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) {
@ -656,7 +655,13 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function, int linen
CalculateStackGap(PASS_REGS1); CalculateStackGap(PASS_REGS1);
return P; return P;
} }
LOCAL_ActiveError->errorNo = type; 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->errorAsText = Yap_errorName(type); LOCAL_ActiveError->errorAsText = Yap_errorName(type);
LOCAL_ActiveError->errorClass = Yap_errorClass(type); LOCAL_ActiveError->errorClass = Yap_errorClass(type);
LOCAL_ActiveError->classAsText = LOCAL_ActiveError->classAsText =
@ -674,28 +679,21 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function, int linen
#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,
(unsigned long int)LOCAL_Signals, LOCAL_PrologMode, fmt); (unsigned long int)LOCAL_Signals, LOCAL_PrologMode, fmt);
else else
fprintf(stderr, "***** Processing Error %d (%x) %s***\n", type, fprintf(stderr, "***** Processing Error %d (%x) %s***\n", type,
LOCAL_PrologMode, fmt); LOCAL_PrologMode, fmt);
#endif #endif
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) {
#if HAVE_VSNPRINTF #if HAVE_VSNPRINTF
(void) vsnprintf(s, MAXPATHLEN - 1, fmt, ap); (void)vsnprintf(s, MAXPATHLEN - 1, fmt, ap);
#else #else
(void)vsprintf(s, fmt, ap); (void)vsprintf(s, fmt, ap);
#endif #endif
@ -717,7 +715,7 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function, int linen
if (where == 0 || where == TermNil) { if (where == 0 || where == TermNil) {
LOCAL_ActiveError->culprit = 0; LOCAL_ActiveError->culprit = 0;
} }
if (P == (yamop *) (FAILCODE)) { if (P == (yamop *)(FAILCODE)) {
LOCAL_PrologMode &= ~InErrorMode; LOCAL_PrologMode &= ~InErrorMode;
return P; return P;
} }
@ -740,8 +738,8 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function, int linen
if (LOCAL_PrologMode & BootMode) { if (LOCAL_PrologMode & BootMode) {
/* crash in flames! */ /* crash in flames! */
fprintf(stderr, fprintf(stderr,
"%s:%d:0 YAP Fatal Error %d in function %s:\n %s exiting....\n", "%s:%d:0 YAP Fatal Error %d in function %s:\n %s exiting....\n",
file, lineno, type, function, s); file, lineno, type, function, s);
error_exit_yap(1); error_exit_yap(1);
} }
#ifdef DEBUG #ifdef DEBUG
@ -757,7 +755,7 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function, int linen
} 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];
@ -766,7 +764,7 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function, int linen
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
@ -837,7 +835,7 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function, int linen
return P; return P;
} }
LOCAL_CommittedError = Yap_GetException(); LOCAL_CommittedError = Yap_GetException();
//reset_error_description(); // reset_error_description();
if (!throw) { if (!throw) {
Yap_JumpToEnv(); Yap_JumpToEnv();
} }
@ -918,19 +916,18 @@ const char *Yap_errorClassName(yap_error_class_number e) {
return c_error_class_name[e]; return c_error_class_name[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,
memcpy(nt,t,sizeof(yap_error_descriptor_t)); *nt = malloc(sizeof(yap_error_descriptor_t));
return t; memcpy(nt, t, sizeof(yap_error_descriptor_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)
@ -940,7 +937,7 @@ bool Yap_RaiseException(void) {
bool Yap_ResetException(yap_error_descriptor_t *i) { bool Yap_ResetException(yap_error_descriptor_t *i) {
// reset error descriptor // reset error descriptor
if(!i) if (!i)
return true; return true;
yap_error_descriptor_t *bf = i->top_error; yap_error_descriptor_t *bf = i->top_error;
memset(i, 0, sizeof(*i)); memset(i, 0, sizeof(*i));
@ -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,50 +1002,104 @@ 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;
} }
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;
int j; if (IsApplTerm(t1)) {
for (j=0; j < sizeof(c_error_list)/sizeof(struct c_error_info); j++) { Functor f1 = FunctorOfTerm(t1);
if (!strcmp(c_error_list[j].name,LOCAL_ActiveError->errorAsText) && arity_t a1 = ArityOfFunctor(f1);
(c_error_list[j].class == 0 || LOCAL_ActiveError->culprit =
!strcmp(LOCAL_ActiveError->classAsText,c_error_class_name[c_error_list[j].class]))) Yap_TermToBuffer(ArgOfTerm(a1, t1), ENC_ISO_UTF8, Quote_illegal_f | Ignore_ops_f | Unfold_cyclics_f);
{ if (a1 == 1) {
LOCAL_ActiveError->errorNo = j; return NULL;
LOCAL_ActiveError->errorClass = c_error_list[j].class; } else {
Term ti;
break; 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;
for (j = 0; j < sizeof(c_error_list) / sizeof(struct c_error_info); j++) {
if (!strcmp(c_error_list[j].name, LOCAL_ActiveError->errorAsText) &&
(c_error_list[j].class == 0 ||
!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->errorClass = c_error_list[j].class;
break;
}
}
}
} else if (IsAtomTerm(t1)) {
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;
} }
} }
Yap_prolog_add_culprit(LOCAL_ActiveError PASS_REGS1); while (IsPairTerm(t2)) {
return Term hd = HeadOfTerm(t2);
LOCAL_ActiveError; 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) {
@ -1084,21 +1133,21 @@ static Int is_callable(USES_REGS1) {
if (IsApplTerm(G)) { if (IsApplTerm(G)) {
Functor f = FunctorOfTerm(G); Functor f = FunctorOfTerm(G);
if (IsExtensionFunctor(f)) { if (IsExtensionFunctor(f)) {
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;
} }
if (!IsAtomTerm(tm)) { if (!IsAtomTerm(tm)) {
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;
} }
} else if (IsPairTerm(G) || IsAtomTerm(G)) { } else if (IsPairTerm(G) || IsAtomTerm(G)) {
return true; return true;
@ -1150,5 +1199,5 @@ void Yap_InitErrorPreds(void) {
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, Yap_InitCPred("is_predicate_indicator", 2, is_predicate_indicator,
TestPredFlag); TestPredFlag);
} }

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,',').

396
C/stack.c
View File

@ -67,13 +67,13 @@ static LogUpdIndex *find_owner_log_index(LogUpdIndex *, yamop *);
static StaticIndex *find_owner_static_index(StaticIndex *, yamop *); static StaticIndex *find_owner_static_index(StaticIndex *, yamop *);
#define IN_BLOCK(P, B, SZ) \ #define IN_BLOCK(P, B, SZ) \
((CODEADDR)(P) >= (CODEADDR)(B) && (CODEADDR)(P) < (CODEADDR)(B) + (SZ)) ((CODEADDR)(P) >= (CODEADDR)(B) && (CODEADDR)(P) < (CODEADDR)(B) + (SZ))
static PredEntry *get_pred(Term t, Term tmod, char *pname) { static PredEntry *get_pred(Term t, Term tmod, char *pname) {
Term t0 = t; Term t0 = t;
restart: restart:
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, t0, pname); Yap_Error(INSTANTIATION_ERROR, t0, pname);
return NULL; return NULL;
@ -209,7 +209,7 @@ static PredEntry *PredForChoicePt(yamop *p_code, op_numbers *opn) {
* *
* usually pretty straightforward, it can fall in trouble with * usually pretty straightforward, it can fall in trouble with
8 OR-P or tabling. 8 OR-P or tabling.
*/ */
PredEntry *Yap_PredForChoicePt(choiceptr cp, op_numbers *op) { PredEntry *Yap_PredForChoicePt(choiceptr cp, op_numbers *op) {
if (cp == NULL) if (cp == NULL)
return NULL; return NULL;
@ -268,8 +268,8 @@ bool Yap_search_for_static_predicate_in_use(PredEntry *p,
/* check first environments that are younger than our latest choicepoint */ /* check first environments that are younger than our latest choicepoint */
if (check_everything && env_ptr) { if (check_everything && env_ptr) {
/* /*
I do not need to check environments for asserts, I do not need to check environments for asserts,
only for retracts only for retracts
*/ */
while (env_ptr && b_ptr > (choiceptr)env_ptr) { while (env_ptr && b_ptr > (choiceptr)env_ptr) {
yamop *cp = (yamop *)env_ptr[E_CP]; yamop *cp = (yamop *)env_ptr[E_CP];
@ -538,69 +538,69 @@ static Int find_code_in_clause(PredEntry *pp, yamop *codeptr, void **startp,
} }
/* /*
static bool put_clause_loc(yap_error_descriptor_t *t, void *clcode, PredEntry *pp) { static bool put_clause_loc(yap_error_descriptor_t *t, void *clcode, PredEntry *pp) {
CACHE_REGS CACHE_REGS
if (pp->PredFlags & LogUpdatePredFlag) { if (pp->PredFlags & LogUpdatePredFlag) {
LogUpdClause *cl = clcode; LogUpdClause *cl = clcode;
if (cl->ClFlags & FactMask) { if (cl->ClFlags & FactMask) {
t->prologPredLine = cl->lusl.ClLine; t->prologPredLine = cl->lusl.ClLine;
} else {
t->prologPredLine = cl->lusl.ClSource->ag.line_number;
}
} else if (pp->PredFlags & DynamicPredFlag) {
// DynamicClause *cl;
// cl = ClauseCodeToDynamicClause(clcode);
return false;
} else if (pp->PredFlags & MegaClausePredFlag) {
MegaClause *mcl = ClauseCodeToMegaClause(pp->cs.p_code.FirstClause);
t->prologPredLine = mcl->ClLine;
} else { } else {
StaticClause *cl; t->prologPredLine = cl->lusl.ClSource->ag.line_number;
cl = clcode; }
if (cl->ClFlags & FactMask) { } else if (pp->PredFlags & DynamicPredFlag) {
t->prologPredLine = cl->usc.ClLine; // DynamicClause *cl;
} else if (cl->ClFlags & SrcMask) { // cl = ClauseCodeToDynamicClause(clcode);
t->prologPredLine = cl->usc.ClSource->ag.line_number;
} else return false;
return MkIntTerm(0); } else if (pp->PredFlags & MegaClausePredFlag) {
MegaClause *mcl = ClauseCodeToMegaClause(pp->cs.p_code.FirstClause);
t->prologPredLine = mcl->ClLine;
} else {
StaticClause *cl;
cl = clcode;
if (cl->ClFlags & FactMask) {
t->prologPredLine = cl->usc.ClLine;
} else if (cl->ClFlags & SrcMask) {
t->prologPredLine = cl->usc.ClSource->ag.line_number;
} else
return MkIntTerm(0);
} }
return MkIntTerm(0); return MkIntTerm(0);
} }
*/ */
static Term clause_loc(void *clcode, PredEntry *pp) { static Term clause_loc(void *clcode, PredEntry *pp) {
CACHE_REGS CACHE_REGS
if (pp->PredFlags & LogUpdatePredFlag) { if (pp->PredFlags & LogUpdatePredFlag) {
LogUpdClause *cl = clcode; LogUpdClause *cl = clcode;
if (cl->ClFlags & FactMask) { if (cl->ClFlags & FactMask) {
return MkIntegerTerm(cl->lusl.ClLine); return MkIntegerTerm(cl->lusl.ClLine);
} else { } else {
return MkIntegerTerm(cl->lusl.ClSource->ag.line_number); return MkIntegerTerm(cl->lusl.ClSource->ag.line_number);
} }
} else if (pp->PredFlags & DynamicPredFlag) { } else if (pp->PredFlags & DynamicPredFlag) {
// DynamicClause *cl; // DynamicClause *cl;
// cl = ClauseCodeToDynamicClause(clcode); // cl = ClauseCodeToDynamicClause(clcode);
return MkIntTerm(0);
} else if (pp->PredFlags & MegaClausePredFlag) {
MegaClause *mcl = ClauseCodeToMegaClause(pp->cs.p_code.FirstClause);
return MkIntTerm(mcl->ClLine);
} else {
StaticClause *cl;
cl = clcode;
if (cl->ClFlags & FactMask) {
return MkIntTerm(cl->usc.ClLine);
} else if (cl->ClFlags & SrcMask) {
return MkIntTerm(cl->usc.ClSource->ag.line_number);
} else
return MkIntTerm(0); return MkIntTerm(0);
} } else if (pp->PredFlags & MegaClausePredFlag) {
MegaClause *mcl = ClauseCodeToMegaClause(pp->cs.p_code.FirstClause);
return MkIntTerm(mcl->ClLine);
} else {
StaticClause *cl;
cl = clcode;
if (cl->ClFlags & FactMask) {
return MkIntTerm(cl->usc.ClLine);
} else if (cl->ClFlags & SrcMask) {
return MkIntTerm(cl->usc.ClSource->ag.line_number);
} else
return MkIntTerm(0);
}
return MkIntTerm(0); return MkIntTerm(0);
} }
@ -613,15 +613,15 @@ static int cl_code_in_pred(PredEntry *pp, yamop *codeptr, void **startp,
if (pp->PredFlags & IndexedPredFlag) { if (pp->PredFlags & IndexedPredFlag) {
if (pp->PredFlags & LogUpdatePredFlag) { if (pp->PredFlags & LogUpdatePredFlag) {
if (code_in_pred_lu_index( if (code_in_pred_lu_index(
ClauseCodeToLogUpdIndex(pp->cs.p_code.TrueCodeOfPred), codeptr, ClauseCodeToLogUpdIndex(pp->cs.p_code.TrueCodeOfPred), codeptr,
startp, endp)) { startp, endp)) {
UNLOCK(pp->PELock); UNLOCK(pp->PELock);
return TRUE; return TRUE;
} }
} else { } else {
if (code_in_pred_s_index( if (code_in_pred_s_index(
ClauseCodeToStaticIndex(pp->cs.p_code.TrueCodeOfPred), codeptr, ClauseCodeToStaticIndex(pp->cs.p_code.TrueCodeOfPred), codeptr,
startp, endp)) { startp, endp)) {
UNLOCK(pp->PELock); UNLOCK(pp->PELock);
return TRUE; return TRUE;
} }
@ -658,16 +658,16 @@ static Int code_in_pred(PredEntry *pp, Atom *pat, UInt *parity,
if (pp->PredFlags & IndexedPredFlag) { if (pp->PredFlags & IndexedPredFlag) {
if (pp->PredFlags & LogUpdatePredFlag) { if (pp->PredFlags & LogUpdatePredFlag) {
if (code_in_pred_lu_index( if (code_in_pred_lu_index(
ClauseCodeToLogUpdIndex(pp->cs.p_code.TrueCodeOfPred), codeptr, ClauseCodeToLogUpdIndex(pp->cs.p_code.TrueCodeOfPred), codeptr,
NULL, NULL)) { NULL, NULL)) {
code_in_pred_info(pp, pat, parity); code_in_pred_info(pp, pat, parity);
UNLOCK(pp->PELock); UNLOCK(pp->PELock);
return -1; return -1;
} }
} else { } else {
if (code_in_pred_s_index( if (code_in_pred_s_index(
ClauseCodeToStaticIndex(pp->cs.p_code.TrueCodeOfPred), codeptr, ClauseCodeToStaticIndex(pp->cs.p_code.TrueCodeOfPred), codeptr,
NULL, NULL)) { NULL, NULL)) {
code_in_pred_info(pp, pat, parity); code_in_pred_info(pp, pat, parity);
UNLOCK(pp->PELock); UNLOCK(pp->PELock);
return -1; return -1;
@ -820,8 +820,8 @@ static PredEntry *found_owner_op(yamop *pc, void **startp,
static PredEntry *found_expand(yamop *pc, void **startp, static PredEntry *found_expand(yamop *pc, void **startp,
void **endp USES_REGS) { void **endp USES_REGS) {
PredEntry *pp = PredEntry *pp =
((PredEntry *)(Unsigned(pc) - ((PredEntry *)(Unsigned(pc) -
(CELL)(&(((PredEntry *)NULL)->cs.p_code.ExpandCode)))); (CELL)(&(((PredEntry *)NULL)->cs.p_code.ExpandCode))));
*startp = (CODEADDR) & (pp->cs.p_code.ExpandCode); *startp = (CODEADDR) & (pp->cs.p_code.ExpandCode);
*endp = (CODEADDR)NEXTOP((yamop *)&(pp->cs.p_code.ExpandCode), e); *endp = (CODEADDR)NEXTOP((yamop *)&(pp->cs.p_code.ExpandCode), e);
return pp; return pp;
@ -897,19 +897,19 @@ static PredEntry *ClauseInfoForCode(yamop *codeptr, void **startp,
PredEntry *Yap_PredEntryForCode(yamop *codeptr, find_pred_type where_from, PredEntry *Yap_PredEntryForCode(yamop *codeptr, find_pred_type where_from,
void **startp, void **endp) { void **startp, void **endp) {
CACHE_REGS CACHE_REGS
if (where_from == FIND_PRED_FROM_CP) { if (where_from == FIND_PRED_FROM_CP) {
PredEntry *pp = PredForChoicePt(codeptr, NULL); PredEntry *pp = PredForChoicePt(codeptr, NULL);
if (cl_code_in_pred(pp, codeptr, startp, endp)) { if (cl_code_in_pred(pp, codeptr, startp, endp)) {
return pp; return pp;
}
} else if (where_from == FIND_PRED_FROM_ENV) {
PredEntry *pp = EnvPreg(codeptr);
if (cl_code_in_pred(pp, codeptr, startp, endp)) {
return pp;
}
} else {
return ClauseInfoForCode(codeptr, startp, endp PASS_REGS);
} }
} else if (where_from == FIND_PRED_FROM_ENV) {
PredEntry *pp = EnvPreg(codeptr);
if (cl_code_in_pred(pp, codeptr, startp, endp)) {
return pp;
}
} else {
return ClauseInfoForCode(codeptr, startp, endp PASS_REGS);
}
return NULL; return NULL;
} }
@ -1096,7 +1096,7 @@ static Int p_all_envs(USES_REGS1) {
static Term clause_info(yamop *codeptr, PredEntry *pp) { static Term clause_info(yamop *codeptr, PredEntry *pp) {
CACHE_REGS CACHE_REGS
Term ts[2]; Term ts[2];
void *begin; void *begin;
if (pp->ArityOfPE == 0) { if (pp->ArityOfPE == 0) {
@ -1122,20 +1122,20 @@ static Term clause_info(yamop *codeptr, PredEntry *pp) {
yap_error_descriptor_t * set_clause_info(yap_error_descriptor_t *t, yamop *codeptr, PredEntry *pp) { yap_error_descriptor_t * set_clause_info(yap_error_descriptor_t *t, yamop *codeptr, PredEntry *pp) {
CACHE_REGS CACHE_REGS
Term ts[2]; Term ts[2];
void *begin; void *begin;
if (pp->ArityOfPE == 0) { if (pp->ArityOfPE == 0) {
t->prologPredName = t->prologPredName =
AtomName((Atom)pp->FunctorOfPred); AtomName((Atom)pp->FunctorOfPred);
t->prologPredArity = 0; t->prologPredArity = 0;
} else { } else {
t->prologPredName = t->prologPredName =
AtomName(NameOfFunctor(pp->FunctorOfPred)); AtomName(NameOfFunctor(pp->FunctorOfPred));
t->prologPredArity = pp->ArityOfPE; t->prologPredArity = pp->ArityOfPE;
} }
t->prologPredModule = t->prologPredModule =
(pp->ModuleOfPred ? RepAtom(AtomOfTerm(pp->ModuleOfPred))->StrOfAE (pp->ModuleOfPred ? RepAtom(AtomOfTerm(pp->ModuleOfPred))->StrOfAE
: "prolog"); : "prolog");
t->prologPredFile = RepAtom(pp->src.OwnerFile)->StrOfAE; t->prologPredFile = RepAtom(pp->src.OwnerFile)->StrOfAE;
if (codeptr->opc == UNDEF_OPCODE) { if (codeptr->opc == UNDEF_OPCODE) {
t->prologPredFirstLine = 0; t->prologPredFirstLine = 0;
@ -1144,28 +1144,32 @@ yap_error_descriptor_t * set_clause_info(yap_error_descriptor_t *t, yamop *cod
return t; return t;
} else if (pp->cs.p_code.NOfClauses) { } else if (pp->cs.p_code.NOfClauses) {
if ((t->prologPredCl = if ((t->prologPredCl =
find_code_in_clause(pp, codeptr, &begin, NULL)) <= 0) { find_code_in_clause(pp, codeptr, &begin, NULL)) <= 0) {
t->prologPredLine = 0; t->prologPredLine = 0;
} else { } else {
t->prologPredLine = IntegerOfTerm(clause_loc(begin, pp)); t->prologPredLine = IntegerOfTerm(clause_loc(begin, pp));
} }
if (pp->PredFlags & LogUpdatePredFlag) { if (pp->PredFlags & LogUpdatePredFlag) {
t->prologPredFirstLine = clause_loc( t->prologPredFirstLine = clause_loc(
ClauseCodeToLogUpdClause(pp->cs.p_code.FirstClause), pp); ClauseCodeToLogUpdClause(pp->cs.p_code.FirstClause), pp);
t->prologPredLastLine = clause_loc(ClauseCodeToLogUpdClause(pp->cs.p_code.LastClause), t->prologPredLastLine = clause_loc(ClauseCodeToLogUpdClause(pp->cs.p_code.LastClause),
pp); pp);
} else { } else {
t->prologPredFirstLine = IntegerOfTerm( t->prologPredFirstLine = IntegerOfTerm(
ts[0] = clause_loc( ts[0] = clause_loc(
ClauseCodeToStaticClause(pp->cs.p_code.FirstClause), pp)); ClauseCodeToStaticClause(pp->cs.p_code.FirstClause), pp));
t->prologPredLastLine = IntegerOfTerm( t->prologPredLastLine = IntegerOfTerm(
ts[1] = clause_loc(ClauseCodeToStaticClause(pp->cs.p_code.LastClause), ts[1] = clause_loc(ClauseCodeToStaticClause(pp->cs.p_code.LastClause),
pp)); pp));
} }
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,23 +1207,33 @@ 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) {
curENV = (CELL *)(curENV[E_E]); if (curENV < (CELL *)curB) {
if (curENV < ASP || curENV >= LCL0) { pe = EnvPreg(curCP);
break; curENV = (CELL *)(curENV[E_E]);
if (curENV < ASP || curENV >= LCL0) {
break;
}
curCP = (yamop *)curENV[E_CP];
if (pe == NULL) {
pe = PredMetaCall;
}
if (pe->ModuleOfPred || !(pe->PredFlags & HiddenPredFlag))
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;
} }
pe = EnvPreg(curCP);
if (pe == NULL) {
pe = PredMetaCall;
}
if (pe->ModuleOfPred)
return set_clause_info(t, curCP, pe);
curCP = (yamop *)(curENV[E_CP]);
} }
curCP = (yamop *)(curENV[E_CP]);
} }
return NULL;
return NULL;
} }
static Term all_calls(bool internal USES_REGS) { static Term all_calls(bool internal USES_REGS) {
@ -1253,7 +1267,7 @@ static Term all_calls(bool internal USES_REGS) {
Term Yap_all_calls(void) { Term Yap_all_calls(void) {
CACHE_REGS CACHE_REGS
return all_calls(true PASS_REGS); return all_calls(true PASS_REGS);
} }
static Int current_stack(USES_REGS1) { static Int current_stack(USES_REGS1) {
@ -1372,23 +1386,23 @@ void Yap_dump_code_area_for_profiler(void) {
while (pp != NULL) { while (pp != NULL) {
/* if (pp->ArityOfPE) { /* if (pp->ArityOfPE) {
fprintf(stderr,"%s/%d %p\n", fprintf(stderr,"%s/%d %p\n",
RepAtom(NameOfFunctor(pp->FunctorOfPred))->StrOfAE, RepAtom(NameOfFunctor(pp->FunctorOfPred))->StrOfAE,
pp->ArityOfPE, pp->ArityOfPE,
pp); pp);
} else { } else {
fprintf(stderr,"%s %p\n", fprintf(stderr,"%s %p\n",
RepAtom((Atom)(pp->FunctorOfPred))->StrOfAE, RepAtom((Atom)(pp->FunctorOfPred))->StrOfAE,
pp); pp);
}*/ }*/
add_code_in_pred(pp); add_code_in_pred(pp);
pp = pp->NextPredOfModule; pp = pp->NextPredOfModule;
} }
me = me->NextME; me = me->NextME;
} }
Yap_inform_profiler_of_clause( Yap_inform_profiler_of_clause(
COMMA_CODE, FAILCODE, RepPredProp(Yap_GetPredPropByFunc(FunctorComma, 0)), COMMA_CODE, FAILCODE, RepPredProp(Yap_GetPredPropByFunc(FunctorComma, 0)),
GPROF_INIT_COMMA); GPROF_INIT_COMMA);
Yap_inform_profiler_of_clause(FAILCODE, FAILCODE + 1, Yap_inform_profiler_of_clause(FAILCODE, FAILCODE + 1,
RepPredProp(Yap_GetPredPropByAtom(AtomFail, 0)), RepPredProp(Yap_GetPredPropByAtom(AtomFail, 0)),
GPROF_INIT_FAIL); GPROF_INIT_FAIL);
@ -1421,7 +1435,7 @@ static Int program_continuation(USES_REGS1) {
static Term BuildActivePred(PredEntry *ap, CELL *vect) { static Term BuildActivePred(PredEntry *ap, CELL *vect) {
CACHE_REGS CACHE_REGS
arity_t i; arity_t i;
if (!ap->ArityOfPE) { if (!ap->ArityOfPE) {
return MkAtomTerm((Atom)ap->FunctorOfPred); return MkAtomTerm((Atom)ap->FunctorOfPred);
@ -1469,8 +1483,8 @@ static int UnifyPredInfo(PredEntry *pe, int start_arg USES_REGS) {
} }
return Yap_unify(XREGS[start_arg], tmod) && return Yap_unify(XREGS[start_arg], tmod) &&
Yap_unify(XREGS[start_arg + 1], tname) && Yap_unify(XREGS[start_arg + 1], tname) &&
Yap_unify(XREGS[start_arg + 2], MkIntegerTerm(arity)); Yap_unify(XREGS[start_arg + 2], MkIntegerTerm(arity));
} }
static Int ClauseId(yamop *ipc, PredEntry *pe) { static Int ClauseId(yamop *ipc, PredEntry *pe) {
@ -1492,7 +1506,7 @@ static Int env_info(USES_REGS1) {
/* pe = PREVOP(env_cp,Osbpp)->y_u.Osbpp.p0; */ /* pe = PREVOP(env_cp,Osbpp)->y_u.Osbpp.p0; */
taddr = MkIntegerTerm((Int)env); taddr = MkIntegerTerm((Int)env);
return Yap_unify(ARG3, MkIntegerTerm((Int)env_cp)) && return Yap_unify(ARG3, MkIntegerTerm((Int)env_cp)) &&
Yap_unify(ARG2, taddr) && Yap_unify(ARG4, env_b); Yap_unify(ARG2, taddr) && Yap_unify(ARG4, env_b);
} }
static Int p_cpc_info(USES_REGS1) { static Int p_cpc_info(USES_REGS1) {
@ -1501,7 +1515,7 @@ static Int p_cpc_info(USES_REGS1) {
pe = PREVOP(ipc, Osbpp)->y_u.Osbpp.p0; pe = PREVOP(ipc, Osbpp)->y_u.Osbpp.p0;
return UnifyPredInfo(pe, 2 PASS_REGS) && return UnifyPredInfo(pe, 2 PASS_REGS) &&
Yap_unify(ARG5, MkIntegerTerm(ClauseId(ipc, pe))); Yap_unify(ARG5, MkIntegerTerm(ClauseId(ipc, pe)));
} }
static Int p_choicepoint_info(USES_REGS1) { static Int p_choicepoint_info(USES_REGS1) {
@ -1542,10 +1556,10 @@ static Int p_choicepoint_info(USES_REGS1) {
t = MkVarTerm(); t = MkVarTerm();
} else } else
#endif /* DETERMINISTIC_TABLING */ #endif /* DETERMINISTIC_TABLING */
{ {
pe = GEN_CP(cptr)->cp_pred_entry; pe = GEN_CP(cptr)->cp_pred_entry;
t = BuildActivePred(pe, (CELL *)(GEN_CP(B) + 1)); t = BuildActivePred(pe, (CELL *)(GEN_CP(B) + 1));
} }
#else #else
pe = UndefCode; pe = UndefCode;
t = MkVarTerm(); t = MkVarTerm();
@ -1681,8 +1695,8 @@ static Int p_choicepoint_info(USES_REGS1) {
} }
} }
return UnifyPredInfo(pe, 3 PASS_REGS) && Yap_unify(ARG2, taddr) && return UnifyPredInfo(pe, 3 PASS_REGS) && Yap_unify(ARG2, taddr) &&
Yap_unify(ARG6, t) && Yap_unify(ARG6, t) &&
Yap_unify(ARG7, MkIntegerTerm(ClauseId(ncl, pe))); Yap_unify(ARG7, MkIntegerTerm(ClauseId(ncl, pe)));
} }
static Int /* $parent_pred(Module, Name, Arity) */ static Int /* $parent_pred(Module, Name, Arity) */
@ -1694,11 +1708,11 @@ parent_pred(USES_REGS1) {
Term module; Term module;
if (!PredForCode(P_before_spy, &at, &arity, &module, NULL)) { if (!PredForCode(P_before_spy, &at, &arity, &module, NULL)) {
return Yap_unify(ARG1, MkIntTerm(0)) && return Yap_unify(ARG1, MkIntTerm(0)) &&
Yap_unify(ARG2, MkAtomTerm(AtomMetaCall)) && Yap_unify(ARG2, MkAtomTerm(AtomMetaCall)) &&
Yap_unify(ARG3, MkIntTerm(0)); Yap_unify(ARG3, MkIntTerm(0));
} }
return Yap_unify(ARG1, MkIntTerm(module)) && return Yap_unify(ARG1, MkIntTerm(module)) &&
Yap_unify(ARG2, MkAtomTerm(at)) && Yap_unify(ARG3, MkIntTerm(arity)); Yap_unify(ARG2, MkAtomTerm(at)) && Yap_unify(ARG3, MkIntTerm(arity));
} }
void Yap_dump_stack(void); void Yap_dump_stack(void);
@ -1709,7 +1723,7 @@ static int hidden(Atom);
static int legal_env(CELL *CACHE_TYPE); static int legal_env(CELL *CACHE_TYPE);
#define ONLOCAL(ptr) \ #define ONLOCAL(ptr) \
(CellPtr(ptr) > CellPtr(HR) && CellPtr(ptr) < CellPtr(LOCAL_LocalBase)) (CellPtr(ptr) > CellPtr(HR) && CellPtr(ptr) < CellPtr(LOCAL_LocalBase))
static int hidden(Atom at) { static int hidden(Atom at) {
@ -1768,7 +1782,7 @@ static bool handled_exception(USES_REGS1) {
void Yap_dump_stack(void) { void Yap_dump_stack(void) {
CACHE_REGS CACHE_REGS
choiceptr b_ptr = B; choiceptr b_ptr = B;
CELL *env_ptr = ENV; CELL *env_ptr = ENV;
char tp[256]; char tp[256];
yamop *ipc = CP; yamop *ipc = CP;
@ -1834,7 +1848,7 @@ void Yap_dump_stack(void) {
#endif #endif
fprintf(stderr, "%% All Active Calls and\n"); fprintf(stderr, "%% All Active Calls and\n");
fprintf(stderr, "%% Goals With Alternatives Open (Global In " fprintf(stderr, "%% Goals With Alternatives Open (Global In "
"Use--Local In Use)\n%%\n"); "Use--Local In Use)\n%%\n");
while (b_ptr != NULL) { while (b_ptr != NULL) {
while (env_ptr && env_ptr <= (CELL *)b_ptr) { while (env_ptr && env_ptr <= (CELL *)b_ptr) {
Yap_detect_bug_location(ipc, FIND_PRED_FROM_ENV, 256); Yap_detect_bug_location(ipc, FIND_PRED_FROM_ENV, 256);
@ -2032,10 +2046,10 @@ void Yap_detect_bug_location(yamop *yap_pc, int where_from, int psize) {
static yap_error_descriptor_t *add_bug_location(yap_error_descriptor_t *p, yamop *codeptr, PredEntry *pe) { static yap_error_descriptor_t *add_bug_location(yap_error_descriptor_t *p, yamop *codeptr, PredEntry *pe) {
CACHE_REGS CACHE_REGS
if (pe->ModuleOfPred == PROLOG_MODULE) if (pe->ModuleOfPred == PROLOG_MODULE)
p->prologPredModule = AtomName(AtomProlog); p->prologPredModule = AtomName(AtomProlog);
else else
p->prologPredModule = AtomName(AtomOfTerm(pe->ModuleOfPred)); p->prologPredModule = AtomName(AtomOfTerm(pe->ModuleOfPred));
if (pe->ArityOfPE) if (pe->ArityOfPE)
p->prologPredName = AtomName(NameOfFunctor(pe->FunctorOfPred)); p->prologPredName = AtomName(NameOfFunctor(pe->FunctorOfPred));
else else
@ -2078,7 +2092,7 @@ static yap_error_descriptor_t *add_bug_location(yap_error_descriptor_t *p, yamop
} }
else if (pe->OpcodeOfPred == UNDEF_OPCODE) { else if (pe->OpcodeOfPred == UNDEF_OPCODE) {
p->prologPredFile = "undefined"; p->prologPredFile = "undefined";
} }
else { else {
// by default, user_input // by default, user_input
p->prologPredFile = AtomName( AtomUserIn ); p->prologPredFile = AtomName( AtomUserIn );
@ -2093,7 +2107,7 @@ yap_error_descriptor_t * Yap_pc_add_location(yap_error_descriptor_t *t, void *pc
// choiceptr b_ptr = b_ptr0; // choiceptr b_ptr = b_ptr0;
//CELL *env = env0; //CELL *env = env0;
PredEntry *pe; PredEntry *pe;
if (PP == NULL) { if (PP == NULL) {
if (PredForCode(xc, NULL, NULL, NULL, &pe) <= 0) if (PredForCode(xc, NULL, NULL, NULL, &pe) <= 0)
return NULL; return NULL;
@ -2102,67 +2116,67 @@ yap_error_descriptor_t * Yap_pc_add_location(yap_error_descriptor_t *t, void *pc
if (pe != NULL if (pe != NULL
// pe->ModuleOfPred != PROLOG_MODULE && // pe->ModuleOfPred != PROLOG_MODULE &&
// &&!(pe->PredFlags & HiddenPredFlag) // &&!(pe->PredFlags & HiddenPredFlag)
) { ) {
return add_bug_location(t, xc, pe); return add_bug_location(t, xc, pe);
} }
return NULL; return NULL;
} }
yap_error_descriptor_t *Yap_env_add_location(yap_error_descriptor_t *t,void *cp0, void *b_ptr0, void *env0, YAP_Int ignore_first) { yap_error_descriptor_t *Yap_env_add_location(yap_error_descriptor_t *t,void *cp0, void *b_ptr0, void *env0, YAP_Int ignore_first) {
yamop *cp = cp0; yamop *cp = cp0;
choiceptr b_ptr = b_ptr0; choiceptr b_ptr = b_ptr0;
CELL *env = env0; CELL *env = env0;
while (true) { while (true) {
if (b_ptr == NULL || env == NULL) if (b_ptr == NULL || env == NULL)
return NULL; return NULL;
PredEntry *pe = EnvPreg(cp); PredEntry *pe = EnvPreg(cp);
if (pe == PredTrue) if (pe == PredTrue)
return NULL; return NULL;
if (ignore_first <= 0 && if (ignore_first <= 0 &&
pe pe
// pe->ModuleOfPred != PROLOG_MODULE &&s // pe->ModuleOfPred != PROLOG_MODULE &&s
&& !(pe->PredFlags & HiddenPredFlag)) { && !(pe->PredFlags & HiddenPredFlag)) {
return add_bug_location(t, cp, pe); return add_bug_location(t, cp, pe);
} else { } else {
if (NULL && b_ptr && b_ptr->cp_env < env) { if (NULL && b_ptr && b_ptr->cp_env < env) {
cp = b_ptr->cp_cp; cp = b_ptr->cp_cp;
env = b_ptr->cp_env; env = b_ptr->cp_env;
b_ptr = b_ptr->cp_b; b_ptr = b_ptr->cp_b;
} else { } else {
cp = (yamop *)env[E_CP]; cp = (yamop *)env[E_CP];
env = ENV_Parent(env); env = ENV_Parent(env);
} }
ignore_first--; ignore_first--;
}
}
} }
}
}
/* /*
Term Yap_env_location(yamop *cp, choiceptr b_ptr, CELL *env, Int ignore_first) { Term Yap_env_location(yamop *cp, choiceptr b_ptr, CELL *env, Int ignore_first) {
while (true) { while (true) {
if (b_ptr == NULL || env == NULL) if (b_ptr == NULL || env == NULL)
return TermNil; return TermNil;
PredEntry *pe = EnvPreg(cp); PredEntry *pe = EnvPreg(cp);
if (pe == PredTrue) if (pe == PredTrue)
return TermNil; return TermNil;
if (ignore_first <= 0 && if (ignore_first <= 0 &&
pe pe
// pe->ModuleOfPred != PROLOG_MODULE &&s // pe->ModuleOfPred != PROLOG_MODULE &&s
&& !(pe->PredFlags & HiddenPredFlag)) { && !(pe->PredFlags & HiddenPredFlag)) {
return add_bug_location(cp, pe); return add_bug_location(cp, pe);
} else { } else {
if (NULL && b_ptr && b_ptr->cp_env < env) { if (NULL && b_ptr && b_ptr->cp_env < env) {
cp = b_ptr->cp_cp; cp = b_ptr->cp_cp;
env = b_ptr->cp_env; env = b_ptr->cp_env;
b_ptr = b_ptr->cp_b; b_ptr = b_ptr->cp_b;
} else { } else {
cp = (yamop *)env[E_CP]; cp = (yamop *)env[E_CP];
env = ENV_Parent(env); env = ENV_Parent(env);
} }
ignore_first--; ignore_first--;
} }
} }
} }
*/ */
static Term mkloc(yap_error_descriptor_t *t) static Term mkloc(yap_error_descriptor_t *t)
@ -2180,15 +2194,15 @@ static Int clause_location(USES_REGS1) {
static Int ancestor_location(USES_REGS1) { static Int ancestor_location(USES_REGS1) {
yap_error_descriptor_t t; yap_error_descriptor_t t;
memset( &t, 0, sizeof(yap_error_descriptor_t)); memset( &t, 0, sizeof(yap_error_descriptor_t));
return return
Yap_unify(mkloc(Yap_env_add_location(&t,CP, B, ENV, 2)), ARG2) && Yap_unify(mkloc(Yap_env_add_location(&t,CP, B, ENV, 2)), ARG2) &&
Yap_unify(mkloc(Yap_env_add_location(&t,CP, B, ENV, 3)), ARG2); Yap_unify(mkloc(Yap_env_add_location(&t,CP, B, ENV, 3)), ARG2);
} }
void Yap_InitStInfo(void) { void Yap_InitStInfo(void) {
CACHE_REGS CACHE_REGS
Term cm = CurrentModule; Term cm = CurrentModule;
Yap_InitCPred("in_use", 2, in_use, Yap_InitCPred("in_use", 2, in_use,
HiddenPredFlag | TestPredFlag | SafePredFlag | SyncPredFlag); HiddenPredFlag | TestPredFlag | SafePredFlag | SyncPredFlag);

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,7 +415,8 @@ 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 DollarVar N "$VAR" A UTF8 N "utf8"
A DollarVar N "$VAR"
A VBar N "|" A VBar N "|"
A VarBranches N "var_branches" A VarBranches N "var_branches"
A VariableNames N "variable_names" A VariableNames N "variable_names"
@ -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)) [nl,nl].
}, compose_message(Throw, _Leve) -->
compose_message( e(Err, In), Level),
[nl,nl].
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,15 +324,15 @@ 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)}, !,
[ ' error: uninstantiated message ~w~n.' - [Msg], nl ]. [ ' error: uninstantiated message ~w~n.' - [Msg], nl ].
main_message( error(syntax_error(Msg),info(between(L0,LM,LF),_Stream, _Pos, Term)), Level, LC ) --> main_message( error(syntax_error(Msg),info(between(L0,LM,LF),_Stream, _Pos, Term)), Level, LC ) -->
!, !,
[' ~a: syntax error ~s' - [Level,Msg]], [' ~a: syntax error ~s' - [Level,Msg]],
[nl], [nl],
( syntax_error_term( between(L0,LM,LF), Term, LC ) ( syntax_error_term( between(L0,LM,LF), Term, LC )
-> ->
[] []
@ -747,7 +747,7 @@ syntax_error_token(number(N), _, _LC) --> !,
syntax_error_token(var(_,S), _, _LC) --> !, syntax_error_token(var(_,S), _, _LC) --> !,
[ '~a' - [S] ]. [ '~a' - [S] ].
syntax_error_token(string(S), _, _LC) --> !, syntax_error_token(string(S), _, _LC) --> !,
[ '`~s`' - [S] ]. [ '`~s`' - [S] ].
syntax_error_token(error, L, _LC) --> !, syntax_error_token(error, L, _LC) --> !,
[ ' <<<< at line %d' - [L] ]. [ ' <<<< at line %d' - [L] ].
syntax_error_token('EOT',_, _LC) --> !, syntax_error_token('EOT',_, _LC) --> !,
@ -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).