keep on working on exs.
This commit is contained in:
parent
bc3555dfbf
commit
7ce963b63c
@ -2099,7 +2099,7 @@ X_API void YAP_ClearExceptions(void) {
|
||||
Yap_ResetException(worker_id);
|
||||
}
|
||||
|
||||
X_API int YAP_InitConsult(int mode, const char *fname, char *full, int *osnop) {
|
||||
X_API int YAP_InitConsult(int mode, const char *fname, char **full, int *osnop) {
|
||||
CACHE_REGS
|
||||
int sno;
|
||||
BACKUP_MACHINE_REGS();
|
||||
@ -2114,19 +2114,25 @@ X_API int YAP_InitConsult(int mode, const char *fname, char *full, int *osnop) {
|
||||
fl = Yap_AbsoluteFile(fname, true);
|
||||
if (!fl || !fl[0]) {
|
||||
pop_text_stack(lvl);
|
||||
*full = NULL;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
bool consulted = (mode == YAP_CONSULT_MODE);
|
||||
sno = Yap_OpenStream(fl, "r", MkAtomTerm(Yap_LookupAtom(fl)), LOCAL_encoding);
|
||||
if (sno < 0)
|
||||
return sno;
|
||||
if (!Yap_ChDir(dirname((char *)fl))) return -1;
|
||||
if (sno < 0 ||
|
||||
!Yap_ChDir(dirname((char *)fl))) {
|
||||
pop_text_stack(lvl);
|
||||
*full = NULL;
|
||||
return -1;
|
||||
}
|
||||
LOCAL_PrologMode = UserMode;
|
||||
|
||||
Yap_init_consult(consulted, fl);
|
||||
GLOBAL_Stream[sno].name = Yap_LookupAtom(fl);
|
||||
GLOBAL_Stream[sno].user_name = MkAtomTerm(Yap_LookupAtom(fname));
|
||||
GLOBAL_Stream[sno].encoding = LOCAL_encoding;
|
||||
pop_text_stack(lvl);
|
||||
*full = pop_output_text_stack(lvl, fl);
|
||||
RECOVER_MACHINE_REGS();
|
||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||
return sno;
|
||||
@ -2285,8 +2291,6 @@ X_API bool YAP_CompileClause(Term t) {
|
||||
}
|
||||
RECOVER_MACHINE_REGS();
|
||||
if (!ok) {
|
||||
t = Yap_GetException();
|
||||
Yap_DebugPlWrite(t);
|
||||
return NULL;
|
||||
}
|
||||
return ok;
|
||||
|
@ -2724,7 +2724,7 @@ static Int new_meta_pred(USES_REGS1) {
|
||||
|
||||
pe = new_pred(Deref(ARG1), Deref(ARG2), "meta_predicate");
|
||||
if (EndOfPAEntr(pe))
|
||||
return FALSE;
|
||||
return false;
|
||||
PELOCK(30, pe);
|
||||
arity = pe->ArityOfPE;
|
||||
if (arity == 0)
|
||||
|
415
C/errors.c
415
C/errors.c
@ -33,6 +33,55 @@
|
||||
#include "Foreign.h"
|
||||
|
||||
|
||||
#define set_key_b(k, ks, q, i, t) \
|
||||
if (strcmp(ks,q) == 0) \
|
||||
{ i->k = t == TermTrue ? true : \
|
||||
false; \
|
||||
return i->k || t == TermFalse; } \
|
||||
|
||||
#define set_key_i(k, ks, q, i, t) \
|
||||
if (strcmp(ks,q) == 0) \
|
||||
{ i->k = IsIntegerTerm(t) ? IntegerOfTerm(t) : \
|
||||
0; \
|
||||
return IsIntegerTerm(t); }
|
||||
|
||||
#define set_key_s(k, ks, q, i, t) \
|
||||
if (strcmp(ks,q) == 0) \
|
||||
{ const char *s = IsAtomTerm(t) ? RepAtom(AtomOfTerm(t))->StrOfAE : \
|
||||
IsStringTerm(t) ? StringOfTerm(t) : \
|
||||
NULL; \
|
||||
if (s) { char *tmp = malloc(strlen(s)+1); strcpy(tmp,s); i->k = tmp; } \
|
||||
return i->k != NULL; } \
|
||||
|
||||
static bool setErr(const char *q, yap_error_descriptor_t *i, Term t) {
|
||||
set_key_i( errorNo, "errorNo", q, i , t);
|
||||
set_key_i(errorClass, "errorClass", q, i, t);
|
||||
set_key_s(errorAsText, "errorAsText", q, i, t);
|
||||
set_key_s( errorGoal, "errorGoal", q, i, t);
|
||||
set_key_s( classAsText, "classAsText", q, i, t);
|
||||
set_key_i( errorLine, "errorLine", q, i , t);
|
||||
set_key_s( errorFunction, "errorFunction", q, i, t);
|
||||
set_key_s( errorFile, "errorFile", q, i, t);
|
||||
set_key_i( prologPredLine, "prologPredLine", q, i, t);
|
||||
set_key_i( prologPredFirstLine, "prologPredFirstLine", q, i, t);
|
||||
set_key_i( prologPredLastLine, "prologPredLastLine", q, i, t);
|
||||
set_key_s( prologPredName, "prologPredName", q, i, t);
|
||||
set_key_i( prologPredArity, "prologPredArity", q, i, t);
|
||||
set_key_s( prologPredModule, "prologPredModule", q, i, t);
|
||||
set_key_s( prologPredFile, "prologPredFile", q, i, t);
|
||||
set_key_i( prologParserPos, "prologParserPos", q, i, t);
|
||||
set_key_i( prologParserLine, "prologParserLine", q, i, t);
|
||||
set_key_i( prologParserFirstLine, "prologParserFirstLine", q, i, t);
|
||||
set_key_i( prologParserLastLine, "prologParserLastLine", q, i, t);
|
||||
set_key_s( prologParserText, "prologParserText", q, i, t);
|
||||
set_key_s( prologParserFile, "prologParserFile", q, i, t);
|
||||
set_key_b( prologConsulting, "prologConsulting", q, i, t);
|
||||
set_key_s( culprit, "culprit", q, i, t);
|
||||
set_key_s( errorMsg, "errorMsg", q, i, t);
|
||||
set_key_i( errorMsgLen, "errorMsgLen", q, i, t);
|
||||
return false;
|
||||
}
|
||||
|
||||
#define query_key_b(k, ks, q, i) \
|
||||
if (strcmp(ks,q) == 0) \
|
||||
{ return i->k ? TermTrue : TermFalse; } \
|
||||
@ -43,7 +92,7 @@
|
||||
|
||||
#define query_key_s(k, ks, q, i) \
|
||||
if (strcmp(ks,q) == 0) \
|
||||
{ return i->k ? MkStringTerm(i->k) : TermNil; }
|
||||
{ return ( i->k && i->k[0] ? MkStringTerm(i->k) : TermEmptyAtom ); }
|
||||
|
||||
static Term queryErr(const char *q, yap_error_descriptor_t *i) {
|
||||
query_key_i( errorNo, "errorNo", q, i );
|
||||
@ -396,7 +445,6 @@ int Yap_SWIHandleError(const char *s, ...) {
|
||||
|
||||
void Yap_RestartYap(int flag) {
|
||||
CACHE_REGS
|
||||
fprintf(stderr,"call siglongjmp HR=%p B=%p\n", HR, B);
|
||||
#if PUSH_REGS
|
||||
restore_absmi_regs(&Yap_standard_regs);
|
||||
#endif
|
||||
@ -785,16 +833,226 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function, int linen
|
||||
|
||||
if (LOCAL_DoingUndefp) {
|
||||
LOCAL_Signals = 0;
|
||||
Yap_PrintWarning(Yap_GetException());
|
||||
Yap_PrintWarning(MkErrorTerm(Yap_GetException()));
|
||||
return P;
|
||||
}
|
||||
LOCAL_CommittedError = Yap_GetException();
|
||||
//reset_error_description();
|
||||
// if (!throw) {
|
||||
if (!throw) {
|
||||
Yap_JumpToEnv();
|
||||
// }
|
||||
}
|
||||
LOCAL_PrologMode = UserMode;
|
||||
return P;
|
||||
}
|
||||
|
||||
static Int close_error(USES_REGS1) {
|
||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
||||
return true;
|
||||
}
|
||||
|
||||
#undef BEGIN_ERROR_CLASSES
|
||||
#undef ECLASS
|
||||
#undef END_ERROR_CLASSES
|
||||
#undef BEGIN_ERRORS
|
||||
#undef E0
|
||||
#undef E
|
||||
#undef E2
|
||||
#undef END_ERRORS
|
||||
|
||||
#define BEGIN_ERROR_CLASSES() typedef enum aux_class {
|
||||
|
||||
#define ECLASS(CL, A, B) CL##__,
|
||||
|
||||
#define END_ERROR_CLASSES() \
|
||||
} \
|
||||
aux_class_t;
|
||||
|
||||
#define BEGIN_ERRORS()
|
||||
#define E0(X, Y)
|
||||
#define E(X, Y, Z)
|
||||
#define E2(X, Y, Z, W)
|
||||
#define END_ERRORS()
|
||||
|
||||
#include <YapErrors.h>
|
||||
|
||||
#undef BEGIN_ERROR_CLASSES
|
||||
#undef ECLASS
|
||||
#undef END_ERROR_CLASSES
|
||||
#undef BEGIN_ERRORS
|
||||
#undef E0
|
||||
#undef E
|
||||
#undef E2
|
||||
#undef END_ERRORS
|
||||
|
||||
#define BEGIN_ERROR_CLASSES() static const char *c_error_class_name[] = {
|
||||
|
||||
#define ECLASS(CL, A, B) A,
|
||||
|
||||
#define END_ERROR_CLASSES() \
|
||||
NULL \
|
||||
}
|
||||
|
||||
typedef struct c_error_info {
|
||||
int class;
|
||||
const char *name;
|
||||
} c_error_t;
|
||||
|
||||
#define BEGIN_ERRORS() static struct c_error_info c_error_list[] = {
|
||||
#define E0(X, Y) {Y##__, ""},
|
||||
#define E(X, Y, Z) {Y##__, Z},
|
||||
#define E2(X, Y, Z, W) {Y##__, Z " " W},
|
||||
#define END_ERRORS() \
|
||||
{ YAPC_NO_ERROR, "" } \
|
||||
} \
|
||||
;
|
||||
|
||||
#include <YapErrors.h>
|
||||
|
||||
yap_error_class_number Yap_errorClass(yap_error_number e) {
|
||||
return c_error_list[e].class;
|
||||
}
|
||||
|
||||
const char *Yap_errorName(yap_error_number e) { return c_error_list[e].name; }
|
||||
|
||||
const char *Yap_errorClassName(yap_error_class_number e) {
|
||||
return c_error_class_name[e];
|
||||
}
|
||||
|
||||
yap_error_descriptor_t * Yap_GetException(void) {
|
||||
CACHE_REGS
|
||||
if (LOCAL_ActiveError->errorNo != YAP_NO_ERROR) {
|
||||
yap_error_descriptor_t *t = LOCAL_ActiveError, *nt = malloc(sizeof(yap_error_descriptor_t));
|
||||
memcpy(nt,t,sizeof(yap_error_descriptor_t));
|
||||
return t;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Yap_PrintException(void) {
|
||||
printErr(LOCAL_ActiveError);
|
||||
}
|
||||
|
||||
bool Yap_RaiseException(void) {
|
||||
if (LOCAL_ActiveError->errorNo == YAP_NO_ERROR)
|
||||
return false;
|
||||
return Yap_JumpToEnv();
|
||||
}
|
||||
|
||||
bool Yap_ResetException(yap_error_descriptor_t *i) {
|
||||
// reset error descriptor
|
||||
if(!i)
|
||||
return true;
|
||||
yap_error_descriptor_t *bf = i->top_error;
|
||||
memset(i, 0, sizeof(*i));
|
||||
i->top_error = bf;
|
||||
return true;
|
||||
}
|
||||
|
||||
static Int reset_exception(USES_REGS1) { return Yap_ResetException(worker_id); }
|
||||
|
||||
Term MkErrorTerm(yap_error_descriptor_t *t)
|
||||
{
|
||||
if (t->errorNo == THROW_EVENT)
|
||||
return t->errorRawTerm;
|
||||
return mkerrort(t->errorNo, Yap_BufferToTerm(t->culprit, TermNil), err2list(t));
|
||||
}
|
||||
|
||||
static Int read_exception(USES_REGS1) {
|
||||
yap_error_descriptor_t *t = AddressOfTerm(Deref(ARG1));
|
||||
Term rc = MkErrorTerm(t);
|
||||
// Yap_DebugPlWriteln(rc);
|
||||
return Yap_unify(ARG2, rc);
|
||||
}
|
||||
|
||||
static Int query_exception(USES_REGS1) {
|
||||
const char *query;
|
||||
Term t;
|
||||
|
||||
if (IsAtomTerm((t = Deref(ARG1))))
|
||||
query = RepAtom(AtomOfTerm(t))->StrOfAE;
|
||||
if (IsStringTerm(t))
|
||||
query = StringOfTerm(t);
|
||||
if (!IsAddressTerm(Deref(ARG1)))
|
||||
return false;
|
||||
yap_error_descriptor_t *y = AddressOfTerm(Deref(ARG2));
|
||||
Term t3 = Deref(ARG3);
|
||||
if (IsVarTerm(t3)) {
|
||||
Term rc = queryErr(query, y);
|
||||
// Yap_DebugPlWriteln(rc);
|
||||
return Yap_unify(ARG3, rc);
|
||||
} else {
|
||||
return setErr(query, y, t3);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static Int drop_exception(USES_REGS1) {
|
||||
yap_error_descriptor_t *t = AddressOfTerm(Deref(ARG1));
|
||||
free(t);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static Int new_exception(USES_REGS1) {
|
||||
Term t = MkSysError(malloc(sizeof(yap_error_descriptor_t)));
|
||||
return Yap_unify(ARG1,t);
|
||||
}
|
||||
|
||||
|
||||
static Int get_exception(USES_REGS1) {
|
||||
yap_error_descriptor_t *i;
|
||||
Term t;
|
||||
|
||||
i = LOCAL_CommittedError;
|
||||
if (i && i->errorNo != YAP_NO_ERROR) {
|
||||
if (i->errorNo == THROW_EVENT)
|
||||
t = i->errorRawTerm;
|
||||
else
|
||||
t = mkerrort(i->errorNo, Yap_BufferToTerm(i->culprit, TermNil), MkSysError(i));
|
||||
Yap_ResetException(i);
|
||||
LOCAL_CommittedError = NULL;
|
||||
Int rc= Yap_unify(t, ARG1);
|
||||
return rc;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
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->errorClass = EVENT;
|
||||
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])))
|
||||
{
|
||||
LOCAL_ActiveError->errorNo = j;
|
||||
LOCAL_ActiveError->errorClass = c_error_list[j].class;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
Yap_prolog_add_culprit(LOCAL_ActiveError PASS_REGS1);
|
||||
return
|
||||
LOCAL_ActiveError;
|
||||
}
|
||||
|
||||
static Int is_boolean(USES_REGS1) {
|
||||
Term t = Deref(ARG1);
|
||||
// Term Context = Deref(ARG2)Yap_Error(INSTANTIATION_ERROR, t, NULL);;
|
||||
@ -879,156 +1137,11 @@ static Int is_predicate_indicator(USES_REGS1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
static Int close_error(USES_REGS1) {
|
||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
||||
return true;
|
||||
}
|
||||
|
||||
#undef BEGIN_ERROR_CLASSES
|
||||
#undef ECLASS
|
||||
#undef END_ERROR_CLASSES
|
||||
#undef BEGIN_ERRORS
|
||||
#undef E0
|
||||
#undef E
|
||||
#undef E2
|
||||
#undef END_ERRORS
|
||||
|
||||
#define BEGIN_ERROR_CLASSES() typedef enum aux_class {
|
||||
|
||||
#define ECLASS(CL, A, B) CL##__,
|
||||
|
||||
#define END_ERROR_CLASSES() \
|
||||
} \
|
||||
aux_class_t;
|
||||
|
||||
#define BEGIN_ERRORS()
|
||||
#define E0(X, Y)
|
||||
#define E(X, Y, Z)
|
||||
#define E2(X, Y, Z, W)
|
||||
#define END_ERRORS()
|
||||
|
||||
#include <YapErrors.h>
|
||||
|
||||
#undef BEGIN_ERROR_CLASSES
|
||||
#undef ECLASS
|
||||
#undef END_ERROR_CLASSES
|
||||
#undef BEGIN_ERRORS
|
||||
#undef E0
|
||||
#undef E
|
||||
#undef E2
|
||||
#undef END_ERRORS
|
||||
|
||||
#define BEGIN_ERROR_CLASSES() static const char *c_error_class_name[] = {
|
||||
|
||||
#define ECLASS(CL, A, B) A,
|
||||
|
||||
#define END_ERROR_CLASSES() \
|
||||
NULL \
|
||||
}
|
||||
|
||||
typedef struct c_error_info {
|
||||
int class;
|
||||
const char *name;
|
||||
} c_error_t;
|
||||
|
||||
#define BEGIN_ERRORS() static struct c_error_info c_error_list[] = {
|
||||
#define E0(X, Y) {Y##__, ""},
|
||||
#define E(X, Y, Z) {Y##__, Z},
|
||||
#define E2(X, Y, Z, W) {Y##__, Z " " W},
|
||||
#define END_ERRORS() \
|
||||
{ YAPC_NO_ERROR, "" } \
|
||||
} \
|
||||
;
|
||||
|
||||
#include <YapErrors.h>
|
||||
|
||||
yap_error_class_number Yap_errorClass(yap_error_number e) {
|
||||
return c_error_list[e].class;
|
||||
}
|
||||
|
||||
const char *Yap_errorName(yap_error_number e) { return c_error_list[e].name; }
|
||||
|
||||
const char *Yap_errorClassName(yap_error_class_number e) {
|
||||
return c_error_class_name[e];
|
||||
}
|
||||
|
||||
Term Yap_GetException(void) {
|
||||
CACHE_REGS
|
||||
if (LOCAL_ActiveError->errorNo != YAP_NO_ERROR) {
|
||||
yap_error_descriptor_t *t = LOCAL_ActiveError, *nt = malloc(sizeof(yap_error_descriptor_t));
|
||||
memcpy(nt,t,sizeof(yap_error_descriptor_t));
|
||||
Term rc = mkerrort(t->errorNo, Yap_BufferToTerm(t->culprit, TermNil), MkAddressTerm(nt));
|
||||
Yap_ResetException(worker_id);
|
||||
save_H();
|
||||
return rc;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Yap_PrintException(void) {
|
||||
printErr(LOCAL_ActiveError);
|
||||
}
|
||||
|
||||
bool Yap_RaiseException(void) {
|
||||
if (LOCAL_ActiveError->errorNo == YAP_NO_ERROR)
|
||||
return false;
|
||||
return Yap_JumpToEnv();
|
||||
}
|
||||
|
||||
bool Yap_ResetException(int wid) {
|
||||
// reset error descriptor
|
||||
yap_error_descriptor_t *bf = REMOTE_ActiveError(wid)->top_error;
|
||||
memset(REMOTE_ActiveError(wid), 0, sizeof(*LOCAL_ActiveError));
|
||||
REMOTE_ActiveError(wid)->top_error = bf;
|
||||
LOCAL_PrologMode &= ~InErrorMode;
|
||||
return true;
|
||||
}
|
||||
|
||||
static Int reset_exception(USES_REGS1) { return Yap_ResetException(worker_id); }
|
||||
|
||||
static Int read_exception(USES_REGS1) {
|
||||
yap_error_descriptor_t *t = AddressOfTerm(Deref(ARG1));
|
||||
Term rc = mkerrort(t->errorNo, Yap_BufferToTerm(t->culprit, TermNil), err2list(t));
|
||||
// Yap_DebugPlWriteln(rc);
|
||||
return Yap_unify(ARG2, rc);
|
||||
}
|
||||
|
||||
static Int query_exception(USES_REGS1) {
|
||||
const char *query;
|
||||
Term t;
|
||||
|
||||
if (IsAtomTerm((t = Deref(ARG1))))
|
||||
query = RepAtom(AtomOfTerm(t))->StrOfAE;
|
||||
if (IsStringTerm(t))
|
||||
query = StringOfTerm(t);
|
||||
yap_error_descriptor_t *y = AddressOfTerm(Deref(ARG2));
|
||||
Term rc = queryErr(query, y);
|
||||
// Yap_DebugPlWriteln(rc);
|
||||
return Yap_unify(ARG3, rc);
|
||||
}
|
||||
|
||||
|
||||
static Int drop_exception(USES_REGS1) {
|
||||
yap_error_descriptor_t *t = AddressOfTerm(Deref(ARG1));
|
||||
free(t);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static Int get_exception(USES_REGS1) {
|
||||
Term t;
|
||||
if (Yap_HasException() && (t = Yap_GetException()) != 0) {
|
||||
Int rc= Yap_unify(t, ARG1);
|
||||
return rc;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void Yap_InitErrorPreds(void) {
|
||||
CACHE_REGS
|
||||
Yap_InitCPred("$reset_exception", 1, reset_exception, 0);
|
||||
Yap_InitCPred("$new_exception", 1, new_exception, 0);
|
||||
Yap_InitCPred("$get_exception", 1, get_exception, 0);
|
||||
Yap_InitCPred("$drop_exception", 1, get_exception, 0);
|
||||
Yap_InitCPred("$read_exception", 2, read_exception, 0);
|
||||
Yap_InitCPred("$query_exception", 3, query_exception, 0);
|
||||
Yap_InitCPred("$drop_exception", 1, drop_exception, 0);
|
||||
|
46
C/exec.c
46
C/exec.c
@ -817,8 +817,8 @@ static bool watch_cut(Term ext USES_REGS) {
|
||||
}
|
||||
CELL *port_pt = deref_ptr(RepAppl(task) + 2);
|
||||
CELL *completion_pt = deref_ptr(RepAppl(task) + 4);
|
||||
if ((ex_mode = Yap_HasException())) {
|
||||
e = Yap_GetException();
|
||||
if (LOCAL_CommittedError) {
|
||||
e = MkErrorTerm(LOCAL_CommittedError);
|
||||
Term t;
|
||||
if (active) {
|
||||
t = Yap_MkApplTerm(FunctorException, 1, &e);
|
||||
@ -873,8 +873,9 @@ static bool watch_retry(Term d0 USES_REGS) {
|
||||
// just do the frrpest
|
||||
if (B >= B0 && !ex_mode && !active)
|
||||
return true;
|
||||
if ((ex_mode = Yap_HasException())) {
|
||||
e = Yap_GetException();
|
||||
if (LOCAL_CommittedError &&
|
||||
LOCAL_CommittedError->errorNo != YAP_NO_ERROR) {
|
||||
e = MkErrorTerm(LOCAL_CommittedError);
|
||||
if (active) {
|
||||
t = Yap_MkApplTerm(FunctorException, 1, &e);
|
||||
} else {
|
||||
@ -1390,7 +1391,6 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
|
||||
|
||||
sigjmp_buf signew, *sighold = LOCAL_RestartEnv;
|
||||
LOCAL_RestartEnv = &signew;
|
||||
REGSTORE *old_rs = Yap_regp;
|
||||
|
||||
if (top && (lval = sigsetjmp(signew, 1)) != 0) {
|
||||
switch (lval) {
|
||||
@ -1449,12 +1449,13 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
|
||||
// going up, unless there is no up to go to. or someone
|
||||
// but we should inform the caller on what happened.
|
||||
|
||||
Yap_regp = old_rs;
|
||||
// Yap_regp = old_rs;
|
||||
restore_TR();
|
||||
restore_B();
|
||||
/* H is not so important, because we're gonna backtrack */
|
||||
restore_H();
|
||||
/* set stack */
|
||||
Yap_JumpToEnv();
|
||||
ASP = (CELL *) PROTECT_FROZEN_B(B);
|
||||
|
||||
if (B == NULL || B->cp_b == NULL || (CELL*)(B->cp_b) > LCL0 - LOCAL_CBorder) {
|
||||
@ -2027,7 +2028,8 @@ bool is_cleanup_cp(choiceptr cp_b) {
|
||||
// DBTerm *dbt = Yap_RefToException();
|
||||
while (handler
|
||||
&& Yap_PredForChoicePt(handler, NULL) != PredDollarCatch
|
||||
&& LOCAL_CBorder < LCL0 - (CELL *)handler && handler->cp_ap != NOCODE
|
||||
&& LOCAL_CBorder < LCL0 - (CELL *)handler
|
||||
&& handler->cp_ap != NOCODE
|
||||
&& handler->cp_b != NULL
|
||||
) {
|
||||
//if (handler->cp_ap != NOCODE)
|
||||
@ -2039,7 +2041,7 @@ bool is_cleanup_cp(choiceptr cp_b) {
|
||||
Yap_signal(YAP_FAIL_SIGNAL);
|
||||
}
|
||||
|
||||
//B = handler;
|
||||
B = handler;
|
||||
P = FAILCODE;
|
||||
return true;
|
||||
}
|
||||
@ -2053,34 +2055,28 @@ bool Yap_JumpToEnv(void) {
|
||||
|
||||
/* This does very nasty stuff!!!!! */
|
||||
static Int jump_env(USES_REGS1) {
|
||||
Term t = Deref(ARG1);
|
||||
Term t = Deref(ARG1), t0 = t, t1;
|
||||
if (IsVarTerm(t)) {
|
||||
Yap_Error(INSTANTIATION_ERROR, t, "throw ball must be bound");
|
||||
return false;
|
||||
} else if (IsApplTerm(t) && FunctorOfTerm(t) == FunctorError) {
|
||||
Term t2;
|
||||
Yap_prolog_add_culprit(LOCAL_ActiveError PASS_REGS);
|
||||
// LOCAL_Error_TYPE = ERROR_EVENT;
|
||||
Term t1 = ArgOfTerm(1, t);
|
||||
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(t)) {
|
||||
LOCAL_ActiveError->errorAsText = RepAtom(AtomOfTerm(t1))->StrOfAE;
|
||||
LOCAL_ActiveError->classAsText = NULL;
|
||||
}
|
||||
} else if (IsApplTerm(t) && FunctorOfTerm(t) == FunctorError
|
||||
&& (t1 = ArgOfTerm(1, t))
|
||||
&& IsPairTerm((t = ArgOfTerm(2, t)))
|
||||
&& IsApplTerm((t = HeadOfTerm(t)))) {
|
||||
LOCAL_ActiveError = Yap_UserError(t, t1, LOCAL_ActiveError);
|
||||
} else {
|
||||
Yap_prolog_add_culprit(LOCAL_ActiveError PASS_REGS);
|
||||
LOCAL_Error_TYPE = THROW_EVENT;
|
||||
LOCAL_ActiveError->errorAsText = NULL;
|
||||
LOCAL_ActiveError->errorRawTerm = Yap_SaveTerm(t);
|
||||
LOCAL_ActiveError->classAsText = NULL;
|
||||
//return true;
|
||||
}
|
||||
LOCAL_ActiveError->prologPredName = NULL;
|
||||
bool out = JumpToEnv(PASS_REGS1);
|
||||
if (B != NULL && P == FAILCODE && B->cp_ap == NOCODE &&
|
||||
LCL0 - (CELL *)B > LOCAL_CBorder) {
|
||||
// we're failing up to the top layer
|
||||
}
|
||||
LOCAL_CommittedError = Yap_GetException();
|
||||
return out;
|
||||
}
|
||||
|
||||
@ -2110,7 +2106,7 @@ static Int jump_env(USES_REGS1) {
|
||||
#endif
|
||||
#endif /* PUSH_REGS */
|
||||
CACHE_REGS
|
||||
Yap_ResetException(worker_id);
|
||||
Yap_ResetException(LOCAL_ActiveError);
|
||||
Yap_PutValue(AtomBreak, MkIntTerm(0));
|
||||
TR = (tr_fr_ptr)REMOTE_TrailBase(myworker_id);
|
||||
HR = H0 = ((CELL *) REMOTE_GlobalBase(myworker_id)) +
|
||||
@ -2263,7 +2259,7 @@ static Int jump_env(USES_REGS1) {
|
||||
Yap_InitCPred("$clean_ifcp", 1, clean_ifcp, SafePredFlag);
|
||||
Yap_InitCPred("qpack_clean_up_to_disjunction", 0, cut_up_to_next_disjunction,
|
||||
SafePredFlag);
|
||||
Yap_InitCPred("$jump_env_and_store_ball", 1, jump_env, 0);
|
||||
Yap_InitCPred("throw", 1, jump_env, 0);
|
||||
Yap_InitCPred("$generate_pred_info", 4, generate_pred_info, 0);
|
||||
Yap_InitCPred("_user_expand_goal", 2, _user_expand_goal, 0);
|
||||
Yap_InitCPred("$do_term_expansion", 2, do_term_expansion, 0);
|
||||
|
@ -159,15 +159,14 @@ static void consult(const char *b_file USES_REGS) {
|
||||
Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1);
|
||||
Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1);
|
||||
Functor functor_compile2 = Yap_MkFunctor(Yap_LookupAtom("c_compile"), 1);
|
||||
char *full;
|
||||
|
||||
/* consult in C */
|
||||
int lvl = push_text_stack();
|
||||
char *full = Malloc(YAP_FILENAME_MAX + 1);
|
||||
full[0] = '\0';
|
||||
/* the consult mode does not matter here, really */
|
||||
if ((osno = Yap_CheckAlias(AtomLoopStream)) < 0)
|
||||
osno = 0;
|
||||
c_stream = YAP_InitConsult(YAP_BOOT_MODE, b_file, full, &oactive);
|
||||
c_stream = YAP_InitConsult(YAP_BOOT_MODE, b_file, &full, &oactive);
|
||||
if (c_stream < 0) {
|
||||
fprintf(stderr, "[ FATAL ERROR: could not open file %s ]\n", b_file);
|
||||
pop_text_stack(lvl);
|
||||
|
29
CXX/yapi.cpp
29
CXX/yapi.cpp
@ -433,11 +433,10 @@ bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) {
|
||||
// allow Prolog style exceotion handling
|
||||
// don't forget, on success these bindings will still be there);
|
||||
result = YAP_LeaveGoal(false, &q);
|
||||
Term terr;
|
||||
|
||||
if ((terr = Yap_GetException()) != 0) {
|
||||
if (LOCAL_CommittedError != nullptr) {
|
||||
std::cerr << "Exception received by " << __func__ << "( "
|
||||
<< YAPTerm(terr).text() << ").\n Forwarded...\n\n";
|
||||
<< YAPError(LOCAL_CommittedError).text() << ").\n Forwarded...\n\n";
|
||||
// Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);
|
||||
// throw YAPError();
|
||||
}
|
||||
@ -481,12 +480,9 @@ bool YAPEngine::mgoal(Term t, Term tmod) {
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
|
||||
|
||||
result = (bool)YAP_EnterGoal(ap, nullptr, &q);
|
||||
Term terr;
|
||||
if ((terr = Yap_GetException()) != 0) {
|
||||
if (LOCAL_CommittedError != nullptr) {
|
||||
std::cerr << "Exception received by " << __func__ << "( "
|
||||
<< YAPTerm(terr).text() << ").\n Forwarded...\n\n";
|
||||
// Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);
|
||||
// throw YAPError();
|
||||
<< YAPError(LOCAL_CommittedError).text() << ").\n Forwarded...\n\n";
|
||||
}
|
||||
|
||||
{
|
||||
@ -547,13 +543,12 @@ Term YAPEngine::fun(Term t) {
|
||||
q.cp = CP;
|
||||
// make sure this is safe
|
||||
// allow Prolog style exception handling
|
||||
Term terr;
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
|
||||
|
||||
bool result = (bool)YAP_EnterGoal(ap, nullptr, &q);
|
||||
if ((terr = Yap_GetException()) != 0) {
|
||||
if (LOCAL_CommittedError != nullptr) {
|
||||
std::cerr << "Exception received by " << __func__ << "( "
|
||||
<< YAPTerm(terr).text() << ").\n Forwarded...\n\n";
|
||||
<< YAPError(LOCAL_CommittedError).text() << ").\n Forwarded...\n\n";
|
||||
// Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);
|
||||
// throw YAPError();
|
||||
}
|
||||
@ -673,16 +668,12 @@ bool YAPQuery::next() {
|
||||
YAP_LeaveGoal(false, &q_h);
|
||||
Yap_CloseHandles(q_handles);
|
||||
q_open = false;
|
||||
if (Yap_HasException()) {
|
||||
terr = Yap_GetException();
|
||||
yap_error_descriptor_t *tp = LOCAL_ActiveError->top_error;
|
||||
memset(LOCAL_ActiveError, 0, sizeof(yap_error_descriptor_t));
|
||||
LOCAL_ActiveError->top_error = tp;
|
||||
std::cerr << "Exception at " << __func__ << "() " << YAPTerm(terr).text()
|
||||
<< ").\n\n\n";
|
||||
if (LOCAL_CommittedError != nullptr) {
|
||||
// Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);
|
||||
// throw YAPError();
|
||||
Term es[2];
|
||||
es[0] = TermError;
|
||||
es[1] = terr;
|
||||
es[1] = MkErrorTerm(LOCAL_CommittedError);
|
||||
Functor f = Yap_MkFunctor(Yap_LookupAtom("print_message"), 2);
|
||||
YAP_RunGoalOnce(Yap_MkApplTerm(f, 2, es));
|
||||
// Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);
|
||||
|
15
CXX/yapi.hh
15
CXX/yapi.hh
@ -42,6 +42,14 @@ extern "C" {
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
#if YAP_PYTHON
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
extern bool python_in_python;
|
||||
#endif
|
||||
|
||||
#include "Yap.h"
|
||||
|
||||
#include "Yatom.h"
|
||||
@ -100,13 +108,6 @@ X_API extern void YAP_UserBackCutCPredicate(const char *name,
|
||||
X_API extern YAP_Term YAP_ReadBuffer(const char *s, YAP_Term *tp);
|
||||
|
||||
|
||||
#if YAP_PYTHON
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
extern bool python_in_python;
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -40,6 +40,11 @@ public:
|
||||
if (ID != YAP_NO_ERROR) {};
|
||||
std::cerr << "Error detected" << ID << "\n";
|
||||
}
|
||||
YAPError(yap_error_descriptor_t *des){
|
||||
ID = des->errorNo;
|
||||
if (ID != YAP_NO_ERROR) {};
|
||||
std::cerr << "Error detected" << ID << "\n";
|
||||
}
|
||||
/// error handler object with initial data when receiving the error term
|
||||
YAPError(yap_error_number id, YAPTerm culprit, std::string txt);
|
||||
|
||||
|
12
H/Yatom.h
12
H/Yatom.h
@ -1601,14 +1601,22 @@ INLINE_ONLY inline EXTERN const char *AtomTermName(Term t) {
|
||||
return RepAtom(AtomOfTerm(t))->rep.uStrOfAE;
|
||||
}
|
||||
|
||||
extern bool Yap_ResetException(int wid);
|
||||
extern Term MkErrorTerm(yap_error_descriptor_t *t);
|
||||
|
||||
extern bool Yap_ResetException(yap_error_descriptor_t *i);
|
||||
extern bool Yap_HasException(void);
|
||||
extern Term Yap_GetException(void);
|
||||
extern yap_error_descriptor_t * Yap_GetException(void);
|
||||
extern void Yap_PrintException(void);
|
||||
INLINE_ONLY inline EXTERN bool Yap_HasException(void) {
|
||||
return LOCAL_ActiveError->errorNo != YAP_NO_ERROR;
|
||||
}
|
||||
|
||||
INLINE_ONLY inline EXTERN Term MkSysError(yap_error_descriptor_t *i) {
|
||||
Term et = MkAddressTerm(i);
|
||||
return Yap_MkApplTerm( FunctorException, 1, &et);
|
||||
}
|
||||
yap_error_descriptor_t *Yap_UserError( Term t, Term t1, yap_error_descriptor_t *i);
|
||||
|
||||
extern bool Yap_RaiseException(void);
|
||||
|
||||
#endif
|
||||
|
@ -195,6 +195,7 @@ LOCAL(ADDR, TrailTop);
|
||||
|
||||
/* error handling info, designed to be easy to pass to the foreign world */
|
||||
LOCAL_INIT(yap_error_descriptor_t *, ActiveError, calloc(sizeof(yap_error_descriptor_t), 1));
|
||||
LOCAL_INIT(yap_error_descriptor_t *, CommittedError, calloc(sizeof(yap_error_descriptor_t), 1));
|
||||
/// pointer to an exception term, from throw
|
||||
LOCAL(jmp_buf, IOBotch);
|
||||
|
||||
|
@ -156,6 +156,7 @@ E(CALL_COUNTER_UNDERFLOW_EVENT, EVENT, "call_counter_underflow")
|
||||
E(PRED_ENTRY_COUNTER_UNDERFLOW_EVENT, EVENT, "pred_entry_counter_underflow")
|
||||
E(RETRY_COUNTER_UNDERFLOW_EVENT, EVENT, "retry_counter_underflow")
|
||||
E(INTERRUPT_EVENT, EVENT, "interrupt")
|
||||
E(USER_EVENT, EVENT, "user event")
|
||||
|
||||
E(TYPE_ERROR_ARRAY, TYPE_ERROR, "array")
|
||||
E(TYPE_ERROR_ATOM, TYPE_ERROR, "atom")
|
||||
|
@ -408,7 +408,7 @@ extern X_API void YAP_Write(YAP_Term t, FILE *s, int);
|
||||
|
||||
extern X_API FILE *YAP_TermToStream(YAP_Term t);
|
||||
|
||||
extern X_API int YAP_InitConsult(int mode, const char *filename, char *buf,
|
||||
extern X_API int YAP_InitConsult(int mode, const char *filename, char **buf,
|
||||
int *previous_sno);
|
||||
|
||||
extern X_API void YAP_EndConsult(int s, int *previous_sno, const char *previous_cwd);
|
||||
|
@ -33,6 +33,7 @@ set(PL_BOOT_SOURCES
|
||||
load_foreign.yap
|
||||
messages.yap
|
||||
meta.yap
|
||||
metadecls.yap
|
||||
modules.yap
|
||||
newmod.yap
|
||||
os.yap
|
||||
|
27
pl/boot.yap
27
pl/boot.yap
@ -119,8 +119,6 @@ print_message(L,E) :-
|
||||
format( user_error, '~w in bootstrap: got ~w~n',[L,E])
|
||||
).
|
||||
|
||||
|
||||
|
||||
'$undefp0'([M|G], _Action) :-
|
||||
stream_property( loop_stream, file_name(F)),
|
||||
stream_property( loop_stream, line_number(L)),
|
||||
@ -129,6 +127,25 @@ print_message(L,E) :-
|
||||
|
||||
:- '$undefp_handler'('$undefp0'(_,_),prolog).
|
||||
|
||||
/**
|
||||
* @pred $system_meta_predicates'( +L )
|
||||
*
|
||||
* @param L declare a set of system meta-predicates
|
||||
*
|
||||
* @return system predicates
|
||||
*/
|
||||
'$system_meta_predicates'([]).
|
||||
'$system_meta_predicates'([P|L]) :-
|
||||
functor(P,N,A),
|
||||
'$new_meta_pred'(P, prolog),
|
||||
G = ('$meta_predicate'(N,_M2,A,P) :- true),
|
||||
'$compile'(G, assertz, G, prolog, _R),
|
||||
'$system_meta_predicates'(L).
|
||||
|
||||
:- '$mk_dynamic'( '$meta_predicate'(_N,_M,_A,_P), prolog).
|
||||
:- '$new_multifile'( '$meta_predicate'(_N,_M,_A,_P), prolog).
|
||||
:- '$new_multifile'('$full_clause_optimisation'(_H, _M, _B0, _BF), prolog).
|
||||
:- '$new_multifile'('$exec_directive'(_,_,_,_,_), prolog).
|
||||
|
||||
/**
|
||||
|
||||
@ -175,7 +192,6 @@ print_message(L,E) :-
|
||||
% These are pseudo declarations
|
||||
% so that the user will get a redefining system predicate
|
||||
|
||||
|
||||
% just create a choice-point
|
||||
% the 6th argument marks the time-stamp.
|
||||
'$do_log_upd_clause'(_,_,_,_,_,_).
|
||||
@ -232,8 +248,9 @@ print_message(L,E) :-
|
||||
:- c_compile('bootlists.yap').
|
||||
:- c_compile('consult.yap').
|
||||
:- c_compile('preddecls.yap').
|
||||
:- c_compile('preddyns.yap').
|
||||
:- c_compile('meta.yap').
|
||||
:- c_compile('metadecls.yap').
|
||||
:- c_compile('preddyns.yap').
|
||||
:- c_compile('builtins.yap').
|
||||
:- c_compile('newmod.yap').
|
||||
|
||||
@ -461,5 +478,3 @@ If this hook preodicate succeeds it must instantiate the _Action_ argument to t
|
||||
:- ensure_loaded('../pl/pathconf.yap').
|
||||
|
||||
:- yap_flag(user:unknown,error).
|
||||
|
||||
|
||||
|
@ -72,7 +72,6 @@ The style_check/1 built-in is now deprecated. Please use
|
||||
%
|
||||
% A Small style checker for YAP
|
||||
|
||||
:- op(1150, fx, [multifile,discontiguous]).
|
||||
|
||||
style_check(V) :- var(V), !, fail.
|
||||
style_check(V) :-
|
||||
|
@ -1,4 +1,4 @@
|
||||
s444444444444444444444444444444444444444444444444444444444444444444444444/*************************************************************************
|
||||
/*************************************************************************
|
||||
* *
|
||||
* YAP Prolog *
|
||||
* *
|
||||
@ -74,6 +74,20 @@ s444444444444444444444444444444444444444444444444444444444444444444444444/******
|
||||
|
||||
:- use_system_module( '$_preds', ['$current_predicate'/4]).
|
||||
|
||||
|
||||
:- '$system_meta_predicates'([
|
||||
compile(:),
|
||||
consult(:),
|
||||
db_files(:),
|
||||
ensure_loaded(:),
|
||||
exo_files(:),
|
||||
load_files(:,+),
|
||||
reconsult(:),
|
||||
use_module(:),
|
||||
use_module(:,+),
|
||||
use_module(?,:,+)
|
||||
] ).
|
||||
|
||||
/**
|
||||
|
||||
@defgroup YAPConsulting Loading files into YAP
|
||||
|
@ -63,12 +63,7 @@ system_error(Type,Goal) :-
|
||||
|
||||
|
||||
'$do_error'(Type,Goal) :-
|
||||
% format('~w~n', [Type]),
|
||||
ancestor_location(Call, Caller),
|
||||
throw(error(Type, [
|
||||
[g|g(Goal)],
|
||||
[p|Call],
|
||||
[e|Caller]])).
|
||||
throw(error(Type, [error(Goal)])).
|
||||
|
||||
/**
|
||||
* @pred system_error( +Error, +Cause, +Culprit)
|
||||
@ -82,13 +77,8 @@ system_error(Type,Goal) :-
|
||||
*
|
||||
*/
|
||||
system_error(Type,Goal,Culprit) :-
|
||||
% format('~w~n', [Type]),
|
||||
ancestor_location(Call, Caller),
|
||||
throw(error(Type, [
|
||||
[i|Culprit],
|
||||
[g|g(Goal)],
|
||||
[p|Call],
|
||||
[e|Caller]])).
|
||||
ancestor_location(Goal, Culprit),
|
||||
throw(error(Type, [error(Goal, Culprit)])).
|
||||
|
||||
'$do_pi_error'(type_error(callable,Name/0),Message) :- !,
|
||||
'$do_error'(type_error(callable,Name),Message).
|
||||
|
105
pl/messages.yap
105
pl/messages.yap
@ -68,7 +68,7 @@ handling in YAP:
|
||||
|
||||
An error record comsists of An ISO compatible descriptor of the format
|
||||
|
||||
error(errror_kind(Culprit,..), Info)
|
||||
error(errror_kind(Culprit,..), In)
|
||||
|
||||
In YAP, the info field describes:
|
||||
|
||||
@ -213,6 +213,9 @@ compose_message( loaded(included,AbsFileName,Mod,Time,Space), _Level) --> !,
|
||||
compose_message( loaded(What,AbsoluteFileName,Mod,Time,Space), _Level) --> !,
|
||||
[ '~a ~a in module ~a, ~d msec ~d bytes' -
|
||||
[What, AbsoluteFileName,Mod,Time,Space] ].
|
||||
compose_message(error(signal(SIG,_), _), _) -->
|
||||
!,
|
||||
[ 'UNEXPECTED SIGNAL: ~a' - [SIG] ].
|
||||
compose_message(trace_command(C), _Leve) -->
|
||||
!,
|
||||
[ '~a is not a valid debugger command.' - [C] ].
|
||||
@ -227,20 +230,74 @@ compose_message(myddas_version(Version), _Leve) -->
|
||||
[ 'MYDDAS version ~a' - [Version] ].
|
||||
compose_message(yes, _Level) --> !,
|
||||
[ 'yes'- [] ].
|
||||
compose_message(Term, Level) -->
|
||||
compose_message(error(E, exception(Exc)), Level) -->
|
||||
{ '$show_consult_level'(LC) },
|
||||
location( Term, Level, LC),
|
||||
main_message( Term, Level, LC ),
|
||||
c_goal( Term, Level ),
|
||||
caller( Term, Level ),
|
||||
extra_info( Term, Level ),
|
||||
location( Exc, Level, LC),
|
||||
main_message( Exc, Level, LC ),
|
||||
c_goal( Exc, Level ),
|
||||
caller( Exc, Level ),
|
||||
extra_info( Exc, Level ),
|
||||
!,
|
||||
[nl,nl].
|
||||
compose_message(Term, Level) -->
|
||||
compose_message(error(E,[I|Is]), Level) -->
|
||||
{ Level == error -> true ; Level == warning },
|
||||
{ '$show_consult_level'(LC) },
|
||||
main_message( Term, Level, LC),
|
||||
{ '$show_consult_level'(LC),
|
||||
translate_info([I|Is], In))
|
||||
},
|
||||
compose_message( e(Err, In), Level),
|
||||
[nl,nl].
|
||||
compose_message(Throw), _Leve) -->
|
||||
!,
|
||||
[ 'UNHANDLED EXCEPTION - message ~w unknown' - [Throw] ].
|
||||
|
||||
translate_info([I1|I2],exception(R) ) :-
|
||||
!,
|
||||
'$new_exception'(R),
|
||||
tinfo(R, [I1|I2], []).
|
||||
translate_info(E, none ).
|
||||
|
||||
tinfo(_Reg) -->
|
||||
!.
|
||||
tinfo(Reg) -->
|
||||
addinfo(Reg),
|
||||
tinfo(Reg).
|
||||
|
||||
addinfo( Desc) -->
|
||||
( [[p|p(M,Na,Ar,File,FilePos)]]
|
||||
->
|
||||
{
|
||||
'$query_exception'(prologPredFile, Desc, File),
|
||||
'$query_exception'(prologPredLine, Desc, FilePos),
|
||||
'$query_exception'(prologPredModule, Desc, M),
|
||||
'$query_exception'(prologPredName, Desc, Na),
|
||||
'$query_exception'(prologPredArity, Desc, Ar)
|
||||
}
|
||||
;
|
||||
[e|p(M,Na,Ar,File,FilePos)], Desc)
|
||||
->
|
||||
{
|
||||
'$query_exception'(prologPredFile, Desc, File),
|
||||
'$query_exception'(prologPredLine, Desc, FilePos),
|
||||
'$query_exception'(prologPredModule, Desc, M),
|
||||
'$query_exception'(prologPredName, Desc, Na),
|
||||
'$query_exception'(prologPredArity, Desc, Ar)
|
||||
}
|
||||
;
|
||||
[[c|c(File, Line, Func)]]
|
||||
->
|
||||
{
|
||||
'$query_exception'(errorFile, Desc, File),
|
||||
'$query_exception'(errorFunction, Desc, Func),
|
||||
'$query_exception'(errorLine, Desc, Line)
|
||||
}
|
||||
;
|
||||
[[g|g(Call)]
|
||||
->
|
||||
{
|
||||
'$query_exception'(errorGoal, Desc, Call)
|
||||
}
|
||||
).
|
||||
|
||||
|
||||
location(error(syntax_error(_),info(between(_,LN,_), FileName, _ChrPos, _Err)), _ , _) -->
|
||||
!,
|
||||
@ -249,28 +306,28 @@ location(error(syntax_error(_),info(between(_,LN,_), FileName, _ChrPos, _Err)),
|
||||
location(error(style_check(style_check(_,LN,FileName,_ ) ),_), _ , _) -->
|
||||
!,
|
||||
[ '~a:~d:0 ' - [FileName,LN] ] .
|
||||
location( error(_,Desc), Level, LC ) -->
|
||||
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 )
|
||||
'$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(_,Desc), Level, LC ) -->
|
||||
location( error(_,exception(Desc)), Level, LC ) -->
|
||||
{ '$query_exception'(prologPredFile, Desc, File),
|
||||
display_consulting( File, Level, LC ),
|
||||
'$query_exception'(prologPredLine, Desc, FilePos),
|
||||
'$query_exception'(prologPredModule, Desc, M),
|
||||
'$query_exception'(prologPredName, Desc, Na),
|
||||
'$query_exception'(prologPredArity, Desc, Ar)
|
||||
},
|
||||
display_consulting( File, Level, LC ),
|
||||
[ '~a:~d:0 ~a in ~a:~q/~d:'-[File, FilePos,Level,M,Na,Ar] ].
|
||||
|
||||
%message(loaded(Past,AbsoluteFileName,user,Msec,Bytes), Prefix, Suffix) :- !,
|
||||
main_message(error(Msg,Info), _, _) --> {var(Info)}, !,
|
||||
main_message(error(Msg,In), _, _) --> {var(In)}, !,
|
||||
[ ' error: uninstantiated message ~w~n.' - [Msg], nl ].
|
||||
main_message( error(syntax_error(Msg),info(between(L0,LM,LF),_Stream, _Pos, Term)), Level, LC ) -->
|
||||
!,
|
||||
@ -336,7 +393,7 @@ display_consulting( F, Level, LC) -->
|
||||
display_consulting(_F, _, _LC) -->
|
||||
[].
|
||||
|
||||
caller( error(_,Desc), _) -->
|
||||
caller( error(_,exception(Desc)), _) -->
|
||||
{
|
||||
'$query_exception'(errorGoal, Desc, Call),
|
||||
Call \= [],
|
||||
@ -352,7 +409,7 @@ caller( error(_,Desc), _) -->
|
||||
[nl],
|
||||
['~*|exception raised from ~a:~q:~d, ~a:~d:0: '-[10,M,Na,Ar,File, FilePos]],
|
||||
[nl].
|
||||
caller( error(_,Desc), _) -->
|
||||
caller( error(_,exception(Desc)), _) -->
|
||||
{
|
||||
'$query_exception'(prologPredFile, Desc, File),
|
||||
File \= [],
|
||||
@ -364,7 +421,7 @@ caller( error(_,Desc), _) -->
|
||||
!,
|
||||
['~*|exception raised from ~a:~q/~d, ~a:~d:0: '-[10,M,Na,Ar,File, FilePos]],
|
||||
[nl].
|
||||
caller( error(_,Desc), _) -->
|
||||
caller( error(_,exception(Desc)), _) -->
|
||||
{
|
||||
'$query_exception'(errorGoal, Desc, Call),
|
||||
Call \= [] },
|
||||
@ -374,8 +431,8 @@ caller( error(_,Desc), _) -->
|
||||
caller( _, _) -->
|
||||
[].
|
||||
|
||||
c_goal( error(_,Desc), Level ) -->
|
||||
{ '$query_exception'(errorFile, Desc, Func),
|
||||
c_goal( error(_,exception(Desc)), Level ) -->
|
||||
{ '$query_exception'(errorFile, Desc, File),
|
||||
Func \= [],
|
||||
'$query_exception'(errorFunction, Desc, File),
|
||||
'$query_exception'(errorLine, Desc, Line)
|
||||
@ -389,9 +446,9 @@ c_goal( _, _Level ) --> [].
|
||||
prolog_message(X) -->
|
||||
system_message(X).
|
||||
|
||||
system_message(error(Msg,Info)) -->
|
||||
( { var(Msg) } ; { var(Info)} ), !,
|
||||
['bad error ~w' - [error(Msg,Info)]].
|
||||
system_message(error(Msg,In)) -->
|
||||
( { var(Msg) } ; { var(In)} ), !,
|
||||
['bad error ~w' - [error(Msg,In)]].
|
||||
system_message(error(consistency_error(Who),Where)) -->
|
||||
[ 'CONSISTENCY ERROR (arguments not compatible with format)- ~w ~w' - [Who,Where] ].
|
||||
system_message(error(context_error(Goal,Who),Where)) -->
|
||||
|
125
pl/meta.yap
125
pl/meta.yap
@ -23,22 +23,20 @@ For example, the declaration for call/1 and setof/3 are:
|
||||
:- meta_predicate call(0), setof(?,0,?).
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
meta_predicate declaration
|
||||
implemented by asserting $meta_predicate(SourceModule,Functor,Arity,Declaration)
|
||||
The meta_predicate declaration is
|
||||
implemented by:
|
||||
|
||||
- asserting `$meta_predicate(SourceModule,Functor,Arity,Declaration)`
|
||||
- setting up a `MetaPredicate` flag in the internal predicate descriptor.
|
||||
*/
|
||||
|
||||
% directive now meta_predicate Ps :- $meta_predicate(Ps).
|
||||
|
||||
:- use_system_module( '$_arith', ['$c_built_in'/4]).
|
||||
|
||||
|
||||
:- dynamic prolog:'$meta_predicate'/4.
|
||||
|
||||
:- multifile prolog:'$meta_predicate'/4,
|
||||
'$inline'/2,
|
||||
'$full_clause_optimisation'/4.
|
||||
|
||||
meta_predicate(P) :-
|
||||
source_module(SM),
|
||||
'$meta_predicate'(P, SM).
|
||||
|
||||
'$meta_predicate'(P,M) :-
|
||||
var(P),
|
||||
@ -500,112 +498,3 @@ expand_goal(Input, Output) :-
|
||||
'$yap_strip_module'(SM:G, M, IG),
|
||||
'$expand_goals'(IG, _, GF0, M, SM, M, HVars-G),
|
||||
'$yap_strip_module'(M:GF0, MF, GF).
|
||||
|
||||
:- '$install_meta_predicate'((0,0),prolog,(','),2).
|
||||
|
||||
meta_predicate(P) :-
|
||||
source_module(SM),
|
||||
'$meta_predicate'(P, SM).
|
||||
|
||||
|
||||
|
||||
:- meta_predicate
|
||||
abolish(:),
|
||||
abolish(:,+),
|
||||
all(?,0,-),
|
||||
assert(:),
|
||||
assert(:,+),
|
||||
assert_static(:),
|
||||
asserta(:),
|
||||
asserta(:,+),
|
||||
asserta_static(:),
|
||||
assertz(:),
|
||||
assertz(:,+),
|
||||
assertz_static(:),
|
||||
at_halt(0),
|
||||
bagof(?,0,-),
|
||||
bb_get(:,-),
|
||||
bb_put(:,+),
|
||||
bb_delete(:,?),
|
||||
bb_update(:,?,?),
|
||||
call(0),
|
||||
call(1,?),
|
||||
call(2,?,?),
|
||||
call(3,?,?,?),
|
||||
call_with_args(0),
|
||||
call_with_args(1,?),
|
||||
call_with_args(2,?,?),
|
||||
call_with_args(3,?,?,?),
|
||||
call_with_args(4,?,?,?,?),
|
||||
call_with_args(5,?,?,?,?,?),
|
||||
call_with_args(6,?,?,?,?,?,?),
|
||||
call_with_args(7,?,?,?,?,?,?,?),
|
||||
call_with_args(8,?,?,?,?,?,?,?,?),
|
||||
call_with_args(9,?,?,?,?,?,?,?,?,?),
|
||||
call_cleanup(0,0),
|
||||
call_cleanup(0,?,0),
|
||||
call_residue(0,?),
|
||||
call_residue_vars(0,?),
|
||||
call_shared_object_function(:,+),
|
||||
catch(0,?,0),
|
||||
clause(:,?),
|
||||
clause(:,?,?),
|
||||
compile(:),
|
||||
consult(:),
|
||||
current_predicate(:),
|
||||
current_predicate(?,:),
|
||||
db_files(:),
|
||||
depth_bound_call(0,+),
|
||||
discontiguous(:),
|
||||
ensure_loaded(:),
|
||||
exo_files(:),
|
||||
findall(?,0,-),
|
||||
findall(?,0,-,?),
|
||||
forall(0,0),
|
||||
format(+,:),
|
||||
format(+,+,:),
|
||||
freeze(?,0),
|
||||
hide_predicate(:),
|
||||
if(0,0,0),
|
||||
ignore(0),
|
||||
incore(0),
|
||||
initializon(0),
|
||||
multifile(:),
|
||||
nospy(:),
|
||||
not(0),
|
||||
notrace(0),
|
||||
once(0),
|
||||
phrase(2,?),
|
||||
phrase(2,?,+),
|
||||
predicate_property(:,?),
|
||||
predicate_statistics(:,-,-,-),
|
||||
on_exception(+,0,0),
|
||||
qsave_program(+,:),
|
||||
reconsult(:),
|
||||
retract(:),
|
||||
retract(:,?),
|
||||
retractall(:),
|
||||
reconsult(:),
|
||||
setof(?,0,-),
|
||||
setup_call_cleanup(0,0,0),
|
||||
setup_call_catcher_cleanup(0,0,?,0),
|
||||
spy(:),
|
||||
stash_predicate(:),
|
||||
use_module(:),
|
||||
use_module(:,+),
|
||||
use_module(?,:,+),
|
||||
when(+,0),
|
||||
with_mutex(+,0),
|
||||
with_output_to(?,0),
|
||||
'->'(0 , 0),
|
||||
'*->'(0 , 0),
|
||||
';'(0 , 0),
|
||||
^(+,0),
|
||||
{}(0,?,?),
|
||||
','(2,2,?,?),
|
||||
';'(2,2,?,?),
|
||||
'|'(2,2,?,?),
|
||||
->(2,2,?,?),
|
||||
\+(2,?,?),
|
||||
\+( 0 )
|
||||
.
|
||||
|
101
pl/metadecls.yap
Normal file
101
pl/metadecls.yap
Normal file
@ -0,0 +1,101 @@
|
||||
|
||||
/**
|
||||
* @file metadecl.yap
|
||||
* @author VITOR SANTOS COSTA <vsc@vcosta-laptop.dcc.fc.up.pt>
|
||||
* @date Sat Apr 7 03:08:03 2018
|
||||
*
|
||||
* @brief meta=declarations to run early.
|
||||
*
|
||||
* @ingroup YAPMetaPredicates
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
:- '$system_meta_predicates'([
|
||||
abolish(:),
|
||||
abolish(:,+),
|
||||
all(?,0,-),
|
||||
assert(:),
|
||||
assert(:,+),
|
||||
assert_static(:),
|
||||
asserta(:),
|
||||
asserta(:,+),
|
||||
asserta_static(:),
|
||||
assertz(:),
|
||||
assertz(:,+),
|
||||
assertz_static(:),
|
||||
at_halt(0),
|
||||
bagof(?,0,-),
|
||||
bb_get(:,-),
|
||||
bb_put(:,+),
|
||||
bb_delete(:,?),
|
||||
bb_update(:,?,?),
|
||||
call(0),
|
||||
call(1,?),
|
||||
call(2,?,?),
|
||||
call(3,?,?,?),
|
||||
call_with_args(0),
|
||||
call_with_args(1,?),
|
||||
call_with_args(2,?,?),
|
||||
call_with_args(3,?,?,?),
|
||||
call_with_args(4,?,?,?,?),
|
||||
call_with_args(5,?,?,?,?,?),
|
||||
call_with_args(6,?,?,?,?,?,?),
|
||||
call_with_args(7,?,?,?,?,?,?,?),
|
||||
call_with_args(8,?,?,?,?,?,?,?,?),
|
||||
call_with_args(9,?,?,?,?,?,?,?,?,?),
|
||||
call_cleanup(0,0),
|
||||
call_cleanup(0,?,0),
|
||||
call_residue(0,?),
|
||||
call_residue_vars(0,?),
|
||||
call_shared_object_function(:,+),
|
||||
clause(:,?),
|
||||
clause(:,?,?),
|
||||
current_predicate(:),
|
||||
current_predicate(?,:),
|
||||
depth_bound_call(0,+),
|
||||
findall(?,0,-),
|
||||
findall(?,0,-,?),
|
||||
forall(0,0),
|
||||
format(+,:),
|
||||
format(+,+,:),
|
||||
freeze(?,0),
|
||||
hide_predicate(:),
|
||||
if(0,0,0),
|
||||
ignore(0),
|
||||
incore(0),
|
||||
initializon(0),
|
||||
nospy(:),
|
||||
not(0),
|
||||
notrace(0),
|
||||
once(0),
|
||||
phrase(2,?),
|
||||
phrase(2,?,+),
|
||||
predicate_property(:,?),
|
||||
predicate_statistics(:,-,-,-),
|
||||
on_exception(+,0,0),
|
||||
qsave_program(+,:),
|
||||
retract(:),
|
||||
retract(:,?),
|
||||
retractall(:),
|
||||
reconsult(:),
|
||||
setof(?,0,-),
|
||||
setup_call_cleanup(0,0,0),
|
||||
setup_call_catcher_cleanup(0,0,?,0),
|
||||
spy(:),
|
||||
stash_predicate(:),
|
||||
when(+,0),
|
||||
with_mutex(+,0),
|
||||
with_output_to(?,0),
|
||||
'->'(0 , 0),
|
||||
'*->'(0 , 0),
|
||||
';'(0 , 0),
|
||||
','(0 , 0),
|
||||
^(+,0),
|
||||
{}(0,?,?),
|
||||
','(2,2,?,?),
|
||||
';'(2,2,?,?),
|
||||
'|'(2,2,?,?),
|
||||
->(2,2,?,?),
|
||||
\+(2,?,?),
|
||||
\+( 0 )]).
|
@ -25,6 +25,15 @@
|
||||
|
||||
:- use_system_module( '$_errors', ['$do_error'/2]).
|
||||
|
||||
|
||||
:- '$system_meta_predicates'([
|
||||
discontiguous(:),
|
||||
multifile(:)
|
||||
]
|
||||
).
|
||||
|
||||
:- op(1150, fx, [multifile,discontiguous]).
|
||||
|
||||
'$log_upd'(1).
|
||||
|
||||
/**
|
||||
|
19
pl/top.yap
19
pl/top.yap
@ -1,3 +1,19 @@
|
||||
/**
|
||||
* @file top.yap
|
||||
* @author VITOR SANTOS COSTA <vsc@vcosta-laptop.dcc.fc.up.pt>
|
||||
* @date Sat Apr 7 03:14:17 2018
|
||||
*
|
||||
* @brief top-level implementation plus system booting.x
|
||||
*
|
||||
* @defgroup Top-Level and Boot Predicates
|
||||
* @ingroup YAPControl
|
||||
*
|
||||
*/
|
||||
|
||||
:- '$system_meta_predicates'([
|
||||
catch(0,?,0),
|
||||
log_event(+,:)]).
|
||||
|
||||
|
||||
live :- '$live'.
|
||||
|
||||
@ -985,9 +1001,6 @@ stopped, and the exception is sent to the ancestor goals until reaching
|
||||
a matching catch/3, or until reaching top-level.
|
||||
|
||||
*/
|
||||
throw(Ball) :-
|
||||
% get current jump point
|
||||
'$jump_env_and_store_ball'(Ball).
|
||||
|
||||
'$run_toplevel_hooks' :-
|
||||
current_prolog_flag(break_level, 0 ),
|
||||
|
Reference in New Issue
Block a user