less invasive error handling

This commit is contained in:
Vitor Santos Costa 2016-10-19 22:44:59 -05:00
parent 8a6de8b157
commit d082af605d
44 changed files with 4258 additions and 5045 deletions

View File

@ -8160,12 +8160,7 @@
saveregs(); saveregs();
d0 = p_plus(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); d0 = p_plus(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS);
setregs(); setregs();
if (d0 == 0L) {
saveregs();
Yap_PreProcessedError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
setregs();
FAIL();
}
} }
XREG(PREG->y_u.xxx.x) = d0; XREG(PREG->y_u.xxx.x) = d0;
PREG = NEXTOP(PREG, xxx); PREG = NEXTOP(PREG, xxx);

View File

@ -527,18 +527,23 @@ static Int number_chars(USES_REGS1) {
restart_aux: restart_aux:
t1 = Deref(ARG1); t1 = Deref(ARG1);
if (IsNumTerm(t1)) { if (IsNumTerm(t1)) {
Term tf; Term t2 = Deref(ARG2);
tf = Yap_NumberToListOfAtoms(t1 PASS_REGS); if (IsVarTerm(t2)) {
if (tf) { t1 = Yap_NumberToListOfAtoms(t1 PASS_REGS);
LOCAL_Error_TYPE = YAP_NO_ERROR; }
return Yap_unify(ARG2, tf); if (t1) {
return Yap_unify(t1, t2);
} else {
t2 = Yap_ListToNumber(t2 PASS_REGS);
if (t2) {
return Yap_unify(t1, t2);
}
} }
} else if (IsVarTerm(t1)) { } else if (IsVarTerm(t1)) {
/* ARG1 unbound */ /* ARG1 unbound */
Term t = Deref(ARG2); Term t = Deref(ARG2);
Term tf = Yap_ListToNumber(t PASS_REGS); Term tf = Yap_ListToNumber(t PASS_REGS);
if (tf) { if (tf) {
LOCAL_Error_TYPE = YAP_NO_ERROR;
return Yap_unify(ARG1, tf); return Yap_unify(ARG1, tf);
} }
} else if (IsVarTerm(t1)) { } else if (IsVarTerm(t1)) {
@ -556,15 +561,24 @@ static Int number_atom(USES_REGS1) {
restart_aux: restart_aux:
t1 = Deref(ARG1); t1 = Deref(ARG1);
if (IsNumTerm(t1)) { if (IsNumTerm(t1)) {
Term t2 = Deref(ARG2);
Atom af; Atom af;
af = Yap_NumberToAtom(t1 PASS_REGS); af = Yap_NumberToAtom(t1 PASS_REGS);
if (af) if (af) {
return Yap_unify(ARG2, MkAtomTerm(af)); if (IsVarTerm(t2)) {
return Yap_unify(t1, t2);
} else {
t2 = Yap_AtomToNumber(t2 PASS_REGS);
if (t2) {
return Yap_unify(t1, t2);
}
}
}
} else if (IsVarTerm(t1)) { } else if (IsVarTerm(t1)) {
/* ARG1 unbound */ /* ARG1 unbound */
Term t = Deref(ARG2); Term t = Deref(ARG2);
Term tf = Yap_AtomToNumber(t PASS_REGS); Term tf = Yap_AtomToNumber(t PASS_REGS);
if (tf)
return Yap_unify(ARG1, tf); return Yap_unify(ARG1, tf);
} else if (IsVarTerm(t1)) { } else if (IsVarTerm(t1)) {
LOCAL_Error_TYPE = TYPE_ERROR_NUMBER; LOCAL_Error_TYPE = TYPE_ERROR_NUMBER;
@ -634,8 +648,8 @@ restart_aux:
i = IntOfTerm(EXTRA_CBACK_ARG(3, 1)); i = IntOfTerm(EXTRA_CBACK_ARG(3, 1));
max = IntOfTerm(EXTRA_CBACK_ARG(3, 2)); max = IntOfTerm(EXTRA_CBACK_ARG(3, 2));
EXTRA_CBACK_ARG(3, 1) = MkIntTerm(i + 1); EXTRA_CBACK_ARG(3, 1) = MkIntTerm(i + 1);
if (!Yap_SpliceAtom(t3, ats, i, max PASS_REGS) && LOCAL_Error_TYPE == if (!Yap_SpliceAtom(t3, ats, i, max PASS_REGS) &&
YAP_NO_ERROR) { LOCAL_Error_TYPE == YAP_NO_ERROR) {
cut_fail(); cut_fail();
} else { } else {
if (i < max) if (i < max)
@ -684,7 +698,6 @@ restart_aux:
return cont_atom_concat3(PASS_REGS1); return cont_atom_concat3(PASS_REGS1);
} else { } else {
LOCAL_Error_TYPE = INSTANTIATION_ERROR; LOCAL_Error_TYPE = INSTANTIATION_ERROR;
LOCAL_Error_Term = t1;
at = NULL; at = NULL;
} }
if (at) { if (at) {
@ -704,7 +717,6 @@ restart_aux:
cut_fail(); cut_fail();
} }
#define CastToNumeric(x) CastToNumeric__(x PASS_REGS) #define CastToNumeric(x) CastToNumeric__(x PASS_REGS)
static Term CastToNumeric__(Atom at USES_REGS) { static Term CastToNumeric__(Atom at USES_REGS) {
@ -772,7 +784,6 @@ restart_aux:
return cont_atomic_concat3(PASS_REGS1); return cont_atomic_concat3(PASS_REGS1);
} else { } else {
LOCAL_Error_TYPE = INSTANTIATION_ERROR; LOCAL_Error_TYPE = INSTANTIATION_ERROR;
LOCAL_Error_Term = t1;
at = NULL; at = NULL;
} }
if (at) { if (at) {
@ -849,7 +860,6 @@ restart_aux:
return cont_string_concat3(PASS_REGS1); return cont_string_concat3(PASS_REGS1);
} else { } else {
LOCAL_Error_TYPE = INSTANTIATION_ERROR; LOCAL_Error_TYPE = INSTANTIATION_ERROR;
LOCAL_Error_Term = t1;
at = NULL; at = NULL;
} }
if (tf) { if (tf) {
@ -913,10 +923,8 @@ restart_aux:
t2 = Deref(ARG2); t2 = Deref(ARG2);
if (IsVarTerm(t2)) { if (IsVarTerm(t2)) {
LOCAL_Error_TYPE = INSTANTIATION_ERROR; LOCAL_Error_TYPE = INSTANTIATION_ERROR;
LOCAL_Error_Term = t2;
} else if (!IsStringTerm(t2)) { } else if (!IsStringTerm(t2)) {
LOCAL_Error_TYPE = TYPE_ERROR_STRING; LOCAL_Error_TYPE = TYPE_ERROR_STRING;
LOCAL_Error_Term = t2;
} else { } else {
s = UStringOfTerm(t2); s = UStringOfTerm(t2);
t1 = Deref(ARG1); t1 = Deref(ARG1);
@ -926,7 +934,6 @@ restart_aux:
return cont_string_code3(PASS_REGS1); return cont_string_code3(PASS_REGS1);
} else if (!IsIntegerTerm(t1)) { } else if (!IsIntegerTerm(t1)) {
LOCAL_Error_TYPE = TYPE_ERROR_INTEGER; LOCAL_Error_TYPE = TYPE_ERROR_INTEGER;
LOCAL_Error_Term = t1;
} else { } else {
const unsigned char *ns = s; const unsigned char *ns = s;
utf8proc_int32_t chr; utf8proc_int32_t chr;
@ -934,7 +941,6 @@ restart_aux:
if (indx <= 0) { if (indx <= 0) {
if (indx < 0) { if (indx < 0) {
LOCAL_Error_TYPE = DOMAIN_ERROR_NOT_LESS_THAN_ZERO; LOCAL_Error_TYPE = DOMAIN_ERROR_NOT_LESS_THAN_ZERO;
LOCAL_Error_Term = t1;
} }
cut_fail(); cut_fail();
} }
@ -970,19 +976,16 @@ restart_aux:
t2 = Deref(ARG2); t2 = Deref(ARG2);
if (IsVarTerm(t2)) { if (IsVarTerm(t2)) {
LOCAL_Error_TYPE = INSTANTIATION_ERROR; LOCAL_Error_TYPE = INSTANTIATION_ERROR;
LOCAL_Error_Term = t2;
} else if (!IsStringTerm(t2)) { } else if (!IsStringTerm(t2)) {
LOCAL_Error_TYPE = TYPE_ERROR_STRING; LOCAL_Error_TYPE = TYPE_ERROR_STRING;
LOCAL_Error_Term = t2;
} else { } else {
s = UStringOfTerm(t2); s = UStringOfTerm(t2);
t1 = Deref(ARG1); t1 = Deref(ARG1);
if (IsVarTerm(t1)) { if (IsVarTerm(t1)) {
LOCAL_Error_TYPE = INSTANTIATION_ERROR; LOCAL_Error_TYPE = INSTANTIATION_ERROR;
LOCAL_Error_Term = t1;
} else if (!IsIntegerTerm(t1)) { } else if (!IsIntegerTerm(t1)) {
LOCAL_Error_TYPE = TYPE_ERROR_INTEGER; LOCAL_Error_TYPE = TYPE_ERROR_INTEGER;
LOCAL_Error_Term = t1;
} else { } else {
const unsigned char *ns = s; const unsigned char *ns = s;
utf8proc_int32_t chr; utf8proc_int32_t chr;
@ -991,7 +994,6 @@ restart_aux:
if (indx <= 0) { if (indx <= 0) {
if (indx < 0) { if (indx < 0) {
LOCAL_Error_TYPE = DOMAIN_ERROR_NOT_LESS_THAN_ZERO; LOCAL_Error_TYPE = DOMAIN_ERROR_NOT_LESS_THAN_ZERO;
LOCAL_Error_Term = t1;
} else { } else {
return false; return false;
} }
@ -1813,7 +1815,6 @@ static Term build_new_atomic(int mask, wchar_t *wp, const unsigned char *p,
src = skip_utf8((unsigned char *)src, min); src = skip_utf8((unsigned char *)src, min);
const unsigned char *cp = src; const unsigned char *cp = src;
LOCAL_TERM_ERROR(t, 4 * (len + 1));
buf = buf_from_tstring(HR); buf = buf_from_tstring(HR);
while (len) { while (len) {
utf8proc_int32_t chr; utf8proc_int32_t chr;

View File

@ -1452,8 +1452,6 @@ static void addcl_permission_error(AtomEntry *ap, Int Arity, int in_use) {
ti[0] = MkAtomTerm(AbsAtom(ap)); ti[0] = MkAtomTerm(AbsAtom(ap));
ti[1] = MkIntegerTerm(Arity); ti[1] = MkIntegerTerm(Arity);
t = Yap_MkApplTerm(FunctorSlash, 2, ti); t = Yap_MkApplTerm(FunctorSlash, 2, ti);
LOCAL_ErrorMessage = LOCAL_ErrorSay;
LOCAL_Error_Term = t;
LOCAL_Error_TYPE = PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE; LOCAL_Error_TYPE = PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE;
if (in_use) { if (in_use) {
if (Arity == 0) if (Arity == 0)
@ -2028,9 +2026,7 @@ static Int p_compile(USES_REGS1) { /* '$compile'(+C,+Flags,+C0,-Ref) */
YAPLeaveCriticalSection(); YAPLeaveCriticalSection();
} }
if (LOCAL_ErrorMessage) { if (LOCAL_ErrorMessage) {
if (!LOCAL_Error_Term) Yap_Error(LOCAL_Error_TYPE, ARG1, LOCAL_ErrorMessage);
LOCAL_Error_Term = TermNil;
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
YAPLeaveCriticalSection(); YAPLeaveCriticalSection();
return false; return false;
} }
@ -3590,7 +3586,8 @@ static Int p_predicate_erased_statistics(USES_REGS1) {
Term tpred = ArgOfTerm(2, Deref(ARG1)); Term tpred = ArgOfTerm(2, Deref(ARG1));
Term tmod = ArgOfTerm(1, Deref(ARG1)); Term tmod = ArgOfTerm(1, Deref(ARG1));
if (EndOfPAEntr(pe = Yap_get_pred(tpred, tmod, "predicate_erased_statistics"))) if (EndOfPAEntr(pe =
Yap_get_pred(tpred, tmod, "predicate_erased_statistics")))
return FALSE; return FALSE;
while (cl) { while (cl) {
if (cl->ClPred == pe) { if (cl->ClPred == pe) {

View File

@ -18,8 +18,6 @@
/// @file cmppreds.c /// @file cmppreds.c
/** /**
@defgroup Comparing_Terms Comparing Terms @defgroup Comparing_Terms Comparing Terms
@ingroup builtins @ingroup builtins
@ -52,14 +50,13 @@ left-to-right order.
*/ */
#ifdef SCCS #ifdef SCCS
static char SccsId[] = "%W% %G%"; static char SccsId[] = "%W% %G%";
#endif #endif
#include "Yap.h" #include "Yap.h"
#include "Yatom.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "Yatom.h"
#include "eval.h" #include "eval.h"
#if HAVE_STRING_H #if HAVE_STRING_H
#include <string.h> #include <string.h>
@ -83,19 +80,19 @@ static Int a_gen_ge(Term,Term);
#define rfloat(X) (X > 0.0 ? 1 : (X == 0.0 ? 0 : -1)) #define rfloat(X) (X > 0.0 ? 1 : (X == 0.0 ? 0 : -1))
static int static int cmp_atoms(Atom a1, Atom a2) {
cmp_atoms(Atom a1, Atom a2)
{
if (IsWideAtom(a1)) { if (IsWideAtom(a1)) {
if (IsWideAtom(a2)) { if (IsWideAtom(a2)) {
return wcscmp((wchar_t *)RepAtom(a1)->StrOfAE,(wchar_t *)RepAtom(a2)->StrOfAE); return wcscmp((wchar_t *)RepAtom(a1)->StrOfAE,
(wchar_t *)RepAtom(a2)->StrOfAE);
} else { } else {
/* The standard does not seem to have nothing on this */ /* The standard does not seem to have nothing on this */
unsigned char *s1 = (unsigned char *)RepAtom(a1)->StrOfAE; unsigned char *s1 = (unsigned char *)RepAtom(a1)->StrOfAE;
wchar_t *s2 = (wchar_t *)RepAtom(a2)->StrOfAE; wchar_t *s2 = (wchar_t *)RepAtom(a2)->StrOfAE;
while (*s1 == *s2) { while (*s1 == *s2) {
if (!*s1) return 0; if (!*s1)
return 0;
s1++; s1++;
s2++; s2++;
} }
@ -107,7 +104,8 @@ cmp_atoms(Atom a1, Atom a2)
unsigned char *s2 = (unsigned char *)RepAtom(a2)->StrOfAE; unsigned char *s2 = (unsigned char *)RepAtom(a2)->StrOfAE;
while (*s1 == *s2) { while (*s1 == *s2) {
if (!*s1) return 0; if (!*s1)
return 0;
s1++; s1++;
s2++; s2++;
} }
@ -117,9 +115,8 @@ cmp_atoms(Atom a1, Atom a2)
} }
} }
static Int compare_complex(register CELL *pt0, register CELL *pt0_end, register static Int compare_complex(register CELL *pt0, register CELL *pt0_end,
CELL *pt1) register CELL *pt1) {
{
CACHE_REGS CACHE_REGS
register CELL **to_visit = (CELL **)HR; register CELL **to_visit = (CELL **)HR;
register Int out = 0; register Int out = 0;
@ -134,9 +131,9 @@ static Int compare_complex(register CELL *pt0, register CELL *pt0_end, register
if (IsVarTerm(d0)) { if (IsVarTerm(d0)) {
if (IsVarTerm(d1)) { if (IsVarTerm(d1)) {
out = Signed(d0) - Signed(d1); out = Signed(d0) - Signed(d1);
if (out) goto done; if (out)
} goto done;
else { } else {
out = -1; out = -1;
goto done; goto done;
} }
@ -144,17 +141,18 @@ static Int compare_complex(register CELL *pt0, register CELL *pt0_end, register
out = 1; out = 1;
goto done; goto done;
} else { } else {
if (d0 == d1) continue; if (d0 == d1)
continue;
else if (IsAtomTerm(d0)) { else if (IsAtomTerm(d0)) {
if (IsAtomTerm(d1)) if (IsAtomTerm(d1))
out = cmp_atoms(AtomOfTerm(d0), AtomOfTerm(d1)); out = cmp_atoms(AtomOfTerm(d0), AtomOfTerm(d1));
else if (IsPrimitiveTerm(d1)) else if (IsPrimitiveTerm(d1))
out = 1; out = 1;
else out = -1; else
out = -1;
/* I know out must be != 0 */ /* I know out must be != 0 */
goto done; goto done;
} } else if (IsIntTerm(d0)) {
else if (IsIntTerm(d0)) {
if (IsIntTerm(d1)) if (IsIntTerm(d1))
out = IntOfTerm(d0) - IntOfTerm(d1); out = IntOfTerm(d0) - IntOfTerm(d1);
else if (IsFloatTerm(d1)) { else if (IsFloatTerm(d1)) {
@ -167,7 +165,8 @@ static Int compare_complex(register CELL *pt0, register CELL *pt0_end, register
#endif #endif
} else if (IsRefTerm(d1)) } else if (IsRefTerm(d1))
out = 1; out = 1;
else out = -1; else
out = -1;
if (out != 0) if (out != 0)
goto done; goto done;
} else if (IsFloatTerm(d0)) { } else if (IsFloatTerm(d0)) {
@ -231,7 +230,8 @@ static Int compare_complex(register CELL *pt0, register CELL *pt0_end, register
out = Yap_gmp_tcmp_big_big(d0, d1); out = Yap_gmp_tcmp_big_big(d0, d1);
} else if (IsRefTerm(d1)) } else if (IsRefTerm(d1))
out = 1; out = 1;
else out = -1; else
out = -1;
if (out != 0) if (out != 0)
goto done; goto done;
} }
@ -244,7 +244,8 @@ static Int compare_complex(register CELL *pt0, register CELL *pt0_end, register
out = 1; out = 1;
else if (!(out = 2 - ArityOfFunctor(f))) else if (!(out = 2 - ArityOfFunctor(f)))
out = strcmp(".", (char *)RepAtom(NameOfFunctor(f))->StrOfAE); out = strcmp(".", (char *)RepAtom(NameOfFunctor(f))->StrOfAE);
} else out = 1; } else
out = 1;
goto done; goto done;
} }
#ifdef RATIONAL_TREES #ifdef RATIONAL_TREES
@ -267,12 +268,11 @@ static Int compare_complex(register CELL *pt0, register CELL *pt0_end, register
pt0_end = RepPair(d0) + 1; pt0_end = RepPair(d0) + 1;
pt1 = RepPair(d1) - 1; pt1 = RepPair(d1) - 1;
continue; continue;
} } else if (IsRefTerm(d0)) {
else if (IsRefTerm(d0)) {
if (IsRefTerm(d1)) if (IsRefTerm(d1))
out = Unsigned(RefOfTerm(d1)) - out = Unsigned(RefOfTerm(d1)) - Unsigned(RefOfTerm(d0));
Unsigned(RefOfTerm(d0)); else
else out = -1; out = -1;
goto done; goto done;
} else if (IsApplTerm(d0)) { } else if (IsApplTerm(d0)) {
register Functor f; register Functor f;
@ -324,7 +324,6 @@ static Int compare_complex(register CELL *pt0, register CELL *pt0_end, register
continue; continue;
} }
} }
} }
} }
/* Do we still have compound terms to visit */ /* Do we still have compound terms to visit */
@ -358,8 +357,7 @@ static Int compare_complex(register CELL *pt0, register CELL *pt0_end, register
return (out); return (out);
} }
inline static Int inline static Int compare(Term t1, Term t2) /* compare terms t1 and t2 */
compare(Term t1, Term t2) /* compare terms t1 and t2 */
{ {
if (t1 == t2) if (t1 == t2)
@ -417,11 +415,10 @@ compare(Term t1, Term t2) /* compare terms t1 and t2 */
} }
} }
if (IsPairTerm(t2)) { if (IsPairTerm(t2)) {
return(compare_complex(RepPair(t1)-1, return (
RepPair(t1)+1, compare_complex(RepPair(t1) - 1, RepPair(t1) + 1, RepPair(t2) - 1));
RepPair(t2)-1)); } else
} return 1;
else return 1;
} else { } else {
/* compound term */ /* compound term */
Functor fun1 = FunctorOfTerm(t1); Functor fun1 = FunctorOfTerm(t1);
@ -429,16 +426,14 @@ compare(Term t1, Term t2) /* compare terms t1 and t2 */
if (IsExtensionFunctor(fun1)) { if (IsExtensionFunctor(fun1)) {
/* float, long, big, dbref */ /* float, long, big, dbref */
switch ((CELL)fun1) { switch ((CELL)fun1) {
case double_e: case double_e: {
{
if (IsFloatTerm(t2)) if (IsFloatTerm(t2))
return (rfloat(FloatOfTerm(t1) - FloatOfTerm(t2))); return (rfloat(FloatOfTerm(t1) - FloatOfTerm(t2)));
if (IsRefTerm(t2)) if (IsRefTerm(t2))
return 1; return 1;
return -1; return -1;
} }
case long_int_e: case long_int_e: {
{
if (IsIntTerm(t2)) if (IsIntTerm(t2))
return LongIntOfTerm(t1) - IntOfTerm(t2); return LongIntOfTerm(t1) - IntOfTerm(t2);
if (IsFloatTerm(t2)) { if (IsFloatTerm(t2)) {
@ -456,8 +451,7 @@ compare(Term t1, Term t2) /* compare terms t1 and t2 */
return -1; return -1;
} }
#ifdef USE_GMP #ifdef USE_GMP
case big_int_e: case big_int_e: {
{
if (IsIntTerm(t2)) if (IsIntTerm(t2))
return Yap_gmp_tcmp_big_int(t1, IntOfTerm(t2)); return Yap_gmp_tcmp_big_int(t1, IntOfTerm(t2));
if (IsFloatTerm(t2)) { if (IsFloatTerm(t2)) {
@ -473,8 +467,7 @@ compare(Term t1, Term t2) /* compare terms t1 and t2 */
return -1; return -1;
} }
#endif #endif
case string_e: case string_e: {
{
if (IsApplTerm(t2)) { if (IsApplTerm(t2)) {
Functor fun2 = FunctorOfTerm(t2); Functor fun2 = FunctorOfTerm(t2);
switch ((CELL)fun2) { switch ((CELL)fun2) {
@ -497,8 +490,7 @@ compare(Term t1, Term t2) /* compare terms t1 and t2 */
} }
case db_ref_e: case db_ref_e:
if (IsRefTerm(t2)) if (IsRefTerm(t2))
return Unsigned(RefOfTerm(t2)) - return Unsigned(RefOfTerm(t2)) - Unsigned(RefOfTerm(t1));
Unsigned(RefOfTerm(t1));
return -1; return -1;
} }
} }
@ -526,15 +518,13 @@ compare(Term t1, Term t2) /* compare terms t1 and t2 */
if (r) if (r)
return r; return r;
else else
return(compare_complex(RepAppl(t1), return (compare_complex(RepAppl(t1), RepAppl(t1) + ArityOfFunctor(fun1),
RepAppl(t1)+ArityOfFunctor(fun1),
RepAppl(t2))); RepAppl(t2)));
} }
} }
} }
Int Yap_compare_terms(Term d0, Term d1) Int Yap_compare_terms(Term d0, Term d1) {
{
return compare(Deref(d0), Deref(d1)); return compare(Deref(d0), Deref(d1));
} }
@ -552,9 +542,7 @@ the following values:
`>` if _Y_ precedes _X_ in the defined order; `>` if _Y_ precedes _X_ in the defined order;
*/ */
Int Int p_compare(USES_REGS1) { /* compare(?Op,?T1,?T2) */
p_compare( USES_REGS1 )
{ /* compare(?Op,?T1,?T2) */
Int r = compare(Deref(ARG2), Deref(ARG3)); Int r = compare(Deref(ARG2), Deref(ARG3));
Atom p; Atom p;
Term t = Deref(ARG1); Term t = Deref(ARG1);
@ -569,9 +557,7 @@ p_compare( USES_REGS1 )
Atom a = AtomOfTerm(t); Atom a = AtomOfTerm(t);
if (a == p) if (a == p)
return true; return true;
if (a != AtomLT && if (a != AtomLT && a != AtomGT && a != AtomEq)
a != AtomGT &&
a != AtomEq)
Yap_Error(DOMAIN_ERROR_ORDER, ARG1, NULL); Yap_Error(DOMAIN_ERROR_ORDER, ARG1, NULL);
} else { } else {
Yap_Error(TYPE_ERROR_ATOM, ARG1, NULL); Yap_Error(TYPE_ERROR_ATOM, ARG1, NULL);
@ -582,22 +568,13 @@ p_compare( USES_REGS1 )
return Yap_unify_constant(ARG1, MkAtomTerm(p)); return Yap_unify_constant(ARG1, MkAtomTerm(p));
} }
/** @pred _X_ \== _Y_ is iso /** @pred _X_ \== _Y_ is iso
Terms _X_ and _Y_ are not strictly identical. Terms _X_ and _Y_ are not strictly identical.
*/ */
static Int static Int a_noteq(Term t1, Term t2) { return (compare(t1, t2) != 0); }
a_noteq(Term t1, Term t2)
{
return (compare(t1, t2) != 0);
}
static Int static Int a_gen_lt(Term t1, Term t2) { return (compare(t1, t2) < 0); }
a_gen_lt(Term t1, Term t2)
{
return (compare(t1, t2) < 0);
}
/** @pred _X_ @=< _Y_ is iso /** @pred _X_ @=< _Y_ is iso
@ -605,33 +582,20 @@ a_gen_lt(Term t1, Term t2)
Term _X_ does not follow term _Y_ in the standard order. Term _X_ does not follow term _Y_ in the standard order.
*/ */
static Int static Int a_gen_le(Term t1, Term t2) { return (compare(t1, t2) <= 0); }
a_gen_le(Term t1, Term t2)
{
return (compare(t1, t2) <= 0);
}
/** @pred _X_ @> _Y_ is iso /** @pred _X_ @> _Y_ is iso
Term _X_ does not follow term _Y_ in the standard order Term _X_ does not follow term _Y_ in the standard order
*/ */
static Int static Int a_gen_gt(Term t1, Term t2) { return compare(t1, t2) > 0; }
a_gen_gt(Term t1, Term t2)
{
return compare(t1, t2) > 0;
}
/** @pred _X_ @>= _Y_ is iso /** @pred _X_ @>= _Y_ is iso
Term _X_ does not precede term _Y_ in the standard order. Term _X_ does not precede term _Y_ in the standard order.
*/ */
static Int static Int a_gen_ge(Term t1, Term t2) { return compare(t1, t2) >= 0; }
a_gen_ge(Term t1, Term t2)
{
return compare(t1, t2) >= 0;
}
/** /**
@} @}
@ -642,19 +606,14 @@ a_gen_ge(Term t1, Term t2)
@defgroup arithmetic_cmps Arithmetic Comparison Predicates @defgroup arithmetic_cmps Arithmetic Comparison Predicates
@ingroup arithmetic @ingroup arithmetic
Comparison of Numeric Expressions. Both arguments must be valid ground expressions at time of call. Comparison of Numeric Expressions. Both arguments must be valid ground
expressions at time of call.
@{ @{
*/ */
inline static Int inline static Int int_cmp(Int dif) { return dif; }
int_cmp(Int dif)
{
return dif;
}
inline static Int inline static Int flt_cmp(Float dif) {
flt_cmp(Float dif)
{
if (dif < 0.0) if (dif < 0.0)
return -1; return -1;
if (dif > 0.0) if (dif > 0.0)
@ -662,18 +621,12 @@ flt_cmp(Float dif)
return dif = 0.0; return dif = 0.0;
} }
static inline Int a_cmp(Term t1, Term t2 USES_REGS) {
static inline Int
a_cmp(Term t1, Term t2 USES_REGS)
{
LOCAL_ArithError = FALSE;
if (IsVarTerm(t1)) { if (IsVarTerm(t1)) {
LOCAL_ArithError = TRUE;
Yap_Error(INSTANTIATION_ERROR, t1, "=:=/2"); Yap_Error(INSTANTIATION_ERROR, t1, "=:=/2");
return FALSE; return FALSE;
} }
if (IsVarTerm(t2)) { if (IsVarTerm(t2)) {
LOCAL_ArithError = TRUE;
Yap_Error(INSTANTIATION_ERROR, t2, "=:=/2"); Yap_Error(INSTANTIATION_ERROR, t2, "=:=/2");
return FALSE; return FALSE;
} }
@ -699,9 +652,7 @@ a_cmp(Term t1, Term t2 USES_REGS)
#if HAVE_ISNAN #if HAVE_ISNAN
if (isnan(f2)) { if (isnan(f2)) {
LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED; LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED;
LOCAL_Error_Term = t2;
LOCAL_ErrorMessage = "trying to evaluate nan"; LOCAL_ErrorMessage = "trying to evaluate nan";
LOCAL_ArithError = TRUE;
} }
#endif #endif
return flt_cmp(i1 - f2); return flt_cmp(i1 - f2);
@ -717,9 +668,7 @@ a_cmp(Term t1, Term t2 USES_REGS)
#if HAVE_ISNAN #if HAVE_ISNAN
if (isnan(f1)) { if (isnan(f1)) {
LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED; LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED;
LOCAL_Error_Term = t1;
LOCAL_ErrorMessage = "trying to evaluate nan"; LOCAL_ErrorMessage = "trying to evaluate nan";
LOCAL_ArithError = TRUE;
} }
#endif #endif
t2 = Yap_Eval(t2); t2 = Yap_Eval(t2);
@ -736,9 +685,7 @@ a_cmp(Term t1, Term t2 USES_REGS)
#if HAVE_ISNAN #if HAVE_ISNAN
if (isnan(f2)) { if (isnan(f2)) {
LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED; LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED;
LOCAL_Error_Term = t2;
LOCAL_ErrorMessage = "trying to evaluate nan"; LOCAL_ErrorMessage = "trying to evaluate nan";
LOCAL_ArithError = TRUE;
} }
#endif #endif
return flt_cmp(f1 - f2); return flt_cmp(f1 - f2);
@ -761,9 +708,7 @@ a_cmp(Term t1, Term t2 USES_REGS)
#if HAVE_ISNAN #if HAVE_ISNAN
if (isnan(f2)) { if (isnan(f2)) {
LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED; LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED;
LOCAL_Error_Term = t2;
LOCAL_ErrorMessage = "trying to evaluate nan"; LOCAL_ErrorMessage = "trying to evaluate nan";
LOCAL_ArithError = TRUE;
} }
#endif #endif
return Yap_gmp_cmp_big_float(t1, f2); return Yap_gmp_cmp_big_float(t1, f2);
@ -779,23 +724,17 @@ a_cmp(Term t1, Term t2 USES_REGS)
} }
} }
Int Int Yap_acmp(Term t1, Term t2 USES_REGS) {
Yap_acmp(Term t1, Term t2 USES_REGS)
{
Int out = a_cmp(t1, t2 PASS_REGS); Int out = a_cmp(t1, t2 PASS_REGS);
if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; }
return out; return out;
} }
static Int static Int p_acomp(USES_REGS1) { /* $a_compare(?R,+X,+Y) */
p_acomp( USES_REGS1 )
{ /* $a_compare(?R,+X,+Y) */
Term t1 = Deref(ARG1); Term t1 = Deref(ARG1);
Term t2 = Deref(ARG2); Term t2 = Deref(ARG2);
Int out; Int out;
out = a_cmp(t1, t2 PASS_REGS); out = a_cmp(t1, t2 PASS_REGS);
if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; }
return out; return out;
} }
@ -806,9 +745,7 @@ p_acomp( USES_REGS1 )
The value of the expression _X_ is equal to the value of expression _Y_. The value of the expression _X_ is equal to the value of expression _Y_.
*/ */
/// @memberof =:=/2 /// @memberof =:=/2
static Int static Int a_eq(Term t1, Term t2) {
a_eq(Term t1, Term t2)
{
CACHE_REGS CACHE_REGS
/* A =:= B */ /* A =:= B */
Int out; Int out;
@ -838,24 +775,21 @@ a_eq(Term t1, Term t2)
} }
} }
out = a_cmp(t1, t2 PASS_REGS); out = a_cmp(t1, t2 PASS_REGS);
if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; } Yap_Error(LOCAL_Error_TYPE, t1, LOCAL_ErrorMessage);
return out == 0; return out == 0;
} }
/* /*
@pred +_X_ =\\= _Y_ is iso @pred +_X_ =\\= _Y_ is iso
Difference of arithmetic expressions Difference of arithmetic expressions
The value of the expression _X_ is different from the value of expression _Y_. The value of the expression _X_ is different from the value of expression
_Y_.
*/ */
/// @memberof =\\=/2 /// @memberof =\\=/2
static Int static Int a_dif(Term t1, Term t2) {
a_dif(Term t1, Term t2)
{
CACHE_REGS CACHE_REGS
Int out = a_cmp(Deref(t1), Deref(t2) PASS_REGS); Int out = a_cmp(Deref(t1), Deref(t2) PASS_REGS);
if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; }
return out != 0; return out != 0;
} }
@ -866,12 +800,9 @@ a_dif(Term t1, Term t2)
The value of the expression _X_ is less than or equal to the value The value of the expression _X_ is less than or equal to the value
of expression _Y_. of expression _Y_.
*/ */
static Int static Int a_gt(Term t1, Term t2) { /* A > B */
a_gt(Term t1, Term t2)
{ /* A > B */
CACHE_REGS CACHE_REGS
Int out = a_cmp(Deref(t1), Deref(t2) PASS_REGS); Int out = a_cmp(Deref(t1), Deref(t2) PASS_REGS);
if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; }
return out > 0; return out > 0;
} }
@ -882,12 +813,9 @@ a_gt(Term t1, Term t2)
The value of the expression _X_ is greater than or equal to the The value of the expression _X_ is greater than or equal to the
value of expression _Y_. value of expression _Y_.
*/ */
static Int static Int a_ge(Term t1, Term t2) { /* A >= B */
a_ge(Term t1, Term t2)
{ /* A >= B */
CACHE_REGS CACHE_REGS
Int out = a_cmp(Deref(t1), Deref(t2) PASS_REGS); Int out = a_cmp(Deref(t1), Deref(t2) PASS_REGS);
if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; }
return out >= 0; return out >= 0;
} }
@ -899,12 +827,9 @@ a_ge(Term t1, Term t2)
_Y_. _Y_.
*/ */
/// @memberof </2 /// @memberof </2
static Int static Int a_lt(Term t1, Term t2) { /* A < B */
a_lt(Term t1, Term t2)
{ /* A < B */
CACHE_REGS CACHE_REGS
Int out = a_cmp(Deref(t1), Deref(t2) PASS_REGS); Int out = a_cmp(Deref(t1), Deref(t2) PASS_REGS);
if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; }
return out < 0; return out < 0;
} }
@ -918,12 +843,9 @@ a_lt(Term t1, Term t2)
of expression _Y_. of expression _Y_.
*/ */
/// @memberof =</2 /// @memberof =</2
static Int static Int a_le(Term t1, Term t2) { /* A <= B */
a_le(Term t1, Term t2)
{ /* A <= B */
CACHE_REGS CACHE_REGS
Int out = a_cmp(Deref(t1), Deref(t2) PASS_REGS); Int out = a_cmp(Deref(t1), Deref(t2) PASS_REGS);
if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; }
return out <= 0; return out <= 0;
} }
@ -931,9 +853,7 @@ a_le(Term t1, Term t2)
@} @}
*/ */
void void Yap_InitCmpPreds(void) {
Yap_InitCmpPreds(void)
{
Yap_InitCmpPred("=:=", 2, a_eq, SafePredFlag | BinaryPredFlag); Yap_InitCmpPred("=:=", 2, a_eq, SafePredFlag | BinaryPredFlag);
Yap_InitCmpPred("=\\=", 2, a_dif, SafePredFlag | BinaryPredFlag); Yap_InitCmpPred("=\\=", 2, a_dif, SafePredFlag | BinaryPredFlag);
Yap_InitCmpPred(">", 2, a_gt, SafePredFlag | BinaryPredFlag); Yap_InitCmpPred(">", 2, a_gt, SafePredFlag | BinaryPredFlag);

File diff suppressed because it is too large Load Diff

View File

@ -336,19 +336,18 @@ static int recover_from_record_error(int nargs) {
goto recover_record; goto recover_record;
case RESOURCE_ERROR_HEAP: case RESOURCE_ERROR_HEAP:
if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) { if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) {
Yap_Error(RESOURCE_ERROR_HEAP, LOCAL_Error_Term, LOCAL_ErrorMessage); Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
goto recover_record; goto recover_record;
case RESOURCE_ERROR_AUXILIARY_STACK: case RESOURCE_ERROR_AUXILIARY_STACK:
if (!Yap_ExpandPreAllocCodeSpace(LOCAL_Error_Size, NULL, TRUE)) { if (!Yap_ExpandPreAllocCodeSpace(LOCAL_Error_Size, NULL, TRUE)) {
Yap_Error(RESOURCE_ERROR_AUXILIARY_STACK, LOCAL_Error_Term, Yap_Error(RESOURCE_ERROR_AUXILIARY_STACK, TermNil, LOCAL_ErrorMessage);
LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
goto recover_record; goto recover_record;
default: default:
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); Yap_Error(LOCAL_Error_TYPE, TermNil, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
recover_record: recover_record:
@ -1121,7 +1120,6 @@ static void sf_include(SFKeep *sfp, struct db_globs *dbg) SFKeep *sfp;
j += 2; j += 2;
} else { } else {
LOCAL_Error_TYPE = TYPE_ERROR_DBTERM; LOCAL_Error_TYPE = TYPE_ERROR_DBTERM;
LOCAL_Error_Term = d0;
LOCAL_ErrorMessage = "wrong term in SF"; LOCAL_ErrorMessage = "wrong term in SF";
return (NULL); return (NULL);
} }
@ -1242,7 +1240,6 @@ static DBRef generate_dberror_msg(int errnumb, UInt sz, char *msg) {
CACHE_REGS CACHE_REGS
LOCAL_Error_Size = sz; LOCAL_Error_Size = sz;
LOCAL_Error_TYPE = errnumb; LOCAL_Error_TYPE = errnumb;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = msg; LOCAL_ErrorMessage = msg;
return NULL; return NULL;
} }
@ -2611,7 +2608,6 @@ static int resize_int_keys(UInt new_size) {
if (new == NULL) { if (new == NULL) {
YAPLeaveCriticalSection(); YAPLeaveCriticalSection();
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = "could not allocate space"; LOCAL_ErrorMessage = "could not allocate space";
return FALSE; return FALSE;
} }
@ -2693,7 +2689,6 @@ static PredEntry *new_lu_int_key(Int key) {
if (INT_LU_KEYS == NULL) { if (INT_LU_KEYS == NULL) {
CACHE_REGS CACHE_REGS
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = "could not allocate space"; LOCAL_ErrorMessage = "could not allocate space";
return NULL; return NULL;
} }
@ -2825,7 +2820,6 @@ static DBProp FetchIntDBPropFromKey(Int key, int flag, int new,
if (INT_KEYS == NULL) { if (INT_KEYS == NULL) {
CACHE_REGS CACHE_REGS
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP;
LOCAL_Error_Term = TermNil;
LOCAL_ErrorMessage = "could not allocate space"; LOCAL_ErrorMessage = "could not allocate space";
return NULL; return NULL;
} }

View File

@ -74,16 +74,17 @@ bool Yap_Warning(const char *s, ...) {
return rc; return rc;
} }
void Yap_InitError(yap_error_number e, Term t, const char *msg) { void Yap_InitError(yap_error_number e, Term t, const char *msg) {
if (LOCAL_ActiveError.status) { if (LOCAL_ActiveError->status) {
Yap_exit(1); Yap_exit(1);
} }
LOCAL_ActiveError.errorNo = e; LOCAL_ActiveError->errorNo = e;
LOCAL_ActiveError.errorFile = NULL; LOCAL_ActiveError->errorFile = NULL;
LOCAL_ActiveError.errorFunction = NULL; LOCAL_ActiveError->errorFunction = NULL;
LOCAL_ActiveError.errorLine = 0; LOCAL_ActiveError->errorLine = 0;
if (msg) { if (msg) {
LOCAL_Error_Size = strlen(msg); LOCAL_Error_Size = strlen(msg);
strcpy(LOCAL_ActiveError.errorComment, msg); LOCAL_ActiveError->errorMsg = malloc(LOCAL_Error_Size + 1);
strcpy(LOCAL_ActiveError->errorMsg, msg);
} else { } else {
LOCAL_Error_Size = 0; LOCAL_Error_Size = 0;
} }
@ -158,7 +159,7 @@ bool Yap_HandleError__(const char *file, const char *function, int lineno,
return false; return false;
} }
default: default:
Yap_Error__(file, function, lineno, err, LOCAL_Error_Term, serr); Yap_Error__(file, function, lineno, err, TermNil, serr);
return false; return false;
} }
} }
@ -196,7 +197,7 @@ int Yap_SWIHandleError(const char *s, ...) {
return FALSE; return FALSE;
} }
default: default:
Yap_Error(err, LOCAL_Error_Term, serr); Yap_Error(err, TermNil, serr);
return (FALSE); return (FALSE);
} }
} }
@ -292,11 +293,23 @@ static char tmpbuf[YAP_BUF_SIZE];
return mkerrorct(B, ts); return mkerrorct(B, ts);
#define END_ERRORS() \ #define END_ERRORS() \
} return TermNil; \ } \
return TermNil; \
} }
#include "YapErrors.h" #include "YapErrors.h"
void Yap_pushErrorContext(yap_error_descriptor_t *new_error) {
new_error->top_error = LOCAL_ActiveError;
LOCAL_ActiveError = new_error;
}
yap_error_descriptor_t *Yap_popErrorContext(void) {
yap_error_descriptor_t *new_error = LOCAL_ActiveError;
LOCAL_ActiveError = LOCAL_ActiveError->top_error;
return new_error;
}
/** /**
* @brief Yap_Error * @brief Yap_Error
* This function handles errors in the C code. Check errors.yap for the * This function handles errors in the C code. Check errors.yap for the
@ -343,17 +356,17 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
/* disallow recursive error handling */ /* disallow recursive error handling */
if (LOCAL_PrologMode & InErrorMode) { if (LOCAL_PrologMode & InErrorMode) {
fprintf(stderr, "%% ERROR WITHIN ERROR %d: %s\n", LOCAL_CurrentError, fprintf(stderr, "%% ERROR WITHIN ERROR %d: %s\n", LOCAL_Error_TYPE, tmpbuf);
tmpbuf);
Yap_RestartYap(1); Yap_RestartYap(1);
} }
LOCAL_ActiveError.errorNo = type; LOCAL_ActiveError->errorNo = type;
LOCAL_ActiveError.errorAsText = Yap_LookupAtom(Yap_errorName( type )); LOCAL_ActiveError->errorAsText = Yap_LookupAtom(Yap_errorName(type));
LOCAL_ActiveError.errorClass = Yap_errorClass( type); LOCAL_ActiveError->errorClass = Yap_errorClass(type);
LOCAL_ActiveError.classAsText = Yap_LookupAtom(Yap_errorClassName( LOCAL_ActiveError.errorClass )); LOCAL_ActiveError->classAsText =
LOCAL_ActiveError.errorLine = lineno; Yap_LookupAtom(Yap_errorClassName(LOCAL_ActiveError->errorClass));
LOCAL_ActiveError.errorFunction = function; LOCAL_ActiveError->errorLine = lineno;
LOCAL_ActiveError.errorFile = file; LOCAL_ActiveError->errorFunction = function;
LOCAL_ActiveError->errorFile = file;
Yap_find_prolog_culprit(PASS_REGS1); Yap_find_prolog_culprit(PASS_REGS1);
LOCAL_PrologMode |= InErrorMode; LOCAL_PrologMode |= InErrorMode;
Yap_ClearExs(); Yap_ClearExs();
@ -380,7 +393,7 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
} }
if (LOCAL_within_print_message) { if (LOCAL_within_print_message) {
/* error within error */ /* error within error */
fprintf(stderr, "%% ERROR WITHIN WARNING %d: %s\n", LOCAL_CurrentError, fprintf(stderr, "%% ERROR WITHIN WARNING %d: %s\n", LOCAL_Error_TYPE,
tmpbuf); tmpbuf);
LOCAL_PrologMode &= ~InErrorMode; LOCAL_PrologMode &= ~InErrorMode;
Yap_exit(1); Yap_exit(1);
@ -395,8 +408,8 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
#endif #endif
// fprintf(stderr, "warning: "); // fprintf(stderr, "warning: ");
comment = MkAtomTerm(Yap_LookupAtom(s)); comment = MkAtomTerm(Yap_LookupAtom(s));
} else if (LOCAL_ErrorSay && LOCAL_ErrorSay[0]) { } else if (LOCAL_ErrorMessage && LOCAL_ErrorMessage[0]) {
comment = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorSay)); comment = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
} else { } else {
comment = TermNil; comment = TermNil;
} }
@ -410,7 +423,6 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
if (type == ABORT_EVENT || LOCAL_PrologMode & BootMode) { if (type == ABORT_EVENT || LOCAL_PrologMode & BootMode) {
where = TermNil; where = TermNil;
LOCAL_PrologMode &= ~AbortMode; LOCAL_PrologMode &= ~AbortMode;
LOCAL_CurrentError = type;
LOCAL_PrologMode &= ~InErrorMode; LOCAL_PrologMode &= ~InErrorMode;
/* make sure failure will be seen at next port */ /* make sure failure will be seen at next port */
// no need to lock & unlock // no need to lock & unlock
@ -426,7 +438,6 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
} }
/* Exit Abort Mode, if we were there */ /* Exit Abort Mode, if we were there */
LOCAL_PrologMode &= ~AbortMode; LOCAL_PrologMode &= ~AbortMode;
LOCAL_CurrentError = type;
LOCAL_PrologMode |= InErrorMode; LOCAL_PrologMode |= InErrorMode;
if (!(where = Yap_CopyTerm(where))) { if (!(where = Yap_CopyTerm(where))) {
where = TermNil; where = TermNil;
@ -528,14 +539,11 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
/* This is used by some complex procedures to detect there was an error */ /* This is used by some complex procedures to detect there was an error */
if (IsAtomTerm(nt[0])) { if (IsAtomTerm(nt[0])) {
strncpy(LOCAL_ErrorSay, (char *)RepAtom(AtomOfTerm(nt[0]))->StrOfAE, strncpy(LOCAL_ErrorMessage, (char *)RepAtom(AtomOfTerm(nt[0]))->StrOfAE,
MAX_ERROR_MSG_SIZE); MAX_ERROR_MSG_SIZE);
LOCAL_ErrorMessage = LOCAL_ErrorSay;
} else { } else {
strncpy(LOCAL_ErrorSay, LOCAL_ErrorMessage =
(char *)RepAtom(NameOfFunctor(FunctorOfTerm(nt[0])))->StrOfAE, (char *)RepAtom(NameOfFunctor(FunctorOfTerm(nt[0])))->StrOfAE;
MAX_ERROR_MSG_SIZE);
LOCAL_ErrorMessage = LOCAL_ErrorSay;
} }
nt[1] = TermNil; nt[1] = TermNil;
switch (type) { switch (type) {

129
C/eval.c
View File

@ -27,11 +27,10 @@ static char SccsId[] = "%W% %G%";
@ingroup arithmetic @ingroup arithmetic
*/ */
#include "Yap.h" #include "Yap.h"
#include "Yatom.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "Yatom.h"
#include "eval.h" #include "eval.h"
#if HAVE_STDARG_H #if HAVE_STDARG_H
#include <stdarg.h> #include <stdarg.h>
@ -46,9 +45,7 @@ static char SccsId[] = "%W% %G%";
static Term Eval(Term t1 USES_REGS); static Term Eval(Term t1 USES_REGS);
static Term static Term get_matrix_element(Term t1, Term t2 USES_REGS) {
get_matrix_element(Term t1, Term t2 USES_REGS)
{
if (!IsPairTerm(t2)) { if (!IsPairTerm(t2)) {
if (t2 == MkAtomTerm(AtomLength)) { if (t2 == MkAtomTerm(AtomLength)) {
Int sz = 1; Int sz = 1;
@ -93,9 +90,7 @@ get_matrix_element(Term t1, Term t2 USES_REGS)
return Eval(t1 PASS_REGS); return Eval(t1 PASS_REGS);
} }
static Term static Term Eval(Term t USES_REGS) {
Eval(Term t USES_REGS)
{
if (IsVarTerm(t)) { if (IsVarTerm(t)) {
return Yap_ArithError(INSTANTIATION_ERROR, t, "in arithmetic"); return Yap_ArithError(INSTANTIATION_ERROR, t, "in arithmetic");
@ -155,32 +150,29 @@ Eval(Term t USES_REGS)
return FALSE; return FALSE;
return Yap_eval_binary(p->FOfEE, t1, t2); return Yap_eval_binary(p->FOfEE, t1, t2);
} }
} /* else if (IsPairTerm(t)) */ { } /* else if (IsPairTerm(t)) */
{
if (TailOfTerm(t) != TermNil) { if (TailOfTerm(t) != TermNil) {
return Yap_ArithError(TYPE_ERROR_EVALUABLE, t, return Yap_ArithError(TYPE_ERROR_EVALUABLE, t,
"string must contain a single character to be evaluated as an arithmetic expression"); "string must contain a single character to be "
"evaluated as an arithmetic expression");
} }
return Eval(HeadOfTerm(t) PASS_REGS); return Eval(HeadOfTerm(t) PASS_REGS);
} }
} }
Term Term Yap_InnerEval__(Term t USES_REGS) { return Eval(t PASS_REGS); }
Yap_InnerEval__(Term t USES_REGS)
{
return Eval(t PASS_REGS);
}
#ifdef BEAM #ifdef BEAM
Int BEAM_is(void); Int BEAM_is(void);
Int Int BEAM_is(void) { /* X is Y */
BEAM_is(void)
{ /* X is Y */
union arith_ret res; union arith_ret res;
blob_type bt; blob_type bt;
bt = Eval(Deref(XREGS[2]), &res); bt = Eval(Deref(XREGS[2]), &res);
if (bt==db_ref_e) return (NULL); if (bt == db_ref_e)
return (NULL);
return (EvalToTerm(bt, &res)); return (EvalToTerm(bt, &res));
} }
@ -197,14 +189,13 @@ X is 2+3*4
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
succeeds with `X = 14`. succeeds with `X = 14`.
Consult @ref arithmetic_operators for the complete list of arithmetic_operators Consult @ref arithmetic_operators for the complete list of
arithmetic_operators
*/ */
/// @memberof is/2 /// @memberof is/2
static Int static Int p_is(USES_REGS1) { /* X is Y */
p_is( USES_REGS1 )
{ /* X is Y */
Term out; Term out;
yap_error_number err; yap_error_number err;
@ -239,20 +230,18 @@ p_is( USES_REGS1 )
*/ */
/// @memberof isnan/1 /// @memberof isnan/1
static Int static Int p_isnan(USES_REGS1) { /* X isnan Y */
p_isnan( USES_REGS1 )
{ /* X isnan Y */
Term out = 0L; Term out = 0L;
while (!(out = Eval(Deref(ARG1) PASS_REGS))) { while (!(out = Eval(Deref(ARG1) PASS_REGS))) {
if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) { if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) {
LOCAL_Error_TYPE = YAP_NO_ERROR; LOCAL_Error_TYPE = YAP_NO_ERROR;
if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) { if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) {
Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage); Yap_EvalError(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
} else { } else {
Yap_EvalError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); Yap_EvalError(LOCAL_Error_TYPE, ARG1, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
} }
@ -274,9 +263,7 @@ p_isnan( USES_REGS1 )
*/ */
/// @memberof isnan/1 /// @memberof isnan/1
static Int static Int p_isinf(USES_REGS1) { /* X is Y */
p_isinf( USES_REGS1 )
{ /* X is Y */
Term out = 0L; Term out = 0L;
while (!(out = Eval(Deref(ARG1) PASS_REGS))) { while (!(out = Eval(Deref(ARG1) PASS_REGS))) {
@ -287,7 +274,7 @@ p_isinf( USES_REGS1 )
return FALSE; return FALSE;
} }
} else { } else {
Yap_EvalError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); Yap_EvalError(LOCAL_Error_TYPE, ARG1, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
} }
@ -312,9 +299,7 @@ True if _Log1_ is the logarithm of the positive number _A1_,
*/ */
/// @memberof logsum/3 /// @memberof logsum/3
static Int static Int p_logsum(USES_REGS1) { /* X is Y */
p_logsum( USES_REGS1 )
{ /* X is Y */
Term t1 = Deref(ARG1); Term t1 = Deref(ARG1);
Term t2 = Deref(ARG2); Term t2 = Deref(ARG2);
int done = FALSE; int done = FALSE;
@ -341,7 +326,7 @@ p_logsum( USES_REGS1 )
return FALSE; return FALSE;
} }
} else { } else {
Yap_EvalError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); Yap_EvalError(LOCAL_Error_TYPE, ARG1, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
} }
@ -369,7 +354,7 @@ p_logsum( USES_REGS1 )
return FALSE; return FALSE;
} }
} else { } else {
Yap_EvalError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); Yap_EvalError(LOCAL_Error_TYPE, ARG1, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} }
} }
@ -384,66 +369,51 @@ p_logsum( USES_REGS1 )
} }
} }
Int Yap_ArithError__(const char *file, const char *function, int lineno,
Int yap_error_number type, Term where, ...) {
Yap_ArithError__(const char *file, const char *function, int lineno, yap_error_number type, Term where,...)
{
CACHE_REGS CACHE_REGS
va_list ap; va_list ap;
char *format; char *format;
char buf[MAX_ERROR_MSG_SIZE];
if (LOCAL_ArithError)
return 0L;
LOCAL_ArithError = TRUE;
LOCAL_Error_TYPE = type; LOCAL_Error_TYPE = type;
LOCAL_Error_File = file; LOCAL_Error_File = file;
LOCAL_Error_Function = function; LOCAL_Error_Function = function;
LOCAL_Error_Lineno = lineno; LOCAL_Error_Lineno = lineno;
LOCAL_Error_Term = where;
if (!LOCAL_ErrorMessage)
LOCAL_ErrorMessage = LOCAL_ErrorSay;
va_start(ap, where); va_start(ap, where);
format = va_arg(ap, char *); format = va_arg(ap, char *);
if (format != NULL) { if (format != NULL) {
#if HAVE_VSNPRINTF #if HAVE_VSNPRINTF
(void) vsnprintf(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE, format, ap); (void)vsnprintf(buf, MAX_ERROR_MSG_SIZE, format, ap);
#else #else
(void) vsprintf(LOCAL_ErrorMessage, format, ap); (void)vsprintf(buf, format, ap);
#endif #endif
} else { } else {
LOCAL_ErrorMessage[0] = '\0'; buf[0] = '\0';
} }
va_end(ap); va_end(ap);
return 0L; return 0L;
} }
yamop * yamop *Yap_EvalError__(const char *file, const char *function, int lineno,
Yap_EvalError__(const char *file, const char *function, int lineno,yap_error_number type, Term where,...) yap_error_number type, Term where, ...) {
{
CACHE_REGS CACHE_REGS
va_list ap; va_list ap;
char *format; char *format, buf[MAX_ERROR_MSG_SIZE];
if (LOCAL_ArithError) {
LOCAL_ArithError = YAP_NO_ERROR;
return Yap_Error__(file, function, lineno, LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage);
}
if (!LOCAL_ErrorMessage)
LOCAL_ErrorMessage = LOCAL_ErrorSay;
va_start(ap, where); va_start(ap, where);
format = va_arg(ap, char *); format = va_arg(ap, char *);
if (format != NULL) { if (format != NULL) {
#if HAVE_VSNPRINTF #if HAVE_VSNPRINTF
(void) vsnprintf(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE, format, ap); (void)vsnprintf(buf, MAX_ERROR_MSG_SIZE, format, ap);
#else #else
(void) vsprintf(LOCAL_ErrorMessage, format, ap); (void)vsprintf(buf, format, ap);
#endif #endif
} else { } else {
LOCAL_ErrorMessage[0] = '\0'; buf[0] = '\0';
} }
va_end(ap); va_end(ap);
return Yap_Error__(file, function, lineno, type, where, LOCAL_ErrorMessage); return Yap_Error__(file, function, lineno, type, where, buf);
} }
/** /**
@ -461,8 +431,7 @@ Yap_EvalError__(const char *file, const char *function, int lineno,yap_error_num
*/ */
/// @memberof between/3 /// @memberof between/3
static Int cont_between( USES_REGS1 ) static Int cont_between(USES_REGS1) {
{
Term t1 = EXTRA_CBACK_ARG(3, 1); Term t1 = EXTRA_CBACK_ARG(3, 1);
Term t2 = EXTRA_CBACK_ARG(3, 2); Term t2 = EXTRA_CBACK_ARG(3, 2);
@ -496,9 +465,7 @@ static Int cont_between( USES_REGS1 )
} }
/// @memberof between/3 /// @memberof between/3
static Int static Int init_between(USES_REGS1) {
init_between( USES_REGS1 )
{
Term t1 = Deref(ARG1); Term t1 = Deref(ARG1);
Term t2 = Deref(ARG2); Term t2 = Deref(ARG2);
@ -510,14 +477,11 @@ init_between( USES_REGS1 )
Yap_EvalError(INSTANTIATION_ERROR, t1, "between/3"); Yap_EvalError(INSTANTIATION_ERROR, t1, "between/3");
return FALSE; return FALSE;
} }
if (!IsIntegerTerm(t1) && if (!IsIntegerTerm(t1) && !IsBigIntTerm(t1)) {
!IsBigIntTerm(t1)) {
Yap_EvalError(TYPE_ERROR_INTEGER, t1, "between/3"); Yap_EvalError(TYPE_ERROR_INTEGER, t1, "between/3");
return FALSE; return FALSE;
} }
if (!IsIntegerTerm(t2) && if (!IsIntegerTerm(t2) && !IsBigIntTerm(t2) && t2 != MkAtomTerm(AtomInf) &&
!IsBigIntTerm(t2) &&
t2 != MkAtomTerm(AtomInf) &&
t2 != MkAtomTerm(AtomInfinity)) { t2 != MkAtomTerm(AtomInfinity)) {
Yap_EvalError(TYPE_ERROR_INTEGER, t2, "between/3"); Yap_EvalError(TYPE_ERROR_INTEGER, t2, "between/3");
return FALSE; return FALSE;
@ -542,7 +506,8 @@ init_between( USES_REGS1 )
cut_fail(); cut_fail();
} }
} }
if (i1 > i2) cut_fail(); if (i1 > i2)
cut_fail();
if (i1 == i2) { if (i1 == i2) {
Yap_unify(ARG3, t1); Yap_unify(ARG3, t1);
cut_succeed(); cut_succeed();
@ -575,12 +540,14 @@ init_between( USES_REGS1 )
Yap_EvalError(TYPE_ERROR_INTEGER, t3, "between/3"); Yap_EvalError(TYPE_ERROR_INTEGER, t3, "between/3");
return FALSE; return FALSE;
} }
if (Yap_acmp(t3, t1 PASS_REGS) >= 0 && Yap_acmp(t2,t3 PASS_REGS) >= 0 && P != FAILCODE) if (Yap_acmp(t3, t1 PASS_REGS) >= 0 && Yap_acmp(t2, t3 PASS_REGS) >= 0 &&
P != FAILCODE)
cut_succeed(); cut_succeed();
cut_fail(); cut_fail();
} }
cmp = Yap_acmp(t1, t2 PASS_REGS); cmp = Yap_acmp(t1, t2 PASS_REGS);
if (cmp > 0) cut_fail(); if (cmp > 0)
cut_fail();
if (cmp == 0) { if (cmp == 0) {
Yap_unify(ARG3, t1); Yap_unify(ARG3, t1);
cut_succeed(); cut_succeed();
@ -591,9 +558,7 @@ init_between( USES_REGS1 )
return cont_between(PASS_REGS1); return cont_between(PASS_REGS1);
} }
void void Yap_InitEval(void) {
Yap_InitEval(void)
{
/* here are the arithmetical predicates */ /* here are the arithmetical predicates */
Yap_InitConstExps(); Yap_InitConstExps();
Yap_InitUnaryExps(); Yap_InitUnaryExps();

View File

@ -1446,7 +1446,7 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) {
/* must be done here, otherwise siglongjmp will clobber all the /* must be done here, otherwise siglongjmp will clobber all the
* registers * registers
*/ */
Yap_Error(LOCAL_matherror, TermNil, NULL); Yap_Error(LOCAL_Error_TYPE, TermNil, NULL);
/* reset the registers so that we don't have trash in abstract /* reset the registers so that we don't have trash in abstract
* machine */ * machine */
Yap_set_fpu_exceptions( Yap_set_fpu_exceptions(
@ -2080,16 +2080,16 @@ static Int jump_env(USES_REGS1) {
LOCAL_Error_TYPE = ERROR_EVENT; LOCAL_Error_TYPE = ERROR_EVENT;
t = ArgOfTerm(1, t); t = ArgOfTerm(1, t);
if (IsApplTerm(t) && IsAtomTerm((t2 = ArgOfTerm(1, t)))) { if (IsApplTerm(t) && IsAtomTerm((t2 = ArgOfTerm(1, t)))) {
LOCAL_ActiveError.errorAsText = AtomOfTerm(t2); LOCAL_ActiveError->errorAsText = AtomOfTerm(t2);
LOCAL_ActiveError.classAsText = NameOfFunctor(FunctorOfTerm(t)); LOCAL_ActiveError->classAsText = NameOfFunctor(FunctorOfTerm(t));
} else if (IsAtomTerm(t)) { } else if (IsAtomTerm(t)) {
LOCAL_ActiveError.errorAsText = AtomOfTerm(t); LOCAL_ActiveError->errorAsText = AtomOfTerm(t);
LOCAL_ActiveError.classAsText = NULL; LOCAL_ActiveError->classAsText = NULL;
} }
} else { } else {
LOCAL_Error_TYPE = THROW_EVENT; LOCAL_Error_TYPE = THROW_EVENT;
} }
LOCAL_ActiveError.prologPredName = NULL; LOCAL_ActiveError->prologPredName = NULL;
Yap_PutException(t); Yap_PutException(t);
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 &&
@ -2225,10 +2225,10 @@ bool Yap_PutException(Term t) {
} }
bool Yap_ResetException(int wid) { bool Yap_ResetException(int wid) {
if (REMOTE_BallTerm(wid)) { if (REMOTE_ActiveError(wid)->errorTerm) {
Yap_PopTermFromDB(REMOTE_BallTerm(wid)); Yap_PopTermFromDB(REMOTE_ActiveError(wid)->errorTerm);
} }
REMOTE_BallTerm(wid) = NULL; REMOTE_ActiveError(wid)->errorTerm = NULL;
return true; return true;
} }

View File

@ -1369,7 +1369,7 @@ do_prolog_flag_property(Term tflag,
args = Yap_ArgList2ToVector(opts, prolog_flag_property_defs, args = Yap_ArgList2ToVector(opts, prolog_flag_property_defs,
PROLOG_FLAG_PROPERTY_END); PROLOG_FLAG_PROPERTY_END);
if (args == NULL) { if (args == NULL) {
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, opts, NULL);
return false; return false;
} }
if (!IsAtomTerm(tflag)) { if (!IsAtomTerm(tflag)) {
@ -1533,7 +1533,7 @@ static Int do_create_prolog_flag(USES_REGS1) {
args = Yap_ArgList2ToVector(opts, prolog_flag_property_defs, args = Yap_ArgList2ToVector(opts, prolog_flag_property_defs,
PROLOG_FLAG_PROPERTY_END); PROLOG_FLAG_PROPERTY_END);
if (args == NULL) { if (args == NULL) {
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, opts, NULL);
return false; return false;
} }
fv = GetFlagProp(AtomOfTerm(tflag)); fv = GetFlagProp(AtomOfTerm(tflag));

View File

@ -127,7 +127,8 @@ void *Yap_LoadForeignFile(char *file, int flags) {
if (out == NULL) { if (out == NULL) {
const char *m_os = dlerror(); const char *m_os = dlerror();
if (m_os) { if (m_os) {
strncpy(LOCAL_ErrorSay, m_os, MAX_ERROR_MSG_SIZE - 1); LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);
strncpy(LOCAL_ErrorMessage, m_os, MAX_ERROR_MSG_SIZE - 1);
} else { } else {
LOCAL_ErrorMessage = "dlopen failed"; LOCAL_ErrorMessage = "dlopen failed";
} }
@ -177,7 +178,8 @@ static Int LoadForeign(StringList ofiles, StringList libs, char *proc_name,
NULL) NULL)
#endif #endif
{ {
strcpy(LOCAL_ErrorSay, dlerror()); LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);
strcpy(LOCAL_ErrorMessage, dlerror());
return LOAD_FAILLED; return LOAD_FAILLED;
} }
libs = libs->next; libs = libs->next;
@ -192,7 +194,8 @@ static Int LoadForeign(StringList ofiles, StringList libs, char *proc_name,
/* dlopen wants to follow the LD_CONFIG_PATH */ /* dlopen wants to follow the LD_CONFIG_PATH */
const char *file = AtomName(ofiles->name); const char *file = AtomName(ofiles->name);
if (!Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true, true)) { if (!Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true, true)) {
strcpy(LOCAL_ErrorSay, LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);
strcpy(LOCAL_ErrorMessage,
"%% Trying to open unexisting file in LoadForeign"); "%% Trying to open unexisting file in LoadForeign");
return LOAD_FAILLED; return LOAD_FAILLED;
} }
@ -217,7 +220,7 @@ static Int LoadForeign(StringList ofiles, StringList libs, char *proc_name,
} }
if (!*init_proc) { if (!*init_proc) {
strcpy(LOCAL_ErrorSay, "Could not locate initialization routine"); LOCAL_ErrorMessage = "Could not locate initialization routine";
return LOAD_FAILLED; return LOAD_FAILLED;
} }

View File

@ -140,7 +140,8 @@ p_open_shared_object( USES_REGS1 ) {
s = (char *)RepAtom(AtomOfTerm(t))->StrOfAE; s = (char *)RepAtom(AtomOfTerm(t))->StrOfAE;
if ((handle = Yap_LoadForeignFile(s, IntegerOfTerm(tflags)))==NULL) { if ((handle = Yap_LoadForeignFile(s, IntegerOfTerm(tflags)))==NULL) {
Yap_Error(EXISTENCE_ERROR_SOURCE_SINK,t,"open_shared_object_failed for %s with %s\n", s, LOCAL_ErrorSay); Yap_Error(EXISTENCE_ERROR_SOURCE_SINK,t,"open_shared_object_failed for %s"
" with %s\n", s, LOCAL_ErrorMessage);
return FALSE; return FALSE;
} else { } else {
return Yap_unify(MkIntegerTerm((Int)handle),ARG3); return Yap_unify(MkIntegerTerm((Int)handle),ARG3);

View File

@ -175,10 +175,9 @@ static void syntax_msg(const char *msg, ...) {
va_list ap; va_list ap;
if (LOCAL_toktide == LOCAL_tokptr) { if (LOCAL_toktide == LOCAL_tokptr) {
char out[YAP_FILENAME_MAX]; LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE+1);
va_start(ap, msg); va_start(ap, msg);
vsnprintf(out, YAP_FILENAME_MAX - 1, msg, ap); vsnprintf(LOCAL_ErrorMessage, YAP_FILENAME_MAX , msg, ap);
LOCAL_Error_Term = MkStringTerm( out );
LOCAL_Error_TYPE = SYNTAX_ERROR; LOCAL_Error_TYPE = SYNTAX_ERROR;
va_end(ap); va_end(ap);
} }

File diff suppressed because it is too large Load Diff

View File

@ -165,9 +165,11 @@ static Int
do_SYSTEM_ERROR_INTERNAL(yap_error_number etype, const char *msg) do_SYSTEM_ERROR_INTERNAL(yap_error_number etype, const char *msg)
{ {
CACHE_REGS CACHE_REGS
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE+1);
#if HAVE_SNPRINTF #if HAVE_SNPRINTF
#if HAVE_STRERROR #if HAVE_STRERROR
snprintf(LOCAL_ErrorSay,MAX_ERROR_MSG_SIZE,"%s (%s when reading %s)", msg, strerror(errno), LOCAL_FileNameBuf); snprintf(LOCAL_ErrorMessage,MAX_ERROR_MSG_SIZE,"%s (%s when reading %s)", msg,
strerror(errno), LOCAL_FileNameBuf);
#else #else
snprintf(LOCAL_ErrorSay,MAX_ERROR_MSG_SIZE,"%s, (system error %d when reading %s)",msg,errno,LOCAL_FileNameBuf); snprintf(LOCAL_ErrorSay,MAX_ERROR_MSG_SIZE,"%s, (system error %d when reading %s)",msg,errno,LOCAL_FileNameBuf);
#endif #endif
@ -178,7 +180,6 @@ do_SYSTEM_ERROR_INTERNAL(yap_error_number etype, const char *msg)
sprintf(LOCAL_ErrorSay,"%s, (system error %d when reading %s)",msg,errno,LOCAL_FileNameBuf); sprintf(LOCAL_ErrorSay,"%s, (system error %d when reading %s)",msg,errno,LOCAL_FileNameBuf);
#endif #endif
#endif #endif
LOCAL_ErrorMessage = LOCAL_ErrorSay;
LOCAL_Error_TYPE = etype; LOCAL_Error_TYPE = etype;
return -1; return -1;
} }
@ -685,8 +686,7 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS)
} }
} }
if (strcmp(pp, msg) != 0) { if (strcmp(pp, msg) != 0) {
LOCAL_ErrorMessage = LOCAL_ErrorSay; strncpy(LOCAL_ErrorMessage, "saved state ", MAX_ERROR_MSG_SIZE-1);
strncpy(LOCAL_ErrorMessage, "saved state ", MAX_ERROR_MSG_SIZE);
strncat(LOCAL_ErrorMessage, LOCAL_FileNameBuf, MAX_ERROR_MSG_SIZE-1); strncat(LOCAL_ErrorMessage, LOCAL_FileNameBuf, MAX_ERROR_MSG_SIZE-1);
strncat(LOCAL_ErrorMessage, " failed to match version ID", MAX_ERROR_MSG_SIZE-1); strncat(LOCAL_ErrorMessage, " failed to match version ID", MAX_ERROR_MSG_SIZE-1);
LOCAL_Error_TYPE = SYSTEM_ERROR_SAVED_STATE; LOCAL_Error_TYPE = SYSTEM_ERROR_SAVED_STATE;

View File

@ -1192,8 +1192,7 @@ Term Yap_scan_num(StreamDesc *inp) {
ef->TokNext = NULL; ef->TokNext = NULL;
LOCAL_tokptr = tokptr; LOCAL_tokptr = tokptr;
LOCAL_toktide = e; LOCAL_toktide = e;
LOCAL_ErrorMessage = NULL; LOCAL_ErrorMessage = Yap_syntax_error(e, inp - GLOBAL_Stream);
LOCAL_Error_Term = Yap_syntax_error(e, inp - GLOBAL_Stream);
LOCAL_Error_TYPE = SYNTAX_ERROR; LOCAL_Error_TYPE = SYNTAX_ERROR;
} }
} }

