keep on working on exs.

This commit is contained in:
Vitor Santos Costa 2018-04-07 19:45:18 +01:00
parent bc3555dfbf
commit 7ce963b63c
22 changed files with 1137 additions and 930 deletions

View File

@ -2099,7 +2099,7 @@ X_API void YAP_ClearExceptions(void) {
Yap_ResetException(worker_id); 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 CACHE_REGS
int sno; int sno;
BACKUP_MACHINE_REGS(); 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); fl = Yap_AbsoluteFile(fname, true);
if (!fl || !fl[0]) { if (!fl || !fl[0]) {
pop_text_stack(lvl); pop_text_stack(lvl);
*full = NULL;
return -1; return -1;
} }
} }
bool consulted = (mode == YAP_CONSULT_MODE); bool consulted = (mode == YAP_CONSULT_MODE);
sno = Yap_OpenStream(fl, "r", MkAtomTerm(Yap_LookupAtom(fl)), LOCAL_encoding); sno = Yap_OpenStream(fl, "r", MkAtomTerm(Yap_LookupAtom(fl)), LOCAL_encoding);
if (sno < 0) if (sno < 0 ||
return sno; !Yap_ChDir(dirname((char *)fl))) {
if (!Yap_ChDir(dirname((char *)fl))) return -1; pop_text_stack(lvl);
*full = NULL;
return -1;
}
LOCAL_PrologMode = UserMode;
Yap_init_consult(consulted, fl); Yap_init_consult(consulted, fl);
GLOBAL_Stream[sno].name = Yap_LookupAtom(fl); GLOBAL_Stream[sno].name = Yap_LookupAtom(fl);
GLOBAL_Stream[sno].user_name = MkAtomTerm(Yap_LookupAtom(fname)); GLOBAL_Stream[sno].user_name = MkAtomTerm(Yap_LookupAtom(fname));
GLOBAL_Stream[sno].encoding = LOCAL_encoding; GLOBAL_Stream[sno].encoding = LOCAL_encoding;
pop_text_stack(lvl); *full = pop_output_text_stack(lvl, fl);
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
UNLOCK(GLOBAL_Stream[sno].streamlock); UNLOCK(GLOBAL_Stream[sno].streamlock);
return sno; return sno;
@ -2285,8 +2291,6 @@ X_API bool YAP_CompileClause(Term t) {
} }
RECOVER_MACHINE_REGS(); RECOVER_MACHINE_REGS();
if (!ok) { if (!ok) {
t = Yap_GetException();
Yap_DebugPlWrite(t);
return NULL; return NULL;
} }
return ok; return ok;

View File

