diff --git a/C/absmi_insts.i b/C/absmi_insts.i index 55257cc1c..8c70a2895 100644 --- a/C/absmi_insts.i +++ b/C/absmi_insts.i @@ -8160,12 +8160,7 @@ saveregs(); d0 = p_plus(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); setregs(); - if (d0 == 0L) { - saveregs(); - Yap_PreProcessedError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } + } XREG(PREG->y_u.xxx.x) = d0; PREG = NEXTOP(PREG, xxx); diff --git a/C/atomic.c b/C/atomic.c index 14744d434..450085cb7 100644 --- a/C/atomic.c +++ b/C/atomic.c @@ -527,18 +527,23 @@ static Int number_chars(USES_REGS1) { restart_aux: t1 = Deref(ARG1); if (IsNumTerm(t1)) { - Term tf; - tf = Yap_NumberToListOfAtoms(t1 PASS_REGS); - if (tf) { - LOCAL_Error_TYPE = YAP_NO_ERROR; - return Yap_unify(ARG2, tf); + Term t2 = Deref(ARG2); + if (IsVarTerm(t2)) { + t1 = Yap_NumberToListOfAtoms(t1 PASS_REGS); + } + 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)) { /* ARG1 unbound */ Term t = Deref(ARG2); Term tf = Yap_ListToNumber(t PASS_REGS); if (tf) { - LOCAL_Error_TYPE = YAP_NO_ERROR; return Yap_unify(ARG1, tf); } } else if (IsVarTerm(t1)) { @@ -556,16 +561,25 @@ static Int number_atom(USES_REGS1) { restart_aux: t1 = Deref(ARG1); if (IsNumTerm(t1)) { + Term t2 = Deref(ARG2); Atom af; af = Yap_NumberToAtom(t1 PASS_REGS); - if (af) - return Yap_unify(ARG2, MkAtomTerm(af)); + if (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)) { /* ARG1 unbound */ Term t = Deref(ARG2); Term tf = Yap_AtomToNumber(t PASS_REGS); - if (tf) - return Yap_unify(ARG1, tf); + return Yap_unify(ARG1, tf); } else if (IsVarTerm(t1)) { LOCAL_Error_TYPE = TYPE_ERROR_NUMBER; } /* error handling */ @@ -634,8 +648,8 @@ restart_aux: i = IntOfTerm(EXTRA_CBACK_ARG(3, 1)); max = IntOfTerm(EXTRA_CBACK_ARG(3, 2)); EXTRA_CBACK_ARG(3, 1) = MkIntTerm(i + 1); - if (!Yap_SpliceAtom(t3, ats, i, max PASS_REGS) && LOCAL_Error_TYPE == - YAP_NO_ERROR) { + if (!Yap_SpliceAtom(t3, ats, i, max PASS_REGS) && + LOCAL_Error_TYPE == YAP_NO_ERROR) { cut_fail(); } else { if (i < max) @@ -666,9 +680,9 @@ restart_aux: t1 = Deref(ARG1); t2 = Deref(ARG2); t3 = Deref(ARG3); - g1 = Yap_IsGroundTerm(t1); - g2 = Yap_IsGroundTerm(t2); - g3 = Yap_IsGroundTerm(t3); + g1 = Yap_IsGroundTerm(t1); + g2 = Yap_IsGroundTerm(t2); + g3 = Yap_IsGroundTerm(t3); if (g1 && g2) { at = Yap_ConcatAtoms(t1, t2 PASS_REGS); ot = ARG3; @@ -677,15 +691,14 @@ restart_aux: ot = ARG2; } else if (g2 && g3) { at = Yap_SubtractTailAtom(t3, t2 PASS_REGS); - ot = ARG1; + ot = ARG1; } else if (g3) { EXTRA_CBACK_ARG(3, 1) = MkIntTerm(0); EXTRA_CBACK_ARG(3, 2) = MkIntTerm(Yap_AtomToLength(t3 PASS_REGS)); return cont_atom_concat3(PASS_REGS1); } else { - LOCAL_Error_TYPE = INSTANTIATION_ERROR; - LOCAL_Error_Term = t1; - at = NULL; + LOCAL_Error_TYPE = INSTANTIATION_ERROR; + at = NULL; } if (at) { if (Yap_unify(ot, MkAtomTerm(at))) @@ -704,7 +717,6 @@ restart_aux: cut_fail(); } - #define CastToNumeric(x) CastToNumeric__(x PASS_REGS) static Term CastToNumeric__(Atom at USES_REGS) { @@ -754,9 +766,9 @@ restart_aux: t1 = Deref(ARG1); t2 = Deref(ARG2); t3 = Deref(ARG3); - g1 = Yap_IsGroundTerm(t1); - g2 = Yap_IsGroundTerm(t2); - g3 = Yap_IsGroundTerm(t3); + g1 = Yap_IsGroundTerm(t1); + g2 = Yap_IsGroundTerm(t2); + g3 = Yap_IsGroundTerm(t3); if (g1 && g2) { at = Yap_ConcatAtomics(t1, t2 PASS_REGS); ot = ARG3; @@ -765,15 +777,14 @@ restart_aux: ot = ARG2; } else if (g2 && g3) { at = Yap_SubtractTailAtom(t3, t2 PASS_REGS); - ot = ARG1; + ot = ARG1; } else if (g3) { EXTRA_CBACK_ARG(3, 1) = MkIntTerm(0); EXTRA_CBACK_ARG(3, 2) = MkIntTerm(Yap_AtomicToLength(t3 PASS_REGS)); return cont_atomic_concat3(PASS_REGS1); } else { - LOCAL_Error_TYPE = INSTANTIATION_ERROR; - LOCAL_Error_Term = t1; - at = NULL; + LOCAL_Error_TYPE = INSTANTIATION_ERROR; + at = NULL; } if (at) { if (Yap_unify(ot, MkAtomTerm(at))) @@ -831,9 +842,9 @@ restart_aux: t1 = Deref(ARG1); t2 = Deref(ARG2); t3 = Deref(ARG3); - g1 = Yap_IsGroundTerm(t1); - g2 = Yap_IsGroundTerm(t2); - g3 = Yap_IsGroundTerm(t3); + g1 = Yap_IsGroundTerm(t1); + g2 = Yap_IsGroundTerm(t2); + g3 = Yap_IsGroundTerm(t3); if (g1 && g2) { tf = Yap_ConcatStrings(t1, t2 PASS_REGS); ot = ARG3; @@ -842,15 +853,14 @@ restart_aux: ot = ARG2; } else if (g2 && g3) { tf = Yap_SubtractTailString(t3, t2 PASS_REGS); - ot = ARG1; + ot = ARG1; } else if (g3) { EXTRA_CBACK_ARG(3, 1) = MkIntTerm(0); EXTRA_CBACK_ARG(3, 2) = MkIntTerm(Yap_StringToLength(t3 PASS_REGS)); return cont_string_concat3(PASS_REGS1); } else { - LOCAL_Error_TYPE = INSTANTIATION_ERROR; - LOCAL_Error_Term = t1; - at = NULL; + LOCAL_Error_TYPE = INSTANTIATION_ERROR; + at = NULL; } if (tf) { if (Yap_unify(ot, tf)) @@ -913,10 +923,8 @@ restart_aux: t2 = Deref(ARG2); if (IsVarTerm(t2)) { LOCAL_Error_TYPE = INSTANTIATION_ERROR; - LOCAL_Error_Term = t2; } else if (!IsStringTerm(t2)) { LOCAL_Error_TYPE = TYPE_ERROR_STRING; - LOCAL_Error_Term = t2; } else { s = UStringOfTerm(t2); t1 = Deref(ARG1); @@ -926,7 +934,6 @@ restart_aux: return cont_string_code3(PASS_REGS1); } else if (!IsIntegerTerm(t1)) { LOCAL_Error_TYPE = TYPE_ERROR_INTEGER; - LOCAL_Error_Term = t1; } else { const unsigned char *ns = s; utf8proc_int32_t chr; @@ -934,7 +941,6 @@ restart_aux: if (indx <= 0) { if (indx < 0) { LOCAL_Error_TYPE = DOMAIN_ERROR_NOT_LESS_THAN_ZERO; - LOCAL_Error_Term = t1; } cut_fail(); } @@ -970,19 +976,16 @@ restart_aux: t2 = Deref(ARG2); if (IsVarTerm(t2)) { LOCAL_Error_TYPE = INSTANTIATION_ERROR; - LOCAL_Error_Term = t2; } else if (!IsStringTerm(t2)) { LOCAL_Error_TYPE = TYPE_ERROR_STRING; - LOCAL_Error_Term = t2; } else { s = UStringOfTerm(t2); t1 = Deref(ARG1); if (IsVarTerm(t1)) { LOCAL_Error_TYPE = INSTANTIATION_ERROR; - LOCAL_Error_Term = t1; + } else if (!IsIntegerTerm(t1)) { LOCAL_Error_TYPE = TYPE_ERROR_INTEGER; - LOCAL_Error_Term = t1; } else { const unsigned char *ns = s; utf8proc_int32_t chr; @@ -991,7 +994,6 @@ restart_aux: if (indx <= 0) { if (indx < 0) { LOCAL_Error_TYPE = DOMAIN_ERROR_NOT_LESS_THAN_ZERO; - LOCAL_Error_Term = t1; } else { 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); const unsigned char *cp = src; - LOCAL_TERM_ERROR(t, 4 * (len + 1)); buf = buf_from_tstring(HR); while (len) { utf8proc_int32_t chr; diff --git a/C/cdmgr.c b/C/cdmgr.c index bb62f0954..892459b53 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -1452,8 +1452,6 @@ static void addcl_permission_error(AtomEntry *ap, Int Arity, int in_use) { ti[0] = MkAtomTerm(AbsAtom(ap)); ti[1] = MkIntegerTerm(Arity); t = Yap_MkApplTerm(FunctorSlash, 2, ti); - LOCAL_ErrorMessage = LOCAL_ErrorSay; - LOCAL_Error_Term = t; LOCAL_Error_TYPE = PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE; if (in_use) { if (Arity == 0) @@ -2028,9 +2026,7 @@ static Int p_compile(USES_REGS1) { /* '$compile'(+C,+Flags,+C0,-Ref) */ YAPLeaveCriticalSection(); } if (LOCAL_ErrorMessage) { - if (!LOCAL_Error_Term) - LOCAL_Error_Term = TermNil; - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); + Yap_Error(LOCAL_Error_TYPE, ARG1, LOCAL_ErrorMessage); YAPLeaveCriticalSection(); return false; } @@ -3590,7 +3586,8 @@ static Int p_predicate_erased_statistics(USES_REGS1) { Term tpred = ArgOfTerm(2, 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; while (cl) { if (cl->ClPred == pe) { diff --git a/C/cmppreds.c b/C/cmppreds.c index da947221f..c6f8e0e63 100644 --- a/C/cmppreds.c +++ b/C/cmppreds.c @@ -18,30 +18,28 @@ /// @file cmppreds.c - - -/** +/** @defgroup Comparing_Terms Comparing Terms @ingroup builtins The following predicates are used to compare and order terms, using the standard ordering: -+ ++ variables come before numbers, numbers come before atoms which in turn come before compound terms, i.e.: variables @< numbers @< atoms @< compound terms. + Variables are roughly ordered by "age" (the "oldest" variable is put first); -+ ++ Floating point numbers are sorted in increasing order; -+ ++ Rational numbers are sorted in increasing order; -+ ++ Integers are sorted in increasing order; -+ ++ Atoms are sorted in lexicographic order; -+ ++ Compound terms are ordered first by arity of the main functor, then by the name of the main functor, and finally by their arguments in left-to-right order. @@ -49,17 +47,16 @@ left-to-right order. @{ - + */ - #ifdef SCCS -static char SccsId[] = "%W% %G%"; +static char SccsId[] = "%W% %G%"; #endif #include "Yap.h" -#include "Yatom.h" #include "YapHeap.h" +#include "Yatom.h" #include "eval.h" #if HAVE_STRING_H #include @@ -67,39 +64,39 @@ static char SccsId[] = "%W% %G%"; #include static Int compare(Term, Term); -static Int p_compare( USES_REGS1 ); -static Int p_acomp( USES_REGS1 ); -static Int a_eq(Term,Term); -static Int a_dif(Term,Term); +static Int p_compare(USES_REGS1); +static Int p_acomp(USES_REGS1); +static Int a_eq(Term, Term); +static Int a_dif(Term, Term); static Int a_gt(Term, Term); -static Int a_ge(Term,Term); -static Int a_lt(Term,Term); -static Int a_le(Term,Term); -static Int a_noteq(Term,Term); -static Int a_gen_lt(Term,Term); -static Int a_gen_le(Term,Term); -static Int a_gen_gt(Term,Term); -static Int a_gen_ge(Term,Term); +static Int a_ge(Term, Term); +static Int a_lt(Term, Term); +static Int a_le(Term, Term); +static Int a_noteq(Term, Term); +static Int a_gen_lt(Term, Term); +static Int a_gen_le(Term, Term); +static Int a_gen_gt(Term, Term); +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 -cmp_atoms(Atom a1, Atom a2) -{ +static int cmp_atoms(Atom a1, Atom a2) { if (IsWideAtom(a1)) { 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 { /* The standard does not seem to have nothing on this */ unsigned char *s1 = (unsigned char *)RepAtom(a1)->StrOfAE; wchar_t *s2 = (wchar_t *)RepAtom(a2)->StrOfAE; while (*s1 == *s2) { - if (!*s1) return 0; - s1++; - s2++; + if (!*s1) + return 0; + s1++; + s2++; } - return *s1-*s2; + return *s1 - *s2; } } else if (IsWideAtom(a2)) { /* The standard does not seem to have nothing on this */ @@ -107,224 +104,226 @@ cmp_atoms(Atom a1, Atom a2) unsigned char *s2 = (unsigned char *)RepAtom(a2)->StrOfAE; while (*s1 == *s2) { - if (!*s1) return 0; + if (!*s1) + return 0; s1++; s2++; } - return *s1-*s2; + return *s1 - *s2; } else { - return strcmp((char *)RepAtom(a1)->StrOfAE,(char *)RepAtom(a2)->StrOfAE); + return strcmp((char *)RepAtom(a1)->StrOfAE, (char *)RepAtom(a2)->StrOfAE); } } -static Int compare_complex(register CELL *pt0, register CELL *pt0_end, register - CELL *pt1) -{ +static Int compare_complex(register CELL *pt0, register CELL *pt0_end, + register CELL *pt1) { CACHE_REGS register CELL **to_visit = (CELL **)HR; register Int out = 0; - loop: +loop: while (pt0 < pt0_end) { register CELL d0, d1; - ++ pt0; - ++ pt1; + ++pt0; + ++pt1; d0 = Derefa(pt0); d1 = Derefa(pt1); if (IsVarTerm(d0)) { if (IsVarTerm(d1)) { - out = Signed(d0) - Signed(d1); - if (out) goto done; - } - else { - out = -1; - goto done; + out = Signed(d0) - Signed(d1); + if (out) + goto done; + } else { + out = -1; + goto done; } } else if (IsVarTerm(d1)) { out = 1; goto done; } else { - if (d0 == d1) continue; + if (d0 == d1) + continue; else if (IsAtomTerm(d0)) { - if (IsAtomTerm(d1)) - out = cmp_atoms(AtomOfTerm(d0), AtomOfTerm(d1)); - else if (IsPrimitiveTerm(d1)) - out = 1; - else out = -1; - /* I know out must be != 0 */ - goto done; - } - else if (IsIntTerm(d0)) { - if (IsIntTerm(d1)) - out = IntOfTerm(d0) - IntOfTerm(d1); - else if (IsFloatTerm(d1)) { - out = 1; - } else if (IsLongIntTerm(d1)) { - out = IntOfTerm(d0) - LongIntOfTerm(d1); + if (IsAtomTerm(d1)) + out = cmp_atoms(AtomOfTerm(d0), AtomOfTerm(d1)); + else if (IsPrimitiveTerm(d1)) + out = 1; + else + out = -1; + /* I know out must be != 0 */ + goto done; + } else if (IsIntTerm(d0)) { + if (IsIntTerm(d1)) + out = IntOfTerm(d0) - IntOfTerm(d1); + else if (IsFloatTerm(d1)) { + out = 1; + } else if (IsLongIntTerm(d1)) { + out = IntOfTerm(d0) - LongIntOfTerm(d1); #ifdef USE_GMP - } else if (IsBigIntTerm(d1)) { - out = Yap_gmp_tcmp_int_big(IntOfTerm(d0), d1); + } else if (IsBigIntTerm(d1)) { + out = Yap_gmp_tcmp_int_big(IntOfTerm(d0), d1); #endif - } else if (IsRefTerm(d1)) - out = 1 ; - else out = -1; - if (out != 0) - goto done; + } else if (IsRefTerm(d1)) + out = 1; + else + out = -1; + if (out != 0) + goto done; } else if (IsFloatTerm(d0)) { - if (IsFloatTerm(d1)){ - out = rfloat(FloatOfTerm(d0) - FloatOfTerm(d1)); - } else if (IsRefTerm(d1)) { - out = 1; - } else { - out = -1; - } - if (out != 0) - goto done; + if (IsFloatTerm(d1)) { + out = rfloat(FloatOfTerm(d0) - FloatOfTerm(d1)); + } else if (IsRefTerm(d1)) { + out = 1; + } else { + out = -1; + } + if (out != 0) + goto done; } else if (IsStringTerm(d0)) { - if (IsStringTerm(d1)){ - out = strcmp((char *)StringOfTerm(d0) , (char *)StringOfTerm(d1)); - } else if (IsIntTerm(d1)) - out = 1; - else if (IsFloatTerm(d1)) { - out = 1; - } else if (IsLongIntTerm(d1)) { - out = 1; + if (IsStringTerm(d1)) { + out = strcmp((char *)StringOfTerm(d0), (char *)StringOfTerm(d1)); + } else if (IsIntTerm(d1)) + out = 1; + else if (IsFloatTerm(d1)) { + out = 1; + } else if (IsLongIntTerm(d1)) { + out = 1; #ifdef USE_GMP - } else if (IsBigIntTerm(d1)) { - out = 1; + } else if (IsBigIntTerm(d1)) { + out = 1; #endif - } else if (IsRefTerm(d1)) { - out = 1 ; - } else { - out = -1; - } - if (out != 0) - goto done; + } else if (IsRefTerm(d1)) { + out = 1; + } else { + out = -1; + } + if (out != 0) + goto done; } else if (IsLongIntTerm(d0)) { - if (IsIntTerm(d1)) - out = LongIntOfTerm(d0) - IntOfTerm(d1); - else if (IsFloatTerm(d1)) { - out = 1; - } else if (IsLongIntTerm(d1)) { - out = LongIntOfTerm(d0) - LongIntOfTerm(d1); + if (IsIntTerm(d1)) + out = LongIntOfTerm(d0) - IntOfTerm(d1); + else if (IsFloatTerm(d1)) { + out = 1; + } else if (IsLongIntTerm(d1)) { + out = LongIntOfTerm(d0) - LongIntOfTerm(d1); #ifdef USE_GMP - } else if (IsBigIntTerm(d1)) { - out = Yap_gmp_tcmp_int_big(LongIntOfTerm(d0), d1); + } else if (IsBigIntTerm(d1)) { + out = Yap_gmp_tcmp_int_big(LongIntOfTerm(d0), d1); #endif - } else if (IsRefTerm(d1)) { - out = 1 ; - } else { - out = -1; - } - if (out != 0) - goto done; + } else if (IsRefTerm(d1)) { + out = 1; + } else { + out = -1; + } + if (out != 0) + goto done; } #ifdef USE_GMP else if (IsBigIntTerm(d0)) { - if (IsIntTerm(d1)) { - out = Yap_gmp_tcmp_big_int(d0, IntOfTerm(d1)); - } else if (IsFloatTerm(d1)) { - out = 1; - } else if (IsLongIntTerm(d1)) { - out = Yap_gmp_tcmp_big_int(d0, LongIntOfTerm(d1)); - } else if (IsBigIntTerm(d1)) { - out = Yap_gmp_tcmp_big_big(d0, d1); - } else if (IsRefTerm(d1)) - out = 1 ; - else out = -1; - if (out != 0) - goto done; + if (IsIntTerm(d1)) { + out = Yap_gmp_tcmp_big_int(d0, IntOfTerm(d1)); + } else if (IsFloatTerm(d1)) { + out = 1; + } else if (IsLongIntTerm(d1)) { + out = Yap_gmp_tcmp_big_int(d0, LongIntOfTerm(d1)); + } else if (IsBigIntTerm(d1)) { + out = Yap_gmp_tcmp_big_big(d0, d1); + } else if (IsRefTerm(d1)) + out = 1; + else + out = -1; + if (out != 0) + goto done; } #endif else if (IsPairTerm(d0)) { - if (!IsPairTerm(d1)) { - if (IsApplTerm(d1)) { - Functor f = FunctorOfTerm(d1); - if (IsExtensionFunctor(f)) - out = 1; - else if (!(out = 2-ArityOfFunctor(f))) - out = strcmp(".",(char *)RepAtom(NameOfFunctor(f))->StrOfAE); - } else out = 1; - goto done; - } + if (!IsPairTerm(d1)) { + if (IsApplTerm(d1)) { + Functor f = FunctorOfTerm(d1); + if (IsExtensionFunctor(f)) + out = 1; + else if (!(out = 2 - ArityOfFunctor(f))) + out = strcmp(".", (char *)RepAtom(NameOfFunctor(f))->StrOfAE); + } else + out = 1; + goto done; + } #ifdef RATIONAL_TREES - to_visit[0] = pt0; - to_visit[1] = pt0_end; - to_visit[2] = pt1; - to_visit[3] = (CELL *)*pt0; - to_visit += 4; - *pt0 = d1; + to_visit[0] = pt0; + to_visit[1] = pt0_end; + to_visit[2] = pt1; + to_visit[3] = (CELL *)*pt0; + to_visit += 4; + *pt0 = d1; #else - /* store the terms to visit */ - if (pt0 < pt0_end) { - to_visit[0] = pt0; - to_visit[1] = pt0_end; - to_visit[2] = pt1; - to_visit += 3; - } + /* store the terms to visit */ + if (pt0 < pt0_end) { + to_visit[0] = pt0; + to_visit[1] = pt0_end; + to_visit[2] = pt1; + to_visit += 3; + } #endif - pt0 = RepPair(d0) - 1; - pt0_end = RepPair(d0) + 1; - pt1 = RepPair(d1) - 1; - continue; - } - else if (IsRefTerm(d0)) { - if (IsRefTerm(d1)) - out = Unsigned(RefOfTerm(d1)) - - Unsigned(RefOfTerm(d0)); - else out = -1; - goto done; + pt0 = RepPair(d0) - 1; + pt0_end = RepPair(d0) + 1; + pt1 = RepPair(d1) - 1; + continue; + } else if (IsRefTerm(d0)) { + if (IsRefTerm(d1)) + out = Unsigned(RefOfTerm(d1)) - Unsigned(RefOfTerm(d0)); + else + out = -1; + goto done; } else if (IsApplTerm(d0)) { - register Functor f; - register CELL *ap2, *ap3; - if (!IsApplTerm(d1)) { - out = 1 ; - goto done; - } else { - /* store the terms to visit */ - Functor f2; - ap2 = RepAppl(d0); - ap3 = RepAppl(d1); - f = (Functor)(*ap2); - if (IsExtensionFunctor(f)) { - out = 1; - goto done; - } - f2 = (Functor)(*ap3); - if (IsExtensionFunctor(f2)) { - out = -1; - goto done; - } - /* compare functors */ - if (f != (Functor)*ap3) { - if (!(out = ArityOfFunctor(f)-ArityOfFunctor(f2))) - out = cmp_atoms(NameOfFunctor(f), NameOfFunctor(f2)); - goto done; - } + register Functor f; + register CELL *ap2, *ap3; + if (!IsApplTerm(d1)) { + out = 1; + goto done; + } else { + /* store the terms to visit */ + Functor f2; + ap2 = RepAppl(d0); + ap3 = RepAppl(d1); + f = (Functor)(*ap2); + if (IsExtensionFunctor(f)) { + out = 1; + goto done; + } + f2 = (Functor)(*ap3); + if (IsExtensionFunctor(f2)) { + out = -1; + goto done; + } + /* compare functors */ + if (f != (Functor)*ap3) { + if (!(out = ArityOfFunctor(f) - ArityOfFunctor(f2))) + out = cmp_atoms(NameOfFunctor(f), NameOfFunctor(f2)); + goto done; + } #ifdef RATIONAL_TREES - to_visit[0] = pt0; - to_visit[1] = pt0_end; - to_visit[2] = pt1; - to_visit[3] = (CELL *)*pt0; - to_visit += 4; - *pt0 = d1; + to_visit[0] = pt0; + to_visit[1] = pt0_end; + to_visit[2] = pt1; + to_visit[3] = (CELL *)*pt0; + to_visit += 4; + *pt0 = d1; #else - /* store the terms to visit */ - if (pt0 < pt0_end) { - to_visit[0] = pt0; - to_visit[1] = pt0_end; - to_visit[2] = pt1; - to_visit += 3; - } + /* store the terms to visit */ + if (pt0 < pt0_end) { + to_visit[0] = pt0; + to_visit[1] = pt0_end; + to_visit[2] = pt1; + to_visit += 3; + } #endif - d0 = ArityOfFunctor(f); - pt0 = ap2; - pt0_end = ap2 + d0; - pt1 = ap3; - continue; - } + d0 = ArityOfFunctor(f); + pt0 = ap2; + pt0_end = ap2 + d0; + pt1 = ap3; + continue; + } } - } } /* Do we still have compound terms to visit */ @@ -344,8 +343,8 @@ static Int compare_complex(register CELL *pt0, register CELL *pt0_end, register goto loop; } - done: - /* failure */ +done: +/* failure */ #ifdef RATIONAL_TREES while (to_visit > (CELL **)HR) { to_visit -= 4; @@ -355,11 +354,10 @@ static Int compare_complex(register CELL *pt0, register CELL *pt0_end, register *pt0 = (CELL)to_visit[3]; } #endif - return(out); + return (out); } -inline static Int -compare(Term t1, Term t2) /* compare terms t1 and t2 */ +inline static Int compare(Term t1, Term t2) /* compare terms t1 and t2 */ { if (t1 == t2) @@ -375,32 +373,32 @@ compare(Term t1, Term t2) /* compare terms t1 and t2 */ if (IsAtomOrIntTerm(t1)) { if (IsAtomTerm(t1)) { if (IsAtomTerm(t2)) - return cmp_atoms(AtomOfTerm(t1),AtomOfTerm(t2)); + return cmp_atoms(AtomOfTerm(t1), AtomOfTerm(t2)); if (IsPrimitiveTerm(t2)) - return 1; + return 1; if (IsStringTerm(t2)) - return 1; + return 1; return -1; } else { if (IsIntTerm(t2)) { - return IntOfTerm(t1) - IntOfTerm(t2); + return IntOfTerm(t1) - IntOfTerm(t2); } if (IsApplTerm(t2)) { - Functor fun2 = FunctorOfTerm(t2); - switch ((CELL)fun2) { - case double_e: - return 1; - case long_int_e: - return IntOfTerm(t1) - LongIntOfTerm(t2); + Functor fun2 = FunctorOfTerm(t2); + switch ((CELL)fun2) { + case double_e: + return 1; + case long_int_e: + return IntOfTerm(t1) - LongIntOfTerm(t2); #ifdef USE_GMP - case big_int_e: - return Yap_gmp_tcmp_int_big(IntOfTerm(t1), t2); + case big_int_e: + return Yap_gmp_tcmp_int_big(IntOfTerm(t1), t2); #endif - case db_ref_e: - return 1; - case string_e: - return -1; - } + case db_ref_e: + return 1; + case string_e: + return -1; + } } return -1; } @@ -408,20 +406,19 @@ compare(Term t1, Term t2) /* compare terms t1 and t2 */ if (IsApplTerm(t2)) { Functor f = FunctorOfTerm(t2); if (IsExtensionFunctor(f)) - return 1; + return 1; else { - int out; - if (!(out = 2-ArityOfFunctor(f))) - out = strcmp(".",(char *)RepAtom(NameOfFunctor(f))->StrOfAE); - return(out); + int out; + if (!(out = 2 - ArityOfFunctor(f))) + out = strcmp(".", (char *)RepAtom(NameOfFunctor(f))->StrOfAE); + return (out); } } if (IsPairTerm(t2)) { - return(compare_complex(RepPair(t1)-1, - RepPair(t1)+1, - RepPair(t2)-1)); - } - else return 1; + return ( + compare_complex(RepPair(t1) - 1, RepPair(t1) + 1, RepPair(t2) - 1)); + } else + return 1; } else { /* compound term */ Functor fun1 = FunctorOfTerm(t1); @@ -429,87 +426,82 @@ compare(Term t1, Term t2) /* compare terms t1 and t2 */ if (IsExtensionFunctor(fun1)) { /* float, long, big, dbref */ switch ((CELL)fun1) { - case double_e: - { - if (IsFloatTerm(t2)) - return(rfloat(FloatOfTerm(t1) - FloatOfTerm(t2))); - if (IsRefTerm(t2)) - return 1; - return -1; - } - case long_int_e: - { - if (IsIntTerm(t2)) - return LongIntOfTerm(t1) - IntOfTerm(t2); - if (IsFloatTerm(t2)) { - return 1; - } - if (IsLongIntTerm(t2)) - return LongIntOfTerm(t1) - LongIntOfTerm(t2); + case double_e: { + if (IsFloatTerm(t2)) + return (rfloat(FloatOfTerm(t1) - FloatOfTerm(t2))); + if (IsRefTerm(t2)) + return 1; + return -1; + } + case long_int_e: { + if (IsIntTerm(t2)) + return LongIntOfTerm(t1) - IntOfTerm(t2); + if (IsFloatTerm(t2)) { + return 1; + } + if (IsLongIntTerm(t2)) + return LongIntOfTerm(t1) - LongIntOfTerm(t2); #ifdef USE_GMP - if (IsBigIntTerm(t2)) { - return Yap_gmp_tcmp_int_big(LongIntOfTerm(t1), t2); - } + if (IsBigIntTerm(t2)) { + return Yap_gmp_tcmp_int_big(LongIntOfTerm(t1), t2); + } #endif - if (IsRefTerm(t2)) - return 1; - return -1; - } + if (IsRefTerm(t2)) + return 1; + return -1; + } #ifdef USE_GMP - case big_int_e: - { - if (IsIntTerm(t2)) - return Yap_gmp_tcmp_big_int(t1, IntOfTerm(t2)); - if (IsFloatTerm(t2)) { - return 1; - } - if (IsLongIntTerm(t2)) - return Yap_gmp_tcmp_big_int(t1, LongIntOfTerm(t2)); - if (IsBigIntTerm(t2)) { - return Yap_gmp_tcmp_big_big(t1, t2); - } - if (IsRefTerm(t2)) - return 1; - return -1; - } + case big_int_e: { + if (IsIntTerm(t2)) + return Yap_gmp_tcmp_big_int(t1, IntOfTerm(t2)); + if (IsFloatTerm(t2)) { + return 1; + } + if (IsLongIntTerm(t2)) + return Yap_gmp_tcmp_big_int(t1, LongIntOfTerm(t2)); + if (IsBigIntTerm(t2)) { + return Yap_gmp_tcmp_big_big(t1, t2); + } + if (IsRefTerm(t2)) + return 1; + return -1; + } #endif - case string_e: - { - if (IsApplTerm(t2)) { - Functor fun2 = FunctorOfTerm(t2); - switch ((CELL)fun2) { - case double_e: - return 1; - case long_int_e: - return 1; + case string_e: { + if (IsApplTerm(t2)) { + Functor fun2 = FunctorOfTerm(t2); + switch ((CELL)fun2) { + case double_e: + return 1; + case long_int_e: + return 1; #ifdef USE_GMP - case big_int_e: - return 1; + case big_int_e: + return 1; #endif - case db_ref_e: - return 1; - case string_e: - return strcmp((char *)StringOfTerm(t1), (char *)StringOfTerm(t2)); - } - return -1; - } - return -1; - } + case db_ref_e: + return 1; + case string_e: + return strcmp((char *)StringOfTerm(t1), (char *)StringOfTerm(t2)); + } + return -1; + } + return -1; + } case db_ref_e: - if (IsRefTerm(t2)) - return Unsigned(RefOfTerm(t2)) - - Unsigned(RefOfTerm(t1)); - return -1; + if (IsRefTerm(t2)) + return Unsigned(RefOfTerm(t2)) - Unsigned(RefOfTerm(t1)); + return -1; } } if (!IsApplTerm(t2)) { if (IsPairTerm(t2)) { - Int out; - Functor f = FunctorOfTerm(t1); + Int out; + Functor f = FunctorOfTerm(t1); - if (!(out = ArityOfFunctor(f))-2) - out = strcmp((char *)RepAtom(NameOfFunctor(f))->StrOfAE,"."); - return out; + if (!(out = ArityOfFunctor(f)) - 2) + out = strcmp((char *)RepAtom(NameOfFunctor(f))->StrOfAE, "."); + return out; } return 1; } else { @@ -517,46 +509,42 @@ compare(Term t1, Term t2) /* compare terms t1 and t2 */ Int r; if (IsExtensionFunctor(fun2)) { - return 1; + return 1; } r = ArityOfFunctor(fun1) - ArityOfFunctor(fun2); if (r) - return r; + return r; r = cmp_atoms(NameOfFunctor(fun1), NameOfFunctor(fun2)); if (r) - return r; + return r; else - return(compare_complex(RepAppl(t1), - RepAppl(t1)+ArityOfFunctor(fun1), - RepAppl(t2))); + return (compare_complex(RepAppl(t1), RepAppl(t1) + ArityOfFunctor(fun1), + RepAppl(t2))); } } } -Int Yap_compare_terms(Term d0, Term d1) -{ - return compare(Deref(d0),Deref(d1)); +Int Yap_compare_terms(Term d0, Term d1) { + return compare(Deref(d0), Deref(d1)); } -/** @pred compare( _C_, _X_, _Y_) is iso +/** @pred compare( _C_, _X_, _Y_) is iso As a result of comparing _X_ and _Y_, _C_ may take one of the following values: -+ ++ `=` if _X_ and _Y_ are identical; -+ ++ `<` if _X_ precedes _Y_ in the defined order; -+ ++ `>` if _Y_ precedes _X_ in the defined order; */ -Int -p_compare( USES_REGS1 ) -{ /* compare(?Op,?T1,?T2) */ - Int r = compare(Deref(ARG2), Deref(ARG3)); - Atom p; +Int p_compare(USES_REGS1) { /* compare(?Op,?T1,?T2) */ + Int r = compare(Deref(ARG2), Deref(ARG3)); + Atom p; Term t = Deref(ARG1); if (r < 0) p = AtomLT; @@ -568,70 +556,46 @@ p_compare( USES_REGS1 ) if (IsAtomTerm(t)) { Atom a = AtomOfTerm(t); if (a == p) - return true; - if (a != AtomLT && - a != AtomGT && - a != AtomEq) - Yap_Error(DOMAIN_ERROR_ORDER, ARG1, NULL); + return true; + if (a != AtomLT && a != AtomGT && a != AtomEq) + Yap_Error(DOMAIN_ERROR_ORDER, ARG1, NULL); } else { - Yap_Error(TYPE_ERROR_ATOM, ARG1, NULL); + Yap_Error(TYPE_ERROR_ATOM, ARG1, NULL); } return false; } - + 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. */ -static Int -a_noteq(Term t1, Term t2) -{ - return (compare(t1, t2) != 0); -} +static Int a_noteq(Term t1, Term t2) { return (compare(t1, t2) != 0); } -static Int -a_gen_lt(Term t1, Term t2) -{ - return (compare(t1, t2) < 0); -} +static Int a_gen_lt(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. */ -static Int -a_gen_le(Term t1, Term t2) -{ - return (compare(t1, t2) <= 0); -} +static Int 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 */ -static Int -a_gen_gt(Term t1, Term t2) -{ - return compare(t1, t2) > 0; -} +static Int 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 -a_gen_ge(Term t1, Term t2) -{ - return compare(t1, t2) >= 0; -} - +static Int 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 @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 -int_cmp(Int dif) -{ - return dif; -} +inline static Int int_cmp(Int dif) { return dif; } -inline static Int -flt_cmp(Float dif) -{ +inline static Int flt_cmp(Float dif) { if (dif < 0.0) return -1; if (dif > 0.0) @@ -662,26 +621,20 @@ flt_cmp(Float dif) return dif = 0.0; } - -static inline Int -a_cmp(Term t1, Term t2 USES_REGS) -{ - LOCAL_ArithError = FALSE; +static inline Int a_cmp(Term t1, Term t2 USES_REGS) { if (IsVarTerm(t1)) { - LOCAL_ArithError = TRUE; Yap_Error(INSTANTIATION_ERROR, t1, "=:=/2"); return FALSE; } if (IsVarTerm(t2)) { - LOCAL_ArithError = TRUE; Yap_Error(INSTANTIATION_ERROR, t2, "=:=/2"); return FALSE; } if (IsFloatTerm(t1) && IsFloatTerm(t2)) { - return flt_cmp(FloatOfTerm(t1)-FloatOfTerm(t2)); + return flt_cmp(FloatOfTerm(t1) - FloatOfTerm(t2)); } if (IsIntegerTerm(t1) && IsIntegerTerm(t2)) { - return int_cmp(IntegerOfTerm(t1)-IntegerOfTerm(t2)); + return int_cmp(IntegerOfTerm(t1) - IntegerOfTerm(t2)); } t1 = Yap_Eval(t1); if (!t1) { @@ -693,21 +646,19 @@ a_cmp(Term t1, Term t2 USES_REGS) if (IsIntegerTerm(t2)) { Int i2 = IntegerOfTerm(t2); - return int_cmp(i1-i2); + return int_cmp(i1 - i2); } else if (IsFloatTerm(t2)) { Float f2 = FloatOfTerm(t2); #if HAVE_ISNAN if (isnan(f2)) { - LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED; - LOCAL_Error_Term = t2; - LOCAL_ErrorMessage = "trying to evaluate nan"; - LOCAL_ArithError = TRUE; + LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED; + LOCAL_ErrorMessage = "trying to evaluate nan"; } -#endif - return flt_cmp(i1-f2); +#endif + return flt_cmp(i1 - f2); #ifdef USE_GMP } else if (IsBigIntTerm(t2)) { - return Yap_gmp_cmp_int_big(i1,t2); + return Yap_gmp_cmp_int_big(i1, t2); #endif } else { return FALSE; @@ -717,34 +668,30 @@ a_cmp(Term t1, Term t2 USES_REGS) #if HAVE_ISNAN if (isnan(f1)) { LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED; - LOCAL_Error_Term = t1; LOCAL_ErrorMessage = "trying to evaluate nan"; - LOCAL_ArithError = TRUE; } -#endif +#endif t2 = Yap_Eval(t2); #if HAVE_ISNAN - if (isnan(f1)) - return -1; -#endif + if (isnan(f1)) + return -1; +#endif if (IsIntegerTerm(t2)) { Int i2 = IntegerOfTerm(t2); - return flt_cmp(f1-i2); + return flt_cmp(f1 - i2); } else if (IsFloatTerm(t2)) { Float f2 = FloatOfTerm(t2); #if HAVE_ISNAN if (isnan(f2)) { - LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED; - LOCAL_Error_Term = t2; - LOCAL_ErrorMessage = "trying to evaluate nan"; - LOCAL_ArithError = TRUE; + LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED; + LOCAL_ErrorMessage = "trying to evaluate nan"; } -#endif - return flt_cmp(f1-f2); +#endif + return flt_cmp(f1 - f2); #ifdef USE_GMP } else if (IsBigIntTerm(t2)) { - return Yap_gmp_cmp_float_big(f1,t2); + return Yap_gmp_cmp_float_big(f1, t2); #endif } else { return FALSE; @@ -755,22 +702,20 @@ a_cmp(Term t1, Term t2 USES_REGS) t2 = Yap_Eval(t2); if (IsIntegerTerm(t2)) { - return Yap_gmp_cmp_big_int(t1, IntegerOfTerm(t2)); + return Yap_gmp_cmp_big_int(t1, IntegerOfTerm(t2)); } else if (IsFloatTerm(t2)) { - Float f2 = FloatOfTerm(t2); + Float f2 = FloatOfTerm(t2); #if HAVE_ISNAN - if (isnan(f2)) { - LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED; - LOCAL_Error_Term = t2; - LOCAL_ErrorMessage = "trying to evaluate nan"; - LOCAL_ArithError = TRUE; - } -#endif - return Yap_gmp_cmp_big_float(t1, f2); + if (isnan(f2)) { + LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED; + LOCAL_ErrorMessage = "trying to evaluate nan"; + } +#endif + return Yap_gmp_cmp_big_float(t1, f2); } else if (IsBigIntTerm(t2)) { - return Yap_gmp_cmp_big_big(t1, t2); + return Yap_gmp_cmp_big_big(t1, t2); } else { - return FALSE; + return FALSE; } } #endif @@ -779,23 +724,17 @@ a_cmp(Term t1, Term t2 USES_REGS) } } -Int -Yap_acmp(Term t1, Term t2 USES_REGS) -{ +Int Yap_acmp(Term t1, Term t2 USES_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; } -static Int -p_acomp( USES_REGS1 ) -{ /* $a_compare(?R,+X,+Y) */ +static Int p_acomp(USES_REGS1) { /* $a_compare(?R,+X,+Y) */ Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); Int out; out = a_cmp(t1, t2 PASS_REGS); - if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; } return out; } @@ -806,9 +745,7 @@ p_acomp( USES_REGS1 ) The value of the expression _X_ is equal to the value of expression _Y_. */ /// @memberof =:=/2 -static Int -a_eq(Term t1, Term t2) -{ +static Int a_eq(Term t1, Term t2) { CACHE_REGS /* A =:= B */ Int out; @@ -817,11 +754,11 @@ a_eq(Term t1, Term t2) if (IsVarTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "=:=/2"); - return(FALSE); + return (FALSE); } if (IsVarTerm(t2)) { Yap_Error(INSTANTIATION_ERROR, t2, "=:=/2"); - return(FALSE); + return (FALSE); } if (IsFloatTerm(t1)) { if (IsFloatTerm(t2)) @@ -837,25 +774,22 @@ a_eq(Term t1, Term t2) return (FloatOfTerm(t2) == IntegerOfTerm(t1)); } } - out = a_cmp(t1,t2 PASS_REGS); - if (LOCAL_ArithError) { Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); return FALSE; } + out = a_cmp(t1, t2 PASS_REGS); + Yap_Error(LOCAL_Error_TYPE, t1, LOCAL_ErrorMessage); return out == 0; } - /* @pred +_X_ =\\= _Y_ is iso 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 -static Int -a_dif(Term t1, Term t2) -{ +static Int a_dif(Term t1, Term t2) { CACHE_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; } + Int out = a_cmp(Deref(t1), Deref(t2) PASS_REGS); 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 of expression _Y_. */ -static Int -a_gt(Term t1, Term t2) -{ /* A > B */ +static Int a_gt(Term t1, Term t2) { /* A > B */ CACHE_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; } + Int out = a_cmp(Deref(t1), Deref(t2) PASS_REGS); 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 value of expression _Y_. */ -static Int -a_ge(Term t1, Term t2) -{ /* A >= B */ +static Int a_ge(Term t1, Term t2) { /* A >= B */ CACHE_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; } + Int out = a_cmp(Deref(t1), Deref(t2) PASS_REGS); return out >= 0; } @@ -899,12 +827,9 @@ a_ge(Term t1, Term t2) _Y_. */ /// @memberof ", 2, a_gt, SafePredFlag | BinaryPredFlag); + Yap_InitCmpPred(">", 2, a_gt, SafePredFlag | BinaryPredFlag); Yap_InitCmpPred("=<", 2, a_le, SafePredFlag | BinaryPredFlag); Yap_InitCmpPred("<", 2, a_lt, SafePredFlag | BinaryPredFlag); Yap_InitCmpPred(">=", 2, a_ge, SafePredFlag | BinaryPredFlag); diff --git a/C/compiler.c b/C/compiler.c index 19a404be2..71ab1760f 100644 --- a/C/compiler.c +++ b/C/compiler.c @@ -11,7 +11,8 @@ * File: compiler.c * * comments: Clause compiler * * * -* Last rev: $Date: 2008-08-06 17:32:18 $,$Author: vsc $ * +* Last rev: $Date: 2008-08-06 17:32:18 $,$Author: vsc $ +** * $Log: not supported by cvs2svn $ * Revision 1.88 2008/03/13 14:37:58 vsc * update chr @@ -67,7 +68,8 @@ * fix debugging typo * * Revision 1.73 2006/04/12 20:08:51 vsc -* make it sure that making vars safe does not propagate across branches of disjunctions. +* make it sure that making vars safe does not propagate across branches of +*disjunctions. * * Revision 1.72 2006/04/05 00:16:54 vsc * Lots of fixes (check logfile for details @@ -137,7 +139,8 @@ * Handle overflows when allocating big clauses properly. * * Revision 1.54 2004/11/19 22:08:41 vsc -* replace SYSTEM_ERROR_INTERNAL by out OUT_OF_WHATEVER_ERROR whenever appropriate. +* replace SYSTEM_ERROR_INTERNAL by out OUT_OF_WHATEVER_ERROR whenever +*appropriate. * * Revision 1.53 2004/09/03 03:11:08 vsc * memory management fixes @@ -167,11 +170,11 @@ #ifdef SCCS static char SccsId[] = "%W% %G%"; -#endif /* SCCS */ +#endif /* SCCS */ #include "Yap.h" -#include "compile.h" -#include "clause.h" #include "alloc.h" +#include "clause.h" +#include "compile.h" #include "yapio.h" #if HAVE_STRING_H #include @@ -179,12 +182,12 @@ static char SccsId[] = "%W% %G%"; #ifdef BEAM extern int EAM; -//extern PInstr *CodeStart, *ppc, *ppc1, *BodyStart, *ppc_body; +// extern PInstr *CodeStart, *ppc, *ppc1, *BodyStart, *ppc_body; #endif typedef struct branch_descriptor { - int id; /* the branch id */ - Term cm; /* if a banch is associated with a commit */ + int id; /* the branch id */ + Term cm; /* if a banch is associated with a commit */ } branch; typedef struct compiler_struct_struct { @@ -232,7 +235,8 @@ static void c_arg(Int, Term, unsigned int, unsigned int, compiler_struct *); static void c_args(Term, unsigned int, compiler_struct *); static void c_eq(Term, Term, compiler_struct *); static void c_test(Int, Term, compiler_struct *); -static void c_bifun(basic_preds, Term, Term, Term, Term, Term, compiler_struct *); +static void c_bifun(basic_preds, Term, Term, Term, Term, Term, + compiler_struct *); static void c_goal(Term, Term, compiler_struct *); static void c_body(Term, Term, compiler_struct *); static void c_head(Term, compiler_struct *); @@ -243,38 +247,34 @@ static void clear_bvarray(int, CELL *, compiler_struct *); #else static void clear_bvarray(int, CELL *); #endif -static void add_bvarray_op(PInstr *,CELL *, int, compiler_struct *); +static void add_bvarray_op(PInstr *, CELL *, int, compiler_struct *); static void AssignPerm(PInstr *, compiler_struct *); static void CheckUnsafe(PInstr *, compiler_struct *); static void CheckVoids(compiler_struct *); -static int checktemp(Int, Int, compiler_vm_op, compiler_struct *); -static Int checkreg(Int, Int, compiler_vm_op, int, compiler_struct *); +static int checktemp(Int, Int, compiler_vm_op, compiler_struct *); +static Int checkreg(Int, Int, compiler_vm_op, int, compiler_struct *); static void c_layout(compiler_struct *); static void c_optimize(PInstr *); #ifdef SFUNC static void compile_sf_term(Term, int); #endif -static void -push_branch(int id, Term cmvar, compiler_struct *cglobs) { +static void push_branch(int id, Term cmvar, compiler_struct *cglobs) { cglobs->branch_pointer->id = id; cglobs->branch_pointer->cm = cmvar; cglobs->branch_pointer++; } -static int -pop_branch(compiler_struct *cglobs) { +static int pop_branch(compiler_struct *cglobs) { cglobs->branch_pointer--; - return(cglobs->branch_pointer->id); + return (cglobs->branch_pointer->id); } #ifdef TABLING -#define is_tabled(pe) (pe->PredFlags & TabledPredFlag) +#define is_tabled(pe) (pe->PredFlags & TabledPredFlag) #endif /* TABLING */ -static inline int -active_branch(int i, int onbranch) -{ +static inline int active_branch(int i, int onbranch) { /* register int *bp;*/ return (i == onbranch); @@ -286,19 +286,22 @@ active_branch(int i, int onbranch) return(i==onbranch);*/ } -#define FAIL(M,T,E) { LOCAL_ErrorMessage=M; LOCAL_Error_TYPE = T; LOCAL_Error_Term = E; return; } +#define FAIL(M, T, E) \ + { \ + LOCAL_Error_TYPE = T; \ + return; \ + } #if USE_SYSTEM_MALLOC -#define IsNewVar(v) ((CELL *)(v) >= H0 && (CELL *)(v) < LCL0) +#define IsNewVar(v) ((CELL *)(v) >= H0 && (CELL *)(v) < LCL0) #else -#define IsNewVar(v) (Addr(v)cint.freep0 || Addr(v)>cglobs->cint.freep) +#define IsNewVar(v) \ + (Addr(v) < cglobs->cint.freep0 || Addr(v) > cglobs->cint.freep) #endif inline static void pop_code(unsigned int, compiler_struct *); -inline static void -pop_code(unsigned int level, compiler_struct *cglobs) -{ +inline static void pop_code(unsigned int level, compiler_struct *cglobs) { if (level == 0) return; if (cglobs->cint.cpc->op == pop_op) @@ -308,8 +311,7 @@ pop_code(unsigned int level, compiler_struct *cglobs) } } -static void -adjust_current_commits(compiler_struct *cglobs) { +static void adjust_current_commits(compiler_struct *cglobs) { branch *bp = cglobs->branch_pointer; while (bp > cglobs->parent_branches) { bp--; @@ -319,22 +321,21 @@ adjust_current_commits(compiler_struct *cglobs) { } } - -static int -check_var(Term t, unsigned int level, Int argno, compiler_struct *cglobs) { +static int check_var(Term t, unsigned int level, Int argno, + compiler_struct *cglobs) { CACHE_REGS int flags, new = FALSE; Ventry *v = (Ventry *)t; - if (IsNewVar(v)) { /* new var */ - v = (Ventry *) Yap_AllocCMem(sizeof(*v), &cglobs->cint); + if (IsNewVar(v)) { /* new var */ + v = (Ventry *)Yap_AllocCMem(sizeof(*v), &cglobs->cint); #if YAPOR_SBA v->SelfOfVE = 0; #else - v->SelfOfVE = (CELL) v; + v->SelfOfVE = (CELL)v; #endif v->AdrsOfVE = t; - *CellPtr(t) = (CELL) v; + *CellPtr(t) = (CELL)v; v->KindOfVE = v->NoOfVE = Unassigned; flags = 0; /* Be careful with eithers. I may make a variable global in a branch, @@ -349,12 +350,11 @@ check_var(Term t, unsigned int level, Int argno, compiler_struct *cglobs) { And, yes, there is code like this... */ - if (((level > 0 || cglobs->onhead) && cglobs->curbranch == 0) - || argno == save_pair_flag || - argno == save_appl_flag) + if (((level > 0 || cglobs->onhead) && cglobs->curbranch == 0) || + argno == save_pair_flag || argno == save_appl_flag) flags |= SafeVar; - if ((level > 0 && cglobs->curbranch == 0) || argno == save_pair_flag || - argno == save_appl_flag) + if ((level > 0 && cglobs->curbranch == 0) || argno == save_pair_flag || + argno == save_appl_flag) flags |= GlobalVal; v->FlagsOfVE = flags; v->BranchOfVE = cglobs->onbranch; @@ -367,29 +367,29 @@ check_var(Term t, unsigned int level, Int argno, compiler_struct *cglobs) { v->FlagsOfVE |= NonVoid; if (v->BranchOfVE > 0) { if (!active_branch(v->BranchOfVE, cglobs->onbranch)) { - v->AgeOfVE = v->FirstOfVE = 1; - new = FALSE; - v->FlagsOfVE |= BranchVar; - /* set the original instruction correctly */ - switch (v->FirstOpForV->op) { - case get_var_op: - v->FirstOpForV->op = get_val_op; - break; - case unify_var_op: - v->FirstOpForV->op = unify_val_op; - break; - case unify_last_var_op: - v->FirstOpForV->op = unify_last_val_op; - break; - case put_var_op: - v->FirstOpForV->op = put_val_op; - break; - case write_var_op: - v->FirstOpForV->op = write_val_op; - break; - default: - break; - } + v->AgeOfVE = v->FirstOfVE = 1; + new = FALSE; + v->FlagsOfVE |= BranchVar; + /* set the original instruction correctly */ + switch (v->FirstOpForV->op) { + case get_var_op: + v->FirstOpForV->op = get_val_op; + break; + case unify_var_op: + v->FirstOpForV->op = unify_val_op; + break; + case unify_last_var_op: + v->FirstOpForV->op = unify_last_val_op; + break; + case put_var_op: + v->FirstOpForV->op = put_val_op; + break; + case write_var_op: + v->FirstOpForV->op = write_val_op; + break; + default: + break; + } } } } @@ -398,10 +398,8 @@ check_var(Term t, unsigned int level, Int argno, compiler_struct *cglobs) { return new; } -static void -tag_var(Term t, int new, compiler_struct *cglobs) -{ - Ventry *v = (Ventry *) t; +static void tag_var(Term t, int new, compiler_struct *cglobs) { + Ventry *v = (Ventry *)t; if (new) { v->FirstOpForV = cglobs->cint.cpc; @@ -414,9 +412,8 @@ tag_var(Term t, int new, compiler_struct *cglobs) v->AgeOfVE = cglobs->goalno; } -static void -c_var(Term t, Int argno, unsigned int arity, unsigned int level, compiler_struct *cglobs) -{ +static void c_var(Term t, Int argno, unsigned int arity, unsigned int level, + compiler_struct *cglobs) { int new = check_var(Deref(t), level, argno, cglobs); t = Deref(t); @@ -450,37 +447,40 @@ c_var(Term t, Int argno, unsigned int arity, unsigned int level, compiler_struct #ifdef SFUNC if (argno < 0) { if (new) - Yap_emit((cglobs->onhead ? unify_s_var_op : write_s_var_op), v, -argno, &cglobs->cint); + Yap_emit((cglobs->onhead ? unify_s_var_op : write_s_var_op), v, -argno, + &cglobs->cint); else - Yap_emit((cglobs->onhead ? unify_s_val_op : write_s_val_op), v, -argno, &cglobs->cint); + Yap_emit((cglobs->onhead ? unify_s_val_op : write_s_val_op), v, -argno, + &cglobs->cint); } else #endif - if (cglobs->onhead) { - cglobs->space_used ++; + if (cglobs->onhead) { + cglobs->space_used++; if (level == 0) - Yap_emit((new ? (++cglobs->nvars, get_var_op) : get_val_op), t, argno, &cglobs->cint); + Yap_emit((new ? (++cglobs->nvars, get_var_op) : get_val_op), t, argno, + &cglobs->cint); else - Yap_emit((new ? (++cglobs->nvars, (argno == (Int)arity ? - unify_last_var_op : - unify_var_op)) : - (argno == (Int)arity ? unify_last_val_op : - unify_val_op)), - t, Zero, &cglobs->cint); - } - else { + Yap_emit( + (new ? (++cglobs->nvars, + (argno == (Int)arity ? unify_last_var_op : unify_var_op)) + : (argno == (Int)arity ? unify_last_val_op : unify_val_op)), + t, Zero, &cglobs->cint); + } else { if (level == 0) - Yap_emit((new ? (++cglobs->nvars, put_var_op) : put_val_op), t, argno, &cglobs->cint); + Yap_emit((new ? (++cglobs->nvars, put_var_op) : put_val_op), t, argno, + &cglobs->cint); else - Yap_emit((new ? (++cglobs->nvars, write_var_op) : write_val_op), t, Zero, &cglobs->cint); + Yap_emit((new ? (++cglobs->nvars, write_var_op) : write_val_op), t, + Zero, &cglobs->cint); } } tag_var(t, new, cglobs); } // built-in like X >= Y. -static void -c_2vars(int op, Term t1, Int argno1, Term t2, Int argno2, CELL extra, unsigned int arity, unsigned int level, compiler_struct *cglobs) -{ +static void c_2vars(int op, Term t1, Int argno1, Term t2, Int argno2, + CELL extra, unsigned int arity, unsigned int level, + compiler_struct *cglobs) { int new1 = check_var((t1 = Deref(t1)), level, argno1, cglobs); int new2 = check_var((t2 = Deref(t2)), level, argno2, cglobs); @@ -495,28 +495,26 @@ c_2vars(int op, Term t1, Int argno1, Term t2, Int argno2, CELL extra, unsigned i tag_var(t2, new2, cglobs); } -static void -reset_vars(Ventry *vtable) -{ +static void reset_vars(Ventry *vtable) { Ventry *v = vtable; CELL *t; while (v != NIL) { - t = (CELL *) v->AdrsOfVE; + t = (CELL *)v->AdrsOfVE; RESET_VARIABLE(t); v = v->NextOfVE; } } -static Term -optimize_ce(Term t, unsigned int arity, unsigned int level, compiler_struct *cglobs) -{ +static Term optimize_ce(Term t, unsigned int arity, unsigned int level, + compiler_struct *cglobs) { CACHE_REGS CExpEntry *p = cglobs->common_exps; int cmp = 0; #ifdef BEAM - if (EAM) return t; + if (EAM) + return t; #endif if (IsApplTerm(t) && IsExtensionFunctor(FunctorOfTerm(t))) @@ -533,7 +531,7 @@ optimize_ce(Term t, unsigned int arity, unsigned int level, compiler_struct *cgl break; } } - if (p != NULL) { /* already there */ + if (p != NULL) { /* already there */ return (p->VarOfCE); } /* first occurrence */ @@ -541,14 +539,14 @@ optimize_ce(Term t, unsigned int arity, unsigned int level, compiler_struct *cgl return t; } ++(cglobs->n_common_exps); - p = (CExpEntry *) Yap_AllocCMem(sizeof(CExpEntry), &cglobs->cint); + p = (CExpEntry *)Yap_AllocCMem(sizeof(CExpEntry), &cglobs->cint); p->TermOfCE = t; p->VarOfCE = MkVarTerm(); if (HR >= (CELL *)cglobs->cint.freep0) { /* oops, too many new variables */ save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_TEMPS_BOTCH); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_TEMPS_BOTCH); } p->NextCE = cglobs->common_exps; cglobs->common_exps = p; @@ -560,46 +558,46 @@ optimize_ce(Term t, unsigned int arity, unsigned int level, compiler_struct *cgl } #ifdef SFUNC -static void -compile_sf_term(Term t, int argno, int level) -{ +static void compile_sf_term(Term t, int argno, int level) { Functor f = FunctorOfTerm(t); CELL *p = ArgsOfSFTerm(t) - 1; SFEntry *pe = RepSFProp(Yap_GetAProp(NameOfFunctor(f), SFProperty)); Term nullvalue = pe->NilValue; if (level == 0) - Yap_emit((cglobs->onhead ? get_s_f_op : put_s_f_op), f, argno, &cglobs->cint); + Yap_emit((cglobs->onhead ? get_s_f_op : put_s_f_op), f, argno, + &cglobs->cint); else - Yap_emit((cglobs->onhead ? unify_s_f_op : write_s_f_op), f, Zero, &cglobs->cint); + Yap_emit((cglobs->onhead ? unify_s_f_op : write_s_f_op), f, Zero, + &cglobs->cint); ++level; while ((argno = *++p)) { t = Derefa(++p); if (t != nullvalue) { if (IsAtomicTerm(t)) - Yap_emit((cglobs->onhead ? unify_s_a_op : write_s_a_op), t, (CELL) argno, &cglobs->cint); + Yap_emit((cglobs->onhead ? unify_s_a_op : write_s_a_op), t, (CELL)argno, + &cglobs->cint); else if (!IsVarTerm(t)) { - LOCAL_Error_TYPE = SYSTEM_ERROR_COMPILER; - LOCAL_Error_Term = TermNil; - LOCAL_ErrorMessage = "illegal argument of soft functor"; - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH); - } - else - c_var(t, -argno, arity, level, cglobs); + LOCAL_Error_TYPE = SYSTEM_ERROR_COMPILER; + LOCAL_ErrorMessage = "illegal argument of soft functor"; + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH); + } else + c_var(t, -argno, arity, level, cglobs); } } --level; if (level == 0) - Yap_emit((cglobs->onhead ? get_s_end_op : put_s_end_op), Zero, Zero, &cglobs->cint); + Yap_emit((cglobs->onhead ? get_s_end_op : put_s_end_op), Zero, Zero, + &cglobs->cint); else - Yap_emit((cglobs->onhead ? unify_s_end_op : write_s_end_op), Zero, Zero, &cglobs->cint); + Yap_emit((cglobs->onhead ? unify_s_end_op : write_s_end_op), Zero, Zero, + &cglobs->cint); } #endif -inline static void -c_args(Term app, unsigned int level, compiler_struct *cglobs) -{ +inline static void c_args(Term app, unsigned int level, + compiler_struct *cglobs) { CACHE_REGS Functor f = FunctorOfTerm(app); unsigned int Arity = ArityOfFunctor(f); @@ -608,7 +606,6 @@ c_args(Term app, unsigned int level, compiler_struct *cglobs) if (level == 0) { if (Arity >= MaxTemps) { LOCAL_Error_TYPE = SYSTEM_ERROR_COMPILER; - LOCAL_Error_Term = TermNil; LOCAL_ErrorMessage = "exceed maximum arity of compiled goal"; save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH); @@ -620,191 +617,208 @@ c_args(Term app, unsigned int level, compiler_struct *cglobs) c_arg(i, ArgOfTerm(i, app), Arity, level, cglobs); } -static int -try_store_as_dbterm(Term t, Int argno, unsigned int arity, int level, compiler_struct *cglobs) -{ +static int try_store_as_dbterm(Term t, Int argno, unsigned int arity, int level, + compiler_struct *cglobs) { CACHE_REGS DBTerm *dbt; int g; CELL *h0 = HR; - while ((g=Yap_SizeGroundTerm(t,TRUE)) < 0) { + while ((g = Yap_SizeGroundTerm(t, TRUE)) < 0) { /* oops, too deep a term */ save_machine_regs(); LOCAL_Error_Size = 0; siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_AUX_BOTCH); } // if (g < 16) - return FALSE; + return FALSE; /* store ground term away */ HR = CellPtr(cglobs->cint.freep); if ((dbt = Yap_StoreTermInDB(t, -1)) == NULL) { HR = h0; - switch(LOCAL_Error_TYPE) { + switch (LOCAL_Error_TYPE) { case RESOURCE_ERROR_STACK: LOCAL_Error_TYPE = YAP_NO_ERROR; - siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_STACK_BOTCH); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_STACK_BOTCH); case RESOURCE_ERROR_TRAIL: LOCAL_Error_TYPE = YAP_NO_ERROR; - siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_TRAIL_BOTCH); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_TRAIL_BOTCH); case RESOURCE_ERROR_HEAP: LOCAL_Error_TYPE = YAP_NO_ERROR; - siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_HEAP_BOTCH); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_HEAP_BOTCH); case RESOURCE_ERROR_AUXILIARY_STACK: LOCAL_Error_TYPE = YAP_NO_ERROR; - siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_AUX_BOTCH); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_AUX_BOTCH); default: - siglongjmp(cglobs->cint.CompilerBotch,COMPILER_ERR_BOTCH); + siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH); } } HR = h0; if (level == 0) - Yap_emit((cglobs->onhead ? get_dbterm_op : put_dbterm_op), dbt->Entry, argno, &cglobs->cint); + Yap_emit((cglobs->onhead ? get_dbterm_op : put_dbterm_op), dbt->Entry, + argno, &cglobs->cint); else Yap_emit((cglobs->onhead ? (argno == (Int)arity ? unify_last_dbterm_op - : unify_dbterm_op) : - write_dbterm_op), dbt->Entry, Zero, &cglobs->cint); + : unify_dbterm_op) + : write_dbterm_op), + dbt->Entry, Zero, &cglobs->cint); return TRUE; } -static void -c_arg(Int argno, Term t, unsigned int arity, unsigned int level, compiler_struct *cglobs) -{ - restart: +static void c_arg(Int argno, Term t, unsigned int arity, unsigned int level, + compiler_struct *cglobs) { +restart: if (IsVarTerm(t)) c_var(t, argno, arity, level, cglobs); else if (IsAtomTerm(t)) { - if (level == 0) { - Yap_emit((cglobs->onhead ? get_atom_op : put_atom_op), (CELL) t, argno, &cglobs->cint); + if (level == 0) { + Yap_emit((cglobs->onhead ? get_atom_op : put_atom_op), (CELL)t, argno, + &cglobs->cint); } else - Yap_emit((cglobs->onhead ? (argno == (Int)arity ? unify_last_atom_op - : unify_atom_op) : - write_atom_op), (CELL) t, Zero, &cglobs->cint); - } else if (IsIntegerTerm(t) || IsFloatTerm(t) || IsBigIntTerm(t) || IsStringTerm(t)) { + Yap_emit((cglobs->onhead + ? (argno == (Int)arity ? unify_last_atom_op : unify_atom_op) + : write_atom_op), + (CELL)t, Zero, &cglobs->cint); + } else if (IsIntegerTerm(t) || IsFloatTerm(t) || IsBigIntTerm(t) || + IsStringTerm(t)) { if (!IsIntTerm(t)) { if (IsFloatTerm(t)) { - if (level == 0) - Yap_emit((cglobs->onhead ? get_float_op : put_float_op), t, argno, &cglobs->cint); - else - Yap_emit((cglobs->onhead ? (argno == (Int)arity ? unify_last_float_op - : unify_float_op) : - write_float_op), t, Zero, &cglobs->cint); + if (level == 0) + Yap_emit((cglobs->onhead ? get_float_op : put_float_op), t, argno, + &cglobs->cint); + else + Yap_emit((cglobs->onhead ? (argno == (Int)arity ? unify_last_float_op + : unify_float_op) + : write_float_op), + t, Zero, &cglobs->cint); } else if (IsLongIntTerm(t)) { - if (level == 0) - Yap_emit((cglobs->onhead ? get_longint_op : put_longint_op), t, argno, &cglobs->cint); - else - Yap_emit((cglobs->onhead ? (argno == (Int)arity ? unify_last_longint_op - : unify_longint_op) : - write_longint_op), t, Zero, &cglobs->cint); + if (level == 0) + Yap_emit((cglobs->onhead ? get_longint_op : put_longint_op), t, argno, + &cglobs->cint); + else + Yap_emit((cglobs->onhead + ? (argno == (Int)arity ? unify_last_longint_op + : unify_longint_op) + : write_longint_op), + t, Zero, &cglobs->cint); } else if (IsStringTerm(t)) { - /* we are taking a string, that is supposed to be - guarded in the clause itself. . */ - CELL l1 = ++cglobs->labelno; - CELL *src = RepAppl(t); - PInstr *ocpc = cglobs->cint.cpc, *OCodeStart = cglobs->cint.CodeStart; - Int sz = (3+src[1])*sizeof(CELL); - CELL *dest; + /* we are taking a string, that is supposed to be + guarded in the clause itself. . */ + CELL l1 = ++cglobs->labelno; + CELL *src = RepAppl(t); + PInstr *ocpc = cglobs->cint.cpc, *OCodeStart = cglobs->cint.CodeStart; + Int sz = (3 + src[1]) * sizeof(CELL); + CELL *dest; - /* use a special list to store the blobs */ - cglobs->cint.cpc = cglobs->cint.icpc; - /* if (IsFloatTerm(t)) { - Yap_emit(align_float_op, Zero, Zero, &cglobs->cint); - }*/ - Yap_emit(label_op, l1, Zero, &cglobs->cint); - dest = - Yap_emit_extra_size(blob_op, sz/CellSize, sz, &cglobs->cint); + /* use a special list to store the blobs */ + cglobs->cint.cpc = cglobs->cint.icpc; + /* if (IsFloatTerm(t)) { + Yap_emit(align_float_op, Zero, Zero, &cglobs->cint); + }*/ + Yap_emit(label_op, l1, Zero, &cglobs->cint); + dest = Yap_emit_extra_size(blob_op, sz / CellSize, sz, &cglobs->cint); - /* copy the bignum */ - memcpy(dest, src, sz); - /* note that we don't need to copy size info, unless we wanted - to garbage collect clauses ;-) */ - cglobs->cint.icpc = cglobs->cint.cpc; - if (cglobs->cint.BlobsStart == NULL) - cglobs->cint.BlobsStart = cglobs->cint.CodeStart; - cglobs->cint.cpc = ocpc; - cglobs->cint.CodeStart = OCodeStart; - /* The argument to pass to the structure is now the label for - where we are storing the blob */ - if (level == 0) - Yap_emit((cglobs->onhead ? get_string_op : put_string_op), l1, argno, &cglobs->cint); - else - Yap_emit((cglobs->onhead ? (argno == (Int)arity ? unify_last_string_op - : unify_string_op) : - write_string_op), l1, Zero, &cglobs->cint); + /* copy the bignum */ + memcpy(dest, src, sz); + /* note that we don't need to copy size info, unless we wanted + to garbage collect clauses ;-) */ + cglobs->cint.icpc = cglobs->cint.cpc; + if (cglobs->cint.BlobsStart == NULL) + cglobs->cint.BlobsStart = cglobs->cint.CodeStart; + cglobs->cint.cpc = ocpc; + cglobs->cint.CodeStart = OCodeStart; + /* The argument to pass to the structure is now the label for + where we are storing the blob */ + if (level == 0) + Yap_emit((cglobs->onhead ? get_string_op : put_string_op), l1, argno, + &cglobs->cint); + else + Yap_emit((cglobs->onhead ? (argno == (Int)arity ? unify_last_string_op + : unify_string_op) + : write_string_op), + l1, Zero, &cglobs->cint); } else { - /* we are taking a blob, that is a binary that is supposed to be - guarded in the clause itself. Possible examples include - floats, long ints, bignums, bitmaps.... */ - CELL l1 = ++cglobs->labelno; - CELL *src = RepAppl(t); - PInstr *ocpc = cglobs->cint.cpc, *OCodeStart = cglobs->cint.CodeStart; - Int sz = 2*sizeof(CELL)+sizeof(Functor)+ - sizeof(MP_INT)+ - ((((MP_INT *)(RepAppl(t)+2))->_mp_alloc)*sizeof(mp_limb_t)); - CELL *dest; + /* we are taking a blob, that is a binary that is supposed to be + guarded in the clause itself. Possible examples include + floats, long ints, bignums, bitmaps.... */ + CELL l1 = ++cglobs->labelno; + CELL *src = RepAppl(t); + PInstr *ocpc = cglobs->cint.cpc, *OCodeStart = cglobs->cint.CodeStart; + Int sz = + 2 * sizeof(CELL) + sizeof(Functor) + sizeof(MP_INT) + + ((((MP_INT *)(RepAppl(t) + 2))->_mp_alloc) * sizeof(mp_limb_t)); + CELL *dest; - /* use a special list to store the blobs */ - cglobs->cint.cpc = cglobs->cint.icpc; - /* if (IsFloatTerm(t)) { - Yap_emit(align_float_op, Zero, Zero, &cglobs->cint); - }*/ - Yap_emit(label_op, l1, Zero, &cglobs->cint); - dest = - Yap_emit_extra_size(blob_op, sz/CellSize, sz, &cglobs->cint); + /* use a special list to store the blobs */ + cglobs->cint.cpc = cglobs->cint.icpc; + /* if (IsFloatTerm(t)) { + Yap_emit(align_float_op, Zero, Zero, &cglobs->cint); + }*/ + Yap_emit(label_op, l1, Zero, &cglobs->cint); + dest = Yap_emit_extra_size(blob_op, sz / CellSize, sz, &cglobs->cint); - /* copy the bignum */ - memcpy(dest, src, sz); - /* note that we don't need to copy size info, unless we wanted - to garbage collect clauses ;-) */ - cglobs->cint.icpc = cglobs->cint.cpc; - if (cglobs->cint.BlobsStart == NULL) - cglobs->cint.BlobsStart = cglobs->cint.CodeStart; - cglobs->cint.cpc = ocpc; - cglobs->cint.CodeStart = OCodeStart; - /* The argument to pass to the structure is now the label for - where we are storing the blob */ - if (level == 0) - Yap_emit((cglobs->onhead ? get_bigint_op : put_bigint_op), l1, argno, &cglobs->cint); - else - Yap_emit((cglobs->onhead ? (argno == (Int)arity ? unify_last_bigint_op - : unify_bigint_op) : - write_bigint_op), l1, Zero, &cglobs->cint); + /* copy the bignum */ + memcpy(dest, src, sz); + /* note that we don't need to copy size info, unless we wanted + to garbage collect clauses ;-) */ + cglobs->cint.icpc = cglobs->cint.cpc; + if (cglobs->cint.BlobsStart == NULL) + cglobs->cint.BlobsStart = cglobs->cint.CodeStart; + cglobs->cint.cpc = ocpc; + cglobs->cint.CodeStart = OCodeStart; + /* The argument to pass to the structure is now the label for + where we are storing the blob */ + if (level == 0) + Yap_emit((cglobs->onhead ? get_bigint_op : put_bigint_op), l1, argno, + &cglobs->cint); + else + Yap_emit((cglobs->onhead ? (argno == (Int)arity ? unify_last_bigint_op + : unify_bigint_op) + : write_bigint_op), + l1, Zero, &cglobs->cint); } /* That's it folks! */ return; } if (level == 0) - Yap_emit((cglobs->onhead ? get_num_op : put_num_op), (CELL) t, argno, &cglobs->cint); + Yap_emit((cglobs->onhead ? get_num_op : put_num_op), (CELL)t, argno, + &cglobs->cint); else - Yap_emit((cglobs->onhead ? (argno == (Int)arity ? unify_last_num_op - : unify_num_op) : - write_num_op), (CELL) t, Zero, &cglobs->cint); + Yap_emit((cglobs->onhead + ? (argno == (Int)arity ? unify_last_num_op : unify_num_op) + : write_num_op), + (CELL)t, Zero, &cglobs->cint); } else if (IsPairTerm(t)) { cglobs->space_used += 2; if (optimizer_on && level < 6) { #if !defined(THREADS) && !defined(YAPOR) /* discard code sharing because we cannot write on shared stuff */ - if (FALSE && !(cglobs->cint.CurrentPred->PredFlags & (DynamicPredFlag|LogUpdatePredFlag))) { - if (try_store_as_dbterm(t, argno, arity, level, cglobs)) - return; - } -#endif + if (FALSE && + !(cglobs->cint.CurrentPred->PredFlags & + (DynamicPredFlag | LogUpdatePredFlag))) { + if (try_store_as_dbterm(t, argno, arity, level, cglobs)) + return; + } +#endif t = optimize_ce(t, arity, level, cglobs); if (IsVarTerm(t)) { - c_var(t, argno, arity, level, cglobs); - return; + c_var(t, argno, arity, level, cglobs); + return; } } if (level == 0) - Yap_emit((cglobs->onhead ? get_list_op : put_list_op), Zero, argno, &cglobs->cint); + Yap_emit((cglobs->onhead ? get_list_op : put_list_op), Zero, argno, + &cglobs->cint); else if (argno == (Int)arity) - Yap_emit((cglobs->onhead ? unify_last_list_op : write_last_list_op), Zero, Zero, &cglobs->cint); + Yap_emit((cglobs->onhead ? unify_last_list_op : write_last_list_op), Zero, + Zero, &cglobs->cint); else - Yap_emit((cglobs->onhead ? unify_list_op : write_list_op), Zero, Zero, &cglobs->cint); + Yap_emit((cglobs->onhead ? unify_list_op : write_list_op), Zero, Zero, + &cglobs->cint); ++level; c_arg(1, HeadOfTerm(t), 2, level, cglobs); if (argno == (Int)arity) { - /* optimise for tail recursion */ + /* optimise for tail recursion */ t = TailOfTerm(t); goto restart; } @@ -814,20 +828,23 @@ c_arg(Int argno, Term t, unsigned int arity, unsigned int level, compiler_struct pop_code(level, cglobs); } } else if (IsRefTerm(t)) { - PELOCK(40,cglobs->cint.CurrentPred); - if (!(cglobs->cint.CurrentPred->PredFlags & (DynamicPredFlag|LogUpdatePredFlag))) { + PELOCK(40, cglobs->cint.CurrentPred); + if (!(cglobs->cint.CurrentPred->PredFlags & + (DynamicPredFlag | LogUpdatePredFlag))) { CACHE_REGS UNLOCK(cglobs->cint.CurrentPred->PELock); - FAIL("can not compile data base reference",TYPE_ERROR_CALLABLE,t); + FAIL("can not compile data base reference", TYPE_ERROR_CALLABLE, t); } else { UNLOCK(cglobs->cint.CurrentPred->PELock); cglobs->hasdbrefs = TRUE; if (level == 0) - Yap_emit((cglobs->onhead ? get_atom_op : put_atom_op), (CELL) t, argno, &cglobs->cint); + Yap_emit((cglobs->onhead ? get_atom_op : put_atom_op), (CELL)t, argno, + &cglobs->cint); else - Yap_emit((cglobs->onhead ? (argno == (Int)arity ? unify_last_atom_op - : unify_atom_op) : - write_atom_op), (CELL) t, Zero, &cglobs->cint); + Yap_emit((cglobs->onhead ? (argno == (Int)arity ? unify_last_atom_op + : unify_atom_op) + : write_atom_op), + (CELL)t, Zero, &cglobs->cint); } } else { @@ -839,26 +856,27 @@ c_arg(Int argno, Term t, unsigned int arity, unsigned int level, compiler_struct #endif if (optimizer_on) { - if (!(cglobs->cint.CurrentPred->PredFlags & (DynamicPredFlag|LogUpdatePredFlag))) { - if (try_store_as_dbterm(t, argno, arity, level, cglobs)) - return; - } + if (!(cglobs->cint.CurrentPred->PredFlags & + (DynamicPredFlag | LogUpdatePredFlag))) { + if (try_store_as_dbterm(t, argno, arity, level, cglobs)) + return; + } t = optimize_ce(t, arity, level, cglobs); if (IsVarTerm(t)) { - c_var(t, argno, arity, level, cglobs); - return; + c_var(t, argno, arity, level, cglobs); + return; } } - cglobs->space_used += 1+arity; + cglobs->space_used += 1 + arity; if (level == 0) Yap_emit((cglobs->onhead ? get_struct_op : put_struct_op), - (CELL) FunctorOfTerm(t), argno, &cglobs->cint); + (CELL)FunctorOfTerm(t), argno, &cglobs->cint); else if (argno == (Int)arity) Yap_emit((cglobs->onhead ? unify_last_struct_op : write_last_struct_op), - (CELL) FunctorOfTerm(t), Zero, &cglobs->cint); + (CELL)FunctorOfTerm(t), Zero, &cglobs->cint); else Yap_emit((cglobs->onhead ? unify_struct_op : write_struct_op), - (CELL) FunctorOfTerm(t), Zero, &cglobs->cint); + (CELL)FunctorOfTerm(t), Zero, &cglobs->cint); ++level; c_args(t, level, cglobs); --level; @@ -868,9 +886,7 @@ c_arg(Int argno, Term t, unsigned int arity, unsigned int level, compiler_struct } } -static void -c_eq(Term t1, Term t2, compiler_struct *cglobs) -{ +static void c_eq(Term t1, Term t2, compiler_struct *cglobs) { CACHE_REGS if (t1 == t2) { Yap_emit(nop_op, Zero, Zero, &cglobs->cint); @@ -884,65 +900,65 @@ c_eq(Term t1, Term t2, compiler_struct *cglobs) } else { /* compile unification */ if (IsAtomicTerm(t1)) { - /* just check if they unify */ - if (!IsAtomicTerm(t2) || !Yap_unify(t1,t2)) { - /* they don't */ - Yap_emit(fail_op, Zero, Zero, &cglobs->cint); - return; - } - /* they do */ - Yap_emit(nop_op, Zero, Zero, &cglobs->cint); - return; + /* just check if they unify */ + if (!IsAtomicTerm(t2) || !Yap_unify(t1, t2)) { + /* they don't */ + Yap_emit(fail_op, Zero, Zero, &cglobs->cint); + return; + } + /* they do */ + Yap_emit(nop_op, Zero, Zero, &cglobs->cint); + return; } else if (IsPairTerm(t1)) { - /* just check if they unify */ - if (!IsPairTerm(t2)) { - /* they don't */ - Yap_emit(fail_op, Zero, Zero, &cglobs->cint); - return; - } - /* they might */ - c_eq(HeadOfTerm(t1), HeadOfTerm(t2), cglobs); - c_eq(TailOfTerm(t1), TailOfTerm(t2), cglobs); - return; + /* just check if they unify */ + if (!IsPairTerm(t2)) { + /* they don't */ + Yap_emit(fail_op, Zero, Zero, &cglobs->cint); + return; + } + /* they might */ + c_eq(HeadOfTerm(t1), HeadOfTerm(t2), cglobs); + c_eq(TailOfTerm(t1), TailOfTerm(t2), cglobs); + return; } else if (IsRefTerm(t1)) { - /* just check if they unify */ - if (t1 != t2) { - /* they don't */ - Yap_emit(fail_op, Zero, Zero, &cglobs->cint); - return; - } - /* they do */ - Yap_emit(nop_op, Zero, Zero, &cglobs->cint); - return; + /* just check if they unify */ + if (t1 != t2) { + /* they don't */ + Yap_emit(fail_op, Zero, Zero, &cglobs->cint); + return; + } + /* they do */ + Yap_emit(nop_op, Zero, Zero, &cglobs->cint); + return; } else { - /* compound terms */ - Functor f = FunctorOfTerm(t1); - UInt i, max; - /* just check if they unify */ - if (!IsApplTerm(t2) || - FunctorOfTerm(t2) != f) { - /* they don't */ - Yap_emit(fail_op, Zero, Zero, &cglobs->cint); - return; - } - /* they might */ - max = ArityOfFunctor(f); - for (i=0; i < max; i++) { - c_eq(ArgOfTerm(i+1,t1), ArgOfTerm(i+1,t2), cglobs); - } - return; + /* compound terms */ + Functor f = FunctorOfTerm(t1); + UInt i, max; + /* just check if they unify */ + if (!IsApplTerm(t2) || FunctorOfTerm(t2) != f) { + /* they don't */ + Yap_emit(fail_op, Zero, Zero, &cglobs->cint); + return; + } + /* they might */ + max = ArityOfFunctor(f); + for (i = 0; i < max; i++) { + c_eq(ArgOfTerm(i + 1, t1), ArgOfTerm(i + 1, t2), cglobs); + } + return; } } } /* first argument is an unbound var */ - if (IsNewVar(t1) && !IsVarTerm(t2) && !(cglobs->cint.CurrentPred->PredFlags & TabledPredFlag)) { + if (IsNewVar(t1) && !IsVarTerm(t2) && + !(cglobs->cint.CurrentPred->PredFlags & TabledPredFlag)) { Int v; - + v = --cglobs->tmpreg; c_arg(v, t2, 0, 0, cglobs); cglobs->onhead = TRUE; c_var(t1, v, 0, 0, cglobs); - cglobs->onhead = FALSE; + cglobs->onhead = FALSE; } else { if (IsVarTerm(t2)) { c_var(t1, 0, 0, 0, cglobs); @@ -958,23 +974,20 @@ c_eq(Term t1, Term t2, compiler_struct *cglobs) } } -static void -c_test(Int Op, Term t1, compiler_struct *cglobs) { +static void c_test(Int Op, Term t1, compiler_struct *cglobs) { CACHE_REGS Term t = Deref(t1); /* be caareful, has to be first occurrence */ if (Op == _save_by) { if (!IsNewVar(t)) { - char s[32]; + char s[32]; - LOCAL_Error_TYPE = UNINSTANTIATION_ERROR; - LOCAL_Error_Term = t; - LOCAL_ErrorMessage = LOCAL_ErrorSay; - Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling %s/2 on bound variable", s); - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,1); + LOCAL_Error_TYPE = UNINSTANTIATION_ERROR; + Yap_bip_name(Op, s); + sprintf(LOCAL_ErrorMessage, "compiling %s/2 on bound variable", s); + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, 1); } c_var(t, save_b_flag, 1, 0, cglobs); return; @@ -987,7 +1000,7 @@ c_test(Int Op, Term t1, compiler_struct *cglobs) { if (Op == _cut_by) c_var(t, commit_b_flag, 1, 0, cglobs); else - c_var(t, f_flag,(unsigned int)Op, 0, cglobs); + c_var(t, f_flag, (unsigned int)Op, 0, cglobs); } /* Arithmetic builtins will be compiled in the form: @@ -998,8 +1011,10 @@ c_test(Int Op, Term t1, compiler_struct *cglobs) { put_var Xk,Ak bip_body Op,Xk -The put_var should always be disposable, and the put_vals can be disposed of if R is an X. -This, in the best case, Ri and Rj are WAM temp registers and this will reduce to: +The put_var should always be disposable, and the put_vals can be disposed of if +R is an X. +This, in the best case, Ri and Rj are WAM temp registers and this will reduce +to: bip Op,Ak,Ri,Rj @@ -1018,292 +1033,270 @@ and this should reduce to : bip_cons Op,Xk,Ri,C */ -static void -c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler_struct *cglobs) -{ +static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, + Term mod, compiler_struct *cglobs) { CACHE_REGS - /* compile Z = X Op Y arithmetic function */ + /* compile Z = X Op Y arithmetic function */ /* first we fetch the arguments */ if (IsVarTerm(t1)) { if (IsVarTerm(t2)) { - /* first temp */ - Int v1 = --cglobs->tmpreg; - /* second temp */ - Int v2 = --cglobs->tmpreg; + /* first temp */ + Int v1 = --cglobs->tmpreg; + /* second temp */ + Int v2 = --cglobs->tmpreg; - Yap_emit(fetch_args_vv_op, Zero, Zero, &cglobs->cint); - /* these should be the arguments */ - c_var(t1, v1, 0, 0, cglobs); - c_var(t2, v2, 0, 0, cglobs); - /* now we know where the arguments are */ + Yap_emit(fetch_args_vv_op, Zero, Zero, &cglobs->cint); + /* these should be the arguments */ + c_var(t1, v1, 0, 0, cglobs); + c_var(t2, v2, 0, 0, cglobs); + /* now we know where the arguments are */ } else { if (Op == _arg) { - /* we know the second argument is bound */ - if (IsPrimitiveTerm(t2) || IsNumTerm(t2)) { - Yap_emit(fail_op, Zero, Zero, &cglobs->cint); - return; - } else { - Term tn = MkVarTerm(); - Int v1 = --cglobs->tmpreg; - Int v2 = --cglobs->tmpreg; + /* we know the second argument is bound */ + if (IsPrimitiveTerm(t2) || IsNumTerm(t2)) { + Yap_emit(fail_op, Zero, Zero, &cglobs->cint); + return; + } else { + Term tn = MkVarTerm(); + Int v1 = --cglobs->tmpreg; + Int v2 = --cglobs->tmpreg; - c_eq(t2, tn, cglobs); - Yap_emit(fetch_args_vv_op, Zero, Zero, &cglobs->cint); - /* these should be the arguments */ - c_var(t1, v1, 0, 0, cglobs); - c_var(tn, v2, 0, 0, cglobs); - } - /* it has to be either an integer or a floating point */ + c_eq(t2, tn, cglobs); + Yap_emit(fetch_args_vv_op, Zero, Zero, &cglobs->cint); + /* these should be the arguments */ + c_var(t1, v1, 0, 0, cglobs); + c_var(tn, v2, 0, 0, cglobs); + } + /* it has to be either an integer or a floating point */ } else if (IsIntegerTerm(t2)) { - /* first temp */ - Int v1 = 0; + /* first temp */ + Int v1 = 0; - Yap_emit(fetch_args_vi_op, IntegerOfTerm(t2), 0L, &cglobs->cint); - /* these should be the arguments */ - c_var(t1, v1, 0, 0, cglobs); - /* now we know where the arguments are */ + Yap_emit(fetch_args_vi_op, IntegerOfTerm(t2), 0L, &cglobs->cint); + /* these should be the arguments */ + c_var(t1, v1, 0, 0, cglobs); + /* now we know where the arguments are */ } else { - char s[32]; + char s[32]; - LOCAL_Error_TYPE = TYPE_ERROR_NUMBER; - LOCAL_Error_Term = t2; - LOCAL_ErrorMessage = LOCAL_ErrorSay; - Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling %s/2 with output bound", s); - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,1); + LOCAL_Error_TYPE = TYPE_ERROR_NUMBER; + + Yap_bip_name(Op, s); + sprintf(LOCAL_ErrorMessage, "compiling %s/2 with output bound", s); + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, 1); } } } else { /* t1 is bound */ /* it has to be either an integer or a floating point */ if (IsVarTerm(t2)) { if (IsNewVar(t2)) { - char s[32]; + char s[32]; - LOCAL_Error_TYPE = INSTANTIATION_ERROR; - LOCAL_Error_Term = t2; - LOCAL_ErrorMessage = LOCAL_ErrorSay; - Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling %s/3",s); - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,1); + LOCAL_Error_TYPE = INSTANTIATION_ERROR; + Yap_bip_name(Op, s); + sprintf(LOCAL_ErrorMessage, "compiling %s/3", s); + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, 1); } } else { if (Op == _functor) { - /* both arguments are bound, we must perform unification */ - Int i2; - - if (!IsIntegerTerm(t2)) { - char s[32]; + /* both arguments are bound, we must perform unification */ + Int i2; - LOCAL_Error_TYPE = TYPE_ERROR_INTEGER; - LOCAL_Error_Term = t2; - LOCAL_ErrorMessage = LOCAL_ErrorSay; - Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling functor/3"); - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,1); - } - i2 = IntegerOfTerm(t2); - if (i2 < 0) { - char s[32]; + if (!IsIntegerTerm(t2)) { + char s[32]; - LOCAL_Error_TYPE = DOMAIN_ERROR_NOT_LESS_THAN_ZERO; - LOCAL_Error_Term = t2; - LOCAL_ErrorMessage = LOCAL_ErrorSay; - Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling functor/3"); - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,1); - } - if (IsNumTerm(t1)) { - /* we will always fail */ - if (i2) - c_goal(MkAtomTerm(AtomFalse), mod, cglobs); - } else if (!IsAtomTerm(t1)) { - char s[32]; + LOCAL_Error_TYPE = TYPE_ERROR_INTEGER; + Yap_bip_name(Op, s); + sprintf(LOCAL_ErrorMessage, "compiling functor/3"); + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, 1); + } + i2 = IntegerOfTerm(t2); + if (i2 < 0) { + char s[32]; - LOCAL_Error_TYPE = TYPE_ERROR_ATOM; - LOCAL_Error_Term = t2; - LOCAL_ErrorMessage = LOCAL_ErrorSay; - Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling functor/3"); - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,1); - } - if (i2 == 0) - c_eq(t1, t3, cglobs); - else { - CELL *hi = HR; - Int i; + LOCAL_Error_TYPE = DOMAIN_ERROR_NOT_LESS_THAN_ZERO; + Yap_bip_name(Op, s); + sprintf(LOCAL_ErrorMessage, "compiling functor/3"); + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, 1); + } + if (IsNumTerm(t1)) { + /* we will always fail */ + if (i2) + c_goal(MkAtomTerm(AtomFalse), mod, cglobs); + } else if (!IsAtomTerm(t1)) { + char s[32]; - if (t1 == TermDot && i2 == 2) { - if (HR+2 >= (CELL *)cglobs->cint.freep0) { - /* oops, too many new variables */ - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_TEMPS_BOTCH); - } - RESET_VARIABLE(HR); - RESET_VARIABLE(HR+1); - HR += 2; - c_eq(AbsPair(HR-2),t3, cglobs); - } else if (i2 < 256 && IsAtomTerm(t1)) { - *HR++ = (CELL)Yap_MkFunctor(AtomOfTerm(t1),i2); - for (i=0; i < i2; i++) { - if (HR >= (CELL *)cglobs->cint.freep0) { - /* oops, too many new variables */ - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_TEMPS_BOTCH); - } - RESET_VARIABLE(HR); - HR++; - } - c_eq(AbsAppl(hi),t3, cglobs); - } else { - /* compile as default */ - Functor f = FunctorOfTerm(Goal); - Prop p0 = PredPropByFunc(f, mod); - if (EndOfPAEntr(p0)) { - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_HEAP_BOTCH); - } - c_args(Goal, 0, cglobs); - Yap_emit(safe_call_op, (CELL)p0 , Zero, &cglobs->cint); - Yap_emit(empty_call_op, Zero, Zero, &cglobs->cint); - Yap_emit(restore_tmps_and_skip_op, Zero, Zero, &cglobs->cint); - return; - } - } + LOCAL_Error_TYPE = TYPE_ERROR_ATOM; + Yap_bip_name(Op, s); + sprintf(LOCAL_ErrorMessage, "compiling functor/3"); + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, 1); + } + if (i2 == 0) + c_eq(t1, t3, cglobs); + else { + CELL *hi = HR; + Int i; + + if (t1 == TermDot && i2 == 2) { + if (HR + 2 >= (CELL *)cglobs->cint.freep0) { + /* oops, too many new variables */ + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_TEMPS_BOTCH); + } + RESET_VARIABLE(HR); + RESET_VARIABLE(HR + 1); + HR += 2; + c_eq(AbsPair(HR - 2), t3, cglobs); + } else if (i2 < 256 && IsAtomTerm(t1)) { + *HR++ = (CELL)Yap_MkFunctor(AtomOfTerm(t1), i2); + for (i = 0; i < i2; i++) { + if (HR >= (CELL *)cglobs->cint.freep0) { + /* oops, too many new variables */ + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_TEMPS_BOTCH); + } + RESET_VARIABLE(HR); + HR++; + } + c_eq(AbsAppl(hi), t3, cglobs); + } else { + /* compile as default */ + Functor f = FunctorOfTerm(Goal); + Prop p0 = PredPropByFunc(f, mod); + if (EndOfPAEntr(p0)) { + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_HEAP_BOTCH); + } + c_args(Goal, 0, cglobs); + Yap_emit(safe_call_op, (CELL)p0, Zero, &cglobs->cint); + Yap_emit(empty_call_op, Zero, Zero, &cglobs->cint); + Yap_emit(restore_tmps_and_skip_op, Zero, Zero, &cglobs->cint); + return; + } + } } else if (Op == _arg) { - Int i1; - if (IsIntegerTerm(t1)) - i1 = IntegerOfTerm(t1); - else { - char s[32]; + Int i1; + if (IsIntegerTerm(t1)) + i1 = IntegerOfTerm(t1); + else { + char s[32]; - LOCAL_Error_TYPE = TYPE_ERROR_INTEGER; - LOCAL_Error_Term = t2; - LOCAL_ErrorMessage = LOCAL_ErrorSay; - Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling %s/2", s); - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,1); - } - if (IsAtomicTerm(t2) || - (IsApplTerm(t2) && IsExtensionFunctor(FunctorOfTerm(t2)))) { - char s[32]; + LOCAL_Error_TYPE = TYPE_ERROR_INTEGER; + Yap_bip_name(Op, s); + sprintf(LOCAL_ErrorMessage, "compiling %s/2", s); + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, 1); + } + if (IsAtomicTerm(t2) || + (IsApplTerm(t2) && IsExtensionFunctor(FunctorOfTerm(t2)))) { + char s[32]; - LOCAL_Error_TYPE = TYPE_ERROR_COMPOUND; - LOCAL_Error_Term = t2; - LOCAL_ErrorMessage = LOCAL_ErrorSay; - Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling %s/2", s); - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,1); - } else if (IsApplTerm(t2)) { - Functor f = FunctorOfTerm(t2); - if (i1 < 1 || i1 > ArityOfFunctor(f)) { - c_goal(MkAtomTerm(AtomFalse), mod, cglobs); - } else { - c_eq(ArgOfTerm(i1, t2), t3, cglobs); - } - return; - } else if (IsPairTerm(t2)) { - switch (i1) { - case 1: - c_eq(HeadOfTerm(t2), t3, cglobs); - return; - case 2: - c_eq(TailOfTerm(t2), t3, cglobs); - return; - default: - c_goal(MkAtomTerm(AtomFalse), mod, cglobs); - return; - } - } + LOCAL_Error_TYPE = TYPE_ERROR_COMPOUND; + Yap_bip_name(Op, s); + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, 1); + } else if (IsApplTerm(t2)) { + Functor f = FunctorOfTerm(t2); + if (i1 < 1 || i1 > ArityOfFunctor(f)) { + c_goal(MkAtomTerm(AtomFalse), mod, cglobs); + } else { + c_eq(ArgOfTerm(i1, t2), t3, cglobs); + } + return; + } else if (IsPairTerm(t2)) { + switch (i1) { + case 1: + c_eq(HeadOfTerm(t2), t3, cglobs); + return; + case 2: + c_eq(TailOfTerm(t2), t3, cglobs); + return; + default: + c_goal(MkAtomTerm(AtomFalse), mod, cglobs); + return; + } + } } else { - char s[32]; + char s[32]; - LOCAL_Error_TYPE = TYPE_ERROR_INTEGER; - LOCAL_Error_Term = t2; - LOCAL_ErrorMessage = LOCAL_ErrorSay; - Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling %s/2", s); - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,1); + LOCAL_Error_TYPE = TYPE_ERROR_INTEGER; + Yap_bip_name(Op, s); + sprintf(LOCAL_ErrorMessage, "compiling %s/2", s); + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, 1); } } if (Op == _functor) { if (!IsAtomicTerm(t1)) { - char s[32]; + char s[32]; - LOCAL_Error_TYPE = TYPE_ERROR_ATOM; - LOCAL_Error_Term = t1; - LOCAL_ErrorMessage = LOCAL_ErrorSay; - Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling %s/2", s); - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,1); + LOCAL_Error_TYPE = TYPE_ERROR_ATOM; + Yap_bip_name(Op, s); + sprintf(LOCAL_ErrorMessage, "compiling %s/2", s); + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, 1); } else { - if (!IsVarTerm(t2)) { - Int arity; + if (!IsVarTerm(t2)) { + Int arity; - /* We actually have the term ready, so let's just do the unification now */ - if (!IsIntegerTerm(t2)) { - char s[32]; + /* We actually have the term ready, so let's just do the unification + * now */ + if (!IsIntegerTerm(t2)) { + char s[32]; - LOCAL_Error_TYPE = TYPE_ERROR_INTEGER; - LOCAL_Error_Term = t2; - LOCAL_ErrorMessage = LOCAL_ErrorSay; - Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling %s/2", s); - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,1); - } - arity = IntOfTerm(t2); - if (arity < 0) { - /* fail straight away */ - Yap_emit(fail_op, Zero, Zero, &cglobs->cint); - } - if (arity) { - Term tnew; - if (!IsAtomTerm(t1)) { - char s[32]; + LOCAL_Error_TYPE = TYPE_ERROR_INTEGER; + Yap_bip_name(Op, s); + sprintf(LOCAL_ErrorMessage, "compiling %s/2", s); + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, 1); + } + arity = IntOfTerm(t2); + if (arity < 0) { + /* fail straight away */ + Yap_emit(fail_op, Zero, Zero, &cglobs->cint); + } + if (arity) { + Term tnew; + if (!IsAtomTerm(t1)) { + char s[32]; - LOCAL_Error_TYPE = TYPE_ERROR_ATOM; - LOCAL_Error_Term = t1; - LOCAL_ErrorMessage = LOCAL_ErrorSay; - Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling %s/2", s); - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,1); - } - if (HR+1+arity >= (CELL *)cglobs->cint.freep0) { - /* oops, too many new variables */ - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_TEMPS_BOTCH); - } - tnew = AbsAppl(HR); - *HR++ = (CELL)Yap_MkFunctor(AtomOfTerm(t1),arity); - while (arity--) { - RESET_VARIABLE(HR); - HR++; - } - c_eq(tnew, t3, cglobs); - } else { - /* just unify the two arguments */ - c_eq(t1,t3, cglobs); - } - return; - } else { - /* first temp */ - Int v1 = 0; - Yap_emit(fetch_args_cv_op, t1, Zero, &cglobs->cint); - /* these should be the arguments */ - c_var(t2, v1, 0, 0, cglobs); - /* now we know where the arguments are */ - } + LOCAL_Error_TYPE = TYPE_ERROR_ATOM; + Yap_bip_name(Op, s); + sprintf(LOCAL_ErrorMessage, "compiling %s/2", s); + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, 1); + } + if (HR + 1 + arity >= (CELL *)cglobs->cint.freep0) { + /* oops, too many new variables */ + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_TEMPS_BOTCH); + } + tnew = AbsAppl(HR); + *HR++ = (CELL)Yap_MkFunctor(AtomOfTerm(t1), arity); + while (arity--) { + RESET_VARIABLE(HR); + HR++; + } + c_eq(tnew, t3, cglobs); + } else { + /* just unify the two arguments */ + c_eq(t1, t3, cglobs); + } + return; + } else { + /* first temp */ + Int v1 = 0; + Yap_emit(fetch_args_cv_op, t1, Zero, &cglobs->cint); + /* these should be the arguments */ + c_var(t2, v1, 0, 0, cglobs); + /* now we know where the arguments are */ + } } } else if (IsIntegerTerm(t1)) { /* first temp */ @@ -1316,53 +1309,54 @@ c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler char s[32]; LOCAL_Error_TYPE = UNINSTANTIATION_ERROR; - LOCAL_Error_Term = t1; - LOCAL_ErrorMessage = LOCAL_ErrorSay; Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling %s/2 with output bound", s); + sprintf(LOCAL_ErrorMessage, "compiling %s/2 with output bound", s); save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,1); + siglongjmp(cglobs->cint.CompilerBotch, 1); } - } + } /* then we compile the opcode/result */ if (!IsVarTerm(t3)) { if (Op == _arg) { Term tmpvar = MkVarTerm(); if (HR == (CELL *)cglobs->cint.freep0) { - /* oops, too many new variables */ - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_TEMPS_BOTCH); + /* oops, too many new variables */ + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_TEMPS_BOTCH); } - c_var(tmpvar,f_flag,(unsigned int)Op, 0, cglobs); - c_eq(tmpvar,t3, cglobs); + c_var(tmpvar, f_flag, (unsigned int)Op, 0, cglobs); + c_eq(tmpvar, t3, cglobs); } else { char s[32]; LOCAL_Error_TYPE = UNINSTANTIATION_ERROR; - LOCAL_Error_Term = t3; - LOCAL_ErrorMessage = LOCAL_ErrorSay; Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling %s/2 with input unbound", s); + sprintf(LOCAL_ErrorMessage, "compiling %s/2 with input unbound", s); save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,1); + siglongjmp(cglobs->cint.CompilerBotch, 1); } - } else if (IsNewVar(t3) && cglobs->curbranch == 0 && cglobs->cint.CurrentPred->PredFlags & TabledPredFlag) { + } else if (IsNewVar(t3) && cglobs->curbranch == 0 && + cglobs->cint.CurrentPred->PredFlags & TabledPredFlag) { Term nv = MkVarTerm(); - c_var(nv,f_flag,(unsigned int)Op, 0, cglobs); + c_var(nv, f_flag, (unsigned int)Op, 0, cglobs); if (Op == _functor) { Yap_emit(empty_call_op, Zero, Zero, &cglobs->cint); Yap_emit(restore_tmps_and_skip_op, Zero, Zero, &cglobs->cint); } - /* make sure that we first get the true t3, and then bind it to nv. That way it will be confitional */ + /* make sure that we first get the true t3, and then bind it to nv. That way + * it will be confitional */ c_eq(t3, nv, cglobs); - } else if (IsNewVar(t3) && cglobs->curbranch == 0 /* otherwise you may have trouble with z(X) :- ( Z is X*2 ; write(Z)) */) { - c_var(t3,f_flag,(unsigned int)Op, 0, cglobs); + } else if ( + IsNewVar(t3) && + cglobs->curbranch == + 0 /* otherwise you may have trouble with z(X) :- ( Z is X*2 ; write(Z)) */) { + c_var(t3, f_flag, (unsigned int)Op, 0, cglobs); if (Op == _functor) { Yap_emit(empty_call_op, Zero, Zero, &cglobs->cint); Yap_emit(restore_tmps_and_skip_op, Zero, Zero, &cglobs->cint); } } else { - /* generate code for a temp and then unify temp with previous variable */ + /* generate code for a temp and then unify temp with previous variable */ Yap_emit(f_0_op, 0, (unsigned int)Op, &cglobs->cint); /* I have to do it here, before I do the unification */ if (Op == _functor) { @@ -1375,9 +1369,7 @@ c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Term mod, compiler } } -static void -c_functor(Term Goal, Term mod, compiler_struct *cglobs) -{ +static void c_functor(Term Goal, Term mod, compiler_struct *cglobs) { CACHE_REGS Term t1 = ArgOfTerm(1, Goal); Term t2 = ArgOfTerm(2, Goal); @@ -1388,23 +1380,22 @@ c_functor(Term Goal, Term mod, compiler_struct *cglobs) } else if (IsNonVarTerm(t1)) { /* just split the structure */ if (IsAtomicTerm(t1)) { - c_eq(t1,t2, cglobs); - c_eq(t3,MkIntTerm(0), cglobs); + c_eq(t1, t2, cglobs); + c_eq(t3, MkIntTerm(0), cglobs); } else if (IsApplTerm(t1)) { Functor f = FunctorOfTerm(t1); - c_eq(t2,MkAtomTerm(NameOfFunctor(f)), cglobs); - c_eq(t3,MkIntegerTerm(ArityOfFunctor(f)), cglobs); + c_eq(t2, MkAtomTerm(NameOfFunctor(f)), cglobs); + c_eq(t3, MkIntegerTerm(ArityOfFunctor(f)), cglobs); } else /* list */ { - c_eq(t2,TermDot, cglobs); - c_eq(t3,MkIntTerm(2), cglobs); + c_eq(t2, TermDot, cglobs); + c_eq(t3, MkIntTerm(2), cglobs); } - } else if (IsVarTerm(t2) && IsNewVar(t2) && - IsVarTerm(t3) && IsNewVar(t3)) { + } else if (IsVarTerm(t2) && IsNewVar(t2) && IsVarTerm(t3) && IsNewVar(t3)) { Int v1 = --cglobs->tmpreg; Yap_emit(fetch_args_vi_op, Zero, Zero, &cglobs->cint); c_var(t1, v1, 0, 0, cglobs); - c_var(t2,f_flag,(unsigned int)_functor, 0, cglobs); - c_var(t3,f_flag,(unsigned int)_functor, 0, cglobs); + c_var(t2, f_flag, (unsigned int)_functor, 0, cglobs); + c_var(t3, f_flag, (unsigned int)_functor, 0, cglobs); } else { Functor f = FunctorOfTerm(Goal); Prop p0 = PredPropByFunc(f, mod); @@ -1418,33 +1409,32 @@ c_functor(Term Goal, Term mod, compiler_struct *cglobs) } else if (call_counting) Yap_emit(count_call_op, (CELL)RepPredProp(p0), Zero, &cglobs->cint); c_args(Goal, 0, cglobs); - Yap_emit(safe_call_op, (CELL)p0 , Zero, &cglobs->cint); + Yap_emit(safe_call_op, (CELL)p0, Zero, &cglobs->cint); Yap_emit(empty_call_op, Zero, Zero, &cglobs->cint); Yap_emit(restore_tmps_and_skip_op, Zero, Zero, &cglobs->cint); } } -static int -IsTrueGoal(Term t) { - if (IsVarTerm(t)) return(FALSE); +static int IsTrueGoal(Term t) { + if (IsVarTerm(t)) + return (FALSE); if (IsApplTerm(t)) { Functor f = FunctorOfTerm(t); if (f == FunctorModule) { - return(IsTrueGoal(ArgOfTerm(2,t))); + return (IsTrueGoal(ArgOfTerm(2, t))); } - if (f == FunctorComma || f == FunctorOr || f == FunctorVBar || f == FunctorArrow) { - return(IsTrueGoal(ArgOfTerm(1,t)) && IsTrueGoal(ArgOfTerm(2,t))); + if (f == FunctorComma || f == FunctorOr || f == FunctorVBar || + f == FunctorArrow) { + return (IsTrueGoal(ArgOfTerm(1, t)) && IsTrueGoal(ArgOfTerm(2, t))); } - return(FALSE); + return (FALSE); } - return(t == MkAtomTerm(AtomTrue)); + return (t == MkAtomTerm(AtomTrue)); } -static void -emit_special_label(Term Goal, compiler_struct *cglobs) -{ - special_label_op lab_op = IntOfTerm(ArgOfTerm(1,Goal)); - special_label_id lab_id = IntOfTerm(ArgOfTerm(2,Goal)); +static void emit_special_label(Term Goal, compiler_struct *cglobs) { + special_label_op lab_op = IntOfTerm(ArgOfTerm(1, Goal)); + special_label_id lab_id = IntOfTerm(ArgOfTerm(2, Goal)); UInt label_name; switch (lab_op) { @@ -1490,9 +1480,7 @@ emit_special_label(Term Goal, compiler_struct *cglobs) } } -static void -c_goal(Term Goal, Term mod, compiler_struct *cglobs) -{ +static void c_goal(Term Goal, Term mod, compiler_struct *cglobs) { Functor f; PredEntry *p; Prop p0; @@ -1505,13 +1493,11 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) if (IsVarTerm(M) || !IsAtomTerm(M)) { CACHE_REGS - if (IsVarTerm(M)) { - LOCAL_Error_TYPE = INSTANTIATION_ERROR; + if (IsVarTerm(M)) { + LOCAL_Error_TYPE = INSTANTIATION_ERROR; } else { - LOCAL_Error_TYPE = TYPE_ERROR_ATOM; + LOCAL_Error_TYPE = TYPE_ERROR_ATOM; } - LOCAL_Error_Term = M; - LOCAL_ErrorMessage = "in module name"; save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH); } @@ -1526,10 +1512,9 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) } else if (IsRefTerm(Goal)) { CACHE_REGS LOCAL_Error_TYPE = TYPE_ERROR_DBREF; - LOCAL_Error_Term = Goal; - FAIL("goal argument in static procedure can not be a data base reference", TYPE_ERROR_CALLABLE, Goal); - } - else if (IsPairTerm(Goal)) { + FAIL("goal argument in static procedure can not be a data base reference", + TYPE_ERROR_CALLABLE, Goal); + } else if (IsPairTerm(Goal)) { Goal = Yap_MkApplTerm(FunctorCall, 1, &Goal); } if (IsAtomTerm(Goal)) { @@ -1538,59 +1523,60 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) if (atom == AtomFail || atom == AtomFalse) { Yap_emit(fail_op, Zero, Zero, &cglobs->cint); return; - } - else if (atom == AtomTrue || atom == AtomOtherwise) { + } else if (atom == AtomTrue || atom == AtomOtherwise) { if (cglobs->onlast) { - Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); + Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); #ifdef TABLING - PELOCK(41,cglobs->cint.CurrentPred); - if (is_tabled(cglobs->cint.CurrentPred)) - Yap_emit(table_new_answer_op, Zero, cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); - else + PELOCK(41, cglobs->cint.CurrentPred); + if (is_tabled(cglobs->cint.CurrentPred)) + Yap_emit(table_new_answer_op, Zero, + cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); + else #endif /* TABLING */ - Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); + Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); #ifdef TABLING - UNLOCK(cglobs->cint.CurrentPred->PELock); + UNLOCK(cglobs->cint.CurrentPred->PELock); #endif } return; - } - else if (atom == AtomCut) { + } else if (atom == AtomCut) { if (profiling) - Yap_emit(enter_profiling_op, (CELL)RepPredProp(PredPropByAtom(AtomCut,0)), Zero, &cglobs->cint); + Yap_emit(enter_profiling_op, + (CELL)RepPredProp(PredPropByAtom(AtomCut, 0)), Zero, + &cglobs->cint); else if (call_counting) - Yap_emit(count_call_op, (CELL)RepPredProp(PredPropByAtom(AtomCut,0)), Zero, &cglobs->cint); + Yap_emit(count_call_op, (CELL)RepPredProp(PredPropByAtom(AtomCut, 0)), + Zero, &cglobs->cint); if (cglobs->onlast) { - /* never a problem here with a -> b, !, c ; d */ - Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); + /* never a problem here with a -> b, !, c ; d */ + Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); #ifdef TABLING - PELOCK(42,cglobs->cint.CurrentPred); - if (is_tabled(cglobs->cint.CurrentPred)) { - Yap_emit_3ops(cut_op, Zero, Zero, Zero, &cglobs->cint); - /* needs to adjust previous commits */ - Yap_emit(empty_call_op, Zero, Zero, &cglobs->cint); - Yap_emit(restore_tmps_and_skip_op, Zero, Zero, &cglobs->cint); - Yap_emit(table_new_answer_op, Zero, cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); - } - else + PELOCK(42, cglobs->cint.CurrentPred); + if (is_tabled(cglobs->cint.CurrentPred)) { + Yap_emit_3ops(cut_op, Zero, Zero, Zero, &cglobs->cint); + /* needs to adjust previous commits */ + Yap_emit(empty_call_op, Zero, Zero, &cglobs->cint); + Yap_emit(restore_tmps_and_skip_op, Zero, Zero, &cglobs->cint); + Yap_emit(table_new_answer_op, Zero, + cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); + } else #endif /* TABLING */ - { - Yap_emit_3ops(cutexit_op, Zero, Zero, Zero, &cglobs->cint); - /* needs to adjust previous commits */ - Yap_emit(empty_call_op, Zero, Zero, &cglobs->cint); - Yap_emit(restore_tmps_and_skip_op, Zero, Zero, &cglobs->cint); - Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); - } + { + Yap_emit_3ops(cutexit_op, Zero, Zero, Zero, &cglobs->cint); + /* needs to adjust previous commits */ + Yap_emit(empty_call_op, Zero, Zero, &cglobs->cint); + Yap_emit(restore_tmps_and_skip_op, Zero, Zero, &cglobs->cint); + Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); + } #ifdef TABLING - UNLOCK(cglobs->cint.CurrentPred->PELock); + UNLOCK(cglobs->cint.CurrentPred->PELock); #endif - } - else { - Yap_emit_3ops(cut_op, Zero, Zero, Zero, &cglobs->cint); - /* needs to adjust previous commits */ - Yap_emit(empty_call_op, Zero, Zero, &cglobs->cint); - Yap_emit(restore_tmps_and_skip_op, Zero, Zero, &cglobs->cint); - adjust_current_commits(cglobs); + } else { + Yap_emit_3ops(cut_op, Zero, Zero, Zero, &cglobs->cint); + /* needs to adjust previous commits */ + Yap_emit(empty_call_op, Zero, Zero, &cglobs->cint); + Yap_emit(restore_tmps_and_skip_op, Zero, Zero, &cglobs->cint); + adjust_current_commits(cglobs); } return; } @@ -1602,9 +1588,13 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) /* I need an either_me */ cglobs->needs_env = TRUE; if (profiling) - Yap_emit(enter_profiling_op, (CELL)RepPredProp(PredPropByAtom(AtomRepeat,0)), Zero, &cglobs->cint); + Yap_emit(enter_profiling_op, + (CELL)RepPredProp(PredPropByAtom(AtomRepeat, 0)), Zero, + &cglobs->cint); else if (call_counting) - Yap_emit(count_call_op, (CELL)RepPredProp(PredPropByAtom(AtomRepeat,0)), Zero, &cglobs->cint); + Yap_emit(count_call_op, + (CELL)RepPredProp(PredPropByAtom(AtomRepeat, 0)), Zero, + &cglobs->cint); cglobs->or_found = TRUE; push_branch(cglobs->onbranch, TermNil, cglobs); cglobs->curbranch++; @@ -1619,20 +1609,21 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) Yap_emit(label_op, l2, Zero, &cglobs->cint); if (cglobs->onlast) { #ifdef TABLING - PELOCK(43,cglobs->cint.CurrentPred); - if (is_tabled(cglobs->cint.CurrentPred)) { - Yap_emit(table_new_answer_op, Zero, cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); - } else { + PELOCK(43, cglobs->cint.CurrentPred); + if (is_tabled(cglobs->cint.CurrentPred)) { + Yap_emit(table_new_answer_op, Zero, + cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); + } else { #endif - Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); - Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); + Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); + Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); #ifdef TABLING - } - UNLOCK(cglobs->cint.CurrentPred->PELock); + } + UNLOCK(cglobs->cint.CurrentPred->PELock); #endif - } else { - ++cglobs->goalno; - } + } else { + ++cglobs->goalno; + } cglobs->onbranch = pop_branch(cglobs); Yap_emit(pop_or_op, Zero, Zero, &cglobs->cint); /* --cglobs->onbranch; */ @@ -1649,8 +1640,7 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) Yap_emit(enter_profiling_op, (CELL)p, Zero, &cglobs->cint); if (call_counting) Yap_emit(count_call_op, (CELL)p, Zero, &cglobs->cint); - } - else { + } else { f = FunctorOfTerm(Goal); p = RepPredProp(p0 = Yap_PredPropByFunctorNonThreadLocal(f, mod)); if (EndOfPAEntr(p0)) { @@ -1675,124 +1665,120 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) cglobs->onbranch = cglobs->curbranch; cglobs->or_found = TRUE; do { - arg = ArgOfTerm(1, Goal); - looking_at_commit = IsApplTerm(arg) && - FunctorOfTerm(arg) == FunctorArrow; - if (frst) { - if (optimizing_commit) { - Yap_emit(label_op, l, Zero, &cglobs->cint); - l = ++cglobs->labelno; - } - Yap_emit_3ops(push_or_op, l, Zero, Zero, &cglobs->cint); - if (looking_at_commit && - Yap_is_a_test_pred(ArgOfTerm(1, arg), mod)) { - /* - * let them think they are still the - * first - */ - // Yap_emit(commit_opt_op, l, Zero, &cglobs->cint); - optimizing_commit = TRUE; - Yap_emit_3ops(label_ctl_op, SPECIAL_LABEL_INIT, SPECIAL_LABEL_FAILURE, l, &cglobs->cint); - } - else { - optimizing_commit = FALSE; - cglobs->needs_env = TRUE; - Yap_emit_3ops(either_op, l, Zero, Zero, &cglobs->cint); - Yap_emit(restore_tmps_op, Zero, Zero, &cglobs->cint); - frst = FALSE; - } - } - else { - optimizing_commit = FALSE; - Yap_emit(label_op, l, Zero, &cglobs->cint); - Yap_emit(pushpop_or_op, Zero, Zero, &cglobs->cint); - Yap_emit_3ops(orelse_op, l = ++cglobs->labelno, Zero, Zero, &cglobs->cint); - cglobs->needs_env = TRUE; - } - /* - * if(IsApplTerm(arg) && - * FunctorOfTerm(arg)==FunctorArrow) { - */ - if (looking_at_commit) { - if (!optimizing_commit && !commitflag) { - CACHE_REGS - /* This instruction is placed before - * the disjunction. This means that - * the program counter must point - * correctly, and also that the age - * of variable is older than the - * current branch. - */ - int my_goalno = cglobs->goalno; + arg = ArgOfTerm(1, Goal); + looking_at_commit = + IsApplTerm(arg) && FunctorOfTerm(arg) == FunctorArrow; + if (frst) { + if (optimizing_commit) { + Yap_emit(label_op, l, Zero, &cglobs->cint); + l = ++cglobs->labelno; + } + Yap_emit_3ops(push_or_op, l, Zero, Zero, &cglobs->cint); + if (looking_at_commit && Yap_is_a_test_pred(ArgOfTerm(1, arg), mod)) { + /* + * let them think they are still the + * first + */ + // Yap_emit(commit_opt_op, l, Zero, &cglobs->cint); + optimizing_commit = TRUE; + Yap_emit_3ops(label_ctl_op, SPECIAL_LABEL_INIT, + SPECIAL_LABEL_FAILURE, l, &cglobs->cint); + } else { + optimizing_commit = FALSE; + cglobs->needs_env = TRUE; + Yap_emit_3ops(either_op, l, Zero, Zero, &cglobs->cint); + Yap_emit(restore_tmps_op, Zero, Zero, &cglobs->cint); + frst = FALSE; + } + } else { + optimizing_commit = FALSE; + Yap_emit(label_op, l, Zero, &cglobs->cint); + Yap_emit(pushpop_or_op, Zero, Zero, &cglobs->cint); + Yap_emit_3ops(orelse_op, l = ++cglobs->labelno, Zero, Zero, + &cglobs->cint); + cglobs->needs_env = TRUE; + } + /* + * if(IsApplTerm(arg) && + * FunctorOfTerm(arg)==FunctorArrow) { + */ + if (looking_at_commit) { + if (!optimizing_commit && !commitflag) { + CACHE_REGS + /* This instruction is placed before + * the disjunction. This means that + * the program counter must point + * correctly, and also that the age + * of variable is older than the + * current branch. + */ + int my_goalno = cglobs->goalno; - cglobs->goalno = savegoalno; - commitflag = cglobs->labelno; - commitvar = MkVarTerm(); - if (HR == (CELL *)cglobs->cint.freep0) { - /* oops, too many new variables */ - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_TEMPS_BOTCH); - } - savecpc = cglobs->cint.cpc; - savencpc = FirstP->nextInst; - cglobs->cint.cpc = FirstP; - cglobs->onbranch = pop_branch(cglobs); - c_var(commitvar, save_b_flag, 1, 0, cglobs); - push_branch(cglobs->onbranch, commitvar, cglobs); - cglobs->onbranch = cglobs->curbranch; - cglobs->cint.cpc->nextInst = savencpc; - cglobs->cint.cpc = savecpc; - cglobs->goalno = my_goalno; - } - save = cglobs->onlast; - cglobs->onlast = FALSE; - c_goal(ArgOfTerm(1, arg), mod, cglobs); - if (!optimizing_commit) { - c_var((Term) commitvar, commit_b_flag, - 1, 0, cglobs); - } else { - Yap_emit_3ops(label_ctl_op, SPECIAL_LABEL_CLEAR, SPECIAL_LABEL_FAILURE, l, &cglobs->cint); - } - cglobs->onlast = save; - c_goal(ArgOfTerm(2, arg), mod, cglobs); - } - else { - /* standard disjunction */ - c_goal(ArgOfTerm(1, Goal), mod, cglobs); - } - if (!cglobs->onlast) { - Yap_emit(jump_op, m, Zero, &cglobs->cint); - } else { - - } - if (!optimizing_commit || !cglobs->onlast) { - cglobs->goalno = savegoalno + 1; - } - Goal = ArgOfTerm(2, Goal); - ++cglobs->curbranch; - cglobs->onbranch = cglobs->curbranch; - } while (IsNonVarTerm(Goal) && IsApplTerm(Goal) - && (FunctorOfTerm(Goal) == FunctorOr - || FunctorOfTerm(Goal) == FunctorVBar)); + cglobs->goalno = savegoalno; + commitflag = cglobs->labelno; + commitvar = MkVarTerm(); + if (HR == (CELL *)cglobs->cint.freep0) { + /* oops, too many new variables */ + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_TEMPS_BOTCH); + } + savecpc = cglobs->cint.cpc; + savencpc = FirstP->nextInst; + cglobs->cint.cpc = FirstP; + cglobs->onbranch = pop_branch(cglobs); + c_var(commitvar, save_b_flag, 1, 0, cglobs); + push_branch(cglobs->onbranch, commitvar, cglobs); + cglobs->onbranch = cglobs->curbranch; + cglobs->cint.cpc->nextInst = savencpc; + cglobs->cint.cpc = savecpc; + cglobs->goalno = my_goalno; + } + save = cglobs->onlast; + cglobs->onlast = FALSE; + c_goal(ArgOfTerm(1, arg), mod, cglobs); + if (!optimizing_commit) { + c_var((Term)commitvar, commit_b_flag, 1, 0, cglobs); + } else { + Yap_emit_3ops(label_ctl_op, SPECIAL_LABEL_CLEAR, + SPECIAL_LABEL_FAILURE, l, &cglobs->cint); + } + cglobs->onlast = save; + c_goal(ArgOfTerm(2, arg), mod, cglobs); + } else { + /* standard disjunction */ + c_goal(ArgOfTerm(1, Goal), mod, cglobs); + } + if (!cglobs->onlast) { + Yap_emit(jump_op, m, Zero, &cglobs->cint); + } else { + } + if (!optimizing_commit || !cglobs->onlast) { + cglobs->goalno = savegoalno + 1; + } + Goal = ArgOfTerm(2, Goal); + ++cglobs->curbranch; + cglobs->onbranch = cglobs->curbranch; + } while (IsNonVarTerm(Goal) && IsApplTerm(Goal) && + (FunctorOfTerm(Goal) == FunctorOr || + FunctorOfTerm(Goal) == FunctorVBar)); Yap_emit(pushpop_or_op, Zero, Zero, &cglobs->cint); Yap_emit(label_op, l, Zero, &cglobs->cint); if (!optimizing_commit) { - Yap_emit(orlast_op, Zero, Zero, &cglobs->cint); + Yap_emit(orlast_op, Zero, Zero, &cglobs->cint); } else { - optimizing_commit = FALSE; /* not really necessary */ + optimizing_commit = FALSE; /* not really necessary */ } c_goal(Goal, mod, cglobs); /* --cglobs->onbranch; */ cglobs->onbranch = pop_branch(cglobs); if (!cglobs->onlast) { - Yap_emit(label_op, m, Zero, &cglobs->cint); - if ((cglobs->onlast = save)) - c_goal(MkAtomTerm(AtomTrue), mod, cglobs); + Yap_emit(label_op, m, Zero, &cglobs->cint); + if ((cglobs->onlast = save)) + c_goal(MkAtomTerm(AtomTrue), mod, cglobs); } Yap_emit(pop_or_op, Zero, Zero, &cglobs->cint); return; - } - else if (f == FunctorComma) { + } else if (f == FunctorComma) { int save = cglobs->onlast; Term t2 = ArgOfTerm(2, Goal); @@ -1801,8 +1787,7 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) cglobs->onlast = save; c_goal(t2, mod, cglobs); return; - } - else if (f == FunctorNot || f == FunctorAltNot) { + } else if (f == FunctorNot || f == FunctorAltNot) { CACHE_REGS CELL label = (cglobs->labelno += 2); CELL end_label = (cglobs->labelno += 2); @@ -1813,9 +1798,9 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) cglobs->needs_env = TRUE; commitvar = MkVarTerm(); if (HR == (CELL *)cglobs->cint.freep0) { - /* oops, too many new variables */ - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_TEMPS_BOTCH); + /* oops, too many new variables */ + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_TEMPS_BOTCH); } push_branch(cglobs->onbranch, commitvar, cglobs); ++cglobs->curbranch; @@ -1824,7 +1809,7 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) cglobs->onlast = FALSE; c_var(commitvar, save_b_flag, 1, 0, cglobs); Yap_emit_3ops(push_or_op, label, Zero, Zero, &cglobs->cint); - Yap_emit_3ops(either_op, label, Zero, Zero, &cglobs->cint); + Yap_emit_3ops(either_op, label, Zero, Zero, &cglobs->cint); Yap_emit(restore_tmps_op, Zero, Zero, &cglobs->cint); c_goal(ArgOfTerm(1, Goal), mod, cglobs); c_var(commitvar, commit_b_flag, 1, 0, cglobs); @@ -1841,17 +1826,16 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) ++cglobs->goalno; Yap_emit(pop_or_op, Zero, Zero, &cglobs->cint); return; - } - else if (f == FunctorArrow) { + } else if (f == FunctorArrow) { CACHE_REGS Term commitvar; int save = cglobs->onlast; commitvar = MkVarTerm(); if (HR == (CELL *)cglobs->cint.freep0) { - /* oops, too many new variables */ - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_TEMPS_BOTCH); + /* oops, too many new variables */ + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_TEMPS_BOTCH); } cglobs->onlast = FALSE; c_var(commitvar, save_b_flag, 1, 0, cglobs); @@ -1860,173 +1844,165 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) cglobs->onlast = save; c_goal(ArgOfTerm(2, Goal), mod, cglobs); return; - } - else if (f == FunctorEq) { + } else if (f == FunctorEq) { if (profiling) - Yap_emit(enter_profiling_op, (CELL)p, Zero, &cglobs->cint); + Yap_emit(enter_profiling_op, (CELL)p, Zero, &cglobs->cint); else if (call_counting) - Yap_emit(count_call_op, (CELL)p, Zero, &cglobs->cint); + Yap_emit(count_call_op, (CELL)p, Zero, &cglobs->cint); c_eq(ArgOfTerm(1, Goal), ArgOfTerm(2, Goal), cglobs); if (cglobs->onlast) { - Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); + Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); #ifdef TABLING - PELOCK(44,cglobs->cint.CurrentPred); - if (is_tabled(cglobs->cint.CurrentPred)) - Yap_emit(table_new_answer_op, Zero, cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); - else + PELOCK(44, cglobs->cint.CurrentPred); + if (is_tabled(cglobs->cint.CurrentPred)) + Yap_emit(table_new_answer_op, Zero, + cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); + else #endif /* TABLING */ - Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); + Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); #ifdef TABLING - UNLOCK(cglobs->cint.CurrentPred->PELock); + UNLOCK(cglobs->cint.CurrentPred->PELock); #endif } return; - } - else if (f == FunctorSafe) { + } else if (f == FunctorSafe) { Ventry *v = (Ventry *)ArgOfTerm(1, Goal); /* This variable must be known before */ v->FlagsOfVE |= SafeVar; return; - } - else if (p->PredFlags & (AsmPredFlag)) { + } else if (p->PredFlags & (AsmPredFlag)) { basic_preds op = p->PredFlags & 0x7f; if (profiling) - Yap_emit(enter_profiling_op, (CELL)p, Zero, &cglobs->cint); + Yap_emit(enter_profiling_op, (CELL)p, Zero, &cglobs->cint); else if (call_counting) - Yap_emit(count_call_op, (CELL)p, Zero, &cglobs->cint); + Yap_emit(count_call_op, (CELL)p, Zero, &cglobs->cint); if (op >= _atom && op <= _primitive) { - c_test(op, ArgOfTerm(1, Goal), cglobs); - if (cglobs->onlast) { - Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); + c_test(op, ArgOfTerm(1, Goal), cglobs); + if (cglobs->onlast) { + Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); #ifdef TABLING - PELOCK(45,cglobs->cint.CurrentPred); - if (is_tabled(cglobs->cint.CurrentPred)) - Yap_emit(table_new_answer_op, Zero, cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); - else + PELOCK(45, cglobs->cint.CurrentPred); + if (is_tabled(cglobs->cint.CurrentPred)) + Yap_emit(table_new_answer_op, Zero, + cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); + else #endif /* TABLING */ - Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); + Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); #ifdef TABLING - UNLOCK(cglobs->cint.CurrentPred->PELock); + UNLOCK(cglobs->cint.CurrentPred->PELock); #endif - } - return; - } - else if (op >= _plus && op <= _functor) { - if (profiling) - Yap_emit(enter_profiling_op, (CELL)p, Zero, &cglobs->cint); - else if (call_counting) - Yap_emit(count_call_op, (CELL)p, Zero, &cglobs->cint); - if (op == _functor) { - c_functor(Goal, mod, cglobs); - } - else { - c_bifun(op, - ArgOfTerm(1, Goal), - ArgOfTerm(2, Goal), - ArgOfTerm(3, Goal), - Goal, - mod, - cglobs); - } - if (cglobs->onlast) { - Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); + } + return; + } else if (op >= _plus && op <= _functor) { + if (profiling) + Yap_emit(enter_profiling_op, (CELL)p, Zero, &cglobs->cint); + else if (call_counting) + Yap_emit(count_call_op, (CELL)p, Zero, &cglobs->cint); + if (op == _functor) { + c_functor(Goal, mod, cglobs); + } else { + c_bifun(op, ArgOfTerm(1, Goal), ArgOfTerm(2, Goal), + ArgOfTerm(3, Goal), Goal, mod, cglobs); + } + if (cglobs->onlast) { + Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); #ifdef TABLING - PELOCK(46,cglobs->cint.CurrentPred); - if (is_tabled(cglobs->cint.CurrentPred)) - Yap_emit(table_new_answer_op, Zero, cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); - else + PELOCK(46, cglobs->cint.CurrentPred); + if (is_tabled(cglobs->cint.CurrentPred)) + Yap_emit(table_new_answer_op, Zero, + cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); + else #endif /* TABLING */ - Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); + Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); #ifdef TABLING - UNLOCK(cglobs->cint.CurrentPred->PELock); + UNLOCK(cglobs->cint.CurrentPred->PELock); #endif - } - return; + } + return; } else if (op == _p_label_ctl) { - emit_special_label(Goal, cglobs); - return; + emit_special_label(Goal, cglobs); + return; } else { - c_args(Goal, 0, cglobs); + c_args(Goal, 0, cglobs); } } #ifdef BEAM else if (p->PredFlags & BinaryPredFlag && !EAM) { #else - else if (p->PredFlags & BinaryPredFlag ) { + else if (p->PredFlags & BinaryPredFlag) { #endif CACHE_REGS - Term a1 = ArgOfTerm(1,Goal); + Term a1 = ArgOfTerm(1, Goal); if (IsVarTerm(a1) && !IsNewVar(a1)) { - Term a2 = ArgOfTerm(2,Goal); - if (IsVarTerm(a2) && !IsNewVar(a2)) { - cglobs->current_p0 = p0; - c_2vars(bt_flag, a1, 0, a2, 0, (CELL)p0, 0, 0, cglobs); - } - else { - Term t2 = MkVarTerm(); - //c_var(t2, --cglobs->tmpreg, 0, 0, cglobs); - if (HR == (CELL *)cglobs->cint.freep0) { - /* oops, too many new variables */ - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_TEMPS_BOTCH); - } - cglobs->current_p0 = p0; - c_eq(t2, a2, cglobs); - c_2vars(bt_flag, a1, 0, t2, 0, (CELL)p0, 0, 0, cglobs); - } + Term a2 = ArgOfTerm(2, Goal); + if (IsVarTerm(a2) && !IsNewVar(a2)) { + cglobs->current_p0 = p0; + c_2vars(bt_flag, a1, 0, a2, 0, (CELL)p0, 0, 0, cglobs); + } else { + Term t2 = MkVarTerm(); + // c_var(t2, --cglobs->tmpreg, 0, 0, cglobs); + if (HR == (CELL *)cglobs->cint.freep0) { + /* oops, too many new variables */ + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_TEMPS_BOTCH); + } + cglobs->current_p0 = p0; + c_eq(t2, a2, cglobs); + c_2vars(bt_flag, a1, 0, t2, 0, (CELL)p0, 0, 0, cglobs); + } } else { - Term a2 = ArgOfTerm(2,Goal); - Term t1 = MkVarTerm(); - //c_var(t1, --cglobs->tmpreg, 0, 0, cglobs); - if (HR == (CELL *)cglobs->cint.freep0) { - /* oops, too many new variables */ - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_TEMPS_BOTCH); - } - c_eq(t1, a1, cglobs); + Term a2 = ArgOfTerm(2, Goal); + Term t1 = MkVarTerm(); + // c_var(t1, --cglobs->tmpreg, 0, 0, cglobs); + if (HR == (CELL *)cglobs->cint.freep0) { + /* oops, too many new variables */ + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_TEMPS_BOTCH); + } + c_eq(t1, a1, cglobs); - if (IsVarTerm(a2) && !IsNewVar(a2)) { - cglobs->current_p0 = p0; - c_2vars(bt_flag, t1, 0, a2, 0, (CELL)p0, 0, 0, cglobs); - } - else { - Term t2 = MkVarTerm(); - // c_var(t2, --cglobs->tmpreg, 0, 0, cglobs); - if (HR == (CELL *)cglobs->cint.freep0) { - /* oops, too many new variables */ - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch,OUT_OF_TEMPS_BOTCH); - } - c_eq(t2, a2, cglobs); - cglobs->current_p0 = p0; - c_2vars(bt_flag, t1, 0, t2, 0, (CELL)p0, 0, 0, cglobs); - } + if (IsVarTerm(a2) && !IsNewVar(a2)) { + cglobs->current_p0 = p0; + c_2vars(bt_flag, t1, 0, a2, 0, (CELL)p0, 0, 0, cglobs); + } else { + Term t2 = MkVarTerm(); + // c_var(t2, --cglobs->tmpreg, 0, 0, cglobs); + if (HR == (CELL *)cglobs->cint.freep0) { + /* oops, too many new variables */ + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_TEMPS_BOTCH); + } + c_eq(t2, a2, cglobs); + cglobs->current_p0 = p0; + c_2vars(bt_flag, t1, 0, t2, 0, (CELL)p0, 0, 0, cglobs); + } } if (cglobs->onlast) { - Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); + Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); #ifdef TABLING - PELOCK(47,cglobs->cint.CurrentPred); - if (is_tabled(cglobs->cint.CurrentPred)) - Yap_emit(table_new_answer_op, Zero, cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); - else + PELOCK(47, cglobs->cint.CurrentPred); + if (is_tabled(cglobs->cint.CurrentPred)) + Yap_emit(table_new_answer_op, Zero, + cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); + else #endif /* TABLING */ - Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); + Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); #ifdef TABLING - UNLOCK(cglobs->cint.CurrentPred->PELock); + UNLOCK(cglobs->cint.CurrentPred->PELock); #endif } return; } else { if (profiling) - Yap_emit(enter_profiling_op, (CELL)p, Zero, &cglobs->cint); + Yap_emit(enter_profiling_op, (CELL)p, Zero, &cglobs->cint); else if (call_counting) - Yap_emit(count_call_op, (CELL)p, Zero, &cglobs->cint); + Yap_emit(count_call_op, (CELL)p, Zero, &cglobs->cint); if (f == FunctorExecuteInMod) { - /* compile the first argument only */ - c_arg(1, ArgOfTerm(1,Goal), 1, 0, cglobs); + /* compile the first argument only */ + c_arg(1, ArgOfTerm(1, Goal), 1, 0, cglobs); } else { - c_args(Goal, 0, cglobs); + c_args(Goal, 0, cglobs); } } } @@ -2036,74 +2012,73 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) /* synchronisation means saving the state, so it is never safe in YAPOR */ && !(p->PredFlags & SyncPredFlag) #endif /* YAPOR */ - ) { - Yap_emit(safe_call_op, (CELL) p0, Zero, &cglobs->cint); + ) { + Yap_emit(safe_call_op, (CELL)p0, Zero, &cglobs->cint); if (cglobs->onlast) { Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); #ifdef TABLING - PELOCK(48,cglobs->cint.CurrentPred); + PELOCK(48, cglobs->cint.CurrentPred); if (is_tabled(cglobs->cint.CurrentPred)) - Yap_emit(table_new_answer_op, Zero, cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); + Yap_emit(table_new_answer_op, Zero, cglobs->cint.CurrentPred->ArityOfPE, + &cglobs->cint); else #endif /* TABLING */ - Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); + Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); #ifdef TABLING UNLOCK(cglobs->cint.CurrentPred->PELock); #endif } - } - else { - if ((p->PredFlags & (AsmPredFlag | - ModuleTransparentPredFlag | - UserCPredFlag)) || - p->FunctorOfPred == FunctorExecuteInMod) { + } else { + if ((p->PredFlags & + (AsmPredFlag | ModuleTransparentPredFlag | UserCPredFlag)) || + p->FunctorOfPred == FunctorExecuteInMod) { #ifdef YAPOR if (p->PredFlags & SyncPredFlag) - Yap_emit(sync_op, (CELL)p, (CELL)(p->ArityOfPE), &cglobs->cint); + Yap_emit(sync_op, (CELL)p, (CELL)(p->ArityOfPE), &cglobs->cint); #endif /* YAPOR */ if (p->FunctorOfPred == FunctorExecuteInMod) { - cglobs->needs_env = TRUE; - Yap_emit_4ops(call_op, (CELL) p0, Zero, Zero, ArgOfTerm(2,Goal), &cglobs->cint); + cglobs->needs_env = TRUE; + Yap_emit_4ops(call_op, (CELL)p0, Zero, Zero, ArgOfTerm(2, Goal), + &cglobs->cint); } else { - cglobs->needs_env = TRUE; - Yap_emit_3ops(call_op, (CELL) p0, Zero, Zero, &cglobs->cint); + cglobs->needs_env = TRUE; + Yap_emit_3ops(call_op, (CELL)p0, Zero, Zero, &cglobs->cint); } /* functor is allowed to call the garbage collector */ if (cglobs->onlast) { - Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); - cglobs->or_found = TRUE; + Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); + cglobs->or_found = TRUE; #ifdef TABLING - PELOCK(49,cglobs->cint.CurrentPred); - if (is_tabled(cglobs->cint.CurrentPred)) - Yap_emit(table_new_answer_op, Zero, cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); - else + PELOCK(49, cglobs->cint.CurrentPred); + if (is_tabled(cglobs->cint.CurrentPred)) + Yap_emit(table_new_answer_op, Zero, + cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); + else #endif /* TABLING */ - Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); + Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); #ifdef TABLING - UNLOCK(cglobs->cint.CurrentPred->PELock); + UNLOCK(cglobs->cint.CurrentPred->PELock); #endif } - } - else { + } else { if (cglobs->onlast) { - Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); + Yap_emit(deallocate_op, Zero, Zero, &cglobs->cint); #ifdef TABLING - PELOCK(50,cglobs->cint.CurrentPred); - if (is_tabled(cglobs->cint.CurrentPred)) { - cglobs->needs_env = TRUE; - Yap_emit_3ops(call_op, (CELL) p0, Zero, Zero, &cglobs->cint); - Yap_emit(table_new_answer_op, Zero, cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); - } - else + PELOCK(50, cglobs->cint.CurrentPred); + if (is_tabled(cglobs->cint.CurrentPred)) { + cglobs->needs_env = TRUE; + Yap_emit_3ops(call_op, (CELL)p0, Zero, Zero, &cglobs->cint); + Yap_emit(table_new_answer_op, Zero, + cglobs->cint.CurrentPred->ArityOfPE, &cglobs->cint); + } else #endif /* TABLING */ - Yap_emit(execute_op, (CELL) p0, Zero, &cglobs->cint); + Yap_emit(execute_op, (CELL)p0, Zero, &cglobs->cint); #ifdef TABLING - UNLOCK(cglobs->cint.CurrentPred->PELock); + UNLOCK(cglobs->cint.CurrentPred->PELock); #endif - } - else { - cglobs->needs_env = TRUE; - Yap_emit_3ops(call_op, (CELL) p0, Zero, Zero, &cglobs->cint); + } else { + cglobs->needs_env = TRUE; + Yap_emit_3ops(call_op, (CELL)p0, Zero, Zero, &cglobs->cint); } } if (!cglobs->onlast) @@ -2111,18 +2086,16 @@ c_goal(Term Goal, Term mod, compiler_struct *cglobs) } } -static void -c_body(Term Body, Term mod, compiler_struct *cglobs) -{ +static void c_body(Term Body, Term mod, compiler_struct *cglobs) { cglobs->onhead = FALSE; cglobs->BodyStart = cglobs->cint.cpc; cglobs->goalno = 1; - while (IsNonVarTerm(Body) && IsApplTerm(Body) - && FunctorOfTerm(Body) == FunctorComma) { + while (IsNonVarTerm(Body) && IsApplTerm(Body) && + FunctorOfTerm(Body) == FunctorComma) { Term t2 = ArgOfTerm(2, Body); if (!cglobs->cint.success_handler && IsTrueGoal(t2)) { /* optimise the case where some idiot left trues at the end - of the clause. + of the clause. */ Body = ArgOfTerm(1, Body); break; @@ -2130,26 +2103,24 @@ c_body(Term Body, Term mod, compiler_struct *cglobs) c_goal(ArgOfTerm(1, Body), mod, cglobs); Body = t2; #ifdef BEAM - if (EAM) Yap_emit(endgoal_op, Zero, Zero, &cglobs->cint); + if (EAM) + Yap_emit(endgoal_op, Zero, Zero, &cglobs->cint); #endif - } cglobs->onlast = TRUE; c_goal(Body, mod, cglobs); #ifdef BEAM - if (EAM && cglobs->goalno > 1) { - if (cglobs->cint.cpc->op==procceed_op) { - cglobs->cint.cpc->op=endgoal_op; - Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); - } else - Yap_emit(endgoal_op, Zero, Zero, &cglobs->cint); - } + if (EAM && cglobs->goalno > 1) { + if (cglobs->cint.cpc->op == procceed_op) { + cglobs->cint.cpc->op = endgoal_op; + Yap_emit(procceed_op, Zero, Zero, &cglobs->cint); + } else + Yap_emit(endgoal_op, Zero, Zero, &cglobs->cint); + } #endif } -static void -c_head(Term t, compiler_struct *cglobs) -{ +static void c_head(Term t, compiler_struct *cglobs) { Functor f; cglobs->goalno = 0; @@ -2160,30 +2131,30 @@ c_head(Term t, compiler_struct *cglobs) cglobs->space_used = 0; cglobs->space_op = NULL; if (IsAtomTerm(t)) { - Yap_emit(name_op, (CELL) AtomOfTerm(t), Zero, &cglobs->cint); + Yap_emit(name_op, (CELL)AtomOfTerm(t), Zero, &cglobs->cint); #ifdef BEAM if (EAM) { - Yap_emit(run_op,Zero,(UInt) cglobs->cint.CurrentPred,&cglobs->cint); + Yap_emit(run_op, Zero, (UInt)cglobs->cint.CurrentPred, &cglobs->cint); } #endif - Yap_emit(ensure_space_op, Zero , Zero, &cglobs->cint); + Yap_emit(ensure_space_op, Zero, Zero, &cglobs->cint); cglobs->space_op = cglobs->cint.cpc; return; } f = FunctorOfTerm(t); - Yap_emit(name_op, (CELL) NameOfFunctor(f), ArityOfFunctor(f), &cglobs->cint); + Yap_emit(name_op, (CELL)NameOfFunctor(f), ArityOfFunctor(f), &cglobs->cint); #ifdef BEAM - if (EAM) { - Yap_emit(run_op,Zero,(UInt) cglobs->cint.CurrentPred,&cglobs->cint); - } + if (EAM) { + Yap_emit(run_op, Zero, (UInt)cglobs->cint.CurrentPred, &cglobs->cint); + } #endif if (Yap_ExecutionMode == MIXED_MODE_USER) - Yap_emit(native_op, 0, 0, &cglobs->cint); - Yap_emit(ensure_space_op, Zero , Zero, &cglobs->cint); + Yap_emit(native_op, 0, 0, &cglobs->cint); + Yap_emit(ensure_space_op, Zero, Zero, &cglobs->cint); cglobs->space_op = cglobs->cint.cpc; #ifdef BEAM if (EAM) { - Yap_emit(run_op,Zero,(UInt) cglobs->cint.CurrentPred,&cglobs->cint); + Yap_emit(run_op, Zero, (UInt)cglobs->cint.CurrentPred, &cglobs->cint); } #endif if (Yap_ExecutionMode == MIXED_MODE || Yap_ExecutionMode == COMPILED) @@ -2200,10 +2171,7 @@ c_head(Term t, compiler_struct *cglobs) c_args(t, 0, cglobs); } - -inline static bool -usesvar(compiler_vm_op ic) -{ +inline static bool usesvar(compiler_vm_op ic) { if (ic >= get_var_op && ic <= put_val_op) return true; switch (ic) { @@ -2223,9 +2191,8 @@ usesvar(compiler_vm_op ic) if (ic >= unify_s_var_op && ic <= write_s_val_op) return true; #endif - return ((ic >= unify_var_op && ic <= write_val_op) - || - (ic >= unify_last_var_op && ic <= unify_last_val_op)); + return ((ic >= unify_var_op && ic <= write_val_op) || + (ic >= unify_last_var_op && ic <= unify_last_val_op)); } /* @@ -2240,11 +2207,7 @@ inline static bool } */ -inline static bool -usesvar2(compiler_vm_op ic) -{ - return ic == bccall_op; -} +inline static bool usesvar2(compiler_vm_op ic) { return ic == bccall_op; } /* * Do as in the traditional WAM and make sure voids are in @@ -2253,43 +2216,38 @@ usesvar2(compiler_vm_op ic) #define LOCALISE_VOIDS 1 #ifdef LOCALISE_VOIDS -typedef struct env_tmp { - Ventry * Var; +typedef struct env_tmp { + Ventry *Var; struct env_tmp *Next; -} EnvTmp; +} EnvTmp; #endif - -static void - tag_use(Ventry *v USES_REGS) -{ +static void tag_use(Ventry *v USES_REGS) { #ifdef BEAM - if (EAM) { - if (v->NoOfVE == Unassigned || v->KindOfVE!=PermVar) { - v->NoOfVE = PermVar | (LOCAL_nperm++); - v->KindOfVE = PermVar; - v->FlagsOfVE |= PermFlag; - } - } + if (EAM) { + if (v->NoOfVE == Unassigned || v->KindOfVE != PermVar) { + v->NoOfVE = PermVar | (LOCAL_nperm++); + v->KindOfVE = PermVar; + v->FlagsOfVE |= PermFlag; + } + } #endif - if (v->NoOfVE == Unassigned) { - if ((v->AgeOfVE > 1 && (v->AgeOfVE > v->FirstOfVE)) - || v->KindOfVE == PermVar /* + if (v->NoOfVE == Unassigned) { + if ((v->AgeOfVE > 1 && (v->AgeOfVE > v->FirstOfVE)) || + v->KindOfVE == PermVar /* * * || (v->FlagsOfVE & NonVoid && !(v->FlagsOfVE & - * * OnHeadFlag)) - */ ) { - v->NoOfVE = PermVar | (LOCAL_nperm++); - v->KindOfVE = PermVar; - v->FlagsOfVE |= PermFlag; - } else { - v->NoOfVE = v->KindOfVE = TempVar; - } - } + * * OnHeadFlag)) + */) { + v->NoOfVE = PermVar | (LOCAL_nperm++); + v->KindOfVE = PermVar; + v->FlagsOfVE |= PermFlag; + } else { + v->NoOfVE = v->KindOfVE = TempVar; + } + } } -static void -AssignPerm(PInstr *pc, compiler_struct *cglobs) -{ +static void AssignPerm(PInstr *pc, compiler_struct *cglobs) { CACHE_REGS int uses_var; PInstr *opc = NULL; @@ -2300,7 +2258,7 @@ AssignPerm(PInstr *pc, compiler_struct *cglobs) /* The WAM tries to keep voids on the * environment. Traditionally, YAP liberally globalises * voids. - * + * * The new version goes to some length to keep void variables * in environments, but it is dubious that improves * performance, and may actually slow down the system @@ -2309,21 +2267,22 @@ AssignPerm(PInstr *pc, compiler_struct *cglobs) PInstr *tpc = pc->nextInst; #ifdef LOCALISE_VOIDS if (pc->op == put_var_op) { - Ventry *v = (Ventry *) (pc->rnd1); - if (v->AgeOfVE == v->FirstOfVE - && !(v->FlagsOfVE & (GlobalVal|OnHeadFlag|OnLastGoal|NonVoid)) ) { - EnvTmp *x = (EnvTmp *)Yap_AllocCMem(sizeof(*x), &cglobs->cint); - x->Next = EnvTmps; - x->Var = v; - EnvTmps = x; + Ventry *v = (Ventry *)(pc->rnd1); + if (v->AgeOfVE == v->FirstOfVE && + !(v->FlagsOfVE & (GlobalVal | OnHeadFlag | OnLastGoal | NonVoid))) { + EnvTmp *x = (EnvTmp *)Yap_AllocCMem(sizeof(*x), &cglobs->cint); + x->Next = EnvTmps; + x->Var = v; + EnvTmps = x; } } else #endif - if (pc->op == call_op || pc->op == either_op || pc->op == orelse_op || pc->op == push_or_op) { + if (pc->op == call_op || pc->op == either_op || pc->op == orelse_op || + pc->op == push_or_op) { #ifdef LOCALISE_VOIDS pc->ops.opseqt[1] = (CELL)EnvTmps; if (EnvTmps) - EnvTmps = NULL; + EnvTmps = NULL; #endif } pc->nextInst = opc; @@ -2338,31 +2297,31 @@ AssignPerm(PInstr *pc, compiler_struct *cglobs) pc->nextInst = opc; uses_var = usesvar(pc->op); if (uses_var) { - Ventry *v = (Ventry *) (pc->rnd1); + Ventry *v = (Ventry *)(pc->rnd1); - tag_use(v PASS_REGS); - if (usesvar2(pc->op) ) { - Ventry *v2 = (Ventry *) (pc->rnd3); - tag_use(v2 PASS_REGS); + tag_use(v PASS_REGS); + if (usesvar2(pc->op)) { + Ventry *v2 = (Ventry *)(pc->rnd3); + tag_use(v2 PASS_REGS); } } else if (pc->op == empty_call_op) { pc->rnd2 = LOCAL_nperm; - } else if (pc->op == call_op || pc->op == either_op || pc->op == orelse_op || pc->op == push_or_op) { + } else if (pc->op == call_op || pc->op == either_op || + pc->op == orelse_op || pc->op == push_or_op) { #ifdef LOCALISE_VOIDS EnvTmps = (EnvTmp *)(pc->ops.opseqt[1]); while (EnvTmps) { - Ventry *v = EnvTmps->Var; - v->NoOfVE = PermVar | (LOCAL_nperm++); - v->KindOfVE = PermVar; - v->FlagsOfVE |= (PermFlag|SafeVar); - EnvTmps = EnvTmps->Next; + Ventry *v = EnvTmps->Var; + v->NoOfVE = PermVar | (LOCAL_nperm++); + v->KindOfVE = PermVar; + v->FlagsOfVE |= (PermFlag | SafeVar); + EnvTmps = EnvTmps->Next; } #endif pc->rnd2 = LOCAL_nperm; - } else if (pc->op == cut_op || - pc->op == cutexit_op || - pc->op == commit_b_op) { + } else if (pc->op == cut_op || pc->op == cutexit_op || + pc->op == commit_b_op) { pc->rnd2 = LOCAL_nperm; } opc = pc; @@ -2370,24 +2329,21 @@ AssignPerm(PInstr *pc, compiler_struct *cglobs) } while (pc != NULL); } -static CELL * -init_bvarray(int nperm, compiler_struct *cglobs) -{ +static CELL *init_bvarray(int nperm, compiler_struct *cglobs) { CELL *vinfo = NULL; - size_t sz = sizeof(CELL)*(1+nperm/(8*sizeof(CELL))); + size_t sz = sizeof(CELL) * (1 + nperm / (8 * sizeof(CELL))); vinfo = (CELL *)Yap_AllocCMem(sz, &cglobs->cint); memset((void *)vinfo, 0, sz); return vinfo; } -static void -clear_bvarray(int var, CELL *bvarray +static void clear_bvarray(int var, CELL *bvarray #ifdef DEBUG - , compiler_struct *cglobs + , + compiler_struct *cglobs #endif -) -{ - int max = 8*sizeof(CELL); + ) { + int max = 8 * sizeof(CELL); CELL nbit; /* get to the array position */ @@ -2402,7 +2358,6 @@ clear_bvarray(int var, CELL *bvarray CACHE_REGS /* someone had already marked this variable: complain */ LOCAL_Error_TYPE = SYSTEM_ERROR_COMPILER; - LOCAL_Error_Term = TermNil; LOCAL_ErrorMessage = "compiler internal error: variable initialized twice"; save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH); @@ -2413,14 +2368,13 @@ clear_bvarray(int var, CELL *bvarray } /* copy the current state of the perm variable state array to code space */ -static void -add_bvarray_op(PInstr *cp, CELL *bvarray, int env_size, compiler_struct *cglobs) -{ - int i, size = env_size/(8*sizeof(CELL)); +static void add_bvarray_op(PInstr *cp, CELL *bvarray, int env_size, + compiler_struct *cglobs) { + int i, size = env_size / (8 * sizeof(CELL)); CELL *dest; - dest = - Yap_emit_extra_size(mark_initialized_pvars_op, (CELL)env_size, (size+1)*sizeof(CELL), &cglobs->cint); + dest = Yap_emit_extra_size(mark_initialized_pvars_op, (CELL)env_size, + (size + 1) * sizeof(CELL), &cglobs->cint); /* copy the cells to dest */ for (i = 0; i <= size; i++) *dest++ = *bvarray++; @@ -2432,19 +2386,16 @@ typedef struct { int lab; int last; PInstr *pc; -} bventry; +} bventry; #define MAX_DISJUNCTIONS 128 static bventry *bvstack; static int bvindex = 0; -static void -push_bvmap(int label, PInstr *pcpc, compiler_struct *cglobs) -{ +static void push_bvmap(int label, PInstr *pcpc, compiler_struct *cglobs) { if (bvindex == MAX_DISJUNCTIONS) { CACHE_REGS LOCAL_Error_TYPE = SYSTEM_ERROR_COMPILER; - LOCAL_Error_Term = TermNil; LOCAL_ErrorMessage = "Too many embedded disjunctions"; save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH); @@ -2457,42 +2408,36 @@ push_bvmap(int label, PInstr *pcpc, compiler_struct *cglobs) bvindex++; } -static void -reset_bvmap(CELL *bvarray, int nperm, compiler_struct *cglobs) -{ +static void reset_bvmap(CELL *bvarray, int nperm, compiler_struct *cglobs) { int size, size1, env_size, i; CELL *source; if (bvarray == NULL) - if (bvindex == 0) { - CACHE_REGS - LOCAL_Error_TYPE = SYSTEM_ERROR_COMPILER; - LOCAL_Error_Term = TermNil; - LOCAL_ErrorMessage = "No embedding in disjunctions"; - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH); - } - env_size = (bvstack[bvindex-1].pc)->rnd1; - size = env_size/(8*sizeof(CELL)); - size1 = nperm/(8*sizeof(CELL)); - source = (bvstack[bvindex-1].pc)->arnds; + if (bvindex == 0) { + CACHE_REGS + LOCAL_Error_TYPE = SYSTEM_ERROR_COMPILER; + LOCAL_ErrorMessage = "No embedding in disjunctions"; + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH); + } + env_size = (bvstack[bvindex - 1].pc)->rnd1; + size = env_size / (8 * sizeof(CELL)); + size1 = nperm / (8 * sizeof(CELL)); + source = (bvstack[bvindex - 1].pc)->arnds; for (i = 0; i <= size; i++) *bvarray++ = *source++; - for (i = size+1; i<= size1; i++) + for (i = size + 1; i <= size1; i++) *bvarray++ = (CELL)(0); } -static void -pop_bvmap(CELL *bvarray, int nperm, compiler_struct *cglobs) -{ +static void pop_bvmap(CELL *bvarray, int nperm, compiler_struct *cglobs) { if (bvindex == 0) { CACHE_REGS LOCAL_Error_TYPE = SYSTEM_ERROR_COMPILER; - LOCAL_Error_Term = TermNil; LOCAL_ErrorMessage = "Too few embedded disjunctions"; /* save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_HEAP_BOTCH); */ + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_HEAP_BOTCH); */ } reset_bvmap(bvarray, nperm, cglobs); bvindex--; @@ -2504,52 +2449,47 @@ typedef struct { } UnsafeEntry; /* extend to also support variable usage bitmaps for garbage collection */ -static void -CheckUnsafe(PInstr *pc, compiler_struct *cglobs) -{ +static void CheckUnsafe(PInstr *pc, compiler_struct *cglobs) { CACHE_REGS int pending = 0; /* say that all variables are yet to initialize */ CELL *vstat = init_bvarray(LOCAL_nperm, cglobs); - UnsafeEntry *UnsafeStack = - (UnsafeEntry *) Yap_AllocCMem(LOCAL_nperm * sizeof(UnsafeEntry), &cglobs->cint); + UnsafeEntry *UnsafeStack = (UnsafeEntry *)Yap_AllocCMem( + LOCAL_nperm * sizeof(UnsafeEntry), &cglobs->cint); /* keep a copy of previous cglobs->cint.cpc and CodeStart */ PInstr *opc = cglobs->cint.cpc; PInstr *OldCodeStart = cglobs->cint.CodeStart; - + cglobs->cint.CodeStart = cglobs->cint.BlobsStart; cglobs->cint.cpc = cglobs->cint.icpc; bvindex = 0; - bvstack = (bventry *)Yap_AllocCMem(MAX_DISJUNCTIONS * sizeof(bventry), &cglobs->cint); + bvstack = (bventry *)Yap_AllocCMem(MAX_DISJUNCTIONS * sizeof(bventry), + &cglobs->cint); while (pc != NIL) { - switch(pc->op) { - case put_val_op: - { - Ventry *v = (Ventry *) (pc->rnd1); - if ((v->FlagsOfVE & PermFlag) && !(v->FlagsOfVE & SafeVar)) { - UnsafeStack[pending].p = pc; - UnsafeStack[pending++].v = v; - v->FlagsOfVE |= SafeVar; - } - break; - } - case bccall_op: - { - Ventry *v = (Ventry *) (pc->rnd1), - *v3 = (Ventry *) (pc->rnd3); - - if ( (v->FlagsOfVE & PermFlag && pc == v->FirstOpForV) || - (v3->FlagsOfVE & PermFlag && pc == v3->FirstOpForV) ) { - CACHE_REGS - LOCAL_Error_TYPE = SYSTEM_ERROR_COMPILER; - LOCAL_Error_Term = TermNil; - LOCAL_ErrorMessage = "comparison should not have first instance of variables"; - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH); - } + switch (pc->op) { + case put_val_op: { + Ventry *v = (Ventry *)(pc->rnd1); + if ((v->FlagsOfVE & PermFlag) && !(v->FlagsOfVE & SafeVar)) { + UnsafeStack[pending].p = pc; + UnsafeStack[pending++].v = v; + v->FlagsOfVE |= SafeVar; } break; + } + case bccall_op: { + Ventry *v = (Ventry *)(pc->rnd1), *v3 = (Ventry *)(pc->rnd3); + + if ((v->FlagsOfVE & PermFlag && pc == v->FirstOpForV) || + (v3->FlagsOfVE & PermFlag && pc == v3->FirstOpForV)) { + CACHE_REGS + LOCAL_Error_TYPE = SYSTEM_ERROR_COMPILER; + LOCAL_ErrorMessage = + "comparison should not have first instance of variables"; + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH); + } + } break; case put_var_op: case get_var_op: case save_b_op: @@ -2558,21 +2498,20 @@ CheckUnsafe(PInstr *pc, compiler_struct *cglobs) case write_var_op: case save_appl_op: case save_pair_op: - case f_var_op: - { - Ventry *v = (Ventry *) (pc->rnd1); + case f_var_op: { + Ventry *v = (Ventry *)(pc->rnd1); - if (v->FlagsOfVE & PermFlag && pc == v->FirstOpForV) { - /* the second condition covers cases such as save_b_op - in a disjunction */ - clear_bvarray((v->NoOfVE & MaskVarAdrs), vstat + if (v->FlagsOfVE & PermFlag && pc == v->FirstOpForV) { + /* the second condition covers cases such as save_b_op + in a disjunction */ + clear_bvarray((v->NoOfVE & MaskVarAdrs), vstat #ifdef DEBUG - , cglobs + , + cglobs #endif - ); - } + ); } - break; + } break; case push_or_op: Yap_emit(label_op, ++cglobs->labelno, Zero, &cglobs->cint); pc->ops.opseqt[1] = (CELL)cglobs->labelno; @@ -2599,7 +2538,7 @@ CheckUnsafe(PInstr *pc, compiler_struct *cglobs) break; case empty_call_op: /* just get ourselves a label describing how - many permanent variables are alive */ + many permanent variables are alive */ Yap_emit(label_op, ++cglobs->labelno, Zero, &cglobs->cint); pc->rnd1 = (CELL)cglobs->labelno; add_bvarray_op(pc, vstat, pc->rnd2, cglobs); @@ -2607,7 +2546,7 @@ CheckUnsafe(PInstr *pc, compiler_struct *cglobs) case cut_op: case cutexit_op: /* just get ourselves a label describing how - many permanent variables are alive */ + many permanent variables are alive */ Yap_emit(label_op, ++cglobs->labelno, Zero, &cglobs->cint); pc->rnd1 = (CELL)cglobs->labelno; add_bvarray_op(pc, vstat, pc->rnd2, cglobs); @@ -2617,20 +2556,19 @@ CheckUnsafe(PInstr *pc, compiler_struct *cglobs) pc->ops.opseqt[1] = (CELL)cglobs->labelno; add_bvarray_op(pc, vstat, pc->rnd2, cglobs); case deallocate_op: - reset_safe_map: - { - int n = pc->op == call_op ? pc->rnd2 : 0; - int no; + reset_safe_map : { + int n = pc->op == call_op ? pc->rnd2 : 0; + int no; - while (pending) { - Ventry *v = UnsafeStack[--pending].v; + while (pending) { + Ventry *v = UnsafeStack[--pending].v; - v->FlagsOfVE &= ~SafeVar; - no = (v->NoOfVE) & MaskVarAdrs; - if (no >= n) - UnsafeStack[pending].p->op = put_unsafe_op; - } + v->FlagsOfVE &= ~SafeVar; + no = (v->NoOfVE) & MaskVarAdrs; + if (no >= n) + UnsafeStack[pending].p->op = put_unsafe_op; } + } default: break; } @@ -2643,9 +2581,8 @@ CheckUnsafe(PInstr *pc, compiler_struct *cglobs) } static void -CheckVoids(compiler_struct *cglobs) -{ /* establish voids in the head and initial - * uses */ +CheckVoids(compiler_struct *cglobs) { /* establish voids in the head and initial + * uses */ Ventry *ve; compiler_vm_op ic; struct PSEUDO *cpc; @@ -2661,21 +2598,20 @@ CheckVoids(compiler_struct *cglobs) #endif case save_pair_op: case save_appl_op: - ve = ((Ventry *) cpc->rnd1); + ve = ((Ventry *)cpc->rnd1); if ((ve->FlagsOfVE & PermFlag) == 0 && ve->RCountOfVE <= 1) { - ve->NoOfVE = ve->KindOfVE = VoidVar; - if (ic == get_var_op || ic == - save_pair_op || ic == save_appl_op + ve->NoOfVE = ve->KindOfVE = VoidVar; + if (ic == get_var_op || ic == save_pair_op || ic == save_appl_op #ifdef SFUNC - || ic == unify_s_var_op + || ic == unify_s_var_op #endif - ) { - cpc->op = nop_op; - break; - } + ) { + cpc->op = nop_op; + break; + } } if (ic != get_var_op) - break; + break; case get_val_op: case get_atom_op: case get_num_op: @@ -2698,10 +2634,9 @@ CheckVoids(compiler_struct *cglobs) } } -static int -checktemp(Int arg, Int rn, compiler_vm_op ic, compiler_struct *cglobs) -{ - Ventry *v = (Ventry *) arg; +static int checktemp(Int arg, Int rn, compiler_vm_op ic, + compiler_struct *cglobs) { + Ventry *v = (Ventry *)arg; PInstr *q; Int Needed[MaxTemps]; Int r, target1, target2; @@ -2710,13 +2645,12 @@ checktemp(Int arg, Int rn, compiler_vm_op ic, compiler_struct *cglobs) Int vadr; Int vreg; - cglobs->vadr = vadr = (v->NoOfVE); cglobs->vreg = vreg = vadr & MaskVarAdrs; if (v->KindOfVE == PermVar || v->KindOfVE == VoidVar) return 0; if (v->RCountOfVE == 1) - return 0; + return 0; if (vreg) { --cglobs->Uses[vreg]; return 1; @@ -2724,8 +2658,9 @@ checktemp(Int arg, Int rn, compiler_vm_op ic, compiler_struct *cglobs) /* follow the life of the variable */ q = cglobs->cint.cpc; /* - * for(r=0; rMaxCTemps; ++r) Needed[r] = cglobs->Uses[r]; might be written - * as: + * for(r=0; rMaxCTemps; ++r) Needed[r] = cglobs->Uses[r]; might be + * written + * as: */ np = Needed; rp = cglobs->Uses; @@ -2734,32 +2669,32 @@ checktemp(Int arg, Int rn, compiler_vm_op ic, compiler_struct *cglobs) if (rn > 0 && (ic == get_var_op || ic == put_var_op)) { if (ic == put_var_op) Needed[rn] = 1; - target1 = rn; /* try to leave it where it is */ - } - else + target1 = rn; /* try to leave it where it is */ + } else target1 = cglobs->MaxCTemps; target2 = cglobs->MaxCTemps; n = v->RCountOfVE - 1; while (q != v->LastOpForV && (q = q->nextInst) != NIL) { - if (q->rnd2 <= 0); /* don't try to reuse REGISTER 0 */ + if (q->rnd2 <= 0) + ; /* don't try to reuse REGISTER 0 */ else if ((usesvar(ic = q->op) && arg == q->rnd1) || - (ic == bccall_op && arg == q->rnd3)/*uses_this_var(q, arg)*/) { + (ic == bccall_op && arg == q->rnd3) /*uses_this_var(q, arg)*/) { ic = q->op; --n; if (ic == put_val_op) { - if (target1 == cglobs->MaxCTemps && Needed[q->rnd2] == 0) - target1 = q->rnd2; - else if (target1 != (r = q->rnd2)) { - if (target2 == cglobs->MaxCTemps && Needed[r] == 0) - target2 = r; - else if (target2 > r && cglobs->Uses[r] == 0 && Needed[r] == 0) - target2 = r; - } + if (target1 == cglobs->MaxCTemps && Needed[q->rnd2] == 0) + target1 = q->rnd2; + else if (target1 != (r = q->rnd2)) { + if (target2 == cglobs->MaxCTemps && Needed[r] == 0) + target2 = r; + else if (target2 > r && cglobs->Uses[r] == 0 && Needed[r] == 0) + target2 = r; + } } } #ifdef SFUNC - else if ((ic >= get_var_op && ic <= put_unsafe_op) - || ic == get_s_f_op || ic == put_s_f_op) + else if ((ic >= get_var_op && ic <= put_unsafe_op) || ic == get_s_f_op || + ic == put_s_f_op) Needed[q->rnd2] = 1; #else else if (ic >= get_var_op && ic <= put_unsafe_op) @@ -2774,17 +2709,18 @@ checktemp(Int arg, Int rn, compiler_vm_op ic, compiler_struct *cglobs) target1 = r; } if (target1 == cglobs->MaxCTemps || cglobs->Uses[target1] || Needed[target1]) - if ((target1 = target2) == cglobs->MaxCTemps || cglobs->Uses[target1] || Needed[target1]) { + if ((target1 = target2) == cglobs->MaxCTemps || cglobs->Uses[target1] || + Needed[target1]) { target1 = cglobs->MaxCTemps; do - --target1; + --target1; while (target1 && cglobs->Uses[target1] == 0 && Needed[target1] == 0); ++target1; } if (target1 == cglobs->MaxCTemps) { CACHE_REGS LOCAL_Error_TYPE = SYSTEM_ERROR_COMPILER; - LOCAL_Error_Term = TermNil; + LOCAL_ErrorMessage = "too many temporaries"; save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, COMPILER_ERR_BOTCH); @@ -2793,8 +2729,9 @@ checktemp(Int arg, Int rn, compiler_vm_op ic, compiler_struct *cglobs) v->KindOfVE = TempVar; cglobs->Uses[cglobs->vreg = vreg = target1] = v->RCountOfVE - 1; /* - * for(r=0; rMaxCTemps; ++r) if(cglobs->Contents[r]==vadr) cglobs->Contents[r] = - * NIL; + * for(r=0; rMaxCTemps; ++r) if(cglobs->Contents[r]==vadr) + * cglobs->Contents[r] = + * NIL; */ cp = cglobs->Contents; for (r = 0; r < cglobs->MaxCTemps; ++r) @@ -2804,16 +2741,15 @@ checktemp(Int arg, Int rn, compiler_vm_op ic, compiler_struct *cglobs) return 1; } -static Int -checkreg(Int arg, Int rn, compiler_vm_op ic, int var_arg, compiler_struct *cglobs) -{ +static Int checkreg(Int arg, Int rn, compiler_vm_op ic, int var_arg, + compiler_struct *cglobs) { PInstr *p = cglobs->cint.cpc; Int vreg; if (rn >= 0) return rn; if (var_arg) { - Ventry *v = (Ventry *) arg; + Ventry *v = (Ventry *)arg; vreg = (v->NoOfVE) & MaskVarAdrs; if (v->KindOfVE == PermVar) @@ -2826,7 +2762,7 @@ checkreg(Int arg, Int rn, compiler_vm_op ic, int var_arg, compiler_struct *cglob if (!vreg) { vreg = 1; while (cglobs->Uses[vreg] != 0) { - ++vreg; + ++vreg; } cglobs->Uses[vreg] = v->RCountOfVE; } @@ -2840,7 +2776,8 @@ checkreg(Int arg, Int rn, compiler_vm_op ic, int var_arg, compiler_struct *cglob if (p->op >= get_var_op && p->op <= put_unsafe_op && p->rnd2 == rn) p->rnd2 = vreg; /* only copy variables until you reach a call */ - if (p->op == procceed_op || p->op == call_op || p->op == push_or_op || p->op == pushpop_or_op) + if (p->op == procceed_op || p->op == call_op || p->op == push_or_op || + p->op == pushpop_or_op) break; p = p->nextInst; } @@ -2848,32 +2785,28 @@ checkreg(Int arg, Int rn, compiler_vm_op ic, int var_arg, compiler_struct *cglob } /* Create a bitmap with all live variables */ -static CELL -copy_live_temps_bmap(int max, compiler_struct *cglobs) -{ - unsigned int size = AdjustSize((max|7)/8+1); +static CELL copy_live_temps_bmap(int max, compiler_struct *cglobs) { + unsigned int size = AdjustSize((max | 7) / 8 + 1); int i; CELL *dest = Yap_emit_extra_size(mark_live_regs_op, max, size, &cglobs->cint); - CELL *ptr=dest; + CELL *ptr = dest; *ptr = 0L; - for (i=1; i <= max; i++) { + for (i = 1; i <= max; i++) { /* move to next cell */ - if (i%(8*CellSize) == 0) { + if (i % (8 * CellSize) == 0) { ptr++; *ptr = 0L; } /* set the register live bit */ if (cglobs->Contents[i]) { - int j = i%(8*CellSize); - *ptr |= (1<BodyStart->nextInst; register Ventry *v = cglobs->vtable; @@ -2894,11 +2827,11 @@ c_layout(compiler_struct *cglobs) if (!cglobs->is_a_fact) { while (v != NIL) { if (v->FlagsOfVE & BranchVar) { - v->AgeOfVE = v->FirstOfVE + 1; /* force permanent */ - ++(v->RCountOfVE); - Yap_emit(put_var_op, (CELL) v, Zero, &cglobs->cint); - v->FlagsOfVE &= ~GlobalVal; - v->FirstOpForV = cglobs->cint.cpc; + v->AgeOfVE = v->FirstOfVE + 1; /* force permanent */ + ++(v->RCountOfVE); + Yap_emit(put_var_op, (CELL)v, Zero, &cglobs->cint); + v->FlagsOfVE &= ~GlobalVal; + v->FirstOpForV = cglobs->cint.cpc; } v = v->NextOfVE; } @@ -2917,18 +2850,18 @@ c_layout(compiler_struct *cglobs) CheckUnsafe(cglobs->cint.CodeStart, cglobs); #ifdef DEBUG if (cglobs->pbvars != LOCAL_nperm) { - CACHE_REGS - LOCAL_Error_TYPE = SYSTEM_ERROR_COMPILER; - LOCAL_Error_Term = TermNil; - LOCAL_ErrorMessage = "wrong number of variables found in bitmap"; - save_machine_regs(); - siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_HEAP_BOTCH); - } + CACHE_REGS + LOCAL_Error_TYPE = SYSTEM_ERROR_COMPILER; + LOCAL_ErrorMessage = "wrong number of variables found in bitmap"; + save_machine_regs(); + siglongjmp(cglobs->cint.CompilerBotch, OUT_OF_HEAP_BOTCH); + } #endif } } - cglobs->MaxCTemps = cglobs->nvars + cglobs->max_args - cglobs->tmpreg + cglobs->n_common_exps + 2; + cglobs->MaxCTemps = cglobs->nvars + cglobs->max_args - cglobs->tmpreg + + cglobs->n_common_exps + 2; if (cglobs->MaxCTemps >= MaxTemps) cglobs->MaxCTemps = MaxTemps; { @@ -2951,7 +2884,7 @@ c_layout(compiler_struct *cglobs) switch (ic) { case pop_or_op: if (needs_either) - needs_either--; + needs_either--; case either_op: needs_either++; break; @@ -2962,67 +2895,68 @@ c_layout(compiler_struct *cglobs) break; #else case cut_op: - case cutexit_op: - { - int i, max; + case cutexit_op: { + int i, max; - max = 0; - for (i = 1; i < cglobs->MaxCTemps; ++i) { - if (cglobs->Contents[i]) max = i; - } - cglobs->cint.cpc->ops.opseqt[1] = max; + max = 0; + for (i = 1; i < cglobs->MaxCTemps; ++i) { + if (cglobs->Contents[i]) + max = i; } - break; + cglobs->cint.cpc->ops.opseqt[1] = max; + } break; #endif /* TABLING_INNER_CUTS */ case allocate_op: case deallocate_op: if (!cglobs->needs_env) { - cglobs->cint.cpc->op = nop_op; + cglobs->cint.cpc->op = nop_op; } else { #ifdef TABLING - PELOCK(51,cglobs->cint.CurrentPred); - if (is_tabled(cglobs->cint.CurrentPred)) - cglobs->cint.cpc->op = nop_op; - else + PELOCK(51, cglobs->cint.CurrentPred); + if (is_tabled(cglobs->cint.CurrentPred)) + cglobs->cint.cpc->op = nop_op; + else #endif /* TABLING */ - if (cglobs->goalno == 1 && !cglobs->or_found && LOCAL_nperm == 0) - cglobs->cint.cpc->op = nop_op; + if (cglobs->goalno == 1 && !cglobs->or_found && LOCAL_nperm == 0) + cglobs->cint.cpc->op = nop_op; #ifdef TABLING - UNLOCK(cglobs->cint.CurrentPred->PELock); + UNLOCK(cglobs->cint.CurrentPred->PELock); #endif } break; case pop_op: ic = (cglobs->cint.cpc->nextInst)->op; if (ic >= get_var_op && ic <= put_unsafe_op) - cglobs->cint.cpc->op = nop_op; + cglobs->cint.cpc->op = nop_op; break; case get_var_op: --cglobs->Uses[rn]; if (checktemp(arg, rn, ic, cglobs)) { #ifdef BEAM - if (cglobs->vreg == rn && !EAM) + if (cglobs->vreg == rn && !EAM) #else - if (cglobs->vreg == rn) + if (cglobs->vreg == rn) #endif - cglobs->cint.cpc->op = nop_op; + cglobs->cint.cpc->op = nop_op; } if (!cglobs->Uses[rn]) - cglobs->Contents[rn] = cglobs->vadr; + cglobs->Contents[rn] = cglobs->vadr; break; case get_val_op: --cglobs->Uses[rn]; checktemp(arg, rn, ic, cglobs); if (!cglobs->Uses[rn]) - cglobs->Contents[rn] = cglobs->vadr; + cglobs->Contents[rn] = cglobs->vadr; break; case f_0_op: - if (rn_to_kill[0]) --cglobs->Uses[rn_to_kill[0]]; - rn_to_kill[1]=rn_to_kill[0]=0; + if (rn_to_kill[0]) + --cglobs->Uses[rn_to_kill[0]]; + rn_to_kill[1] = rn_to_kill[0] = 0; break; case f_var_op: - if (rn_to_kill[0]) --cglobs->Uses[rn_to_kill[0]]; - rn_to_kill[1]=rn_to_kill[0]=0; + if (rn_to_kill[0]) + --cglobs->Uses[rn_to_kill[0]]; + rn_to_kill[1] = rn_to_kill[0] = 0; case unify_var_op: case unify_val_op: case unify_last_var_op: @@ -3046,16 +2980,16 @@ c_layout(compiler_struct *cglobs) case get_bigint_op: --cglobs->Uses[rn]; /* This is not safe if we are in the middle of a disjunction and there - is something ahead. + is something ahead. */ if (!cglobs->Uses[rn]) - cglobs->Contents[rn] = arg; + cglobs->Contents[rn] = arg; break; case get_list_op: case get_struct_op: --cglobs->Uses[rn]; if (!cglobs->Uses[rn]) - cglobs->Contents[rn] = NIL; + cglobs->Contents[rn] = NIL; break; case put_var_op: case put_unsafe_op: @@ -3072,38 +3006,36 @@ c_layout(compiler_struct *cglobs) #else if (rn && cglobs->Contents[rn] == (Term)cglobs->vadr) #endif - { - cglobs->cint.cpc->op = nop_op; - } + { + cglobs->cint.cpc->op = nop_op; + } cglobs->Contents[rn] = cglobs->vadr; ++cglobs->Uses[rn]; if (rn_kills) { - rn_kills--; - rn_to_kill[rn_kills]=rn; + rn_kills--; + rn_to_kill[rn_kills] = rn; } break; case fetch_args_cv_op: case fetch_args_vc_op: case fetch_args_iv_op: case fetch_args_vi_op: - rn_to_kill[1]=rn_to_kill[0]=0; + rn_to_kill[1] = rn_to_kill[0] = 0; if (cglobs->cint.cpc->nextInst && - cglobs->cint.cpc->nextInst->op == put_val_op && - cglobs->cint.cpc->nextInst->nextInst && - (cglobs->cint.cpc->nextInst->nextInst->op == f_var_op || - cglobs->cint.cpc->nextInst->nextInst->op == f_0_op) ) - rn_kills = 1; + cglobs->cint.cpc->nextInst->op == put_val_op && + cglobs->cint.cpc->nextInst->nextInst && + (cglobs->cint.cpc->nextInst->nextInst->op == f_var_op || + cglobs->cint.cpc->nextInst->nextInst->op == f_0_op)) + rn_kills = 1; break; case f_val_op: #ifdef SFUNC - case write_s_var_op: - { - Ventry *ve = (Ventry *) arg; + case write_s_var_op: { + Ventry *ve = (Ventry *)arg; - if ((ve->FlagsOfVE & PermFlag) == 0 && ve->RCountOfVE <= 1) - cglobs->cint.cpc->op = nop_op; - } - break; + if ((ve->FlagsOfVE & PermFlag) == 0 && ve->RCountOfVE <= 1) + cglobs->cint.cpc->op = nop_op; + } break; case write_s_val_op: #endif case write_var_op: @@ -3125,7 +3057,7 @@ c_layout(compiler_struct *cglobs) case put_bigint_op: rn = checkreg(arg, rn, ic, FALSE, cglobs); if (cglobs->Contents[rn] == arg) - cglobs->cint.cpc->op = nop_op; + cglobs->cint.cpc->op = nop_op; cglobs->Contents[rn] = arg; ++cglobs->Uses[rn]; break; @@ -3140,87 +3072,84 @@ c_layout(compiler_struct *cglobs) cglobs->cut_mark->op = clause_with_cut_op; #endif /* TABLING_INNER_CUTS */ case save_b_op: - case patch_b_op: + case patch_b_op: case save_appl_op: case save_pair_op: checktemp(arg, rn, ic, cglobs); break; case safe_call_op: /* - vsc: The variables will be in use after this!!!! - { - UInt Arity = RepPredProp((Prop) arg)->ArityOfPE; - for (rn = 1; rn <= Arity; ++rn) - --cglobs->Uses[rn]; - } + vsc: The variables will be in use after this!!!! + { + UInt Arity = RepPredProp((Prop) arg)->ArityOfPE; + for (rn = 1; rn <= Arity; ++rn) + --cglobs->Uses[rn]; + } */ break; case call_op: case orelse_op: - case orlast_op: - { - up = cglobs->Uses; - cop = cglobs->Contents; - for (rn = 1; rn < cglobs->MaxCTemps; ++rn) { - *up++ = *cop++ = NIL; - } + case orlast_op: { + up = cglobs->Uses; + cop = cglobs->Contents; + for (rn = 1; rn < cglobs->MaxCTemps; ++rn) { + *up++ = *cop++ = NIL; } - break; - case label_op: - { - up = cglobs->Uses; - cop = cglobs->Contents; - for (rn = 0; rn < cglobs->MaxCTemps; ++rn) { - if (*cop != (TempVar | rn)) { - *up++ = *cop++ = NIL; - } else { - up++; - cop++; - } - } + } break; + case label_op: { + up = cglobs->Uses; + cop = cglobs->Contents; + for (rn = 0; rn < cglobs->MaxCTemps; ++rn) { + if (*cop != (TempVar | rn)) { + *up++ = *cop++ = NIL; + } else { + up++; + cop++; + } } - break; + } break; case restore_tmps_and_skip_op: case restore_tmps_op: /* - This instruction is required by the garbage collector to find out - how many temporaries are live right now. It is also useful when - waking up goals before an either or ! instruction. + This instruction is required by the garbage collector to find out + how many temporaries are live right now. It is also useful when + waking up goals before an either or ! instruction. */ { - PInstr *mycpc = cglobs->cint.cpc, *oldCodeStart = cglobs->cint.CodeStart; - int i, max; + PInstr *mycpc = cglobs->cint.cpc, + *oldCodeStart = cglobs->cint.CodeStart; + int i, max; - /* instructions must be placed at BlobsStart */ - cglobs->cint.CodeStart = cglobs->cint.BlobsStart; - cglobs->cint.cpc = cglobs->cint.icpc; - max = 0; - for (i = 1; i < cglobs->MaxCTemps; ++i) { - if (cglobs->Contents[i]) max = i; - } - Yap_emit(label_op, ++cglobs->labelno, Zero, &cglobs->cint); - mycpc->rnd1 = cglobs->labelno; - rn = copy_live_temps_bmap(max, cglobs); - cglobs->cint.icpc = cglobs->cint.cpc; - cglobs->cint.BlobsStart = cglobs->cint.CodeStart; - cglobs->cint.cpc = mycpc; - cglobs->cint.CodeStart = oldCodeStart; + /* instructions must be placed at BlobsStart */ + cglobs->cint.CodeStart = cglobs->cint.BlobsStart; + cglobs->cint.cpc = cglobs->cint.icpc; + max = 0; + for (i = 1; i < cglobs->MaxCTemps; ++i) { + if (cglobs->Contents[i]) + max = i; + } + Yap_emit(label_op, ++cglobs->labelno, Zero, &cglobs->cint); + mycpc->rnd1 = cglobs->labelno; + rn = copy_live_temps_bmap(max, cglobs); + cglobs->cint.icpc = cglobs->cint.cpc; + cglobs->cint.BlobsStart = cglobs->cint.CodeStart; + cglobs->cint.cpc = mycpc; + cglobs->cint.CodeStart = oldCodeStart; } default: break; } if (cglobs->cint.cpc->nextInst) cglobs->cint.cpc = cglobs->cint.cpc->nextInst; - else return; + else + return; } } -static void -push_allocate(PInstr *pc, PInstr *oldpc) -{ +static void push_allocate(PInstr *pc, PInstr *oldpc) { /* The idea is to push an allocate forward as much as we can. This - delays work in the emulated code, and in the best case we may get rid of + delays work in the emulated code, and in the best case we may get rid of allocates altogether. */ /* we can push the allocate */ @@ -3228,7 +3157,7 @@ push_allocate(PInstr *pc, PInstr *oldpc) PInstr *initial = oldpc, *dealloc_founds[16]; int d_founds = 0; int level = 0; - + while (pc) { switch (pc->op) { case jump_op: @@ -3236,20 +3165,21 @@ push_allocate(PInstr *pc, PInstr *oldpc) case call_op: case safe_call_op: if (!safe) - return; + return; else { - PInstr *where = initial->nextInst->nextInst; - while (d_founds) - dealloc_founds[--d_founds]->op = nop_op; - if (where == pc || oldpc == initial->nextInst) - return; - oldpc->nextInst = initial->nextInst; - initial->nextInst->nextInst = pc; - initial->nextInst = where; - return; + PInstr *where = initial->nextInst->nextInst; + while (d_founds) + dealloc_founds[--d_founds]->op = nop_op; + if (where == pc || oldpc == initial->nextInst) + return; + oldpc->nextInst = initial->nextInst; + initial->nextInst->nextInst = pc; + initial->nextInst = where; + return; } case push_or_op: - /* we cannot just put an allocate here, because it may never be executed */ + /* we cannot just put an allocate here, because it may never be executed + */ level++; safe = FALSE; break; @@ -3257,7 +3187,7 @@ push_allocate(PInstr *pc, PInstr *oldpc) /* last branch and we did not need an allocate so far, cool! */ level--; if (!level) - safe = TRUE; + safe = TRUE; break; case cut_op: case either_op: @@ -3266,7 +3196,7 @@ push_allocate(PInstr *pc, PInstr *oldpc) case deallocate_op: dealloc_founds[d_founds++] = pc; if (d_founds == 16) - return; + return; default: break; } @@ -3275,11 +3205,7 @@ push_allocate(PInstr *pc, PInstr *oldpc) } } - - -static void -c_optimize(PInstr *pc) -{ +static void c_optimize(PInstr *pc) { char onTail; Ventry *v; PInstr *opc = NULL; @@ -3304,55 +3230,51 @@ c_optimize(PInstr *pc) case get_var_op: /* handle clumsy either branches */ if (npc->op == f_0_op) { - npc->rnd1 = pc->rnd1; - npc->op = f_var_op; - pc->op = nop_op; - break; + npc->rnd1 = pc->rnd1; + npc->op = f_var_op; + pc->op = nop_op; + break; } case put_val_op: - case get_val_op: - { - Ventry *ve = (Ventry *) pc->rnd1; + case get_val_op: { + Ventry *ve = (Ventry *)pc->rnd1; - if (ve->KindOfVE == TempVar) { - UInt argno = ve->NoOfVE & MaskVarAdrs; - if (argno && argno == pc->rnd2) { - pc->op = nop_op; - } - } + if (ve->KindOfVE == TempVar) { + UInt argno = ve->NoOfVE & MaskVarAdrs; + if (argno && argno == pc->rnd2) { + pc->op = nop_op; + } } + } onTail = 1; break; - case save_pair_op: - { - Term ve = (Term) pc->rnd1; - PInstr *npc = pc->nextInst; + case save_pair_op: { + Term ve = (Term)pc->rnd1; + PInstr *npc = pc->nextInst; - if (((Ventry *) ve)->RCountOfVE <= 1) - pc->op = nop_op; - else { - *pc = *npc; - pc->nextInst = npc; - npc->op = save_pair_op; - npc->rnd1 = (CELL) ve; - } - } - break; - case save_appl_op: - { - Term ve = (Term) pc->rnd1; - PInstr *npc = pc->nextInst; - - if (((Ventry *) ve)->RCountOfVE <= 1) - pc->op = nop_op; - else { - *pc = *npc; - pc->nextInst = npc; - npc->op = save_appl_op; - npc->rnd1 = (CELL) ve; - } - break; + if (((Ventry *)ve)->RCountOfVE <= 1) + pc->op = nop_op; + else { + *pc = *npc; + pc->nextInst = npc; + npc->op = save_pair_op; + npc->rnd1 = (CELL)ve; } + } break; + case save_appl_op: { + Term ve = (Term)pc->rnd1; + PInstr *npc = pc->nextInst; + + if (((Ventry *)ve)->RCountOfVE <= 1) + pc->op = nop_op; + else { + *pc = *npc; + pc->nextInst = npc; + npc->op = save_appl_op; + npc->rnd1 = (CELL)ve; + } + break; + } case nop_op: break; case unify_var_op: @@ -3364,49 +3286,47 @@ c_optimize(PInstr *pc) * finish the structure for the last instructions to * work correctly. Instead, we will use unify_void * with very little overhead */ - v = (Ventry *) (pc->rnd1); + v = (Ventry *)(pc->rnd1); if (v->KindOfVE == VoidVar && onTail) { pc->op = nop_op; - } - else -#endif /* OLD_SYSTEM */ - onTail = 0; + } else +#endif /* OLD_SYSTEM */ + onTail = 0; break; case unify_val_op: - v = (Ventry *) (pc->rnd1); + v = (Ventry *)(pc->rnd1); if (!(v->FlagsOfVE & GlobalVal)) - pc->op = unify_local_op; + pc->op = unify_local_op; onTail = 0; break; case unify_last_val_op: - v = (Ventry *) (pc->rnd1); + v = (Ventry *)(pc->rnd1); if (!(v->FlagsOfVE & GlobalVal)) - pc->op = unify_last_local_op; + pc->op = unify_last_local_op; onTail = 0; break; case write_val_op: - v = (Ventry *) (pc->rnd1); + v = (Ventry *)(pc->rnd1); if (!(v->FlagsOfVE & GlobalVal)) - pc->op = write_local_op; + pc->op = write_local_op; onTail = 0; break; case pop_op: if (FALSE && onTail == 1) { - pc->op = nop_op; - onTail = 1; - break; - } - else { - PInstr *p = pc->nextInst; + pc->op = nop_op; + onTail = 1; + break; + } else { + PInstr *p = pc->nextInst; - while (p != NIL && p->op == nop_op) - p = p->nextInst; - if (p != NIL && p->op == pop_op) { - pc->rnd1 += p->rnd1; - pc->nextInst = p->nextInst; - } - onTail = 2; - break; + while (p != NIL && p->op == nop_op) + p = p->nextInst; + if (p != NIL && p->op == pop_op) { + pc->rnd1 += p->rnd1; + pc->nextInst = p->nextInst; + } + onTail = 2; + break; } case write_var_op: case unify_atom_op: @@ -3455,15 +3375,15 @@ c_optimize(PInstr *pc) if (pc->op == allocate_op) { push_allocate(pc, opc); break; - } + } opc = pc; pc = pc->nextInst; } } -yamop * -Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src) -{ /* compile a prolog clause, copy of clause myst be in ARG1 */ +yamop *Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, + volatile Term src) { /* compile a prolog clause, copy of + clause myst be in ARG1 */ CACHE_REGS /* returns address of code for clause */ Term head, body; @@ -3473,13 +3393,14 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src) volatile int maxvnum = 512; int botch_why; /* may botch while doing a different module */ - /* first, initialize cglobs->cint.CompilerBotch to handle all cases of interruptions */ + /* first, initialize cglobs->cint.CompilerBotch to handle all cases of + * interruptions */ compiler_struct cglobs; - - #ifdef TABLING_INNER_CUTS + +#ifdef TABLING_INNER_CUTS PInstr cglobs_cut_mark; cglobs.cut_mark = &cglobs_cut_mark; - #endif /* TABLING_INNER_CUTS */ +#endif /* TABLING_INNER_CUTS */ /* make sure we know there was no error yet */ LOCAL_ErrorMessage = NULL; @@ -3487,28 +3408,26 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src) restore_machine_regs(); reset_vars(cglobs.vtable); Yap_ReleaseCMem(&cglobs.cint); - switch(botch_why) { + switch (botch_why) { case OUT_OF_STACK_BOTCH: /* out of local stack, just duplicate the stack */ { - Int osize = 2*sizeof(CELL)*(ASP-HR); - ARG1 = inp_clause; - ARG3 = src; + Int osize = 2 * sizeof(CELL) * (ASP - HR); + ARG1 = inp_clause; + ARG3 = src; - YAPLeaveCriticalSection(); - if (!Yap_gcl(LOCAL_Error_Size, NOfArgs, ENV, gc_P(P,CP))) { - LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; - LOCAL_Error_Term = inp_clause; - } - if (osize > ASP-HR) { - if (!Yap_growstack(2*sizeof(CELL)*(ASP-HR))) { - LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; - LOCAL_Error_Term = inp_clause; - } - } - YAPEnterCriticalSection(); - src = ARG3; - inp_clause = ARG1; + YAPLeaveCriticalSection(); + if (!Yap_gcl(LOCAL_Error_Size, NOfArgs, ENV, gc_P(P, CP))) { + LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; + } + if (osize > ASP - HR) { + if (!Yap_growstack(2 * sizeof(CELL) * (ASP - HR))) { + LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; + } + } + YAPEnterCriticalSection(); + src = ARG3; + inp_clause = ARG1; } break; case OUT_OF_AUX_BOTCH: @@ -3517,8 +3436,7 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src) ARG1 = inp_clause; ARG3 = src; if (!Yap_ExpandPreAllocCodeSpace(LOCAL_Error_Size, NULL, TRUE)) { - LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; - LOCAL_Error_Term = inp_clause; + LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; } YAPEnterCriticalSection(); src = ARG3; @@ -3526,10 +3444,10 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src) break; case OUT_OF_TEMPS_BOTCH: /* out of temporary cells */ - if (maxvnum < 16*1024) { - maxvnum *= 2; + if (maxvnum < 16 * 1024) { + maxvnum *= 2; } else { - maxvnum += 4096; + maxvnum += 4096; } break; case OUT_OF_HEAP_BOTCH: @@ -3538,9 +3456,8 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src) ARG3 = src; YAPLeaveCriticalSection(); if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) { - LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; - LOCAL_Error_Term = inp_clause; - return NULL; + LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; + return NULL; } YAPEnterCriticalSection(); src = ARG3; @@ -3551,10 +3468,9 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src) ARG1 = inp_clause; ARG3 = src; YAPLeaveCriticalSection(); - if (!Yap_growtrail(LOCAL_TrailTop-(ADDR)TR, FALSE)) { - LOCAL_Error_TYPE = RESOURCE_ERROR_TRAIL; - LOCAL_Error_Term = inp_clause; - return NULL; + if (!Yap_growtrail(LOCAL_TrailTop - (ADDR)TR, FALSE)) { + LOCAL_Error_TYPE = RESOURCE_ERROR_TRAIL; + return NULL; } YAPEnterCriticalSection(); src = ARG3; @@ -3570,24 +3486,25 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src) LOCAL_Error_Size = 0; LOCAL_Error_TYPE = YAP_NO_ERROR; /* initialize variables for code generation */ - + cglobs.cint.CodeStart = cglobs.cint.cpc = NULL; cglobs.cint.BlobsStart = cglobs.cint.icpc = NULL; cglobs.cint.dbterml = NULL; cglobs.cint.blks = NULL; cglobs.cint.label_offset = NULL; - cglobs.cint.freep = - cglobs.cint.freep0 = - (char *) (HR + maxvnum+(sizeof(Int)/sizeof(CELL))*MaxTemps+MaxTemps); + cglobs.cint.freep = cglobs.cint.freep0 = + (char *)(HR + maxvnum + (sizeof(Int) / sizeof(CELL)) * MaxTemps + + MaxTemps); cglobs.cint.success_handler = 0L; - if (ASP <= CellPtr (cglobs.cint.freep) + 256) { + if (ASP <= CellPtr(cglobs.cint.freep) + 256) { cglobs.vtable = NULL; - LOCAL_Error_Size = (256+maxvnum)*sizeof(CELL); + LOCAL_Error_Size = (256 + maxvnum) * sizeof(CELL); save_machine_regs(); - siglongjmp(cglobs.cint.CompilerBotch,3); + siglongjmp(cglobs.cint.CompilerBotch, 3); } - cglobs.Uses = (Int *)(HR+maxvnum); - cglobs.Contents = (Term *)(HR+maxvnum+(sizeof(Int)/sizeof(CELL))*MaxTemps); + cglobs.Uses = (Int *)(HR + maxvnum); + cglobs.Contents = + (Term *)(HR + maxvnum + (sizeof(Int) / sizeof(CELL)) * MaxTemps); cglobs.curbranch = cglobs.onbranch = 0; cglobs.branch_pointer = cglobs.parent_branches; cglobs.or_found = FALSE; @@ -3597,7 +3514,7 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src) cglobs.needs_env = FALSE; /* * 2000 added to H in case we need to construct call(G) when G is a - * variable used as a goal + * variable used as a goal */ cglobs.vtable = NULL; cglobs.common_exps = NULL; @@ -3607,39 +3524,40 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src) cglobs.hasdbrefs = FALSE; if (IsVarTerm(my_clause)) { LOCAL_Error_TYPE = INSTANTIATION_ERROR; - LOCAL_Error_Term = my_clause; LOCAL_ErrorMessage = "in compiling clause"; return 0; } if (IsApplTerm(my_clause) && FunctorOfTerm(my_clause) == FunctorAssert) { head = ArgOfTerm(1, my_clause); body = ArgOfTerm(2, my_clause); - } - else { + } else { head = my_clause, body = MkAtomTerm(AtomTrue); } - if (IsVarTerm(head) || IsPairTerm(head) || IsIntTerm(head) || IsFloatTerm(head) || IsRefTerm(head)) { + if (IsVarTerm(head) || IsPairTerm(head) || IsIntTerm(head) || + IsFloatTerm(head) || IsRefTerm(head)) { LOCAL_Error_TYPE = TYPE_ERROR_CALLABLE; - LOCAL_Error_Term = head; LOCAL_ErrorMessage = "clause head should be atom or compound term"; return (0); } else { - + /* find out which predicate we are compiling for */ if (IsAtomTerm(head)) { Atom ap = AtomOfTerm(head); cglobs.cint.CurrentPred = RepPredProp(PredPropByAtom(ap, mod)); } else { - cglobs.cint.CurrentPred = RepPredProp(PredPropByFunc(FunctorOfTerm(head),mod)); + cglobs.cint.CurrentPred = + RepPredProp(PredPropByFunc(FunctorOfTerm(head), mod)); } /* insert extra instructions to count calls */ - PELOCK(52,cglobs.cint.CurrentPred); + PELOCK(52, cglobs.cint.CurrentPred); if ((cglobs.cint.CurrentPred->PredFlags & ProfiledPredFlag) || - (PROFILING && (cglobs.cint.CurrentPred->cs.p_code.FirstClause == NIL))) { + (PROFILING && + (cglobs.cint.CurrentPred->cs.p_code.FirstClause == NIL))) { profiling = TRUE; call_counting = FALSE; } else if ((cglobs.cint.CurrentPred->PredFlags & CountPredFlag) || - (CALL_COUNTING && (cglobs.cint.CurrentPred->cs.p_code.FirstClause == NIL))) { + (CALL_COUNTING && + (cglobs.cint.CurrentPred->cs.p_code.FirstClause == NIL))) { call_counting = TRUE; profiling = FALSE; } else { @@ -3655,9 +3573,10 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src) if (cglobs.is_a_fact && !cglobs.vtable) { #ifdef TABLING - PELOCK(53,cglobs.cint.CurrentPred); + PELOCK(53, cglobs.cint.CurrentPred); if (is_tabled(cglobs.cint.CurrentPred)) - Yap_emit(table_new_answer_op, Zero, cglobs.cint.CurrentPred->ArityOfPE, &cglobs.cint); + Yap_emit(table_new_answer_op, Zero, cglobs.cint.CurrentPred->ArityOfPE, + &cglobs.cint); else #endif /* TABLING */ Yap_emit(procceed_op, Zero, Zero, &cglobs.cint); @@ -3687,11 +3606,12 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src) Yap_emit(allocate_op, Zero, Zero, &cglobs.cint); #ifdef BEAM - if (EAM) Yap_emit(body_op, Zero, Zero, &cglobs.cint); + if (EAM) + Yap_emit(body_op, Zero, Zero, &cglobs.cint); #endif c_body(body, mod, &cglobs); - /* Insert blobs at the very end */ + /* Insert blobs at the very end */ if (cglobs.space_op) cglobs.space_op->rnd1 = cglobs.space_used; @@ -3714,12 +3634,12 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src) #endif /* phase 2: classify variables and optimize temporaries */ c_layout(&cglobs); - /* Insert blobs at the very end */ + /* Insert blobs at the very end */ if (cglobs.cint.BlobsStart != NULL) { cglobs.cint.cpc->nextInst = cglobs.cint.BlobsStart; cglobs.cint.BlobsStart = NULL; while (cglobs.cint.cpc->nextInst != NULL) - cglobs.cint.cpc = cglobs.cint.cpc->nextInst; + cglobs.cint.cpc = cglobs.cint.cpc->nextInst; } } /* eliminate superfluous pop's and unify_var's */ @@ -3730,17 +3650,21 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src) #endif #ifdef BEAM - { - void codigo_eam(compiler_struct *); - - if (EAM) codigo_eam(&cglobs); - } + { + void codigo_eam(compiler_struct *); + + if (EAM) + codigo_eam(&cglobs); + } #endif /* phase 3: assemble code */ - acode = Yap_assemble(ASSEMBLING_CLAUSE, src, cglobs.cint.CurrentPred, (cglobs.is_a_fact && !cglobs.hasdbrefs && !(cglobs.cint.CurrentPred->PredFlags & TabledPredFlag)), &cglobs.cint, cglobs.labelno+1); + acode = Yap_assemble(ASSEMBLING_CLAUSE, src, cglobs.cint.CurrentPred, + (cglobs.is_a_fact && !cglobs.hasdbrefs && + !(cglobs.cint.CurrentPred->PredFlags & TabledPredFlag)), + &cglobs.cint, cglobs.labelno + 1); /* check first if there was space for us */ - Yap_ReleaseCMem (&cglobs.cint); + Yap_ReleaseCMem(&cglobs.cint); if (acode == NULL) { return NULL; } else { @@ -3749,6 +3673,5 @@ Yap_cclause(volatile Term inp_clause, Int NOfArgs, Term mod, volatile Term src) } #ifdef BEAM - #include "toeam.c" +#include "toeam.c" #endif - diff --git a/C/dbase.c b/C/dbase.c index 8c944d905..195cf6d72 100644 --- a/C/dbase.c +++ b/C/dbase.c @@ -336,19 +336,18 @@ static int recover_from_record_error(int nargs) { goto recover_record; case RESOURCE_ERROR_HEAP: 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; } goto recover_record; case RESOURCE_ERROR_AUXILIARY_STACK: if (!Yap_ExpandPreAllocCodeSpace(LOCAL_Error_Size, NULL, TRUE)) { - Yap_Error(RESOURCE_ERROR_AUXILIARY_STACK, LOCAL_Error_Term, - LOCAL_ErrorMessage); + Yap_Error(RESOURCE_ERROR_AUXILIARY_STACK, TermNil, LOCAL_ErrorMessage); return FALSE; } goto recover_record; default: - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); + Yap_Error(LOCAL_Error_TYPE, TermNil, LOCAL_ErrorMessage); return FALSE; } recover_record: @@ -1121,7 +1120,6 @@ static void sf_include(SFKeep *sfp, struct db_globs *dbg) SFKeep *sfp; j += 2; } else { LOCAL_Error_TYPE = TYPE_ERROR_DBTERM; - LOCAL_Error_Term = d0; LOCAL_ErrorMessage = "wrong term in SF"; return (NULL); } @@ -1242,7 +1240,6 @@ static DBRef generate_dberror_msg(int errnumb, UInt sz, char *msg) { CACHE_REGS LOCAL_Error_Size = sz; LOCAL_Error_TYPE = errnumb; - LOCAL_Error_Term = TermNil; LOCAL_ErrorMessage = msg; return NULL; } @@ -2611,7 +2608,6 @@ static int resize_int_keys(UInt new_size) { if (new == NULL) { YAPLeaveCriticalSection(); LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; - LOCAL_Error_Term = TermNil; LOCAL_ErrorMessage = "could not allocate space"; return FALSE; } @@ -2693,7 +2689,6 @@ static PredEntry *new_lu_int_key(Int key) { if (INT_LU_KEYS == NULL) { CACHE_REGS LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; - LOCAL_Error_Term = TermNil; LOCAL_ErrorMessage = "could not allocate space"; return NULL; } @@ -2825,7 +2820,6 @@ static DBProp FetchIntDBPropFromKey(Int key, int flag, int new, if (INT_KEYS == NULL) { CACHE_REGS LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; - LOCAL_Error_Term = TermNil; LOCAL_ErrorMessage = "could not allocate space"; return NULL; } diff --git a/C/errors.c b/C/errors.c index dba801a01..3bb7d7752 100755 --- a/C/errors.c +++ b/C/errors.c @@ -74,16 +74,17 @@ bool Yap_Warning(const char *s, ...) { return rc; } void Yap_InitError(yap_error_number e, Term t, const char *msg) { - if (LOCAL_ActiveError.status) { + if (LOCAL_ActiveError->status) { Yap_exit(1); } - LOCAL_ActiveError.errorNo = e; - LOCAL_ActiveError.errorFile = NULL; - LOCAL_ActiveError.errorFunction = NULL; - LOCAL_ActiveError.errorLine = 0; + LOCAL_ActiveError->errorNo = e; + LOCAL_ActiveError->errorFile = NULL; + LOCAL_ActiveError->errorFunction = NULL; + LOCAL_ActiveError->errorLine = 0; if (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 { LOCAL_Error_Size = 0; } @@ -158,7 +159,7 @@ bool Yap_HandleError__(const char *file, const char *function, int lineno, return false; } default: - Yap_Error__(file, function, lineno, err, LOCAL_Error_Term, serr); + Yap_Error__(file, function, lineno, err, TermNil, serr); return false; } } @@ -196,7 +197,7 @@ int Yap_SWIHandleError(const char *s, ...) { return FALSE; } default: - Yap_Error(err, LOCAL_Error_Term, serr); + Yap_Error(err, TermNil, serr); return (FALSE); } } @@ -266,8 +267,8 @@ static char tmpbuf[YAP_BUF_SIZE]; } #define END_ERROR_CLASSES() \ - } \ - return TermNil; \ + } \ + return TermNil; \ } #define BEGIN_ERRORS() \ @@ -292,11 +293,23 @@ static char tmpbuf[YAP_BUF_SIZE]; return mkerrorct(B, ts); #define END_ERRORS() \ - } return TermNil; \ + } \ + return TermNil; \ } #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 * 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 */ if (LOCAL_PrologMode & InErrorMode) { - fprintf(stderr, "%% ERROR WITHIN ERROR %d: %s\n", LOCAL_CurrentError, - tmpbuf); + fprintf(stderr, "%% ERROR WITHIN ERROR %d: %s\n", LOCAL_Error_TYPE, tmpbuf); Yap_RestartYap(1); } - LOCAL_ActiveError.errorNo = type; - LOCAL_ActiveError.errorAsText = Yap_LookupAtom(Yap_errorName( type )); - LOCAL_ActiveError.errorClass = Yap_errorClass( type); - LOCAL_ActiveError.classAsText = Yap_LookupAtom(Yap_errorClassName( LOCAL_ActiveError.errorClass )); - LOCAL_ActiveError.errorLine = lineno; - LOCAL_ActiveError.errorFunction = function; - LOCAL_ActiveError.errorFile = file; + LOCAL_ActiveError->errorNo = type; + LOCAL_ActiveError->errorAsText = Yap_LookupAtom(Yap_errorName(type)); + LOCAL_ActiveError->errorClass = Yap_errorClass(type); + LOCAL_ActiveError->classAsText = + Yap_LookupAtom(Yap_errorClassName(LOCAL_ActiveError->errorClass)); + LOCAL_ActiveError->errorLine = lineno; + LOCAL_ActiveError->errorFunction = function; + LOCAL_ActiveError->errorFile = file; Yap_find_prolog_culprit(PASS_REGS1); LOCAL_PrologMode |= InErrorMode; Yap_ClearExs(); @@ -380,7 +393,7 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno, } if (LOCAL_within_print_message) { /* 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); LOCAL_PrologMode &= ~InErrorMode; Yap_exit(1); @@ -395,8 +408,8 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno, #endif // fprintf(stderr, "warning: "); comment = MkAtomTerm(Yap_LookupAtom(s)); - } else if (LOCAL_ErrorSay && LOCAL_ErrorSay[0]) { - comment = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorSay)); + } else if (LOCAL_ErrorMessage && LOCAL_ErrorMessage[0]) { + comment = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage)); } else { comment = TermNil; } @@ -410,7 +423,6 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno, if (type == ABORT_EVENT || LOCAL_PrologMode & BootMode) { where = TermNil; LOCAL_PrologMode &= ~AbortMode; - LOCAL_CurrentError = type; LOCAL_PrologMode &= ~InErrorMode; /* make sure failure will be seen at next port */ // 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 */ LOCAL_PrologMode &= ~AbortMode; - LOCAL_CurrentError = type; LOCAL_PrologMode |= InErrorMode; if (!(where = Yap_CopyTerm(where))) { 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 */ 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); - LOCAL_ErrorMessage = LOCAL_ErrorSay; } else { - strncpy(LOCAL_ErrorSay, - (char *)RepAtom(NameOfFunctor(FunctorOfTerm(nt[0])))->StrOfAE, - MAX_ERROR_MSG_SIZE); - LOCAL_ErrorMessage = LOCAL_ErrorSay; + LOCAL_ErrorMessage = + (char *)RepAtom(NameOfFunctor(FunctorOfTerm(nt[0])))->StrOfAE; } nt[1] = TermNil; switch (type) { diff --git a/C/eval.c b/C/eval.c index 4f7569f92..72eecf918 100644 --- a/C/eval.c +++ b/C/eval.c @@ -15,23 +15,22 @@ * * *************************************************************************/ #ifdef SCCS -static char SccsId[] = "%W% %G%"; +static char SccsId[] = "%W% %G%"; #endif //! @file eval.c -//! @{ +//! @{ /** @defgroup arithmetic_preds Arithmetic Predicates @ingroup arithmetic */ - - #include "Yap.h" -#include "Yatom.h" + #include "YapHeap.h" +#include "Yatom.h" #include "eval.h" #if HAVE_STDARG_H #include @@ -46,41 +45,39 @@ static char SccsId[] = "%W% %G%"; static Term Eval(Term t1 USES_REGS); -static Term -get_matrix_element(Term t1, Term t2 USES_REGS) -{ +static Term get_matrix_element(Term t1, Term t2 USES_REGS) { if (!IsPairTerm(t2)) { if (t2 == MkAtomTerm(AtomLength)) { Int sz = 1; while (IsApplTerm(t1)) { - Functor f = FunctorOfTerm(t1); - if (NameOfFunctor(f) != AtomNil) { - return MkIntegerTerm(sz); - } - sz *= ArityOfFunctor(f); - t1 = ArgOfTerm(1, t1); + Functor f = FunctorOfTerm(t1); + if (NameOfFunctor(f) != AtomNil) { + return MkIntegerTerm(sz); + } + sz *= ArityOfFunctor(f); + t1 = ArgOfTerm(1, t1); } return MkIntegerTerm(sz); } Yap_ArithError(TYPE_ERROR_EVALUABLE, t2, "X is Y^[A]"); - return FALSE; + return FALSE; } while (IsPairTerm(t2)) { Int indx; Term indxt = Eval(HeadOfTerm(t2) PASS_REGS); if (!IsIntegerTerm(indxt)) { Yap_ArithError(TYPE_ERROR_EVALUABLE, t2, "X is Y^[A]"); - return FALSE; + return FALSE; } indx = IntegerOfTerm(indxt); if (!IsApplTerm(t1)) { Yap_ArithError(TYPE_ERROR_EVALUABLE, t1, "X is Y^[A]"); - return FALSE; + return FALSE; } else { Functor f = FunctorOfTerm(t1); if (ArityOfFunctor(f) < indx) { - Yap_ArithError(TYPE_ERROR_EVALUABLE, t1, "X is Y^[A]"); - return FALSE; + Yap_ArithError(TYPE_ERROR_EVALUABLE, t1, "X is Y^[A]"); + return FALSE; } } t1 = ArgOfTerm(indx, t1); @@ -93,95 +90,90 @@ get_matrix_element(Term t1, Term t2 USES_REGS) return Eval(t1 PASS_REGS); } -static Term -Eval(Term t USES_REGS) -{ +static Term Eval(Term t USES_REGS) { if (IsVarTerm(t)) { - return Yap_ArithError(INSTANTIATION_ERROR,t,"in arithmetic"); + return Yap_ArithError(INSTANTIATION_ERROR, t, "in arithmetic"); } else if (IsNumTerm(t)) { return t; } else if (IsAtomTerm(t)) { ExpEntry *p; - Atom name = AtomOfTerm(t); + Atom name = AtomOfTerm(t); if (EndOfPAEntr(p = RepExpProp(Yap_GetExpProp(name, 0)))) { return Yap_ArithError(TYPE_ERROR_EVALUABLE, takeIndicator(t), - "atom %s in arithmetic expression", - RepAtom(name)->StrOfAE); + "atom %s in arithmetic expression", + RepAtom(name)->StrOfAE); } return Yap_eval_atom(p->FOfEE); } else if (IsApplTerm(t)) { Functor fun = FunctorOfTerm(t); if (fun == FunctorString) { - const char *s = (const char*)StringOfTerm(t); + const char *s = (const char *)StringOfTerm(t); if (s[1] == '\0') - return MkIntegerTerm(s[0]); + return MkIntegerTerm(s[0]); return Yap_ArithError(TYPE_ERROR_EVALUABLE, t, - "string in arithmetic expression"); + "string in arithmetic expression"); } else if ((Atom)fun == AtomFoundVar) { return Yap_ArithError(TYPE_ERROR_EVALUABLE, TermNil, - "cyclic term in arithmetic expression"); + "cyclic term in arithmetic expression"); } else { Int n = ArityOfFunctor(fun); - Atom name = NameOfFunctor(fun); + Atom name = NameOfFunctor(fun); ExpEntry *p; Term t1, t2; - + if (EndOfPAEntr(p = RepExpProp(Yap_GetExpProp(name, n)))) { - return Yap_ArithError(TYPE_ERROR_EVALUABLE, takeIndicator(t), - "functor %s/%d for arithmetic expression", - RepAtom(name)->StrOfAE,n); + return Yap_ArithError(TYPE_ERROR_EVALUABLE, takeIndicator(t), + "functor %s/%d for arithmetic expression", + RepAtom(name)->StrOfAE, n); } if (p->FOfEE == op_power && p->ArityOfEE == 2) { - t2 = ArgOfTerm(2, t); - if (IsPairTerm(t2)) { - return get_matrix_element(ArgOfTerm(1, t), t2 PASS_REGS); - } + t2 = ArgOfTerm(2, t); + if (IsPairTerm(t2)) { + return get_matrix_element(ArgOfTerm(1, t), t2 PASS_REGS); + } } *RepAppl(t) = (CELL)AtomFoundVar; - t1 = Eval(ArgOfTerm(1,t) PASS_REGS); + t1 = Eval(ArgOfTerm(1, t) PASS_REGS); if (t1 == 0L) { - *RepAppl(t) = (CELL)fun; - return FALSE; + *RepAppl(t) = (CELL)fun; + return FALSE; } if (n == 1) { - *RepAppl(t) = (CELL)fun; - return Yap_eval_unary(p->FOfEE, t1); + *RepAppl(t) = (CELL)fun; + return Yap_eval_unary(p->FOfEE, t1); } - t2 = Eval(ArgOfTerm(2,t) PASS_REGS); + t2 = Eval(ArgOfTerm(2, t) PASS_REGS); *RepAppl(t) = (CELL)fun; if (t2 == 0L) - return FALSE; - return Yap_eval_binary(p->FOfEE,t1,t2); + return FALSE; + return Yap_eval_binary(p->FOfEE, t1, t2); } - } /* else if (IsPairTerm(t)) */ { + } /* else if (IsPairTerm(t)) */ + { if (TailOfTerm(t) != TermNil) { 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); } } -Term -Yap_InnerEval__(Term t USES_REGS) -{ - return Eval(t PASS_REGS); -} +Term Yap_InnerEval__(Term t USES_REGS) { return Eval(t PASS_REGS); } #ifdef BEAM Int BEAM_is(void); -Int -BEAM_is(void) -{ /* X is Y */ +Int BEAM_is(void) { /* X is Y */ union arith_ret res; blob_type bt; bt = Eval(Deref(XREGS[2]), &res); - if (bt==db_ref_e) return (NULL); - return (EvalToTerm(bt,&res)); + if (bt == db_ref_e) + return (NULL); + return (EvalToTerm(bt, &res)); } #endif @@ -197,21 +189,20 @@ X is 2+3*4 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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 -static Int -p_is( USES_REGS1 ) -{ /* X is Y */ +static Int p_is(USES_REGS1) { /* X is Y */ Term out; yap_error_number err; Term t = Deref(ARG2); if (IsVarTerm(t)) { - Yap_EvalError(INSTANTIATION_ERROR,t, "X is Y"); - return(FALSE); + Yap_EvalError(INSTANTIATION_ERROR, t, "X is Y"); + return (FALSE); } Yap_ClearExs(); do { @@ -221,15 +212,15 @@ p_is( USES_REGS1 ) if (err == RESOURCE_ERROR_STACK) { LOCAL_Error_TYPE = YAP_NO_ERROR; if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, CP)) { - Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage); - return FALSE; + Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage); + return FALSE; } } else { - Yap_EvalError(err, takeIndicator( ARG2 ), "X is Exp"); + Yap_EvalError(err, takeIndicator(ARG2), "X is Exp"); return FALSE; } } while (TRUE); - return Yap_unify_constant(ARG1,out); + return Yap_unify_constant(ARG1, out); } /** @@ -239,20 +230,18 @@ p_is( USES_REGS1 ) */ /// @memberof isnan/1 -static Int -p_isnan( USES_REGS1 ) -{ /* X isnan Y */ +static Int p_isnan(USES_REGS1) { /* X isnan Y */ Term out = 0L; - + while (!(out = Eval(Deref(ARG1) PASS_REGS))) { if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) { LOCAL_Error_TYPE = YAP_NO_ERROR; if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) { - Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage); - return FALSE; + Yap_EvalError(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage); + return FALSE; } } else { - Yap_EvalError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); + Yap_EvalError(LOCAL_Error_TYPE, ARG1, LOCAL_ErrorMessage); return FALSE; } } @@ -274,9 +263,7 @@ p_isnan( USES_REGS1 ) */ /// @memberof isnan/1 -static Int -p_isinf( USES_REGS1 ) -{ /* X is Y */ +static Int p_isinf(USES_REGS1) { /* X is Y */ Term out = 0L; while (!(out = Eval(Deref(ARG1) PASS_REGS))) { @@ -287,7 +274,7 @@ p_isinf( USES_REGS1 ) return FALSE; } } else { - Yap_EvalError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); + Yap_EvalError(LOCAL_Error_TYPE, ARG1, LOCAL_ErrorMessage); return FALSE; } } @@ -312,14 +299,12 @@ True if _Log1_ is the logarithm of the positive number _A1_, */ /// @memberof logsum/3 -static Int -p_logsum( USES_REGS1 ) -{ /* X is Y */ +static Int p_logsum(USES_REGS1) { /* X is Y */ Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); int done = FALSE; Float f1, f2; - + while (!done) { if (IsFloatTerm(t1)) { f1 = FloatOfTerm(t1); @@ -334,16 +319,16 @@ p_logsum( USES_REGS1 ) #endif } else { while (!(t1 = Eval(t1 PASS_REGS))) { - if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) { - LOCAL_Error_TYPE = YAP_NO_ERROR; - if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) { - Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage); - return FALSE; - } - } else { - Yap_EvalError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - return FALSE; - } + if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) { + LOCAL_Error_TYPE = YAP_NO_ERROR; + if (!Yap_gcl(LOCAL_Error_Size, 1, ENV, CP)) { + Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage); + return FALSE; + } + } else { + Yap_EvalError(LOCAL_Error_TYPE, ARG1, LOCAL_ErrorMessage); + return FALSE; + } } } } @@ -362,88 +347,73 @@ p_logsum( USES_REGS1 ) #endif } else { while (!(t2 = Eval(t2 PASS_REGS))) { - if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) { - LOCAL_Error_TYPE = YAP_NO_ERROR; - if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, CP)) { - Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage); - return FALSE; - } - } else { - Yap_EvalError(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - return FALSE; - } + if (LOCAL_Error_TYPE == RESOURCE_ERROR_STACK) { + LOCAL_Error_TYPE = YAP_NO_ERROR; + if (!Yap_gcl(LOCAL_Error_Size, 2, ENV, CP)) { + Yap_EvalError(RESOURCE_ERROR_STACK, ARG2, LOCAL_ErrorMessage); + return FALSE; + } + } else { + Yap_EvalError(LOCAL_Error_TYPE, ARG1, LOCAL_ErrorMessage); + return FALSE; + } } } } if (f1 >= f2) { - Float fi = exp(f2-f1); - return Yap_unify(ARG3,MkFloatTerm(f1+log(1+fi))); + Float fi = exp(f2 - f1); + return Yap_unify(ARG3, MkFloatTerm(f1 + log(1 + fi))); } else { - Float fi = exp(f1-f2); - return Yap_unify(ARG3,MkFloatTerm(f2+log(1+fi))); + Float fi = exp(f1 - f2); + return Yap_unify(ARG3, MkFloatTerm(f2 + log(1 + fi))); } } - -Int -Yap_ArithError__(const char *file, const char *function, int lineno, yap_error_number type, Term where,...) -{ +Int Yap_ArithError__(const char *file, const char *function, int lineno, + yap_error_number type, Term where, ...) { CACHE_REGS va_list ap; char *format; - - if (LOCAL_ArithError) - return 0L; - LOCAL_ArithError = TRUE; + char buf[MAX_ERROR_MSG_SIZE]; + LOCAL_Error_TYPE = type; LOCAL_Error_File = file; LOCAL_Error_Function = function; LOCAL_Error_Lineno = lineno; - LOCAL_Error_Term = where; - if (!LOCAL_ErrorMessage) - LOCAL_ErrorMessage = LOCAL_ErrorSay; - va_start (ap, where); - format = va_arg( ap, char *); + va_start(ap, where); + format = va_arg(ap, char *); if (format != NULL) { -#if HAVE_VSNPRINTF - (void) vsnprintf(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE, format, ap); +#if HAVE_VSNPRINTF + (void)vsnprintf(buf, MAX_ERROR_MSG_SIZE, format, ap); #else - (void) vsprintf(LOCAL_ErrorMessage, format, ap); + (void)vsprintf(buf, format, ap); #endif } else { - LOCAL_ErrorMessage[0] = '\0'; + buf[0] = '\0'; } - va_end (ap); + va_end(ap); return 0L; } -yamop * -Yap_EvalError__(const char *file, const char *function, int lineno,yap_error_number type, Term where,...) -{ +yamop *Yap_EvalError__(const char *file, const char *function, int lineno, + yap_error_number type, Term where, ...) { CACHE_REGS 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 *); if (format != NULL) { -#if HAVE_VSNPRINTF - (void) vsnprintf(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE, format, ap); +#if HAVE_VSNPRINTF + (void)vsnprintf(buf, MAX_ERROR_MSG_SIZE, format, ap); #else - (void) vsprintf(LOCAL_ErrorMessage, format, ap); + (void)vsprintf(buf, format, ap); #endif } else { - LOCAL_ErrorMessage[0] = '\0'; + buf[0] = '\0'; } - va_end (ap); - return Yap_Error__(file, function, lineno, type, where, LOCAL_ErrorMessage); + va_end(ap); + return Yap_Error__(file, function, lineno, type, where, buf); } /** @@ -461,11 +431,10 @@ Yap_EvalError__(const char *file, const char *function, int lineno,yap_error_num */ /// @memberof between/3 -static Int cont_between( USES_REGS1 ) -{ - Term t1 = EXTRA_CBACK_ARG(3,1); - Term t2 = EXTRA_CBACK_ARG(3,2); - +static Int cont_between(USES_REGS1) { + Term t1 = EXTRA_CBACK_ARG(3, 1); + Term t2 = EXTRA_CBACK_ARG(3, 2); + Yap_unify(ARG3, t1); if (IsIntegerTerm(t1)) { Int i1; @@ -475,7 +444,7 @@ static Int cont_between( USES_REGS1 ) cut_succeed(); i1 = IntegerOfTerm(t1); tn = add_int(i1, 1 PASS_REGS); - EXTRA_CBACK_ARG(3,1) = tn; + EXTRA_CBACK_ARG(3, 1) = tn; HB = B->cp_h = HR; return TRUE; } else { @@ -489,16 +458,14 @@ static Int cont_between( USES_REGS1 ) t[0] = t1; t[1] = MkIntTerm(1); tn = Eval(Yap_MkApplTerm(FunctorPlus, 2, t) PASS_REGS); - EXTRA_CBACK_ARG(3,1) = tn; + EXTRA_CBACK_ARG(3, 1) = tn; HB = B->cp_h = HR; return TRUE; } } /// @memberof between/3 -static Int -init_between( USES_REGS1 ) -{ +static Int init_between(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); @@ -510,14 +477,11 @@ init_between( USES_REGS1 ) Yap_EvalError(INSTANTIATION_ERROR, t1, "between/3"); return FALSE; } - if (!IsIntegerTerm(t1) && - !IsBigIntTerm(t1)) { + if (!IsIntegerTerm(t1) && !IsBigIntTerm(t1)) { Yap_EvalError(TYPE_ERROR_INTEGER, t1, "between/3"); return FALSE; } - if (!IsIntegerTerm(t2) && - !IsBigIntTerm(t2) && - t2 != MkAtomTerm(AtomInf) && + if (!IsIntegerTerm(t2) && !IsBigIntTerm(t2) && t2 != MkAtomTerm(AtomInf) && t2 != MkAtomTerm(AtomInfinity)) { Yap_EvalError(TYPE_ERROR_INTEGER, t2, "between/3"); return FALSE; @@ -530,19 +494,20 @@ init_between( USES_REGS1 ) t3 = Deref(ARG3); if (!IsVarTerm(t3)) { if (!IsIntegerTerm(t3)) { - if (!IsBigIntTerm(t3)) { - Yap_EvalError(TYPE_ERROR_INTEGER, t3, "between/3"); - return FALSE; - } - cut_fail(); + if (!IsBigIntTerm(t3)) { + Yap_EvalError(TYPE_ERROR_INTEGER, t3, "between/3"); + return FALSE; + } + cut_fail(); } else { - Int i3 = IntegerOfTerm(t3); - if (i3 >= i1 && i3 <= i2) - cut_succeed(); - cut_fail(); + Int i3 = IntegerOfTerm(t3); + if (i3 >= i1 && i3 <= i2) + cut_succeed(); + cut_fail(); } } - if (i1 > i2) cut_fail(); + if (i1 > i2) + cut_fail(); if (i1 == i2) { Yap_unify(ARG3, t1); cut_succeed(); @@ -554,16 +519,16 @@ init_between( USES_REGS1 ) t3 = Deref(ARG3); if (!IsVarTerm(t3)) { if (!IsIntegerTerm(t3)) { - if (!IsBigIntTerm(t3)) { - Yap_EvalError(TYPE_ERROR_INTEGER, t3, "between/3"); - return FALSE; - } - cut_fail(); + if (!IsBigIntTerm(t3)) { + Yap_EvalError(TYPE_ERROR_INTEGER, t3, "between/3"); + return FALSE; + } + cut_fail(); } else { - Int i3 = IntegerOfTerm(t3); - if (i3 >= i1) - cut_succeed(); - cut_fail(); + Int i3 = IntegerOfTerm(t3); + if (i3 >= i1) + cut_succeed(); + cut_fail(); } } } else { @@ -572,28 +537,28 @@ init_between( USES_REGS1 ) if (!IsVarTerm(t3)) { if (!IsIntegerTerm(t3) && !IsBigIntTerm(t3)) { - Yap_EvalError(TYPE_ERROR_INTEGER, t3, "between/3"); - return FALSE; + Yap_EvalError(TYPE_ERROR_INTEGER, t3, "between/3"); + return FALSE; } - if (Yap_acmp(t3, t1 PASS_REGS) >= 0 && Yap_acmp(t2,t3 PASS_REGS) >= 0 && P != FAILCODE) - cut_succeed(); + if (Yap_acmp(t3, t1 PASS_REGS) >= 0 && Yap_acmp(t2, t3 PASS_REGS) >= 0 && + P != FAILCODE) + cut_succeed(); cut_fail(); } cmp = Yap_acmp(t1, t2 PASS_REGS); - if (cmp > 0) cut_fail(); + if (cmp > 0) + cut_fail(); if (cmp == 0) { Yap_unify(ARG3, t1); cut_succeed(); } } - EXTRA_CBACK_ARG(3,1) = t1; - EXTRA_CBACK_ARG(3,2) = t2; - return cont_between( PASS_REGS1 ); + EXTRA_CBACK_ARG(3, 1) = t1; + EXTRA_CBACK_ARG(3, 2) = t2; + return cont_between(PASS_REGS1); } -void -Yap_InitEval(void) -{ +void Yap_InitEval(void) { /* here are the arithmetical predicates */ Yap_InitConstExps(); Yap_InitUnaryExps(); diff --git a/C/exec.c b/C/exec.c index 6c88e9560..7869bf728 100755 --- a/C/exec.c +++ b/C/exec.c @@ -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 * 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 * machine */ Yap_set_fpu_exceptions( @@ -2080,16 +2080,16 @@ static Int jump_env(USES_REGS1) { LOCAL_Error_TYPE = ERROR_EVENT; t = ArgOfTerm(1, t); if (IsApplTerm(t) && IsAtomTerm((t2 = ArgOfTerm(1, t)))) { - LOCAL_ActiveError.errorAsText = AtomOfTerm(t2); - LOCAL_ActiveError.classAsText = NameOfFunctor(FunctorOfTerm(t)); + LOCAL_ActiveError->errorAsText = AtomOfTerm(t2); + LOCAL_ActiveError->classAsText = NameOfFunctor(FunctorOfTerm(t)); } else if (IsAtomTerm(t)) { - LOCAL_ActiveError.errorAsText = AtomOfTerm(t); - LOCAL_ActiveError.classAsText = NULL; + LOCAL_ActiveError->errorAsText = AtomOfTerm(t); + LOCAL_ActiveError->classAsText = NULL; } } else { LOCAL_Error_TYPE = THROW_EVENT; } - LOCAL_ActiveError.prologPredName = NULL; + LOCAL_ActiveError->prologPredName = NULL; Yap_PutException(t); bool out = JumpToEnv(PASS_REGS1); if (B != NULL && P == FAILCODE && B->cp_ap == NOCODE && @@ -2225,10 +2225,10 @@ bool Yap_PutException(Term t) { } bool Yap_ResetException(int wid) { - if (REMOTE_BallTerm(wid)) { - Yap_PopTermFromDB(REMOTE_BallTerm(wid)); + if (REMOTE_ActiveError(wid)->errorTerm) { + Yap_PopTermFromDB(REMOTE_ActiveError(wid)->errorTerm); } - REMOTE_BallTerm(wid) = NULL; + REMOTE_ActiveError(wid)->errorTerm = NULL; return true; } diff --git a/C/flags.c b/C/flags.c index 4b850c0d9..d185a38ae 100644 --- a/C/flags.c +++ b/C/flags.c @@ -1369,7 +1369,7 @@ do_prolog_flag_property(Term tflag, args = Yap_ArgList2ToVector(opts, prolog_flag_property_defs, PROLOG_FLAG_PROPERTY_END); if (args == NULL) { - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, opts, NULL); return false; } if (!IsAtomTerm(tflag)) { @@ -1533,7 +1533,7 @@ static Int do_create_prolog_flag(USES_REGS1) { args = Yap_ArgList2ToVector(opts, prolog_flag_property_defs, PROLOG_FLAG_PROPERTY_END); if (args == NULL) { - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, opts, NULL); return false; } fv = GetFlagProp(AtomOfTerm(tflag)); diff --git a/C/load_dl.c b/C/load_dl.c index d0ad81787..0a437d589 100755 --- a/C/load_dl.c +++ b/C/load_dl.c @@ -127,7 +127,8 @@ void *Yap_LoadForeignFile(char *file, int flags) { if (out == NULL) { const char *m_os = dlerror(); 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 { LOCAL_ErrorMessage = "dlopen failed"; } @@ -177,7 +178,8 @@ static Int LoadForeign(StringList ofiles, StringList libs, char *proc_name, NULL) #endif { - strcpy(LOCAL_ErrorSay, dlerror()); + LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE); + strcpy(LOCAL_ErrorMessage, dlerror()); return LOAD_FAILLED; } 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 */ const char *file = AtomName(ofiles->name); 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"); return LOAD_FAILLED; } @@ -217,7 +220,7 @@ static Int LoadForeign(StringList ofiles, StringList libs, char *proc_name, } if (!*init_proc) { - strcpy(LOCAL_ErrorSay, "Could not locate initialization routine"); + LOCAL_ErrorMessage = "Could not locate initialization routine"; return LOAD_FAILLED; } diff --git a/C/load_foreign.c b/C/load_foreign.c index 472d65e76..a1dd5fea7 100644 --- a/C/load_foreign.c +++ b/C/load_foreign.c @@ -140,7 +140,8 @@ p_open_shared_object( USES_REGS1 ) { s = (char *)RepAtom(AtomOfTerm(t))->StrOfAE; 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; } else { return Yap_unify(MkIntegerTerm((Int)handle),ARG3); diff --git a/C/parser.c b/C/parser.c index b2ccbdc8b..82c35294e 100755 --- a/C/parser.c +++ b/C/parser.c @@ -175,11 +175,10 @@ static void syntax_msg(const char *msg, ...) { va_list ap; if (LOCAL_toktide == LOCAL_tokptr) { - char out[YAP_FILENAME_MAX]; + LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE+1); va_start(ap, msg); - vsnprintf(out, YAP_FILENAME_MAX - 1, msg, ap); - LOCAL_Error_Term = MkStringTerm( out ); - LOCAL_Error_TYPE = SYNTAX_ERROR; + vsnprintf(LOCAL_ErrorMessage, YAP_FILENAME_MAX , msg, ap); + LOCAL_Error_TYPE = SYNTAX_ERROR; va_end(ap); } } diff --git a/C/prim_absmi_insts.h b/C/prim_absmi_insts.h index 419bb48cf..00358ba10 100644 --- a/C/prim_absmi_insts.h +++ b/C/prim_absmi_insts.h @@ -8,7 +8,6 @@ { #endif /* INDENT_CODE */ - Op(p_plus_vv, xxx); BEGD(d0); BEGD(d1); @@ -23,17 +22,10 @@ /* d0 and d1 are where I want them */ if (IsIntTerm(d0) && IsIntTerm(d1)) { d0 = MkIntegerTerm(IntOfTerm(d0) + IntOfTerm(d1)); - } - else { + } else { saveregs(); d0 = p_plus(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } } XREG(PREG->y_u.xxx.x) = d0; PREG = NEXTOP(PREG, xxx); @@ -41,17 +33,13 @@ BEGP(pt0); deref_body(d0, pt0, plus_vv_unk, plus_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is _+B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, plus_vv_nvar_unk, plus_vv_nvar_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A+B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d1); @@ -63,33 +51,23 @@ d0 = XREG(PREG->y_u.xxn.xi); /* first check pt1 */ deref_head(d0, plus_vc_unk); - plus_vc_nvar: - { - Int d1 = PREG->y_u.xxn.c; - if (IsIntTerm(d0)) { - d0 = MkIntegerTerm(IntOfTerm(d0) + d1); - } - else { - saveregs(); - d0 = p_plus(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); - setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } - } + plus_vc_nvar : { + Int d1 = PREG->y_u.xxn.c; + if (IsIntTerm(d0)) { + d0 = MkIntegerTerm(IntOfTerm(d0) + d1); + } else { + saveregs(); + d0 = p_plus(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); + setregs(); } + } XREG(PREG->y_u.xxn.x) = d0; PREG = NEXTOP(PREG, xxn); GONext(); BEGP(pt0); deref_body(d0, pt0, plus_vc_unk, plus_vc_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A + " Int_FORMAT, PREG->y_u.xxn.c); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); @@ -109,38 +87,27 @@ /* d0 and d1 are where I want them */ if (IsIntTerm(d0) && IsIntTerm(d1)) { d0 = MkIntegerTerm(IntOfTerm(d0) + IntOfTerm(d1)); - } - else { + } else { saveregs(); d0 = p_plus(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } } BEGP(pt0); pt0 = YREG + PREG->y_u.yxx.y; PREG = NEXTOP(PREG, yxx); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, plus_y_vv_unk, plus_y_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A+B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, plus_y_vv_nvar_unk, plus_y_vv_nvar_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A+B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d1); @@ -152,36 +119,26 @@ d0 = XREG(PREG->y_u.yxn.xi); /* first check pt1 */ deref_head(d0, plus_y_vc_unk); - plus_y_vc_nvar: - { - Int d1 = PREG->y_u.yxn.c; - if (IsIntTerm(d0)) { - d0 = MkIntegerTerm(IntOfTerm(d0) + d1); - } - else { - saveregs(); - d0 = p_plus(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); - setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } - } + plus_y_vc_nvar : { + Int d1 = PREG->y_u.yxn.c; + if (IsIntTerm(d0)) { + d0 = MkIntegerTerm(IntOfTerm(d0) + d1); + } else { + saveregs(); + d0 = p_plus(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); + setregs(); } + } BEGP(pt0); pt0 = YREG + PREG->y_u.yxn.y; PREG = NEXTOP(PREG, yxn); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, plus_y_vc_unk, plus_y_vc_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A + " Int_FORMAT, PREG->y_u.yxn.c); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); @@ -201,17 +158,10 @@ /* d0 and d1 are where I want them */ if (IsIntTerm(d0) && IsIntTerm(d1)) { d0 = MkIntegerTerm(IntOfTerm(d0) - IntOfTerm(d1)); - } - else { + } else { saveregs(); d0 = p_minus(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } } XREG(PREG->y_u.xxx.x) = d0; PREG = NEXTOP(PREG, xxx); @@ -219,17 +169,13 @@ BEGP(pt0); deref_body(d0, pt0, minus_vv_unk, minus_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A-B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, minus_vv_nvar_unk, minus_vv_nvar_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A-B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d1); @@ -241,33 +187,23 @@ d0 = XREG(PREG->y_u.xxn.xi); /* first check pt1 */ deref_head(d0, minus_cv_unk); - minus_cv_nvar: - { - Int d1 = PREG->y_u.xxn.c; - if (IsIntTerm(d0)) { - d0 = MkIntegerTerm(d1 - IntOfTerm(d0)); - } - else { - saveregs(); - d0 = p_minus(MkIntegerTerm(d1),Yap_Eval(d0) PASS_REGS); - setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } - } + minus_cv_nvar : { + Int d1 = PREG->y_u.xxn.c; + if (IsIntTerm(d0)) { + d0 = MkIntegerTerm(d1 - IntOfTerm(d0)); + } else { + saveregs(); + d0 = p_minus(MkIntegerTerm(d1), Yap_Eval(d0) PASS_REGS); + setregs(); } + } XREG(PREG->y_u.xxn.x) = d0; PREG = NEXTOP(PREG, xxn); GONext(); BEGP(pt0); deref_body(d0, pt0, minus_cv_unk, minus_cv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is " Int_FORMAT "-A", PREG->y_u.xxn.c); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); @@ -287,38 +223,27 @@ /* d0 and d1 are where I want them */ if (IsIntTerm(d0) && IsIntTerm(d1)) { d0 = MkIntegerTerm(IntOfTerm(d0) - IntOfTerm(d1)); - } - else { + } else { saveregs(); d0 = p_minus(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } } BEGP(pt0); pt0 = YREG + PREG->y_u.yxx.y; PREG = NEXTOP(PREG, yxx); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, minus_y_vv_unk, minus_y_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A-B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, minus_y_vv_nvar_unk, minus_y_vv_nvar_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A-B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d1); @@ -330,36 +255,26 @@ d0 = XREG(PREG->y_u.yxn.xi); /* first check pt1 */ deref_head(d0, minus_y_cv_unk); - minus_y_cv_nvar: - { - Int d1 = PREG->y_u.yxn.c; - if (IsIntTerm(d0)) { - d0 = MkIntegerTerm(d1 - IntOfTerm(d0)); - } - else { - saveregs(); - d0 = p_minus(MkIntegerTerm(d1), Yap_Eval(d0) PASS_REGS); - setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } - } + minus_y_cv_nvar : { + Int d1 = PREG->y_u.yxn.c; + if (IsIntTerm(d0)) { + d0 = MkIntegerTerm(d1 - IntOfTerm(d0)); + } else { + saveregs(); + d0 = p_minus(MkIntegerTerm(d1), Yap_Eval(d0) PASS_REGS); + setregs(); } + } BEGP(pt0); pt0 = YREG + PREG->y_u.yxn.y; PREG = NEXTOP(PREG, yxn); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, minus_y_cv_unk, minus_y_cv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is " Int_FORMAT "-A", PREG->y_u.yxn.c); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); @@ -379,17 +294,9 @@ /* d0 and d1 are where I want them */ if (IsIntTerm(d0) && IsIntTerm(d1)) { d0 = times_int(IntOfTerm(d0), IntOfTerm(d1) PASS_REGS); - } - else { + } else { saveregs(); d0 = p_times(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); - setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } } XREG(PREG->y_u.xxx.x) = d0; PREG = NEXTOP(PREG, xxx); @@ -397,17 +304,13 @@ BEGP(pt0); deref_body(d0, pt0, times_vv_unk, times_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A*B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, times_vv_nvar_unk, times_vv_nvar_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A*B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d1); @@ -419,33 +322,23 @@ d0 = XREG(PREG->y_u.xxn.xi); /* first check pt1 */ deref_head(d0, times_vc_unk); - times_vc_nvar: - { - Int d1 = PREG->y_u.xxn.c; - if (IsIntTerm(d0)) { - d0 = times_int(IntOfTerm(d0), d1 PASS_REGS); - } - else { - saveregs(); - d0 = p_times(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); - setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } - } + times_vc_nvar : { + Int d1 = PREG->y_u.xxn.c; + if (IsIntTerm(d0)) { + d0 = times_int(IntOfTerm(d0), d1 PASS_REGS); + } else { + saveregs(); + d0 = p_times(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); + setregs(); } + } XREG(PREG->y_u.xxn.x) = d0; PREG = NEXTOP(PREG, xxn); GONext(); BEGP(pt0); deref_body(d0, pt0, times_vc_unk, times_vc_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A* " Int_FORMAT, PREG->y_u.xxn.c); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); @@ -465,38 +358,27 @@ /* d0 and d1 are where I want them */ if (IsIntTerm(d0) && IsIntTerm(d1)) { d0 = times_int(IntOfTerm(d0), IntOfTerm(d1) PASS_REGS); - } - else { + } else { saveregs(); d0 = p_times(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } } BEGP(pt0); pt0 = YREG + PREG->y_u.yxx.y; PREG = NEXTOP(PREG, yxx); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, times_y_vv_unk, times_y_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A*B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, times_y_vv_nvar_unk, times_y_vv_nvar_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A*B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d1); @@ -508,36 +390,26 @@ d0 = XREG(PREG->y_u.yxn.xi); /* first check pt1 */ deref_head(d0, times_y_vc_unk); - times_y_vc_nvar: - { - Int d1 = PREG->y_u.yxn.c; - if (IsIntTerm(d0)) { - d0 = times_int(IntOfTerm(d0), d1 PASS_REGS); - } - else { - saveregs(); - d0 = p_times(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); - setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } - } + times_y_vc_nvar : { + Int d1 = PREG->y_u.yxn.c; + if (IsIntTerm(d0)) { + d0 = times_int(IntOfTerm(d0), d1 PASS_REGS); + } else { + saveregs(); + d0 = p_times(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); + setregs(); } + } BEGP(pt0); pt0 = YREG + PREG->y_u.yxn.y; PREG = NEXTOP(PREG, yxn); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, times_y_vc_unk, times_y_vc_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A* " Int_FORMAT, PREG->y_u.yxn.c); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); @@ -558,23 +430,13 @@ if (IsIntTerm(d0) && IsIntTerm(d1)) { Int div = IntOfTerm(d1); if (div == 0) { - saveregs(); - Yap_NilError(EVALUATION_ERROR_ZERO_DIVISOR,"// /2"); - setregs(); - FAIL(); + Yap_AsmError(EVALUATION_ERROR_ZERO_DIVISOR); } d0 = MkIntTerm(IntOfTerm(d0) / div); - } - else { + } else { saveregs(); d0 = p_div(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } } XREG(PREG->y_u.xxx.x) = d0; PREG = NEXTOP(PREG, xxx); @@ -582,17 +444,13 @@ BEGP(pt0); deref_body(d0, pt0, div_vv_unk, div_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A//B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, div_vv_nvar_unk, div_vv_nvar_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A//B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d1); @@ -604,33 +462,23 @@ d0 = XREG(PREG->y_u.xxn.xi); /* first check pt1 */ deref_head(d0, div_vc_unk); - div_vc_nvar: - { - Int d1 = PREG->y_u.xxn.c; - if (IsIntTerm(d0)) { - d0 = MkIntTerm(IntOfTerm(d0) / d1); - } - else { - saveregs(); - d0 = p_div(Yap_Eval(d0),MkIntegerTerm(d1) PASS_REGS); - setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } - } + div_vc_nvar : { + Int d1 = PREG->y_u.xxn.c; + if (IsIntTerm(d0)) { + d0 = MkIntTerm(IntOfTerm(d0) / d1); + } else { + saveregs(); + d0 = p_div(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); + setregs(); } + } XREG(PREG->y_u.xxn.x) = d0; PREG = NEXTOP(PREG, xxn); GONext(); BEGP(pt0); deref_body(d0, pt0, div_vc_unk, div_vc_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A//B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); @@ -641,39 +489,27 @@ d0 = XREG(PREG->y_u.xxn.xi); /* first check pt1 */ deref_head(d0, div_cv_unk); - div_cv_nvar: - { - Int d1 = PREG->y_u.xxn.c; - if (IsIntTerm(d0)) { - Int div = IntOfTerm(d0); - if (div == 0){ - saveregs(); - Yap_NilError(EVALUATION_ERROR_ZERO_DIVISOR,"// /2"); - setregs(); - FAIL(); - } - d0 = MkIntegerTerm(d1 / div); - } - else { - saveregs(); - d0 = p_div(MkIntegerTerm(d1),Yap_Eval(d0) PASS_REGS); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } + div_cv_nvar : { + Int d1 = PREG->y_u.xxn.c; + if (IsIntTerm(d0)) { + Int div = IntOfTerm(d0); + if (div == 0) { + Yap_AsmError(EVALUATION_ERROR_ZERO_DIVISOR); + FAIL(); } + d0 = MkIntegerTerm(d1 / div); + } else { + saveregs(); + d0 = p_div(MkIntegerTerm(d1), Yap_Eval(d0) PASS_REGS); } + } XREG(PREG->y_u.xxn.x) = d0; PREG = NEXTOP(PREG, xxn); GONext(); BEGP(pt0); deref_body(d0, pt0, div_cv_unk, div_cv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is " Int_FORMAT "// A", PREG->y_u.xxn.c); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); @@ -694,44 +530,31 @@ if (IsIntTerm(d0) && IsIntTerm(d1)) { Int div = IntOfTerm(d1); if (div == 0) { - saveregs(); - Yap_NilError(EVALUATION_ERROR_ZERO_DIVISOR,"// /2"); - setregs(); + Yap_AsmError(EVALUATION_ERROR_ZERO_DIVISOR); FAIL(); } d0 = MkIntTerm(IntOfTerm(d0) / div); - } - else { + } else { saveregs(); d0 = p_div(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } } BEGP(pt0); pt0 = YREG + PREG->y_u.yxx.y; PREG = NEXTOP(PREG, yxx); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, div_y_vv_unk, div_y_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A//B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, div_y_vv_nvar_unk, div_y_vv_nvar_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A//B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d1); @@ -743,36 +566,26 @@ d0 = XREG(PREG->y_u.yxn.xi); /* first check pt1 */ deref_head(d0, div_y_vc_unk); - div_y_vc_nvar: - { - Int d1 = PREG->y_u.yxn.c; - if (IsIntTerm(d0)) { - d0 = MkIntTerm(IntOfTerm(d0)/d1); - } - else { - saveregs(); - d0 = p_div(Yap_Eval(d0),MkIntegerTerm(d1) PASS_REGS); - setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } - } + div_y_vc_nvar : { + Int d1 = PREG->y_u.yxn.c; + if (IsIntTerm(d0)) { + d0 = MkIntTerm(IntOfTerm(d0) / d1); + } else { + saveregs(); + d0 = p_div(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); + setregs(); } + } BEGP(pt0); pt0 = YREG + PREG->y_u.yxn.y; PREG = NEXTOP(PREG, yxn); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, div_y_vc_unk, div_y_vc_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A//B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); @@ -783,49 +596,36 @@ d0 = XREG(PREG->y_u.yxn.xi); /* first check pt1 */ deref_head(d0, div_y_cv_unk); - div_y_cv_nvar: - { - Int d1 = PREG->y_u.yxn.c; - if (IsIntTerm(d0)) { - Int div = IntOfTerm(d0); - if (div == 0) { - saveregs(); - Yap_NilError(EVALUATION_ERROR_ZERO_DIVISOR,"// /2"); - setregs(); - FAIL(); - } - d0 = MkIntegerTerm(d1 / div); - } - else { - saveregs(); - d0 = p_div(MkIntegerTerm(d1), Yap_Eval(d0) PASS_REGS); - setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } + div_y_cv_nvar : { + Int d1 = PREG->y_u.yxn.c; + if (IsIntTerm(d0)) { + Int div = IntOfTerm(d0); + if (div == 0) { + Yap_AsmError(EVALUATION_ERROR_ZERO_DIVISOR); + FAIL(); } + d0 = MkIntegerTerm(d1 / div); + } else { + saveregs(); + d0 = p_div(MkIntegerTerm(d1), Yap_Eval(d0) PASS_REGS); + setregs(); } + } BEGP(pt0); pt0 = YREG + PREG->y_u.yxn.y; PREG = NEXTOP(PREG, yxn); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, div_y_cv_unk, div_y_cv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is " Int_FORMAT "// A", PREG->y_u.yxn.c); - setregs(); + Yap_AbsmiError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); ENDOp(); - Op(p_and_vv, xxx); BEGD(d0); BEGD(d1); @@ -840,17 +640,10 @@ /* d0 and d1 are where I want them */ if (IsIntTerm(d0) && IsIntTerm(d1)) { d0 = MkIntegerTerm(IntOfTerm(d0) & IntOfTerm(d1)); - } - else { + } else { saveregs(); d0 = p_and(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } } XREG(PREG->y_u.xxx.x) = d0; PREG = NEXTOP(PREG, xxx); @@ -858,17 +651,13 @@ BEGP(pt0); deref_body(d0, pt0, and_vv_unk, and_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A/\\B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, and_vv_nvar_unk, and_vv_nvar_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A/\\B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d1); @@ -880,33 +669,23 @@ d0 = XREG(PREG->y_u.xxn.xi); /* first check pt1 */ deref_head(d0, and_vc_unk); - and_vc_nvar: - { - Int d1 = PREG->y_u.xxn.c; - if (IsIntTerm(d0)) { - d0 = MkIntegerTerm(IntOfTerm(d0) & d1); - } - else { - saveregs(); - d0 = p_and(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); - setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } - } + and_vc_nvar : { + Int d1 = PREG->y_u.xxn.c; + if (IsIntTerm(d0)) { + d0 = MkIntegerTerm(IntOfTerm(d0) & d1); + } else { + saveregs(); + d0 = p_and(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); + setregs(); } + } XREG(PREG->y_u.xxn.x) = d0; PREG = NEXTOP(PREG, xxn); GONext(); BEGP(pt0); deref_body(d0, pt0, and_vc_unk, and_vc_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A /\\ " Int_FORMAT , PREG->y_u.xxn.c); - setregs(); + Yap_AbsmiError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); @@ -926,38 +705,27 @@ /* d0 and d1 are where I want them */ if (IsIntTerm(d0) && IsIntTerm(d1)) { d0 = MkIntegerTerm(IntOfTerm(d0) & IntOfTerm(d1)); - } - else { + } else { saveregs(); d0 = p_and(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } } BEGP(pt0); pt0 = YREG + PREG->y_u.yxx.y; PREG = NEXTOP(PREG, yxx); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, and_y_vv_unk, and_y_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A/\\B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, and_y_vv_nvar_unk, and_y_vv_nvar_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A/\\B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d1); @@ -969,42 +737,31 @@ d0 = XREG(PREG->y_u.yxn.xi); /* first check pt1 */ deref_head(d0, and_y_vc_unk); - and_y_vc_nvar: - { - Int d1 = PREG->y_u.yxn.c; - if (IsIntTerm(d0)) { - d0 = MkIntegerTerm(IntOfTerm(d0) & d1); - } - else { - saveregs(); - d0 = p_and(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); - setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } - } + and_y_vc_nvar : { + Int d1 = PREG->y_u.yxn.c; + if (IsIntTerm(d0)) { + d0 = MkIntegerTerm(IntOfTerm(d0) & d1); + } else { + saveregs(); + d0 = p_and(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); + setregs(); } + } BEGP(pt0); pt0 = YREG + PREG->y_u.yxn.y; PREG = NEXTOP(PREG, yxn); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, and_y_vc_unk, and_y_vc_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A /\\ " Int_FORMAT , PREG->y_u.yxn.c); - setregs(); + Yap_AbsmiError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); ENDOp(); - Op(p_or_vv, xxx); BEGD(d0); BEGD(d1); @@ -1019,17 +776,10 @@ /* d0 and d1 are where I want them */ if (IsIntTerm(d0) && IsIntTerm(d1)) { d0 = MkIntegerTerm(IntOfTerm(d0) | IntOfTerm(d1)); - } - else { + } else { saveregs(); d0 = p_or(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } } XREG(PREG->y_u.xxx.x) = d0; PREG = NEXTOP(PREG, xxx); @@ -1037,17 +787,13 @@ BEGP(pt0); deref_body(d0, pt0, or_vv_unk, or_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A\\/B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, or_vv_nvar_unk, or_vv_nvar_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A\\/B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d1); @@ -1059,32 +805,22 @@ d0 = XREG(PREG->y_u.xxn.xi); /* first check pt1 */ deref_head(d0, or_vc_unk); - or_vc_nvar: - { - Int d1 = PREG->y_u.xxn.c; - if (IsIntTerm(d0)) { - d0 = MkIntegerTerm(IntOfTerm(d0) | d1); - } - else { - saveregs(); - d0 = p_or(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } - } + or_vc_nvar : { + Int d1 = PREG->y_u.xxn.c; + if (IsIntTerm(d0)) { + d0 = MkIntegerTerm(IntOfTerm(d0) | d1); + } else { + saveregs(); + d0 = p_or(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); } + } XREG(PREG->y_u.xxn.x) = d0; PREG = NEXTOP(PREG, xxn); GONext(); BEGP(pt0); deref_body(d0, pt0, or_vc_unk, or_vc_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A \\/ " Int_FORMAT , PREG->y_u.xxn.c); - setregs(); + Yap_AbsmiError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); @@ -1104,38 +840,27 @@ /* d0 and d1 are where I want them */ if (IsIntTerm(d0) && IsIntTerm(d1)) { d0 = MkIntegerTerm(IntOfTerm(d0) | IntOfTerm(d1)); - } - else { + } else { saveregs(); d0 = p_or(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } } BEGP(pt0); pt0 = YREG + PREG->y_u.yxx.y; PREG = NEXTOP(PREG, yxx); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, or_y_vv_unk, or_y_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A\\/B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, or_y_vv_nvar_unk, or_y_vv_nvar_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A\\/B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d1); @@ -1147,36 +872,26 @@ d0 = XREG(PREG->y_u.yxn.xi); /* first check pt1 */ deref_head(d0, or_y_vc_unk); - or_y_vc_nvar: - { - Int d1 = PREG->y_u.yxn.c; - if (IsIntTerm(d0)) { - d0 = MkIntegerTerm(IntOfTerm(d0) | d1); - } - else { - saveregs(); - d0 = p_or(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); - setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } - } + or_y_vc_nvar : { + Int d1 = PREG->y_u.yxn.c; + if (IsIntTerm(d0)) { + d0 = MkIntegerTerm(IntOfTerm(d0) | d1); + } else { + saveregs(); + d0 = p_or(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); + setregs(); } + } BEGP(pt0); pt0 = YREG + PREG->y_u.yxn.y; PREG = NEXTOP(PREG, yxn); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, or_y_vc_unk, or_y_vc_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A \\/ " Int_FORMAT , PREG->y_u.yxn.c); - setregs(); + Yap_AbsmiError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); @@ -1199,36 +914,25 @@ if (i2 < 0) d0 = MkIntegerTerm(SLR(IntOfTerm(d0), -i2)); else - d0 = do_sll(IntOfTerm(d0),i2 PASS_REGS); - } - else { + d0 = do_sll(IntOfTerm(d0), i2 PASS_REGS); + } else { saveregs(); d0 = p_sll(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); setregs(); } - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } XREG(PREG->y_u.xxx.x) = d0; PREG = NEXTOP(PREG, xxx); GONext(); BEGP(pt0); deref_body(d0, pt0, sll_vv_unk, sll_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A<y_u.xxn.xi); /* first check pt1 */ deref_head(d0, sll_vc_unk); - sll_vc_nvar: - { - Int d1 = PREG->y_u.xxn.c; - if (IsIntTerm(d0)) { - d0 = do_sll(IntOfTerm(d0), (Int)d1 PASS_REGS); - } - else { - saveregs(); - d0 = p_sll(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); - setregs(); - } - } - if (d0 == 0L) { + sll_vc_nvar : { + Int d1 = PREG->y_u.xxn.c; + if (IsIntTerm(d0)) { + d0 = do_sll(IntOfTerm(d0), (Int)d1 PASS_REGS); + } else { saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); + d0 = p_sll(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); setregs(); - FAIL(); } + } XREG(PREG->y_u.xxn.x) = d0; PREG = NEXTOP(PREG, xxn); GONext(); BEGP(pt0); deref_body(d0, pt0, sll_vc_unk, sll_vc_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A<y_u.xxn.xi); /* first check pt1 */ deref_head(d0, sll_cv_unk); - sll_cv_nvar: - { - Int d1 = PREG->y_u.xxn.c; - if (IsIntTerm(d0)) { - Int i2 = IntOfTerm(d0); - if (i2 < 0) - d0 = MkIntegerTerm(SLR(d1, -i2)); - else - d0 = do_sll(d1,i2 PASS_REGS); - } - else { - saveregs(); - d0 = p_sll(MkIntegerTerm(d1), Yap_Eval(d0) PASS_REGS); - setregs(); - } - } - if (d0 == 0L) { + sll_cv_nvar : { + Int d1 = PREG->y_u.xxn.c; + if (IsIntTerm(d0)) { + Int i2 = IntOfTerm(d0); + if (i2 < 0) + d0 = MkIntegerTerm(SLR(d1, -i2)); + else + d0 = do_sll(d1, i2 PASS_REGS); + } else { saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); + d0 = p_sll(MkIntegerTerm(d1), Yap_Eval(d0) PASS_REGS); setregs(); - FAIL(); } + } XREG(PREG->y_u.xxn.x) = d0; PREG = NEXTOP(PREG, xxn); GONext(); BEGP(pt0); deref_body(d0, pt0, sll_cv_unk, sll_cv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A<y_u.yxx.y; PREG = NEXTOP(PREG, yxx); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, sll_y_vv_unk, sll_y_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A<y_u.yxn.xi); /* first check pt1 */ deref_head(d0, sll_y_vc_unk); - sll_y_vc_nvar: - { - Int d1 = PREG->y_u.yxn.c; - if (IsIntTerm(d0)) { - d0 = do_sll(IntOfTerm(d0), Yap_Eval(d1) PASS_REGS); - } - else { - saveregs(); - d0 = p_sll(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); - setregs(); - } - } - if (d0 == 0L) { + sll_y_vc_nvar : { + Int d1 = PREG->y_u.yxn.c; + if (IsIntTerm(d0)) { + d0 = do_sll(IntOfTerm(d0), Yap_Eval(d1) PASS_REGS); + } else { saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); + d0 = p_sll(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); setregs(); - FAIL(); } + } BEGP(pt0); pt0 = YREG + PREG->y_u.yxn.y; PREG = NEXTOP(PREG, yxn); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, sll_y_vc_unk, sll_y_vc_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A<y_u.yxn.xi); /* first check pt1 */ deref_head(d0, sll_y_cv_unk); - sll_y_cv_nvar: - { - Int d1 = PREG->y_u.yxn.c; - if (IsIntTerm(d0)) { - Int i2 = IntOfTerm(d0); - if (i2 < 0) - d0 = MkIntegerTerm(SLR(d1, -i2)); - else - d0 = do_sll(d1,i2 PASS_REGS); - } - else { - saveregs(); - d0 = p_sll(MkIntegerTerm(d1), Yap_Eval(0) PASS_REGS); - setregs(); - } - } - if (d0 == 0L) { + sll_y_cv_nvar : { + Int d1 = PREG->y_u.yxn.c; + if (IsIntTerm(d0)) { + Int i2 = IntOfTerm(d0); + if (i2 < 0) + d0 = MkIntegerTerm(SLR(d1, -i2)); + else + d0 = do_sll(d1, i2 PASS_REGS); + } else { saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); + d0 = p_sll(MkIntegerTerm(d1), Yap_Eval(0) PASS_REGS); setregs(); - FAIL(); } + } BEGP(pt0); pt0 = YREG + PREG->y_u.yxn.y; PREG = NEXTOP(PREG, yxn); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, sll_y_cv_unk, sll_y_cv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A<y_u.xxx.x) = d0; PREG = NEXTOP(PREG, xxx); GONext(); BEGP(pt0); deref_body(d0, pt0, slr_vv_unk, slr_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A>>B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, slr_vv_nvar_unk, slr_vv_nvar_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A>>B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d1); @@ -1512,33 +1153,23 @@ d0 = XREG(PREG->y_u.xxn.xi); /* first check pt1 */ deref_head(d0, slr_vc_unk); - slr_vc_nvar: - { - Int d1 = PREG->y_u.xxn.c; - if (IsIntTerm(d0)) { - d0 = MkIntTerm(SLR(IntOfTerm(d0), d1)); - } - else { - saveregs(); - d0 = p_slr(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); - setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } - } + slr_vc_nvar : { + Int d1 = PREG->y_u.xxn.c; + if (IsIntTerm(d0)) { + d0 = MkIntTerm(SLR(IntOfTerm(d0), d1)); + } else { + saveregs(); + d0 = p_slr(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); + setregs(); } + } XREG(PREG->y_u.xxn.x) = d0; PREG = NEXTOP(PREG, xxn); GONext(); BEGP(pt0); deref_body(d0, pt0, slr_vc_unk, slr_vc_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A>>B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); @@ -1549,37 +1180,27 @@ d0 = XREG(PREG->y_u.xxn.xi); /* first check pt1 */ deref_head(d0, slr_cv_unk); - slr_cv_nvar: - { - Int d1 = PREG->y_u.xxn.c; - if (IsIntTerm(d0)) { - Int i2 = IntOfTerm(d0); - if (i2 < 0) - d0 = do_sll(d1, -i2 PASS_REGS); - else - d0 = MkIntegerTerm(SLR(d1, i2)); - } - else { - saveregs(); - d0 = p_slr(MkIntegerTerm(d1), Yap_Eval(d0) PASS_REGS); - setregs(); - } - } - if (d0 == 0L) { + slr_cv_nvar : { + Int d1 = PREG->y_u.xxn.c; + if (IsIntTerm(d0)) { + Int i2 = IntOfTerm(d0); + if (i2 < 0) + d0 = do_sll(d1, -i2 PASS_REGS); + else + d0 = MkIntegerTerm(SLR(d1, i2)); + } else { saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); + d0 = p_slr(MkIntegerTerm(d1), Yap_Eval(d0) PASS_REGS); setregs(); - FAIL(); } + } XREG(PREG->y_u.xxn.x) = d0; PREG = NEXTOP(PREG, xxn); GONext(); BEGP(pt0); deref_body(d0, pt0, slr_cv_unk, slr_cv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A>>B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); @@ -1603,38 +1224,27 @@ d0 = do_sll(IntOfTerm(d0), -i2 PASS_REGS); else d0 = MkIntTerm(SLR(IntOfTerm(d0), i2)); - } - else { + } else { saveregs(); d0 = p_slr(Yap_Eval(d0), Yap_Eval(d1) PASS_REGS); setregs(); } BEGP(pt0); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } pt0 = YREG + PREG->y_u.yxx.y; PREG = NEXTOP(PREG, yxx); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, slr_y_vv_unk, slr_y_vv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A>>B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, slr_y_vv_nvar_unk, slr_y_vv_nvar_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A>>B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d1); @@ -1646,36 +1256,26 @@ d0 = XREG(PREG->y_u.yxn.xi); /* first check pt1 */ deref_head(d0, slr_y_vc_unk); - slr_y_vc_nvar: - { - Int d1 = PREG->y_u.yxn.c; - if (IsIntTerm(d0)) { - d0 = MkIntTerm(SLR(IntOfTerm(d0), d1)); - } - else { - saveregs(); - d0 = p_slr(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); - setregs(); - if (d0 == 0L) { - saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); - setregs(); - FAIL(); - } - } + slr_y_vc_nvar : { + Int d1 = PREG->y_u.yxn.c; + if (IsIntTerm(d0)) { + d0 = MkIntTerm(SLR(IntOfTerm(d0), d1)); + } else { + saveregs(); + d0 = p_slr(Yap_Eval(d0), MkIntegerTerm(d1) PASS_REGS); + setregs(); } + } BEGP(pt0); pt0 = YREG + PREG->y_u.yxn.y; PREG = NEXTOP(PREG, yxn); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, slr_y_vc_unk, slr_y_vc_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A>>B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt0); ENDD(d0); ENDOp(); @@ -1685,40 +1285,34 @@ d0 = XREG(PREG->y_u.yxn.xi); /* first check pt1 */ deref_head(d0, slr_y_cv_unk); - slr_y_cv_nvar: - { - Int d1 = PREG->y_u.yxn.c; - if (IsIntTerm(d0)) { - Int i2 = IntOfTerm(d0); - if (i2 < 0) - d0 = do_sll(d1, -i2 PASS_REGS); - else - d0 = MkIntegerTerm(SLR(d1, i2)); - } - else { - saveregs(); - d0 = p_slr(MkIntegerTerm(d1), Yap_Eval(d0) PASS_REGS); - setregs(); - } - } - if (d0 == 0L) { + slr_y_cv_nvar : { + Int d1 = PREG->y_u.yxn.c; + if (IsIntTerm(d0)) { + Int i2 = IntOfTerm(d0); + if (i2 < 0) + d0 = do_sll(d1, -i2 PASS_REGS); + else + d0 = MkIntegerTerm(SLR(d1, i2)); + } else { saveregs(); - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, LOCAL_ErrorMessage); + d0 = p_slr(MkIntegerTerm(d1), Yap_Eval(d0) PASS_REGS); setregs(); + } + } + if (d0 == 0L) { + Yap_AsmError(LOCAL_Error_TYPE); FAIL(); } BEGP(pt0); pt0 = YREG + PREG->y_u.yxn.y; PREG = NEXTOP(PREG, yxn); - INITIALIZE_PERMVAR(pt0,d0); + INITIALIZE_PERMVAR(pt0, d0); ENDP(pt0); GONext(); BEGP(pt0); deref_body(d0, pt0, slr_y_cv_unk, slr_y_cv_nvar); - saveregs(); - Yap_NilError(INSTANTIATION_ERROR, "X is A>>B"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); FAIL(); ENDP(pt0); ENDD(d0); @@ -1782,13 +1376,12 @@ } } } - exec_bin_cmp_xx: - { - CmpPredicate f = PREG->y_u.plxxs.p->cs.d_code; - saveregs(); - d0 = (CELL) (f) (d0,d1); - setregs(); - } + exec_bin_cmp_xx : { + CmpPredicate f = PREG->y_u.plxxs.p->cs.d_code; + saveregs(); + d0 = (CELL)(f)(d0, d1); + setregs(); + } if (PREG == FAILCODE) { JMPNext(); } @@ -1857,13 +1450,12 @@ } } } - exec_bin_cmp_yx: - { - CmpPredicate f = PREG->y_u.plxys.p->cs.d_code; - saveregs(); - d0 = (CELL) (f) (d0,d1); - setregs(); - } + exec_bin_cmp_yx : { + CmpPredicate f = PREG->y_u.plxys.p->cs.d_code; + saveregs(); + d0 = (CELL)(f)(d0, d1); + setregs(); + } if (!d0 || PREG == FAILCODE) { if (PREG != FAILCODE) PREG = PREG->y_u.plxys.f; @@ -1930,13 +1522,12 @@ } } } - exec_bin_cmp_xy: - { - CmpPredicate f = PREG->y_u.plxys.p->cs.d_code; - saveregs(); - d0 = (CELL) (f) (d0,d1); - setregs(); - } + exec_bin_cmp_xy : { + CmpPredicate f = PREG->y_u.plxys.p->cs.d_code; + saveregs(); + d0 = (CELL)(f)(d0, d1); + setregs(); + } if (!d0 || PREG == FAILCODE) { if (PREG != FAILCODE) PREG = PREG->y_u.plxys.f; @@ -2006,13 +1597,12 @@ } } } - exec_bin_cmp_yy: - { - CmpPredicate f = PREG->y_u.plyys.p->cs.d_code; - saveregs(); - d0 = (CELL) (f) (d0,d1); - setregs(); - } + exec_bin_cmp_yy : { + CmpPredicate f = PREG->y_u.plyys.p->cs.d_code; + saveregs(); + d0 = (CELL)(f)(d0, d1); + setregs(); + } if (!d0 || PREG == FAILCODE) { if (PREG != FAILCODE) PREG = PREG->y_u.plyys.f; @@ -2049,8 +1639,10 @@ Op(p_dif, l); #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorDiff,0)),XREGS+1); -#endif /* LOW_LEVEL_TRACE */ + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorDiff, 0)), + XREGS + 1); +#endif /* LOW_LEVEL_TRACE */ BEGD(d0); BEGD(d1); d0 = ARG1; @@ -2091,7 +1683,7 @@ * be trailed */ HBREG = HR; - B = (choiceptr) HR; + B = (choiceptr)HR; B->cp_h = HR; SET_BB(B); save_hb(); @@ -2117,8 +1709,8 @@ if (IsVarTerm(d1)) { #if defined(YAPOR_SBA) && defined(YAPOR) /* clean up the trail when we backtrack */ - if (Unsigned((Int)(d1)-(Int)(H_FZ)) > - Unsigned((Int)(B_FZ)-(Int)(H_FZ))) { + if (Unsigned((Int)(d1) - (Int)(H_FZ)) > + Unsigned((Int)(B_FZ) - (Int)(H_FZ))) { RESET_VARIABLE(STACK_TO_SBA(d1)); } else #endif @@ -2127,9 +1719,9 @@ #ifdef MULTI_ASSIGNMENT_VARIABLES } else /* if (IsApplTerm(d1)) */ { CELL *pt = RepAppl(d1); - /* AbsAppl means */ - /* multi-assignment variable */ - /* so the next cell is the old value */ +/* AbsAppl means */ +/* multi-assignment variable */ +/* so the next cell is the old value */ #ifdef FROZEN_STACKS pt[0] = TrailVal(--TR); #else @@ -2177,8 +1769,10 @@ #endif #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorSame,0)),XREGS+1); -#endif /* LOW_LEVEL_TRACE */ + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorSame, 0)), + XREGS + 1); +#endif /* LOW_LEVEL_TRACE */ BEGD(d0); BEGD(d1); d0 = ARG1; @@ -2200,7 +1794,7 @@ } BEGD(d2); always_save_pc(); - d2 = iequ_complex(RepPair(d0)-1, RepPair(d0)+1,RepPair(d1)-1); + d2 = iequ_complex(RepPair(d0) - 1, RepPair(d0) + 1, RepPair(d1) - 1); if (d2 == false) { PREG = PREG->y_u.l.l; GONext(); @@ -2248,7 +1842,8 @@ PREG = PREG->y_u.l.l; GONext(); } - if (strcmp((char *)(RepAppl(d0)+2),(char *)(RepAppl(d1)+2)) == 0) { + if (strcmp((char *)(RepAppl(d0) + 2), (char *)(RepAppl(d1) + 2)) == + 0) { PREG = NEXTOP(PREG, l); GONext(); } @@ -2261,7 +1856,7 @@ PREG = PREG->y_u.l.l; GONext(); } - if (Yap_gmp_tcmp_big_big(d0,d1) == 0) { + if (Yap_gmp_tcmp_big_big(d0, d1) == 0) { PREG = NEXTOP(PREG, l); GONext(); } @@ -2291,7 +1886,8 @@ } always_save_pc(); BEGD(d2); - d2 = iequ_complex(RepAppl(d0), RepAppl(d0)+ArityOfFunctor(f0), RepAppl(d1)); + d2 = iequ_complex(RepAppl(d0), RepAppl(d0) + ArityOfFunctor(f0), + RepAppl(d1)); if (d2 == false) { PREG = PREG->y_u.l.l; GONext(); @@ -2342,7 +1938,7 @@ ENDD(d0); #ifdef COROUTINING - /* Problem: have I got an environment or not? */ + /* Problem: have I got an environment or not? */ NoStackEq: PROCESS_INT(interrupt_eq, do_eq); #endif @@ -2350,16 +1946,16 @@ ENDOp(); #endif /* INLINE_BIG_COMPARISONS */ - Op(p_arg_vv, xxx); #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) { HR[0] = XREG(PREG->y_u.xxx.x1); HR[1] = XREG(PREG->y_u.xxx.x2); - RESET_VARIABLE(HR+2); - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorArg,0)),HR); + RESET_VARIABLE(HR + 2); + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HR); } -#endif /* LOW_LEVEL_TRACE */ +#endif /* LOW_LEVEL_TRACE */ BEGD(d0); d0 = XREG(PREG->y_u.xxx.x1); deref_head(d0, arg_arg1_unk); @@ -2370,11 +1966,9 @@ else if (IsLongIntTerm(d0)) { d0 = LongIntOfTerm(d0); } else { - if (IsBigIntTerm( d0 )) + if (IsBigIntTerm(d0)) FAIL(); - saveregs(); - Yap_Error(TYPE_ERROR_INTEGER,d0,"arg 1 of arg/3"); - setregs(); + Yap_AsmError(TYPE_ERROR_INTEGER); FAIL(); } @@ -2389,18 +1983,15 @@ BEGP(pt0); pt0 = RepAppl(d1); d1 = *pt0; - if (IsExtensionFunctor((Functor) d1)) { - saveregs(); - Yap_Error(TYPE_ERROR_COMPOUND, d1, "arg 2 of arg/3"); - setregs(); + if (IsExtensionFunctor((Functor)d1)) { + Yap_AsmError(TYPE_ERROR_COMPOUND); FAIL(); } - if ((Int)d0 <= 0 || - (Int)d0 > ArityOfFunctor((Functor) d1)) { + if ((Int)d0 <= 0 || (Int)d0 > ArityOfFunctor((Functor)d1)) { /* don't complain here for Prolog compatibility if ((Int)d0 <= 0) { saveregs(); - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, +Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); MkIntegerTerm(d0),"arg 1 of arg/3"); setregs(); } @@ -2411,35 +2002,29 @@ PREG = NEXTOP(PREG, xxx); GONext(); ENDP(pt0); - } - else if (IsPairTerm(d1)) { + } else if (IsPairTerm(d1)) { BEGP(pt0); pt0 = RepPair(d1); if (d0 != 1 && d0 != 2) { if ((Int)d0 < 0) { - saveregs(); - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, - MkIntegerTerm(d0),"arg 1 of arg/3"); - setregs(); + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); } FAIL(); } - XREG(PREG->y_u.xxx.x) = pt0[d0-1]; + XREG(PREG->y_u.xxx.x) = pt0[d0 - 1]; PREG = NEXTOP(PREG, xxx); GONext(); ENDP(pt0); - } - else { - saveregs(); - Yap_Error(TYPE_ERROR_COMPOUND, d1, "arg 2 of arg/3"); - setregs(); + } else { + Yap_AsmError(TYPE_ERROR_COMPOUND); FAIL(); } BEGP(pt0); deref_body(d1, pt0, arg_arg2_unk, arg_arg2_nvar); saveregs(); - Yap_Error(INSTANTIATION_ERROR, d1,"arg 2 of arg/3");; + Yap_AsmError(INSTANTIATION_ERROR); + ; setregs(); ENDP(pt0); FAIL(); @@ -2448,7 +2033,8 @@ BEGP(pt0); deref_body(d0, pt0, arg_arg1_unk, arg_arg1_nvar); saveregs(); - Yap_Error(INSTANTIATION_ERROR, d0, "arg 1 of arg/3");; + Yap_AsmError(INSTANTIATION_ERROR); + ; setregs(); ENDP(pt0); FAIL(); @@ -2460,13 +2046,14 @@ if (Yap_do_low_level_trace) { CELL *Ho = HR; Term t = MkIntegerTerm(PREG->y_u.xxn.c); - HR[0] = t; + HR[0] = t; HR[1] = XREG(PREG->y_u.xxn.xi); - RESET_VARIABLE(HR+2); - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorArg,0)),HR); + RESET_VARIABLE(HR + 2); + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HR); HR = Ho; } -#endif /* LOW_LEVEL_TRACE */ +#endif /* LOW_LEVEL_TRACE */ BEGD(d0); d0 = PREG->y_u.xxn.c; /* d0 now got the argument we want */ @@ -2480,18 +2067,15 @@ BEGP(pt0); pt0 = RepAppl(d1); d1 = *pt0; - if (IsExtensionFunctor((Functor) d1)) { - saveregs(); - Yap_Error(TYPE_ERROR_COMPOUND, d1, "arg 2 of arg/3"); - setregs(); + if (IsExtensionFunctor((Functor)d1)) { + Yap_AsmError(TYPE_ERROR_COMPOUND); FAIL(); } - if ((Int)d0 <= 0 || - (Int)d0 > ArityOfFunctor((Functor) d1)) { + if ((Int)d0 <= 0 || (Int)d0 > ArityOfFunctor((Functor)d1)) { /* don't complain here for Prolog compatibility if ((Int)d0 <= 0) { saveregs(); - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, +Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); MkIntegerTerm(d0),"arg 1 of arg/3"); setregs(); } @@ -2502,36 +2086,28 @@ PREG = NEXTOP(PREG, xxn); GONext(); ENDP(pt0); - } - else if (IsPairTerm(d1)) { + } else if (IsPairTerm(d1)) { BEGP(pt0); pt0 = RepPair(d1); if (d0 != 1 && d0 != 2) { if ((Int)d0 < 0) { saveregs(); - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, - MkIntegerTerm(d0),"arg 1 of arg/3"); - setregs(); + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); } FAIL(); } - XREG(PREG->y_u.xxn.x) = pt0[d0-1]; + XREG(PREG->y_u.xxn.x) = pt0[d0 - 1]; PREG = NEXTOP(PREG, xxn); GONext(); ENDP(pt0); - } - else { - saveregs(); - Yap_Error(TYPE_ERROR_COMPOUND, d1, "arg 2 of arg/3"); - setregs(); + } else { + Yap_AsmError(TYPE_ERROR_COMPOUND); FAIL(); } BEGP(pt0); deref_body(d1, pt0, arg_arg2_vc_unk, arg_arg2_vc_nvar); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d1,"arg 2 of arg/3");; - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt0); FAIL(); ENDD(d1); @@ -2545,10 +2121,11 @@ HR[0] = XREG(PREG->y_u.yxx.x1); HR[1] = XREG(PREG->y_u.yxx.x2); HR[2] = YREG[PREG->y_u.yxx.y]; - RESET_VARIABLE(HR+2); - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorArg,0)),HR); + RESET_VARIABLE(HR + 2); + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HR); } -#endif /* LOW_LEVEL_TRACE */ +#endif /* LOW_LEVEL_TRACE */ BEGD(d0); d0 = XREG(PREG->y_u.yxx.x1); deref_head(d0, arg_y_arg1_unk); @@ -2559,11 +2136,9 @@ else if (IsLongIntTerm(d0)) { d0 = LongIntOfTerm(d0); } else { - if (IsBigIntTerm( d0 )) + if (IsBigIntTerm(d0)) FAIL(); - saveregs(); - Yap_Error(TYPE_ERROR_INTEGER,d0,"arg 1 of arg/3"); - setregs(); + Yap_AsmError(TYPE_ERROR_INTEGER); FAIL(); } @@ -2578,18 +2153,15 @@ BEGP(pt0); pt0 = RepAppl(d1); d1 = *pt0; - if (IsExtensionFunctor((Functor) d1)) { - saveregs(); - Yap_Error(TYPE_ERROR_COMPOUND, d1, "arg 2 of arg/3"); - setregs(); + if (IsExtensionFunctor((Functor)d1)) { + Yap_AsmError(TYPE_ERROR_COMPOUND); FAIL(); } - if ((Int)d0 <= 0 || - (Int)d0 > ArityOfFunctor((Functor) d1)) { + if ((Int)d0 <= 0 || (Int)d0 > ArityOfFunctor((Functor)d1)) { /* don't complain here for Prolog compatibility if ((Int)d0 <= 0) { saveregs(); - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, +Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); MkIntegerTerm(d0),"arg 1 of arg/3"); saveregs(); } @@ -2599,52 +2171,42 @@ BEGP(pt1); pt1 = YREG + PREG->y_u.yxx.y; PREG = NEXTOP(PREG, yxx); - INITIALIZE_PERMVAR(pt1,pt0[d0]); + INITIALIZE_PERMVAR(pt1, pt0[d0]); ENDP(pt1); GONext(); ENDP(pt0); - } - else if (IsPairTerm(d1)) { + } else if (IsPairTerm(d1)) { BEGP(pt0); pt0 = RepPair(d1); if (d0 != 1 && d0 != 2) { if ((Int)d0 < 0) { saveregs(); - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, - MkIntegerTerm(d0),"arg 1 of arg/3"); - setregs(); + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); } FAIL(); } BEGP(pt1); pt1 = YREG + PREG->y_u.yxx.y; PREG = NEXTOP(PREG, yxx); - INITIALIZE_PERMVAR(pt1,pt0[d0-1]); + INITIALIZE_PERMVAR(pt1, pt0[d0 - 1]); GONext(); ENDP(pt1); ENDP(pt0); - } - else { - saveregs(); - Yap_Error(TYPE_ERROR_COMPOUND, d1, "arg 2 of arg/3"); - setregs(); + } else { + Yap_AsmError(TYPE_ERROR_COMPOUND); FAIL(); } BEGP(pt0); deref_body(d1, pt0, arg_y_arg2_unk, arg_y_arg2_nvar); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d1,"arg 2 of arg/3");; - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt0); FAIL(); ENDD(d1); BEGP(pt0); deref_body(d0, pt0, arg_y_arg1_unk, arg_y_arg1_nvar); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d0, "arg 1 of arg/3");; - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt0); FAIL(); ENDD(d0); @@ -2655,14 +2217,15 @@ if (Yap_do_low_level_trace) { CELL *Ho = HR; Term t = MkIntegerTerm(PREG->y_u.yxn.c); - HR[0] = t; + HR[0] = t; HR[1] = XREG(PREG->y_u.yxn.xi); HR[2] = YREG[PREG->y_u.yxn.y]; - RESET_VARIABLE(HR+2); - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorArg,0)),HR); + RESET_VARIABLE(HR + 2); + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorArg, 0)), HR); HR = Ho; } -#endif /* LOW_LEVEL_TRACE */ +#endif /* LOW_LEVEL_TRACE */ BEGD(d0); d0 = PREG->y_u.yxn.c; /* d0 now got the argument we want */ @@ -2676,20 +2239,14 @@ BEGP(pt0); pt0 = RepAppl(d1); d1 = *pt0; - if (IsExtensionFunctor((Functor) d1)) { - saveregs(); - Yap_Error(TYPE_ERROR_COMPOUND, d1, "arg 2 of arg/3"); - setregs(); - FAIL(); + if (IsExtensionFunctor((Functor)d1)) { + Yap_AsmError(TYPE_ERROR_COMPOUND); + FAIL(); } - if ((Int)d0 <= 0 || - (Int)d0 > ArityOfFunctor((Functor) d1)) { + if ((Int)d0 <= 0 || (Int)d0 > ArityOfFunctor((Functor)d1)) { /* don't complain here for Prolog compatibility if ((Int)d0 <= 0) { - saveregs(); - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, - MkIntegerTerm(d0),"arg 1 of arg/3"); - setregs(); +Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); } */ FAIL(); @@ -2697,43 +2254,35 @@ BEGP(pt1); pt1 = YREG + PREG->y_u.yxn.y; PREG = NEXTOP(PREG, yxn); - INITIALIZE_PERMVAR(pt1,pt0[d0]); + INITIALIZE_PERMVAR(pt1, pt0[d0]); ENDP(pt1); GONext(); ENDP(pt0); - } - else if (IsPairTerm(d1)) { + } else if (IsPairTerm(d1)) { BEGP(pt0); pt0 = RepPair(d1); if (d0 != 1 && d0 != 2) { if ((Int)d0 < 0) { saveregs(); - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, - MkIntegerTerm(d0),"arg 1 of arg/3"); - setregs(); + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); } FAIL(); } BEGP(pt1); pt1 = YREG + PREG->y_u.yxn.y; PREG = NEXTOP(PREG, yxn); - INITIALIZE_PERMVAR(pt1,pt0[d0-1]); + INITIALIZE_PERMVAR(pt1, pt0[d0 - 1]); ENDP(pt1); GONext(); ENDP(pt0); - } - else { - saveregs(); - Yap_Error(TYPE_ERROR_COMPOUND, d1, "arg 2 of arg/3"); - setregs(); + } else { + Yap_AsmError(TYPE_ERROR_COMPOUND); FAIL(); } BEGP(pt0); deref_body(d1, pt0, arg_y_arg2_vc_unk, arg_y_arg2_vc_nvar); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d1,"arg 2 of arg/3");; - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt0); FAIL(); ENDD(d1); @@ -2742,17 +2291,19 @@ ENDOp(); Op(p_func2s_vv, xxx); - /* A1 is a variable */ + /* A1 is a variable */ restart_func2s: #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) { RESET_VARIABLE(HR); HR[1] = XREG(PREG->y_u.xxx.x1); HR[2] = XREG(PREG->y_u.xxx.x2); - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor,0)),HR); + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)), + HR); } -#endif /* LOW_LEVEL_TRACE */ - /* We have to build the structure */ +#endif /* LOW_LEVEL_TRACE */ + /* We have to build the structure */ BEGD(d0); d0 = XREG(PREG->y_u.xxx.x1); deref_head(d0, func2s_unk); @@ -2768,55 +2319,51 @@ else { saveregs(); if (IsBigIntTerm(d1)) { - Yap_Error(RESOURCE_ERROR_STACK, d1, "functor/3"); + setregs(); + Yap_AsmError(RESOURCE_ERROR_STACK); } else { - Yap_Error(TYPE_ERROR_INTEGER, d1, "functor/3"); + setregs(); + Yap_AsmError(TYPE_ERROR_INTEGER); } - setregs(); FAIL(); } if (!IsAtomicTerm(d0)) { - saveregs(); - Yap_Error(TYPE_ERROR_ATOM,d0,"functor/3"); - setregs(); + Yap_AsmError(TYPE_ERROR_ATOM); FAIL(); } /* We made it!!!!! we got in d0 the name, in d1 the arity and * in pt0 the variable to bind it to. */ if (d0 == TermDot && d1 == 2) { RESET_VARIABLE(HR); - RESET_VARIABLE(HR+1); + RESET_VARIABLE(HR + 1); d0 = AbsPair(HR); HR += 2; /* else if arity is 0 just pass d0 through */ /* Ding, ding, we made it */ XREG(PREG->y_u.xxx.x) = d0; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxx),Osbpp),l); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxx), Osbpp), l); GONext(); - } - else if ((Int)d1 > 0) { + } else if ((Int)d1 > 0) { /* now let's build a compound term */ if (!IsAtomTerm(d0)) { - saveregs(); - Yap_Error(TYPE_ERROR_ATOM,d0,"functor/3"); - setregs(); + Yap_AsmError(TYPE_ERROR_ATOM); FAIL(); } BEGP(pt1); if (!IsAtomTerm(d0)) { FAIL(); - } - else - d0 = (CELL) Yap_MkFunctor(AtomOfTerm(d0), (Int) d1); + } else + d0 = (CELL)Yap_MkFunctor(AtomOfTerm(d0), (Int)d1); pt1 = HR; *pt1++ = d0; d0 = AbsAppl(HR); - if (pt1+d1 > ENV || pt1+d1 > (CELL *)B) { + if (pt1 + d1 > ENV || pt1 + d1 > (CELL *)B) { /* make sure we have something to show for our trouble */ saveregs(); - if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,xxx),Osbpp))) { - Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage); - setregs(); + if (!Yap_gcl((1 + d1) * sizeof(CELL), 0, YREG, + NEXTOP(NEXTOP(PREG, xxx), Osbpp))) { + setregs(); + Yap_AsmError(RESOURCE_ERROR_STACK); JMPNext(); } else { setregs(); @@ -2833,24 +2380,19 @@ /* else if arity is 0 just pass d0 through */ /* Ding, ding, we made it */ XREG(PREG->y_u.xxx.x) = d0; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxx),Osbpp),l); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxx), Osbpp), l); GONext(); - } else if ((Int)d1 == 0) { + } else if ((Int)d1 == 0) { XREG(PREG->y_u.xxx.x) = d0; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxx),Osbpp),l); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxx), Osbpp), l); GONext(); - } else { - saveregs(); - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO,MkIntegerTerm(d1),"functor/3"); - setregs(); - FAIL(); + } else { + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); } BEGP(pt1); deref_body(d1, pt1, func2s_unk2, func2s_nvar2); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d1, "functor/3"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt1); /* Oops, third argument was unbound */ FAIL(); @@ -2858,9 +2400,7 @@ BEGP(pt1); deref_body(d0, pt1, func2s_unk, func2s_nvar); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d0, "functor/3"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -2868,16 +2408,18 @@ ENDOp(); Op(p_func2s_cv, xxc); - /* A1 is a variable */ + /* A1 is a variable */ restart_func2s_cv: #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) { RESET_VARIABLE(HR); HR[1] = PREG->y_u.xxc.c; HR[2] = XREG(PREG->y_u.xxc.xi); - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor,0)),HR); + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)), + HR); } -#endif /* LOW_LEVEL_TRACE */ +#endif /* LOW_LEVEL_TRACE */ BEGD(d0); /* We have to build the structure */ d0 = PREG->y_u.xxc.c; @@ -2892,48 +2434,47 @@ else { saveregs(); if (IsBigIntTerm(d1)) { - Yap_Error(RESOURCE_ERROR_STACK, d1, "functor/3"); + setregs(); + Yap_AsmError(RESOURCE_ERROR_STACK); } else { - Yap_Error(TYPE_ERROR_INTEGER,d1,"functor/3"); + setregs(); + Yap_AsmError(TYPE_ERROR_INTEGER); } - setregs(); FAIL(); } /* We made it!!!!! we got in d0 the name, in d1 the arity and * in pt0 the variable to bind it to. */ if (d0 == TermDot && d1 == 2) { RESET_VARIABLE(HR); - RESET_VARIABLE(HR+1); + RESET_VARIABLE(HR + 1); d0 = AbsPair(HR); HR += 2; /* else if arity is 0 just pass d0 through */ /* Ding, ding, we made it */ XREG(PREG->y_u.xxc.x) = d0; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxc),Osbpp),l); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxc), Osbpp), l); GONext(); } else if ((Int)d1 > 0) { /* now let's build a compound term */ if (!IsAtomTerm(d0)) { - saveregs(); - Yap_Error(TYPE_ERROR_ATOM,d0,"functor/3"); - setregs(); + Yap_AsmError(TYPE_ERROR_ATOM); FAIL(); } BEGP(pt1); if (!IsAtomTerm(d0)) { FAIL(); - } - else - d0 = (CELL) Yap_MkFunctor(AtomOfTerm(d0), (Int) d1); + } else + d0 = (CELL)Yap_MkFunctor(AtomOfTerm(d0), (Int)d1); pt1 = HR; *pt1++ = d0; d0 = AbsAppl(HR); - if (pt1+d1 > ENV || pt1+d1 > (CELL *)B) { + if (pt1 + d1 > ENV || pt1 + d1 > (CELL *)B) { /* make sure we have something to show for our trouble */ saveregs(); - if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,xxc),Osbpp))) { - Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage); - setregs(); + if (!Yap_gcl((1 + d1) * sizeof(CELL), 0, YREG, + NEXTOP(NEXTOP(PREG, xxc), Osbpp))) { + setregs(); + Yap_AsmError(RESOURCE_ERROR_STACK); JMPNext(); } else { setregs(); @@ -2950,24 +2491,19 @@ /* else if arity is 0 just pass d0 through */ /* Ding, ding, we made it */ XREG(PREG->y_u.xxc.x) = d0; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxc),Osbpp),l); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxc), Osbpp), l); GONext(); - } else if (d1 == 0) { + } else if (d1 == 0) { XREG(PREG->y_u.xxc.x) = d0; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxc),Osbpp),l); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxc), Osbpp), l); GONext(); - } else { - saveregs(); - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO,MkIntegerTerm(d1),"functor/3"); - setregs(); - FAIL(); + } else { + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); } BEGP(pt1); deref_body(d1, pt1, func2s_unk2_cv, func2s_nvar2_cv); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d1, "functor/3"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt1); /* Oops, third argument was unbound */ FAIL(); @@ -2976,7 +2512,7 @@ ENDOp(); Op(p_func2s_vc, xxn); - /* A1 is a variable */ + /* A1 is a variable */ restart_func2s_vc: #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) { @@ -2987,11 +2523,13 @@ RESET_VARIABLE(HR); HR[1] = XREG(PREG->y_u.xxn.xi); HR[2] = ti; - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor,0)),HR); + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)), + HR); HR = hi; } -#endif /* LOW_LEVEL_TRACE */ - /* We have to build the structure */ +#endif /* LOW_LEVEL_TRACE */ + /* We have to build the structure */ BEGD(d0); d0 = XREG(PREG->y_u.xxn.xi); deref_head(d0, func2s_unk_vc); @@ -2999,51 +2537,46 @@ BEGD(d1); d1 = PREG->y_u.xxn.c; if (!IsAtomicTerm(d0)) { - saveregs(); - Yap_Error(TYPE_ERROR_ATOM,d0,"functor/3"); - setregs(); + Yap_AsmError(TYPE_ERROR_ATOM); FAIL(); } /* We made it!!!!! we got in d0 the name, in d1 the arity and * in pt0 the variable to bind it to. */ if (d0 == TermDot && d1 == 2) { RESET_VARIABLE(HR); - RESET_VARIABLE(HR+1); + RESET_VARIABLE(HR + 1); d0 = AbsPair(HR); HR += 2; /* else if arity is 0 just pass d0 through */ /* Ding, ding, we made it */ XREG(PREG->y_u.xxn.x) = d0; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxn),Osbpp),l); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxn), Osbpp), l); GONext(); } /* now let's build a compound term */ if (d1 == 0) { XREG(PREG->y_u.xxn.x) = d0; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxn),Osbpp),l); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxn), Osbpp), l); GONext(); } if (!IsAtomTerm(d0)) { - saveregs(); - Yap_Error(TYPE_ERROR_ATOM,d0,"functor/3"); - setregs(); + Yap_AsmError(TYPE_ERROR_ATOM); FAIL(); } BEGP(pt1); if (!IsAtomTerm(d0)) { FAIL(); - } - else - d0 = (CELL) Yap_MkFunctor(AtomOfTerm(d0), (Int) d1); + } else + d0 = (CELL)Yap_MkFunctor(AtomOfTerm(d0), (Int)d1); pt1 = HR; *pt1++ = d0; d0 = AbsAppl(HR); - if (pt1+d1 > ENV || pt1+d1 > (CELL *)B) { + if (pt1 + d1 > ENV || pt1 + d1 > (CELL *)B) { /* make sure we have something to show for our trouble */ saveregs(); - if (!Yap_gc(0, YREG, NEXTOP(NEXTOP(PREG,xxn),Osbpp))) { - Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage); - setregs(); + if (!Yap_gc(0, YREG, NEXTOP(NEXTOP(PREG, xxn), Osbpp))) { + setregs(); + Yap_AsmError(RESOURCE_ERROR_STACK); JMPNext(); } else { setregs(); @@ -3061,14 +2594,12 @@ /* else if arity is 0 just pass d0 through */ /* Ding, ding, we made it */ XREG(PREG->y_u.xxn.x) = d0; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxn),Osbpp),l); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxn), Osbpp), l); GONext(); BEGP(pt1); deref_body(d0, pt1, func2s_unk_vc, func2s_nvar_vc); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d0, "functor/3"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -3076,17 +2607,19 @@ ENDOp(); Op(p_func2s_y_vv, yxx); - /* A1 is a variable */ + /* A1 is a variable */ restart_func2s_y: #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) { RESET_VARIABLE(HR); HR[1] = XREG(PREG->y_u.yxx.x1); HR[2] = XREG(PREG->y_u.yxx.x2); - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor,0)),HR); + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)), + HR); } -#endif /* LOW_LEVEL_TRACE */ - /* We have to build the structure */ +#endif /* LOW_LEVEL_TRACE */ + /* We have to build the structure */ BEGD(d0); d0 = XREG(PREG->y_u.yxx.x1); deref_head(d0, func2s_y_unk); @@ -3102,55 +2635,52 @@ else { saveregs(); if (IsBigIntTerm(d1)) { - Yap_Error(RESOURCE_ERROR_STACK, d1, "functor/3"); + setregs(); + Yap_AsmError(RESOURCE_ERROR_STACK); } else { - Yap_Error(TYPE_ERROR_INTEGER,d1,"functor/3"); + setregs(); + Yap_AsmError(TYPE_ERROR_INTEGER); } - setregs(); FAIL(); } if (!IsAtomicTerm(d0)) { - saveregs(); - Yap_Error(TYPE_ERROR_ATOM,d0,"functor/3"); - setregs(); + Yap_AsmError(TYPE_ERROR_ATOM); FAIL(); } /* We made it!!!!! we got in d0 the name, in d1 the arity and * in pt0 the variable to bind it to. */ if (d0 == TermDot && d1 == 2) { RESET_VARIABLE(HR); - RESET_VARIABLE(HR+1); + RESET_VARIABLE(HR + 1); d0 = AbsPair(HR); HR += 2; BEGP(pt1); pt1 = YREG + PREG->y_u.yxx.y; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxx),Osbpp),l); - INITIALIZE_PERMVAR(pt1,d0); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxx), Osbpp), l); + INITIALIZE_PERMVAR(pt1, d0); ENDP(pt1); GONext(); } else if ((Int)d1 > 0) { /* now let's build a compound term */ if (!IsAtomTerm(d0)) { - saveregs(); - Yap_Error(TYPE_ERROR_ATOM,d0,"functor/3"); - setregs(); + Yap_AsmError(TYPE_ERROR_ATOM); FAIL(); } BEGP(pt1); if (!IsAtomTerm(d0)) { FAIL(); - } - else - d0 = (CELL) Yap_MkFunctor(AtomOfTerm(d0), (Int) d1); + } else + d0 = (CELL)Yap_MkFunctor(AtomOfTerm(d0), (Int)d1); pt1 = HR; *pt1++ = d0; d0 = AbsAppl(HR); - if (pt1+d1 > ENV || pt1+d1 > (CELL *)B) { + if (pt1 + d1 > ENV || pt1 + d1 > (CELL *)B) { /* make sure we have something to show for our trouble */ saveregs(); - if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxx),Osbpp))) { - Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage); + if (!Yap_gcl((1 + d1) * sizeof(CELL), 0, YREG, + NEXTOP(NEXTOP(PREG, yxx), Osbpp))) { setregs(); + Yap_AsmError(RESOURCE_ERROR_STACK); JMPNext(); } else { setregs(); @@ -3168,29 +2698,24 @@ /* Ding, ding, we made it */ BEGP(pt1); pt1 = YREG + PREG->y_u.yxx.y; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxx),Osbpp),l); - INITIALIZE_PERMVAR(pt1,d0); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxx), Osbpp), l); + INITIALIZE_PERMVAR(pt1, d0); ENDP(pt1); GONext(); - } else if (d1 == 0) { + } else if (d1 == 0) { BEGP(pt1); pt1 = YREG + PREG->y_u.yxx.y; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxx),Osbpp),l); - INITIALIZE_PERMVAR(pt1,d0); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxx), Osbpp), l); + INITIALIZE_PERMVAR(pt1, d0); ENDP(pt1); GONext(); - } else { - saveregs(); - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO,MkIntegerTerm(d1),"functor/3"); - setregs(); - FAIL(); + } else { + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); } BEGP(pt1); deref_body(d1, pt1, func2s_y_unk2, func2s_y_nvar2); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d1, "functor/3"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt1); /* Oops, third argument was unbound */ FAIL(); @@ -3198,9 +2723,7 @@ BEGP(pt1); deref_body(d0, pt1, func2s_y_unk, func2s_y_nvar); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d0, "functor/3"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -3208,17 +2731,19 @@ ENDOp(); Op(p_func2s_y_cv, yxc); - /* A1 is a variable */ + /* A1 is a variable */ restart_func2s_y_cv: #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) { RESET_VARIABLE(HR); HR[1] = PREG->y_u.yxc.c; HR[2] = XREG(PREG->y_u.yxc.xi); - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor,0)),HR); + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)), + HR); } -#endif /* LOW_LEVEL_TRACE */ - /* We have to build the structure */ +#endif /* LOW_LEVEL_TRACE */ + /* We have to build the structure */ BEGD(d0); d0 = PREG->y_u.yxc.c; /* we do, let's get the third argument */ @@ -3230,54 +2755,49 @@ if (IsIntegerTerm(d1)) { d1 = IntegerOfTerm(d1); } else { - saveregs(); if (IsBigIntTerm(d1)) { - Yap_Error(RESOURCE_ERROR_STACK, d1, "functor/3"); + Yap_AsmError(RESOURCE_ERROR_STACK); } else { - Yap_Error(TYPE_ERROR_INTEGER,d1,"functor/3"); + Yap_AsmError(TYPE_ERROR_INTEGER); } - setregs(); FAIL(); } /* We made it!!!!! we got in d0 the name, in d1 the arity and * in pt0 the variable to bind it to. */ if (d0 == TermDot && d1 == 2) { RESET_VARIABLE(HR); - RESET_VARIABLE(HR+1); + RESET_VARIABLE(HR + 1); d0 = AbsPair(HR); HR += 2; /* else if arity is 0 just pass d0 through */ /* Ding, ding, we made it */ BEGP(pt1); pt1 = YREG + PREG->y_u.yxc.y; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxc),Osbpp),l); - INITIALIZE_PERMVAR(pt1,d0); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxc), Osbpp), l); + INITIALIZE_PERMVAR(pt1, d0); ENDP(pt1); GONext(); - } - else if ((Int)d1 > 0) { + } else if ((Int)d1 > 0) { /* now let's build a compound term */ if (!IsAtomTerm(d0)) { - saveregs(); - Yap_Error(TYPE_ERROR_ATOM,d0,"functor/3"); - setregs(); + Yap_AsmError(TYPE_ERROR_ATOM); FAIL(); } if (!IsAtomTerm(d0)) { FAIL(); - } - else - d0 = (CELL) Yap_MkFunctor(AtomOfTerm(d0), (Int) d1); + } else + d0 = (CELL)Yap_MkFunctor(AtomOfTerm(d0), (Int)d1); BEGP(pt1); pt1 = HR; *pt1++ = d0; d0 = AbsAppl(HR); - if (pt1+d1 > ENV || pt1+d1 > (CELL *)B) { + if (pt1 + d1 > ENV || pt1 + d1 > (CELL *)B) { /* make sure we have something to show for our trouble */ saveregs(); - if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxc),Osbpp))) { - Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage); + if (!Yap_gcl((1 + d1) * sizeof(CELL), 0, YREG, + NEXTOP(NEXTOP(PREG, yxc), Osbpp))) { setregs(); + Yap_AsmError(RESOURCE_ERROR_STACK); JMPNext(); } else { setregs(); @@ -3295,29 +2815,24 @@ /* Ding, ding, we made it */ BEGP(pt1); pt1 = YREG + PREG->y_u.yxc.y; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxc),Osbpp),l); - INITIALIZE_PERMVAR(pt1,d0); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxc), Osbpp), l); + INITIALIZE_PERMVAR(pt1, d0); ENDP(pt1); GONext(); - } else if (d1 == 0) { + } else if (d1 == 0) { BEGP(pt1); pt1 = YREG + PREG->y_u.yxc.y; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxc),Osbpp),l); - INITIALIZE_PERMVAR(pt1,d0); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxc), Osbpp), l); + INITIALIZE_PERMVAR(pt1, d0); ENDP(pt1); GONext(); - } else { - saveregs(); - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO,MkIntegerTerm(d1),"functor/3"); - setregs(); - FAIL(); + } else { + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); } BEGP(pt1); deref_body(d1, pt1, func2s_y_unk_cv, func2s_y_nvar_cv); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d1, "functor/3"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt1); /* Oops, third argument was unbound */ FAIL(); @@ -3326,7 +2841,7 @@ ENDOp(); Op(p_func2s_y_vc, yxn); - /* A1 is a variable */ + /* A1 is a variable */ restart_func2s_y_vc: #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) { @@ -3337,11 +2852,13 @@ RESET_VARIABLE(HR); HR[1] = XREG(PREG->y_u.yxn.xi); HR[2] = ti; - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor,0)),HR); + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)), + HR); HR = hi; } -#endif /* LOW_LEVEL_TRACE */ - /* We have to build the structure */ +#endif /* LOW_LEVEL_TRACE */ + /* We have to build the structure */ BEGD(d0); d0 = XREG(PREG->y_u.yxn.xi); deref_head(d0, func2s_y_unk_vc); @@ -3349,63 +2866,57 @@ BEGD(d1); d1 = PREG->y_u.yxn.c; if (!IsAtomicTerm(d0)) { - saveregs(); - Yap_Error(TYPE_ERROR_ATOM,d0,"functor/3"); - setregs(); + Yap_AsmError(TYPE_ERROR_ATOM); FAIL(); } /* We made it!!!!! we got in d0 the name, in d1 the arity and * in pt0 the variable to bind it to. */ if (d0 == TermDot && d1 == 2) { RESET_VARIABLE(HR); - RESET_VARIABLE(HR+1); + RESET_VARIABLE(HR + 1); d0 = AbsPair(HR); HR += 2; /* else if arity is 0 just pass d0 through */ /* Ding, ding, we made it */ BEGP(pt1); pt1 = YREG + PREG->y_u.yxn.y; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxn),Osbpp),l); - INITIALIZE_PERMVAR(pt1,d0); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxn), Osbpp), l); + INITIALIZE_PERMVAR(pt1, d0); ENDP(pt1); GONext(); } if (d1 == 0) { BEGP(pt1); pt1 = YREG + PREG->y_u.yxn.y; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxn),Osbpp),l); - INITIALIZE_PERMVAR(pt1,d0); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxn), Osbpp), l); + INITIALIZE_PERMVAR(pt1, d0); ENDP(pt1); GONext(); } if (!IsAtomTerm(d0)) { - saveregs(); - Yap_Error(TYPE_ERROR_ATOM,d0,"functor/3"); - setregs(); + Yap_AsmError(TYPE_ERROR_ATOM); FAIL(); } /* now let's build a compound term */ if (!IsAtomTerm(d0)) { - saveregs(); - Yap_Error(TYPE_ERROR_ATOM,d0,"functor/3"); - setregs(); + Yap_AsmError(TYPE_ERROR_ATOM); FAIL(); } BEGP(pt1); if (!IsAtomTerm(d0)) { FAIL(); - } - else - d0 = (CELL) Yap_MkFunctor(AtomOfTerm(d0), (Int) d1); + } else + d0 = (CELL)Yap_MkFunctor(AtomOfTerm(d0), (Int)d1); pt1 = HR; *pt1++ = d0; d0 = AbsAppl(HR); - if (pt1+d1 > ENV || pt1+d1 > (CELL *)B) { + if (pt1 + d1 > ENV || pt1 + d1 > (CELL *)B) { /* make sure we have something to show for our trouble */ saveregs(); - if (!Yap_gcl((1+d1)*sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG,yxn),Osbpp))) { - Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage); - setregs(); + if (!Yap_gcl((1 + d1) * sizeof(CELL), 0, YREG, + NEXTOP(NEXTOP(PREG, yxn), Osbpp))) { + setregs(); + Yap_AsmError(RESOURCE_ERROR_STACK); JMPNext(); } else { setregs(); @@ -3423,17 +2934,15 @@ /* Ding, ding, we made it */ BEGP(pt1); pt1 = YREG + PREG->y_u.yxn.y; - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxn),Osbpp),l); - INITIALIZE_PERMVAR(pt1,d0); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, yxn), Osbpp), l); + INITIALIZE_PERMVAR(pt1, d0); ENDP(pt1); ENDD(d1); GONext(); BEGP(pt1); deref_body(d0, pt1, func2s_y_unk_vc, func2s_y_nvar_vc); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d0, "functor/3"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -3444,11 +2953,13 @@ #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) { HR[0] = XREG(PREG->y_u.xxx.x); - RESET_VARIABLE(HR+1); - RESET_VARIABLE(HR+2); - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor,0)),HR); + RESET_VARIABLE(HR + 1); + RESET_VARIABLE(HR + 2); + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)), + HR); } -#endif /* LOW_LEVEL_TRACE */ +#endif /* LOW_LEVEL_TRACE */ BEGD(d0); d0 = XREG(PREG->y_u.xxx.x); deref_head(d0, func2f_xx_unk); @@ -3479,9 +2990,7 @@ BEGP(pt1); deref_body(d0, pt1, func2f_xx_unk, func2f_xx_nvar); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d0, "functor/3"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -3492,18 +3001,20 @@ #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) { HR[0] = XREG(PREG->y_u.xxy.x); - RESET_VARIABLE(HR+1); - RESET_VARIABLE(HR+2); - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor,0)),HR); + RESET_VARIABLE(HR + 1); + RESET_VARIABLE(HR + 2); + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)), + HR); } -#endif /* LOW_LEVEL_TRACE */ +#endif /* LOW_LEVEL_TRACE */ BEGD(d0); d0 = XREG(PREG->y_u.xxy.x); deref_head(d0, func2f_xy_unk); func2f_xy_nvar: if (IsApplTerm(d0)) { Functor d1 = FunctorOfTerm(d0); - CELL *pt0 = YREG+PREG->y_u.xxy.y2; + CELL *pt0 = YREG + PREG->y_u.xxy.y2; if (IsExtensionFunctor(d1)) { XREG(PREG->y_u.xxy.x1) = d0; PREG = NEXTOP(PREG, xxy); @@ -3515,13 +3026,13 @@ INITIALIZE_PERMVAR(pt0, MkIntegerTerm(ArityOfFunctor(d1))); GONext(); } else if (IsPairTerm(d0)) { - CELL *pt0 = YREG+PREG->y_u.xxy.y2; + CELL *pt0 = YREG + PREG->y_u.xxy.y2; XREG(PREG->y_u.xxy.x1) = TermDot; PREG = NEXTOP(PREG, xxy); INITIALIZE_PERMVAR(pt0, MkIntTerm(2)); GONext(); } else { - CELL *pt0 = YREG+PREG->y_u.xxy.y2; + CELL *pt0 = YREG + PREG->y_u.xxy.y2; XREG(PREG->y_u.xxy.x1) = d0; PREG = NEXTOP(PREG, xxy); INITIALIZE_PERMVAR(pt0, MkIntTerm(0)); @@ -3530,9 +3041,7 @@ BEGP(pt1); deref_body(d0, pt1, func2f_xy_unk, func2f_xy_nvar); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d0, "functor/3"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -3543,18 +3052,20 @@ #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) { HR[0] = XREG(PREG->y_u.yxx.x2); - RESET_VARIABLE(HR+1); - RESET_VARIABLE(HR+2); - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor,0)),HR); + RESET_VARIABLE(HR + 1); + RESET_VARIABLE(HR + 2); + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)), + HR); } -#endif /* LOW_LEVEL_TRACE */ +#endif /* LOW_LEVEL_TRACE */ BEGD(d0); d0 = XREG(PREG->y_u.yxx.x2); deref_head(d0, func2f_yx_unk); func2f_yx_nvar: if (IsApplTerm(d0)) { Functor d1 = FunctorOfTerm(d0); - CELL *pt0 = YREG+PREG->y_u.yxx.y; + CELL *pt0 = YREG + PREG->y_u.yxx.y; if (IsExtensionFunctor(d1)) { XREG(PREG->y_u.yxx.x1) = MkIntTerm(0); PREG = NEXTOP(PREG, yxx); @@ -3563,16 +3074,16 @@ } XREG(PREG->y_u.yxx.x1) = MkIntegerTerm(ArityOfFunctor(d1)); PREG = NEXTOP(PREG, yxx); - INITIALIZE_PERMVAR(pt0, MkAtomTerm(NameOfFunctor(d1))); + INITIALIZE_PERMVAR(pt0, MkAtomTerm(NameOfFunctor(d1))); GONext(); } else if (IsPairTerm(d0)) { - CELL *pt0 = YREG+PREG->y_u.yxx.y; + CELL *pt0 = YREG + PREG->y_u.yxx.y; XREG(PREG->y_u.yxx.x1) = MkIntTerm(2); PREG = NEXTOP(PREG, yxx); - INITIALIZE_PERMVAR(pt0 ,TermDot); + INITIALIZE_PERMVAR(pt0, TermDot); GONext(); } else { - CELL *pt0 = YREG+PREG->y_u.yxx.y; + CELL *pt0 = YREG + PREG->y_u.yxx.y; XREG(PREG->y_u.yxx.x1) = MkIntTerm(0); PREG = NEXTOP(PREG, yxx); INITIALIZE_PERMVAR(pt0, d0); @@ -3581,9 +3092,7 @@ BEGP(pt1); deref_body(d0, pt1, func2f_yx_unk, func2f_yx_nvar); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d0, "functor/3"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -3594,22 +3103,24 @@ #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) { HR[0] = XREG(PREG->y_u.yyx.x); - RESET_VARIABLE(HR+1); - RESET_VARIABLE(HR+2); - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor,0)),HR); + RESET_VARIABLE(HR + 1); + RESET_VARIABLE(HR + 2); + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)), + HR); } -#endif /* LOW_LEVEL_TRACE */ +#endif /* LOW_LEVEL_TRACE */ BEGD(d0); d0 = XREG(PREG->y_u.yyx.x); deref_head(d0, func2f_yy_unk); func2f_yy_nvar: if (IsApplTerm(d0)) { Functor d1 = FunctorOfTerm(d0); - CELL *pt0 = YREG+PREG->y_u.yyx.y1; - CELL *pt1 = YREG+PREG->y_u.yyx.y2; + CELL *pt0 = YREG + PREG->y_u.yyx.y1; + CELL *pt1 = YREG + PREG->y_u.yyx.y2; if (IsExtensionFunctor(d1)) { PREG = NEXTOP(PREG, yyx); - INITIALIZE_PERMVAR(pt0, d0); + INITIALIZE_PERMVAR(pt0, d0); INITIALIZE_PERMVAR(pt1, MkIntTerm(0)); GONext(); } @@ -3618,15 +3129,15 @@ INITIALIZE_PERMVAR(pt1, MkIntegerTerm(ArityOfFunctor(d1))); GONext(); } else if (IsPairTerm(d0)) { - CELL *pt0 = YREG+PREG->y_u.yyx.y1; - CELL *pt1 = YREG+PREG->y_u.yyx.y2; + CELL *pt0 = YREG + PREG->y_u.yyx.y1; + CELL *pt1 = YREG + PREG->y_u.yyx.y2; PREG = NEXTOP(PREG, yyx); INITIALIZE_PERMVAR(pt0, TermDot); INITIALIZE_PERMVAR(pt1, MkIntTerm(2)); GONext(); } else { - CELL *pt0 = YREG+PREG->y_u.yyx.y1; - CELL *pt1 = YREG+PREG->y_u.yyx.y2; + CELL *pt0 = YREG + PREG->y_u.yyx.y1; + CELL *pt1 = YREG + PREG->y_u.yyx.y2; PREG = NEXTOP(PREG, yyx); INITIALIZE_PERMVAR(pt0, d0); INITIALIZE_PERMVAR(pt1, MkIntTerm(0)); @@ -3635,9 +3146,7 @@ BEGP(pt1); deref_body(d0, pt1, func2f_yy_unk, func2f_yy_nvar); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d0, "functor/3"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -3647,8 +3156,10 @@ Op(p_functor, e); #ifdef LOW_LEVEL_TRACER if (Yap_do_low_level_trace) - low_level_trace(enter_pred,RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor,0)),XREGS+1); -#endif /* LOW_LEVEL_TRACE */ + low_level_trace(enter_pred, + RepPredProp(Yap_GetPredPropByFunc(FunctorFunctor, 0)), + XREGS + 1); +#endif /* LOW_LEVEL_TRACE */ restart_functor: BEGD(d0); d0 = ARG1; @@ -3658,21 +3169,19 @@ BEGD(d1); if (IsApplTerm(d0)) { d1 = *RepAppl(d0); - if (IsExtensionFunctor((Functor) d1)) { - if (d1 <= (CELL)FunctorDouble && d1 >= (CELL)FunctorLongInt ) { + if (IsExtensionFunctor((Functor)d1)) { + if (d1 <= (CELL)FunctorDouble && d1 >= (CELL)FunctorLongInt) { d1 = MkIntTerm(0); } else FAIL(); } else { - d0 = MkAtomTerm(NameOfFunctor((Functor) d1)); - d1 = MkIntTerm(ArityOfFunctor((Functor) d1)); + d0 = MkAtomTerm(NameOfFunctor((Functor)d1)); + d1 = MkIntTerm(ArityOfFunctor((Functor)d1)); } - } - else if (IsPairTerm(d0)) { + } else if (IsPairTerm(d0)) { d0 = TermDot; d1 = MkIntTerm(2); - } - else { + } else { d1 = MkIntTerm(0); } /* d1 and d0 now have the two arguments */ @@ -3687,7 +3196,8 @@ if (d0 != d1) { FAIL(); } - /* I have to this here so that I don't have a jump to a closing bracket */ + /* I have to this here so that I don't have a jump to a closing bracket + */ d0 = arity; goto func_bind_x3; @@ -3695,7 +3205,8 @@ deref_body(d1, pt0, func_nvar_unk, func_nvar_nvar); /* A2 is a variable, go and bind it */ YapBind(pt0, d0); - /* I have to this here so that I don't have a jump to a closing bracket */ + /* I have to this here so that I don't have a jump to a closing bracket + */ d0 = arity; ENDP(pt0); func_bind_x3: @@ -3708,20 +3219,18 @@ FAIL(); } /* Done */ - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, e),Osbmp),l); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, e), Osbmp), l); GONext(); BEGP(pt0); deref_body(d1, pt0, func_nvar3_unk, func_nvar3_nvar); /* A3 is a variable, go and bind it */ - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, e),Osbmp),l); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, e), Osbmp), l); YapBind(pt0, d0); /* Done */ GONext(); - ENDP(pt0); - } ENDD(d1); @@ -3741,78 +3250,65 @@ if (IsIntTerm(d1)) d1 = IntOfTerm(d1); else { - saveregs(); - Yap_Error(TYPE_ERROR_INTEGER,ARG3,"functor/3"); - setregs(); + Yap_AsmError(TYPE_ERROR_INTEGER); FAIL(); } if (!IsAtomicTerm(d0)) { - saveregs(); - Yap_Error(TYPE_ERROR_ATOM,d0,"functor/3"); - setregs(); + Yap_AsmError(TYPE_ERROR_ATOM); FAIL(); - } /* We made it!!!!! we got in d0 the name, in d1 the arity and - * in pt0 the variable to bind it to. */ + } /* We made it!!!!! we got in d0 the name, in d1 the arity and + * in pt0 the variable to bind it to. */ if (d0 == TermDot && d1 == 2) { RESET_VARIABLE(HR); - RESET_VARIABLE(HR+1); + RESET_VARIABLE(HR + 1); d0 = AbsPair(HR); HR += 2; - } - else if ((Int)d1 > 0) { + } else if ((Int)d1 > 0) { /* now let's build a compound term */ - if (!IsAtomTerm(d0)) { - saveregs(); - Yap_Error(TYPE_ERROR_ATOM,d0,"functor/3"); - setregs(); - FAIL(); - } - BEGP(pt1); - if (!IsAtomTerm(d0)) { - FAIL(); - } - else - d0 = (CELL) Yap_MkFunctor(AtomOfTerm(d0), (Int) d1); - pt1 = HR; - *pt1++ = d0; - d0 = AbsAppl(HR); - if (pt1+d1 > ENV || pt1+d1 > (CELL *)B) { - /* make sure we have something to show for our trouble */ - saveregs(); - if (!Yap_gcl((1+d1)*sizeof(CELL), 3, YREG, NEXTOP(NEXTOP(PREG,e),Osbmp))) { - Yap_NilError(RESOURCE_ERROR_STACK,LOCAL_ErrorMessage); - setregs(); - JMPNext(); - } else { - setregs(); - } - goto restart_functor; /* */ - } - while ((Int)d1--) { - RESET_VARIABLE(pt1); - pt1++; - } - /* done building the term */ - HR = pt1; - ENDP(pt1); - } else if ((Int)d1 < 0) { - saveregs(); - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO,MkIntegerTerm(d1),"functor/3"); - setregs(); - FAIL(); + if (!IsAtomTerm(d0)) { + Yap_AsmError(TYPE_ERROR_ATOM); + FAIL(); + } + BEGP(pt1); + if (!IsAtomTerm(d0)) { + FAIL(); + } else + d0 = (CELL)Yap_MkFunctor(AtomOfTerm(d0), (Int)d1); + pt1 = HR; + *pt1++ = d0; + d0 = AbsAppl(HR); + if (pt1 + d1 > ENV || pt1 + d1 > (CELL *)B) { + /* make sure we have something to show for our trouble */ + saveregs(); + if (!Yap_gcl((1 + d1) * sizeof(CELL), 3, YREG, + NEXTOP(NEXTOP(PREG, e), Osbmp))) { + setregs(); + Yap_AsmError(RESOURCE_ERROR_STACK); + } else { + setregs(); + } + goto restart_functor; /* */ + } + while ((Int)d1--) { + RESET_VARIABLE(pt1); + pt1++; + } + /* done building the term */ + HR = pt1; + ENDP(pt1); + } else if ((Int)d1 < 0) { + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); + FAIL(); } /* else if arity is 0 just pass d0 through */ /* Ding, ding, we made it */ - PREG = NEXTOP(NEXTOP(NEXTOP(PREG, e),Osbpp),l); + PREG = NEXTOP(NEXTOP(NEXTOP(PREG, e), Osbpp), l); YapBind(pt0, d0); GONext(); - BEGP(pt1); deref_body(d1, pt1, func_var_3unk, func_var_3nvar); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d1, "functor/3"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt1); /* Oops, third argument was unbound */ FAIL(); @@ -3820,13 +3316,10 @@ BEGP(pt1); deref_body(d0, pt1, func_var_2unk, func_var_2nvar); - saveregs(); - Yap_Error(INSTANTIATION_ERROR, d0, "functor/3"); - setregs(); + Yap_AsmError(INSTANTIATION_ERROR); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); ENDP(pt0); ENDD(d0); ENDOp(); - diff --git a/C/save.c b/C/save.c index a30849ef2..5e3326316 100755 --- a/C/save.c +++ b/C/save.c @@ -165,9 +165,11 @@ static Int do_SYSTEM_ERROR_INTERNAL(yap_error_number etype, const char *msg) { CACHE_REGS + LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE+1); #if HAVE_SNPRINTF #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 snprintf(LOCAL_ErrorSay,MAX_ERROR_MSG_SIZE,"%s, (system error %d when reading %s)",msg,errno,LOCAL_FileNameBuf); #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); #endif #endif - LOCAL_ErrorMessage = LOCAL_ErrorSay; LOCAL_Error_TYPE = etype; return -1; } @@ -685,8 +686,7 @@ check_header(CELL *info, CELL *ATrail, CELL *AStack, CELL *AHeap USES_REGS) } } if (strcmp(pp, msg) != 0) { - LOCAL_ErrorMessage = LOCAL_ErrorSay; - strncpy(LOCAL_ErrorMessage, "saved state ", MAX_ERROR_MSG_SIZE); + strncpy(LOCAL_ErrorMessage, "saved state ", 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); LOCAL_Error_TYPE = SYSTEM_ERROR_SAVED_STATE; diff --git a/C/scanner.c b/C/scanner.c index 1f54342e0..a5b5cd2a7 100755 --- a/C/scanner.c +++ b/C/scanner.c @@ -1192,8 +1192,7 @@ Term Yap_scan_num(StreamDesc *inp) { ef->TokNext = NULL; LOCAL_tokptr = tokptr; LOCAL_toktide = e; - LOCAL_ErrorMessage = NULL; - LOCAL_Error_Term = Yap_syntax_error(e, inp - GLOBAL_Stream); + LOCAL_ErrorMessage = Yap_syntax_error(e, inp - GLOBAL_Stream); LOCAL_Error_TYPE = SYNTAX_ERROR; } } diff --git a/C/stack.c b/C/stack.c index 21a5ef335..e8a6ec09e 100644 --- a/C/stack.c +++ b/C/stack.c @@ -1074,40 +1074,40 @@ bool set_clause_info(yamop *codeptr, PredEntry *pp) { Term ts[2]; void *begin; if (pp->ArityOfPE == 0) { - LOCAL_ActiveError.prologPredName = (Atom)pp->FunctorOfPred; - LOCAL_ActiveError.prologPredArity = 0; + LOCAL_ActiveError->prologPredName = (Atom)pp->FunctorOfPred; + LOCAL_ActiveError->prologPredArity = 0; } else { - LOCAL_ActiveError.prologPredName = NameOfFunctor(pp->FunctorOfPred); - LOCAL_ActiveError.prologPredArity = pp->ArityOfPE; + LOCAL_ActiveError->prologPredName = NameOfFunctor(pp->FunctorOfPred); + LOCAL_ActiveError->prologPredArity = pp->ArityOfPE; } - LOCAL_ActiveError.prologPredModule = + LOCAL_ActiveError->prologPredModule = (pp->ModuleOfPred ? pp->ModuleOfPred : TermProlog); - LOCAL_ActiveError.prologPredFile = pp->src.OwnerFile; + LOCAL_ActiveError->prologPredFile = pp->src.OwnerFile; if (codeptr->opc == UNDEF_OPCODE) { - LOCAL_ActiveError.prologPredFirstLine = 0; - LOCAL_ActiveError.prologPredLine = 0; - LOCAL_ActiveError.prologPredLastLine = 0; + LOCAL_ActiveError->prologPredFirstLine = 0; + LOCAL_ActiveError->prologPredLine = 0; + LOCAL_ActiveError->prologPredLastLine = 0; return true; } else if (pp->cs.p_code.NOfClauses) { - if ((LOCAL_ActiveError.prologPredCl = + if ((LOCAL_ActiveError->prologPredCl = find_code_in_clause(pp, codeptr, &begin, NULL)) <= 0) { - LOCAL_ActiveError.prologPredLine = 0; + LOCAL_ActiveError->prologPredLine = 0; } else { - LOCAL_ActiveError.prologPredLine = IntegerOfTerm(clause_loc(begin, pp)); + LOCAL_ActiveError->prologPredLine = IntegerOfTerm(clause_loc(begin, pp)); } if (pp->PredFlags & LogUpdatePredFlag) { - LOCAL_ActiveError.prologPredFirstLine = IntegerOfTerm( + LOCAL_ActiveError->prologPredFirstLine = IntegerOfTerm( ts[0] = clause_loc( 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), pp)); } else { - LOCAL_ActiveError.prologPredFirstLine = IntegerOfTerm( + LOCAL_ActiveError->prologPredFirstLine = IntegerOfTerm( ts[0] = clause_loc( 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), pp)); } diff --git a/C/text.c b/C/text.c index dce99663f..802fbda14 100644 --- a/C/text.c +++ b/C/text.c @@ -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) #endif -void *buf__, *cur__; +#ifndef MAX_PATHHNAME +#define MAX_PATHHNAME 1024 +#endif -#define init_alloc(I) \ - void *ov__ = TR, *ocur__ = LOCAL_ScannerStack; \ - if (!LOCAL_ScannerStack) \ - LOCAL_ScannerStack = (char *)TR - -#define mark_stack() \ - void *otr__ = TR; \ - 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; +void +Yap_InitTextAllocator( void ) +{ + struct TextBuffer_manager *new = malloc(sizeof(struct TextBuffer_manager)+MAX_PATHHNAME*2 ); + new->prev = NULL; + new->ptr = new->buf = (struct TextBuffer_manager *)new+1; + LOCAL_TextBuffer = new; } 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; n = SkipListCodes(&bufc, &t, &r, atoms, widep, inp PASS_REGS); if (n < 0) { - LOCAL_Error_TYPE = -n; - LOCAL_Error_Term = *r; return NULL; } *lenp = n; @@ -319,7 +288,6 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) { YAP_STRING_BIG)) == inp->type) { LOCAL_Error_TYPE = TYPE_ERROR_NUMBER; } - LOCAL_Error_Term = inp->val.t; } } 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; else 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) { - AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), s, char); + AUX_ERROR(inp->val.t, 2 * (MAX_PATHNAME), s, char); } *lengp = strlen(s); Malloc(*lengp); diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp index 96ad0815f..a677d4cf7 100644 --- a/CXX/yapi.cpp +++ b/CXX/yapi.cpp @@ -612,12 +612,15 @@ Term YAPEngine::fun(Term t) { } else if (IsAtomTerm(t)) { name = AtomOfTerm(t); f = nullptr; - } else if (IsAtomTerm(t)) { + } else if (IsPairTerm(t)) { XREGS[1] = ts[0]; XREGS[2] = ts[1]; name = AtomDot; f = FunctorDot; - } + } else { + Yap_Error(TYPE_ERROR_CALLABLE, t, 0); + return 0L; + } XREGS[arity+1] = MkVarTerm(); arity ++; f = Yap_MkFunctor(name,arity); @@ -1027,37 +1030,37 @@ const char *YAPError::text() { char buf[256]; std::string s = ""; - if (LOCAL_ActiveError.errorFunction) { - s += LOCAL_ActiveError.errorFile; + if (LOCAL_ActiveError->errorFunction) { + s += LOCAL_ActiveError->errorFile; s += ":"; - sprintf(buf, "%ld", (long int)LOCAL_ActiveError.errorLine); + sprintf(buf, "%ld", (long int)LOCAL_ActiveError->errorLine); s += buf; s += ":0 in C-code"; } - if (LOCAL_ActiveError.prologPredLine) { + if (LOCAL_ActiveError->prologPredLine) { s += "\n"; - s += LOCAL_ActiveError.prologPredFile->StrOfAE; + s += LOCAL_ActiveError->prologPredFile->StrOfAE; s += ":"; - sprintf(buf, "%ld", (long int)LOCAL_ActiveError.prologPredLine); - s += buf; // std::to_string(LOCAL_ActiveError.prologPredLine) ; - // YAPIntegerTerm(LOCAL_ActiveError.prologPredLine).text(); + sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredLine); + s += buf; // std::to_string(LOCAL_ActiveError->prologPredLine) ; + // YAPIntegerTerm(LOCAL_ActiveError->prologPredLine).text(); s += ":0 "; - s += LOCAL_ActiveError.prologPredModule; + s += LOCAL_ActiveError->prologPredModule; s += ":"; - s += (LOCAL_ActiveError.prologPredName)->StrOfAE; + s += (LOCAL_ActiveError->prologPredName)->StrOfAE; s += "/"; - sprintf(buf, "%ld", (long int)LOCAL_ActiveError.prologPredArity); - s += // std::to_string(LOCAL_ActiveError.prologPredArity); + sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredArity); + s += // std::to_string(LOCAL_ActiveError->prologPredArity); buf; } s += " error "; - if (LOCAL_ActiveError.classAsText != nullptr) - s += LOCAL_ActiveError.classAsText->StrOfAE; + if (LOCAL_ActiveError->classAsText != nullptr) + s += LOCAL_ActiveError->classAsText->StrOfAE; s += "."; - s += LOCAL_ActiveError.errorAsText->StrOfAE; + s += LOCAL_ActiveError->errorAsText->StrOfAE; s += ".\n"; - if (LOCAL_ActiveError.errorTerm) { - Term t = Yap_PopTermFromDB(LOCAL_ActiveError.errorTerm); + if (LOCAL_ActiveError->errorTerm) { + Term t = Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm); if (t) { s += "error term is: "; s += YAPTerm(t).text(); diff --git a/CXX/yapie.hh b/CXX/yapie.hh index f85723bb9..1c425cc8e 100644 --- a/CXX/yapie.hh +++ b/CXX/yapie.hh @@ -15,17 +15,17 @@ public: YAPError(){}; /// we just know the error number /// exact error ID - yap_error_number getID() { return LOCAL_ActiveError.errorNo; }; + yap_error_number getID() { return LOCAL_ActiveError->errorNo; }; /// class of error yap_error_class_number getErrorClass() { - return Yap_errorClass(LOCAL_ActiveError.errorNo); + return Yap_errorClass(LOCAL_ActiveError->errorNo); }; /// where in the code things happened; - const char *getFile() { return LOCAL_ActiveError.errorFile; }; + const char *getFile() { return LOCAL_ActiveError->errorFile; }; /// predicate things happened; - Int getLine() { return LOCAL_ActiveError.errorLine; }; + Int getLine() { return LOCAL_ActiveError->errorLine; }; /// the term that caused the bug - // YAPTerm getCulprit(LOCAL_ActiveError.errorFile){}; + // YAPTerm getCulprit(LOCAL_ActiveError->errorFile){}; /// text describing the Error const char *text(); }; diff --git a/CXX/yapq.hh b/CXX/yapq.hh index 3304e82c5..247507754 100644 --- a/CXX/yapq.hh +++ b/CXX/yapq.hh @@ -183,9 +183,16 @@ public: bool goalt(YAPTerm t); /// current directory for the engine bool goal(Term t); -#if SWIGPYTHON - bool unlockedGoal(Term t) {bool rc;Py_BEGIN_ALLOW_THREADS; rc = goal(t);Py_END_ALLOW_THREADS; return rc; } + bool unlockedGoal(Term t) {bool rc; +#ifdef SWIGPYTHON + Py_BEGIN_ALLOW_THREADS; #endif + rc = goal(t); +#ifdef SWIGPYTHON + Py_END_ALLOW_THREADS; +#endif + return rc; + } /// reset Prolog state void reSet(); /// release: assune that there are no stack pointers, just release memory diff --git a/H/LOCALS b/H/LOCALS index 7a4af0fdf..26ad866d9 100755 --- a/H/LOCALS +++ b/H/LOCALS @@ -79,7 +79,6 @@ UInt GlobalArenaOverflows =0L Int ArenaOverflows =0L Int DepthArenas =0 -int ArithError =FALSE struct pred_entry* LastAssertedPred =NULL struct pred_entry* TmpPred =NULL char* ScannerStack =NULL @@ -194,13 +193,10 @@ ADDR LocalBase void ADDR GlobalBase void ADDR TrailBase void ADDR TrailTop void -char* ErrorMessage void -Term Error_Term void -/** error handling info, designed to be easy to pass to the foreign world */ -struct yap_error_descriptor ActiveError void +/* error handling info, designed to be easy to pass to the foreign world */ +yap_error_descriptor_t* ActiveError =calloc(sizeof(yap_error_descriptor_t),1) /// pointer to an exception term, from throw -struct DB_TERM* BallTerm =NULL jmp_buf IOBotch void TokEntry* tokptr void @@ -217,6 +213,8 @@ sigjmp_buf RestartEnv void char FileNameBuf[YAP_FILENAME_MAX+1] void char FileNameBuf2[YAP_FILENAME_MAX+1] void +struct TextBuffer_manager* TextBuffer =Yap_InitTextAllocator() + // Prolog State UInt BreakLevel =0 Int PrologMode =BootMode @@ -237,10 +235,8 @@ YAP_ULONG_LONG 2opcount[_std_top+1][_std_top+1] void struct db_globs* s_dbg void //eval.c -yap_error_number matherror =YAP_NO_ERROR Term mathtt void char* mathstring =NULL -yap_error_number CurrentError =YAP_NO_ERROR //grow.c int heap_overflows =0 diff --git a/H/YapText.h b/H/YapText.h index 7c8d2140f..7a2352031 100644 --- a/H/YapText.h +++ b/H/YapText.h @@ -31,6 +31,48 @@ #include "../utf8proc/utf8proc.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 definition table **************************/ diff --git a/H/absmi.h b/H/absmi.h index d103ee25a..b36ea254a 100755 --- a/H/absmi.h +++ b/H/absmi.h @@ -99,7 +99,8 @@ register struct yami *P1REG asm("bp"); /* can't use yamop before Yap.h */ #define LIMITED_PREFETCH 1 #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 S_IN_MEM 1 @@ -215,13 +216,13 @@ INLINE_ONLY inline EXTERN void restore_absmi_regs(REGSTORE *old_regs) { #define BEGP(TMP) \ { \ - register CELL *TMP + register CELL *TMP #define ENDP(TMP) } #define BEGD(TMP) \ { \ - register CELL TMP + register CELL TMP #define ENDD(TMP) } @@ -229,7 +230,7 @@ INLINE_ONLY inline EXTERN void restore_absmi_regs(REGSTORE *old_regs) { #define BEGCHO(TMP) \ { \ - register choiceptr TMP + register choiceptr TMP #define ENDCHO(TMP) } @@ -242,7 +243,7 @@ INLINE_ONLY inline EXTERN void restore_absmi_regs(REGSTORE *old_regs) { #define CACHE_Y(A) \ { \ - register CELL *S_YREG = ((CELL *)(A)) + register CELL *S_YREG = ((CELL *)(A)) #define ENDCACHE_Y() \ YREG = S_YREG; \ @@ -258,7 +259,7 @@ INLINE_ONLY inline EXTERN void restore_absmi_regs(REGSTORE *old_regs) { #define CACHE_Y(A) \ { \ - YREG = ((CELL *)(A)) + YREG = ((CELL *)(A)) #define ENDCACHE_Y() } @@ -268,7 +269,7 @@ INLINE_ONLY inline EXTERN void restore_absmi_regs(REGSTORE *old_regs) { #define CACHE_Y_AS_ENV(A) \ { \ - register CELL *ENV_YREG = (A) + register CELL *ENV_YREG = (A) #define FETCH_Y_FROM_ENV(A) ENV_YREG = (A) @@ -292,7 +293,7 @@ INLINE_ONLY inline EXTERN void restore_absmi_regs(REGSTORE *old_regs) { #define CACHE_Y_AS_ENV(A) \ { \ - YREG = (A) + YREG = (A) #define FETCH_Y_FROM_ENV(A) (A) @@ -345,7 +346,7 @@ INLINE_ONLY inline EXTERN void restore_absmi_regs(REGSTORE *old_regs) { #define CACHE_TR(A) \ { \ - register tr_fr_ptr S_TR = (A) + register tr_fr_ptr S_TR = (A) #define RESTORE_TR() TR = S_TR @@ -467,7 +468,7 @@ INLINE_ONLY inline EXTERN void restore_absmi_regs(REGSTORE *old_regs) { #define ALWAYS_START_PREFETCH(TYPE) \ { \ register void *to_go; \ - DO_PREFETCH(TYPE) + DO_PREFETCH(TYPE) #if YAP_JIT #define ALWAYS_LOOKAHEAD(WHAT) \ @@ -487,7 +488,7 @@ INLINE_ONLY inline EXTERN void restore_absmi_regs(REGSTORE *old_regs) { #define ALWAYS_START_PREFETCH_W(TYPE) \ { \ register void *to_go; \ - DO_PREFETCH_W(TYPE) + DO_PREFETCH_W(TYPE) #else @@ -909,14 +910,14 @@ INLINE_ONLY inline EXTERN void restore_absmi_regs(REGSTORE *old_regs) { (ExpEnv.config_struc.current_displacement) \ ? print_instruction(PREG, ON_PROFILED_INTERPRETER) \ : print_instruction(PREG, ON_INTERPRETER); \ - START_PREFETCH(Type) + START_PREFETCH(Type) #define OpW(Label, Type) \ _##Label : { \ (ExpEnv.config_struc.current_displacement) \ ? print_instruction(PREG, ON_PROFILED_INTERPRETER) \ : print_instruction(PREG, ON_INTERPRETER); \ - START_PREFETCH_W(Type) + START_PREFETCH_W(Type) #define BOp(Label, Type) \ _##Label : { \ @@ -929,7 +930,7 @@ INLINE_ONLY inline EXTERN void restore_absmi_regs(REGSTORE *old_regs) { (ExpEnv.config_struc.current_displacement) \ ? print_instruction(PREG, ON_PROFILED_INTERPRETER) \ : print_instruction(PREG, ON_INTERPRETER); \ - INIT_PREFETCH() + INIT_PREFETCH() #define OpRW(Label, Type) \ _##Label : { \ @@ -942,12 +943,12 @@ INLINE_ONLY inline EXTERN void restore_absmi_regs(REGSTORE *old_regs) { #define Op(Label, Type) \ _##Label : { \ print_instruction(PREG, ON_INTERPRETER); \ - START_PREFETCH(Type) + START_PREFETCH(Type) #define OpW(Label, Type) \ _##Label : { \ print_instruction(PREG, ON_INTERPRETER); \ - START_PREFETCH_W(Type) + START_PREFETCH_W(Type) #define BOp(Label, Type) \ _##Label : { \ @@ -956,7 +957,7 @@ INLINE_ONLY inline EXTERN void restore_absmi_regs(REGSTORE *old_regs) { #define PBOp(Label, Type) \ _##Label : { \ print_instruction(PREG, ON_INTERPRETER); \ - INIT_PREFETCH() + INIT_PREFETCH() #define OpRW(Label, Type) \ _##Label : { \ @@ -968,17 +969,17 @@ INLINE_ONLY inline EXTERN void restore_absmi_regs(REGSTORE *old_regs) { #define Op(Label, Type) \ _##Label : { \ - START_PREFETCH(Type) + START_PREFETCH(Type) #define OpW(Label, Type) \ _##Label : { \ - START_PREFETCH_W(Type) + START_PREFETCH_W(Type) #define BOp(Label, Type) _##Label : { #define PBOp(Label, Type) \ _##Label : { \ - INIT_PREFETCH() + INIT_PREFETCH() #define OpRW(Label, Type) _##Label : { @@ -1000,17 +1001,17 @@ INLINE_ONLY inline EXTERN void restore_absmi_regs(REGSTORE *old_regs) { #define Op(Label, Type) \ case _##Label: { \ - START_PREFETCH(Type) + START_PREFETCH(Type) #define OpW(Label, Type) \ case _##Label: { \ - START_PREFETCH_W(Type) + START_PREFETCH_W(Type) #define BOp(Label, Type) case _##Label: { #define PBOp(Label, Type) \ case _##Label: { \ - INIT_PREFETCH() + INIT_PREFETCH() #define OpRW(Label, Type) case _##Label: { @@ -2075,7 +2076,8 @@ cufail: #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, register CELL *pt1) { @@ -2450,4 +2452,11 @@ extern yamop *headoftrace; ENDD(d0); #endif +#define Yap_AsmError(e) \ + { \ + saveregs(); \ + Yap_Error(e, 0, ""); \ + setregs(); \ + } + #endif // ABSMI_H diff --git a/H/eval.h b/H/eval.h index 81be993d7..2d670f6d1 100644 --- a/H/eval.h +++ b/H/eval.h @@ -375,6 +375,7 @@ Functor EvalArg(Term); eval_flt = (F); \ return (FFloat); \ } + #define REvalError() \ { return (FError); } @@ -407,8 +408,12 @@ yamop *Yap_EvalError__(const char *, const char *, int, yap_error_number, Term, #define Yap_ArithError(id, t, ...) \ 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" @@ -429,7 +434,7 @@ INLINE_ONLY inline EXTERN Term Yap_Eval__(Term t USES_REGS) { #if HAVE_FECLEAREXCEPT inline static void Yap_ClearExs(void) { feclearexcept(FE_ALL_EXCEPT); } #else -inline static void Yap_ClearExs(void) { } +inline static void Yap_ClearExs(void) {} #endif inline static yap_error_number Yap_FoundArithError__(USES_REGS1) { @@ -463,7 +468,11 @@ Atom Yap_NameOfBinaryOp(int i); #define RINT(v) return (MkIntegerTerm(v)) #define RFLOAT(v) return (MkFloatTerm(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) { if (IsIntTerm(t)) diff --git a/H/generated/dlocals.h b/H/generated/dlocals.h index 9f9ac0a5d..2034b0403 100644 --- a/H/generated/dlocals.h +++ b/H/generated/dlocals.h @@ -121,8 +121,6 @@ #define REMOTE_ArenaOverflows(wid) REMOTE(wid)->ArenaOverflows_ #define LOCAL_DepthArenas LOCAL->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 REMOTE_LastAssertedPred(wid) REMOTE(wid)->LastAssertedPred_ #define LOCAL_TmpPred LOCAL->TmpPred_ @@ -288,16 +286,10 @@ #define REMOTE_TrailBase(wid) REMOTE(wid)->TrailBase_ #define LOCAL_TrailTop LOCAL->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 REMOTE_ActiveError(wid) REMOTE(wid)->ActiveError_ -#define LOCAL_BallTerm LOCAL->BallTerm_ -#define REMOTE_BallTerm(wid) REMOTE(wid)->BallTerm_ #define LOCAL_IOBotch LOCAL->IOBotch_ #define REMOTE_IOBotch(wid) REMOTE(wid)->IOBotch_ #define LOCAL_tokptr LOCAL->tokptr_ @@ -326,6 +318,8 @@ #define REMOTE_FileNameBuf(wid) REMOTE(wid)->FileNameBuf_ #define LOCAL_FileNameBuf2 LOCAL->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 REMOTE_BreakLevel(wid) REMOTE(wid)->BreakLevel_ @@ -350,14 +344,10 @@ #define LOCAL_s_dbg LOCAL->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 REMOTE_mathtt(wid) REMOTE(wid)->mathtt_ #define LOCAL_mathstring LOCAL->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 REMOTE_heap_overflows(wid) REMOTE(wid)->heap_overflows_ diff --git a/H/generated/hlocals.h b/H/generated/hlocals.h index 9e0474a25..46a00dad4 100644 --- a/H/generated/hlocals.h +++ b/H/generated/hlocals.h @@ -69,7 +69,6 @@ typedef struct worker_local { UInt GlobalArenaOverflows_; Int ArenaOverflows_; Int DepthArenas_; - int ArithError_; struct pred_entry* LastAssertedPred_; struct pred_entry* TmpPred_; char* ScannerStack_; @@ -164,12 +163,9 @@ typedef struct worker_local { ADDR GlobalBase_; ADDR TrailBase_; ADDR TrailTop_; - char* ErrorMessage_; - Term Error_Term_; -/** error handling info, designed to be easy to pass to the foreign world */ - struct yap_error_descriptor ActiveError_; +/* error handling info, designed to be easy to pass to the foreign world */ + yap_error_descriptor_t* ActiveError_; /// pointer to an exception term, from throw - struct DB_TERM* BallTerm_; jmp_buf IOBotch_; TokEntry* tokptr_; TokEntry* toktide_; @@ -184,6 +180,7 @@ typedef struct worker_local { sigjmp_buf RestartEnv_; char FileNameBuf_[YAP_FILENAME_MAX+1]; char FileNameBuf2_[YAP_FILENAME_MAX+1]; + struct TextBuffer_manager* TextBuffer_; // Prolog State UInt BreakLevel_; Int PrologMode_; @@ -200,10 +197,8 @@ typedef struct worker_local { //dbase.c struct db_globs* s_dbg_; //eval.c - yap_error_number matherror_; Term mathtt_; char* mathstring_; - yap_error_number CurrentError_; //grow.c int heap_overflows_; Int total_heap_overflow_time_; diff --git a/H/generated/ilocals.h b/H/generated/ilocals.h index 8dcf95218..2ada8ba04 100755 --- a/H/generated/ilocals.h +++ b/H/generated/ilocals.h @@ -69,7 +69,6 @@ static void InitWorker(int wid) { REMOTE_GlobalArenaOverflows(wid) = 0L; REMOTE_ArenaOverflows(wid) = 0L; REMOTE_DepthArenas(wid) = 0; - REMOTE_ArithError(wid) = FALSE; REMOTE_LastAssertedPred(wid) = NULL; REMOTE_TmpPred(wid) = NULL; REMOTE_ScannerStack(wid) = NULL; @@ -165,11 +164,7 @@ static void InitWorker(int wid) { - - - - - REMOTE_BallTerm(wid) = NULL; + REMOTE_ActiveError(wid) = calloc(sizeof(yap_error_descriptor_t),1); @@ -185,6 +180,8 @@ static void InitWorker(int wid) { + REMOTE_TextBuffer(wid) = Yap_InitTextAllocator(); + REMOTE_BreakLevel(wid) = 0; REMOTE_PrologMode(wid) = BootMode; REMOTE_CritLocks(wid) = 0; @@ -200,10 +197,8 @@ static void InitWorker(int wid) { - REMOTE_matherror(wid) = YAP_NO_ERROR; REMOTE_mathstring(wid) = NULL; - REMOTE_CurrentError(wid) = YAP_NO_ERROR; REMOTE_heap_overflows(wid) = 0; REMOTE_total_heap_overflow_time(wid) = 0; diff --git a/H/generated/rlocals.h b/H/generated/rlocals.h index cbdfa2b80..77f95bc68 100644 --- a/H/generated/rlocals.h +++ b/H/generated/rlocals.h @@ -86,7 +86,6 @@ static void RestoreWorker(int wid USES_REGS) { - #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 #endif diff --git a/H/walkclause.h b/H/walkclause.h index 20a25fc2c..0252df004 100644 --- a/H/walkclause.h +++ b/H/walkclause.h @@ -1,748 +1,746 @@ - - /* This file was generated automatically by "yap -L misc/buildops" +/* This file was generated automatically by "yap -L misc/buildops" please do not update */ +while (TRUE) { + op_numbers op; - while (TRUE) { - op_numbers op; - - op = Yap_op_from_opcode(pc->opc); - /* C-code, maybe indexing */ - switch (op) { - /* instructions type D */ - case _write_dbterm: - pc = NEXTOP(pc,D); - break; - /* instructions type Illss */ - case _enter_lu_pred: - return walk_got_lu_block(pc->y_u.Illss.I, startp, endp); - /* instructions type J */ + op = Yap_op_from_opcode(pc->opc); + /* C-code, maybe indexing */ + switch (op) { + /* instructions type D */ + case _write_dbterm: + pc = NEXTOP(pc, D); + break; + /* instructions type Illss */ + case _enter_lu_pred: + return walk_got_lu_block(pc->y_u.Illss.I, startp, endp); +/* instructions type J */ #ifdef YAP_JIT - case _jit_handler: + case _jit_handler: #endif - pc = NEXTOP(pc,J); - break; - /* instructions type L */ - case _alloc_for_logical_pred: - return walk_got_lu_clause(pc->y_u.L.ClBase, startp, endp); - /* instructions type N */ - case _write_bigint: - pc = NEXTOP(pc,N); - break; - /* instructions type Osblp */ - case _either: - case _or_else: - clause_code = TRUE; - pp = pc->y_u.Osblp.p0; - pc = NEXTOP(pc,Osblp); - break; - /* instructions type Osbmp */ - case _p_execute: - case _p_execute_tail: - pc = NEXTOP(pc,Osbmp); - break; - /* instructions type Osbpa */ - case _ensure_space: - pc = NEXTOP(pc,Osbpa); - break; - /* instructions type Osbpp */ - case _call_cpred: - pp = pc->y_u.Osbpp.p; - return walk_found_c_pred(pp, startp, endp); - case _call_usercpred: - pp = pc->y_u.Osbpp.p; - return walk_found_c_pred(pp, startp, endp); - case _p_execute2: - return found_meta_call(startp, endp); - case _call: - case _fcall: - clause_code = TRUE; - pp = pc->y_u.Osbpp.p0; - pc = NEXTOP(pc,Osbpp); - break; - /* instructions type OtILl */ - case _count_trust_logical: - case _profiled_trust_logical: - case _trust_logical: - return walk_got_lu_block(pc->y_u.OtILl.block, startp, endp); - /* instructions type OtaLl */ - case _count_retry_logical: - case _profiled_retry_logical: - case _retry_logical: - case _try_logical: - pc = pc->y_u.OtaLl.n; - break; - /* instructions type OtapFs */ - case _cut_c: - case _cut_userc: - case _retry_c: - case _retry_userc: - case _try_c: - case _try_userc: - clause_code = TRUE; - pp = pc->y_u.OtapFs.p; - pc = NEXTOP(pc,OtapFs); - break; - /* instructions type Otapl */ - case _count_retry_and_mark: - case _count_retry_me: - case _count_trust_me: - case _profiled_retry_and_mark: - case _profiled_retry_me: - case _profiled_trust_me: - case _retry: - case _retry_and_mark: - case _retry_me: - case _spy_or_trymark: - case _trust: - case _trust_me: - case _try_and_mark: - case _try_clause: - case _try_me: - clause_code = FALSE; - pp = pc->y_u.Otapl.p; - pc = NEXTOP(pc,Otapl); - break; - /* instructions type c */ - case _write_atom: - pc = NEXTOP(pc,c); - break; - /* instructions type cc */ - case _get_2atoms: - pc = NEXTOP(pc,cc); - break; - /* instructions type ccc */ - case _get_3atoms: - pc = NEXTOP(pc,ccc); - break; - /* instructions type cccc */ - case _get_4atoms: - pc = NEXTOP(pc,cccc); - break; - /* instructions type ccccc */ - case _get_5atoms: - pc = NEXTOP(pc,ccccc); - break; - /* instructions type cccccc */ - case _get_6atoms: - pc = NEXTOP(pc,cccccc); - break; - /* instructions type clll */ - case _if_not_then: - pc = NEXTOP(pc,clll); - break; - /* instructions type d */ - case _write_float: - pc = NEXTOP(pc,d); - break; - /* instructions type e */ - case _Nstop: - return NULL; - case _copy_idb_term: - return found_idb_clause(pc, startp, endp); - case _expand_index: - return found_expand(pc, startp, endp PASS_REGS); - case _index_pred: - return found_owner_op(pc, startp, endp PASS_REGS); - case _lock_pred: - return found_owner_op(pc, startp, endp PASS_REGS); - case _op_fail: - if (codeptr == FAILCODE) - return found_fail(pc, startp, endp PASS_REGS); - pc = NEXTOP(pc,e); - break; - case _spy_pred: - return found_owner_op(pc, startp, endp PASS_REGS); - case _trust_fail: - if (codeptr == TRUSTFAILCODE) - return found_fail(pc, startp, endp PASS_REGS); - pc = NEXTOP(pc,e); - break; - case _undef_p: - return found_owner_op(pc, startp, endp PASS_REGS); - case _unify_idb_term: - return found_idb_clause(pc, startp, endp); - case _allocate: - case _enter_exo: - case _index_blob: - case _index_dbref: - case _index_long: - case _p_equal: - case _p_functor: - case _pop: + pc = NEXTOP(pc, J); + break; + /* instructions type L */ + case _alloc_for_logical_pred: + return walk_got_lu_clause(pc->y_u.L.ClBase, startp, endp); + /* instructions type N */ + case _write_bigint: + pc = NEXTOP(pc, N); + break; + /* instructions type Osblp */ + case _either: + case _or_else: + clause_code = TRUE; + pp = pc->y_u.Osblp.p0; + pc = NEXTOP(pc, Osblp); + break; + /* instructions type Osbmp */ + case _p_execute: + case _p_execute_tail: + pc = NEXTOP(pc, Osbmp); + break; + /* instructions type Osbpa */ + case _ensure_space: + pc = NEXTOP(pc, Osbpa); + break; + /* instructions type Osbpp */ + case _call_cpred: + pp = pc->y_u.Osbpp.p; + return walk_found_c_pred(pp, startp, endp); + case _call_usercpred: + pp = pc->y_u.Osbpp.p; + return walk_found_c_pred(pp, startp, endp); + case _p_execute2: + return found_meta_call(startp, endp); + case _call: + case _fcall: + clause_code = TRUE; + pp = pc->y_u.Osbpp.p0; + pc = NEXTOP(pc, Osbpp); + break; + /* instructions type OtILl */ + case _count_trust_logical: + case _profiled_trust_logical: + case _trust_logical: + return walk_got_lu_block(pc->y_u.OtILl.block, startp, endp); + /* instructions type OtaLl */ + case _count_retry_logical: + case _profiled_retry_logical: + case _retry_logical: + case _try_logical: + pc = pc->y_u.OtaLl.n; + break; + /* instructions type OtapFs */ + case _cut_c: + case _cut_userc: + case _retry_c: + case _retry_userc: + case _try_c: + case _try_userc: + clause_code = TRUE; + pp = pc->y_u.OtapFs.p; + pc = NEXTOP(pc, OtapFs); + break; + /* instructions type Otapl */ + case _count_retry_and_mark: + case _count_retry_me: + case _count_trust_me: + case _profiled_retry_and_mark: + case _profiled_retry_me: + case _profiled_trust_me: + case _retry: + case _retry_and_mark: + case _retry_me: + case _spy_or_trymark: + case _trust: + case _trust_me: + case _try_and_mark: + case _try_clause: + case _try_me: + clause_code = FALSE; + pp = pc->y_u.Otapl.p; + pc = NEXTOP(pc, Otapl); + break; + /* instructions type c */ + case _write_atom: + pc = NEXTOP(pc, c); + break; + /* instructions type cc */ + case _get_2atoms: + pc = NEXTOP(pc, cc); + break; + /* instructions type ccc */ + case _get_3atoms: + pc = NEXTOP(pc, ccc); + break; + /* instructions type cccc */ + case _get_4atoms: + pc = NEXTOP(pc, cccc); + break; + /* instructions type ccccc */ + case _get_5atoms: + pc = NEXTOP(pc, ccccc); + break; + /* instructions type cccccc */ + case _get_6atoms: + pc = NEXTOP(pc, cccccc); + break; + /* instructions type clll */ + case _if_not_then: + pc = NEXTOP(pc, clll); + break; + /* instructions type d */ + case _write_float: + pc = NEXTOP(pc, d); + break; + /* instructions type e */ + case _Nstop: + return NULL; + case _copy_idb_term: + return found_idb_clause(pc, startp, endp); + case _expand_index: + return found_expand(pc, startp, endp PASS_REGS); + case _index_pred: + return found_owner_op(pc, startp, endp PASS_REGS); + case _lock_pred: + return found_owner_op(pc, startp, endp PASS_REGS); + case _op_fail: + if (codeptr == FAILCODE) + return found_fail(pc, startp, endp PASS_REGS); + pc = NEXTOP(pc, e); + break; + case _spy_pred: + return found_owner_op(pc, startp, endp PASS_REGS); + case _trust_fail: + if (codeptr == TRUSTFAILCODE) + return found_fail(pc, startp, endp PASS_REGS); + pc = NEXTOP(pc, e); + break; + case _undef_p: + return found_owner_op(pc, startp, endp PASS_REGS); + case _unify_idb_term: + return found_idb_clause(pc, startp, endp); + case _allocate: + case _enter_exo: + case _index_blob: + case _index_dbref: + case _index_long: + case _p_equal: + case _p_functor: + case _pop: #ifdef BEAM - case _retry_eam: + case _retry_eam: #endif #ifdef THREADS - case _thread_local: + case _thread_local: #endif - case _unlock_lu: - case _write_l_list: - case _write_list: - case _write_void: - pc = NEXTOP(pc,e); - break; - /* instructions type fa */ - case _write_l_struc: - case _write_struct: - pc = NEXTOP(pc,fa); - break; - /* instructions type i */ - case _write_longint: - pc = NEXTOP(pc,i); - break; - /* instructions type l */ - case _Ystop: - return found_ystop(pc, clause_code, startp, endp, pp PASS_REGS); - case _jump: - case _jump_if_var: - case _move_back: + case _unlock_lu: + case _write_l_list: + case _write_list: + case _write_void: + pc = NEXTOP(pc, e); + break; + /* instructions type fa */ + case _write_l_struc: + case _write_struct: + pc = NEXTOP(pc, fa); + break; + /* instructions type i */ + case _write_longint: + pc = NEXTOP(pc, i); + break; + /* instructions type l */ + case _Ystop: + return found_ystop(pc, clause_code, startp, endp, pp PASS_REGS); + case _jump: + case _jump_if_var: + case _move_back: #if INLINE_BIG_COMPARISONS - case _p_dif: - case _p_eq: + case _p_dif: + case _p_eq: #endif - case _retry2: - case _retry3: - case _retry4: - case _skip: - case _try_clause2: - case _try_clause3: - case _try_clause4: - case _try_in: - pc = NEXTOP(pc,l); - break; - /* instructions type llll */ - case _switch_on_type: - pc = NEXTOP(pc,llll); - break; - /* instructions type lp */ - case _retry_all_exo: - case _retry_exo: - case _retry_exo_udi: - case _try_all_exo: - case _try_exo: - case _try_exo_udi: - case _user_switch: - pc = NEXTOP(pc,lp); - break; - /* instructions type o */ - case _unify_l_list: - case _unify_l_list_write: - case _unify_l_void: - case _unify_l_void_write: - case _unify_list: - case _unify_list_write: - case _unify_void: - case _unify_void_write: - pc = NEXTOP(pc,o); - break; - /* instructions type oD */ - case _unify_dbterm: - case _unify_l_dbterm: - pc = NEXTOP(pc,oD); - break; - /* instructions type oN */ - case _unify_bigint: - case _unify_l_bigint: - pc = NEXTOP(pc,oN); - break; - /* instructions type oc */ - case _unify_atom: - case _unify_atom_write: - case _unify_l_atom: - case _unify_l_atom_write: - pc = NEXTOP(pc,oc); - break; - /* instructions type od */ - case _unify_float: - case _unify_float_write: - case _unify_l_float: - case _unify_l_float_write: - pc = NEXTOP(pc,od); - break; - /* instructions type ofa */ - case _unify_l_struc: - case _unify_l_struc_write: - case _unify_struct: - case _unify_struct_write: - pc = NEXTOP(pc,ofa); - break; - /* instructions type oi */ - case _unify_l_longint: - case _unify_l_longint_write: - case _unify_longint: - case _unify_longint_write: - pc = NEXTOP(pc,oi); - break; - /* instructions type ollll */ - case _switch_list_nl: - pc = NEXTOP(pc,ollll); - break; - /* instructions type os */ + case _retry2: + case _retry3: + case _retry4: + case _skip: + case _try_clause2: + case _try_clause3: + case _try_clause4: + case _try_in: + pc = NEXTOP(pc, l); + break; + /* instructions type llll */ + case _switch_on_type: + pc = NEXTOP(pc, llll); + break; + /* instructions type lp */ + case _retry_all_exo: + case _retry_exo: + case _retry_exo_udi: + case _try_all_exo: + case _try_exo: + case _try_exo_udi: + case _user_switch: + pc = NEXTOP(pc, lp); + break; + /* instructions type o */ + case _unify_l_list: + case _unify_l_list_write: + case _unify_l_void: + case _unify_l_void_write: + case _unify_list: + case _unify_list_write: + case _unify_void: + case _unify_void_write: + pc = NEXTOP(pc, o); + break; + /* instructions type oD */ + case _unify_dbterm: + case _unify_l_dbterm: + pc = NEXTOP(pc, oD); + break; + /* instructions type oN */ + case _unify_bigint: + case _unify_l_bigint: + pc = NEXTOP(pc, oN); + break; + /* instructions type oc */ + case _unify_atom: + case _unify_atom_write: + case _unify_l_atom: + case _unify_l_atom_write: + pc = NEXTOP(pc, oc); + break; + /* instructions type od */ + case _unify_float: + case _unify_float_write: + case _unify_l_float: + case _unify_l_float_write: + pc = NEXTOP(pc, od); + break; + /* instructions type ofa */ + case _unify_l_struc: + case _unify_l_struc_write: + case _unify_struct: + case _unify_struct_write: + pc = NEXTOP(pc, ofa); + break; + /* instructions type oi */ + case _unify_l_longint: + case _unify_l_longint_write: + case _unify_longint: + case _unify_longint_write: + pc = NEXTOP(pc, oi); + break; + /* instructions type ollll */ + case _switch_list_nl: + pc = NEXTOP(pc, ollll); + break; +/* instructions type os */ #ifdef BEAM - case _run_eam: + case _run_eam: #endif - case _unify_l_n_voids: - case _unify_l_n_voids_write: - case _unify_n_voids: - case _unify_n_voids_write: - pc = NEXTOP(pc,os); - break; - /* instructions type osc */ - case _unify_n_atoms: - case _unify_n_atoms_write: - pc = NEXTOP(pc,osc); - break; - /* instructions type ou */ - case _unify_l_string: - case _unify_string: - pc = NEXTOP(pc,ou); - break; - /* instructions type ox */ - case _save_appl_x: - case _save_appl_x_write: - case _save_pair_x: - case _save_pair_x_write: - case _unify_l_x_loc: - case _unify_l_x_loc_write: - case _unify_l_x_val: - case _unify_l_x_val_write: - case _unify_l_x_var: - case _unify_l_x_var_write: - case _unify_x_loc: - case _unify_x_loc_write: - case _unify_x_val: - case _unify_x_val_write: - case _unify_x_var: - case _unify_x_var_write: - pc = NEXTOP(pc,ox); - break; - /* instructions type oxx */ - case _unify_l_x_var2: - case _unify_l_x_var2_write: - case _unify_x_var2: - case _unify_x_var2_write: - pc = NEXTOP(pc,oxx); - break; - /* instructions type oy */ - case _save_appl_y: - case _save_appl_y_write: - case _save_pair_y: - case _save_pair_y_write: - case _unify_l_y_loc: - case _unify_l_y_loc_write: - case _unify_l_y_val: - case _unify_l_y_val_write: - case _unify_l_y_var: - case _unify_l_y_var_write: - case _unify_y_loc: - case _unify_y_loc_write: - case _unify_y_val: - case _unify_y_val_write: - case _unify_y_var: - case _unify_y_var_write: - pc = NEXTOP(pc,oy); - break; - /* instructions type p */ - case _lock_lu: - case _procceed: - pp = pc->y_u.p.p; - if (pp->PredFlags & MegaClausePredFlag) - return found_mega_clause(pp, startp, endp); - clause_code = TRUE; - pc = NEXTOP(pc,p); - break; - case _count_call: - case _count_retry: - case _deallocate: - case _enter_profiling: - case _retry_profiled: - case _retry_udi: - case _try_udi: - pc = NEXTOP(pc,p); - break; - /* instructions type plxxs */ - case _call_bfunc_xx: - pc = NEXTOP(pc,plxxs); - break; - /* instructions type plxys */ - case _call_bfunc_xy: - case _call_bfunc_yx: - pc = NEXTOP(pc,plxys); - break; - /* instructions type plyys */ - case _call_bfunc_yy: - pc = NEXTOP(pc,plyys); - break; - /* instructions type pp */ - case _execute_cpred: - pp = pc->y_u.pp.p; - return walk_found_c_pred(pp, startp, endp); - case _dexecute: - case _execute: - clause_code = TRUE; - pp = pc->y_u.pp.p0; - pc = NEXTOP(pc,pp); - break; - /* instructions type s */ - case _cut: - case _cut_e: - case _cut_t: - case _pop_n: - case _write_n_voids: - pc = NEXTOP(pc,s); - break; - /* instructions type sc */ - case _write_n_atoms: - pc = NEXTOP(pc,sc); - break; - /* instructions type sllll */ - case _switch_on_sub_arg_type: - pc = NEXTOP(pc,sllll); - break; - /* instructions type slpp */ - case _call_c_wfail: - pp = pc->y_u.slpp.p; - return walk_found_c_pred(pp, startp, endp); - /* instructions type sssl */ - case _go_on_cons: - case _go_on_func: - case _if_cons: - case _if_func: - case _switch_on_cons: - case _switch_on_func: - pc = NEXTOP(pc,sssl); - break; - /* instructions type sssllp */ - case _expand_clauses: - return found_expand_index(pc, startp, endp, codeptr PASS_REGS); - pc = NEXTOP(pc,sssllp); - break; - /* instructions type x */ - case _get_atom_exo: - case _get_list: - case _put_list: - case _save_b_x: - case _write_x_loc: - case _write_x_val: - case _write_x_var: - pc = NEXTOP(pc,x); - break; - /* instructions type xD */ - case _get_dbterm: - case _put_dbterm: - pc = NEXTOP(pc,xD); - break; - /* instructions type xN */ - case _get_bigint: - case _put_bigint: - pc = NEXTOP(pc,xN); - break; - /* instructions type xc */ - case _get_atom: - case _put_atom: - pc = NEXTOP(pc,xc); - break; - /* instructions type xd */ - case _get_float: - case _put_float: - pc = NEXTOP(pc,xd); - break; - /* instructions type xfa */ - case _get_struct: - case _put_struct: - pc = NEXTOP(pc,xfa); - break; - /* instructions type xi */ - case _get_longint: - case _put_longint: - pc = NEXTOP(pc,xi); - break; - /* instructions type xl */ - case _p_atom_x: - case _p_atomic_x: - case _p_compound_x: - case _p_db_ref_x: - case _p_float_x: - case _p_integer_x: - case _p_nonvar_x: - case _p_number_x: - case _p_primitive_x: - case _p_var_x: - pc = NEXTOP(pc,xl); - break; - /* instructions type xll */ - case _jump_if_nonvar: - pc = NEXTOP(pc,xll); - break; - /* instructions type xllll */ - case _switch_on_arg_type: - pc = NEXTOP(pc,xllll); - break; - /* instructions type xps */ - case _commit_b_x: - pc = NEXTOP(pc,xps); - break; - /* instructions type xu */ - case _get_string: - pc = NEXTOP(pc,xu); - break; - /* instructions type xx */ - case _get_x_val: - case _get_x_var: - case _gl_void_valx: - case _gl_void_varx: - case _glist_valx: - case _put_x_val: - case _put_x_var: - pc = NEXTOP(pc,xx); - break; - /* instructions type xxc */ - case _p_func2s_cv: - pc = NEXTOP(pc,xxc); - break; - /* instructions type xxn */ - case _p_and_vc: - case _p_arg_cv: - case _p_div_cv: - case _p_div_vc: - case _p_func2s_vc: - case _p_minus_cv: - case _p_or_vc: - case _p_plus_vc: - case _p_sll_cv: - case _p_sll_vc: - case _p_slr_cv: - case _p_slr_vc: - case _p_times_vc: - pc = NEXTOP(pc,xxn); - break; - /* instructions type xxx */ - case _p_and_vv: - case _p_arg_vv: - case _p_div_vv: - case _p_func2f_xx: - case _p_func2s_vv: - case _p_minus_vv: - case _p_or_vv: - case _p_plus_vv: - case _p_sll_vv: - case _p_slr_vv: - case _p_times_vv: - pc = NEXTOP(pc,xxx); - break; - /* instructions type xxxx */ - case _put_xx_val: - pc = NEXTOP(pc,xxxx); - break; - /* instructions type xxy */ - case _p_func2f_xy: - pc = NEXTOP(pc,xxy); - break; - /* instructions type y */ - case _save_b_y: - case _write_y_loc: - case _write_y_val: - case _write_y_var: - pc = NEXTOP(pc,y); - break; - /* instructions type yl */ - case _p_atom_y: - case _p_atomic_y: - case _p_compound_y: - case _p_db_ref_y: - case _p_float_y: - case _p_integer_y: - case _p_nonvar_y: - case _p_number_y: - case _p_primitive_y: - case _p_var_y: - pc = NEXTOP(pc,yl); - break; - /* instructions type yps */ - case _commit_b_y: - pc = NEXTOP(pc,yps); - break; - /* instructions type yx */ - case _get_y_val: - case _get_y_var: - case _gl_void_valy: - case _gl_void_vary: - case _glist_valy: - case _put_unsafe: - case _put_y_val: - case _put_y_var: - pc = NEXTOP(pc,yx); - break; - /* instructions type yxc */ - case _p_func2s_y_cv: - pc = NEXTOP(pc,yxc); - break; - /* instructions type yxn */ - case _p_and_y_vc: - case _p_arg_y_cv: - case _p_div_y_cv: - case _p_div_y_vc: - case _p_func2s_y_vc: - case _p_minus_y_cv: - case _p_or_y_vc: - case _p_plus_y_vc: - case _p_sll_y_cv: - case _p_sll_y_vc: - case _p_slr_y_cv: - case _p_slr_y_vc: - case _p_times_y_vc: - pc = NEXTOP(pc,yxn); - break; - /* instructions type yxx */ - case _p_and_y_vv: - case _p_arg_y_vv: - case _p_div_y_vv: - case _p_func2f_yx: - case _p_func2s_y_vv: - case _p_minus_y_vv: - case _p_or_y_vv: - case _p_plus_y_vv: - case _p_sll_y_vv: - case _p_slr_y_vv: - case _p_times_y_vv: - pc = NEXTOP(pc,yxx); - break; - /* instructions type yyx */ - case _p_func2f_yy: - pc = NEXTOP(pc,yyx); - break; - /* instructions type yyxx */ - case _get_yy_var: - case _put_y_vals: - pc = NEXTOP(pc,yyxx); - break; + case _unify_l_n_voids: + case _unify_l_n_voids_write: + case _unify_n_voids: + case _unify_n_voids_write: + pc = NEXTOP(pc, os); + break; + /* instructions type osc */ + case _unify_n_atoms: + case _unify_n_atoms_write: + pc = NEXTOP(pc, osc); + break; + /* instructions type ou */ + case _unify_l_string: + case _unify_string: + pc = NEXTOP(pc, ou); + break; + /* instructions type ox */ + case _save_appl_x: + case _save_appl_x_write: + case _save_pair_x: + case _save_pair_x_write: + case _unify_l_x_loc: + case _unify_l_x_loc_write: + case _unify_l_x_val: + case _unify_l_x_val_write: + case _unify_l_x_var: + case _unify_l_x_var_write: + case _unify_x_loc: + case _unify_x_loc_write: + case _unify_x_val: + case _unify_x_val_write: + case _unify_x_var: + case _unify_x_var_write: + pc = NEXTOP(pc, ox); + break; + /* instructions type oxx */ + case _unify_l_x_var2: + case _unify_l_x_var2_write: + case _unify_x_var2: + case _unify_x_var2_write: + pc = NEXTOP(pc, oxx); + break; + /* instructions type oy */ + case _save_appl_y: + case _save_appl_y_write: + case _save_pair_y: + case _save_pair_y_write: + case _unify_l_y_loc: + case _unify_l_y_loc_write: + case _unify_l_y_val: + case _unify_l_y_val_write: + case _unify_l_y_var: + case _unify_l_y_var_write: + case _unify_y_loc: + case _unify_y_loc_write: + case _unify_y_val: + case _unify_y_val_write: + case _unify_y_var: + case _unify_y_var_write: + pc = NEXTOP(pc, oy); + break; + /* instructions type p */ + case _lock_lu: + case _procceed: + pp = pc->y_u.p.p; + if (pp->PredFlags & MegaClausePredFlag) + return found_mega_clause(pp, startp, endp); + clause_code = TRUE; + pc = NEXTOP(pc, p); + break; + case _count_call: + case _count_retry: + case _deallocate: + case _enter_profiling: + case _retry_profiled: + case _retry_udi: + case _try_udi: + pc = NEXTOP(pc, p); + break; + /* instructions type plxxs */ + case _call_bfunc_xx: + pc = NEXTOP(pc, plxxs); + break; + /* instructions type plxys */ + case _call_bfunc_xy: + case _call_bfunc_yx: + pc = NEXTOP(pc, plxys); + break; + /* instructions type plyys */ + case _call_bfunc_yy: + pc = NEXTOP(pc, plyys); + break; + /* instructions type pp */ + case _execute_cpred: + pp = pc->y_u.pp.p; + return walk_found_c_pred(pp, startp, endp); + case _dexecute: + case _execute: + clause_code = TRUE; + pp = pc->y_u.pp.p0; + pc = NEXTOP(pc, pp); + break; + /* instructions type s */ + case _cut: + case _cut_e: + case _cut_t: + case _pop_n: + case _write_n_voids: + pc = NEXTOP(pc, s); + break; + /* instructions type sc */ + case _write_n_atoms: + pc = NEXTOP(pc, sc); + break; + /* instructions type sllll */ + case _switch_on_sub_arg_type: + pc = NEXTOP(pc, sllll); + break; + /* instructions type slpp */ + case _call_c_wfail: + pp = pc->y_u.slpp.p; + return walk_found_c_pred(pp, startp, endp); + /* instructions type sssl */ + case _go_on_cons: + case _go_on_func: + case _if_cons: + case _if_func: + case _switch_on_cons: + case _switch_on_func: + pc = NEXTOP(pc, sssl); + break; + /* instructions type sssllp */ + case _expand_clauses: + return found_expand_index(pc, startp, endp, codeptr PASS_REGS); + pc = NEXTOP(pc, sssllp); + break; + /* instructions type x */ + case _get_atom_exo: + case _get_list: + case _put_list: + case _save_b_x: + case _write_x_loc: + case _write_x_val: + case _write_x_var: + pc = NEXTOP(pc, x); + break; + /* instructions type xD */ + case _get_dbterm: + case _put_dbterm: + pc = NEXTOP(pc, xD); + break; + /* instructions type xN */ + case _get_bigint: + case _put_bigint: + pc = NEXTOP(pc, xN); + break; + /* instructions type xc */ + case _get_atom: + case _put_atom: + pc = NEXTOP(pc, xc); + break; + /* instructions type xd */ + case _get_float: + case _put_float: + pc = NEXTOP(pc, xd); + break; + /* instructions type xfa */ + case _get_struct: + case _put_struct: + pc = NEXTOP(pc, xfa); + break; + /* instructions type xi */ + case _get_longint: + case _put_longint: + pc = NEXTOP(pc, xi); + break; + /* instructions type xl */ + case _p_atom_x: + case _p_atomic_x: + case _p_compound_x: + case _p_db_ref_x: + case _p_float_x: + case _p_integer_x: + case _p_nonvar_x: + case _p_number_x: + case _p_primitive_x: + case _p_var_x: + pc = NEXTOP(pc, xl); + break; + /* instructions type xll */ + case _jump_if_nonvar: + pc = NEXTOP(pc, xll); + break; + /* instructions type xllll */ + case _switch_on_arg_type: + pc = NEXTOP(pc, xllll); + break; + /* instructions type xps */ + case _commit_b_x: + pc = NEXTOP(pc, xps); + break; + /* instructions type xu */ + case _get_string: + pc = NEXTOP(pc, xu); + break; + /* instructions type xx */ + case _get_x_val: + case _get_x_var: + case _gl_void_valx: + case _gl_void_varx: + case _glist_valx: + case _put_x_val: + case _put_x_var: + pc = NEXTOP(pc, xx); + break; + /* instructions type xxc */ + case _p_func2s_cv: + pc = NEXTOP(pc, xxc); + break; + /* instructions type xxn */ + case _p_and_vc: + case _p_arg_cv: + case _p_div_cv: + case _p_div_vc: + case _p_func2s_vc: + case _p_minus_cv: + case _p_or_vc: + case _p_plus_vc: + case _p_sll_cv: + case _p_sll_vc: + case _p_slr_cv: + case _p_slr_vc: + case _p_times_vc: + pc = NEXTOP(pc, xxn); + break; + /* instructions type xxx */ + case _p_and_vv: + case _p_arg_vv: + case _p_div_vv: + case _p_func2f_xx: + case _p_func2s_vv: + case _p_minus_vv: + case _p_or_vv: + case _p_plus_vv: + case _p_sll_vv: + case _p_slr_vv: + case _p_times_vv: + pc = NEXTOP(pc, xxx); + break; + /* instructions type xxxx */ + case _put_xx_val: + pc = NEXTOP(pc, xxxx); + break; + /* instructions type xxy */ + case _p_func2f_xy: + pc = NEXTOP(pc, xxy); + break; + /* instructions type y */ + case _save_b_y: + case _write_y_loc: + case _write_y_val: + case _write_y_var: + pc = NEXTOP(pc, y); + break; + /* instructions type yl */ + case _p_atom_y: + case _p_atomic_y: + case _p_compound_y: + case _p_db_ref_y: + case _p_float_y: + case _p_integer_y: + case _p_nonvar_y: + case _p_number_y: + case _p_primitive_y: + case _p_var_y: + pc = NEXTOP(pc, yl); + break; + /* instructions type yps */ + case _commit_b_y: + pc = NEXTOP(pc, yps); + break; + /* instructions type yx */ + case _get_y_val: + case _get_y_var: + case _gl_void_valy: + case _gl_void_vary: + case _glist_valy: + case _put_unsafe: + case _put_y_val: + case _put_y_var: + pc = NEXTOP(pc, yx); + break; + /* instructions type yxc */ + case _p_func2s_y_cv: + pc = NEXTOP(pc, yxc); + break; + /* instructions type yxn */ + case _p_and_y_vc: + case _p_arg_y_cv: + case _p_div_y_cv: + case _p_div_y_vc: + case _p_func2s_y_vc: + case _p_minus_y_cv: + case _p_or_y_vc: + case _p_plus_y_vc: + case _p_sll_y_cv: + case _p_sll_y_vc: + case _p_slr_y_cv: + case _p_slr_y_vc: + case _p_times_y_vc: + pc = NEXTOP(pc, yxn); + break; + /* instructions type yxx */ + case _p_and_y_vv: + case _p_arg_y_vv: + case _p_div_y_vv: + case _p_func2f_yx: + case _p_func2s_y_vv: + case _p_minus_y_vv: + case _p_or_y_vv: + case _p_plus_y_vv: + case _p_sll_y_vv: + case _p_slr_y_vv: + case _p_times_y_vv: + pc = NEXTOP(pc, yxx); + break; + /* instructions type yyx */ + case _p_func2f_yy: + pc = NEXTOP(pc, yyx); + break; + /* instructions type yyxx */ + case _get_yy_var: + case _put_y_vals: + pc = NEXTOP(pc, yyxx); + break; #ifdef YAPOR - /* instructions type Otapl */ - case _getwork: - case _getwork_seq: - case _sync: - clause_code = FALSE; - pp = pc->y_u.Otapl.p; - pc = NEXTOP(pc,Otapl); - break; - /* instructions type e */ - case _getwork_first_time: - pc = NEXTOP(pc,e); - break; + /* instructions type Otapl */ + case _getwork: + case _getwork_seq: + case _sync: + clause_code = FALSE; + pp = pc->y_u.Otapl.p; + pc = NEXTOP(pc, Otapl); + break; + /* instructions type e */ + case _getwork_first_time: + pc = NEXTOP(pc, e); + break; #endif #ifdef TABLING - /* instructions type Otapl */ - case _table_answer_resolution: + /* instructions type Otapl */ + case _table_answer_resolution: #ifdef THREADS_CONSUMER_SHARING - case _table_answer_resolution_completion: + case _table_answer_resolution_completion: #endif - case _table_completion: - case _table_load_answer: - case _table_retry: - case _table_retry_me: - case _table_trust: - case _table_trust_me: - case _table_try: - case _table_try_answer: - case _table_try_me: - case _table_try_single: - clause_code = FALSE; - pp = pc->y_u.Otapl.p; - pc = NEXTOP(pc,Otapl); - break; - /* instructions type e */ + case _table_completion: + case _table_load_answer: + case _table_retry: + case _table_retry_me: + case _table_trust: + case _table_trust_me: + case _table_try: + case _table_try_answer: + case _table_try_me: + case _table_try_single: + clause_code = FALSE; + pp = pc->y_u.Otapl.p; + pc = NEXTOP(pc, Otapl); + break; +/* instructions type e */ #ifdef TABLING_INNER_CUTS - case _clause_with_cut: + case _clause_with_cut: #endif - pc = NEXTOP(pc,e); - break; - /* instructions type s */ - case _table_new_answer: - pc = NEXTOP(pc,s); - break; - /* instructions type e */ - case _trie_do_appl: - case _trie_do_appl_in_pair: - case _trie_do_atom: - case _trie_do_atom_in_pair: - case _trie_do_bigint: - case _trie_do_double: - case _trie_do_extension: - case _trie_do_gterm: - case _trie_do_longint: - case _trie_do_null: - case _trie_do_null_in_pair: - case _trie_do_pair: - case _trie_do_val: - case _trie_do_val_in_pair: - case _trie_do_var: - case _trie_do_var_in_pair: - case _trie_retry_appl: - case _trie_retry_appl_in_pair: - case _trie_retry_atom: - case _trie_retry_atom_in_pair: - case _trie_retry_bigint: - case _trie_retry_double: - case _trie_retry_extension: - case _trie_retry_gterm: - case _trie_retry_longint: - case _trie_retry_null: - case _trie_retry_null_in_pair: - case _trie_retry_pair: - case _trie_retry_val: - case _trie_retry_val_in_pair: - case _trie_retry_var: - case _trie_retry_var_in_pair: - case _trie_trust_appl: - case _trie_trust_appl_in_pair: - case _trie_trust_atom: - case _trie_trust_atom_in_pair: - case _trie_trust_bigint: - case _trie_trust_double: - case _trie_trust_extension: - case _trie_trust_gterm: - case _trie_trust_longint: - case _trie_trust_null: - case _trie_trust_null_in_pair: - case _trie_trust_pair: - case _trie_trust_val: - case _trie_trust_val_in_pair: - case _trie_trust_var: - case _trie_trust_var_in_pair: - case _trie_try_appl: - case _trie_try_appl_in_pair: - case _trie_try_atom: - case _trie_try_atom_in_pair: - case _trie_try_bigint: - case _trie_try_double: - case _trie_try_extension: - case _trie_try_gterm: - case _trie_try_longint: - case _trie_try_null: - case _trie_try_null_in_pair: - case _trie_try_pair: - case _trie_try_val: - case _trie_try_val_in_pair: - case _trie_try_var: - case _trie_try_var_in_pair: - pc = NEXTOP(pc,e); - break; + pc = NEXTOP(pc, e); + break; + /* instructions type s */ + case _table_new_answer: + pc = NEXTOP(pc, s); + break; + /* instructions type e */ + case _trie_do_appl: + case _trie_do_appl_in_pair: + case _trie_do_atom: + case _trie_do_atom_in_pair: + case _trie_do_bigint: + case _trie_do_double: + case _trie_do_extension: + case _trie_do_gterm: + case _trie_do_longint: + case _trie_do_null: + case _trie_do_null_in_pair: + case _trie_do_pair: + case _trie_do_val: + case _trie_do_val_in_pair: + case _trie_do_var: + case _trie_do_var_in_pair: + case _trie_retry_appl: + case _trie_retry_appl_in_pair: + case _trie_retry_atom: + case _trie_retry_atom_in_pair: + case _trie_retry_bigint: + case _trie_retry_double: + case _trie_retry_extension: + case _trie_retry_gterm: + case _trie_retry_longint: + case _trie_retry_null: + case _trie_retry_null_in_pair: + case _trie_retry_pair: + case _trie_retry_val: + case _trie_retry_val_in_pair: + case _trie_retry_var: + case _trie_retry_var_in_pair: + case _trie_trust_appl: + case _trie_trust_appl_in_pair: + case _trie_trust_atom: + case _trie_trust_atom_in_pair: + case _trie_trust_bigint: + case _trie_trust_double: + case _trie_trust_extension: + case _trie_trust_gterm: + case _trie_trust_longint: + case _trie_trust_null: + case _trie_trust_null_in_pair: + case _trie_trust_pair: + case _trie_trust_val: + case _trie_trust_val_in_pair: + case _trie_trust_var: + case _trie_trust_var_in_pair: + case _trie_try_appl: + case _trie_try_appl_in_pair: + case _trie_try_atom: + case _trie_try_atom_in_pair: + case _trie_try_bigint: + case _trie_try_double: + case _trie_try_extension: + case _trie_try_gterm: + case _trie_try_longint: + case _trie_try_null: + case _trie_try_null_in_pair: + case _trie_try_pair: + case _trie_try_val: + case _trie_try_val_in_pair: + case _trie_try_var: + case _trie_try_var_in_pair: + pc = NEXTOP(pc, e); + break; #endif - /* this instruction is hardwired */ - case _or_last: + /* this instruction is hardwired */ + case _or_last: #ifdef YAPOR - pp = pc->y_u.Osblp.p0; - if (pp->PredFlags & MegaClausePredFlag) - return found_mega_clause(pp, startp, endp); - clause_code = TRUE; - pc = NEXTOP(pc,Osblp); + pp = pc->y_u.Osblp.p0; + if (pp->PredFlags & MegaClausePredFlag) + return found_mega_clause(pp, startp, endp); + clause_code = TRUE; + pc = NEXTOP(pc, Osblp); #else - pp = pc->y_u.p.p; - if (pp->PredFlags & MegaClausePredFlag) - return found_mega_clause(pp, startp, endp); - clause_code = TRUE; - pc = NEXTOP(pc,p); + pp = pc->y_u.p.p; + if (pp->PredFlags & MegaClausePredFlag) + return found_mega_clause(pp, startp, endp); + clause_code = TRUE; + pc = NEXTOP(pc, p); #endif - } } +} diff --git a/include/YapError.h b/include/YapError.h index 04e3351bf..22ebb3628 100644 --- a/include/YapError.h +++ b/include/YapError.h @@ -76,7 +76,6 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi, #define JMP_LOCAL_ERROR(v, LAB) \ if (H + 2 * (v) > ASP - 1024) { \ LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \ - LOCAL_Error_Term = t; \ LOCAL_Error_Size = 2 * (v) * sizeof(CELL); \ 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) \ if (HR + (v) > ASP - 1024) { \ LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \ - LOCAL_Error_Term = t; \ LOCAL_Error_Size = 2 * (v) * sizeof(CELL); \ 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) \ if (HR + (v) > ASP - 1024) { \ LOCAL_Error_TYPE = RESOURCE_ERROR_STACK; \ - LOCAL_Error_Term = t; \ LOCAL_Error_Size = 2 * (v) * sizeof(CELL); \ 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) \ if (s + (n + 1) > (TYPE *)AuxSp) { \ LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \ - LOCAL_Error_Term = t; \ LOCAL_Error_Size = n * sizeof(TYPE); \ 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) \ if (s + (n + 1) > (TYPE *)AuxSp) { \ LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \ - LOCAL_Error_Term = t; \ LOCAL_Error_Size = n * sizeof(TYPE); \ 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) \ if (s + (n + 1) > (TYPE *)AuxSp) { \ LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \ - LOCAL_Error_Term = t; \ LOCAL_Error_Size = n * sizeof(TYPE); \ 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) \ if (a == NIL) { \ LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; \ - LOCAL_Error_Term = t; \ LOCAL_Error_Size = n * sizeof(TYPE); \ 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) \ if (a == NIL) { \ LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; \ - LOCAL_Error_Term = t; \ LOCAL_Error_Size = n * sizeof(TYPE); \ 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) \ if (a == NIL) { \ LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; \ - LOCAL_Error_Term = t; \ LOCAL_Error_Size = n * sizeof(TYPE); \ goto LAB; \ } @@ -174,6 +165,21 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi, /// go back 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 typedef struct yap_error_descriptor { 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; const char *errorFunction; const char *errorFile; + // struct error_prolog_source *errorSource; YAP_Int prologPredCl; YAP_UInt prologPredLine; 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_Term prologPredModule; 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; - char errorComment[MAX_ERROR_MSG_SIZE]; + char *errorMsg; size_t errorMsgLen; + struct yap_error_descriptor *top_error; } yap_error_descriptor_t; /// compatibility with existing code.. -#define LOCAL_Error_TYPE LOCAL_ActiveError.errorNo -#define LOCAL_Error_File LOCAL_ActiveError.errorFile -#define LOCAL_Error_Function LOCAL_ActiveError.errorFunction -#define LOCAL_Error_Lineno LOCAL_ActiveError.errorLine -#define LOCAL_Error_Size LOCAL_ActiveError.errorMsgLen -#define LOCAL_ErrorSay LOCAL_ActiveError.errorComment +#define LOCAL_Error_TYPE LOCAL_ActiveError->errorNo +#define LOCAL_Error_File LOCAL_ActiveError->errorFile +#define LOCAL_Error_Function LOCAL_ActiveError->errorFunction +#define LOCAL_Error_Lineno LOCAL_ActiveError->errorLine +#define LOCAL_Error_Size LOCAL_ActiveError->errorMsgLen +#define LOCAL_BallTerm LOCAL_ActiveError->errorTerm +#define LOCAL_ErrorMessage LOCAL_ActiveError->errorMsg extern bool Yap_find_prolog_culprit(); extern yap_error_class_number Yap_errorClass(yap_error_number e); extern const char *Yap_errorName(yap_error_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 diff --git a/os/iopreds.c b/os/iopreds.c index 09d0473b4..a4e534d2e 100644 --- a/os/iopreds.c +++ b/os/iopreds.c @@ -454,16 +454,16 @@ int Yap_DebugPuts(FILE *s, const char *sch) { void Yap_DebugErrorPuts(const char *s) { Yap_DebugPuts(stderr, s); } void Yap_DebugPlWrite(Term t) { - if (t==0) - fprintf(stderr,"NULL"); - Yap_plwrite(t, GLOBAL_Stream + 2, 0, 0, GLOBAL_MaxPriority); + if (t == 0) + fprintf(stderr, "NULL"); + Yap_plwrite(t, GLOBAL_Stream + 2, 0, 0, GLOBAL_MaxPriority); } void Yap_DebugPlWriteln(Term t) { CACHE_REGS - if (t==0) - fprintf(stderr,"NULL"); - Yap_plwrite(t, NULL, 15, 0, GLOBAL_MaxPriority); + if (t == 0) + fprintf(stderr, "NULL"); + Yap_plwrite(t, NULL, 15, 0, GLOBAL_MaxPriority); Yap_DebugPutc(GLOBAL_Stream[LOCAL_c_error_stream].file, '.'); Yap_DebugPutc(GLOBAL_Stream[LOCAL_c_error_stream].file, 10); } @@ -616,12 +616,12 @@ int post_process_read_wchar(int ch, size_t n, StreamDesc *s) { if (ch == EOF) { return post_process_weof(s); } - #if DEBUG +#if DEBUG if (GLOBAL_Option[1]) { static int v; - fprintf(stderr, "%d %C\n", v, ch); - v++; - } + fprintf(stderr, "%d %C\n", v, ch); + v++; + } #endif s->charcount += n; s->linepos += n; @@ -1193,8 +1193,7 @@ do_open(Term file_name, Term t2, if (LOCAL_Error_TYPE != YAP_NO_ERROR) { if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG) LOCAL_Error_TYPE = DOMAIN_ERROR_OPEN_OPTION; - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, - "option handling in open/3"); + Yap_Error(LOCAL_Error_TYPE, tlist, "option handling in open/3"); } 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 == DOMAIN_ERROR_PROLOG_FLAG) 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; @@ -1762,7 +1761,7 @@ static Int abs_file_parameters(USES_REGS1) { if (LOCAL_Error_TYPE != YAP_NO_ERROR) { if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG) 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; } diff --git a/os/iopreds.h b/os/iopreds.h index c21b2e583..b547f11c0 100644 --- a/os/iopreds.h +++ b/os/iopreds.h @@ -24,7 +24,8 @@ #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) && (IsAtomTerm(t) || (IsApplTerm(t) && (FunctorOfTerm(t) == FunctorStream))); @@ -121,28 +122,28 @@ extern bool Yap_ReadlineOps(StreamDesc *st); extern int Yap_OpenBufWriteStream(USES_REGS1); extern void Yap_ConsoleOps(StreamDesc *s); -void Yap_InitRandomPreds(void); -void Yap_InitSignalPreds(void); -void Yap_InitTimePreds(void); +extern void Yap_InitRandomPreds(void); +extern void Yap_InitSignalPreds(void); +extern void Yap_InitTimePreds(void); -void Yap_init_socks(char *host, long interface_port); -void Yap_InitPipes(void); -void Yap_InitMem(void); -void Yap_InitSockets(void); -void Yap_InitSocketLayer(void); -void Yap_InitMems(void); -void Yap_InitConsole(void); -void Yap_InitReadlinePreds(void); +extern void Yap_init_socks(char *host, long interface_port); +extern void Yap_InitPipes(void); +extern void Yap_InitMem(void); +extern void Yap_InitSockets(void); +extern void Yap_InitSocketLayer(void); +extern void Yap_InitMems(void); +extern void Yap_InitConsole(void); +extern void Yap_InitReadlinePreds(void); bool Yap_InitReadline(Term); -void Yap_InitChtypes(void); -void Yap_InitCharsio(void); -void Yap_InitFormat(void); -void Yap_InitFiles(void); -void Yap_InitIOStreams(void); -void Yap_InitWriteTPreds(void); -void Yap_InitReadTPreds(void); -void Yap_socketStream(StreamDesc *s); -void Yap_ReadlineFlush(int sno); +extern void Yap_InitChtypes(void); +extern void Yap_InitCharsio(void); +extern void Yap_InitFormat(void); +extern void Yap_InitFiles(void); +extern void Yap_InitIOStreams(void); +extern void Yap_InitWriteTPreds(void); +extern void Yap_InitReadTPreds(void); +extern void Yap_socketStream(StreamDesc *s); +extern void Yap_ReadlineFlush(int sno); Int Yap_ReadlinePeekChar(int sno); int Yap_ReadlineForSIGINT(void); bool Yap_DoPrompt(StreamDesc *s); @@ -150,7 +151,7 @@ bool Yap_DoPrompt(StreamDesc *s); Int Yap_peek(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_eof(StreamDesc *); @@ -173,15 +174,15 @@ int ResetEOF(StreamDesc *s); int EOFPeek(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); int Yap_CheckAlias(Atom arg); 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_DeleteAliases(int sno); -bool Yap_FindStreamForAlias(Atom al); -bool Yap_FetchStreamAlias(int sno, Term t2 USES_REGS); +extern bool Yap_FindStreamForAlias(Atom al); +extern bool Yap_FetchStreamAlias(int sno, Term t2 USES_REGS); 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); -bool Yap_Exists(const char *f); +extern bool Yap_Exists(const char *f); static inline void freeBuffer(const void *ptr) { CACHE_REGS diff --git a/os/readterm.c b/os/readterm.c index 5fc63433a..d26ebb4d7 100644 --- a/os/readterm.c +++ b/os/readterm.c @@ -8,9 +8,9 @@ * * ************************************************************************** * * - * File: iopreds.c * + * File: iopreds.c * * Last rev: 5/2/88 * - * mods: * + * mods: * * comments: Input/Output C implemented predicates * * * *************************************************************************/ @@ -95,7 +95,7 @@ static char SccsId[] = "%W% %G%"; #define SYSTEM_STAT stat #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) { if (p == NULL) @@ -120,9 +120,9 @@ reflects the location in the real file. static Int qq_open(USES_REGS1) { PRED_LD - Term t = Deref(ARG1); + Term t = Deref(ARG1); if (!IsVarTerm(t) && IsApplTerm(t) && FunctorOfTerm(t) = - FunctorDQuasiQuotation) { + FunctorDQuasiQuotation) { void *ptr; char *start; size_t l int s; @@ -173,26 +173,26 @@ static int parse_quasi_quotations(ReadData _PL_rd ARG_LD) { } else return TRUE; } else if (_PL_rd->quasi_quotations) /* user option, but no quotes */ - { - return PL_unify_nil(_PL_rd->quasi_quotations); - } else + { + return PL_unify_nil(_PL_rd->quasi_quotations); + } else return TRUE; } #endif /*O_QUASIQUOTATIONS*/ -#define READ_DEFS() \ - PAR("comments", list_filler, READ_COMMENTS) \ - , PAR("module", isatom, READ_MODULE), PAR("priority", nat, READ_PRIORITY), \ - PAR("quasi_quotations", filler, READ_QUASI_QUOTATIONS), \ - PAR("term_position", filler, READ_TERM_POSITION), \ - PAR("syntax_errors", isatom, READ_SYNTAX_ERRORS), \ - PAR("singletons", filler, READ_SINGLETONS), \ - PAR("variables", filler, READ_VARIABLES), \ - PAR("variable_names", filler, READ_VARIABLE_NAMES), \ - PAR("character_escapes", booleanFlag, READ_CHARACTER_ESCAPES), \ - PAR("backquoted_string", isatom, READ_BACKQUOTED_STRING), \ - PAR("cycles", ok, READ_CYCLES), PAR(NULL, ok, READ_END) +#define READ_DEFS() \ + PAR("comments", list_filler, READ_COMMENTS) \ + , PAR("module", isatom, READ_MODULE), PAR("priority", nat, READ_PRIORITY), \ + PAR("quasi_quotations", filler, READ_QUASI_QUOTATIONS), \ + PAR("term_position", filler, READ_TERM_POSITION), \ + PAR("syntax_errors", isatom, READ_SYNTAX_ERRORS), \ + PAR("singletons", filler, READ_SINGLETONS), \ + PAR("variables", filler, READ_VARIABLES), \ + PAR("variable_names", filler, READ_VARIABLE_NAMES), \ + PAR("character_escapes", booleanFlag, READ_CHARACTER_ESCAPES), \ + PAR("backquoted_string", isatom, READ_BACKQUOTED_STRING), \ + PAR("cycles", ok, READ_CYCLES), PAR(NULL, ok, READ_END) #define PAR(x, y, z) z @@ -200,7 +200,7 @@ typedef enum open_enum_choices { READ_DEFS() } read_choices_t; #undef PAR -#define PAR(x, y, z) \ +#define PAR(x, y, z) \ { x, y, z } static const param_t read_defs[] = {READ_DEFS()}; @@ -215,9 +215,9 @@ static const param_t read_defs[] = {READ_DEFS()}; * Implicit arguments: * + */ -static Term syntax_error(TokEntry *errtok, int sno, Term cmod) { +static char * syntax_error(TokEntry *errtok, int sno, Term cmod) { CACHE_REGS - Term info; + Term info; Term startline, errline, endline; Term tf[4]; Term *tailp = tf + 3; @@ -264,85 +264,67 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) { t0[0] = TermNil; } ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0); - } - break; - case QuasiQuotes_tok: - { - Term t0[2]; - t0[0] = MkAtomTerm(Yap_LookupAtom("")); - ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0); - } - break; - case WQuasiQuotes_tok: - { - Term t0[2]; - t0[0] = MkAtomTerm(Yap_LookupAtom("")); - ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0); - } - break; + } break; + case QuasiQuotes_tok: { + Term t0[2]; + t0[0] = MkAtomTerm(Yap_LookupAtom("")); + ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0); + } break; + case WQuasiQuotes_tok: { + Term t0[2]; + t0[0] = MkAtomTerm(Yap_LookupAtom("")); + ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, t0); + } break; case Number_tok: ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomNumber, 1), 1, &(tok->TokInfo)); break; - case Var_tok: - { - Term t[2]; - VarEntry *varinfo = (VarEntry *)info; + case Var_tok: { + Term t[2]; + VarEntry *varinfo = (VarEntry *)info; - t[0] = MkIntTerm(0); - t[1] = Yap_CharsToString(varinfo->VarRep, ENC_ISO_LATIN1 PASS_REGS); - ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomGVar, 2), 2, t); + t[0] = MkIntTerm(0); + t[1] = Yap_CharsToString(varinfo->VarRep, ENC_ISO_LATIN1 PASS_REGS); + ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomGVar, 2), 2, t); + } break; + case String_tok: { + Term t0 = Yap_CharsToTDQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS); + if (!t0) { + return 0; } - break; - case String_tok: - { - Term t0 = Yap_CharsToTDQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS); - if (!t0) { - return 0; - } - ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0); - } - break; - case WString_tok: - { - Term t0 = Yap_WCharsToTDQ((wchar_t *)info, cmod PASS_REGS); - if (!t0) - return 0; - ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0); - } - break; - case BQString_tok: - { - Term t0 = Yap_CharsToTBQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS); - ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0); - } - break; - case WBQString_tok: - { - Term t0 = Yap_WCharsToTBQ((wchar_t *)info, cmod PASS_REGS); - ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0); - } - break; - case Error_tok: - { - ts[0] = MkAtomTerm(AtomError); - } - break; + ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0); + } break; + case WString_tok: { + Term t0 = Yap_WCharsToTDQ((wchar_t *)info, cmod PASS_REGS); + if (!t0) + return 0; + ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0); + } break; + case BQString_tok: { + Term t0 = Yap_CharsToTBQ((char *)info, cmod, ENC_ISO_LATIN1 PASS_REGS); + ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0); + } break; + case WBQString_tok: { + Term t0 = Yap_WCharsToTBQ((wchar_t *)info, cmod PASS_REGS); + ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &t0); + } break; + case Error_tok: { + ts[0] = MkAtomTerm(AtomError); + } break; case eot_tok: endline = MkIntegerTerm(tok->TokPos); ts[0] = MkAtomTerm(Yap_LookupAtom("EOT")); break; - case Ponctuation_tok: - { - char s[2]; - s[1] = '\0'; - if ((info) == 'l') { - s[0] = '('; - } else { - s[0] = (char)info; - } - ts[0] = MkAtomTerm(Yap_LookupAtom(s)); + case Ponctuation_tok: { + char s[2]; + s[1] = '\0'; + if ((info) == 'l') { + s[0] = '('; + } else { + s[0] = (char)info; } + ts[0] = MkAtomTerm(Yap_LookupAtom(s)); + } } if (tok->TokNext) { tok = tok->TokNext; @@ -379,10 +361,10 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) { Yap_DebugPlWriteln(terr); } #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); } @@ -420,7 +402,7 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream); static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) { CACHE_REGS - LOCAL_VarTable = NULL; + LOCAL_VarTable = NULL; LOCAL_AnonVarTable = NULL; fe->enc = GLOBAL_Stream[inp_stream].encoding; xarg *args = Yap_ArgListToVector(opts, read_defs, READ_END); @@ -517,7 +499,7 @@ typedef enum { Int Yap_FirstLineInParse(void) { CACHE_REGS - return LOCAL_StartLineCount; + return LOCAL_StartLineCount; } #define PUSHFET(X) *HR++ = fe->X @@ -526,7 +508,7 @@ Int Yap_FirstLineInParse(void) { static void reset_regs(TokEntry *tokstart, FEnv *fe) { CACHE_REGS - restore_machine_regs(); + restore_machine_regs(); /* restart global */ PUSHFET(qq); @@ -553,7 +535,7 @@ static void reset_regs(TokEntry *tokstart, FEnv *fe) { static Term get_variables(FEnv *fe, TokEntry *tokstart) { CACHE_REGS - Term v; + Term v; if (fe->vp) { while (true) { fe->old_H = HR; @@ -573,7 +555,7 @@ static Term get_variables(FEnv *fe, TokEntry *tokstart) { static Term get_varnames(FEnv *fe, TokEntry *tokstart) { CACHE_REGS - Term v; + Term v; if (fe->np) { while (true) { fe->old_H = HR; @@ -593,7 +575,7 @@ static Term get_varnames(FEnv *fe, TokEntry *tokstart) { static Term get_singletons(FEnv *fe, TokEntry *tokstart) { CACHE_REGS - Term v; + Term v; if (fe->sp) { while (TRUE) { fe->old_H = HR; @@ -611,7 +593,7 @@ static Term get_singletons(FEnv *fe, TokEntry *tokstart) { static void warn_singletons(FEnv *fe, TokEntry *tokstart) { CACHE_REGS - Term v; + Term v; fe->sp = TermNil; v = get_singletons(fe, tokstart); if (v && v != TermNil) { @@ -633,7 +615,7 @@ static void warn_singletons(FEnv *fe, TokEntry *tokstart) { static Term get_stream_position(FEnv *fe, TokEntry *tokstart) { CACHE_REGS - Term v; + Term v; if (fe->tp) { while (true) { fe->old_H = HR; @@ -651,7 +633,7 @@ static Term get_stream_position(FEnv *fe, TokEntry *tokstart) { static bool complete_processing(FEnv *fe, TokEntry *tokstart) { CACHE_REGS - Term v1, v2, v3, vc, tp; + Term v1, v2, v3, vc, tp; if (fe->t && fe->vp) v1 = get_variables(fe, tokstart); @@ -679,15 +661,15 @@ static bool complete_processing(FEnv *fe, TokEntry *tokstart) { // trail must be ok by now.] if (fe->t) { return (!v1 || Yap_unify(v1, fe->vp)) && (!v2 || Yap_unify(v2, fe->np)) && - (!v3 || Yap_unify(v3, fe->sp)) && (!tp || Yap_unify(tp, fe->tp)) && - (!vc || Yap_unify(vc, fe->tcomms)); + (!v3 || Yap_unify(v3, fe->sp)) && (!tp || Yap_unify(tp, fe->tp)) && + (!vc || Yap_unify(vc, fe->tcomms)); } return true; } static bool complete_clause_processing(FEnv *fe, TokEntry *tokstart) { CACHE_REGS - Term v_vp, v_vnames, v_comments, v_pos; + Term v_vp, v_vnames, v_comments, v_pos; if (fe->t && fe->vp) v_vp = get_variables(fe, tokstart); @@ -713,9 +695,9 @@ static bool complete_clause_processing(FEnv *fe, TokEntry *tokstart) { // trail must be ok by now.] if (fe->t) { return (!v_vp || Yap_unify(v_vp, fe->vp)) && - (!v_vnames || Yap_unify(v_vnames, fe->np)) && - (!v_pos || Yap_unify(v_pos, fe->tp)) && - (!v_comments || Yap_unify(v_comments, fe->tcomms)); + (!v_vnames || Yap_unify(v_vnames, fe->np)) && + (!v_pos || Yap_unify(v_pos, fe->tp)) && + (!v_comments || Yap_unify(v_comments, fe->tcomms)); } return true; } @@ -733,8 +715,8 @@ static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream); static parser_state_t scanEOF(FEnv *fe, int inp_stream) { CACHE_REGS - // bool store_comments = false; - TokEntry *tokstart = LOCAL_tokptr; + // bool store_comments = false; + TokEntry *tokstart = LOCAL_tokptr; // check for an user abort if (tokstart != NULL && tokstart->Tok != Ord(eot_tok)) { /* we got the end of file from an abort */ @@ -774,7 +756,7 @@ static parser_state_t scanEOF(FEnv *fe, int inp_stream) { static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream, int nargs) { CACHE_REGS - LOCAL_ErrorMessage = NULL; + LOCAL_ErrorMessage = NULL; fe->old_TR = TR; LOCAL_Error_TYPE = YAP_NO_ERROR; LOCAL_SourceFileName = GLOBAL_Stream[inp_stream].name; @@ -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); } 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; if (LOCAL_Error_TYPE) - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, opts, NULL); fe->t = 0; return YAP_PARSING_FINISHED; ; @@ -811,11 +793,11 @@ static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream, static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) { CACHE_REGS - /* preserve value of H after scanning: otherwise we may lose strings - and floats */ - LOCAL_tokptr = LOCAL_toktide = + /* preserve value of H after scanning: otherwise we may lose strings + and floats */ + LOCAL_tokptr = LOCAL_toktide = - Yap_tokenizer(GLOBAL_Stream + inp_stream, false, &fe->tpos); + Yap_tokenizer(GLOBAL_Stream + inp_stream, false, &fe->tpos); if (LOCAL_ErrorMessage) return YAP_SCANNING_ERROR; if (LOCAL_tokptr->Tok != Ord(eot_tok)) { @@ -828,7 +810,6 @@ static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) { strncpy(out, "Empty clause", len); LOCAL_ErrorMessage = out; LOCAL_Error_TYPE = SYNTAX_ERROR; - LOCAL_Error_Term = TermEof; return YAP_PARSING_ERROR; } return scanEOF(fe, inp_stream); @@ -836,7 +817,7 @@ static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) { static parser_state_t scanError(REnv *re, FEnv *fe, int inp_stream) { CACHE_REGS - fe->t = 0; + fe->t = 0; // running out of memory if (LOCAL_Error_TYPE == RESOURCE_ERROR_TRAIL) { LOCAL_Error_TYPE = YAP_NO_ERROR; @@ -876,7 +857,7 @@ static parser_state_t scanError(REnv *re, FEnv *fe, int inp_stream) { static parser_state_t parseError(REnv *re, FEnv *fe, int inp_stream) { CACHE_REGS - fe->t = 0; + fe->t = 0; if (LOCAL_Error_TYPE == RESOURCE_ERROR_TRAIL || LOCAL_Error_TYPE == RESOURCE_ERROR_AUXILIARY_STACK || LOCAL_Error_TYPE == RESOURCE_ERROR_HEAP || @@ -889,13 +870,14 @@ static parser_state_t parseError(REnv *re, FEnv *fe, int inp_stream) { LOCAL_Error_TYPE = YAP_NO_ERROR; return YAP_PARSING_FINISHED; } 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) { - LOCAL_ErrorMessage = NULL; + LOCAL_ErrorMessage = s; LOCAL_Error_TYPE = SYNTAX_ERROR; return YAP_PARSING_FINISHED; // dec-10 - } else if (Yap_PrintWarning(terr)) { + } else if (Yap_PrintWarning(MkStringTerm(s))) { + free(s); LOCAL_Error_TYPE = YAP_NO_ERROR; return YAP_SCANNING; } @@ -906,7 +888,7 @@ static parser_state_t parseError(REnv *re, FEnv *fe, int inp_stream) { static parser_state_t parse(REnv *re, FEnv *fe, int inp_stream) { CACHE_REGS - TokEntry *tokstart = LOCAL_tokptr; + TokEntry *tokstart = LOCAL_tokptr; fe->t = Yap_Parse(re->prio, fe->enc, fe->cmod); fe->toklast = LOCAL_tokptr; LOCAL_tokptr = tokstart; @@ -961,34 +943,33 @@ Term Yap_read_term(int inp_stream, Term opts, int nargs) { case YAP_PARSING_ERROR: state = parseError(&re, &fe, inp_stream); break; - case YAP_PARSING_FINISHED: - { - CACHE_REGS - bool done; - if (fe.reading_clause) - done = complete_clause_processing(&fe, LOCAL_tokptr); - else - done = complete_processing(&fe, LOCAL_tokptr); - if (!done) { - state = YAP_PARSING_ERROR; - fe.t = 0; - break; - } - if (LOCAL_Error_TYPE != YAP_NO_ERROR) { - Yap_Error(LOCAL_Error_TYPE, ARG1, LOCAL_ErrorMessage); - } -#if EMACS - first_char = tokstart->TokPos; -#endif /* EMACS */ - return fe.t; + case YAP_PARSING_FINISHED: { + CACHE_REGS + bool done; + if (fe.reading_clause) + done = complete_clause_processing(&fe, LOCAL_tokptr); + else + done = complete_processing(&fe, LOCAL_tokptr); + if (!done) { + state = YAP_PARSING_ERROR; + fe.t = 0; + break; } + if (LOCAL_Error_TYPE != YAP_NO_ERROR) { + Yap_Error(LOCAL_Error_TYPE, ARG1, LOCAL_ErrorMessage); + } +#if EMACS + first_char = tokstart->TokPos; +#endif /* EMACS */ + return fe.t; + } } } return 0; } static Int -read_term2(USES_REGS1) { /* '$read'(+Flag,?Term,?Module,?Vars,-Pos,-Err) */ + read_term2(USES_REGS1) { /* '$read'(+Flag,?Term,?Module,?Vars,-Pos,-Err) */ Term rc; yhandle_t h = Yap_PushHandle(ARG1); if ((rc = Yap_read_term(LOCAL_c_input_stream, ARG2, 2)) == 0) @@ -998,7 +979,7 @@ read_term2(USES_REGS1) { /* '$read'(+Flag,?Term,?Module,?Vars,-Pos,-Err) */ } static Int read_term( - USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */ + USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */ int inp_stream; Term out; @@ -1015,14 +996,14 @@ static Int read_term( return out != 0L && Yap_unify(tf, out); } -#define READ_CLAUSE_DEFS() \ - PAR("comments", list_filler, READ_CLAUSE_COMMENTS) \ - , PAR("module", isatom, READ_CLAUSE_MODULE), \ - PAR("variable_names", filler, READ_CLAUSE_VARIABLE_NAMES), \ - PAR("variables", filler, READ_CLAUSE_VARIABLES), \ - PAR("term_position", filler, READ_CLAUSE_TERM_POSITION), \ - PAR("syntax_errors", isatom, READ_CLAUSE_SYNTAX_ERRORS), \ - PAR(NULL, ok, READ_CLAUSE_END) +#define READ_CLAUSE_DEFS() \ + PAR("comments", list_filler, READ_CLAUSE_COMMENTS) \ + , PAR("module", isatom, READ_CLAUSE_MODULE), \ + PAR("variable_names", filler, READ_CLAUSE_VARIABLE_NAMES), \ + PAR("variables", filler, READ_CLAUSE_VARIABLES), \ + PAR("term_position", filler, READ_CLAUSE_TERM_POSITION), \ + PAR("syntax_errors", isatom, READ_CLAUSE_SYNTAX_ERRORS), \ + PAR(NULL, ok, READ_CLAUSE_END) #define PAR(x, y, z) z @@ -1032,7 +1013,7 @@ typedef enum read_clause_enum_choices { #undef PAR -#define PAR(x, y, z) \ +#define PAR(x, y, z) \ { x, y, z } static const param_t read_clause_defs[] = {READ_CLAUSE_DEFS()}; @@ -1042,7 +1023,7 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) { CACHE_REGS - xarg *args = Yap_ArgListToVector(opts, read_clause_defs, READ_CLAUSE_END); + xarg *args = Yap_ArgListToVector(opts, read_clause_defs, READ_CLAUSE_END); if (args == NULL) { if (LOCAL_Error_TYPE == DOMAIN_ERROR_GENERIC_ARGUMENT) LOCAL_Error_TYPE = DOMAIN_ERROR_READ_OPTION; @@ -1136,7 +1117,7 @@ static Int read_clause2(USES_REGS1) { * + The `singletons` option is set from the single var flag */ static Int read_clause( - USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */ + USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */ int inp_stream; Term out; Term t3 = Deref(ARG3); @@ -1165,7 +1146,8 @@ static Int read_clause( /** * @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 *friends.>position * It ignores user_input or @@ -1178,7 +1160,7 @@ static Int read_clause( */ static Int source_location(USES_REGS1) { return Yap_unify(ARG1, MkAtomTerm(LOCAL_SourceFileName)) && - Yap_unify(ARG2, MkIntegerTerm(LOCAL_SourceFileLineno)); + Yap_unify(ARG2, MkIntegerTerm(LOCAL_SourceFileLineno)); } /** @@ -1192,7 +1174,7 @@ static Int source_location(USES_REGS1) { * */ static Int read2( - USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */ + USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */ int inp_stream; Int out; @@ -1217,7 +1199,7 @@ the same stream may cause an error failure (see open/3). */ static Int read1( - USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */ + USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */ Term out = Yap_read_term(LOCAL_c_input_stream, TermNil, 1); return out && Yap_unify(ARG1, out); } @@ -1242,7 +1224,7 @@ static Int fileerrors(USES_REGS1) { */ static Int nofileerrors( - USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */ + USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */ return setYapFlag(TermFileerrors, TermFalse); } @@ -1293,7 +1275,7 @@ static Int style_checker(USES_REGS1) { X_API Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp, int prio, Term *bindings) { CACHE_REGS - Term bvar = MkVarTerm(), ctl; + Term bvar = MkVarTerm(), ctl; yhandle_t sl; if (len == 0) { diff --git a/os/sig.c b/os/sig.c index 9c63cf009..678fe9df9 100644 --- a/os/sig.c +++ b/os/sig.c @@ -1,7 +1,6 @@ #include "sysbits.h" - #if HAVE_SIGINFO_H #include #endif @@ -13,107 +12,105 @@ #include #endif -#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 -#define SIG_ATOM_GC (SIG_PROLOG_OFFSET+1) +#define SIG_ATOM_GC (SIG_PROLOG_OFFSET + 1) #endif -#define SIG_GC (SIG_PROLOG_OFFSET+2) +#define SIG_GC (SIG_PROLOG_OFFSET + 2) #ifdef O_PLMT -#define SIG_THREAD_SIGNAL (SIG_PROLOG_OFFSET+3) +#define SIG_THREAD_SIGNAL (SIG_PROLOG_OFFSET + 3) #endif -#define SIG_FREECLAUSES (SIG_PROLOG_OFFSET+4) -#define SIG_PLABORT (SIG_PROLOG_OFFSET+5) +#define SIG_FREECLAUSES (SIG_PROLOG_OFFSET + 4) +#define SIG_PLABORT (SIG_PROLOG_OFFSET + 5) -static struct signame -{ int sig; +static struct signame { + int sig; const char *name; - int flags; -} signames[] = -{ + int flags; +} signames[] = { #ifdef SIGHUP - { SIGHUP, "hup", 0}, + {SIGHUP, "hup", 0}, #endif - { SIGINT, "int", 0}, + {SIGINT, "int", 0}, #ifdef SIGQUIT - { SIGQUIT, "quit", 0}, + {SIGQUIT, "quit", 0}, #endif - { SIGILL, "ill", 0}, - { SIGABRT, "abrt", 0}, - { SIGFPE, "fpe", 0}, + {SIGILL, "ill", 0}, + {SIGABRT, "abrt", 0}, + {SIGFPE, "fpe", 0}, #ifdef SIGKILL - { SIGKILL, "kill", 0}, + {SIGKILL, "kill", 0}, #endif - { SIGSEGV, "segv", 0}, + {SIGSEGV, "segv", 0}, #ifdef SIGPIPE - { SIGPIPE, "pipe", 0}, + {SIGPIPE, "pipe", 0}, #endif #ifdef SIGALRM - { SIGALRM, "alrm", 0}, + {SIGALRM, "alrm", 0}, #endif - { SIGTERM, "term", 0}, + {SIGTERM, "term", 0}, #ifdef SIGUSR1 - { SIGUSR1, "usr1", 0}, + {SIGUSR1, "usr1", 0}, #endif #ifdef SIGUSR2 - { SIGUSR2, "usr2", 0}, + {SIGUSR2, "usr2", 0}, #endif #ifdef SIGCHLD - { SIGCHLD, "chld", 0}, + {SIGCHLD, "chld", 0}, #endif #ifdef SIGCONT - { SIGCONT, "cont", 0}, + {SIGCONT, "cont", 0}, #endif #ifdef SIGSTOP - { SIGSTOP, "stop", 0}, + {SIGSTOP, "stop", 0}, #endif #ifdef SIGTSTP - { SIGTSTP, "tstp", 0}, + {SIGTSTP, "tstp", 0}, #endif #ifdef SIGTTIN - { SIGTTIN, "ttin", 0}, + {SIGTTIN, "ttin", 0}, #endif #ifdef SIGTTOU - { SIGTTOU, "ttou", 0}, + {SIGTTOU, "ttou", 0}, #endif #ifdef SIGTRAP - { SIGTRAP, "trap", 0}, + {SIGTRAP, "trap", 0}, #endif #ifdef SIGBUS - { SIGBUS, "bus", 0}, + {SIGBUS, "bus", 0}, #endif #ifdef SIGSTKFLT - { SIGSTKFLT, "stkflt", 0}, + {SIGSTKFLT, "stkflt", 0}, #endif #ifdef SIGURG - { SIGURG, "urg", 0}, + {SIGURG, "urg", 0}, #endif #ifdef SIGIO - { SIGIO, "io", 0}, + {SIGIO, "io", 0}, #endif #ifdef SIGPOLL - { SIGPOLL, "poll", 0}, + {SIGPOLL, "poll", 0}, #endif #ifdef SIGXCPU - { SIGXCPU, "xcpu", 0}, + {SIGXCPU, "xcpu", 0}, #endif #ifdef SIGXFSZ - { SIGXFSZ, "xfsz", 0}, + {SIGXFSZ, "xfsz", 0}, #endif #ifdef SIGVTALRM - { SIGVTALRM, "vtalrm", 0}, + {SIGVTALRM, "vtalrm", 0}, #endif #ifdef SIGPROF - { SIGPROF, "prof", 0}, + {SIGPROF, "prof", 0}, #endif #ifdef SIGPWR - { SIGPWR, "pwr", 0}, + {SIGPWR, "pwr", 0}, #endif - { SIG_EXCEPTION, "prolog:exception", 0 }, + {SIG_EXCEPTION, "prolog:exception", 0}, #ifdef SIG_ATOM_GC - { SIG_ATOM_GC, "prolog:atom_gc", 0 }, + {SIG_ATOM_GC, "prolog:atom_gc", 0}, #endif {SIG_GC, "prolog:gc", 0}, #ifdef SIG_THREAD_SIGNAL @@ -122,7 +119,6 @@ static struct signame {-1, NULL, 0}}; - #if HAVE_SIGACTION static void my_signal_info(int sig, void *handler) { struct sigaction sigact; @@ -146,13 +142,13 @@ static void my_signal(int sig, void *handler) { #else static void my_signal(int sig, void *handler) { - #if HAVE_SIGNAL +#if HAVE_SIGNAL signal(sig, handler); #endif } static void my_signal_info(int sig, void *handler) { - #if HAVE_SIGNAL +#if HAVE_SIGNAL if (signal(sig, (void *)handler) == SIG_ERR) exit(1); #endif @@ -160,15 +156,13 @@ static void my_signal_info(int sig, void *handler) { #endif - static void HandleMatherr(int sig, void *sipv, void *uapv) { CACHE_REGS - LOCAL_matherror = Yap_MathException(); + LOCAL_Error_TYPE = Yap_MathException(); /* reset the registers so that we don't have trash in abstract machine */ Yap_external_signal(worker_id, YAP_FPE_SIGNAL); } - /* SWI emulation */ int Yap_signal_index(const char *name) { struct signame *sn = signames; @@ -318,10 +312,8 @@ static bool set_fpu_exceptions(Term flag) { return true; } - #if !defined(LIGHT) && !_MSC_VER && !defined(__MINGW32__) - static void ReceiveSignal(int s, void *x, void *y) { CACHE_REGS LOCAL_PrologMode |= InterruptMode; @@ -412,7 +404,6 @@ static BOOL WINAPI MSCHandleSignal(DWORD dwCtrlType) { } #endif - /* wrapper for alarm system call */ #if _MSC_VER || defined(__MINGW32__) @@ -671,7 +662,6 @@ VaxFixFrame(dummy) { #if defined(_WIN32) - int WINAPI win_yap(HANDLE, DWORD, LPVOID); 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); #endif - return LOCAL_matherror; -} - -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; + return LOCAL_Error_TYPE; } /* 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) { CACHE_REGS Term cm = CurrentModule; - - Yap_InitCPred("$fpe_error", 0, fpe_error, 0); Yap_InitCPred("$alarm", 4, alarm4, SafePredFlag | SyncPredFlag); CurrentModule = HACKS_MODULE; Yap_InitCPred("virtual_alarm", 4, virtual_alarm, SafePredFlag | SyncPredFlag); diff --git a/os/sysbits.h b/os/sysbits.h index 8c0dac6c2..f1bbe6307 100644 --- a/os/sysbits.h +++ b/os/sysbits.h @@ -37,11 +37,10 @@ #include #include #ifndef S_ISDIR -#define S_ISDIR(x) (((x)&_S_IFDIR)==_S_IFDIR) +#define S_ISDIR(x) (((x)&_S_IFDIR) == _S_IFDIR) #endif #endif - #ifdef HAVE_UNISTD_H #include #endif diff --git a/os/time.c b/os/time.c index cb105c55e..3927ea9d4 100644 --- a/os/time.c +++ b/os/time.c @@ -27,10 +27,10 @@ #if THREADS #define StartOfTimes (*(LOCAL_ThreadHandle.start_of_timesp)) -#define last_time (*(LOCAL_ThreadHandle.last_timep)) +#define last_time (*(LOCAL_ThreadHandle.last_timep)) #define StartOfTimes_sys (*(LOCAL_ThreadHandle.start_of_times_sysp)) -#define last_time_sys (*(LOCAL_ThreadHandle.last_time_sysp)) +#define last_time_sys (*(LOCAL_ThreadHandle.last_time_sysp)) #else /* since the point YAP was started */ @@ -45,82 +45,71 @@ static struct timeval StartOfTimes_sys; #endif /* store user time in this variable */ - void -Yap_InitTime (int wid) -{ - struct rusage rusage; +void Yap_InitTime(int wid) { + struct rusage rusage; #if THREADS - REMOTE_ThreadHandle(wid).start_of_timesp = (struct timeval *)malloc(sizeof(struct timeval)); - REMOTE_ThreadHandle(wid).last_timep = (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)); + REMOTE_ThreadHandle(wid).start_of_timesp = + (struct timeval *)malloc(sizeof(struct timeval)); + REMOTE_ThreadHandle(wid).last_timep = + (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); (*REMOTE_ThreadHandle(wid).last_timep).tv_sec = - (*REMOTE_ThreadHandle(wid).start_of_timesp).tv_sec = - rusage.ru_utime.tv_sec; + (*REMOTE_ThreadHandle(wid).start_of_timesp).tv_sec = + rusage.ru_utime.tv_sec; (*REMOTE_ThreadHandle(wid).last_timep).tv_usec = - (*REMOTE_ThreadHandle(wid).start_of_timesp).tv_usec = - rusage.ru_utime.tv_usec; + (*REMOTE_ThreadHandle(wid).start_of_timesp).tv_usec = + rusage.ru_utime.tv_usec; (*REMOTE_ThreadHandle(wid).last_time_sysp).tv_sec = - (*REMOTE_ThreadHandle(wid).start_of_times_sysp).tv_sec = - rusage.ru_stime.tv_sec; + (*REMOTE_ThreadHandle(wid).start_of_times_sysp).tv_sec = + rusage.ru_stime.tv_sec; (*REMOTE_ThreadHandle(wid).last_time_sysp).tv_usec = - (*REMOTE_ThreadHandle(wid).start_of_times_sysp).tv_usec = - rusage.ru_stime.tv_usec; + (*REMOTE_ThreadHandle(wid).start_of_times_sysp).tv_usec = + rusage.ru_stime.tv_usec; #else getrusage(RUSAGE_SELF, &rusage); - last_time.tv_sec = - StartOfTimes.tv_sec = - rusage.ru_utime.tv_sec; - last_time.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; + last_time.tv_sec = StartOfTimes.tv_sec = rusage.ru_utime.tv_sec; + last_time.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 } - -UInt -Yap_cputime ( void ) -{ +UInt Yap_cputime(void) { CACHE_REGS - struct rusage rusage; + struct rusage rusage; getrusage(RUSAGE_SELF, &rusage); - return((rusage.ru_utime.tv_sec - StartOfTimes.tv_sec)) * 1000 + - ((rusage.ru_utime.tv_usec - StartOfTimes.tv_usec) / 1000); + return ((rusage.ru_utime.tv_sec - StartOfTimes.tv_sec)) * 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 - struct rusage rusage; + struct rusage rusage; getrusage(RUSAGE_SELF, &rusage); *now = (rusage.ru_utime.tv_sec - StartOfTimes.tv_sec) * 1000 + - (rusage.ru_utime.tv_usec - StartOfTimes.tv_usec) / 1000; + (rusage.ru_utime.tv_usec - StartOfTimes.tv_usec) / 1000; *interval = (rusage.ru_utime.tv_sec - last_time.tv_sec) * 1000 + - (rusage.ru_utime.tv_usec - last_time.tv_usec) / 1000; + (rusage.ru_utime.tv_usec - last_time.tv_usec) / 1000; last_time.tv_usec = rusage.ru_utime.tv_usec; 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 - struct rusage rusage; + struct rusage rusage; getrusage(RUSAGE_SELF, &rusage); *now = (rusage.ru_stime.tv_sec - StartOfTimes_sys.tv_sec) * 1000 + - (rusage.ru_stime.tv_usec - StartOfTimes_sys.tv_usec) / 1000; + (rusage.ru_stime.tv_usec - StartOfTimes_sys.tv_usec) / 1000; *interval = (rusage.ru_stime.tv_sec - last_time_sys.tv_sec) * 1000 + - (rusage.ru_stime.tv_usec - last_time_sys.tv_usec) / 1000; + (rusage.ru_stime.tv_usec - last_time_sys.tv_usec) / 1000; last_time_sys.tv_usec = rusage.ru_stime.tv_usec; last_time_sys.tv_sec = rusage.ru_stime.tv_sec; } @@ -132,24 +121,25 @@ void Yap_systime_interval(Int *now,Int *interval) /* This is stolen from the Linux kernel. The problem is that mingw32 does not seem to have acces to div */ #ifndef do_div -#define do_div(n,base) ({ \ - unsigned long __upper, __low, __high, __mod; \ - asm("":"=a" (__low), "=d" (__high):"A" (n)); \ - __upper = __high; \ - if (__high) { \ - __upper = __high % (base); \ - __high = __high / (base); \ - } \ - asm("divl %2":"=a" (__low), "=d" (__mod):"rm" (base), "0" (__low), "1" (__upper)); \ - asm("":"=A" (n):"a" (__low),"d" (__high)); \ - __mod; \ - }) +#define do_div(n, base) \ + ({ \ + unsigned long __upper, __low, __high, __mod; \ + asm("" : "=a"(__low), "=d"(__high) : "A"(n)); \ + __upper = __high; \ + if (__high) { \ + __upper = __high % (base); \ + __high = __high / (base); \ + } \ + asm("divl %2" \ + : "=a"(__low), "=d"(__mod) \ + : "rm"(base), "0"(__low), "1"(__upper)); \ + asm("" : "=A"(n) : "a"(__low), "d"(__high)); \ + __mod; \ + }) #endif #endif - - #include static FILETIME StartOfTimes, last_time; @@ -159,148 +149,134 @@ static FILETIME StartOfTimes_sys, last_time_sys; static clock_t TimesStartOfTimes, Times_last_time; /* store user time in this variable */ -void -Yap_InitTime (int wid) -{ +void Yap_InitTime(int wid) { HANDLE hProcess = GetCurrentProcess(); FILETIME CreationTime, ExitTime, KernelTime, UserTime; - if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) { + if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, + &UserTime)) { /* WIN98 */ clock_t t; - t = clock (); + t = clock(); Times_last_time = TimesStartOfTimes = t; } else { #if THREADS - REMOTE_ThreadHandle(wid).start_of_timesp = (struct _FILETIME *)malloc(sizeof(FILETIME)); - REMOTE_ThreadHandle(wid).last_timep = (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).start_of_timesp = + (struct _FILETIME *)malloc(sizeof(FILETIME)); + REMOTE_ThreadHandle(wid).last_timep = + (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 = - UserTime.dwLowDateTime; + UserTime.dwLowDateTime; (*REMOTE_ThreadHandle(wid).last_timep).dwHighDateTime = - UserTime.dwHighDateTime; + UserTime.dwHighDateTime; (*REMOTE_ThreadHandle(wid).start_of_timesp).dwLowDateTime = - UserTime.dwLowDateTime; + UserTime.dwLowDateTime; (*REMOTE_ThreadHandle(wid).start_of_timesp).dwHighDateTime = - UserTime.dwHighDateTime; + UserTime.dwHighDateTime; (*REMOTE_ThreadHandle(wid).last_time_sysp).dwLowDateTime = - KernelTime.dwLowDateTime; + KernelTime.dwLowDateTime; (*REMOTE_ThreadHandle(wid).last_time_sysp).dwHighDateTime = - KernelTime.dwHighDateTime; + KernelTime.dwHighDateTime; (*REMOTE_ThreadHandle(wid).start_of_times_sysp).dwLowDateTime = - KernelTime.dwLowDateTime; + KernelTime.dwLowDateTime; (*REMOTE_ThreadHandle(wid).start_of_times_sysp).dwHighDateTime = - KernelTime.dwHighDateTime; + KernelTime.dwHighDateTime; #else - last_time.dwLowDateTime = - UserTime.dwLowDateTime; - last_time.dwHighDateTime = - UserTime.dwHighDateTime; - StartOfTimes.dwLowDateTime = - UserTime.dwLowDateTime; - StartOfTimes.dwHighDateTime = - UserTime.dwHighDateTime; - last_time_sys.dwLowDateTime = - KernelTime.dwLowDateTime; - last_time_sys.dwHighDateTime = - KernelTime.dwHighDateTime; - StartOfTimes_sys.dwLowDateTime = - KernelTime.dwLowDateTime; - StartOfTimes_sys.dwHighDateTime = - KernelTime.dwHighDateTime; + last_time.dwLowDateTime = UserTime.dwLowDateTime; + last_time.dwHighDateTime = UserTime.dwHighDateTime; + StartOfTimes.dwLowDateTime = UserTime.dwLowDateTime; + StartOfTimes.dwHighDateTime = UserTime.dwHighDateTime; + last_time_sys.dwLowDateTime = KernelTime.dwLowDateTime; + last_time_sys.dwHighDateTime = KernelTime.dwHighDateTime; + StartOfTimes_sys.dwLowDateTime = KernelTime.dwLowDateTime; + StartOfTimes_sys.dwHighDateTime = KernelTime.dwHighDateTime; #endif } } #ifdef __GNUC__ -static unsigned long long int -sub_utime(FILETIME t1, FILETIME t2) -{ +static unsigned long long int sub_utime(FILETIME t1, FILETIME t2) { ULARGE_INTEGER u[2]; - memcpy((void *)u,(void *)&t1,sizeof(FILETIME)); - memcpy((void *)(u+1),(void *)&t2,sizeof(FILETIME)); - return - u[0].QuadPart - u[1].QuadPart; + memcpy((void *)u, (void *)&t1, sizeof(FILETIME)); + memcpy((void *)(u + 1), (void *)&t2, sizeof(FILETIME)); + return u[0].QuadPart - u[1].QuadPart; } #endif -UInt -Yap_cputime ( void ) -{ +UInt Yap_cputime(void) { HANDLE hProcess = GetCurrentProcess(); FILETIME CreationTime, ExitTime, KernelTime, UserTime; - if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) { + if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, + &UserTime)) { clock_t t; - t = clock (); - return(((t - TimesStartOfTimes)*1000) / CLOCKS_PER_SEC); + t = clock(); + return (((t - TimesStartOfTimes) * 1000) / CLOCKS_PER_SEC); } else { #ifdef __GNUC__ - unsigned long long int t = - sub_utime(UserTime,StartOfTimes); - do_div(t,10000); - return((Int)t); + unsigned long long int t = sub_utime(UserTime, StartOfTimes); + do_div(t, 10000); + return ((Int)t); #endif #ifdef _MSC_VER __int64 t = *(__int64 *)&UserTime - *(__int64 *)&StartOfTimes; - return((Int)(t/10000)); + return ((Int)(t / 10000)); #endif } } -void Yap_cputime_interval(Int *now,Int *interval) -{ +void Yap_cputime_interval(Int *now, Int *interval) { HANDLE hProcess = GetCurrentProcess(); FILETIME CreationTime, ExitTime, KernelTime, UserTime; - if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) { + if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, + &UserTime)) { clock_t t; - t = clock (); - *now = ((t - TimesStartOfTimes)*1000) / CLOCKS_PER_SEC; + t = clock(); + *now = ((t - TimesStartOfTimes) * 1000) / CLOCKS_PER_SEC; *interval = (t - Times_last_time) * 1000 / CLOCKS_PER_SEC; Times_last_time = t; } else { #ifdef __GNUC__ - unsigned long long int t1 = - sub_utime(UserTime, StartOfTimes); - unsigned long long int t2 = - sub_utime(UserTime, last_time); - do_div(t1,10000); + unsigned long long int t1 = sub_utime(UserTime, StartOfTimes); + unsigned long long int t2 = sub_utime(UserTime, last_time); + do_div(t1, 10000); *now = (Int)t1; - do_div(t2,10000); + do_div(t2, 10000); *interval = (Int)t2; #endif #ifdef _MSC_VER __int64 t1 = *(__int64 *)&UserTime - *(__int64 *)&StartOfTimes; __int64 t2 = *(__int64 *)&UserTime - *(__int64 *)&last_time; - *now = (Int)(t1/10000); - *interval = (Int)(t2/10000); + *now = (Int)(t1 / 10000); + *interval = (Int)(t2 / 10000); #endif last_time.dwLowDateTime = UserTime.dwLowDateTime; last_time.dwHighDateTime = UserTime.dwHighDateTime; } } -void Yap_systime_interval(Int *now,Int *interval) -{ +void Yap_systime_interval(Int *now, Int *interval) { HANDLE hProcess = GetCurrentProcess(); FILETIME CreationTime, ExitTime, KernelTime, UserTime; - if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, &UserTime)) { + if (!GetProcessTimes(hProcess, &CreationTime, &ExitTime, &KernelTime, + &UserTime)) { *now = *interval = 0; /* not available */ } else { #ifdef __GNUC__ - unsigned long long int t1 = - sub_utime(KernelTime, StartOfTimes_sys); - unsigned long long int t2 = - sub_utime(KernelTime, last_time_sys); - do_div(t1,10000); + unsigned long long int t1 = sub_utime(KernelTime, StartOfTimes_sys); + unsigned long long int t2 = sub_utime(KernelTime, last_time_sys); + do_div(t1, 10000); *now = (Int)t1; - do_div(t2,10000); + do_div(t2, 10000); *interval = (Int)t2; #endif #ifdef _MSC_VER __int64 t1 = *(__int64 *)&KernelTime - *(__int64 *)&StartOfTimes_sys; __int64 t2 = *(__int64 *)&KernelTime - *(__int64 *)&last_time_sys; - *now = (Int)(t1/10000); - *interval = (Int)(t2/10000); + *now = (Int)(t1 / 10000); + *interval = (Int)(t2 / 10000); #endif last_time_sys.dwLowDateTime = KernelTime.dwLowDateTime; last_time_sys.dwHighDateTime = KernelTime.dwHighDateTime; @@ -313,7 +289,7 @@ void Yap_systime_interval(Int *now,Int *interval) #include -#define TicksPerSec CLOCKS_PER_SEC +#define TicksPerSec CLOCKS_PER_SEC #else @@ -329,16 +305,17 @@ void Yap_systime_interval(Int *now,Int *interval) #include #endif -#define TicksPerSec CLK_TCK +#define TicksPerSec CLK_TCK #endif -#if defined(__alpha) || defined(__FreeBSD__) || defined(__linux__) || defined(__DragonFly__) +#if defined(__alpha) || defined(__FreeBSD__) || defined(__linux__) || \ + defined(__DragonFly__) #if HAVE_TIME_H #include #endif -#define TicksPerSec sysconf(_SC_CLK_TCK) +#define TicksPerSec sysconf(_SC_CLK_TCK) #endif @@ -353,37 +330,31 @@ static clock_t StartOfTimes, last_time; static clock_t StartOfTimes_sys, last_time_sys; /* store user time in this variable */ -static void -InitTime (void) -{ +static void InitTime(void) { struct tms t; - times (&t); + times(&t); (*REMOTE_ThreadHandle(wid).last_timep) = StartOfTimes = t.tms_utime; last_time_sys = StartOfTimes_sys = t.tms_stime; } -UInt -Yap_cputime (void) -{ +UInt Yap_cputime(void) { struct tms 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; - times (&t); - *now = ((t.tms_utime - StartOfTimes)*1000) / TicksPerSec; + times(&t); + *now = ((t.tms_utime - StartOfTimes) * 1000) / TicksPerSec; *interval = (t.tms_utime - last_time) * 1000 / TicksPerSec; last_time = t.tms_utime; } -void Yap_systime_interval(Int *now,Int *interval) -{ +void Yap_systime_interval(Int *now, Int *interval) { struct tms t; - times (&t); - *now = ((t.tms_stime - StartOfTimes_sys)*1000) / TicksPerSec; + times(&t); + *now = ((t.tms_stime - StartOfTimes_sys) * 1000) / TicksPerSec; *interval = (t.tms_stime - last_time_sys) * 1000 / TicksPerSec; last_time_sys = t.tms_stime; } @@ -401,47 +372,42 @@ static struct timeval StartOfTimes; static struct timeval last_time; /* store user time in this variable */ -static void -InitTime (int wid) -{ - struct timeval tp; +static void InitTime(int wid) { + struct timeval tp; - 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_usec = (*REMOTE_ThreadHandle.start_of_timesp(wid)).tv_usec = tp.tv_usec; + 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_usec = + (*REMOTE_ThreadHandle.start_of_timesp(wid)).tv_usec = tp.tv_usec; } +UInt Yap_cputime(void) { + struct timeval tp; -UInt -Yap_cputime (void) -{ - struct timeval tp; - - gettimeofday(&tp,NULL); + gettimeofday(&tp, NULL); if (StartOfTimes.tv_usec > tp.tv_usec) - return((tp.tv_sec - StartOfTimes.tv_sec - 1) * 1000 + - (StartOfTimes.tv_usec - tp.tv_usec) /1000); + return ((tp.tv_sec - StartOfTimes.tv_sec - 1) * 1000 + + (StartOfTimes.tv_usec - tp.tv_usec) / 1000); else - return((tp.tv_sec - StartOfTimes.tv_sec)) * 1000 + - ((tp.tv_usec - StartOfTimes.tv_usec) / 1000); + return ((tp.tv_sec - StartOfTimes.tv_sec)) * 1000 + + ((tp.tv_usec - StartOfTimes.tv_usec) / 1000); } -void Yap_cputime_interval(Int *now,Int *interval) -{ - struct timeval tp; +void Yap_cputime_interval(Int *now, Int *interval) { + struct timeval tp; - gettimeofday(&tp,NULL); + gettimeofday(&tp, NULL); *now = (tp.tv_sec - StartOfTimes.tv_sec) * 1000 + - (tp.tv_usec - StartOfTimes.tv_usec) / 1000; + (tp.tv_usec - StartOfTimes.tv_usec) / 1000; *interval = (tp.tv_sec - last_time.tv_sec) * 1000 + - (tp.tv_usec - last_time.tv_usec) / 1000; + (tp.tv_usec - last_time.tv_usec) / 1000; last_time.tv_usec = tp.tv_usec; last_time.tv_sec = tp.tv_sec; } -void Yap_systime_interval(Int *now,Int *interval) -{ - *now = *interval = 0; /* not available */ +void Yap_systime_interval(Int *now, Int *interval) { + *now = *interval = 0; /* not available */ } #endif /* SIMICS */ @@ -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 */ #ifdef MPW -#include #include +#include #define TicksPerSec 60.0 -static double -real_cputime () -{ - return (((double) TickCount ()) / TicksPerSec); -} +static double real_cputime() { return (((double)TickCount()) / TicksPerSec); } #endif /* MPW */ @@ -469,18 +431,13 @@ real_cputime () static long *ptime; -gettime () -{ - *ptime = *(long *) 0x462; -} +gettime() { *ptime = *(long *)0x462; } -static double -real_cputime () -{ +static double real_cputime() { long thetime; ptime = &thetime; - xbios (38, gettime); - return (((double) thetime) / (Getrez () == 2 ? 70 : 60)); + xbios(38, gettime); + return (((double)thetime) / (Getrez() == 2 ? 70 : 60)); } #endif /* LATTICE */ @@ -492,18 +449,12 @@ real_cputime () static long *ptime; -static long -readtime () -{ - return (*((long *) 0x4ba)); -} +static long readtime() { return (*((long *)0x4ba)); } -static double -real_cputime () -{ +static double real_cputime() { long time; - time = Supexec (readtime); + time = Supexec(readtime); return (time / 200.0); } @@ -518,11 +469,7 @@ real_cputime () #define TicksPerSec 60.0 -static double -real_cputime () -{ - return (((double) TickCount ()) / TicksPerSec); -} +static double real_cputime() { return (((double)TickCount()) / TicksPerSec); } #endif /* LIGHT */ @@ -540,48 +487,35 @@ uint64_t Yap_StartOfWTimes; /* since the point YAP was started */ - void -Yap_InitWTime (void) -{ - Yap_StartOfWTimes = (uint64_t)gethrtime(); -} +void Yap_InitWTime(void) { Yap_StartOfWTimes = (uint64_t)gethrtime(); } /// returns time since Jan 1 1980 in nano-seconds -uint64_t Yap_walltime(uint64_t old) -{ - hrtime_t tp = gethrtime(); - /* return time in milliseconds */ - return = (uint64_t)tp; +uint64_t Yap_walltime(uint64_t old) { + hrtime_t tp = gethrtime(); + /* return time in milliseconds */ + return (uint64_t)tp; } - - #elif HAVE_GETTIMEOFDAY /* since the point YAP was started */ /* store user time in this variable */ - void -Yap_InitWTime (void) -{ - struct timeval tp; +void Yap_InitWTime(void) { + struct timeval tp; - gettimeofday(&tp, NULL); - Yap_StartOfWTimes = (uint64_t)tp.tv_sec * 1000000000 + (uint64_t)tp.tv_usec * 1000; + gettimeofday(&tp, NULL); + Yap_StartOfWTimes = + (uint64_t)tp.tv_sec * 1000000000 + (uint64_t)tp.tv_usec * 1000; } +/// returns time in nano-secs since the epoch +uint64_t Yap_walltime(void) { + struct timeval tp; - /// returns time in nano-secs since the epoch -uint64_t -Yap_walltime(void) -{ - struct timeval tp; - - gettimeofday(&tp, NULL); - return (uint64_t)tp.tv_sec * 1000000000 + (uint64_t)tp.tv_usec * 1000; + gettimeofday(&tp, NULL); + return (uint64_t)tp.tv_sec * 1000000000 + (uint64_t)tp.tv_usec * 1000; } - - #elif defined(_WIN32) #include @@ -591,67 +525,50 @@ Yap_walltime(void) static LARGE_INTEGER Frequency; /* store user time in this variable */ - void -Yap_InitWTime (void) -{ - LARGE_INTEGER ElapsedNanoseconds; - QueryPerformanceFrequency(&Frequency); - QueryPerformanceCounter(&ElapsedNanoseconds); - ElapsedNanoseconds.QuadPart *= 1000000; - ElapsedNanoseconds.QuadPart /= Frequency.QuadPart; - Yap_StartOfWTimes = (uint64_t)ElapsedNanoseconds.QuadPart; +void Yap_InitWTime(void) { + LARGE_INTEGER ElapsedNanoseconds; + QueryPerformanceFrequency(&Frequency); + QueryPerformanceCounter(&ElapsedNanoseconds); + ElapsedNanoseconds.QuadPart *= 1000000; + ElapsedNanoseconds.QuadPart /= Frequency.QuadPart; + Yap_StartOfWTimes = (uint64_t)ElapsedNanoseconds.QuadPart; } +uint64_t Yap_walltime(void) { + LARGE_INTEGER ElapsedNanoseconds; + QueryPerformanceCounter(&ElapsedNanoseconds); + // + // We now have the elapsed number of ticks, along with the + // number of ticks-per-second. We use these values + // to convert to the number of elapsed microseconds. + // To guard against loss-of-precision, we convert + // to microseconds *before* dividing by ticks-per-second. + // - -uint64_t -Yap_walltime (void) -{ - LARGE_INTEGER ElapsedNanoseconds; - QueryPerformanceCounter(&ElapsedNanoseconds); - // - // We now have the elapsed number of ticks, along with the - // number of ticks-per-second. We use these values - // to convert to the number of elapsed microseconds. - // To guard against loss-of-precision, we convert - // to microseconds *before* dividing by ticks-per-second. - // - - ElapsedNanoseconds.QuadPart *= 1000000; - ElapsedNanoseconds.QuadPart /= Frequency.QuadPart; - return ElapsedNanoseconds.QuadPart; + ElapsedNanoseconds.QuadPart *= 1000000; + ElapsedNanoseconds.QuadPart /= Frequency.QuadPart; + return ElapsedNanoseconds.QuadPart; } #elif HAVE_TIMES /* store user time in this variable */ - void -Yap_InitWTime (void) -{ +void Yap_InitWTime(void) { // start thread 0 - REMOTE_LastWTime(0) = - Yap_StartOfWTimes = ((uint64_t)times(NULL))*10000000/TicksPerSec; + REMOTE_LastWTime(0) = Yap_StartOfWTimes = + ((uint64_t)times(NULL)) * 10000000 / TicksPerSec; } -uint64_t -Yap_walltime (void) -{ +uint64_t Yap_walltime(void) { clock_t t; t = times(NULL); return = ((uint64_t)times(NULL)) * 10000000 / TicksPerSec; } #endif /* HAVE_TIMES */ - void - Yap_ReInitWTime (void) - { - Yap_InitWTime(); - } +void Yap_ReInitWTime(void) { Yap_InitWTime(); } - -void -Yap_InitTimePreds(void) -{ - /* can only do after heap is initialized */ - Yap_InitWTime(); +void Yap_InitTimePreds(void) { + /* can only do after heap is initialized */ + Yap_InitWTime(); } diff --git a/os/writeterm.c b/os/writeterm.c index 5b61975f7..381c5dea1 100644 --- a/os/writeterm.c +++ b/os/writeterm.c @@ -88,7 +88,6 @@ static char SccsId[] = "%W% %G%"; #endif #include "iopreds.h" - static Term readFromBuffer(const char *s, Term opts) { Term rval; int sno; @@ -100,7 +99,7 @@ static Term readFromBuffer(const char *s, Term opts) { Yap_CloseStream(sno); return rval; } - + #if _MSC_VER || defined(__MINGW32__) #define SYSTEM_STAT _stat #else @@ -291,21 +290,20 @@ end: /** * */ -bool Yap_WriteTerm( int output_stream, Term t, Term opts USES_REGS) -{ - xarg *args = Yap_ArgListToVector( opts, write_defs, WRITE_END); +bool Yap_WriteTerm(int output_stream, Term t, Term opts USES_REGS) { + xarg *args = Yap_ArgListToVector(opts, write_defs, WRITE_END); if (args == NULL) { if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; if (LOCAL_Error_TYPE) - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, opts, NULL); return false; } yhandle_t mySlots = Yap_StartSlots(); LOCK(GLOBAL_Stream[output_stream].streamlock); write_term(output_stream, t, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); - free( args ); + free(args); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -316,16 +314,16 @@ static Int write_term2(USES_REGS1) { /* '$write'(+Flags,?Term) */ /* notice: we must have ASP well set when using portray, otherwise we cannot make recursive Prolog calls */ - return Yap_WriteTerm( LOCAL_c_output_stream, ARG1, ARG2 PASS_REGS); + return Yap_WriteTerm(LOCAL_c_output_stream, ARG1, ARG2 PASS_REGS); } static Int write_term3(USES_REGS1) { - int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2"); + int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2"); if (output_stream < 0) { return false; } - return Yap_WriteTerm( output_stream, ARG2, ARG3 PASS_REGS); + return Yap_WriteTerm(output_stream, ARG2, ARG3 PASS_REGS); } static Int write2(USES_REGS1) { @@ -343,7 +341,7 @@ static Int write2(USES_REGS1) { if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; if (LOCAL_Error_TYPE) - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, TermNil, NULL); return false; } mySlots = Yap_StartSlots(); @@ -351,7 +349,7 @@ static Int write2(USES_REGS1) { args[WRITE_NUMBERVARS].tvalue = TermTrue; write_term(output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); - free( args ); + free(args); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -369,7 +367,7 @@ static Int write1(USES_REGS1) { if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; if (LOCAL_Error_TYPE) - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, TermNil, NULL); return false; } yhandle_t mySlots = Yap_StartSlots(); @@ -378,7 +376,7 @@ static Int write1(USES_REGS1) { LOCK(GLOBAL_Stream[output_stream].streamlock); write_term(output_stream, ARG1, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); - free( args ); + free(args); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -396,7 +394,7 @@ static Int write_canonical1(USES_REGS1) { if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; if (LOCAL_Error_TYPE) - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, TermNil, NULL); return false; } yhandle_t mySlots = Yap_StartSlots(); @@ -407,7 +405,7 @@ static Int write_canonical1(USES_REGS1) { LOCK(GLOBAL_Stream[output_stream].streamlock); write_term(output_stream, ARG1, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); - free( args ); + free(args); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -422,12 +420,12 @@ static Int write_canonical(USES_REGS1) { if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; if (LOCAL_Error_TYPE) - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, TermNil, NULL); return false; } int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2"); if (output_stream < 0) { - free( args ); + free(args); return false; } yhandle_t mySlots = Yap_StartSlots(); @@ -437,7 +435,7 @@ static Int write_canonical(USES_REGS1) { args[WRITE_QUOTED].tvalue = TermTrue; write_term(output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); - free( args ); + free(args); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -452,13 +450,13 @@ static Int writeq1(USES_REGS1) { if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; if (LOCAL_Error_TYPE) - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, TermNil, NULL); return false; } yhandle_t mySlots = Yap_StartSlots(); int output_stream = LOCAL_c_output_stream; if (output_stream == -1) { - free( args ); + free(args); output_stream = 1; } args[WRITE_NUMBERVARS].used = true; @@ -467,7 +465,7 @@ static Int writeq1(USES_REGS1) { args[WRITE_QUOTED].tvalue = TermTrue; write_term(output_stream, ARG1, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); - free( args ); + free(args); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -482,12 +480,12 @@ static Int writeq(USES_REGS1) { if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; if (LOCAL_Error_TYPE) - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, TermNil, NULL); return false; } int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2"); if (output_stream < 0) { - free( args ); + free(args); return false; } yhandle_t mySlots = Yap_StartSlots(); @@ -497,7 +495,7 @@ static Int writeq(USES_REGS1) { args[WRITE_QUOTED].tvalue = TermTrue; write_term(output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); - free( args ); + free(args); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -512,13 +510,13 @@ static Int print1(USES_REGS1) { if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; if (LOCAL_Error_TYPE) - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, TermNil, NULL); return false; } yhandle_t mySlots = Yap_StartSlots(); int output_stream = LOCAL_c_output_stream; if (output_stream == -1) { - free( args ); + free(args); output_stream = 1; } args[WRITE_PORTRAY].used = true; @@ -528,7 +526,7 @@ static Int print1(USES_REGS1) { LOCK(GLOBAL_Stream[output_stream].streamlock); write_term(output_stream, ARG1, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); - free( args ); + free(args); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -543,12 +541,12 @@ static Int print(USES_REGS1) { if (LOCAL_Error_TYPE == DOMAIN_ERROR_OUT_OF_RANGE) LOCAL_Error_TYPE = DOMAIN_ERROR_WRITE_OPTION; if (LOCAL_Error_TYPE) - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, TermNil, NULL); return false; } int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "write/2"); if (output_stream < 0) { - free( args ); + free(args); return false; } yhandle_t mySlots = Yap_StartSlots(); @@ -558,7 +556,7 @@ static Int print(USES_REGS1) { args[WRITE_NUMBERVARS].tvalue = TermTrue; write_term(output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); - free( args ); + free(args); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -574,7 +572,7 @@ static Int writeln1(USES_REGS1) { xarg *args = Yap_ArgListToVector(TermNil, write_defs, WRITE_END); if (args == NULL) { if (LOCAL_Error_TYPE) - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, TermNil, NULL); return false; } yhandle_t mySlots = Yap_StartSlots(); @@ -585,7 +583,7 @@ static Int writeln1(USES_REGS1) { LOCK(GLOBAL_Stream[output_stream].streamlock); write_term(output_stream, ARG1, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); - free( args ); + free(args); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -598,13 +596,13 @@ static Int writeln(USES_REGS1) { xarg *args = Yap_ArgListToVector(TermNil, write_defs, WRITE_END); if (args == NULL) { if (LOCAL_Error_TYPE) - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, TermNil, NULL); return false; } int output_stream = Yap_CheckTextStream(ARG1, Output_Stream_f, "writeln/2"); if (output_stream < 0) { - free( args ); -return false; + free(args); + return false; } yhandle_t mySlots = Yap_StartSlots(); args[WRITE_NL].used = true; @@ -613,7 +611,7 @@ return false; args[WRITE_NUMBERVARS].tvalue = TermTrue; write_term(output_stream, ARG2, args PASS_REGS); UNLOCK(GLOBAL_Stream[output_stream].streamlock); - free( args ); + free(args); Yap_CloseSlots(mySlots); Yap_RaiseException(); return (TRUE); @@ -676,7 +674,6 @@ static Int dollar_var(USES_REGS1) { return Yap_unify(tv, ARG2); } - static Int term_to_string(USES_REGS1) { Term t2 = Deref(ARG2), rc = false, t1 = Deref(ARG1); const char *s; @@ -703,9 +700,9 @@ static Int term_to_atom(USES_REGS1) { Term t2 = Deref(ARG2), ctl, rc = false; Atom at; if (IsVarTerm(t2)) { - size_t length; - const char *s = Yap_TermToString(Deref(ARG1), &length, LOCAL_encoding, - Quote_illegal_f | Handle_vars_f); + size_t length; + const char *s = Yap_TermToString(Deref(ARG1), &length, LOCAL_encoding, + Quote_illegal_f | Handle_vars_f); if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) { Yap_Error(RESOURCE_ERROR_HEAP, t2, "Could not get memory from the operating system"); @@ -737,9 +734,9 @@ void Yap_InitWriteTPreds(void) { Yap_InitCPred("print", 2, print, SyncPredFlag); Yap_InitCPred("write_depth", 3, p_write_depth, SafePredFlag | SyncPredFlag); ; - - Yap_InitCPred("term_to_string", 3, term_to_string, 0); - Yap_InitCPred("term_to_atom", 3, term_to_atom, 0); + + Yap_InitCPred("term_to_string", 3, term_to_string, 0); + Yap_InitCPred("term_to_atom", 3, term_to_atom, 0); Yap_InitCPred("write_depth", 3, p_write_depth, SafePredFlag | SyncPredFlag); ; Yap_InitCPred("$VAR", 2, dollar_var, SafePredFlag); diff --git a/packages/python/pandas.yap b/packages/python/pandas.yap index 04d5b105d..62c68b1b4 100644 --- a/packages/python/pandas.yap +++ b/packages/python/pandas.yap @@ -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) :- - \ No newline at end of file +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]) diff --git a/packages/python/python.h b/packages/python/python.h index 8046b38d3..bacb3d6e9 100644 --- a/packages/python/python.h +++ b/packages/python/python.h @@ -21,7 +21,7 @@ typedef YAP_Arity arity_t; extern atom_t ATOM_true, ATOM_false, ATOM_colon, ATOM_dot, ATOM_none, ATOM_t, - ATOM_comma, ATOM_builtin, ATOM_V, ATOM_A, ATOM_self; + ATOM_comma, ATOM_builtin, ATOM_V, ATOM_A, ATOM_self; extern functor_t FUNCTOR_dollar1, FUNCTOR_abs1, FUNCTOR_all1, FUNCTOR_any1, FUNCTOR_bin1, FUNCTOR_brackets1, FUNCTOR_comma2, FUNCTOR_dir1, @@ -39,6 +39,8 @@ extern PyObject *py_F2P; 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) { if (o == NULL) 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_pytree(term_t t, functor_t fun); - extern PyObject *yap_to_python(YAP_Term t, bool eval); extern PyObject *term_to_python(term_t t, bool eval); extern foreign_t python_to_ptr(PyObject *pVal, term_t t); diff --git a/packages/python/yap_kernel/yap_kernel.py b/packages/python/yap_kernel/yap_kernel.py index 4156545be..17c072b5d 100644 --- a/packages/python/yap_kernel/yap_kernel.py +++ b/packages/python/yap_kernel/yap_kernel.py @@ -138,9 +138,9 @@ class YAPKernel(KernelBase): implementation = 'YAP' implementation_version = release.version language_info = { - 'name': 'python', + 'name': 'prolog', 'version': sys.version.split()[0], - 'mimetype': 'text/x-python', + 'mimetype': 'text/x-prolog', 'codemirror_mode': { 'name': 'prolog', 'version': sys.version_info[0] @@ -333,7 +333,7 @@ class YAPKernel(KernelBase): elif hist_access_type == 'range': hist = self.shell.history_manager.get_range(session, start, stop, - raw=raw, output=output) + raw=raw, output=output) elif hist_access_type == 'search': hist = self.shell.history_manager.search( diff --git a/packages/raptor/raptor_yap.c b/packages/raptor/raptor_yap.c index ba7301675..5460d219f 100644 --- a/packages/raptor/raptor_yap.c +++ b/packages/raptor/raptor_yap.c @@ -15,22 +15,22 @@ * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. */ -#include #include +#include #include #include -#include "raptor_config.h" #include "YapInterface.h" -#ifdef HAVE_RAPTOR2_RAPTOR2_H +#include "raptor_config.h" +#ifdef HAVE_RAPTOR2_RAPTOR2_H #include "raptor2/raptor2.h" #else #include "raptor2.h" #endif -void raptor_yap_init (void); +void raptor_yap_init(void); -raptor_world* world; +raptor_world *world; struct exo_aux { YAP_Functor functor; @@ -38,79 +38,74 @@ struct exo_aux { size_t n; }; -static YAP_Atom -term_load(const raptor_term *term) -{ +static YAP_Atom term_load(const raptor_term *term) { size_t len; - switch(term->type) { - case RAPTOR_TERM_TYPE_LITERAL: -// fprintf(stderr, "%s,", term->value.literal.string); - return YAP_LookupAtom((const char *)term->value.literal.string); + switch (term->type) { + case RAPTOR_TERM_TYPE_LITERAL: + // fprintf(stderr, "%s,", term->value.literal.string); + return YAP_LookupAtom((const char *)term->value.literal.string); - case RAPTOR_TERM_TYPE_BLANK: -// fprintf(stderr, "%s,", term->value.blank.string); - return YAP_LookupAtom((const char *)term->value.blank.string); + case RAPTOR_TERM_TYPE_BLANK: + // fprintf(stderr, "%s,", term->value.blank.string); + return YAP_LookupAtom((const char *)term->value.blank.string); - case RAPTOR_TERM_TYPE_URI: -// fprintf(stderr, "%s,", 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_URI: + // fprintf(stderr, "%s,", + // 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: - default: - raptor_log_error_formatted(term->world, RAPTOR_LOG_LEVEL_ERROR, NULL, - "Triple has unsupported term type %d", - term->type); - break; - } + case RAPTOR_TERM_TYPE_UNKNOWN: + default: - return NULL; + raptor_log_error_formatted(term->world, RAPTOR_LOG_LEVEL_ERROR, NULL, + "Triple has unsupported term type %d", + term->type); + break; + } + + return NULL; } static int so_far = 0; -static void -load_triples(void* user_data, raptor_statement* triple) -{ - struct exo_aux *aux = (struct exo_aux *) user_data; +static void load_triples(void *user_data, raptor_statement *triple) { + struct exo_aux *aux = (struct exo_aux *)user_data; YAP_Term args[4]; - //args[0] = (YAP_CELL)aux->functor; + // args[0] = (YAP_CELL)aux->functor; args[0] = YAP_MkAtomTerm(term_load(triple->subject)); args[1] = YAP_MkAtomTerm(term_load(triple->predicate)); args[2] = YAP_MkAtomTerm(term_load(triple->object)); -// fprintf(stderr, "\n"); + // fprintf(stderr, "\n"); - YAP_AssertTuples( aux->pred, args, so_far++, 1 ); + YAP_AssertTuples(aux->pred, args, so_far++, 1); } -static void -count_triples(void* user_data, raptor_statement* triple) -{ - unsigned int* count_p = (unsigned int*)user_data; +static void count_triples(void *user_data, raptor_statement *triple) { + unsigned int *count_p = (unsigned int *)user_data; (*count_p)++; term_load(triple->subject); term_load(triple->predicate); term_load(triple->object); -// fprintf(stderr, "\n"); + // fprintf(stderr, "\n"); } -static YAP_Bool -load(void) -{ +static YAP_Bool load(void) { YAP_Term tfn = YAP_ARG1; YAP_Term mod = YAP_ARG2; YAP_Term tfunctor = YAP_ARG3; const char *filename; - raptor_parser* rdf_parser = NULL; + raptor_parser *rdf_parser = NULL; unsigned int count; unsigned char *uri_string; raptor_uri *uri, *base_uri; if (YAP_IsVarTerm(tfn) || !YAP_IsAtomTerm(tfn)) { - return FALSE; - } + return FALSE; + } filename = YAP_AtomName(YAP_AtomOfTerm(tfn)); @@ -123,11 +118,11 @@ load(void) base_uri = raptor_uri_copy(uri); count = 0; - if(!raptor_parser_parse_file(rdf_parser, uri, base_uri)) { -// fprintf(stderr, "%s : %d triples\n", filename, count); + if (!raptor_parser_parse_file(rdf_parser, uri, base_uri)) { + // fprintf(stderr, "%s : %d triples\n", filename, count); } else { - fprintf(stderr, "%s : failed to parse\n", filename); - return FALSE; + fprintf(stderr, "%s : failed to parse\n", filename); + return FALSE; } /* now lets load */ @@ -136,18 +131,18 @@ load(void) size_t sz; aux.functor = YAP_MkFunctor(YAP_AtomOfTerm(tfunctor), 3); - aux.pred = YAP_FunctorToPredInModule( aux.functor, mod ); - sz = 3*sizeof(YAP_CELL)*count; - - if (!YAP_NewExo( aux.pred, sz, NULL)){ + aux.pred = YAP_FunctorToPredInModule(aux.functor, mod); + sz = 3 * sizeof(YAP_CELL) * count; + + if (!YAP_NewExo(aux.pred, sz, NULL)) { fprintf(stderr, "Failed to alocate space\n"); return FALSE; } aux.n = 0; - raptor_parser_set_statement_handler(rdf_parser, (void *) &aux, load_triples); - if(!raptor_parser_parse_file(rdf_parser, uri, base_uri)) { - fprintf(stderr, "%s : %d triples\n", filename, count); + raptor_parser_set_statement_handler(rdf_parser, (void *)&aux, load_triples); + if (!raptor_parser_parse_file(rdf_parser, uri, base_uri)) { + fprintf(stderr, "%s : %d triples\n", filename, count); } } @@ -160,16 +155,13 @@ load(void) return TRUE; } -static inline void -raptor_yap_halt (int exit, void* world) -{ - raptor_free_world((raptor_world*) world); +static inline void raptor_yap_halt(int exit, void *world) { + raptor_free_world((raptor_world *)world); } -void raptor_yap_init (void) -{ +void raptor_yap_init(void) { world = raptor_new_world(); - YAP_HaltRegisterHook (raptor_yap_halt, (void *) world); + YAP_HaltRegisterHook(raptor_yap_halt, (void *)world); YAP_UserCPredicate("rdf_load", load, 3); } diff --git a/pl/dbload.yap b/pl/dbload.yap index d9fb466c0..4506db1d1 100644 --- a/pl/dbload.yap +++ b/pl/dbload.yap @@ -27,44 +27,19 @@ :- dynamic dbloading/6, dbprocess/2. -dbload_from_stream(R, M0, Type) :- - repeat, - read(R,T), - ( T == end_of_file -> !, close_dbload(R, Type); - dbload_count(T, M0), - fail - ). - -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(_, _). +dbload_from_stream(R, M0, rdf, term ) :- + '$lines_in_file'(R, Lines), + '$input_lines'(R, Type, Lines), + dbload_from_stream(R, M0, Type, Storage ) :- + '$lines_in_file'(R, Lines), + '$input_lines'(R, Type, Lines), +'$input_lines'(R, csv, yeLines ) :- + '$process_lines'(R, Lines, Type ), + close(R). prolog:load_db(Fs) :- - '$current_module'(M0), + '$current_module'(M0), prolog_flag(agc_margin,Old,0), dbload(Fs,M0,load_db(Fs)), load_facts, @@ -73,8 +48,8 @@ prolog:load_db(Fs) :- dbload(Fs, _, G) :- var(Fs), - '$do_error'(instantiation_error,G). -dbload([], _, _) :- !. + '$do_error'(instantiation_error,G). +dbload([], _, _) :- !. dbload([F|Fs], M0, G) :- !, dbload(F, M0, G), dbload(Fs, M0, G). @@ -99,7 +74,7 @@ check_dbload_stream(R, M0) :- catch(read(R,T), _, fail), ( T = end_of_file -> !; dbload_count(T, M0), - fail + fail ). dbload_count(T0, M0) :- @@ -121,7 +96,7 @@ get_module(M1:T0,_,T,M) :- !, get_module(T0, M1, T , M). get_module(T,M,T,M). - + load_facts :- !, % yap_flag(exo_compilation, on), !. load_exofacts. @@ -145,7 +120,7 @@ dbload_add_facts(R, M) :- catch(read(R,T), _, fail), ( T = end_of_file -> !; dbload_add_fact(T, M), - fail + fail ). dbload_add_fact(T0, M0) :- @@ -182,7 +157,7 @@ protected_exodb_add_fact(R, M) :- read(R,T), ( T == end_of_file -> !; exodb_add_fact(T, M), - fail + fail ). exodb_add_fact(T0, M0) :- @@ -199,4 +174,3 @@ clean_up :- retractall(dbprocess(_,_)), fail. clean_up. - diff --git a/pl/signals.yap b/pl/signals.yap index d12d0c2c9..1729c9510 100644 --- a/pl/signals.yap +++ b/pl/signals.yap @@ -191,9 +191,8 @@ order of dispatch. '$continue_signals', '$hacks':'$stack_dump', '$execute0'(G,M). -'$do_signal'(sig_fpe, [_M|_G]) :- - '$fpe_error'. -% Unix signals +'$do_signal'(sig_fpe,G) :- + '$signal_handler'(sig_fpe, G) '$do_signal'(sig_alarm, G) :- '$signal_handler'(sig_alarm, G). '$do_signal'(sig_vtalarm, G) :-