View File

@ -1074,40 +1074,40 @@ bool set_clause_info(yamop *codeptr, PredEntry *pp) {
Term ts[2]; Term ts[2];
void *begin; void *begin;
if (pp->ArityOfPE == 0) { if (pp->ArityOfPE == 0) {
LOCAL_ActiveError.prologPredName = (Atom)pp->FunctorOfPred; LOCAL_ActiveError->prologPredName = (Atom)pp->FunctorOfPred;
LOCAL_ActiveError.prologPredArity = 0; LOCAL_ActiveError->prologPredArity = 0;
} else { } else {
LOCAL_ActiveError.prologPredName = NameOfFunctor(pp->FunctorOfPred); LOCAL_ActiveError->prologPredName = NameOfFunctor(pp->FunctorOfPred);
LOCAL_ActiveError.prologPredArity = pp->ArityOfPE; LOCAL_ActiveError->prologPredArity = pp->ArityOfPE;
} }
LOCAL_ActiveError.prologPredModule = LOCAL_ActiveError->prologPredModule =
(pp->ModuleOfPred ? pp->ModuleOfPred : TermProlog); (pp->ModuleOfPred ? pp->ModuleOfPred : TermProlog);
LOCAL_ActiveError.prologPredFile = pp->src.OwnerFile; LOCAL_ActiveError->prologPredFile = pp->src.OwnerFile;
if (codeptr->opc == UNDEF_OPCODE) { if (codeptr->opc == UNDEF_OPCODE) {
LOCAL_ActiveError.prologPredFirstLine = 0; LOCAL_ActiveError->prologPredFirstLine = 0;
LOCAL_ActiveError.prologPredLine = 0; LOCAL_ActiveError->prologPredLine = 0;
LOCAL_ActiveError.prologPredLastLine = 0; LOCAL_ActiveError->prologPredLastLine = 0;
return true; return true;
} else if (pp->cs.p_code.NOfClauses) { } else if (pp->cs.p_code.NOfClauses) {
if ((LOCAL_ActiveError.prologPredCl = if ((LOCAL_ActiveError->prologPredCl =
find_code_in_clause(pp, codeptr, &begin, NULL)) <= 0) { find_code_in_clause(pp, codeptr, &begin, NULL)) <= 0) {
LOCAL_ActiveError.prologPredLine = 0; LOCAL_ActiveError->prologPredLine = 0;
} else { } else {
LOCAL_ActiveError.prologPredLine = IntegerOfTerm(clause_loc(begin, pp)); LOCAL_ActiveError->prologPredLine = IntegerOfTerm(clause_loc(begin, pp));
} }
if (pp->PredFlags & LogUpdatePredFlag) { if (pp->PredFlags & LogUpdatePredFlag) {
LOCAL_ActiveError.prologPredFirstLine = IntegerOfTerm( LOCAL_ActiveError->prologPredFirstLine = IntegerOfTerm(
ts[0] = clause_loc( ts[0] = clause_loc(
ClauseCodeToLogUpdClause(pp->cs.p_code.FirstClause), pp)); ClauseCodeToLogUpdClause(pp->cs.p_code.FirstClause), pp));
LOCAL_ActiveError.prologPredLastLine = IntegerOfTerm( LOCAL_ActiveError->prologPredLastLine = IntegerOfTerm(
ts[1] = clause_loc(ClauseCodeToLogUpdClause(pp->cs.p_code.LastClause), ts[1] = clause_loc(ClauseCodeToLogUpdClause(pp->cs.p_code.LastClause),
pp)); pp));
} else { } else {
LOCAL_ActiveError.prologPredFirstLine = IntegerOfTerm( LOCAL_ActiveError->prologPredFirstLine = IntegerOfTerm(
ts[0] = clause_loc( ts[0] = clause_loc(
ClauseCodeToStaticClause(pp->cs.p_code.FirstClause), pp)); ClauseCodeToStaticClause(pp->cs.p_code.FirstClause), pp));
LOCAL_ActiveError.prologPredLastLine = IntegerOfTerm( LOCAL_ActiveError->prologPredLastLine = IntegerOfTerm(
ts[1] = clause_loc(ClauseCodeToStaticClause(pp->cs.p_code.LastClause), ts[1] = clause_loc(ClauseCodeToStaticClause(pp->cs.p_code.LastClause),
pp)); pp));
} }

View File

@ -35,46 +35,17 @@ inline static size_t min_size(size_t i, size_t j) { return (i < j ? i : j); }
#define NAN (0.0 / 0.0) #define NAN (0.0 / 0.0)
#endif #endif
void *buf__, *cur__; #ifndef MAX_PATHHNAME
#define MAX_PATHHNAME 1024
#endif
#define init_alloc(I) \ void
void *ov__ = TR, *ocur__ = LOCAL_ScannerStack; \ Yap_InitTextAllocator( void )
if (!LOCAL_ScannerStack) \ {
LOCAL_ScannerStack = (char *)TR struct TextBuffer_manager *new = malloc(sizeof(struct TextBuffer_manager)+MAX_PATHHNAME*2 );
new->prev = NULL;
#define mark_stack() \ new->ptr = new->buf = (struct TextBuffer_manager *)new+1;
void *otr__ = TR; \ LOCAL_TextBuffer = new;
void *ost__ = LOCAL_ScannerStack; \
TR = (tr_fr_ptr)LOCAL_ScannerStack
#define restore_stack() \
TR = otr__; \
LOCAL_ScannerStack = ost__
#define export_buf(s) \
{}
#define unprotect_stack(s) TR = ov__, LOCAL_ScannerStack = ocur__
// LOCAL_ScannerStack = ov__, TR = ot__
static bool alloc_ovfl(size_t sz) {
return (char *)+(sz + 4096) > (char *)LOCAL_TrailTop;
}
static void *Malloc(size_t sz USES_REGS) {
sz = ALIGN_BY_TYPE(sz, CELL);
if (alloc_ovfl(sz))
return NULL;
void *o = LOCAL_ScannerStack;
LOCAL_ScannerStack = (void *)((char *)LOCAL_ScannerStack + sz);
return o;
}
static size_t MaxTmp(USES_REGS1) {
if (LOCAL_ScannerStack) {
return (char *)LOCAL_TrailTop - (char *)LOCAL_ScannerStack;
}
return 0;
} }
static Term Globalize(Term v USES_REGS) { static Term Globalize(Term v USES_REGS) {
@ -244,8 +215,6 @@ static unsigned char *to_buffer(unsigned char *buf, Term t, seq_tv_t *inp,
unsigned char *bufc = buf; unsigned char *bufc = buf;
n = SkipListCodes(&bufc, &t, &r, atoms, widep, inp PASS_REGS); n = SkipListCodes(&bufc, &t, &r, atoms, widep, inp PASS_REGS);
if (n < 0) { if (n < 0) {
LOCAL_Error_TYPE = -n;
LOCAL_Error_Term = *r;
return NULL; return NULL;
} }
*lenp = n; *lenp = n;
@ -319,7 +288,6 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
YAP_STRING_BIG)) == inp->type) { YAP_STRING_BIG)) == inp->type) {
LOCAL_Error_TYPE = TYPE_ERROR_NUMBER; LOCAL_Error_TYPE = TYPE_ERROR_NUMBER;
} }
LOCAL_Error_Term = inp->val.t;
} }
} }
if (LOCAL_Error_TYPE != YAP_NO_ERROR) if (LOCAL_Error_TYPE != YAP_NO_ERROR)
@ -370,9 +338,9 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
s = (char *)s0; s = (char *)s0;
else else
s = Malloc(0); s = Malloc(0);
if (snprintf(s, MaxTmp(PASS_REGS1) - 1, Int_FORMAT, if (snprintf(s, MAX_PATHNAME - 1, Int_FORMAT,
IntegerOfTerm(inp->val.t)) < 0) { IntegerOfTerm(inp->val.t)) < 0) {
AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), s, char); AUX_ERROR(inp->val.t, 2 * (MAX_PATHNAME), s, char);
} }
*lengp = strlen(s); *lengp = strlen(s);
Malloc(*lengp); Malloc(*lengp);