@ -2724,7 +2724,7 @@ static Int new_meta_pred(USES_REGS1) {
pe = new_pred(Deref(ARG1), Deref(ARG2), "meta_predicate"); pe = new_pred(Deref(ARG1), Deref(ARG2), "meta_predicate");
if (EndOfPAEntr(pe)) if (EndOfPAEntr(pe))
return FALSE; return false;
PELOCK(30, pe); PELOCK(30, pe);
arity = pe->ArityOfPE; arity = pe->ArityOfPE;
if (arity == 0) if (arity == 0)

View File

@ -33,6 +33,55 @@
#include "Foreign.h" #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) \ #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; } \
@ -43,7 +92,7 @@
#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 ? 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) { 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 );
@ -92,7 +141,7 @@ static void print_key_s(const char *key, const char *v)
fprintf(stderr,"%s: %s\n", key, v); fprintf(stderr,"%s: %s\n", key, v);
} }
static void printErr(yap_error_descriptor_t *i) { static void printErr(yap_error_descriptor_t *i) {
if (i->errorNo == YAP_NO_ERROR) { if (i->errorNo == YAP_NO_ERROR) {
return; return;
@ -156,7 +205,7 @@ static YAP_Term add_key_s(const char *key, const char *v, YAP_Term o0)
return MkPairTerm(node, o0); return MkPairTerm(node, o0);
} }
static Term err2list(yap_error_descriptor_t *i) { static Term err2list(yap_error_descriptor_t *i) {
Term o = TermNil; Term o = TermNil;
if (i->errorNo == YAP_NO_ERROR) { if (i->errorNo == YAP_NO_ERROR) {
return o; return o;
@ -227,7 +276,7 @@ bool Yap_Warning(const char *s, ...) {
if (pred->OpcodeOfPred == UNDEF_OPCODE || pred->OpcodeOfPred == FAIL_OPCODE) { if (pred->OpcodeOfPred == UNDEF_OPCODE || pred->OpcodeOfPred == FAIL_OPCODE) {
fprintf(stderr, "warning message: %s\n", tmpbuf); fprintf(stderr, "warning message: %s\n", tmpbuf);
LOCAL_DoingUndefp = false; LOCAL_DoingUndefp = false;
LOCAL_PrologMode &= ~InErrorMode; LOCAL_PrologMode &= ~InErrorMode;
Yap_popErrorContext(false); Yap_popErrorContext(false);
return false; return false;
} }
@ -396,7 +445,6 @@ int Yap_SWIHandleError(const char *s, ...) {
void Yap_RestartYap(int flag) { void Yap_RestartYap(int flag) {
CACHE_REGS CACHE_REGS
fprintf(stderr,"call siglongjmp HR=%p B=%p\n", HR, B);
#if PUSH_REGS #if PUSH_REGS
restore_absmi_regs(&Yap_standard_regs); restore_absmi_regs(&Yap_standard_regs);
#endif #endif
@ -785,16 +833,226 @@ yamop *Yap_Error__(bool throw, const char *file, const char *function, int linen
if (LOCAL_DoingUndefp) { if (LOCAL_DoingUndefp) {
LOCAL_Signals = 0; LOCAL_Signals = 0;
Yap_PrintWarning(Yap_GetException()); Yap_PrintWarning(MkErrorTerm(Yap_GetException()));
return P; return P;
} }
LOCAL_CommittedError = Yap_GetException();
//reset_error_description(); //reset_error_description();
// if (!throw) { if (!throw) {
Yap_JumpToEnv(); Yap_JumpToEnv();
// } }
LOCAL_PrologMode = UserMode;
return P; 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) { static Int is_boolean(USES_REGS1) {
Term t = Deref(ARG1); Term t = Deref(ARG1);
// Term Context = Deref(ARG2)Yap_Error(INSTANTIATION_ERROR, t, NULL);; // Term Context = Deref(ARG2)Yap_Error(INSTANTIATION_ERROR, t, NULL);;
@ -879,156 +1137,11 @@ static Int is_predicate_indicator(USES_REGS1) {
return false; 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) { void Yap_InitErrorPreds(void) {
CACHE_REGS CACHE_REGS
Yap_InitCPred("$reset_exception", 1, reset_exception, 0); 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("$get_exception", 1, get_exception, 0);
Yap_InitCPred("$drop_exception", 1, get_exception, 0);
Yap_InitCPred("$read_exception", 2, read_exception, 0); Yap_InitCPred("$read_exception", 2, read_exception, 0);
Yap_InitCPred("$query_exception", 3, query_exception, 0); Yap_InitCPred("$query_exception", 3, query_exception, 0);
Yap_InitCPred("$drop_exception", 1, drop_exception, 0); Yap_InitCPred("$drop_exception", 1, drop_exception, 0);

View File

@ -214,7 +214,7 @@ static Int save_env_b(USES_REGS1) {
static PredEntry *new_pred(Term t, Term tmod, char *pname) { static PredEntry *new_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;
@ -392,7 +392,7 @@ inline static bool do_execute_n(Term t, Term mod, unsigned int n USES_REGS) {
int j = -n; int j = -n;
Term t0 = t, mod0 = mod; Term t0 = t, mod0 = mod;
restart_exec: restart_exec:
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
return CallError(INSTANTIATION_ERROR, t0, mod0 PASS_REGS); return CallError(INSTANTIATION_ERROR, t0, mod0 PASS_REGS);
} else if (IsAtomTerm(t)) { } else if (IsAtomTerm(t)) {
@ -649,7 +649,7 @@ static Int execute_clause(USES_REGS1) { /* '$execute_clause'(Goal) */
yamop *code; yamop *code;
Term clt = Deref(ARG3); Term clt = Deref(ARG3);
restart_exec: restart_exec:
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, ARG3, "call/1"); Yap_Error(INSTANTIATION_ERROR, ARG3, "call/1");
return FALSE; return FALSE;
@ -817,8 +817,8 @@ static bool watch_cut(Term ext USES_REGS) {
} }
CELL *port_pt = deref_ptr(RepAppl(task) + 2); CELL *port_pt = deref_ptr(RepAppl(task) + 2);
CELL *completion_pt = deref_ptr(RepAppl(task) + 4); CELL *completion_pt = deref_ptr(RepAppl(task) + 4);
if ((ex_mode = Yap_HasException())) { if (LOCAL_CommittedError) {
e = Yap_GetException(); e = MkErrorTerm(LOCAL_CommittedError);
Term t; Term t;
if (active) { if (active) {
t = Yap_MkApplTerm(FunctorException, 1, &e); t = Yap_MkApplTerm(FunctorException, 1, &e);
@ -873,8 +873,9 @@ static bool watch_retry(Term d0 USES_REGS) {
// just do the frrpest // just do the frrpest
if (B >= B0 && !ex_mode && !active) if (B >= B0 && !ex_mode && !active)
return true; return true;
if ((ex_mode = Yap_HasException())) { if (LOCAL_CommittedError &&
e = Yap_GetException(); LOCAL_CommittedError->errorNo != YAP_NO_ERROR) {
e = MkErrorTerm(LOCAL_CommittedError);
if (active) { if (active) {
t = Yap_MkApplTerm(FunctorException, 1, &e); t = Yap_MkApplTerm(FunctorException, 1, &e);
} else { } else {
@ -1091,7 +1092,7 @@ static Int execute0(USES_REGS1) { /* '$execute0'(Goal,Mod) */
return EnterCreepMode(t, mod PASS_REGS); return EnterCreepMode(t, mod PASS_REGS);
} }
t = Yap_YapStripModule(t, &mod); t = Yap_YapStripModule(t, &mod);
restart_exec: restart_exec:
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
Yap_Error(INSTANTIATION_ERROR, ARG3, "call/1"); Yap_Error(INSTANTIATION_ERROR, ARG3, "call/1");
return false; return false;
@ -1390,7 +1391,6 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
sigjmp_buf signew, *sighold = LOCAL_RestartEnv; sigjmp_buf signew, *sighold = LOCAL_RestartEnv;
LOCAL_RestartEnv = &signew; LOCAL_RestartEnv = &signew;
REGSTORE *old_rs = Yap_regp;
if (top && (lval = sigsetjmp(signew, 1)) != 0) { if (top && (lval = sigsetjmp(signew, 1)) != 0) {
switch (lval) { 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 // going up, unless there is no up to go to. or someone
// but we should inform the caller on what happened. // but we should inform the caller on what happened.
Yap_regp = old_rs; // Yap_regp = old_rs;
restore_TR(); restore_TR();
restore_B(); restore_B();
/* H is not so important, because we're gonna backtrack */ /* H is not so important, because we're gonna backtrack */
restore_H(); restore_H();
/* set stack */ /* set stack */
Yap_JumpToEnv();
ASP = (CELL *) PROTECT_FROZEN_B(B); ASP = (CELL *) PROTECT_FROZEN_B(B);
if (B == NULL || B->cp_b == NULL || (CELL*)(B->cp_b) > LCL0 - LOCAL_CBorder) { if (B == NULL || B->cp_b == NULL || (CELL*)(B->cp_b) > LCL0 - LOCAL_CBorder) {
@ -1468,7 +1469,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
} }
YENV = ASP; YENV = ASP;
YENV[E_CB] = Unsigned(B); YENV[E_CB] = Unsigned(B);
out = Yap_absmi(0); out = Yap_absmi(0);
/* make sure we don't leave a FAIL signal hanging around */ /* make sure we don't leave a FAIL signal hanging around */
Yap_get_signal(YAP_FAIL_SIGNAL); Yap_get_signal(YAP_FAIL_SIGNAL);
if (!Yap_has_a_signal()) if (!Yap_has_a_signal())
@ -1572,7 +1573,7 @@ void Yap_fail_all(choiceptr bb USES_REGS) {
DEPTH = B->cp_depth; DEPTH = B->cp_depth;
#endif /* DEPTH_LIMIT */ #endif /* DEPTH_LIMIT */
YENV = ENV = B->cp_env; YENV = ENV = B->cp_env;
/* recover local stack */ /* recover local stack */
#ifdef DEPTH_LIMIT #ifdef DEPTH_LIMIT
DEPTH = ENV[E_DEPTH]; DEPTH = ENV[E_DEPTH];
#endif #endif
@ -2017,7 +2018,7 @@ bool is_cleanup_cp(choiceptr cp_b) {
return pe == PredSafeCallCleanup; return pe == PredSafeCallCleanup;
} }
static Int JumpToEnv(USES_REGS1) { static Int JumpToEnv(USES_REGS1) {
choiceptr handler = B; choiceptr handler = B;
/* just keep the throwm object away, we don't need to care about it /* just keep the throwm object away, we don't need to care about it
*/ */
@ -2027,7 +2028,8 @@ bool is_cleanup_cp(choiceptr cp_b) {
// DBTerm *dbt = Yap_RefToException(); // DBTerm *dbt = Yap_RefToException();
while (handler while (handler
&& Yap_PredForChoicePt(handler, NULL) != PredDollarCatch && 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 && handler->cp_b != NULL
) { ) {
//if (handler->cp_ap != NOCODE) //if (handler->cp_ap != NOCODE)
@ -2039,7 +2041,7 @@ bool is_cleanup_cp(choiceptr cp_b) {
Yap_signal(YAP_FAIL_SIGNAL); Yap_signal(YAP_FAIL_SIGNAL);
} }
//B = handler; B = handler;
P = FAILCODE; P = FAILCODE;
return true; return true;
} }
@ -2053,46 +2055,40 @@ 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); Term t = Deref(ARG1), t0 = t, t1;
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
Term t2; && (t1 = ArgOfTerm(1, t))
Yap_prolog_add_culprit(LOCAL_ActiveError PASS_REGS); && IsPairTerm((t = ArgOfTerm(2, t)))
// LOCAL_Error_TYPE = ERROR_EVENT; && IsApplTerm((t = HeadOfTerm(t)))) {
Term t1 = ArgOfTerm(1, t); LOCAL_ActiveError = Yap_UserError(t, t1, LOCAL_ActiveError);
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 { } else {
Yap_prolog_add_culprit(LOCAL_ActiveError PASS_REGS); LOCAL_Error_TYPE = THROW_EVENT;
LOCAL_ActiveError->errorAsText = NULL; LOCAL_ActiveError->errorAsText = NULL;
LOCAL_ActiveError->errorRawTerm = Yap_SaveTerm(t);
LOCAL_ActiveError->classAsText = NULL; LOCAL_ActiveError->classAsText = NULL;
//return true; //return true;
} }
LOCAL_ActiveError->prologPredName = NULL;
bool out = JumpToEnv(PASS_REGS1); bool out = JumpToEnv(PASS_REGS1);
if (B != NULL && P == FAILCODE && B->cp_ap == NOCODE && if (B != NULL && P == FAILCODE && B->cp_ap == NOCODE &&
LCL0 - (CELL *)B > LOCAL_CBorder) { LCL0 - (CELL *)B > LOCAL_CBorder) {
// we're failing up to the top layer // we're failing up to the top layer
} }
LOCAL_CommittedError = Yap_GetException();
return out; return out;
} }
/* set up a meta-call based on . context info */ /* set up a meta-call based on . context info */
static Int generate_pred_info(USES_REGS1) { static Int generate_pred_info(USES_REGS1) {
ARG1 = ARG3 = ENV[-EnvSizeInCells - 1]; ARG1 = ARG3 = ENV[-EnvSizeInCells - 1];
ARG4 = ENV[-EnvSizeInCells - 3]; ARG4 = ENV[-EnvSizeInCells - 3];
ARG2 = cp_as_integer((choiceptr)ENV[E_CB] PASS_REGS); ARG2 = cp_as_integer((choiceptr)ENV[E_CB] PASS_REGS);
return TRUE; return TRUE;
} }
void Yap_InitYaamRegs(int myworker_id, bool full_reset) { void Yap_InitYaamRegs(int myworker_id, bool full_reset) {
Term h0var; Term h0var;
// getchar(); // getchar();
#if PUSH_REGS #if PUSH_REGS
@ -2110,7 +2106,7 @@ static Int jump_env(USES_REGS1) {
#endif #endif
#endif /* PUSH_REGS */ #endif /* PUSH_REGS */
CACHE_REGS CACHE_REGS
Yap_ResetException(worker_id); Yap_ResetException(LOCAL_ActiveError);
Yap_PutValue(AtomBreak, MkIntTerm(0)); Yap_PutValue(AtomBreak, MkIntTerm(0));
TR = (tr_fr_ptr)REMOTE_TrailBase(myworker_id); TR = (tr_fr_ptr)REMOTE_TrailBase(myworker_id);
HR = H0 = ((CELL *) REMOTE_GlobalBase(myworker_id)) + HR = H0 = ((CELL *) REMOTE_GlobalBase(myworker_id)) +
@ -2179,9 +2175,9 @@ static Int jump_env(USES_REGS1) {
if (REMOTE_top_dep_fr(myworker_id)) if (REMOTE_top_dep_fr(myworker_id))
DepFr_cons_cp(REMOTE_top_dep_fr(myworker_id)) = NORM_CP(B); DepFr_cons_cp(REMOTE_top_dep_fr(myworker_id)) = NORM_CP(B);
#endif #endif
} }
int Yap_dogc(int extra_args, Term *tp USES_REGS) { int Yap_dogc(int extra_args, Term *tp USES_REGS) {
UInt arity; UInt arity;
yamop *nextpc; yamop *nextpc;
int i; int i;
@ -2203,9 +2199,9 @@ static Int jump_env(USES_REGS1) {
tp[i] = XREGS[arity + i + 1]; tp[i] = XREGS[arity + i + 1];
} }
return TRUE; return TRUE;
} }
void Yap_InitExecFs(void) { void Yap_InitExecFs(void) {
CACHE_REGS CACHE_REGS
YAP_opaque_handler_t catcher_ops; YAP_opaque_handler_t catcher_ops;
memset(&catcher_ops, 0, sizeof(catcher_ops)); memset(&catcher_ops, 0, sizeof(catcher_ops));
@ -2263,7 +2259,7 @@ static Int jump_env(USES_REGS1) {
Yap_InitCPred("$clean_ifcp", 1, clean_ifcp, SafePredFlag); Yap_InitCPred("$clean_ifcp", 1, clean_ifcp, SafePredFlag);
Yap_InitCPred("qpack_clean_up_to_disjunction", 0, cut_up_to_next_disjunction, Yap_InitCPred("qpack_clean_up_to_disjunction", 0, cut_up_to_next_disjunction,
SafePredFlag); 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("$generate_pred_info", 4, generate_pred_info, 0);
Yap_InitCPred("_user_expand_goal", 2, _user_expand_goal, 0); Yap_InitCPred("_user_expand_goal", 2, _user_expand_goal, 0);
Yap_InitCPred("$do_term_expansion", 2, do_term_expansion, 0); Yap_InitCPred("$do_term_expansion", 2, do_term_expansion, 0);
@ -2271,4 +2267,4 @@ static Int jump_env(USES_REGS1) {
0); 0);
Yap_InitCPred("$cleanup_on_exit", 2, cleanup_on_exit, 0); Yap_InitCPred("$cleanup_on_exit", 2, cleanup_on_exit, 0);
Yap_InitCPred("$tag_cleanup", 2, tag_cleanup, 0); Yap_InitCPred("$tag_cleanup", 2, tag_cleanup, 0);
} }

View File

@ -159,15 +159,14 @@ static void consult(const char *b_file USES_REGS) {
Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1); Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1);
Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1); Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1);
Functor functor_compile2 = Yap_MkFunctor(Yap_LookupAtom("c_compile"), 1); Functor functor_compile2 = Yap_MkFunctor(Yap_LookupAtom("c_compile"), 1);
char *full;
/* consult in C */ /* consult in C */
int lvl = push_text_stack(); int lvl = push_text_stack();
char *full = Malloc(YAP_FILENAME_MAX + 1);
full[0] = '\0';
/* the consult mode does not matter here, really */ /* the consult mode does not matter here, really */
if ((osno = Yap_CheckAlias(AtomLoopStream)) < 0) if ((osno = Yap_CheckAlias(AtomLoopStream)) < 0)
osno = 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) { if (c_stream < 0) {
fprintf(stderr, "[ FATAL ERROR: could not open file %s ]\n", b_file); fprintf(stderr, "[ FATAL ERROR: could not open file %s ]\n", b_file);
pop_text_stack(lvl); pop_text_stack(lvl);

View File

@ -433,11 +433,10 @@ bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) {
// allow Prolog style exceotion handling // allow Prolog style exceotion handling
// don't forget, on success these bindings will still be there); // don't forget, on success these bindings will still be there);
result = YAP_LeaveGoal(false, &q); result = YAP_LeaveGoal(false, &q);
Term terr;
if ((terr = Yap_GetException()) != 0) { if (LOCAL_CommittedError != nullptr) {
std::cerr << "Exception received by " << __func__ << "( " 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); // Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);
// throw YAPError(); // throw YAPError();
} }
@ -481,12 +480,9 @@ bool YAPEngine::mgoal(Term t, Term tmod) {
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec "); __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
result = (bool)YAP_EnterGoal(ap, nullptr, &q); result = (bool)YAP_EnterGoal(ap, nullptr, &q);
Term terr; if (LOCAL_CommittedError != nullptr) {
if ((terr = Yap_GetException()) != 0) {
std::cerr << "Exception received by " << __func__ << "( " 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();
} }
{ {
@ -547,13 +543,12 @@ Term YAPEngine::fun(Term t) {
q.cp = CP; q.cp = CP;
// make sure this is safe // make sure this is safe
// allow Prolog style exception handling // allow Prolog style exception handling
Term terr;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec "); __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
bool result = (bool)YAP_EnterGoal(ap, nullptr, &q); bool result = (bool)YAP_EnterGoal(ap, nullptr, &q);
if ((terr = Yap_GetException()) != 0) { if (LOCAL_CommittedError != nullptr) {
std::cerr << "Exception received by " << __func__ << "( " 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); // Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);
// throw YAPError(); // throw YAPError();
} }
@ -673,16 +668,12 @@ bool YAPQuery::next() {
YAP_LeaveGoal(false, &q_h); YAP_LeaveGoal(false, &q_h);
Yap_CloseHandles(q_handles); Yap_CloseHandles(q_handles);
q_open = false; q_open = false;
if (Yap_HasException()) { if (LOCAL_CommittedError != nullptr) {
terr = Yap_GetException(); // Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);
yap_error_descriptor_t *tp = LOCAL_ActiveError->top_error; // throw YAPError();
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";
Term es[2]; Term es[2];
es[0] = TermError; es[0] = TermError;
es[1] = terr; es[1] = MkErrorTerm(LOCAL_CommittedError);
Functor f = Yap_MkFunctor(Yap_LookupAtom("print_message"), 2); Functor f = Yap_MkFunctor(Yap_LookupAtom("print_message"), 2);
YAP_RunGoalOnce(Yap_MkApplTerm(f, 2, es)); YAP_RunGoalOnce(Yap_MkApplTerm(f, 2, es));
// Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm); // Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);

View File

@ -42,6 +42,14 @@ extern "C" {
#include <stddef.h> #include <stddef.h>
#if YAP_PYTHON
#include <Python.h>
extern bool python_in_python;
#endif
#include "Yap.h" #include "Yap.h"
#include "Yatom.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); 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
} }

View File

@ -40,6 +40,11 @@ public:
if (ID != YAP_NO_ERROR) {}; if (ID != YAP_NO_ERROR) {};
std::cerr << "Error detected" << ID << "\n"; 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 /// error handler object with initial data when receiving the error term
YAPError(yap_error_number id, YAPTerm culprit, std::string txt); YAPError(yap_error_number id, YAPTerm culprit, std::string txt);

View File

@ -1601,14 +1601,22 @@ INLINE_ONLY inline EXTERN const char *AtomTermName(Term t) {
return RepAtom(AtomOfTerm(t))->rep.uStrOfAE; 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 bool Yap_HasException(void);
extern Term Yap_GetException(void); extern yap_error_descriptor_t * Yap_GetException(void);
extern void Yap_PrintException(void); extern void Yap_PrintException(void);
INLINE_ONLY inline EXTERN bool Yap_HasException(void) { INLINE_ONLY inline EXTERN bool Yap_HasException(void) {
return LOCAL_ActiveError->errorNo != YAP_NO_ERROR; 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); extern bool Yap_RaiseException(void);
#endif #endif

View File

@ -195,6 +195,7 @@ LOCAL(ADDR, TrailTop);
/* error handling info, designed to be easy to pass to the foreign world */ /* 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 *, 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 /// pointer to an exception term, from throw
LOCAL(jmp_buf, IOBotch); LOCAL(jmp_buf, IOBotch);

View File

@ -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(PRED_ENTRY_COUNTER_UNDERFLOW_EVENT, EVENT, "pred_entry_counter_underflow")
E(RETRY_COUNTER_UNDERFLOW_EVENT, EVENT, "retry_counter_underflow") E(RETRY_COUNTER_UNDERFLOW_EVENT, EVENT, "retry_counter_underflow")
E(INTERRUPT_EVENT, EVENT, "interrupt") E(INTERRUPT_EVENT, EVENT, "interrupt")
E(USER_EVENT, EVENT, "user event")
E(TYPE_ERROR_ARRAY, TYPE_ERROR, "array") E(TYPE_ERROR_ARRAY, TYPE_ERROR, "array")
E(TYPE_ERROR_ATOM, TYPE_ERROR, "atom") E(TYPE_ERROR_ATOM, TYPE_ERROR, "atom")

View File

@ -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 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); int *previous_sno);
extern X_API void YAP_EndConsult(int s, int *previous_sno, const char *previous_cwd); extern X_API void YAP_EndConsult(int s, int *previous_sno, const char *previous_cwd);

View File

@ -33,6 +33,7 @@ set(PL_BOOT_SOURCES
load_foreign.yap load_foreign.yap
messages.yap messages.yap
meta.yap meta.yap
metadecls.yap
modules.yap modules.yap
newmod.yap newmod.yap
os.yap os.yap

View File

@ -119,8 +119,6 @@ print_message(L,E) :-
format( user_error, '~w in bootstrap: got ~w~n',[L,E]) format( user_error, '~w in bootstrap: got ~w~n',[L,E])
). ).
'$undefp0'([M|G], _Action) :- '$undefp0'([M|G], _Action) :-
stream_property( loop_stream, file_name(F)), stream_property( loop_stream, file_name(F)),
stream_property( loop_stream, line_number(L)), stream_property( loop_stream, line_number(L)),
@ -129,6 +127,25 @@ print_message(L,E) :-
:- '$undefp_handler'('$undefp0'(_,_),prolog). :- '$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 % These are pseudo declarations
% so that the user will get a redefining system predicate % so that the user will get a redefining system predicate
% just create a choice-point % just create a choice-point
% the 6th argument marks the time-stamp. % the 6th argument marks the time-stamp.
'$do_log_upd_clause'(_,_,_,_,_,_). '$do_log_upd_clause'(_,_,_,_,_,_).
@ -232,8 +248,9 @@ print_message(L,E) :-
:- c_compile('bootlists.yap'). :- c_compile('bootlists.yap').
:- c_compile('consult.yap'). :- c_compile('consult.yap').
:- c_compile('preddecls.yap'). :- c_compile('preddecls.yap').
:- c_compile('preddyns.yap').
:- c_compile('meta.yap'). :- c_compile('meta.yap').
:- c_compile('metadecls.yap').
:- c_compile('preddyns.yap').
:- c_compile('builtins.yap'). :- c_compile('builtins.yap').
:- c_compile('newmod.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'). :- ensure_loaded('../pl/pathconf.yap').
:- yap_flag(user:unknown,error). :- yap_flag(user:unknown,error).

View File

@ -72,7 +72,6 @@ The style_check/1 built-in is now deprecated. Please use
% %
% A Small style checker for YAP % A Small style checker for YAP
:- op(1150, fx, [multifile,discontiguous]).
style_check(V) :- var(V), !, fail. style_check(V) :- var(V), !, fail.
style_check(V) :- style_check(V) :-

View File

@ -1,4 +1,4 @@
s444444444444444444444444444444444444444444444444444444444444444444444444/************************************************************************* /*************************************************************************
* * * *
* YAP Prolog * * YAP Prolog *
* * * *
@ -74,6 +74,20 @@ s444444444444444444444444444444444444444444444444444444444444444444444444/******
:- use_system_module( '$_preds', ['$current_predicate'/4]). :- 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 @defgroup YAPConsulting Loading files into YAP

View File

@ -63,12 +63,7 @@ system_error(Type,Goal) :-
'$do_error'(Type,Goal) :- '$do_error'(Type,Goal) :-
% format('~w~n', [Type]), throw(error(Type, [error(Goal)])).
ancestor_location(Call, Caller),
throw(error(Type, [
[g|g(Goal)],
[p|Call],
[e|Caller]])).
/** /**
* @pred system_error( +Error, +Cause, +Culprit) * @pred system_error( +Error, +Cause, +Culprit)
@ -82,13 +77,8 @@ system_error(Type,Goal) :-
* *
*/ */
system_error(Type,Goal,Culprit) :- system_error(Type,Goal,Culprit) :-
% format('~w~n', [Type]), ancestor_location(Goal, Culprit),
ancestor_location(Call, Caller), throw(error(Type, [error(Goal, Culprit)])).
throw(error(Type, [
[i|Culprit],
[g|g(Goal)],
[p|Call],
[e|Caller]])).
'$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).

View File

@ -68,7 +68,7 @@ handling in YAP:
An error record comsists of An ISO compatible descriptor of the format 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: 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) --> !, 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,_), _), _) -->
!,
[ 'UNEXPECTED SIGNAL: ~a' - [SIG] ].
compose_message(trace_command(C), _Leve) --> compose_message(trace_command(C), _Leve) -->
!, !,
[ '~a is not a valid debugger command.' - [C] ]. [ '~a is not a valid debugger command.' - [C] ].
@ -227,20 +230,74 @@ compose_message(myddas_version(Version), _Leve) -->
[ 'MYDDAS version ~a' - [Version] ]. [ 'MYDDAS version ~a' - [Version] ].
compose_message(yes, _Level) --> !, compose_message(yes, _Level) --> !,
[ 'yes'- [] ]. [ 'yes'- [] ].
compose_message(Term, Level) --> compose_message(error(E, exception(Exc)), Level) -->
{ '$show_consult_level'(LC) }, { '$show_consult_level'(LC) },
location( Term, Level, LC), location( Exc, Level, LC),
main_message( Term, Level, LC ), main_message( Exc, Level, LC ),
c_goal( Term, Level ), c_goal( Exc, Level ),
caller( Term, Level ), caller( Exc, Level ),
extra_info( Term, Level ), extra_info( Exc, Level ),
!, !,
[nl,nl]. [nl,nl].
compose_message(Term, Level) --> compose_message(error(E,[I|Is]), Level) -->
{ Level == error -> true ; Level == warning }, { Level == error -> true ; Level == warning },
{ '$show_consult_level'(LC) }, { '$show_consult_level'(LC),
main_message( Term, Level, LC), translate_info([I|Is], In))
},
compose_message( e(Err, In), Level),
[nl,nl]. [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)), _ , _) --> 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,_ ) ),_), _ , _) --> location(error(style_check(style_check(_,LN,FileName,_ ) ),_), _ , _) -->
!, !,
[ '~a:~d:0 ' - [FileName,LN] ] . [ '~a:~d:0 ' - [FileName,LN] ] .
location( error(_,Desc), Level, LC ) --> location( error(_,exception(Desc)), Level, LC ) -->
{ source_location(F0, L), { source_location(F0, L),
stream_property(_Stream, alias(loop_stream)), stream_property(_Stream, alias(loop_stream)),
!, !,
'$query_exception'(prologPredModule, Desc, M), '$query_exception'(prologPredModule, Desc, M),
'$query_exception'(prologPredName, Desc, Na), '$query_exception'(prologPredName, Desc, Na),
'$query_exception'(prologPredArity, Desc, Ar), '$query_exception'(prologPredArity, Desc, Ar)
display_consulting( F0, Level, LC )
}, },
display_consulting( F0, Level, LC ),
[ '~a:~d:0 ~a in ~a:~q/~d:'-[F0, L,Level,M,Na,Ar] ]. [ '~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), { '$query_exception'(prologPredFile, Desc, File),
display_consulting( File, Level, LC ),
'$query_exception'(prologPredLine, Desc, FilePos), '$query_exception'(prologPredLine, Desc, FilePos),
'$query_exception'(prologPredModule, Desc, M), '$query_exception'(prologPredModule, Desc, M),
'$query_exception'(prologPredName, Desc, Na), '$query_exception'(prologPredName, Desc, Na),
'$query_exception'(prologPredArity, Desc, Ar) '$query_exception'(prologPredArity, Desc, Ar)
}, },
display_consulting( File, Level, LC ),
[ '~a:~d:0 ~a in ~a:~q/~d:'-[File, FilePos,Level,M,Na,Ar] ]. [ '~a:~d:0 ~a in ~a:~q/~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,Info), _, _) --> {var(Info)}, !, 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 ) -->
!, !,
@ -336,7 +393,7 @@ display_consulting( F, Level, LC) -->
display_consulting(_F, _, _LC) --> display_consulting(_F, _, _LC) -->
[]. [].
caller( error(_,Desc), _) --> caller( error(_,exception(Desc)), _) -->
{ {
'$query_exception'(errorGoal, Desc, Call), '$query_exception'(errorGoal, Desc, Call),
Call \= [], Call \= [],
@ -352,7 +409,7 @@ caller( error(_,Desc), _) -->
[nl], [nl],
['~*|exception raised from ~a:~q:~d, ~a:~d:0: '-[10,M,Na,Ar,File, FilePos]], ['~*|exception raised from ~a:~q:~d, ~a:~d:0: '-[10,M,Na,Ar,File, FilePos]],
[nl]. [nl].
caller( error(_,Desc), _) --> caller( error(_,exception(Desc)), _) -->
{ {
'$query_exception'(prologPredFile, Desc, File), '$query_exception'(prologPredFile, Desc, File),
File \= [], File \= [],
@ -364,7 +421,7 @@ caller( error(_,Desc), _) -->
!, !,
['~*|exception raised from ~a:~q/~d, ~a:~d:0: '-[10,M,Na,Ar,File, FilePos]], ['~*|exception raised from ~a:~q/~d, ~a:~d:0: '-[10,M,Na,Ar,File, FilePos]],
[nl]. [nl].
caller( error(_,Desc), _) --> caller( error(_,exception(Desc)), _) -->
{ {
'$query_exception'(errorGoal, Desc, Call), '$query_exception'(errorGoal, Desc, Call),
Call \= [] }, Call \= [] },
@ -374,8 +431,8 @@ caller( error(_,Desc), _) -->
caller( _, _) --> caller( _, _) -->
[]. [].
c_goal( error(_,Desc), Level ) --> c_goal( error(_,exception(Desc)), Level ) -->
{ '$query_exception'(errorFile, Desc, Func), { '$query_exception'(errorFile, Desc, File),
Func \= [], Func \= [],
'$query_exception'(errorFunction, Desc, File), '$query_exception'(errorFunction, Desc, File),
'$query_exception'(errorLine, Desc, Line) '$query_exception'(errorLine, Desc, Line)
@ -389,9 +446,9 @@ c_goal( _, _Level ) --> [].
prolog_message(X) --> prolog_message(X) -->
system_message(X). system_message(X).
system_message(error(Msg,Info)) --> system_message(error(Msg,In)) -->
( { var(Msg) } ; { var(Info)} ), !, ( { var(Msg) } ; { var(In)} ), !,
['bad error ~w' - [error(Msg,Info)]]. ['bad error ~w' - [error(Msg,In)]].
system_message(error(consistency_error(Who),Where)) --> system_message(error(consistency_error(Who),Where)) -->
[ 'CONSISTENCY ERROR (arguments not compatible with format)- ~w ~w' - [Who,Where] ]. [ 'CONSISTENCY ERROR (arguments not compatible with format)- ~w ~w' - [Who,Where] ].
system_message(error(context_error(Goal,Who),Where)) --> system_message(error(context_error(Goal,Who),Where)) -->

View File

@ -23,22 +23,20 @@ For example, the declaration for call/1 and setof/3 are:
:- meta_predicate call(0), setof(?,0,?). :- meta_predicate call(0), setof(?,0,?).
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
meta_predicate declaration The meta_predicate declaration is
implemented by asserting $meta_predicate(SourceModule,Functor,Arity,Declaration) 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). % directive now meta_predicate Ps :- $meta_predicate(Ps).
:- use_system_module( '$_arith', ['$c_built_in'/4]). :- use_system_module( '$_arith', ['$c_built_in'/4]).
meta_predicate(P) :-
:- dynamic prolog:'$meta_predicate'/4. source_module(SM),
'$meta_predicate'(P, SM).
:- multifile prolog:'$meta_predicate'/4,
'$inline'/2,
'$full_clause_optimisation'/4.
'$meta_predicate'(P,M) :- '$meta_predicate'(P,M) :-
var(P), var(P),
@ -220,8 +218,8 @@ meta_predicate declaration
% %
% %
% head variab'$expand_goals'(M:G,G1,GO,HM,SM,,_M,HVars)les. % head variab'$expand_goals'(M:G,G1,GO,HM,SM,,_M,HVars)les.
% goals or arguments/sub-arguments? % goals or arguments/sub-arguments?
% I cannot use call here because of format/3 % I cannot use call here because of format/3
% modules: % modules:
% A4: module for body of clause (this is the one used in looking up predicates) % A4: module for body of clause (this is the one used in looking up predicates)
% A5: context module (this is the current context % A5: context module (this is the current context
@ -500,112 +498,3 @@ expand_goal(Input, Output) :-
'$yap_strip_module'(SM:G, M, IG), '$yap_strip_module'(SM:G, M, IG),
'$expand_goals'(IG, _, GF0, M, SM, M, HVars-G), '$expand_goals'(IG, _, GF0, M, SM, M, HVars-G),
'$yap_strip_module'(M:GF0, MF, GF). '$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
View 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 )]).

View File

@ -25,6 +25,15 @@
:- use_system_module( '$_errors', ['$do_error'/2]). :- use_system_module( '$_errors', ['$do_error'/2]).
:- '$system_meta_predicates'([
discontiguous(:),
multifile(:)
]
).
:- op(1150, fx, [multifile,discontiguous]).
'$log_upd'(1). '$log_upd'(1).
/** /**

View File

@ -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'. live :- '$live'.
@ -64,8 +80,8 @@ live :- '$live'.
% stop at spy-points if debugging is on. % stop at spy-points if debugging is on.
nb_setval('$debug_run',off), nb_setval('$debug_run',off),
nb_setval('$debug_jump',off), nb_setval('$debug_jump',off),
'$command'(Command,Varnames,Pos,top), '$command'(Command,Varnames,Pos,top),
current_prolog_flag(break_level, BreakLevel), current_prolog_flag(break_level, BreakLevel),
( (
BreakLevel \= 0 BreakLevel \= 0
-> ->
@ -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. a matching catch/3, or until reaching top-level.
*/ */
throw(Ball) :-
% get current jump point
'$jump_env_and_store_ball'(Ball).
'$run_toplevel_hooks' :- '$run_toplevel_hooks' :-
current_prolog_flag(break_level, 0 ), current_prolog_flag(break_level, 0 ),