View File

@ -612,11 +612,14 @@ Term YAPEngine::fun(Term t) {
} else if (IsAtomTerm(t)) { } else if (IsAtomTerm(t)) {
name = AtomOfTerm(t); name = AtomOfTerm(t);
f = nullptr; f = nullptr;
} else if (IsAtomTerm(t)) { } else if (IsPairTerm(t)) {
XREGS[1] = ts[0]; XREGS[1] = ts[0];
XREGS[2] = ts[1]; XREGS[2] = ts[1];
name = AtomDot; name = AtomDot;
f = FunctorDot; f = FunctorDot;
} else {
Yap_Error(TYPE_ERROR_CALLABLE, t, 0);
return 0L;
} }
XREGS[arity+1] = MkVarTerm(); XREGS[arity+1] = MkVarTerm();
arity ++; arity ++;
@ -1027,37 +1030,37 @@ const char *YAPError::text() {
char buf[256]; char buf[256];
std::string s = ""; std::string s = "";
if (LOCAL_ActiveError.errorFunction) { if (LOCAL_ActiveError->errorFunction) {
s += LOCAL_ActiveError.errorFile; s += LOCAL_ActiveError->errorFile;
s += ":"; s += ":";
sprintf(buf, "%ld", (long int)LOCAL_ActiveError.errorLine); sprintf(buf, "%ld", (long int)LOCAL_ActiveError->errorLine);
s += buf; s += buf;
s += ":0 in C-code"; s += ":0 in C-code";
} }
if (LOCAL_ActiveError.prologPredLine) { if (LOCAL_ActiveError->prologPredLine) {
s += "\n"; s += "\n";
s += LOCAL_ActiveError.prologPredFile->StrOfAE; s += LOCAL_ActiveError->prologPredFile->StrOfAE;
s += ":"; s += ":";
sprintf(buf, "%ld", (long int)LOCAL_ActiveError.prologPredLine); sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredLine);
s += buf; // std::to_string(LOCAL_ActiveError.prologPredLine) ; s += buf; // std::to_string(LOCAL_ActiveError->prologPredLine) ;
// YAPIntegerTerm(LOCAL_ActiveError.prologPredLine).text(); // YAPIntegerTerm(LOCAL_ActiveError->prologPredLine).text();
s += ":0 "; s += ":0 ";
s += LOCAL_ActiveError.prologPredModule; s += LOCAL_ActiveError->prologPredModule;
s += ":"; s += ":";
s += (LOCAL_ActiveError.prologPredName)->StrOfAE; s += (LOCAL_ActiveError->prologPredName)->StrOfAE;
s += "/"; s += "/";
sprintf(buf, "%ld", (long int)LOCAL_ActiveError.prologPredArity); sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredArity);
s += // std::to_string(LOCAL_ActiveError.prologPredArity); s += // std::to_string(LOCAL_ActiveError->prologPredArity);
buf; buf;
} }
s += " error "; s += " error ";
if (LOCAL_ActiveError.classAsText != nullptr) if (LOCAL_ActiveError->classAsText != nullptr)
s += LOCAL_ActiveError.classAsText->StrOfAE; s += LOCAL_ActiveError->classAsText->StrOfAE;
s += "."; s += ".";
s += LOCAL_ActiveError.errorAsText->StrOfAE; s += LOCAL_ActiveError->errorAsText->StrOfAE;
s += ".\n"; s += ".\n";
if (LOCAL_ActiveError.errorTerm) { if (LOCAL_ActiveError->errorTerm) {
Term t = Yap_PopTermFromDB(LOCAL_ActiveError.errorTerm); Term t = Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);
if (t) { if (t) {
s += "error term is: "; s += "error term is: ";
s += YAPTerm(t).text(); s += YAPTerm(t).text();

View File

@ -15,17 +15,17 @@ public:
YAPError(){}; YAPError(){};
/// we just know the error number /// we just know the error number
/// exact error ID /// exact error ID
yap_error_number getID() { return LOCAL_ActiveError.errorNo; }; yap_error_number getID() { return LOCAL_ActiveError->errorNo; };
/// class of error /// class of error
yap_error_class_number getErrorClass() { yap_error_class_number getErrorClass() {
return Yap_errorClass(LOCAL_ActiveError.errorNo); return Yap_errorClass(LOCAL_ActiveError->errorNo);
}; };
/// where in the code things happened; /// where in the code things happened;
const char *getFile() { return LOCAL_ActiveError.errorFile; }; const char *getFile() { return LOCAL_ActiveError->errorFile; };
/// predicate things happened; /// predicate things happened;
Int getLine() { return LOCAL_ActiveError.errorLine; }; Int getLine() { return LOCAL_ActiveError->errorLine; };
/// the term that caused the bug /// the term that caused the bug
// YAPTerm getCulprit(LOCAL_ActiveError.errorFile){}; // YAPTerm getCulprit(LOCAL_ActiveError->errorFile){};
/// text describing the Error /// text describing the Error
const char *text(); const char *text();
}; };

View File

@ -183,9 +183,16 @@ public:
bool goalt(YAPTerm t); bool goalt(YAPTerm t);
/// current directory for the engine /// current directory for the engine
bool goal(Term t); bool goal(Term t);
#if SWIGPYTHON bool unlockedGoal(Term t) {bool rc;
bool unlockedGoal(Term t) {bool rc;Py_BEGIN_ALLOW_THREADS; rc = goal(t);Py_END_ALLOW_THREADS; return rc; } #ifdef SWIGPYTHON
Py_BEGIN_ALLOW_THREADS;
#endif #endif
rc = goal(t);
#ifdef SWIGPYTHON
Py_END_ALLOW_THREADS;
#endif
return rc;
}
/// reset Prolog state /// reset Prolog state
void reSet(); void reSet();
/// release: assune that there are no stack pointers, just release memory /// release: assune that there are no stack pointers, just release memory

View File

@ -79,7 +79,6 @@ UInt GlobalArenaOverflows =0L
Int ArenaOverflows =0L Int ArenaOverflows =0L
Int DepthArenas =0 Int DepthArenas =0
int ArithError =FALSE
struct pred_entry* LastAssertedPred =NULL struct pred_entry* LastAssertedPred =NULL
struct pred_entry* TmpPred =NULL struct pred_entry* TmpPred =NULL
char* ScannerStack =NULL char* ScannerStack =NULL
@ -194,13 +193,10 @@ ADDR LocalBase void
ADDR GlobalBase void ADDR GlobalBase void
ADDR TrailBase void ADDR TrailBase void
ADDR TrailTop void ADDR TrailTop void
char* ErrorMessage void
Term Error_Term void
/** 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 */
struct yap_error_descriptor ActiveError void yap_error_descriptor_t* ActiveError =calloc(sizeof(yap_error_descriptor_t),1)
/// pointer to an exception term, from throw /// pointer to an exception term, from throw
struct DB_TERM* BallTerm =NULL
jmp_buf IOBotch void jmp_buf IOBotch void
TokEntry* tokptr void TokEntry* tokptr void
@ -217,6 +213,8 @@ sigjmp_buf RestartEnv void
char FileNameBuf[YAP_FILENAME_MAX+1] void char FileNameBuf[YAP_FILENAME_MAX+1] void
char FileNameBuf2[YAP_FILENAME_MAX+1] void char FileNameBuf2[YAP_FILENAME_MAX+1] void
struct TextBuffer_manager* TextBuffer =Yap_InitTextAllocator()
// Prolog State // Prolog State
UInt BreakLevel =0 UInt BreakLevel =0
Int PrologMode =BootMode Int PrologMode =BootMode
@ -237,10 +235,8 @@ YAP_ULONG_LONG 2opcount[_std_top+1][_std_top+1] void
struct db_globs* s_dbg void struct db_globs* s_dbg void
//eval.c //eval.c
yap_error_number matherror =YAP_NO_ERROR
Term mathtt void Term mathtt void
char* mathstring =NULL char* mathstring =NULL
yap_error_number CurrentError =YAP_NO_ERROR
//grow.c //grow.c
int heap_overflows =0 int heap_overflows =0

View File

@ -31,6 +31,48 @@
#include "../utf8proc/utf8proc.h" #include "../utf8proc/utf8proc.h"
#include "Yap.h" #include "Yap.h"
typedef struct TextBuffer_manager {
void *buf, *ptr;
size_t sz;
struct TextBuffer_manager *prev;
} text_buffer_t;
/**
* TextBuffer is allocated as a chain of blocks, They area
* recovered at the end if the translation.
*/
inline void init_alloc(int line) {
while (LOCAL_TextBuffer->prev ) {
struct TextBuffer_manager *old = LOCAL_TextBuffer;
LOCAL_TextBuffer = LOCAL_TextBuffer->prev;
free(old);
}
LOCAL_TextBuffer->sz = (YAP_FILENAME_MAX + 1);
LOCAL_TextBuffer->buf = LOCAL_TextBuffer->ptr = realloc(LOCAL_TextBuffer->ptr, YAP_FILENAME_MAX + 1 );
}
extern inline void mark_stack(void) {}
extern inline void restore_stack(void ) {} \
extern inline void unprotect_stack(void *ptr) {} \
extern inline void *Malloc(size_t sz USES_REGS) {
sz = ALIGN_BY_TYPE(sz, CELL);
void *o = LOCAL_TextBuffer->ptr;
if ((char*)LOCAL_TextBuffer->ptr+sz>(char*)LOCAL_TextBuffer->buf + LOCAL_TextBuffer->sz) {
struct TextBuffer_manager *new = malloc(sizeof(struct TextBuffer_manager)+YAP_FILENAME_MAX + 1);
new->prev = LOCAL_TextBuffer;
new->buf = (struct TextBuffer_manager *)new+1;
new->ptr = new->buf + sz;
LOCAL_TextBuffer= new;
return new->buf;
}
LOCAL_TextBuffer->ptr += sz;
return o;
}
/* Character types for tokenizer and write.c */ /* Character types for tokenizer and write.c */
/****************** character definition table **************************/ /****************** character definition table **************************/

View File

@ -99,7 +99,8 @@ register struct yami *P1REG asm("bp"); /* can't use yamop before Yap.h */
#define LIMITED_PREFETCH 1 #define LIMITED_PREFETCH 1
#endif /* __x86_64__ */ #endif /* __x86_64__ */
#if defined(__arm__) || defined(__thumb__) || defined(mips) || defined(__mips64) || defined(__aarch64__) #if defined(__arm__) || defined(__thumb__) || defined(mips) || \
defined(__mips64) || defined(__aarch64__)
#define Y_IN_MEM 1 #define Y_IN_MEM 1
#define S_IN_MEM 1 #define S_IN_MEM 1
@ -2075,7 +2076,8 @@ cufail:
#endif #endif
#if /* defined(IN_ABSMI_C) ||*/ defined(IN_INLINES_C) /*|| defined(IN_TRACED_ABSMI_C) */ #if /* defined(IN_ABSMI_C) ||*/ defined( \
IN_INLINES_C) /*|| defined(IN_TRACED_ABSMI_C) */
static int iequ_complex(register CELL *pt0, register CELL *pt0_end, static int iequ_complex(register CELL *pt0, register CELL *pt0_end,
register CELL *pt1) { register CELL *pt1) {
@ -2450,4 +2452,11 @@ extern yamop *headoftrace;
ENDD(d0); ENDD(d0);
#endif #endif
#define Yap_AsmError(e) \
{ \
saveregs(); \
Yap_Error(e, 0, ""); \
setregs(); \
}
#endif // ABSMI_H #endif // ABSMI_H

View File

@ -375,6 +375,7 @@ Functor EvalArg(Term);
eval_flt = (F); \ eval_flt = (F); \
return (FFloat); \ return (FFloat); \
} }
#define REvalError() \ #define REvalError() \
{ return (FError); } { return (FError); }
@ -407,8 +408,12 @@ yamop *Yap_EvalError__(const char *, const char *, int, yap_error_number, Term,
#define Yap_ArithError(id, t, ...) \ #define Yap_ArithError(id, t, ...) \
Yap_ArithError__(__FILE__, __FUNCTION__, __LINE__, id, t, __VA_ARGS__) Yap_ArithError__(__FILE__, __FUNCTION__, __LINE__, id, t, __VA_ARGS__)
Int Yap_ArithError__(const char *, const char *, int, yap_error_number, Term, #define Yap_BinError(id) \
...); Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, 0L, "")
#define Yap_AbsmiError(id) \
Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, 0L, "")
extern Int Yap_ArithError__(const char *, const char *, int, yap_error_number,
Term, ...);
#include "inline-only.h" #include "inline-only.h"
@ -463,7 +468,11 @@ Atom Yap_NameOfBinaryOp(int i);
#define RINT(v) return (MkIntegerTerm(v)) #define RINT(v) return (MkIntegerTerm(v))
#define RFLOAT(v) return (MkFloatTerm(v)) #define RFLOAT(v) return (MkFloatTerm(v))
#define RBIG(v) return (Yap_MkBigIntTerm(v)) #define RBIG(v) return (Yap_MkBigIntTerm(v))
#define RERROR() return (0L) #define RERROR() \
{ \
Yap_BinError(LOCAL_Error_TYPE); \
return (0L); \
}
static inline blob_type ETypeOfTerm(Term t) { static inline blob_type ETypeOfTerm(Term t) {
if (IsIntTerm(t)) if (IsIntTerm(t))

View File

@ -121,8 +121,6 @@
#define REMOTE_ArenaOverflows(wid) REMOTE(wid)->ArenaOverflows_ #define REMOTE_ArenaOverflows(wid) REMOTE(wid)->ArenaOverflows_
#define LOCAL_DepthArenas LOCAL->DepthArenas_ #define LOCAL_DepthArenas LOCAL->DepthArenas_
#define REMOTE_DepthArenas(wid) REMOTE(wid)->DepthArenas_ #define REMOTE_DepthArenas(wid) REMOTE(wid)->DepthArenas_
#define LOCAL_ArithError LOCAL->ArithError_
#define REMOTE_ArithError(wid) REMOTE(wid)->ArithError_
#define LOCAL_LastAssertedPred LOCAL->LastAssertedPred_ #define LOCAL_LastAssertedPred LOCAL->LastAssertedPred_
#define REMOTE_LastAssertedPred(wid) REMOTE(wid)->LastAssertedPred_ #define REMOTE_LastAssertedPred(wid) REMOTE(wid)->LastAssertedPred_
#define LOCAL_TmpPred LOCAL->TmpPred_ #define LOCAL_TmpPred LOCAL->TmpPred_
@ -288,16 +286,10 @@
#define REMOTE_TrailBase(wid) REMOTE(wid)->TrailBase_ #define REMOTE_TrailBase(wid) REMOTE(wid)->TrailBase_
#define LOCAL_TrailTop LOCAL->TrailTop_ #define LOCAL_TrailTop LOCAL->TrailTop_
#define REMOTE_TrailTop(wid) REMOTE(wid)->TrailTop_ #define REMOTE_TrailTop(wid) REMOTE(wid)->TrailTop_
#define LOCAL_ErrorMessage LOCAL->ErrorMessage_
#define REMOTE_ErrorMessage(wid) REMOTE(wid)->ErrorMessage_
#define LOCAL_Error_Term LOCAL->Error_Term_
#define REMOTE_Error_Term(wid) REMOTE(wid)->Error_Term_
#define LOCAL_ActiveError LOCAL->ActiveError_ #define LOCAL_ActiveError LOCAL->ActiveError_
#define REMOTE_ActiveError(wid) REMOTE(wid)->ActiveError_ #define REMOTE_ActiveError(wid) REMOTE(wid)->ActiveError_
#define LOCAL_BallTerm LOCAL->BallTerm_
#define REMOTE_BallTerm(wid) REMOTE(wid)->BallTerm_
#define LOCAL_IOBotch LOCAL->IOBotch_ #define LOCAL_IOBotch LOCAL->IOBotch_
#define REMOTE_IOBotch(wid) REMOTE(wid)->IOBotch_ #define REMOTE_IOBotch(wid) REMOTE(wid)->IOBotch_
#define LOCAL_tokptr LOCAL->tokptr_ #define LOCAL_tokptr LOCAL->tokptr_
@ -326,6 +318,8 @@
#define REMOTE_FileNameBuf(wid) REMOTE(wid)->FileNameBuf_ #define REMOTE_FileNameBuf(wid) REMOTE(wid)->FileNameBuf_
#define LOCAL_FileNameBuf2 LOCAL->FileNameBuf2_ #define LOCAL_FileNameBuf2 LOCAL->FileNameBuf2_
#define REMOTE_FileNameBuf2(wid) REMOTE(wid)->FileNameBuf2_ #define REMOTE_FileNameBuf2(wid) REMOTE(wid)->FileNameBuf2_
#define LOCAL_TextBuffer LOCAL->TextBuffer_
#define REMOTE_TextBuffer(wid) REMOTE(wid)->TextBuffer_
#define LOCAL_BreakLevel LOCAL->BreakLevel_ #define LOCAL_BreakLevel LOCAL->BreakLevel_
#define REMOTE_BreakLevel(wid) REMOTE(wid)->BreakLevel_ #define REMOTE_BreakLevel(wid) REMOTE(wid)->BreakLevel_
@ -350,14 +344,10 @@
#define LOCAL_s_dbg LOCAL->s_dbg_ #define LOCAL_s_dbg LOCAL->s_dbg_
#define REMOTE_s_dbg(wid) REMOTE(wid)->s_dbg_ #define REMOTE_s_dbg(wid) REMOTE(wid)->s_dbg_
#define LOCAL_matherror LOCAL->matherror_
#define REMOTE_matherror(wid) REMOTE(wid)->matherror_
#define LOCAL_mathtt LOCAL->mathtt_ #define LOCAL_mathtt LOCAL->mathtt_
#define REMOTE_mathtt(wid) REMOTE(wid)->mathtt_ #define REMOTE_mathtt(wid) REMOTE(wid)->mathtt_
#define LOCAL_mathstring LOCAL->mathstring_ #define LOCAL_mathstring LOCAL->mathstring_
#define REMOTE_mathstring(wid) REMOTE(wid)->mathstring_ #define REMOTE_mathstring(wid) REMOTE(wid)->mathstring_
#define LOCAL_CurrentError LOCAL->CurrentError_
#define REMOTE_CurrentError(wid) REMOTE(wid)->CurrentError_
#define LOCAL_heap_overflows LOCAL->heap_overflows_ #define LOCAL_heap_overflows LOCAL->heap_overflows_
#define REMOTE_heap_overflows(wid) REMOTE(wid)->heap_overflows_ #define REMOTE_heap_overflows(wid) REMOTE(wid)->heap_overflows_

View File

@ -69,7 +69,6 @@ typedef struct worker_local {
UInt GlobalArenaOverflows_; UInt GlobalArenaOverflows_;
Int ArenaOverflows_; Int ArenaOverflows_;
Int DepthArenas_; Int DepthArenas_;
int ArithError_;
struct pred_entry* LastAssertedPred_; struct pred_entry* LastAssertedPred_;
struct pred_entry* TmpPred_; struct pred_entry* TmpPred_;
char* ScannerStack_; char* ScannerStack_;
@ -164,12 +163,9 @@ typedef struct worker_local {
ADDR GlobalBase_; ADDR GlobalBase_;
ADDR TrailBase_; ADDR TrailBase_;
ADDR TrailTop_; ADDR TrailTop_;
char* ErrorMessage_; /* error handling info, designed to be easy to pass to the foreign world */
Term Error_Term_; yap_error_descriptor_t* ActiveError_;
/** error handling info, designed to be easy to pass to the foreign world */
struct yap_error_descriptor ActiveError_;
/// pointer to an exception term, from throw /// pointer to an exception term, from throw
struct DB_TERM* BallTerm_;
jmp_buf IOBotch_; jmp_buf IOBotch_;
TokEntry* tokptr_; TokEntry* tokptr_;
TokEntry* toktide_; TokEntry* toktide_;
@ -184,6 +180,7 @@ typedef struct worker_local {
sigjmp_buf RestartEnv_; sigjmp_buf RestartEnv_;
char FileNameBuf_[YAP_FILENAME_MAX+1]; char FileNameBuf_[YAP_FILENAME_MAX+1];
char FileNameBuf2_[YAP_FILENAME_MAX+1]; char FileNameBuf2_[YAP_FILENAME_MAX+1];
struct TextBuffer_manager* TextBuffer_;
// Prolog State // Prolog State
UInt BreakLevel_; UInt BreakLevel_;
Int PrologMode_; Int PrologMode_;
@ -200,10 +197,8 @@ typedef struct worker_local {
//dbase.c //dbase.c
struct db_globs* s_dbg_; struct db_globs* s_dbg_;
//eval.c //eval.c
yap_error_number matherror_;
Term mathtt_; Term mathtt_;
char* mathstring_; char* mathstring_;
yap_error_number CurrentError_;
//grow.c //grow.c
int heap_overflows_; int heap_overflows_;
Int total_heap_overflow_time_; Int total_heap_overflow_time_;

View File

@ -69,7 +69,6 @@ static void InitWorker(int wid) {
REMOTE_GlobalArenaOverflows(wid) = 0L; REMOTE_GlobalArenaOverflows(wid) = 0L;
REMOTE_ArenaOverflows(wid) = 0L; REMOTE_ArenaOverflows(wid) = 0L;
REMOTE_DepthArenas(wid) = 0; REMOTE_DepthArenas(wid) = 0;
REMOTE_ArithError(wid) = FALSE;
REMOTE_LastAssertedPred(wid) = NULL; REMOTE_LastAssertedPred(wid) = NULL;
REMOTE_TmpPred(wid) = NULL; REMOTE_TmpPred(wid) = NULL;
REMOTE_ScannerStack(wid) = NULL; REMOTE_ScannerStack(wid) = NULL;
@ -165,11 +164,7 @@ static void InitWorker(int wid) {
REMOTE_ActiveError(wid) = calloc(sizeof(yap_error_descriptor_t),1);
REMOTE_BallTerm(wid) = NULL;
@ -185,6 +180,8 @@ static void InitWorker(int wid) {
REMOTE_TextBuffer(wid) = Yap_InitTextAllocator();
REMOTE_BreakLevel(wid) = 0; REMOTE_BreakLevel(wid) = 0;
REMOTE_PrologMode(wid) = BootMode; REMOTE_PrologMode(wid) = BootMode;
REMOTE_CritLocks(wid) = 0; REMOTE_CritLocks(wid) = 0;
@ -200,10 +197,8 @@ static void InitWorker(int wid) {
REMOTE_matherror(wid) = YAP_NO_ERROR;
REMOTE_mathstring(wid) = NULL; REMOTE_mathstring(wid) = NULL;
REMOTE_CurrentError(wid) = YAP_NO_ERROR;
REMOTE_heap_overflows(wid) = 0; REMOTE_heap_overflows(wid) = 0;
REMOTE_total_heap_overflow_time(wid) = 0; REMOTE_total_heap_overflow_time(wid) = 0;

View File

@ -86,7 +86,6 @@ static void RestoreWorker(int wid USES_REGS) {
#ifdef COROUTINING #ifdef COROUTINING
@ -188,8 +187,6 @@ static void RestoreWorker(int wid USES_REGS) {
@ -214,8 +211,6 @@ static void RestoreWorker(int wid USES_REGS) {
#ifdef LOAD_DYLD #ifdef LOAD_DYLD
#endif #endif

View File

@ -1,8 +1,6 @@
/* This file was generated automatically by "yap -L misc/buildops" /* This file was generated automatically by "yap -L misc/buildops"
please do not update */ please do not update */
while (TRUE) { while (TRUE) {
op_numbers op; op_numbers op;

View File

@ -76,7 +76,6 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
#define JMP_LOCAL_ERROR(v, LAB) \ #define JMP_LOCAL_ERROR(v, LAB) \
if (H + 2 * (v) > ASP - 1024) { \ if (H + 2 * (v) > ASP - 1024) { \
LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \ LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \
LOCAL_Error_Term = t; \
LOCAL_Error_Size = 2 * (v) * sizeof(CELL); \ LOCAL_Error_Size = 2 * (v) * sizeof(CELL); \
goto LAB; \ goto LAB; \
} }
@ -84,7 +83,6 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
#define LOCAL_ERROR(t, v) \ #define LOCAL_ERROR(t, v) \
if (HR + (v) > ASP - 1024) { \ if (HR + (v) > ASP - 1024) { \
LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \ LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \
LOCAL_Error_Term = t; \
LOCAL_Error_Size = 2 * (v) * sizeof(CELL); \ LOCAL_Error_Size = 2 * (v) * sizeof(CELL); \
return NULL; \ return NULL; \
} }
@ -92,7 +90,6 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
#define LOCAL_TERM_ERROR(t, v) \ #define LOCAL_TERM_ERROR(t, v) \
if (HR + (v) > ASP - 1024) { \ if (HR + (v) > ASP - 1024) { \
LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \ LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \
LOCAL_Error_Term = t; \
LOCAL_Error_Size = 2 * (v) * sizeof(CELL); \ LOCAL_Error_Size = 2 * (v) * sizeof(CELL); \
return 0L; \ return 0L; \
} }
@ -100,7 +97,6 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
#define AUX_ERROR(t, n, s, TYPE) \ #define AUX_ERROR(t, n, s, TYPE) \
if (s + (n + 1) > (TYPE *)AuxSp) { \ if (s + (n + 1) > (TYPE *)AuxSp) { \
LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \ LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \
LOCAL_Error_Term = t; \
LOCAL_Error_Size = n * sizeof(TYPE); \ LOCAL_Error_Size = n * sizeof(TYPE); \
return NULL; \ return NULL; \
} }
@ -108,7 +104,6 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
#define AUX_TERM_ERROR(t, n, s, TYPE) \ #define AUX_TERM_ERROR(t, n, s, TYPE) \
if (s + (n + 1) > (TYPE *)AuxSp) { \ if (s + (n + 1) > (TYPE *)AuxSp) { \
LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \ LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \
LOCAL_Error_Term = t; \
LOCAL_Error_Size = n * sizeof(TYPE); \ LOCAL_Error_Size = n * sizeof(TYPE); \
return 0L; \ return 0L; \
} }
@ -116,7 +111,6 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
#define JMP_AUX_ERROR(n, s, t, TYPE, LAB) \ #define JMP_AUX_ERROR(n, s, t, TYPE, LAB) \
if (s + (n + 1) > (TYPE *)AuxSp) { \ if (s + (n + 1) > (TYPE *)AuxSp) { \
LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \ LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \
LOCAL_Error_Term = t; \
LOCAL_Error_Size = n * sizeof(TYPE); \ LOCAL_Error_Size = n * sizeof(TYPE); \
goto LAB; \ goto LAB; \
} }
@ -124,7 +118,6 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
#define HEAP_ERROR(a, TYPE) \ #define HEAP_ERROR(a, TYPE) \
if (a == NIL) { \ if (a == NIL) { \
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; \ LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; \
LOCAL_Error_Term = t; \
LOCAL_Error_Size = n * sizeof(TYPE); \ LOCAL_Error_Size = n * sizeof(TYPE); \
return NULL; \ return NULL; \
} }
@ -132,7 +125,6 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
#define HEAP_TERM_ERROR(a, TYPE, n) \ #define HEAP_TERM_ERROR(a, TYPE, n) \
if (a == NIL) { \ if (a == NIL) { \
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; \ LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; \
LOCAL_Error_Term = t; \
LOCAL_Error_Size = n * sizeof(TYPE); \ LOCAL_Error_Size = n * sizeof(TYPE); \
return 0L; \ return 0L; \
} }
@ -140,7 +132,6 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
#define JMP_HEAP_ERROR(a, n, t, TYPE, LAB) \ #define JMP_HEAP_ERROR(a, n, t, TYPE, LAB) \
if (a == NIL) { \ if (a == NIL) { \
LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; \ LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; \
LOCAL_Error_Term = t; \
LOCAL_Error_Size = n * sizeof(TYPE); \ LOCAL_Error_Size = n * sizeof(TYPE); \
goto LAB; \ goto LAB; \
} }
@ -174,6 +165,21 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
/// go back t /// go back t
} yap_error_stage_t; } yap_error_stage_t;
/// a Prolo goal that caused a bug
typedef struct error_prolog_source {
YAP_Int prologPredCl;
YAP_UInt prologPredLine;
YAP_UInt prologPredFirstLine;
YAP_UInt prologPredLastLine;
YAP_Atom prologPredName;
YAP_UInt prologPredArity;
YAP_Term prologPredModule;
YAP_Atom prologPredFile;
struct DB_TERM *errorGoal;
struct error_prolog_source *errorParent;
} error_prolog_source_t;
/// all we need to know about an error/throw /// all we need to know about an error/throw
typedef struct yap_error_descriptor { typedef struct yap_error_descriptor {
enum yap_error_status status; enum yap_error_status status;
@ -184,6 +190,7 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
YAP_Int errorLine; YAP_Int errorLine;
const char *errorFunction; const char *errorFunction;
const char *errorFile; const char *errorFile;
// struct error_prolog_source *errorSource;
YAP_Int prologPredCl; YAP_Int prologPredCl;
YAP_UInt prologPredLine; YAP_UInt prologPredLine;
YAP_UInt prologPredFirstLine; YAP_UInt prologPredFirstLine;
@ -192,22 +199,33 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
YAP_UInt prologPredArity; YAP_UInt prologPredArity;
YAP_Term prologPredModule; YAP_Term prologPredModule;
YAP_Atom prologPredFile; YAP_Atom prologPredFile;
YAP_UInt prologParserLine;
YAP_UInt prologParserFirstLine;
YAP_UInt prologParserLastLine;
YAP_Atom prologParserName;
YAP_Atom prologParserFile;
YAP_Bool prologConsulting;
struct DB_TERM *errorTerm; struct DB_TERM *errorTerm;
char errorComment[MAX_ERROR_MSG_SIZE]; char *errorMsg;
size_t errorMsgLen; size_t errorMsgLen;
struct yap_error_descriptor *top_error;
} yap_error_descriptor_t; } yap_error_descriptor_t;
/// compatibility with existing code.. /// compatibility with existing code..
#define LOCAL_Error_TYPE LOCAL_ActiveError.errorNo #define LOCAL_Error_TYPE LOCAL_ActiveError->errorNo
#define LOCAL_Error_File LOCAL_ActiveError.errorFile #define LOCAL_Error_File LOCAL_ActiveError->errorFile
#define LOCAL_Error_Function LOCAL_ActiveError.errorFunction #define LOCAL_Error_Function LOCAL_ActiveError->errorFunction
#define LOCAL_Error_Lineno LOCAL_ActiveError.errorLine #define LOCAL_Error_Lineno LOCAL_ActiveError->errorLine
#define LOCAL_Error_Size LOCAL_ActiveError.errorMsgLen #define LOCAL_Error_Size LOCAL_ActiveError->errorMsgLen
#define LOCAL_ErrorSay LOCAL_ActiveError.errorComment #define LOCAL_BallTerm LOCAL_ActiveError->errorTerm
#define LOCAL_ErrorMessage LOCAL_ActiveError->errorMsg
extern bool Yap_find_prolog_culprit(); extern bool Yap_find_prolog_culprit();
extern yap_error_class_number Yap_errorClass(yap_error_number e); extern yap_error_class_number Yap_errorClass(yap_error_number e);
extern const char *Yap_errorName(yap_error_number e); extern const char *Yap_errorName(yap_error_number e);
extern const char *Yap_errorClassName(yap_error_class_number e); extern const char *Yap_errorClassName(yap_error_class_number e);
extern void Yap_pushErrorContext(yap_error_descriptor_t * new_error);
extern yap_error_descriptor_t *Yap_popErrorContext(void);
#endif #endif

View File

@ -1193,8 +1193,7 @@ do_open(Term file_name, Term t2,
if (LOCAL_Error_TYPE != YAP_NO_ERROR) { if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG) if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG)
LOCAL_Error_TYPE = DOMAIN_ERROR_OPEN_OPTION; LOCAL_Error_TYPE = DOMAIN_ERROR_OPEN_OPTION;
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, Yap_Error(LOCAL_Error_TYPE, tlist, "option handling in open/3");
"option handling in open/3");
} }
return false; return false;
} }
@ -1700,7 +1699,7 @@ static Int close2(USES_REGS1) { /* '$close'(+GLOBAL_Stream) */
if (LOCAL_Error_TYPE != YAP_NO_ERROR) { if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG) if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG)
LOCAL_Error_TYPE = DOMAIN_ERROR_CLOSE_OPTION; LOCAL_Error_TYPE = DOMAIN_ERROR_CLOSE_OPTION;
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, tlist, NULL);
} }
return false; return false;
return FALSE; return FALSE;
@ -1762,7 +1761,7 @@ static Int abs_file_parameters(USES_REGS1) {
if (LOCAL_Error_TYPE != YAP_NO_ERROR) { if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG) if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG)
LOCAL_Error_TYPE = DOMAIN_ERROR_ABSOLUTE_FILE_NAME_OPTION; LOCAL_Error_TYPE = DOMAIN_ERROR_ABSOLUTE_FILE_NAME_OPTION;
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, tlist, NULL);
} }
return false; return false;
} }

View File

@ -24,7 +24,8 @@
#include "YapStreams.h" #include "YapStreams.h"
static inline bool IsStreamTerm(Term t) { INLINE_ONLY EXTERN inline UInt PRED_HASH(FunctorEntry *, Term, UInt);
INLINE_ONLY EXTERN inline bool IsStreamTerm(Term t) {
return !IsVarTerm(t) && return !IsVarTerm(t) &&
(IsAtomTerm(t) || (IsAtomTerm(t) ||
(IsApplTerm(t) && (FunctorOfTerm(t) == FunctorStream))); (IsApplTerm(t) && (FunctorOfTerm(t) == FunctorStream)));
@ -121,28 +122,28 @@ extern bool Yap_ReadlineOps(StreamDesc *st);
extern int Yap_OpenBufWriteStream(USES_REGS1); extern int Yap_OpenBufWriteStream(USES_REGS1);
extern void Yap_ConsoleOps(StreamDesc *s); extern void Yap_ConsoleOps(StreamDesc *s);
void Yap_InitRandomPreds(void); extern void Yap_InitRandomPreds(void);
void Yap_InitSignalPreds(void); extern void Yap_InitSignalPreds(void);
void Yap_InitTimePreds(void); extern void Yap_InitTimePreds(void);
void Yap_init_socks(char *host, long interface_port); extern void Yap_init_socks(char *host, long interface_port);
void Yap_InitPipes(void); extern void Yap_InitPipes(void);
void Yap_InitMem(void); extern void Yap_InitMem(void);
void Yap_InitSockets(void); extern void Yap_InitSockets(void);
void Yap_InitSocketLayer(void); extern void Yap_InitSocketLayer(void);
void Yap_InitMems(void); extern void Yap_InitMems(void);
void Yap_InitConsole(void); extern void Yap_InitConsole(void);
void Yap_InitReadlinePreds(void); extern void Yap_InitReadlinePreds(void);
bool Yap_InitReadline(Term); bool Yap_InitReadline(Term);
void Yap_InitChtypes(void); extern void Yap_InitChtypes(void);
void Yap_InitCharsio(void); extern void Yap_InitCharsio(void);
void Yap_InitFormat(void); extern void Yap_InitFormat(void);
void Yap_InitFiles(void); extern void Yap_InitFiles(void);
void Yap_InitIOStreams(void); extern void Yap_InitIOStreams(void);
void Yap_InitWriteTPreds(void); extern void Yap_InitWriteTPreds(void);
void Yap_InitReadTPreds(void); extern void Yap_InitReadTPreds(void);
void Yap_socketStream(StreamDesc *s); extern void Yap_socketStream(StreamDesc *s);
void Yap_ReadlineFlush(int sno); extern void Yap_ReadlineFlush(int sno);
Int Yap_ReadlinePeekChar(int sno); Int Yap_ReadlinePeekChar(int sno);
int Yap_ReadlineForSIGINT(void); int Yap_ReadlineForSIGINT(void);
bool Yap_DoPrompt(StreamDesc *s); bool Yap_DoPrompt(StreamDesc *s);
@ -150,7 +151,7 @@ bool Yap_DoPrompt(StreamDesc *s);
Int Yap_peek(int sno); Int Yap_peek(int sno);
int Yap_MemPeekc(int sno); int Yap_MemPeekc(int sno);
Term Yap_syntax_error(TokEntry *tokptr, int sno); char *Yap_syntax_error(TokEntry *tokptr, int sno);
int console_post_process_read_char(int, StreamDesc *); int console_post_process_read_char(int, StreamDesc *);
int console_post_process_eof(StreamDesc *); int console_post_process_eof(StreamDesc *);
@ -173,15 +174,15 @@ int ResetEOF(StreamDesc *s);
int EOFPeek(int sno); int EOFPeek(int sno);
int EOFWPeek(int sno); int EOFWPeek(int sno);
void Yap_SetAlias(Atom arg, int sno); extern void Yap_SetAlias(Atom arg, int sno);
bool Yap_AddAlias(Atom arg, int sno); bool Yap_AddAlias(Atom arg, int sno);
int Yap_CheckAlias(Atom arg); int Yap_CheckAlias(Atom arg);
int Yap_RemoveAlias(Atom arg, int snoinline); int Yap_RemoveAlias(Atom arg, int snoinline);
void Yap_SetAlias(Atom arg, int sno); extern void Yap_SetAlias(Atom arg, int sno);
void Yap_InitAliases(void); void Yap_InitAliases(void);
void Yap_DeleteAliases(int sno); void Yap_DeleteAliases(int sno);
bool Yap_FindStreamForAlias(Atom al); extern bool Yap_FindStreamForAlias(Atom al);
bool Yap_FetchStreamAlias(int sno, Term t2 USES_REGS); extern bool Yap_FetchStreamAlias(int sno, Term t2 USES_REGS);
INLINE_ONLY inline EXTERN void count_output_char(int ch, StreamDesc *s); INLINE_ONLY inline EXTERN void count_output_char(int ch, StreamDesc *s);
@ -270,7 +271,7 @@ extern FILE *Yap_stderr;
char *Yap_MemExportStreamPtr(int sno); char *Yap_MemExportStreamPtr(int sno);
bool Yap_Exists(const char *f); extern bool Yap_Exists(const char *f);
static inline void freeBuffer(const void *ptr) { static inline void freeBuffer(const void *ptr) {
CACHE_REGS CACHE_REGS

View File

@ -95,7 +95,7 @@ static char SccsId[] = "%W% %G%";
#define SYSTEM_STAT stat #define SYSTEM_STAT stat
#endif #endif
static Term syntax_error(TokEntry *errtok, int sno, Term cmod); static char *syntax_error(TokEntry *errtok, int sno, Term cmod);
static void clean_vars(VarEntry *p) { static void clean_vars(VarEntry *p) {
if (p == NULL) if (p == NULL)
@ -215,7 +215,7 @@ static const param_t read_defs[] = {READ_DEFS()};
* Implicit arguments: * Implicit arguments:
* + * +
*/ */
static Term syntax_error(TokEntry *errtok, int sno, Term cmod) { static char * syntax_error(TokEntry *errtok, int sno, Term cmod) {
CACHE_REGS CACHE_REGS
Term info; Term info;
Term startline, errline, endline; Term startline, errline, endline;
@ -264,76 +264,58 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) {
t0[0] = TermNil; t0[0] = TermNil;
} }
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0); ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0);
} } break;
break; case QuasiQuotes_tok: {
case QuasiQuotes_tok:
{
Term t0[2]; Term t0[2];
t0[0] = MkAtomTerm(Yap_LookupAtom("<QQ>")); t0[0] = MkAtomTerm(Yap_LookupAtom("<QQ>"));
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0); ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0);
} } break;
break; case WQuasiQuotes_tok: {
case WQuasiQuotes_tok:
{
Term t0[2]; Term t0[2];
t0[0] = MkAtomTerm(Yap_LookupAtom("<WideQQ>")); t0[0] = MkAtomTerm(Yap_LookupAtom("<WideQQ>"));
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0); ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0);
} } break;
break;
case Number_tok: case Number_tok:
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomNumber, 1), 1, &(tok->TokInfo)); ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomNumber, 1), 1, &(tok->TokInfo));
break; break;
case Var_tok: case Var_tok: {
{
Term t[2]; Term t[2];
VarEntry *varinfo = (VarEntry *)info; VarEntry *varinfo = (VarEntry *)info;
t[0] = MkIntTerm(0); t[0] = MkIntTerm(0);
t[1] = Yap_CharsToString(varinfo->VarRep, ENC_ISO_LATIN1 PASS_REGS); t[1] = Yap_CharsToString(varinfo->VarRep, ENC_ISO_LATIN1 PASS_REGS);
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomGVar, 2), 2, t); ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomGVar, 2), 2, t);
} } break;
break; case String_tok: {
case String_tok:
{
Term t0 = Yap_CharsToTDQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS); Term t0 = Yap_CharsToTDQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS);
if (!t0) { if (!t0) {
return 0; return 0;
} }
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0); ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
} } break;
break; case WString_tok: {
case WString_tok:
{
Term t0 = Yap_WCharsToTDQ((wchar_t *)info, cmod PASS_REGS); Term t0 = Yap_WCharsToTDQ((wchar_t *)info, cmod PASS_REGS);
if (!t0) if (!t0)
return 0; return 0;
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0); ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
} } break;
break; case BQString_tok: {
case BQString_tok:
{
Term t0 = Yap_CharsToTBQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS); Term t0 = Yap_CharsToTBQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS);
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0); ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
} } break;
break; case WBQString_tok: {
case WBQString_tok:
{
Term t0 = Yap_WCharsToTBQ((wchar_t *)info, cmod PASS_REGS); Term t0 = Yap_WCharsToTBQ((wchar_t *)info, cmod PASS_REGS);
ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0); ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0);
} } break;
break; case Error_tok: {
case Error_tok:
{
ts[0] = MkAtomTerm(AtomError); ts[0] = MkAtomTerm(AtomError);
} } break;
break;
case eot_tok: case eot_tok:
endline = MkIntegerTerm(tok->TokPos); endline = MkIntegerTerm(tok->TokPos);
ts[0] = MkAtomTerm(Yap_LookupAtom("EOT")); ts[0] = MkAtomTerm(Yap_LookupAtom("EOT"));
break; break;
case Ponctuation_tok: case Ponctuation_tok: {
{
char s[2]; char s[2];
s[1] = '\0'; s[1] = '\0';
if ((info) == 'l') { if ((info) == 'l') {
@ -379,10 +361,10 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) {
Yap_DebugPlWriteln(terr); Yap_DebugPlWriteln(terr);
} }
#endif #endif
return terr; return NULL;
} }
Term Yap_syntax_error(TokEntry *errtok, int sno) { char * Yap_syntax_error(TokEntry *errtok, int sno) {
return syntax_error(errtok, sno, CurrentModule); return syntax_error(errtok, sno, CurrentModule);
} }
@ -790,10 +772,10 @@ static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream,
fe->args = setReadEnv(opts, fe, re, inp_stream); fe->args = setReadEnv(opts, fe, re, inp_stream);
} }
if (fe->args == NULL) { if (fe->args == NULL) {
if (LOCAL_Error_TYPE == DOMAIN_ERROR_READ_OPTION) if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE)
LOCAL_Error_TYPE = DOMAIN_ERROR_READ_OPTION; LOCAL_Error_TYPE = DOMAIN_ERROR_READ_OPTION;
if (LOCAL_Error_TYPE) if (LOCAL_Error_TYPE)
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, opts, NULL);
fe->t = 0; fe->t = 0;
return YAP_PARSING_FINISHED; return YAP_PARSING_FINISHED;
; ;
@ -828,7 +810,6 @@ static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) {
strncpy(out, "Empty clause", len); strncpy(out, "Empty clause", len);
LOCAL_ErrorMessage = out; LOCAL_ErrorMessage = out;
LOCAL_Error_TYPE = SYNTAX_ERROR; LOCAL_Error_TYPE = SYNTAX_ERROR;
LOCAL_Error_Term = TermEof;
return YAP_PARSING_ERROR; return YAP_PARSING_ERROR;
} }
return scanEOF(fe, inp_stream); return scanEOF(fe, inp_stream);
@ -889,13 +870,14 @@ static parser_state_t parseError(REnv *re, FEnv *fe, int inp_stream) {
LOCAL_Error_TYPE = YAP_NO_ERROR; LOCAL_Error_TYPE = YAP_NO_ERROR;
return YAP_PARSING_FINISHED; return YAP_PARSING_FINISHED;
} else { } else {
Term terr = syntax_error(fe->toklast, inp_stream, fe->cmod); const char*s = syntax_error(fe->toklast, inp_stream, fe->cmod);
if (ParserErrorStyle == TermError) { if (ParserErrorStyle == TermError) {
LOCAL_ErrorMessage = NULL; LOCAL_ErrorMessage = s;
LOCAL_Error_TYPE = SYNTAX_ERROR; LOCAL_Error_TYPE = SYNTAX_ERROR;
return YAP_PARSING_FINISHED; return YAP_PARSING_FINISHED;
// dec-10 // dec-10
} else if (Yap_PrintWarning(terr)) { } else if (Yap_PrintWarning(MkStringTerm(s))) {
free(s);
LOCAL_Error_TYPE = YAP_NO_ERROR; LOCAL_Error_TYPE = YAP_NO_ERROR;
return YAP_SCANNING; return YAP_SCANNING;
} }
@ -961,8 +943,7 @@ Term Yap_read_term(int inp_stream, Term opts, int nargs) {
case YAP_PARSING_ERROR: case YAP_PARSING_ERROR:
state = parseError(&re, &fe, inp_stream); state = parseError(&re, &fe, inp_stream);
break; break;
case YAP_PARSING_FINISHED: case YAP_PARSING_FINISHED: {
{
CACHE_REGS CACHE_REGS
bool done; bool done;
if (fe.reading_clause) if (fe.reading_clause)
@ -1165,7 +1146,8 @@ static Int read_clause(
/** /**
* @pred source_location( - _File_ , _Line_ ) * @pred source_location( - _File_ , _Line_ )
* *
* unify _File_ and _Line_ wuth the position of the last term read, if the term * unify _File_ and _Line_ wuth the position of the last term read, if the
*term
* comes from a stream created by opening a file-system path with open/3 and * comes from a stream created by opening a file-system path with open/3 and
*friends.>position *friends.>position
* It ignores user_input or * It ignores user_input or

View File

@ -1,7 +1,6 @@
#include "sysbits.h" #include "sysbits.h"
#if HAVE_SIGINFO_H #if HAVE_SIGINFO_H
#include <siginfo.h> #include <siginfo.h>
#endif #endif
@ -15,7 +14,6 @@
#define SIG_PROLOG_OFFSET 32 /* Start of Prolog signals */ #define SIG_PROLOG_OFFSET 32 /* Start of Prolog signals */
#define SIG_EXCEPTION (SIG_PROLOG_OFFSET + 0) #define SIG_EXCEPTION (SIG_PROLOG_OFFSET + 0)
#ifdef O_ATOMGC #ifdef O_ATOMGC
#define SIG_ATOM_GC (SIG_PROLOG_OFFSET + 1) #define SIG_ATOM_GC (SIG_PROLOG_OFFSET + 1)
@ -27,12 +25,11 @@
#define SIG_FREECLAUSES (SIG_PROLOG_OFFSET + 4) #define SIG_FREECLAUSES (SIG_PROLOG_OFFSET + 4)
#define SIG_PLABORT (SIG_PROLOG_OFFSET + 5) #define SIG_PLABORT (SIG_PROLOG_OFFSET + 5)
static struct signame static struct signame {
{ int sig; int sig;
const char *name; const char *name;
int flags; int flags;
} signames[] = } signames[] = {
{
#ifdef SIGHUP #ifdef SIGHUP
{SIGHUP, "hup", 0}, {SIGHUP, "hup", 0},
#endif #endif
@ -122,7 +119,6 @@ static struct signame
{-1, NULL, 0}}; {-1, NULL, 0}};
#if HAVE_SIGACTION #if HAVE_SIGACTION
static void my_signal_info(int sig, void *handler) { static void my_signal_info(int sig, void *handler) {
struct sigaction sigact; struct sigaction sigact;
@ -160,15 +156,13 @@ static void my_signal_info(int sig, void *handler) {
#endif #endif
static void HandleMatherr(int sig, void *sipv, void *uapv) { static void HandleMatherr(int sig, void *sipv, void *uapv) {
CACHE_REGS CACHE_REGS
LOCAL_matherror = Yap_MathException(); LOCAL_Error_TYPE = Yap_MathException();
/* reset the registers so that we don't have trash in abstract machine */ /* reset the registers so that we don't have trash in abstract machine */
Yap_external_signal(worker_id, YAP_FPE_SIGNAL); Yap_external_signal(worker_id, YAP_FPE_SIGNAL);
} }
/* SWI emulation */ /* SWI emulation */
int Yap_signal_index(const char *name) { int Yap_signal_index(const char *name) {
struct signame *sn = signames; struct signame *sn = signames;
@ -318,10 +312,8 @@ static bool set_fpu_exceptions(Term flag) {
return true; return true;
} }
#if !defined(LIGHT) && !_MSC_VER && !defined(__MINGW32__) #if !defined(LIGHT) && !_MSC_VER && !defined(__MINGW32__)
static void ReceiveSignal(int s, void *x, void *y) { static void ReceiveSignal(int s, void *x, void *y) {
CACHE_REGS CACHE_REGS
LOCAL_PrologMode |= InterruptMode; LOCAL_PrologMode |= InterruptMode;
@ -412,7 +404,6 @@ static BOOL WINAPI MSCHandleSignal(DWORD dwCtrlType) {
} }
#endif #endif
/* wrapper for alarm system call */ /* wrapper for alarm system call */
#if _MSC_VER || defined(__MINGW32__) #if _MSC_VER || defined(__MINGW32__)
@ -671,7 +662,6 @@ VaxFixFrame(dummy) {
#if defined(_WIN32) #if defined(_WIN32)
int WINAPI win_yap(HANDLE, DWORD, LPVOID); int WINAPI win_yap(HANDLE, DWORD, LPVOID);
int WINAPI win_yap(HANDLE hinst, DWORD reason, LPVOID reserved) { int WINAPI win_yap(HANDLE hinst, DWORD reason, LPVOID reserved) {
@ -821,15 +811,7 @@ yap_error_number Yap_MathException__(USES_REGS1) {
set_fpu_exceptions(0); set_fpu_exceptions(0);
#endif #endif
return LOCAL_matherror; return LOCAL_Error_TYPE;
}
static Int fpe_error(USES_REGS1) {
Yap_Error(LOCAL_matherror, LOCAL_mathtt, LOCAL_mathstring);
LOCAL_matherror = YAP_NO_ERROR;
LOCAL_mathtt = TermNil;
LOCAL_mathstring = NULL;
return FALSE;
} }
/* SIGINT can cause problems, if caught before full initialization */ /* SIGINT can cause problems, if caught before full initialization */
@ -865,18 +847,11 @@ void Yap_InitOSSignals(int wid) {
} }
} }
bool Yap_set_fpu_exceptions(Term flag) { return set_fpu_exceptions(flag); }
bool Yap_set_fpu_exceptions(Term flag) {
return set_fpu_exceptions(flag);
}
void Yap_InitSignalPreds(void) { void Yap_InitSignalPreds(void) {
CACHE_REGS CACHE_REGS
Term cm = CurrentModule; Term cm = CurrentModule;
Yap_InitCPred("$fpe_error", 0, fpe_error, 0);
Yap_InitCPred("$alarm", 4, alarm4, SafePredFlag | SyncPredFlag); Yap_InitCPred("$alarm", 4, alarm4, SafePredFlag | SyncPredFlag);
CurrentModule = HACKS_MODULE; CurrentModule = HACKS_MODULE;
Yap_InitCPred("virtual_alarm", 4, virtual_alarm, SafePredFlag | SyncPredFlag); Yap_InitCPred("virtual_alarm", 4, virtual_alarm, SafePredFlag | SyncPredFlag);

View File

@ -41,7 +41,6 @@
#endif #endif
#endif #endif
#ifdef HAVE_UNISTD_H #ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif

267
os/time.c
View File

@ -45,16 +45,18 @@ static struct timeval StartOfTimes_sys;
#endif #endif
/* store user time in this variable */ /* store user time in this variable */
void void Yap_InitTime(int wid) {
Yap_InitTime (int wid)
{
struct rusage rusage; struct rusage rusage;
#if THREADS #if THREADS
REMOTE_ThreadHandle(wid).start_of_timesp = (struct timeval *)malloc(sizeof(struct timeval)); REMOTE_ThreadHandle(wid).start_of_timesp =
REMOTE_ThreadHandle(wid).last_timep = (struct timeval *)malloc(sizeof(struct timeval)); (struct timeval *)malloc(sizeof(struct timeval));
REMOTE_ThreadHandle(wid).start_of_times_sysp = (struct timeval *)malloc(sizeof(struct timeval)); REMOTE_ThreadHandle(wid).last_timep =
REMOTE_ThreadHandle(wid).last_time_sysp = (struct timeval *)malloc(sizeof(struct timeval)); (struct timeval *)malloc(sizeof(struct timeval));
REMOTE_ThreadHandle(wid).start_of_times_sysp =
(struct timeval *)malloc(sizeof(struct timeval));
REMOTE_ThreadHandle(wid).last_time_sysp =
(struct timeval *)malloc(sizeof(struct timeval));
getrusage(RUSAGE_SELF, &rusage); getrusage(RUSAGE_SELF, &rusage);
(*REMOTE_ThreadHandle(wid).last_timep).tv_sec = (*REMOTE_ThreadHandle(wid).last_timep).tv_sec =
(*REMOTE_ThreadHandle(wid).start_of_timesp).tv_sec = (*REMOTE_ThreadHandle(wid).start_of_timesp).tv_sec =
@ -70,25 +72,14 @@ Yap_InitTime (int wid)
rusage.ru_stime.tv_usec; rusage.ru_stime.tv_usec;
#else #else
getrusage(RUSAGE_SELF, &rusage); getrusage(RUSAGE_SELF, &rusage);
last_time.tv_sec = last_time.tv_sec = StartOfTimes.tv_sec = rusage.ru_utime.tv_sec;
StartOfTimes.tv_sec = last_time.tv_usec = StartOfTimes.tv_usec = rusage.ru_utime.tv_usec;
rusage.ru_utime.tv_sec; last_time_sys.tv_sec = StartOfTimes_sys.tv_sec = rusage.ru_stime.tv_sec;
last_time.tv_usec = last_time_sys.tv_usec = StartOfTimes_sys.tv_usec = rusage.ru_stime.tv_usec;
StartOfTimes.tv_usec =
rusage.ru_utime.tv_usec;
last_time_sys.tv_sec =
StartOfTimes_sys.tv_sec =
rusage.ru_stime.tv_sec;
last_time_sys.tv_usec =
StartOfTimes_sys.tv_usec =
rusage.ru_stime.tv_usec;
#endif #endif
} }
UInt Yap_cputime(void) {
UInt
Yap_cputime ( void )
{
CACHE_REGS CACHE_REGS
struct rusage rusage; struct rusage rusage;
@ -97,8 +88,7 @@ Yap_cputime ( void )
((rusage.ru_utime.tv_usec - StartOfTimes.tv_usec) / 1000); ((rusage.ru_utime.tv_usec - StartOfTimes.tv_usec) / 1000);
} }
void Yap_cputime_interval(Int *now,Int *interval) void Yap_cputime_interval(Int *now, Int *interval) {
{
CACHE_REGS CACHE_REGS
struct rusage rusage; struct rusage rusage;
@ -111,8 +101,7 @@ void Yap_cputime_interval(Int *now,Int *interval)
last_time.tv_sec = rusage.ru_utime.tv_sec; last_time.tv_sec = rusage.ru_utime.tv_sec;
} }
void Yap_systime_interval(Int *now,Int *interval) void Yap_systime_interval(Int *now, Int *interval) {
{
CACHE_REGS CACHE_REGS
struct rusage rusage; struct rusage rusage;
@ -132,7 +121,8 @@ void Yap_systime_interval(Int *now,Int *interval)
/* This is stolen from the Linux kernel. /* This is stolen from the Linux kernel.
The problem is that mingw32 does not seem to have acces to div */ The problem is that mingw32 does not seem to have acces to div */
#ifndef do_div #ifndef do_div
#define do_div(n,base) ({ \ #define do_div(n, base) \
({ \
unsigned long __upper, __low, __high, __mod; \ unsigned long __upper, __low, __high, __mod; \
asm("" : "=a"(__low), "=d"(__high) : "A"(n)); \ asm("" : "=a"(__low), "=d"(__high) : "A"(n)); \
__upper = __high; \ __upper = __high; \
@ -140,7 +130,9 @@ void Yap_systime_interval(Int *now,Int *interval)
__upper = __high % (base); \ __upper = __high % (base); \
__high = __high / (base); \ __high = __high / (base); \
} \ } \
asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (base), "0" (__low), "1" (__upper)); \ asm("divl %2" \
: "=a"(__low), "=d"(__mod) \
: "rm"(base), "0"(__low), "1"(__upper)); \
asm("" : "=A"(n) : "a"(__low), "d"(__high)); \ asm("" : "=A"(n) : "a"(__low), "d"(__high)); \
__mod; \ __mod; \
}) })
@ -148,8 +140,6 @@ void Yap_systime_interval(Int *now,Int *interval)
#endif #endif
#include <time.h> #include <time.h>
static FILETIME StartOfTimes, last_time; static FILETIME StartOfTimes, last_time;
@ -159,22 +149,25 @@ static FILETIME StartOfTimes_sys, last_time_sys;
static clock_t TimesStartOfTimes, Times_last_time; static clock_t TimesStartOfTimes, Times_last_time;
/* store user time in this variable */ /* store user time in this variable */
void void Yap_InitTime(int wid) {
Yap_InitTime (int wid)
{
HANDLE hProcess = GetCurrentProcess(); HANDLE hProcess = GetCurrentProcess();
FILETIME CreationTime, ExitTime, KernelTime, UserTime; FILETIME CreationTime, ExitTime, KernelTime, UserTime;
if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) { if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime,
&UserTime)) {
/* WIN98 */ /* WIN98 */
clock_t t; clock_t t;
t = clock(); t = clock();
Times_last_time = TimesStartOfTimes = t; Times_last_time = TimesStartOfTimes = t;
} else { } else {
#if THREADS #if THREADS
REMOTE_ThreadHandle(wid).start_of_timesp = (struct _FILETIME *)malloc(sizeof(FILETIME)); REMOTE_ThreadHandle(wid).start_of_timesp =
REMOTE_ThreadHandle(wid).last_timep = (struct _FILETIME *)malloc(sizeof(FILETIME)); (struct _FILETIME *)malloc(sizeof(FILETIME));
REMOTE_ThreadHandle(wid).start_of_times_sysp = (struct _FILETIME *)malloc(sizeof(FILETIME)); REMOTE_ThreadHandle(wid).last_timep =
REMOTE_ThreadHandle(wid).last_time_sysp = (struct _FILETIME *)malloc(sizeof(FILETIME)); (struct _FILETIME *)malloc(sizeof(FILETIME));
REMOTE_ThreadHandle(wid).start_of_times_sysp =
(struct _FILETIME *)malloc(sizeof(FILETIME));
REMOTE_ThreadHandle(wid).last_time_sysp =
(struct _FILETIME *)malloc(sizeof(FILETIME));
(*REMOTE_ThreadHandle(wid).last_timep).dwLowDateTime = (*REMOTE_ThreadHandle(wid).last_timep).dwLowDateTime =
UserTime.dwLowDateTime; UserTime.dwLowDateTime;
(*REMOTE_ThreadHandle(wid).last_timep).dwHighDateTime = (*REMOTE_ThreadHandle(wid).last_timep).dwHighDateTime =
@ -192,51 +185,38 @@ Yap_InitTime (int wid)
(*REMOTE_ThreadHandle(wid).start_of_times_sysp).dwHighDateTime = (*REMOTE_ThreadHandle(wid).start_of_times_sysp).dwHighDateTime =
KernelTime.dwHighDateTime; KernelTime.dwHighDateTime;
#else #else
last_time.dwLowDateTime = last_time.dwLowDateTime = UserTime.dwLowDateTime;
UserTime.dwLowDateTime; last_time.dwHighDateTime = UserTime.dwHighDateTime;
last_time.dwHighDateTime = StartOfTimes.dwLowDateTime = UserTime.dwLowDateTime;
UserTime.dwHighDateTime; StartOfTimes.dwHighDateTime = UserTime.dwHighDateTime;
StartOfTimes.dwLowDateTime = last_time_sys.dwLowDateTime = KernelTime.dwLowDateTime;
UserTime.dwLowDateTime; last_time_sys.dwHighDateTime = KernelTime.dwHighDateTime;
StartOfTimes.dwHighDateTime = StartOfTimes_sys.dwLowDateTime = KernelTime.dwLowDateTime;
UserTime.dwHighDateTime; StartOfTimes_sys.dwHighDateTime = KernelTime.dwHighDateTime;
last_time_sys.dwLowDateTime =
KernelTime.dwLowDateTime;
last_time_sys.dwHighDateTime =
KernelTime.dwHighDateTime;
StartOfTimes_sys.dwLowDateTime =
KernelTime.dwLowDateTime;
StartOfTimes_sys.dwHighDateTime =
KernelTime.dwHighDateTime;
#endif #endif
} }
} }
#ifdef __GNUC__ #ifdef __GNUC__
static unsigned long long int static unsigned long long int sub_utime(FILETIME t1, FILETIME t2) {
sub_utime(FILETIME t1, FILETIME t2)
{
ULARGE_INTEGER u[2]; ULARGE_INTEGER u[2];
memcpy((void *)u, (void *)&t1, sizeof(FILETIME)); memcpy((void *)u, (void *)&t1, sizeof(FILETIME));
memcpy((void *)(u + 1), (void *)&t2, sizeof(FILETIME)); memcpy((void *)(u + 1), (void *)&t2, sizeof(FILETIME));
return return u[0].QuadPart - u[1].QuadPart;
u[0].QuadPart - u[1].QuadPart;
} }
#endif #endif
UInt UInt Yap_cputime(void) {
Yap_cputime ( void )
{
HANDLE hProcess = GetCurrentProcess(); HANDLE hProcess = GetCurrentProcess();
FILETIME CreationTime, ExitTime, KernelTime, UserTime; FILETIME CreationTime, ExitTime, KernelTime, UserTime;
if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) { if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime,
&UserTime)) {
clock_t t; clock_t t;
t = clock(); t = clock();
return (((t - TimesStartOfTimes) * 1000) / CLOCKS_PER_SEC); return (((t - TimesStartOfTimes) * 1000) / CLOCKS_PER_SEC);
} else { } else {
#ifdef __GNUC__ #ifdef __GNUC__
unsigned long long int t = unsigned long long int t = sub_utime(UserTime, StartOfTimes);
sub_utime(UserTime,StartOfTimes);
do_div(t, 10000); do_div(t, 10000);
return ((Int)t); return ((Int)t);
#endif #endif
@ -247,11 +227,11 @@ Yap_cputime ( void )
} }
} }
void Yap_cputime_interval(Int *now,Int *interval) void Yap_cputime_interval(Int *now, Int *interval) {
{
HANDLE hProcess = GetCurrentProcess(); HANDLE hProcess = GetCurrentProcess();
FILETIME CreationTime, ExitTime, KernelTime, UserTime; FILETIME CreationTime, ExitTime, KernelTime, UserTime;
if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) { if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime,
&UserTime)) {
clock_t t; clock_t t;
t = clock(); t = clock();
*now = ((t - TimesStartOfTimes) * 1000) / CLOCKS_PER_SEC; *now = ((t - TimesStartOfTimes) * 1000) / CLOCKS_PER_SEC;
@ -259,10 +239,8 @@ void Yap_cputime_interval(Int *now,Int *interval)
Times_last_time = t; Times_last_time = t;
} else { } else {
#ifdef __GNUC__ #ifdef __GNUC__
unsigned long long int t1 = unsigned long long int t1 = sub_utime(UserTime, StartOfTimes);
sub_utime(UserTime, StartOfTimes); unsigned long long int t2 = sub_utime(UserTime, last_time);
unsigned long long int t2 =
sub_utime(UserTime, last_time);
do_div(t1, 10000); do_div(t1, 10000);
*now = (Int)t1; *now = (Int)t1;
do_div(t2, 10000); do_div(t2, 10000);
@ -279,18 +257,16 @@ void Yap_cputime_interval(Int *now,Int *interval)
} }
} }
void Yap_systime_interval(Int *now,Int *interval) void Yap_systime_interval(Int *now, Int *interval) {
{
HANDLE hProcess = GetCurrentProcess(); HANDLE hProcess = GetCurrentProcess();
FILETIME CreationTime, ExitTime, KernelTime, UserTime; FILETIME CreationTime, ExitTime, KernelTime, UserTime;
if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) { if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime,
&UserTime)) {
*now = *interval = 0; /* not available */ *now = *interval = 0; /* not available */
} else { } else {
#ifdef __GNUC__ #ifdef __GNUC__
unsigned long long int t1 = unsigned long long int t1 = sub_utime(KernelTime, StartOfTimes_sys);
sub_utime(KernelTime, StartOfTimes_sys); unsigned long long int t2 = sub_utime(KernelTime, last_time_sys);
unsigned long long int t2 =
sub_utime(KernelTime, last_time_sys);
do_div(t1, 10000); do_div(t1, 10000);
*now = (Int)t1; *now = (Int)t1;
do_div(t2, 10000); do_div(t2, 10000);
@ -332,7 +308,8 @@ void Yap_systime_interval(Int *now,Int *interval)
#define TicksPerSec CLK_TCK #define TicksPerSec CLK_TCK
#endif #endif
#if defined(__alpha) || defined(__FreeBSD__) || defined(__linux__) || defined(__DragonFly__) #if defined(__alpha) || defined(__FreeBSD__) || defined(__linux__) || \
defined(__DragonFly__)
#if HAVE_TIME_H #if HAVE_TIME_H
#include <time.h> #include <time.h>
@ -353,25 +330,20 @@ static clock_t StartOfTimes, last_time;
static clock_t StartOfTimes_sys, last_time_sys; static clock_t StartOfTimes_sys, last_time_sys;
/* store user time in this variable */ /* store user time in this variable */
static void static void InitTime(void) {
InitTime (void)
{
struct tms t; struct tms t;
times(&t); times(&t);
(*REMOTE_ThreadHandle(wid).last_timep) = StartOfTimes = t.tms_utime; (*REMOTE_ThreadHandle(wid).last_timep) = StartOfTimes = t.tms_utime;
last_time_sys = StartOfTimes_sys = t.tms_stime; last_time_sys = StartOfTimes_sys = t.tms_stime;
} }
UInt UInt Yap_cputime(void) {
Yap_cputime (void)
{
struct tms t; struct tms t;
times(&t); times(&t);
return ((t.tms_utime - StartOfTimes) * 1000 / TicksPerSec); return ((t.tms_utime - StartOfTimes) * 1000 / TicksPerSec);
} }
void Yap_cputime_interval(Int *now,Int *interval) void Yap_cputime_interval(Int *now, Int *interval) {
{
struct tms t; struct tms t;
times(&t); times(&t);
*now = ((t.tms_utime - StartOfTimes) * 1000) / TicksPerSec; *now = ((t.tms_utime - StartOfTimes) * 1000) / TicksPerSec;
@ -379,8 +351,7 @@ void Yap_cputime_interval(Int *now,Int *interval)
last_time = t.tms_utime; last_time = t.tms_utime;
} }
void Yap_systime_interval(Int *now,Int *interval) void Yap_systime_interval(Int *now, Int *interval) {
{
struct tms t; struct tms t;
times(&t); times(&t);
*now = ((t.tms_stime - StartOfTimes_sys) * 1000) / TicksPerSec; *now = ((t.tms_stime - StartOfTimes_sys) * 1000) / TicksPerSec;
@ -401,20 +372,17 @@ static struct timeval StartOfTimes;
static struct timeval last_time; static struct timeval last_time;
/* store user time in this variable */ /* store user time in this variable */
static void static void InitTime(int wid) {
InitTime (int wid)
{
struct timeval tp; struct timeval tp;
gettimeofday(&tp, NULL); gettimeofday(&tp, NULL);
(*REMOTE_ThreadHandle(wid).last_timep).tv_sec = (*REMOTE_ThreadHandle.start_of_timesp(wid)).tv_sec = tp.tv_sec; (*REMOTE_ThreadHandle(wid).last_timep).tv_sec =
(*REMOTE_ThreadHandle(wid).last_timep).tv_usec = (*REMOTE_ThreadHandle.start_of_timesp(wid)).tv_usec = tp.tv_usec; (*REMOTE_ThreadHandle.start_of_timesp(wid)).tv_sec = tp.tv_sec;
(*REMOTE_ThreadHandle(wid).last_timep).tv_usec =
(*REMOTE_ThreadHandle.start_of_timesp(wid)).tv_usec = tp.tv_usec;
} }
UInt Yap_cputime(void) {
UInt
Yap_cputime (void)
{
struct timeval tp; struct timeval tp;
gettimeofday(&tp, NULL); gettimeofday(&tp, NULL);
@ -426,8 +394,7 @@ Yap_cputime (void)
((tp.tv_usec - StartOfTimes.tv_usec) / 1000); ((tp.tv_usec - StartOfTimes.tv_usec) / 1000);
} }
void Yap_cputime_interval(Int *now,Int *interval) void Yap_cputime_interval(Int *now, Int *interval) {
{
struct timeval tp; struct timeval tp;
gettimeofday(&tp, NULL); gettimeofday(&tp, NULL);
@ -439,8 +406,7 @@ void Yap_cputime_interval(Int *now,Int *interval)
last_time.tv_sec = tp.tv_sec; last_time.tv_sec = tp.tv_sec;
} }
void Yap_systime_interval(Int *now,Int *interval) void Yap_systime_interval(Int *now, Int *interval) {
{
*now = *interval = 0; /* not available */ *now = *interval = 0; /* not available */
} }
@ -450,16 +416,12 @@ void Yap_systime_interval(Int *now,Int *interval)
/* This code is not working properly. I left it here to help future ports */ /* This code is not working properly. I left it here to help future ports */
#ifdef MPW #ifdef MPW
#include <files.h>
#include <Events.h> #include <Events.h>
#include <files.h>
#define TicksPerSec 60.0 #define TicksPerSec 60.0
static double static double real_cputime() { return (((double)TickCount()) / TicksPerSec); }
real_cputime ()
{
return (((double) TickCount ()) / TicksPerSec);
}
#endif /* MPW */ #endif /* MPW */
@ -469,14 +431,9 @@ real_cputime ()
static long *ptime; static long *ptime;
gettime () gettime() { *ptime = *(long *)0x462; }
{
*ptime = *(long *) 0x462;
}
static double static double real_cputime() {
real_cputime ()
{
long thetime; long thetime;
ptime = &thetime; ptime = &thetime;
xbios(38, gettime); xbios(38, gettime);
@ -492,15 +449,9 @@ real_cputime ()
static long *ptime; static long *ptime;
static long static long readtime() { return (*((long *)0x4ba)); }
readtime ()
{
return (*((long *) 0x4ba));
}
static double static double real_cputime() {
real_cputime ()
{
long time; long time;
time = Supexec(readtime); time = Supexec(readtime);
@ -518,11 +469,7 @@ real_cputime ()
#define TicksPerSec 60.0 #define TicksPerSec 60.0
static double static double real_cputime() { return (((double)TickCount()) / TicksPerSec); }
real_cputime ()
{
return (((double) TickCount ()) / TicksPerSec);
}
#endif /* LIGHT */ #endif /* LIGHT */
@ -540,48 +487,35 @@ uint64_t Yap_StartOfWTimes;
/* since the point YAP was started */ /* since the point YAP was started */
void void Yap_InitWTime(void) { Yap_StartOfWTimes = (uint64_t)gethrtime(); }
Yap_InitWTime (void)
{
Yap_StartOfWTimes = (uint64_t)gethrtime();
}
/// returns time since Jan 1 1980 in nano-seconds /// returns time since Jan 1 1980 in nano-seconds
uint64_t Yap_walltime(uint64_t old) uint64_t Yap_walltime(uint64_t old) {
{
hrtime_t tp = gethrtime(); hrtime_t tp = gethrtime();
/* return time in milliseconds */ /* return time in milliseconds */
return = (uint64_t)tp; return (uint64_t)tp;
} }
#elif HAVE_GETTIMEOFDAY #elif HAVE_GETTIMEOFDAY
/* since the point YAP was started */ /* since the point YAP was started */
/* store user time in this variable */ /* store user time in this variable */
void void Yap_InitWTime(void) {
Yap_InitWTime (void)
{
struct timeval tp; struct timeval tp;
gettimeofday(&tp, NULL); gettimeofday(&tp, NULL);
Yap_StartOfWTimes = (uint64_t)tp.tv_sec * 1000000000 + (uint64_t)tp.tv_usec * 1000; Yap_StartOfWTimes =
(uint64_t)tp.tv_sec * 1000000000 + (uint64_t)tp.tv_usec * 1000;
} }
/// returns time in nano-secs since the epoch /// returns time in nano-secs since the epoch
uint64_t uint64_t Yap_walltime(void) {
Yap_walltime(void)
{
struct timeval tp; struct timeval tp;
gettimeofday(&tp, NULL); gettimeofday(&tp, NULL);
return (uint64_t)tp.tv_sec * 1000000000 + (uint64_t)tp.tv_usec * 1000; return (uint64_t)tp.tv_sec * 1000000000 + (uint64_t)tp.tv_usec * 1000;
} }
#elif defined(_WIN32) #elif defined(_WIN32)
#include <sys/timeb.h> #include <sys/timeb.h>
@ -591,9 +525,7 @@ Yap_walltime(void)
static LARGE_INTEGER Frequency; static LARGE_INTEGER Frequency;
/* store user time in this variable */ /* store user time in this variable */
void void Yap_InitWTime(void) {
Yap_InitWTime (void)
{
LARGE_INTEGER ElapsedNanoseconds; LARGE_INTEGER ElapsedNanoseconds;
QueryPerformanceFrequency(&Frequency); QueryPerformanceFrequency(&Frequency);
QueryPerformanceCounter(&ElapsedNanoseconds); QueryPerformanceCounter(&ElapsedNanoseconds);
@ -602,11 +534,7 @@ Yap_InitWTime (void)
Yap_StartOfWTimes = (uint64_t)ElapsedNanoseconds.QuadPart; Yap_StartOfWTimes = (uint64_t)ElapsedNanoseconds.QuadPart;
} }
uint64_t Yap_walltime(void) {
uint64_t
Yap_walltime (void)
{
LARGE_INTEGER ElapsedNanoseconds; LARGE_INTEGER ElapsedNanoseconds;
QueryPerformanceCounter(&ElapsedNanoseconds); QueryPerformanceCounter(&ElapsedNanoseconds);
// //
@ -625,33 +553,22 @@ Yap_walltime (void)
#elif HAVE_TIMES #elif HAVE_TIMES
/* store user time in this variable */ /* store user time in this variable */
void void Yap_InitWTime(void) {
Yap_InitWTime (void)
{
// start thread 0 // start thread 0
REMOTE_LastWTime(0) = REMOTE_LastWTime(0) = Yap_StartOfWTimes =
Yap_StartOfWTimes = ((uint64_t)times(NULL))*10000000/TicksPerSec; ((uint64_t)times(NULL)) * 10000000 / TicksPerSec;
} }
uint64_t uint64_t Yap_walltime(void) {
Yap_walltime (void)
{
clock_t t; clock_t t;
t = times(NULL); t = times(NULL);
return = ((uint64_t)times(NULL)) * 10000000 / TicksPerSec; return = ((uint64_t)times(NULL)) * 10000000 / TicksPerSec;
} }
#endif /* HAVE_TIMES */ #endif /* HAVE_TIMES */
void void Yap_ReInitWTime(void) { Yap_InitWTime(); }
Yap_ReInitWTime (void)
{
Yap_InitWTime();
}
void Yap_InitTimePreds(void) {
void
Yap_InitTimePreds(void)
{
/* can only do after heap is initialized */ /* can only do after heap is initialized */
Yap_InitWTime(); Yap_InitWTime();
} }

View File

@ -88,7 +88,6 @@ static char SccsId[] = "%W% %G%";
#endif #endif
#include "iopreds.h" #include "iopreds.h"
static Term readFromBuffer(const char *s, Term opts) { static Term readFromBuffer(const char *s, Term opts) {
Term rval; Term rval;
int sno; int sno;
@ -291,14 +290,13 @@ end:
/** /**
* *
*/ */
bool Yap_WriteTerm( int output_stream, Term t, Term opts USES_REGS) bool Yap_WriteTerm(int output_stream, Term t, Term opts USES_REGS) {
{
xarg *args = Yap_ArgListToVector(opts, write_defs, WRITE_END); xarg *args = Yap_ArgListToVector(opts, write_defs, WRITE_END);
if (args == NULL) { if (args == NULL) {
if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE)
LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION;
if (LOCAL_Error_TYPE) if (LOCAL_Error_TYPE)
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, opts, NULL);
return false; return false;
} }
yhandle_t mySlots = Yap_StartSlots(); yhandle_t mySlots = Yap_StartSlots();
@ -343,7 +341,7 @@ static Int write2(USES_REGS1) {
if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE)
LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION;
if (LOCAL_Error_TYPE) if (LOCAL_Error_TYPE)
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, TermNil, NULL);
return false; return false;
} }
mySlots = Yap_StartSlots(); mySlots = Yap_StartSlots();
@ -369,7 +367,7 @@ static Int write1(USES_REGS1) {
if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE)
LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION;
if (LOCAL_Error_TYPE) if (LOCAL_Error_TYPE)
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, TermNil, NULL);
return false; return false;
} }
yhandle_t mySlots = Yap_StartSlots(); yhandle_t mySlots = Yap_StartSlots();
@ -396,7 +394,7 @@ static Int write_canonical1(USES_REGS1) {
if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE)
LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION;
if (LOCAL_Error_TYPE) if (LOCAL_Error_TYPE)
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, TermNil, NULL);
return false; return false;
} }
yhandle_t mySlots = Yap_StartSlots(); yhandle_t mySlots = Yap_StartSlots();
@ -422,7 +420,7 @@ static Int write_canonical(USES_REGS1) {
if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE)
LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION;
if (LOCAL_Error_TYPE) if (LOCAL_Error_TYPE)
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, TermNil, NULL);
return false; return false;
} }
int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2"); int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2");
@ -452,7 +450,7 @@ static Int writeq1(USES_REGS1) {
if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE)
LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION;
if (LOCAL_Error_TYPE) if (LOCAL_Error_TYPE)
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, TermNil, NULL);
return false; return false;
} }
yhandle_t mySlots = Yap_StartSlots(); yhandle_t mySlots = Yap_StartSlots();
@ -482,7 +480,7 @@ static Int writeq(USES_REGS1) {
if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE)
LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION;
if (LOCAL_Error_TYPE) if (LOCAL_Error_TYPE)
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, TermNil, NULL);
return false; return false;
} }
int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2"); int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2");
@ -512,7 +510,7 @@ static Int print1(USES_REGS1) {
if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE)
LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION;
if (LOCAL_Error_TYPE) if (LOCAL_Error_TYPE)
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, TermNil, NULL);
return false; return false;
} }
yhandle_t mySlots = Yap_StartSlots(); yhandle_t mySlots = Yap_StartSlots();
@ -543,7 +541,7 @@ static Int print(USES_REGS1) {
if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE)
LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION;
if (LOCAL_Error_TYPE) if (LOCAL_Error_TYPE)
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, TermNil, NULL);
return false; return false;
} }
int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2"); int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2");
@ -574,7 +572,7 @@ static Int writeln1(USES_REGS1) {
xarg *args = Yap_ArgListToVector(TermNil, write_defs, WRITE_END); xarg *args = Yap_ArgListToVector(TermNil, write_defs, WRITE_END);
if (args == NULL) { if (args == NULL) {
if (LOCAL_Error_TYPE) if (LOCAL_Error_TYPE)
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, TermNil, NULL);
return false; return false;
} }
yhandle_t mySlots = Yap_StartSlots(); yhandle_t mySlots = Yap_StartSlots();
@ -598,7 +596,7 @@ static Int writeln(USES_REGS1) {
xarg *args = Yap_ArgListToVector(TermNil, write_defs, WRITE_END); xarg *args = Yap_ArgListToVector(TermNil, write_defs, WRITE_END);
if (args == NULL) { if (args == NULL) {
if (LOCAL_Error_TYPE) if (LOCAL_Error_TYPE)
Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); Yap_Error(LOCAL_Error_TYPE, TermNil, NULL);
return false; return false;
} }
int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "writeln/2"); int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "writeln/2");
@ -676,7 +674,6 @@ static Int dollar_var(USES_REGS1) {
return Yap_unify(tv, ARG2); return Yap_unify(tv, ARG2);
} }
static Int term_to_string(USES_REGS1) { static Int term_to_string(USES_REGS1) {
Term t2 = Deref(ARG2), rc = false, t1 = Deref(ARG1); Term t2 = Deref(ARG2), rc = false, t1 = Deref(ARG1);
const char *s; const char *s;

View File

@ -1,7 +1,61 @@
%matplotlib inline
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
sns.set(style="white", context="talk")
rs = np.random.RandomState(7)
:- use_module( library(python) ). pos={0:(0,0),
1:(1,0),
2:(0,1),
3:(1,1),
4:(0.1,0.9),
5:(0.3,1.1),
6:(0.9,0.9)
}
:- := import(pandas)). names={4:'MMM',
5:'XXX',
6:'ZZZ'}
pred2panda(Pred, Obj) :- def plot1(y10,y20):
def gen(f,f0):
return [f[0],f[1],-f[2]]/max(f,f0)
ax1 = plt.subplot2grid((1,2), (0,0), colspan=2)
ax2 = plt.subplot2grid((1,2), (0,1), colspan=2)
ax3 = plt.subplot2grid((2,2), (2,0), colspan=2, rowspan=2)
xs = ["+-","++","--"]
y1 = gen(y10, y20)
sns.barplot(xs, y1, palette="RdBu_r", ax=ax1)
y2 = gen(y20,y10)
sns.barplot(xs, y2, palette="Set3", ax=ax2)
# Finalize the plot
# sns.despine(bottom=True)
G=nx.Graph()
i=0
G.pos={} # location
G.pop={} # size
lpos={0:(0,0),1:(0,0),2:(0,0),3:(0,0)}
last=len(pos)-1
for i in range(4,len(pos)):
G.pos[i]=pos[i]
G.pop[i]=2000
(x,y) = pos[i]
lpos[i] = (x,y-0.05)
if i > 4:
G.add_edge(i-1,i)
else:
G.add_edge(2,i)
G.add_edge(3,last)
nx.draw_networkx_nodes(G,pos,nodelist=range(4,len(pos)),ax=ax3)
nx.draw_networkx_nodes(G,pos,nodelist=[0,1,2,3],node_color='b',ax=ax3)
nx.draw_networkx_edges(G,pos,alpha=0.5,ax=ax3)
nx.draw_networkx_labels(G,lpos,names,alpha=0.5,ax=ax3)
plt.axis('off')
plt.tight_layout(h_pad=3)
plt.savefig("house_with_colors.png") # save as png
plot1([20,30,10],[30,30,5])

View File

@ -39,6 +39,8 @@ extern PyObject *py_F2P;
extern bool python_in_python; extern bool python_in_python;
#define PythonReturn PyGILState_Release(gstate) && return
static inline Py_ssize_t get_p_int(PyObject *o, Py_ssize_t def) { static inline Py_ssize_t get_p_int(PyObject *o, Py_ssize_t def) {
if (o == NULL) if (o == NULL)
return def; return def;
@ -94,7 +96,6 @@ static inline PyObject *atom_to_python_string(term_t t) {
extern PyObject *compound_to_pyeval(term_t t, functor_t fun); extern PyObject *compound_to_pyeval(term_t t, functor_t fun);
extern PyObject *compound_to_pytree(term_t t, functor_t fun); extern PyObject *compound_to_pytree(term_t t, functor_t fun);
extern PyObject *yap_to_python(YAP_Term t, bool eval); extern PyObject *yap_to_python(YAP_Term t, bool eval);
extern PyObject *term_to_python(term_t t, bool eval); extern PyObject *term_to_python(term_t t, bool eval);
extern foreign_t python_to_ptr(PyObject *pVal, term_t t); extern foreign_t python_to_ptr(PyObject *pVal, term_t t);

View File

@ -138,9 +138,9 @@ class YAPKernel(KernelBase):
implementation = 'YAP' implementation = 'YAP'
implementation_version = release.version implementation_version = release.version
language_info = { language_info = {
'name': 'python', 'name': 'prolog',
'version': sys.version.split()[0], 'version': sys.version.split()[0],
'mimetype': 'text/x-python', 'mimetype': 'text/x-prolog',
'codemirror_mode': { 'codemirror_mode': {
'name': 'prolog', 'name': 'prolog',
'version': sys.version_info[0] 'version': sys.version_info[0]

View File

@ -15,13 +15,13 @@
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA. * Boston, MA 02110-1301, USA.
*/ */
#include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include "raptor_config.h"
#include "YapInterface.h" #include "YapInterface.h"
#include "raptor_config.h"
#ifdef HAVE_RAPTOR2_RAPTOR2_H #ifdef HAVE_RAPTOR2_RAPTOR2_H
#include "raptor2/raptor2.h" #include "raptor2/raptor2.h"
#else #else
@ -38,9 +38,7 @@ struct exo_aux {
size_t n; size_t n;
}; };
static YAP_Atom static YAP_Atom term_load(const raptor_term *term) {
term_load(const raptor_term *term)
{
size_t len; size_t len;
switch (term->type) { switch (term->type) {
case RAPTOR_TERM_TYPE_LITERAL: case RAPTOR_TERM_TYPE_LITERAL:
@ -52,11 +50,14 @@ term_load(const raptor_term *term)
return YAP_LookupAtom((const char *)term->value.blank.string); return YAP_LookupAtom((const char *)term->value.blank.string);
case RAPTOR_TERM_TYPE_URI: case RAPTOR_TERM_TYPE_URI:
// fprintf(stderr, "%s,", raptor_uri_as_counted_string(term->value.uri, &len)); // fprintf(stderr, "%s,",
return YAP_LookupAtom((const char *)raptor_uri_as_counted_string(term->value.uri, &len)); // raptor_uri_as_counted_string(term->value.uri, &len));
return YAP_LookupAtom(
(const char *)raptor_uri_as_counted_string(term->value.uri, &len));
case RAPTOR_TERM_TYPE_UNKNOWN: case RAPTOR_TERM_TYPE_UNKNOWN:
default: default:
raptor_log_error_formatted(term->world, RAPTOR_LOG_LEVEL_ERROR, NULL, raptor_log_error_formatted(term->world, RAPTOR_LOG_LEVEL_ERROR, NULL,
"Triple has unsupported term type %d", "Triple has unsupported term type %d",
term->type); term->type);
@ -68,9 +69,7 @@ term_load(const raptor_term *term)
static int so_far = 0; static int so_far = 0;
static void static void load_triples(void *user_data, raptor_statement *triple) {
load_triples(void* user_data, raptor_statement* triple)
{
struct exo_aux *aux = (struct exo_aux *)user_data; struct exo_aux *aux = (struct exo_aux *)user_data;
YAP_Term args[4]; YAP_Term args[4];
@ -83,9 +82,7 @@ load_triples(void* user_data, raptor_statement* triple)
YAP_AssertTuples(aux->pred, args, so_far++, 1); YAP_AssertTuples(aux->pred, args, so_far++, 1);
} }
static void static void count_triples(void *user_data, raptor_statement *triple) {
count_triples(void* user_data, raptor_statement* triple)
{
unsigned int *count_p = (unsigned int *)user_data; unsigned int *count_p = (unsigned int *)user_data;
(*count_p)++; (*count_p)++;
@ -95,9 +92,7 @@ count_triples(void* user_data, raptor_statement* triple)
// fprintf(stderr, "\n"); // fprintf(stderr, "\n");
} }
static YAP_Bool static YAP_Bool load(void) {
load(void)
{
YAP_Term tfn = YAP_ARG1; YAP_Term tfn = YAP_ARG1;
YAP_Term mod = YAP_ARG2; YAP_Term mod = YAP_ARG2;
YAP_Term tfunctor = YAP_ARG3; YAP_Term tfunctor = YAP_ARG3;
@ -160,14 +155,11 @@ load(void)
return TRUE; return TRUE;
} }
static inline void static inline void raptor_yap_halt(int exit, void *world) {
raptor_yap_halt (int exit, void* world)
{
raptor_free_world((raptor_world *)world); raptor_free_world((raptor_world *)world);
} }
void raptor_yap_init (void) void raptor_yap_init(void) {
{
world = raptor_new_world(); world = raptor_new_world();
YAP_HaltRegisterHook(raptor_yap_halt, (void *)world); YAP_HaltRegisterHook(raptor_yap_halt, (void *)world);

View File

@ -27,41 +27,16 @@
:- dynamic dbloading/6, dbprocess/2. :- dynamic dbloading/6, dbprocess/2.
dbload_from_stream(R, M0, Type) :- dbload_from_stream(R, M0, rdf, term ) :-
repeat, '$lines_in_file'(R, Lines),
read(R,T), '$input_lines'(R, Type, Lines),
( T == end_of_file -> !, close_dbload(R, Type); dbload_from_stream(R, M0, Type, Storage ) :-
dbload_count(T, M0), '$lines_in_file'(R, Lines),
fail '$input_lines'(R, Type, Lines),
).
close_dbload(_R, exo) :-
retract(dbloading(Na,Arity,M,T,NaAr,_)),
nb_getval(NaAr,Size),
exo_db_get_space(T, M, Size, Handle),
assertz(dbloading(Na,Arity,M,T,NaAr,Handle)),
nb_setval(NaAr,0),
fail.
close_dbload(R, exo) :-
seek(R, 0, bof, _),
exodb_add_facts(R, _M),
fail.
close_dbload(_R, mega) :-
retract(dbloading(Na,Arity,M,T,NaAr,_)),
nb_getval(NaAr,Size),
dbload_get_space(T, M, Size, Handle),
assertz(dbloading(Na,Arity,M,T,NaAr,Handle)),
nb_setval(NaAr,0),
fail.
close_dbload(R, mega) :-
seek(R, 0, bof, _),
dbload_add_facts(R, _M),
fail.
close_dbload(_, _) :-
retractall(dbloading(_Na,_Arity,_M,_T,_NaAr,_Handle)),
fail.
close_dbload(_, _).
'$input_lines'(R, csv, yeLines ) :-
'$process_lines'(R, Lines, Type ),
close(R).
prolog:load_db(Fs) :- prolog:load_db(Fs) :-
'$current_module'(M0), '$current_module'(M0),
@ -199,4 +174,3 @@ clean_up :-
retractall(dbprocess(_,_)), retractall(dbprocess(_,_)),
fail. fail.
clean_up. clean_up.

View File

@ -191,9 +191,8 @@ order of dispatch.
'$continue_signals', '$continue_signals',
'$hacks':'$stack_dump', '$hacks':'$stack_dump',
'$execute0'(G,M). '$execute0'(G,M).
'$do_signal'(sig_fpe, [_M|_G]) :- '$do_signal'(sig_fpe,G) :-
'$fpe_error'. '$signal_handler'(sig_fpe, G)
% Unix signals
'$do_signal'(sig_alarm, G) :- '$do_signal'(sig_alarm, G) :-
'$signal_handler'(sig_alarm, G). '$signal_handler'(sig_alarm, G).
'$do_signal'(sig_vtalarm, G) :- '$do_signal'(sig_vtalarm, G) :-