From ad5347257be6c1d00cc56bb18d27fa9277c0f393 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Sun, 16 Oct 2016 17:23:00 -0500 Subject: [PATCH 01/41] avoid long vrs in error handling --- os/streams.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/os/streams.c b/os/streams.c index 78c81f7ca..0f32b6ab6 100644 --- a/os/streams.c +++ b/os/streams.c @@ -631,7 +631,7 @@ static Int cont_stream_property(USES_REGS1) { /* current_stream */ if (LOCAL_Error_TYPE != YAP_NO_ERROR) { if (LOCAL_Error_TYPE == DOMAIN_ERROR_GENERIC_ARGUMENT) LOCAL_Error_TYPE = DOMAIN_ERROR_STREAM_PROPERTY_OPTION; - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, t2, NULL); return false; } cut_fail(); @@ -714,7 +714,7 @@ static Int stream_property(USES_REGS1) { /* Init current_stream */ if (LOCAL_Error_TYPE != YAP_NO_ERROR) { if (LOCAL_Error_TYPE == DOMAIN_ERROR_PROLOG_FLAG) LOCAL_Error_TYPE = DOMAIN_ERROR_STREAM_PROPERTY_OPTION; - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, ARG2, NULL); return false; } UNLOCK(GLOBAL_Stream[i].streamlock); @@ -774,7 +774,7 @@ static bool do_set_stream(int sno, if (LOCAL_Error_TYPE != YAP_NO_ERROR) { if (LOCAL_Error_TYPE == DOMAIN_ERROR_GENERIC_ARGUMENT) LOCAL_Error_TYPE = DOMAIN_ERROR_SET_STREAM_OPTION; - Yap_Error(LOCAL_Error_TYPE, LOCAL_Error_Term, NULL); + Yap_Error(LOCAL_Error_TYPE, opts, NULL); } UNLOCK(GLOBAL_Stream[sno].streamlock); return false; From d082af605d9cda95fd597d00ea93cf286b147d55 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 19 Oct 2016 22:44:59 -0500 Subject: [PATCH 02/41] less invasive error handling --- C/absmi_insts.i | 7 +- C/atomic.c | 89 +- C/cdmgr.c | 9 +- C/cmppreds.c | 846 +++---- C/compiler.c | 2869 +++++++++++----------- C/dbase.c | 12 +- C/errors.c | 70 +- C/eval.c | 343 ++- C/exec.c | 18 +- C/flags.c | 4 +- C/load_dl.c | 11 +- C/load_foreign.c | 3 +- C/parser.c | 7 +- C/prim_absmi_insts.h | 1855 +++++--------- C/save.c | 8 +- C/scanner.c | 3 +- C/stack.c | 32 +- C/text.c | 56 +- CXX/yapi.cpp | 41 +- CXX/yapie.hh | 10 +- CXX/yapq.hh | 11 +- H/LOCALS | 12 +- H/YapText.h | 42 + H/absmi.h | 57 +- H/eval.h | 17 +- H/generated/dlocals.h | 14 +- H/generated/hlocals.h | 11 +- H/generated/ilocals.h | 11 +- H/generated/rlocals.h | 5 - H/walkclause.h | 1444 ++++++----- include/YapError.h | 50 +- os/iopreds.c | 27 +- os/iopreds.h | 55 +- os/readterm.c | 308 ++- os/sig.c | 121 +- os/sysbits.h | 3 +- os/time.c | 485 ++-- os/writeterm.c | 85 +- packages/python/pandas.yap | 62 +- packages/python/python.h | 5 +- packages/python/yap_kernel/yap_kernel.py | 6 +- packages/raptor/raptor_yap.c | 116 +- pl/dbload.yap | 58 +- pl/signals.yap | 5 +- 44 files changed, 4258 insertions(+), 5045 deletions(-) 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) :- From 46a9d52d2de9b7c66e631f323bd13e913d1dd722 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 4 Nov 2016 11:36:48 -0500 Subject: [PATCH 03/41] Memory management and UTF-8 for all fixes --- C/adtdefs.c | 15 +- C/alloc.c | 10 +- C/atomic.c | 611 ++++++++++++++++++++++++------------------- C/cmppreds.c | 33 ++- C/compiler.c | 16 +- C/errors.c | 21 ++ C/exec.c | 1 + C/grow.c | 2 - C/parser.c | 100 ++++--- C/scanner.c | 17 +- C/text.c | 54 ++-- C/write.c | 6 +- CXX/yapa.hh | 8 +- H/ATOMS | 2 - H/ScannerTypes.h | 5 +- H/YapGFlagInfo.h | 2 +- H/YapText.h | 2 +- H/generated/iatoms.h | 2 - H/generated/ratoms.h | 2 - H/generated/tatoms.h | 3 - include/YapError.h | 9 +- os/iopreds.c | 2 +- os/iopreds.h | 2 +- os/readterm.c | 75 +++--- pl/boot.yap | 8 +- pl/grammar.yap | 1 - 26 files changed, 526 insertions(+), 483 deletions(-) diff --git a/C/adtdefs.c b/C/adtdefs.c index c83473e5d..617027a14 100755 --- a/C/adtdefs.c +++ b/C/adtdefs.c @@ -57,10 +57,15 @@ GetFunctorProp(AtomEntry *ae, arity_t arity) { /* look property list of atom a for kind */ FunctorEntry *pp; - pp = RepFunctorProp(ae->PropsOfAE); - while (!EndOfPAEntr(pp) && (pp = RepFunctorProp(pp->NextOfPE))) - ; - return (AbsFunctorProp(pp)); + PropEntry *p = RepFunctorProp(ae->PropsOfAE); + while (p != NIL) { + if (p->KindOfPE == FunctorProperty && + RepFunctorProp(p)->ArityOfFE == arity) { + return p; + } + p = p->NextOfPE; + } + return NIL; } /* vsc: We must guarantee that IsVarTerm(functor) returns true! */ @@ -155,7 +160,6 @@ LookupAtom(const unsigned char *atom) { /* lookup atom in atom table */ hash = HashFunction(p); hash = hash % sz; - /* we'll start by holding a read lock in order to avoid contention */ READ_LOCK(HashChain[hash].AERWLock); a = HashChain[hash].Entry; @@ -199,6 +203,7 @@ LookupAtom(const unsigned char *atom) { /* lookup atom in atom table */ if (NOfAtoms > 2 * AtomHashTableSize) { Yap_signal(YAP_CDOVF_SIGNAL); } + return na; } diff --git a/C/alloc.c b/C/alloc.c index 842f96966..395d9ab5f 100644 --- a/C/alloc.c +++ b/C/alloc.c @@ -77,7 +77,7 @@ void *my_malloc(size_t sz) { p = malloc(sz); // Yap_DebugPuts(stderr,"gof\n"); - if (Yap_do_low_level_trace||1) + if (Yap_do_low_level_trace) fprintf(stderr, "+ %p : %lu\n", p, sz); if (sz > 500 && write_malloc++ > 0) __android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "+ %d %p", write_malloc, @@ -89,8 +89,8 @@ void *my_realloc(void *ptr, size_t sz) { void *p; p = realloc(ptr, sz); - if (Yap_do_low_level_trace||1) - fprintf(stderr, "+ %p -> %p : %lu\n", ptr, p, sz); + if (Yap_do_low_level_trace) + // fprintf(stderr, "+ %p -> %p : %lu\n", ptr, p, sz); // Yap_DebugPuts(stderr,"gof\n"); if (sz > 500 && write_malloc++ > 0) __android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "* %d %p", write_malloc, @@ -100,7 +100,7 @@ void *my_realloc(void *ptr, size_t sz) { void my_free(void *p) { // printf("f %p\n",p); - if (Yap_do_low_level_trace||1) + if (Yap_do_low_level_trace) fprintf(stderr, "+ %p\n", p); if (write_malloc && write_malloc++ > 0) __android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "- %d %p", write_malloc, @@ -671,7 +671,7 @@ static char *AllocHeap(size_t size) { LOCK(FreeBlocksLock); if ((b = GetBlock(size))) { if (b->b_size >= size + 24 + 1) { - n = (BlockHeader *)(((YAP_SEG_SIZE *)b) + size + 1); + n = (BlockHeader *)(((YAP_SEG_SIZE *)b) + size + 1)v; n->b_size = b->b_size - size - 1; b->b_size = size; AddToFreeList(n); diff --git a/C/atomic.c b/C/atomic.c index b0ce06e4d..2b274a134 100644 --- a/C/atomic.c +++ b/C/atomic.c @@ -68,6 +68,10 @@ static Int hide_atom(USES_REGS1); static Int hidden_atom(USES_REGS1); static Int unhide_atom(USES_REGS1); +#define ReleaseAndReturn(r) { pop_text_stack(l); return r; } +#define release_cut_fail() { pop_text_stack(l); cut_fail(); } +#define release_cut_succeed() { pop_text_stack(l); cut_succeed(); } + static int AlreadyHidden(unsigned char *name) { AtomEntry *chain; @@ -78,8 +82,8 @@ static int AlreadyHidden(unsigned char *name) { strcmp((char *)chain->StrOfAE, (char *)name) != 0) chain = RepAtom(chain->NextOfAE); if (EndOfPAEntr(chain)) - return (FALSE); - return (TRUE); + return false; + return true; } /** @pred hide_atom(+ _Atom_) @@ -237,7 +241,7 @@ static Int char_code(USES_REGS1) { return (FALSE); } size_t n = put_utf8( codes, code); - codes[0] = code; + codes[n] = code; tout = MkAtomTerm(Yap_ULookupAtom(codes)); } else { char codes[2]; @@ -270,50 +274,62 @@ static Int name(USES_REGS1) { /* name(?Atomic,?String) */ Term t = Deref(ARG2), NewT, AtomNameT = Deref(ARG1); LOCAL_MAX_SIZE = 1024; + int l = push_text_stack( ); restart_aux: if (Yap_IsGroundTerm(AtomNameT)) { if (!IsVarTerm(t) && !IsPairTerm(t) && t != TermNil) { Yap_Error(TYPE_ERROR_LIST, ARG2, "name/2"); - return FALSE; + pop_text_stack( l); + ReleaseAndReturn( FALSE ); } // verify if an atom, int, float or bi§gnnum NewT = Yap_AtomicToListOfCodes(AtomNameT PASS_REGS); - if (NewT) - return Yap_unify(NewT, ARG2); + if (NewT) { + pop_text_stack( l); + ReleaseAndReturn( Yap_unify(NewT, ARG2) ); + } // else } else if (IsVarTerm(t)) { Yap_Error(INSTANTIATION_ERROR, t, "name/2"); + pop_text_stack( l); return FALSE; } else { Term at = Yap_ListToAtomic(t PASS_REGS); - if (at) - return Yap_unify(at, ARG1); + if (at) { + pop_text_stack( l); + ReleaseAndReturn( Yap_unify(at, ARG1) ); + } } if (LOCAL_Error_TYPE && Yap_HandleError("atom/2")) { AtomNameT = Deref(ARG1); t = Deref(ARG2); goto restart_aux; } - return FALSE; + pop_text_stack( l); + ReleaseAndReturn( FALSE ); } static Int string_to_atomic( USES_REGS1) { /* string_to_atom(?String,?Atom) */ Term t2 = Deref(ARG2), t1 = Deref(ARG1); LOCAL_MAX_SIZE = 1024; - + int l = push_text_stack( ); restart_aux: if (IsStringTerm(t1)) { Term t; // verify if an atom, int, float or bignnum t = Yap_StringToAtomic(t1 PASS_REGS); - if (t != 0L) - return Yap_unify(t, t2); + if (t != 0L) { + pop_text_stack( l); + ReleaseAndReturn( Yap_unify(t, t2) ); + } // else } else if (IsVarTerm(t1)) { Term t0 = Yap_AtomicToString(t2 PASS_REGS); - if (t0) - return Yap_unify(t0, t1); + if (t0) { + pop_text_stack( l); + ReleaseAndReturn( Yap_unify(t0, t1) ); + } } else { LOCAL_Error_TYPE = TYPE_ERROR_STRING; } @@ -322,26 +338,32 @@ restart_aux: t2 = Deref(ARG2); goto restart_aux; } - return FALSE; + pop_text_stack( l); + ReleaseAndReturn( FALSE ); } static Int string_to_atom( USES_REGS1) { /* string_to_atom(?String,?Atom) */ Term t2 = Deref(ARG2), t1 = Deref(ARG1); LOCAL_MAX_SIZE = 1024; + int l = push_text_stack( ); restart_aux: if (IsStringTerm(t1)) { Atom at; // verify if an atom, int, float or bignnum at = Yap_StringSWIToAtom(t1 PASS_REGS); - if (at) - return Yap_unify(MkAtomTerm(at), t2); + if (at) { + pop_text_stack( l); + ReleaseAndReturn( Yap_unify(MkAtomTerm(at), t2) ); + } // else } else if (IsVarTerm(t1)) { Term t0 = Yap_AtomSWIToString(t2 PASS_REGS); - if (t0) - return Yap_unify(t0, t1); + if (t0) { + pop_text_stack( l); + ReleaseAndReturn( Yap_unify(t0, t1) ); + } } else { LOCAL_Error_TYPE = TYPE_ERROR_ATOM; } @@ -350,21 +372,26 @@ restart_aux: t2 = Deref(ARG2); goto restart_aux; } - return FALSE; + pop_text_stack( l); + ReleaseAndReturn( FALSE ); } static Int string_to_list(USES_REGS1) { Term list = Deref(ARG2), string = Deref(ARG1); LOCAL_MAX_SIZE = 1024; + int l = push_text_stack( ); restart_aux: if (IsVarTerm(string)) { Term t1 = Yap_ListToString(list PASS_REGS); - if (t1) - return Yap_unify(ARG1, t1); + if (t1) { + pop_text_stack( l); + ReleaseAndReturn( Yap_unify(ARG1, t1) ); + } } else if (IsStringTerm(string)) { Term tf = Yap_StringToListOfCodes(string PASS_REGS); - return Yap_unify(ARG2, tf); + pop_text_stack( l); + ReleaseAndReturn( Yap_unify(ARG2, tf) ); } else { LOCAL_Error_TYPE = TYPE_ERROR_STRING; } @@ -373,12 +400,14 @@ restart_aux: list = Deref(ARG2); goto restart_aux; } - return FALSE; + pop_text_stack( l); + ReleaseAndReturn( FALSE ); } static Int atom_string(USES_REGS1) { Term t1 = Deref(ARG1), t2 = Deref(ARG2); LOCAL_MAX_SIZE = 1024; + int l = push_text_stack( ); restart_aux: if (IsVarTerm(t1)) { @@ -386,12 +415,12 @@ restart_aux: // verify if an atom, int, float or bignnum at = Yap_StringSWIToAtom(t2 PASS_REGS); if (at) - return Yap_unify(MkAtomTerm(at), t1); + ReleaseAndReturn( Yap_unify(MkAtomTerm(at), t1) ); // else } else if (IsAtomTerm(t1)) { Term t0 = Yap_AtomSWIToString(t1 PASS_REGS); if (t0) - return Yap_unify(t0, t2); + ReleaseAndReturn( Yap_unify(t0, t2) ); } else { LOCAL_Error_TYPE = TYPE_ERROR_ATOM; } @@ -400,25 +429,26 @@ restart_aux: t2 = Deref(ARG2); goto restart_aux; } - return FALSE; + ReleaseAndReturn( FALSE ); } static Int atom_chars(USES_REGS1) { Term t1; LOCAL_MAX_SIZE = 1024; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); if (IsAtomTerm(t1)) { Term tf = Yap_AtomSWIToListOfAtoms(t1 PASS_REGS); if (tf) - return Yap_unify(ARG2, tf); + ReleaseAndReturn( Yap_unify(ARG2, tf) ); } else if (IsVarTerm(t1)) { /* ARG1 unbound */ Term t = Deref(ARG2); Atom af = Yap_ListOfAtomsToAtom(t PASS_REGS); if (af) - return Yap_unify(ARG1, MkAtomTerm(af)); + ReleaseAndReturn( Yap_unify(ARG1, MkAtomTerm(af)) ); /* error handling */ } else { LOCAL_Error_TYPE = TYPE_ERROR_ATOM; @@ -426,23 +456,24 @@ restart_aux: if (LOCAL_Error_TYPE && Yap_HandleError("atom_chars/2")) { goto restart_aux; } - return false; + ReleaseAndReturn( false ); } static Int atom_codes(USES_REGS1) { Term t1; t1 = Deref(ARG1); + int l = push_text_stack( ); restart_aux: if (IsAtomTerm(t1)) { Term tf = Yap_AtomToListOfCodes(t1 PASS_REGS); if (tf) - return Yap_unify(ARG2, tf); + ReleaseAndReturn( Yap_unify(ARG2, tf) ); } else if (IsVarTerm(t1)) { /* ARG1 unbound */ Term t = Deref(ARG2); Atom af = Yap_ListToAtom(t PASS_REGS); if (af) - return Yap_unify(ARG1, MkAtomTerm(af)); + ReleaseAndReturn( Yap_unify(ARG1, MkAtomTerm(af)) ); } else if (IsVarTerm(t1)) { LOCAL_Error_TYPE = TYPE_ERROR_ATOM; } @@ -451,23 +482,24 @@ restart_aux: t1 = Deref(ARG1); goto restart_aux; } - return FALSE; + ReleaseAndReturn( FALSE ); } static Int string_codes(USES_REGS1) { Term t1; t1 = Deref(ARG1); + int l = push_text_stack( ); restart_aux: if (IsStringTerm(t1)) { Term tf = Yap_StringSWIToListOfCodes(t1 PASS_REGS); if (tf) - return Yap_unify(ARG2, tf); + ReleaseAndReturn( Yap_unify(ARG2, tf) ); } else if (IsVarTerm(t1)) { /* ARG1 unbound */ Term t = Deref(ARG2); Term tf = Yap_ListSWIToString(t PASS_REGS); if (tf) - return Yap_unify(ARG1, tf); + ReleaseAndReturn( Yap_unify(ARG1, tf) ); } else { LOCAL_Error_TYPE = TYPE_ERROR_STRING; } @@ -476,23 +508,24 @@ restart_aux: t1 = Deref(ARG1); goto restart_aux; } - return FALSE; + ReleaseAndReturn( FALSE ); } static Int string_chars(USES_REGS1) { Term t1; t1 = Deref(ARG1); + int l = push_text_stack( ); restart_aux: if (IsStringTerm(t1)) { Term tf = Yap_StringSWIToListOfAtoms(t1 PASS_REGS); if (tf) - return Yap_unify(ARG2, tf); + ReleaseAndReturn( Yap_unify(ARG2, tf) ); } else if (IsVarTerm(t1)) { /* ARG1 unbound */ Term t = Deref(ARG2); Term tf = Yap_ListSWIToString(t PASS_REGS); if (tf) - return Yap_unify(ARG1, tf); + ReleaseAndReturn( Yap_unify(ARG1, tf) ); } else { LOCAL_Error_TYPE = TYPE_ERROR_STRING; } @@ -501,7 +534,7 @@ restart_aux: t1 = Deref(ARG1); goto restart_aux; } - return FALSE; + ReleaseAndReturn( FALSE ); } /** @pred number_chars(? _I_,? _L_) is iso @@ -514,6 +547,7 @@ characters of the external representation of _I_. */ static Int number_chars(USES_REGS1) { Term t1; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); if (IsNumTerm(t1)) { @@ -522,11 +556,11 @@ restart_aux: t1 = Yap_NumberToListOfAtoms(t1 PASS_REGS); } if (t1) { - return Yap_unify(t1, t2); + ReleaseAndReturn( Yap_unify(t1, t2) ); } else { t2 = Yap_ListToNumber(t2 PASS_REGS); if (t2) { - return Yap_unify(t1, t2); + ReleaseAndReturn( Yap_unify(t1, t2) ); } } } else if (IsVarTerm(t1)) { @@ -534,7 +568,7 @@ restart_aux: Term t = Deref(ARG2); Term tf = Yap_ListToNumber(t PASS_REGS); if (tf) { - return Yap_unify(ARG1, tf); + ReleaseAndReturn( Yap_unify(ARG1, tf) ); } } else if (IsVarTerm(t1)) { LOCAL_Error_TYPE = TYPE_ERROR_NUMBER; @@ -543,11 +577,12 @@ restart_aux: if (LOCAL_Error_TYPE && Yap_HandleError("number_chars/2")) { goto restart_aux; } - return false; + ReleaseAndReturn( false ); } static Int number_atom(USES_REGS1) { Term t1; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); if (IsNumTerm(t1)) { @@ -557,11 +592,11 @@ restart_aux: if (af) { if (IsVarTerm(t2)) { - return Yap_unify(t1, t2); + ReleaseAndReturn( Yap_unify(t1, t2) ); } else { t2 = Yap_AtomToNumber(t2 PASS_REGS); if (t2) { - return Yap_unify(t1, t2); + ReleaseAndReturn( Yap_unify(t1, t2) ); } } } @@ -569,31 +604,32 @@ restart_aux: /* ARG1 unbound */ Term t = Deref(ARG2); Term tf = Yap_AtomToNumber(t PASS_REGS); - return Yap_unify(ARG1, tf); + ReleaseAndReturn( Yap_unify(ARG1, tf) ); } else if (IsVarTerm(t1)) { LOCAL_Error_TYPE = TYPE_ERROR_NUMBER; } /* error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("number_atom/2")) { goto restart_aux; } - return false; + ReleaseAndReturn( false ); } static Int number_string(USES_REGS1) { Term t1; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); if (IsNumTerm(t1)) { Term tf; tf = Yap_NumberToString(t1 PASS_REGS); if (tf) - return Yap_unify(ARG2, tf); + ReleaseAndReturn( Yap_unify(ARG2, tf) ); } else if (IsVarTerm(t1)) { /* ARG1 unbound */ Term t = Deref(ARG2); Term tf = Yap_StringToNumber(t PASS_REGS); if (tf) - return Yap_unify(ARG1, tf); + ReleaseAndReturn( Yap_unify(ARG1, tf) ); } else { LOCAL_Error_TYPE = TYPE_ERROR_NUMBER; } @@ -601,24 +637,25 @@ restart_aux: if (LOCAL_Error_TYPE && Yap_HandleError("number_string/2")) { goto restart_aux; } - return FALSE; + ReleaseAndReturn( FALSE ); } static Int number_codes(USES_REGS1) { Term t1; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); if (IsNumTerm(t1)) { Term tf; tf = Yap_NumberToListOfCodes(t1 PASS_REGS); if (tf) - return Yap_unify(ARG2, tf); + ReleaseAndReturn( Yap_unify(ARG2, tf) ); } else if (IsVarTerm(t1)) { /* ARG1 unbound */ Term t = Deref(ARG2); Term tf = Yap_ListToNumber(t PASS_REGS); if (tf) - return Yap_unify(ARG1, tf); + ReleaseAndReturn( Yap_unify(ARG1, tf) ); } else { LOCAL_Error_TYPE = TYPE_ERROR_NUMBER; } @@ -626,13 +663,14 @@ restart_aux: if (LOCAL_Error_TYPE && Yap_HandleError("number_codes/2")) { goto restart_aux; } - return FALSE; + ReleaseAndReturn( FALSE ); } static Int cont_atom_concat3(USES_REGS1) { Term t3; Atom ats[2]; Int i, max; + int l = push_text_stack( ); restart_aux: t3 = Deref(ARG3); i = IntOfTerm(EXTRA_CBACK_ARG(3, 1)); @@ -640,25 +678,25 @@ restart_aux: EXTRA_CBACK_ARG(3, 1) = MkIntTerm(i + 1); if (!Yap_SpliceAtom(t3, ats, i, max PASS_REGS) && LOCAL_Error_TYPE == YAP_NO_ERROR) { - cut_fail(); + release_cut_fail(); } else { - if (i < max) - return Yap_unify(ARG1, MkAtomTerm(ats[0])) && - Yap_unify(ARG2, MkAtomTerm(ats[1])); + if (i < max) { + ReleaseAndReturn( Yap_unify(ARG1, MkAtomTerm(ats[0])) && + Yap_unify(ARG2, MkAtomTerm(ats[1])) ); } if (Yap_unify(ARG1, MkAtomTerm(ats[0])) && Yap_unify(ARG2, MkAtomTerm(ats[1]))) - cut_succeed(); - cut_fail(); + release_cut_succeed(); + release_cut_fail(); } /* Error handling */ if (LOCAL_Error_TYPE) { if (Yap_HandleError("atom_concat/3")) { goto restart_aux; } else { - return false; + ReleaseAndReturn( false ); } } - cut_fail(); + release_cut_fail(); } static Int atom_concat3(USES_REGS1) { @@ -666,6 +704,7 @@ static Int atom_concat3(USES_REGS1) { Term t2, t3, ot; Atom at; bool g1, g2, g3; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); t2 = Deref(ARG2); @@ -685,26 +724,28 @@ restart_aux: } 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); + ReleaseAndReturn( cont_atom_concat3(PASS_REGS1) ); } else { LOCAL_Error_TYPE = INSTANTIATION_ERROR; at = NULL; } + pop_text_stack( l); if (at) { - if (Yap_unify(ot, MkAtomTerm(at))) - cut_succeed(); - else - cut_fail(); + if (Yap_unify(ot, MkAtomTerm(at))) { + release_cut_succeed(); + } else { + release_cut_fail(); + } } /* Error handling */ if (LOCAL_Error_TYPE) { if (Yap_HandleError("atom_concat/3")) { goto restart_aux; } else { - return false; + ReleaseAndReturn( false ); } } - cut_fail(); + release_cut_fail(); } #define CastToNumeric(x) CastToNumeric__(x PASS_REGS) @@ -720,31 +761,32 @@ static Int cont_atomic_concat3(USES_REGS1) { Term t3; Atom ats[2]; size_t i, max; + int l = push_text_stack( ); restart_aux: t3 = Deref(ARG3); 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)) { - cut_fail(); + release_cut_fail(); } else { Term t1 = CastToNumeric(ats[0]); Term t2 = CastToNumeric(ats[1]); if (i < max) - return Yap_unify(ARG1, t1) && Yap_unify(ARG2, t2); + ReleaseAndReturn( Yap_unify(ARG1, t1) && Yap_unify(ARG2, t2) ); if (Yap_unify(ARG1, t1) && Yap_unify(ARG2, t2)) - cut_succeed(); - cut_fail(); + release_cut_succeed(); + release_cut_fail(); } /* Error handling */ if (LOCAL_Error_TYPE) { if (Yap_HandleError("string_concat/3")) { goto restart_aux; } else { - return FALSE; + ReleaseAndReturn( FALSE ); } } - cut_fail(); + release_cut_fail(); } static Int atomic_concat3(USES_REGS1) { @@ -752,6 +794,7 @@ static Int atomic_concat3(USES_REGS1) { Term t2, t3, ot; Atom at = NULL; bool g1, g2, g3; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); t2 = Deref(ARG2); @@ -777,10 +820,11 @@ restart_aux: at = NULL; } if (at) { - if (Yap_unify(ot, MkAtomTerm(at))) - cut_succeed(); - else - cut_fail(); + if (Yap_unify(ot, MkAtomTerm(at))) { + release_cut_succeed(); + } else { + release_cut_fail(); + } } /* Error handling */ if (LOCAL_Error_TYPE) { @@ -790,26 +834,27 @@ restart_aux: return false; } } - cut_fail(); + release_cut_fail(); } static Int cont_string_concat3(USES_REGS1) { Term t3; Term ts[2]; size_t i, max; + int l = push_text_stack( ); restart_aux: t3 = Deref(ARG3); i = IntOfTerm(EXTRA_CBACK_ARG(3, 1)); max = IntOfTerm(EXTRA_CBACK_ARG(3, 2)); EXTRA_CBACK_ARG(3, 1) = MkIntTerm(i + 1); if (!Yap_SpliceString(t3, ts, i, max PASS_REGS)) { - cut_fail(); + release_cut_fail(); } else { if (i < max) return Yap_unify(ARG1, ts[0]) && Yap_unify(ARG2, ts[1]); if (Yap_unify(ARG1, ts[0]) && Yap_unify(ARG2, ts[1])) - cut_succeed(); - cut_fail(); + release_cut_succeed(); + release_cut_fail(); } /* Error handling */ if (LOCAL_Error_TYPE) { @@ -819,7 +864,7 @@ restart_aux: return FALSE; } } - cut_fail(); + release_cut_fail(); } static Int string_concat3(USES_REGS1) { @@ -828,6 +873,7 @@ static Int string_concat3(USES_REGS1) { Term tf = 0; bool g1, g2, g3; Atom at; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); t2 = Deref(ARG2); @@ -853,20 +899,21 @@ restart_aux: at = NULL; } if (tf) { - if (Yap_unify(ot, tf)) - cut_succeed(); - else - cut_fail(); + if (Yap_unify(ot, tf)) { + release_cut_succeed(); + } else { + release_cut_fail(); + } } /* Error handling */ if (LOCAL_Error_TYPE) { if (Yap_HandleError("atom_concat/3")) { goto restart_aux; } else { - return false; + ReleaseAndReturn( false ); } } - cut_fail(); + release_cut_fail(); } static Int cont_string_code3(USES_REGS1) { @@ -875,6 +922,7 @@ static Int cont_string_code3(USES_REGS1) { utf8proc_int32_t chr; const unsigned char *s; const unsigned char *s0; + int l = push_text_stack( ); restart_aux: t2 = Deref(ARG2); s0 = UStringOfTerm(t2); @@ -886,28 +934,30 @@ restart_aux: if (s[0]) { EXTRA_CBACK_ARG(3, 1) = MkIntTerm(s - s0); EXTRA_CBACK_ARG(3, 2) = MkIntTerm(j + 1); - return Yap_unify(MkIntegerTerm(chr), ARG3) && - Yap_unify(MkIntegerTerm(j + 1), ARG1); + ReleaseAndReturn( Yap_unify(MkIntegerTerm(chr), ARG3) && + Yap_unify(MkIntegerTerm(j + 1), ARG1) ); + } + if (Yap_unify(MkIntegerTerm(chr), ARG3) && Yap_unify(MkIntegerTerm(j), ARG1)) { + release_cut_succeed(); + } else { + release_cut_fail(); } - if (Yap_unify(MkIntegerTerm(chr), ARG3) && Yap_unify(MkIntegerTerm(j), ARG1)) - cut_succeed(); - else - cut_fail(); /* Error handling */ if (LOCAL_Error_TYPE) { if (Yap_HandleError("string_code/3")) { goto restart_aux; } else { - return FALSE; + ReleaseAndReturn( FALSE ) ; } } - cut_fail(); + release_cut_fail(); } static Int string_code3(USES_REGS1) { Term t1; Term t2; const unsigned char *s; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); t2 = Deref(ARG2); @@ -932,18 +982,18 @@ restart_aux: if (indx < 0) { LOCAL_Error_TYPE = DOMAIN_ERROR_NOT_LESS_THAN_ZERO; } - cut_fail(); + release_cut_fail(); } ns = skip_utf8(s, indx); if (ns == NULL) { - cut_fail(); // silently fail? + release_cut_fail(); // silently fail? } get_utf8(ns, -1, &chr); if (chr == '\0') - cut_fail(); + release_cut_fail(); if (Yap_unify(ARG3, MkIntegerTerm(chr))) - cut_succeed(); - cut_fail(); + release_cut_succeed(); + release_cut_fail(); } } /* Error handling */ @@ -951,16 +1001,17 @@ restart_aux: if (Yap_HandleError("string_code/3")) { goto restart_aux; } else { - return FALSE; + ReleaseAndReturn( FALSE ); } } - cut_fail(); + release_cut_fail(); } static Int get_string_code3(USES_REGS1) { Term t1; Term t2; const unsigned char *s; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); t2 = Deref(ARG2); @@ -985,20 +1036,20 @@ restart_aux: if (indx < 0) { LOCAL_Error_TYPE = DOMAIN_ERROR_NOT_LESS_THAN_ZERO; } else { - return false; + ReleaseAndReturn( false ); } } else { indx -= 1; ns = skip_utf8(ns, indx); if (ns == NULL) { - return false; + ReleaseAndReturn( false ); } else { get_utf8(ns, -1, &chr); if (chr != '\0') - return Yap_unify(ARG3, MkIntegerTerm(chr)); + ReleaseAndReturn( Yap_unify(ARG3, MkIntegerTerm(chr)) ); } } - return FALSE; // replace by error code + ReleaseAndReturn( FALSE ); // replace by error cod )e } } /* Error handling */ @@ -1006,16 +1057,17 @@ restart_aux: if (Yap_HandleError("string_code/3")) { goto restart_aux; } else { - return FALSE; + ReleaseAndReturn( FALSE ); } } - cut_fail(); + release_cut_fail(); } static Int atom_concat2(USES_REGS1) { Term t1; Term *tailp; Int n; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); n = Yap_SkipList(&t1, &tailp); @@ -1046,7 +1098,7 @@ restart_aux: free(inpv); at = out.val.a; if (at) - return Yap_unify(ARG2, MkAtomTerm(at)); + ReleaseAndReturn( Yap_unify(ARG2, MkAtomTerm(at)) ); } error: /* Error handling */ @@ -1054,16 +1106,17 @@ error: if (Yap_HandleError("atom_concat/2")) { goto restart_aux; } else { - return FALSE; + ReleaseAndReturn( FALSE ); } } - cut_fail(); + release_cut_fail(); } static Int string_concat2(USES_REGS1) { Term t1; Term *tailp; Int n; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); n = Yap_SkipList(&t1, &tailp); @@ -1092,7 +1145,7 @@ restart_aux: } free(inpv); if (out.val.t) - return Yap_unify(ARG2, out.val.t); + ReleaseAndReturn( Yap_unify(ARG2, out.val.t) ); } error: /* Error handling */ @@ -1100,16 +1153,17 @@ error: if (Yap_HandleError("string_code/3")) { goto restart_aux; } else { - return FALSE; + ReleaseAndReturn( FALSE ); } } - cut_fail(); + release_cut_fail(); } static Int atomic_concat2(USES_REGS1) { Term t1; Term *tailp; Int n; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); n = Yap_SkipList(&t1, &tailp); @@ -1121,7 +1175,7 @@ restart_aux: Atom at; if (n == 1) - return Yap_unify(ARG2, HeadOfTerm(t1)); + ReleaseAndReturn( Yap_unify(ARG2, HeadOfTerm(t1)) ); if (!inpv) { LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; free(inpv); @@ -1144,7 +1198,7 @@ restart_aux: free(inpv); at = out.val.a; if (at) - return Yap_unify(ARG2, MkAtomTerm(at)); + ReleaseAndReturn( Yap_unify(ARG2, MkAtomTerm(at)) ); } error: /* Error handling */ @@ -1158,6 +1212,7 @@ static Int atomics_to_string2(USES_REGS1) { Term t1; Term *tailp; Int n; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); n = Yap_SkipList(&t1, &tailp); @@ -1189,20 +1244,21 @@ restart_aux: free(inpv); at = out.val.a; if (at) - return Yap_unify(ARG2, MkAtomTerm(at)); + ReleaseAndReturn( Yap_unify(ARG2, MkAtomTerm(at)) ); } error: /* Error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("atomics_to_string/2")) { goto restart_aux; } - return FALSE; + ReleaseAndReturn( FALSE ); } static Int atomics_to_string3(USES_REGS1) { Term t1, t2; Term *tailp; Int n; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); t2 = Deref(ARG2); @@ -1239,14 +1295,14 @@ restart_aux: free(inpv); at = out.val.a; if (at) - return Yap_unify(ARG3, MkAtomTerm(at)); + ReleaseAndReturn( Yap_unify(ARG3, MkAtomTerm(at)) ); } error: /* Error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("atomics_to_string/3")) { goto restart_aux; } - return FALSE; + ReleaseAndReturn( FALSE ); } static Int atom_length(USES_REGS1) { @@ -1254,33 +1310,34 @@ static Int atom_length(USES_REGS1) { Term t2 = Deref(ARG2); size_t len; + int l = push_text_stack( ); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - return (FALSE); + ReleaseAndReturn( FALSE ); } else if (!IsAtomTerm(t1)) { Yap_Error(TYPE_ERROR_ATOM, t1, "at first argument"); - return (FALSE); + ReleaseAndReturn( FALSE ); } if (Yap_IsGroundTerm(t2)) { if (!IsIntegerTerm(t2)) { Yap_Error(TYPE_ERROR_INTEGER, t2, "atom_length/2"); - return (FALSE); + ReleaseAndReturn( FALSE); } else if ((Int)(len = IntegerOfTerm(t2)) < 0) { Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2, "atom_length/2"); - return (FALSE); + ReleaseAndReturn( FALSE); } } restart_aux: len = Yap_AtomicToLength(t1 PASS_REGS); if (len != (size_t)-1) - return Yap_unify(ARG2, MkIntegerTerm(len)); + ReleaseAndReturn( Yap_unify(ARG2, MkIntegerTerm(len)) ); /* error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("atom_length/2")) { goto restart_aux; } - return FALSE; + ReleaseAndReturn( FALSE ); } static Int atomic_length(USES_REGS1) { @@ -1288,30 +1345,31 @@ static Int atomic_length(USES_REGS1) { Term t2 = Deref(ARG2); size_t len; + int l = push_text_stack( ); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - return (FALSE); + ReleaseAndReturn( FALSE); } if (IsNonVarTerm(t2)) { if (!IsIntegerTerm(t2)) { Yap_Error(TYPE_ERROR_INTEGER, t2, "atom_length/2"); - return (FALSE); + ReleaseAndReturn( FALSE); } else if ((Int)(len = IntegerOfTerm(t2)) < 0) { Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2, "atom_length/2"); - return (FALSE); + ReleaseAndReturn( FALSE); } } restart_aux: len = Yap_AtomicToLength(t1 PASS_REGS); if (len != (size_t)-1) - return Yap_unify(ARG2, MkIntegerTerm(len)); + ReleaseAndReturn( Yap_unify(ARG2, MkIntegerTerm(len)) ); /* error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("atomic_length/2")) { goto restart_aux; } - return FALSE; + ReleaseAndReturn( FALSE ); } static Int string_length(USES_REGS1) { @@ -1319,27 +1377,28 @@ static Int string_length(USES_REGS1) { Term t2 = Deref(ARG2); size_t len; + int l = push_text_stack( ); if (Yap_IsGroundTerm(t2)) { if (!IsIntegerTerm(t2)) { Yap_Error(TYPE_ERROR_INTEGER, t2, "string_length/2"); - return (FALSE); + ReleaseAndReturn( FALSE); } if (FALSE && (Int)(len = IntegerOfTerm(t2)) < 0) { Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2, "string_length/2"); - return (FALSE); + ReleaseAndReturn( FALSE); } } restart_aux: t1 = Deref(ARG1); len = Yap_AtomicToLength(t1 PASS_REGS); if (len != (size_t)-1) - return Yap_unify(ARG2, MkIntegerTerm(len)); + ReleaseAndReturn( Yap_unify(ARG2, MkIntegerTerm(len)) ); /* error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("string_length/2")) { goto restart_aux; } - return FALSE; + ReleaseAndReturn( FALSE ); } /** @pred downcase_text_to_atom(+Text, -Atom) @@ -1352,15 +1411,16 @@ static Int downcase_text_to_atom(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); + int l = push_text_stack( ); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - return false; + ReleaseAndReturn( false ); } if (IsNonVarTerm(t2)) { if (!IsAtomTerm(t2)) { Yap_Error(TYPE_ERROR_ATOM, t2, "at second argument"); - return (FALSE); + ReleaseAndReturn( (FALSE) ); } } while (true) { @@ -1368,11 +1428,11 @@ static Int downcase_text_to_atom(USES_REGS1) { if (at == NULL) { if (LOCAL_Error_TYPE && Yap_HandleError("downcase_text_to_atom/2")) continue; - return false; + ReleaseAndReturn( false ); } - return Yap_unify(MkAtomTerm(at), t2); + ReleaseAndReturn( Yap_unify(MkAtomTerm(at), t2) ); } - return false; + ReleaseAndReturn( false ); } /** @pred upcase_text_to_atom(+Text, -Atom) @@ -1385,15 +1445,16 @@ static Int upcase_text_to_atom(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); + int l = push_text_stack( ); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - return false; + ReleaseAndReturn( false ); } if (IsNonVarTerm(t2)) { if (!IsAtomTerm(t2)) { Yap_Error(TYPE_ERROR_ATOM, t2, "at second argument"); - return (FALSE); + ReleaseAndReturn( (FALSE) ); } } while (true) { @@ -1401,11 +1462,11 @@ static Int upcase_text_to_atom(USES_REGS1) { if (at == NULL) { if (LOCAL_Error_TYPE && Yap_HandleError("upcase_text_to_atom/2")) continue; - return false; + ReleaseAndReturn( false ); } - return Yap_unify(MkAtomTerm(at), t2); + ReleaseAndReturn( Yap_unify(MkAtomTerm(at), t2) ); } - return false; + ReleaseAndReturn( false ); } /** @pred downcase_text_to_string(+Text, -String) @@ -1418,15 +1479,16 @@ static Int downcase_text_to_string(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); + int l = push_text_stack( ); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - return false; + ReleaseAndReturn( false ); } if (IsNonVarTerm(t2)) { if (!IsStringTerm(t2)) { Yap_Error(TYPE_ERROR_STRING, t2, "at second argument"); - return (FALSE); + ReleaseAndReturn( (FALSE) ); } } while (true) { @@ -1434,11 +1496,11 @@ static Int downcase_text_to_string(USES_REGS1) { if (t == TermZERO) { if (LOCAL_Error_TYPE && Yap_HandleError("downcase_text_to_string/2")) continue; - return false; + ReleaseAndReturn( false ); } - return Yap_unify(t, t2); + ReleaseAndReturn( Yap_unify(t, t2) ); } - return false; + ReleaseAndReturn( false ); } /** @pred upcase_text_to_string(+Text, -String) @@ -1451,15 +1513,16 @@ static Int upcase_text_to_string(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); + int l = push_text_stack( ); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - return false; + ReleaseAndReturn( false ); } if (IsNonVarTerm(t2)) { if (!IsStringTerm(t2)) { Yap_Error(TYPE_ERROR_STRING, t2, "at second argument"); - return (FALSE); + ReleaseAndReturn( (FALSE) ); } } while (true) { @@ -1467,11 +1530,11 @@ static Int upcase_text_to_string(USES_REGS1) { if (t == TermZERO) { if (LOCAL_Error_TYPE && Yap_HandleError("upcase_text_to_string/2")) continue; - return false; + ReleaseAndReturn( false ); } - return Yap_unify(t, t2); + ReleaseAndReturn( Yap_unify(t, t2) ); } - return false; + ReleaseAndReturn( false ); } /** @pred downcase_text_to_codes(+Text, -Codes) @@ -1484,15 +1547,16 @@ static Int downcase_text_to_codes(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); + int l = push_text_stack( ); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - return false; + ReleaseAndReturn( false ); } if (IsNonVarTerm(t2)) { if (!Yap_IsListTerm(t2)) { Yap_Error(TYPE_ERROR_LIST, t2, "at second argument"); - return false; + ReleaseAndReturn( false ); } } while (true) { @@ -1500,11 +1564,11 @@ static Int downcase_text_to_codes(USES_REGS1) { if (t == TermZERO) { if (LOCAL_Error_TYPE && Yap_HandleError("downcase_text_to_codes/2")) continue; - return false; + ReleaseAndReturn( false ); } - return Yap_unify(t, t2); + ReleaseAndReturn( Yap_unify(t, t2) ); } - return false; + ReleaseAndReturn( false ); } /** @pred upcase_text_to_codes(+Text, -Codes) @@ -1517,15 +1581,16 @@ static Int upcase_text_to_codes(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); + int l = push_text_stack( ); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - return false; + ReleaseAndReturn( false ); } if (IsNonVarTerm(t2)) { if (!Yap_IsListTerm(t2)) { Yap_Error(TYPE_ERROR_LIST, t2, "at second argument"); - return (FALSE); + ReleaseAndReturn( (FALSE) ); } } while (true) { @@ -1533,11 +1598,11 @@ static Int upcase_text_to_codes(USES_REGS1) { if (t == TermZERO) { if (LOCAL_Error_TYPE && Yap_HandleError("upcase_text_to_codes/2")) continue; - return false; + ReleaseAndReturn( false ); } - return Yap_unify(t, t2); + ReleaseAndReturn( Yap_unify(t, t2) ); } - return false; + ReleaseAndReturn( false ); } /** @pred downcase_text_to_chars(+Text, -Chars) @@ -1550,15 +1615,16 @@ static Int downcase_text_to_chars(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); + int l = push_text_stack( ); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - return false; + ReleaseAndReturn( false ); } if (IsNonVarTerm(t2)) { if (!Yap_IsListTerm(t2)) { Yap_Error(TYPE_ERROR_LIST, t2, "at second argument"); - return false; + ReleaseAndReturn( false ); } } while (true) { @@ -1566,11 +1632,11 @@ static Int downcase_text_to_chars(USES_REGS1) { if (t == TermZERO) { if (LOCAL_Error_TYPE && Yap_HandleError("downcase_text_to_to_chars/2")) continue; - return false; + ReleaseAndReturn( false ); } - return Yap_unify(t, t2); + ReleaseAndReturn( Yap_unify(t, t2) ); } - return false; + ReleaseAndReturn( false ); } /** @pred upcase_text_to_chars(+Text, -Chars) @@ -1583,15 +1649,16 @@ static Int upcase_text_to_chars(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); + int l = push_text_stack( ); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - return false; + ReleaseAndReturn( false ); } if (IsNonVarTerm(t2)) { if (!Yap_IsListTerm(t2)) { Yap_Error(TYPE_ERROR_LIST, t2, "at second argument"); - return (FALSE); + ReleaseAndReturn( (FALSE) ); } } while (true) { @@ -1599,11 +1666,11 @@ static Int upcase_text_to_chars(USES_REGS1) { if (t == TermZERO) { if (LOCAL_Error_TYPE && Yap_HandleError("upcase_text_to_chars/2")) continue; - return false; + ReleaseAndReturn( false ); } - return Yap_unify(t, t2); + ReleaseAndReturn( Yap_unify(t, t2) ); } - return false; + ReleaseAndReturn( false ); } /* split an atom into two sub-atoms */ @@ -1614,31 +1681,32 @@ static Int atom_split(USES_REGS1) { Term to1, to2; Atom at; + int l = push_text_stack( ); if (IsVarTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "$atom_split/4"); - return (FALSE); + ReleaseAndReturn( (FALSE) ); } if (!IsAtomTerm(t1)) { Yap_Error(TYPE_ERROR_ATOM, t1, "$atom_split/4"); - return (FALSE); + ReleaseAndReturn( (FALSE) ); } if (IsVarTerm(t2)) { Yap_Error(INSTANTIATION_ERROR, t2, "$atom_split/4"); - return (FALSE); + ReleaseAndReturn( (FALSE) ); } if (!IsIntTerm(t2)) { Yap_Error(TYPE_ERROR_INTEGER, t2, "$atom_split/4"); - return (FALSE); + ReleaseAndReturn( (FALSE) ); } if ((Int)(len = IntOfTerm(t2)) < 0) { Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2, "$atom_split/4"); - return (FALSE); + ReleaseAndReturn( (FALSE) ); } at = AtomOfTerm(t1); unsigned char *s, *s1, *s10; s = RepAtom(at)->UStrOfAE; if (len > (Int)strlen_utf8(s)) - return (FALSE); + ReleaseAndReturn( (FALSE) ); s1 = s10 = Malloc(len); if (s1 + len > (unsigned char *)ASP - 1024) Yap_Error(RESOURCE_ERROR_STACK, t1, "$atom_split/4"); @@ -1651,53 +1719,55 @@ static Int atom_split(USES_REGS1) { s1[0] = '\0'; to1 = MkAtomTerm(Yap_ULookupAtom(s10)); to2 = MkAtomTerm(Yap_ULookupAtom(s)); - return (Yap_unify_constant(ARG3, to1) && Yap_unify_constant(ARG4, to2)); + ReleaseAndReturn( (Yap_unify_constant(ARG3, to1) && Yap_unify_constant(ARG4, to2)) ); } static Int atom_number(USES_REGS1) { Term t1; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); if (Yap_IsGroundTerm(t1)) { Term tf = Yap_AtomToNumber(t1 PASS_REGS); if (tf) - return Yap_unify(ARG2, tf); + ReleaseAndReturn( Yap_unify(ARG2, tf) ); } else { /* ARG1 unbound */ Term t = Deref(ARG2); Atom af = Yap_NumberToAtom(t PASS_REGS); if (af) - return Yap_unify(ARG1, MkAtomTerm(af)); + ReleaseAndReturn( Yap_unify(ARG1, MkAtomTerm(af)) ); } /* error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("atom_number/2")) { t1 = Deref(ARG1); goto restart_aux; } - return FALSE; + ReleaseAndReturn( FALSE ); } static Int string_number(USES_REGS1) { Term t1; + int l = push_text_stack( ); restart_aux: t1 = Deref(ARG1); if (Yap_IsGroundTerm(t1)) { Term tf = Yap_StringToNumber(t1 PASS_REGS); if (tf) - return Yap_unify(ARG2, tf); + ReleaseAndReturn( Yap_unify(ARG2, tf) ); } else { /* ARG1 unbound */ Term t = Deref(ARG2); Term tf = Yap_NumberToString(t PASS_REGS); if (tf) - return Yap_unify(ARG1, tf); + ReleaseAndReturn( Yap_unify(ARG1, tf) ); } /* error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("string_number/2")) { t1 = Deref(ARG1); goto restart_aux; } - return FALSE; + ReleaseAndReturn( FALSE ); } #define SUB_ATOM_HAS_MIN 1 @@ -1708,30 +1778,40 @@ restart_aux: #define SUB_ATOM_HAS_UTF8 32 -static Term build_new_atomic(int mask, wchar_t *wp, const unsigned char *p, - size_t minv, size_t len USES_REGS) { - { - const unsigned char *src = p; - unsigned char *buf; - Term t = init_tstring(PASS_REGS1); - src = skip_utf8((unsigned char *)src, minv); - const unsigned char *cp = src; - - buf = buf_from_tstring(HR); - while (len) { - utf8proc_int32_t chr; - cp += get_utf8((unsigned char *)cp, -1, &chr); - buf += put_utf8((unsigned char *)buf, chr); - len--; - } - *buf++ = '\0'; -if (mask & SUB_ATOM_HAS_ATOM) - return MkAtomTerm( Yap_ULookupAtom(buf ) ); - - close_tstring(buf PASS_REGS); - return t; +static Term build_new_atomic(int mask, wchar_t *wp, const unsigned char *p, size_t minv,size_t len USES_REGS) +{ + int n; + seq_tv_t outv[5], inp; + size_t cuts[3]; + if (minv) { + cuts[0] = minv; + cuts[1] = minv+len; + cuts[2] = 0; + outv[0].type = 0; + n = 1; + } else { + cuts[0] = minv+len; + cuts[1] = 0; + n = 0; + } + inp.type = YAP_STRING_CHARS; + inp.enc = ENC_ISO_UTF8; + inp.val.uc0 = p; + outv[n+1].type = 0; + if (mask & SUB_ATOM_HAS_ATOM) { + outv[n].type = YAP_STRING_ATOM; + } else { + outv[n].type = YAP_STRING_STRING; + outv[n].val.c = Malloc(512); } - return 0L; + int lvl = push_text_stack(PASS_REGS1); +bool rc = Yap_Splice_Text(2+n, cuts, &inp, outv PASS_REGS); + pop_text_stack(lvl); + if (!rc) + return( false ); + if (mask & SUB_ATOM_HAS_ATOM) + return( MkAtomTerm(outv[n].val.a) ); + return( outv[n].val.t ); } @@ -1739,7 +1819,7 @@ static int check_sub_atom_at(int minv, Atom at, Atom nat, size_t len) { const unsigned char *p1; const unsigned char *p2 = RepAtom(nat)->UStrOfAE; p1 = skip_utf8(RepAtom(at)->UStrOfAE, minv); - return cmpn_utf8(p1, p2, len) == 0; + return cmpn_utf8(p1, p2, len) == 0 ; } static int check_sub_string_at(int minv, const unsigned char *p1, @@ -1790,8 +1870,8 @@ static Int cont_sub_atomic(USES_REGS1) { wchar_t *wp = NULL; const unsigned char *p = NULL, *p5 = NULL; Term nat; - int sub_atom = TRUE; + int l = push_text_stack( ); mask = IntegerOfTerm(EXTRA_CBACK_ARG(5, 1)); minv = IntegerOfTerm(EXTRA_CBACK_ARG(5, 2)); len = IntegerOfTerm(EXTRA_CBACK_ARG(5, 3)); @@ -1845,9 +1925,9 @@ static Int cont_sub_atomic(USES_REGS1) { } if (found) { if (minv > sz - len) - cut_succeed(); + release_cut_succeed(); } else { - cut_fail(); + release_cut_fail(); } } else if (mask & SUB_ATOM_HAS_SIZE) { nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); @@ -1856,7 +1936,7 @@ static Int cont_sub_atomic(USES_REGS1) { Yap_unify(ARG5, nat); minv++; if (after-- == 0) - cut_succeed(); + release_cut_succeed(); } else if (mask & SUB_ATOM_HAS_MIN) { after = sz - (minv + len); nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); @@ -1865,7 +1945,7 @@ static Int cont_sub_atomic(USES_REGS1) { Yap_unify(ARG5, nat); len++; if (after-- == 0) - cut_succeed(); + release_cut_succeed(); } else if (mask & SUB_ATOM_HAS_AFTER) { len = sz - (minv + after); nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); @@ -1874,7 +1954,7 @@ static Int cont_sub_atomic(USES_REGS1) { Yap_unify(ARG5, nat); minv++; if (len-- == 0) - cut_succeed(); + release_cut_succeed(); } else { nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); Yap_unify(ARG2, MkIntegerTerm(minv)); @@ -1884,7 +1964,7 @@ static Int cont_sub_atomic(USES_REGS1) { len++; if (after-- == 0) { if (minv == sz) - cut_succeed(); + release_cut_succeed(); minv++; len = 0; after = sz - minv; @@ -1895,10 +1975,10 @@ static Int cont_sub_atomic(USES_REGS1) { EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(len); EXTRA_CBACK_ARG(5, 4) = MkIntegerTerm(after); EXTRA_CBACK_ARG(5, 5) = MkIntegerTerm(sz); - return TRUE; + ReleaseAndReturn( TRUE ); } -static Int sub_atomic(bool sub_atom USES_REGS) { +static Int sub_atomic(bool sub_atom, bool sub_string USES_REGS) { Term tat1, tbef, tsize, tafter, tout; int mask = SUB_ATOM_HAS_UTF8; size_t minv, len, after, sz; @@ -1908,6 +1988,7 @@ static Int sub_atomic(bool sub_atom USES_REGS) { Term nat = 0L; Atom at = NULL; + int l = push_text_stack( ); if (sub_atom) mask |= SUB_ATOM_HAS_ATOM; @@ -1916,34 +1997,38 @@ static Int sub_atomic(bool sub_atom USES_REGS) { if (!IsVarTerm(tat1)) { if (IsAtomTerm(tat1)) { + if (sub_atom) { p = AtomOfTerm(tat1)->UStrOfAE; - } else { + sz = strlen_utf8(p); + } else { + Yap_Error(TYPE_ERROR_ATOM, tat1, "sub_atom/5"); + ReleaseAndReturn( false ); + } + } else if (IsStringTerm(tat1)) { + if (sub_string) { p = UStringOfTerm(tat1); + sz = strlen_utf8(p); + } else { + Yap_Error(TYPE_ERROR_STRING, tat1, "sub_atom/5"); + ReleaseAndReturn( false ); + } } + } else { + Yap_Error(INSTANTIATION_ERROR, tat1, "sub_atom/5: first variable\n"); + ReleaseAndReturn( false ); } - EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(0); - if (IsVarTerm(tat1)) { - Yap_Error(INSTANTIATION_ERROR, tat1, "sub_atom/5: first variable\n"); - return FALSE; - } else if (IsAtomTerm(tat1)) { - Yap_Error(TYPE_ERROR_ATOM, tat1, "sub_atom/5"); - return FALSE; - } else if (!sub_atom && !IsStringTerm(tat1)) { - Yap_Error(TYPE_ERROR_STRING, tat1, "sub_string/5"); - return FALSE; - } tbef = Deref(ARG2); if (IsVarTerm(tbef)) { minv = 0; } else if (!IsIntegerTerm(tbef)) { Yap_Error(TYPE_ERROR_INTEGER, tbef, "sub_string/5"); - return FALSE; + ReleaseAndReturn( FALSE ); } else { minv = IntegerOfTerm(tbef); if ((Int)minv < 0) { Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, tbef, "sub_string/5"); - return FALSE; + ReleaseAndReturn( FALSE ); }; mask |= SUB_ATOM_HAS_MIN; bnds++; @@ -1952,12 +2037,12 @@ static Int sub_atomic(bool sub_atom USES_REGS) { len = 0; } else if (!IsIntegerTerm(tsize)) { Yap_Error(TYPE_ERROR_INTEGER, tsize, "sub_string/5"); - return FALSE; + ReleaseAndReturn( FALSE ); } else { len = IntegerOfTerm(tsize); if ((Int)len < 0) { Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, tsize, "sub_string/5"); - return FALSE; + ReleaseAndReturn( FALSE ); }; mask |= SUB_ATOM_HAS_SIZE; bnds++; @@ -1966,12 +2051,12 @@ static Int sub_atomic(bool sub_atom USES_REGS) { after = 0; } else if (!IsIntegerTerm(tafter)) { Yap_Error(TYPE_ERROR_INTEGER, tafter, "sub_string/5"); - return FALSE; + ReleaseAndReturn( FALSE ); } else { after = IntegerOfTerm(tafter); if ((Int)after < 0) { Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, tafter, "sub_string/5"); - return FALSE; + ReleaseAndReturn( FALSE ); }; mask |= SUB_ATOM_HAS_AFTER; bnds++; @@ -1980,7 +2065,7 @@ static Int sub_atomic(bool sub_atom USES_REGS) { if (sub_atom) { if (!IsAtomTerm(tout)) { Yap_Error(TYPE_ERROR_ATOM, tout, "sub_atom/5"); - return FALSE; + ReleaseAndReturn( FALSE ); } else { Atom oat; mask |= SUB_ATOM_HAS_VAL | SUB_ATOM_HAS_SIZE; @@ -1990,20 +2075,16 @@ static Int sub_atomic(bool sub_atom USES_REGS) { } else { if (!IsStringTerm(tout)) { Yap_Error(TYPE_ERROR_STRING, tout, "sub_string/5"); - return FALSE; + ReleaseAndReturn( FALSE ); } else { mask |= SUB_ATOM_HAS_VAL | SUB_ATOM_HAS_SIZE; len = strlen_utf8(UStringOfTerm(tout)); } } if (!Yap_unify(ARG3, MkIntegerTerm(len))) - cut_fail(); + release_cut_fail(); bnds += 2; } - if (!IsVarTerm(tat1)) { - mask |= SUB_ATOM_HAS_UTF8; - sz = strlen_utf8(p); - } /* the problem is deterministic if we have two cases */ if (bnds > 1) { int out = FALSE; @@ -2011,30 +2092,30 @@ static Int sub_atomic(bool sub_atom USES_REGS) { if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) == (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) { if (minv + len > sz) - cut_fail(); + release_cut_fail(); if ((Int)(after = (sz - (minv + len))) < 0) - cut_fail(); + release_cut_fail(); nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); if (!nat) - cut_fail(); + release_cut_fail(); out = Yap_unify(ARG4, MkIntegerTerm(after)) && Yap_unify(ARG5, nat); } else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_AFTER)) == (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_AFTER)) { if (sz < minv + after) - cut_fail(); + release_cut_fail(); len = sz - (minv + after); nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); if (!nat) - cut_fail(); + release_cut_fail(); out = Yap_unify(ARG3, MkIntegerTerm(len)) && Yap_unify(ARG5, nat); } else if ((mask & (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_AFTER)) == (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_AFTER)) { if (len + after > sz) - cut_fail(); + release_cut_fail(); minv = sz - (len + after); nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); if (!nat) - cut_fail(); + release_cut_fail(); out = Yap_unify(ARG2, MkIntegerTerm(minv)) && Yap_unify(ARG5, nat); } else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) == (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) { @@ -2053,19 +2134,19 @@ static Int sub_atomic(bool sub_atom USES_REGS) { if (!sub_atom) { out = (strlen_utf8(UStringOfTerm(tout)) == len); if (!out) - cut_fail(); + release_cut_fail(); } else { out = (strlen_utf8(RepAtom(AtomOfTerm(tout))->UStrOfAE) == len); if (!out) - cut_fail(); + release_cut_fail(); } if (len == sz) { out = out && Yap_unify(ARG1, ARG5) && Yap_unify(ARG2, MkIntegerTerm(0)) && Yap_unify(ARG4, MkIntegerTerm(0)); } else if (len > sz) { - cut_fail(); + release_cut_fail(); } else { mask |= SUB_ATOM_HAS_SIZE; minv = 0; @@ -2074,8 +2155,8 @@ static Int sub_atomic(bool sub_atom USES_REGS) { } } if (out) - cut_succeed(); - cut_fail(); + release_cut_succeed(); + release_cut_fail(); } else { if (!(mask & SUB_ATOM_HAS_MIN)) minv = 0; @@ -2090,7 +2171,7 @@ backtrackable: EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(len); EXTRA_CBACK_ARG(5, 4) = MkIntegerTerm(after); EXTRA_CBACK_ARG(5, 5) = MkIntegerTerm(sz); - return cont_sub_atomic(PASS_REGS1); + ReleaseAndReturn( cont_sub_atomic(PASS_REGS1) ); } /** @pred sub_atom(+ _A_,? _Bef_, ? _Size_, ? _After_, ? _At_out_) is iso @@ -2107,7 +2188,7 @@ are unbound, the built-in will backtrack through all possible sub-strings of _A_. */ -static Int sub_atom(USES_REGS1) { return sub_atomic(true PASS_REGS); } +static Int sub_atom(USES_REGS1) { return( sub_atomic(true, false PASS_REGS) );} /** @pred sub_string(+ _S_,? _Bef_, ? _Size_, ? _After_, ? _S_out_) is iso @@ -2123,7 +2204,7 @@ are unbound, the built-in will generate all possible sub-strings of _S_. */ -static Int sub_string(USES_REGS1) { return sub_atomic(false PASS_REGS); } +static Int sub_string(USES_REGS1) { return sub_atomic(false, true PASS_REGS); } static Int cont_current_atom(USES_REGS1) { Atom catom; @@ -2176,9 +2257,9 @@ static Int cont_current_atom(USES_REGS1) { READ_UNLOCK(ap->ARWLock); } EXTRA_CBACK_ARG(1, 2) = MkIntTerm(i); - return TRUE; + return( TRUE ); } else { - return FALSE; + return( FALSE ); } } diff --git a/C/cmppreds.c b/C/cmppreds.c index a7de778d1..d650e4410 100644 --- a/C/cmppreds.c +++ b/C/cmppreds.c @@ -63,6 +63,8 @@ static char SccsId[] = "%W% %G%"; #endif #include +#include "YapError.h" + static Int compare(Term, Term); static Int p_compare(USES_REGS1); static Int p_acomp(USES_REGS1); @@ -378,9 +380,11 @@ inline static Int compare(Term t1, Term t2) /* compare terms t1 and t2 */ return 1; else { int out; - if (!(out = 2 - ArityOfFunctor(f))) - out = strcmp(".", (char *)RepAtom(NameOfFunctor(f))->StrOfAE); - return (out); + if (f != FunctorDot) + return strcmp(".", RepAtom(NameOfFunctor(f))->StrOfAE); + else { + return compare_complex(RepPair(t1) - 1, RepPair(t1) + 1, RepAppl(t2) ); + } } } if (IsPairTerm(t2)) { @@ -590,14 +594,12 @@ inline static Int flt_cmp(Float dif) { return dif = 0.0; } -static inline Int a_cmp(Term t1, Term t2 USES_REGS) { +static Int a_cmp(Term t1, Term t2 USES_REGS) { if (IsVarTerm(t1)) { - Yap_Error(INSTANTIATION_ERROR, t1, "=:=/2"); - return FALSE; + Yap_ThrowError( INSTANTIATION_ERROR, t1, "while doing arithmetic comparison" ); } if (IsVarTerm(t2)) { - Yap_Error(INSTANTIATION_ERROR, t2, "=:=/2"); - return FALSE; + Yap_ThrowError( INSTANTIATION_ERROR, t1, "while doing arithmetic comparison" ); } if (IsFloatTerm(t1) && IsFloatTerm(t2)) { return flt_cmp(FloatOfTerm(t1) - FloatOfTerm(t2)); @@ -620,8 +622,7 @@ static inline Int a_cmp(Term t1, Term t2 USES_REGS) { Float f2 = FloatOfTerm(t2); #if HAVE_ISNAN if (isnan(f2)) { - LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED; - LOCAL_ErrorMessage = "trying to evaluate nan"; + Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t2, "trying to evaluate nan" ); } #endif return flt_cmp(i1 - f2); @@ -636,8 +637,7 @@ static inline Int a_cmp(Term t1, Term t2 USES_REGS) { Float f1 = FloatOfTerm(t1); #if HAVE_ISNAN if (isnan(f1)) { - LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED; - LOCAL_ErrorMessage = "trying to evaluate nan"; + Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t1, "trying to evaluate nan" ); } #endif t2 = Yap_Eval(t2); @@ -653,9 +653,8 @@ static inline Int a_cmp(Term t1, Term t2 USES_REGS) { Float f2 = FloatOfTerm(t2); #if HAVE_ISNAN if (isnan(f2)) { - LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED; - LOCAL_ErrorMessage = "trying to evaluate nan"; - } + Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t2, "trying to evaluate nan" ); + } #endif return flt_cmp(f1 - f2); #ifdef USE_GMP @@ -676,8 +675,7 @@ static inline Int a_cmp(Term t1, Term t2 USES_REGS) { Float f2 = FloatOfTerm(t2); #if HAVE_ISNAN if (isnan(f2)) { - LOCAL_Error_TYPE = EVALUATION_ERROR_UNDEFINED; - LOCAL_ErrorMessage = "trying to evaluate nan"; + Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t2, "trying to evaluate nan" ); } #endif return Yap_gmp_cmp_big_float(t1, f2); @@ -744,7 +742,6 @@ static Int a_eq(Term t1, Term t2) { } } out = a_cmp(t1, t2 PASS_REGS); - Yap_Error(LOCAL_Error_TYPE, t1, LOCAL_ErrorMessage); return out == 0; } diff --git a/C/compiler.c b/C/compiler.c index b8f0f82d6..29735c82e 100644 --- a/C/compiler.c +++ b/C/compiler.c @@ -1080,10 +1080,8 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, } else { char s[32]; - LOCAL_Error_TYPE = TYPE_ERROR_NUMBER; - Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling %s/2 with output bound", s); + Yap_ThrowError( TYPE_ERROR_NUMBER, t2, "compiling %s/2 with output bound", s); save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, 1); } @@ -1094,9 +1092,8 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, if (IsNewVar(t2)) { char s[32]; - LOCAL_Error_TYPE = INSTANTIATION_ERROR; Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling %s/3", s); + Yap_ThrowError(INSTANTIATION_ERROR , t2, "compiling %s/3", s); save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, 1); } @@ -1107,10 +1104,7 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, if (!IsIntegerTerm(t2)) { char s[32]; - - LOCAL_Error_TYPE = TYPE_ERROR_INTEGER; - Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling functor/3"); + Yap_ThrowError( TYPE_ERROR_INTEGER, t2, "compiling functor/3"); save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, 1); } @@ -1118,9 +1112,7 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, if (i2 < 0) { char s[32]; - LOCAL_Error_TYPE = DOMAIN_ERROR_NOT_LESS_THAN_ZERO; - Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling functor/3"); + Yap_ThrowError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO , t2, "compiling functor/3"); save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, 1); } diff --git a/C/errors.c b/C/errors.c index 3bb7d7752..3e00393b1 100755 --- a/C/errors.c +++ b/C/errors.c @@ -310,6 +310,27 @@ yap_error_descriptor_t *Yap_popErrorContext(void) { return new_error; } +void Yap_ThrowError__(const char *file, const char *function, int lineno, + yap_error_number type, Term where, ...) { + va_list ap; + char tmpbuf[MAXPATHLEN]; + + va_start(ap, where); + char *format = va_arg(ap, char *); + if (format != NULL) { +#if HAVE_VSNPRINTF + (void)vsnprintf(tmpbuf, MAXPATHLEN - 1, format, ap); +#else + (void)vsprintf(tnpbuf, format, ap); +#endif + // fprintf(stderr, "warning: "); +Yap_Error__(file, function, lineno, type, where, tmpbuf); + } else { + Yap_Error__(file, function, lineno, type, where); + } + siglongjmp(LOCAL_RestartEnv, 2); +} + /** * @brief Yap_Error * This function handles errors in the C code. Check errors.yap for the diff --git a/C/exec.c b/C/exec.c index 7869bf728..b6f61030b 100755 --- a/C/exec.c +++ b/C/exec.c @@ -2229,6 +2229,7 @@ bool Yap_ResetException(int wid) { Yap_PopTermFromDB(REMOTE_ActiveError(wid)->errorTerm); } REMOTE_ActiveError(wid)->errorTerm = NULL; + REMOTE_ActiveError(wid)->errorTerm = NULL; return true; } diff --git a/C/grow.c b/C/grow.c index 953ea53f4..e3e373d62 100755 --- a/C/grow.c +++ b/C/grow.c @@ -749,9 +749,7 @@ AdjustScannerStacks(TokEntry **tksp, VarEntry **vep USES_REGS) break; case Var_tok: case String_tok: - case WString_tok: case BQString_tok: - case WBQString_tok: if (IsOldTrail(tks->TokInfo)) tks->TokInfo = TrailAdjust(tks->TokInfo); break; diff --git a/C/parser.c b/C/parser.c index 791ea2da1..b8c0c794e 100755 --- a/C/parser.c +++ b/C/parser.c @@ -173,12 +173,15 @@ const char *Yap_tokRep(void *tokptr, encoding_t enc); static void syntax_msg(const char *msg, ...) { CACHE_REGS va_list ap; - - if (LOCAL_toktide == LOCAL_tokptr) { - LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE + 1); + if (!LOCAL_ErrorMessage || + (LOCAL_Error_TYPE == SYNTAX_ERROR && + LOCAL_ActiveError->prologParserLine < LOCAL_tokptr->TokPos)) { + if (!LOCAL_ErrorMessage) { + LOCAL_ErrorMessage = malloc(1024 + 1); + } + LOCAL_ActiveError->prologParserLine = LOCAL_tokptr->TokPos; va_start(ap, msg); - vsnprintf(LOCAL_ErrorMessage, YAP_FILENAME_MAX, msg, ap); - LOCAL_Error_TYPE = SYNTAX_ERROR; + vsnprintf(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE, msg, ap); va_end(ap); } } @@ -224,22 +227,18 @@ static void syntax_msg(const char *msg, ...) { #define FAIL siglongjmp(FailBuff->JmpBuff, 1) -VarEntry * -Yap_LookupVar(const char *var) /* lookup variable in variables table - * */ +VarEntry *Yap_LookupVar(const char *var) /* lookup variable in variables table + * */ { CACHE_REGS VarEntry *p; - int32_t ch; - const unsigned char *v1 = var; + Atom vat = Yap_LookupAtom(var); #if DEBUG if (GLOBAL_Option[4]) fprintf(stderr, "[LookupVar %s]", var); #endif - - v1 = v1 + get_utf8(v1, 1, &ch); - if (ch != '_' || v1[0] != '\0') { + if (var[0] != '_' || var[1] != '\0') { VarEntry **op = &LOCAL_VarTable; UInt hv; @@ -249,7 +248,7 @@ Yap_LookupVar(const char *var) /* lookup variable in variables table CELL hpv = p->hv; if (hv == hpv) { Int scmp; - if ((scmp = strcmp(var, p->VarRep)) == 0) { + if ((scmp = strcmp(var, RepAtom(p->VarRep)->StrOfAE)) == 0) { p->refs++; return (p); } else if (scmp < 0) { @@ -267,22 +266,21 @@ Yap_LookupVar(const char *var) /* lookup variable in variables table p = p->VarRight; } } - p = (VarEntry *)Yap_AllocScannerMemory(strlen(var) + 1+ sizeof(VarEntry)); + p = (VarEntry *)Yap_AllocScannerMemory(sizeof(VarEntry)); *op = p; p->VarLeft = p->VarRight = NULL; p->hv = hv; p->refs = 1L; - strcpy(p->VarRep, var); + p->VarRep = vat; } else { /* anon var */ - p = (VarEntry *)Yap_AllocScannerMemory(sizeof(VarEntry) + 3); + p = (VarEntry *)Yap_AllocScannerMemory(sizeof(VarEntry)); p->VarLeft = LOCAL_AnonVarTable; LOCAL_AnonVarTable = p; p->VarRight = NULL; p->refs = 0L; p->hv = 1L; - p->VarRep[0] = '_'; - p->VarRep[1] = '\0'; + p->VarRep = vat; } p->VarAdr = TermNil; return (p); @@ -290,11 +288,11 @@ Yap_LookupVar(const char *var) /* lookup variable in variables table static Term VarNames(VarEntry *p, Term l USES_REGS) { if (p != NULL) { - if (strcmp(p->VarRep, "_") != 0) { + if (strcmp(RepAtom(p->VarRep)->StrOfAE, "_") != 0) { Term t[2]; Term o; - t[0] = MkAtomTerm(Yap_LookupAtom(p->VarRep)); + t[0] = MkAtomTerm(p->VarRep); if (!IsVarTerm(p->VarAdr)) p->VarAdr = MkVarTerm(); t[1] = p->VarAdr; @@ -321,11 +319,11 @@ Term Yap_VarNames(VarEntry *p, Term l) { static Term Singletons(VarEntry *p, Term l USES_REGS) { if (p != NULL) { - if (p->VarRep[0] != '_' && p->refs == 1) { + if (RepAtom(p->VarRep)->StrOfAE[0] != '_' && p->refs == 1) { Term t[2]; Term o; - t[0] = MkAtomTerm(Yap_LookupAtom(p->VarRep)); + t[0] = MkAtomTerm(p->VarRep); t[1] = p->VarAdr; o = Yap_MkApplTerm(FunctorEq, 2, t); o = MkPairTerm(o, @@ -404,10 +402,10 @@ static int IsInfixOp(Atom op, int *pptr, int *lpptr, int *rpptr, OpEntry *opp = Yap_GetOpProp(op, INFIX_OP, cmod PASS_REGS); if (!opp) - return FALSE; + return false; if (opp->OpModule && opp->OpModule != cmod) { READ_UNLOCK(opp->OpRWLock); - return FALSE; + return false; } if ((p = opp->Infix) != 0) { READ_UNLOCK(opp->OpRWLock); @@ -614,7 +612,8 @@ static Term ParseArgs(Atom a, Term close, JMPBUFF *FailBuff, Term arg1, } static Term MakeAccessor(Term t, Functor f USES_REGS) { - UInt arity = ArityOfFunctor(FunctorOfTerm(t)), i; + UInt arity = ArityOfFunctor(FunctorOfTerm(t)); + int i; Term tf[2], tl = TermNil; tf[1] = ArgOfTerm(1, t); @@ -791,7 +790,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, case '{': NextToken; if (LOCAL_tokptr->Tok == Ponctuation_tok && - (int)LOCAL_tokptr->TokInfo == TermEndSquareBracket) { + (int)LOCAL_tokptr->TokInfo == TermEndCurlyBracket) { t = MkAtomTerm(AtomBraces); NextToken; break; @@ -803,7 +802,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, syntax_msg("line %d: Stack Overflow", LOCAL_tokptr->TokPos); FAIL; } - checkfor(TermEndSquareBracket, FailBuff, enc PASS_REGS); + checkfor(TermEndCurlyBracket, FailBuff, enc PASS_REGS); break; default: syntax_msg("line %d: unexpected ponctuation signal %s", @@ -905,15 +904,16 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, /* main loop to parse infix and posfix operators starts here */ while (true) { + Atom name; if (LOCAL_tokptr->Tok == Ord(Name_tok) && - Yap_HasOp(AtomOfTerm(LOCAL_tokptr->TokInfo))) { - Atom save_opinfo = opinfo = AtomOfTerm(LOCAL_tokptr->TokInfo); + Yap_HasOp((name = AtomOfTerm(LOCAL_tokptr->TokInfo)))) { + Atom save_opinfo = opinfo = name; if (IsInfixOp(save_opinfo, &opprio, &oplprio, &oprprio, cmod PASS_REGS) && opprio <= prio && oplprio >= curprio) { /* try parsing as infix operator */ Volatile int oldprio = curprio; TRY3( - func = Yap_MkFunctor(AtomOfTerm(LOCAL_tokptr->TokInfo), 2); + func = Yap_MkFunctor(save_opinfo, 2); if (func == NULL) { syntax_msg("line %d: Heap Overflow", LOCAL_tokptr->TokPos); FAIL; @@ -954,7 +954,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, break; } if (LOCAL_tokptr->Tok == Ord(Ponctuation_tok)) { - if (LOCAL_tokptr->TokInfo == TermDot && prio >= 1000 && curprio <= 999) { + if (LOCAL_tokptr->TokInfo == TermComma && prio >= 1000 && curprio <= 999) { Volatile Term args[2]; NextToken; args[0] = t; @@ -1001,17 +1001,17 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, curprio = opprio; continue; } else if (LOCAL_tokptr->TokInfo == TermBeginCurlyBracket && - IsPosfixOp(AtomEmptyCurlyBrackets, &opprio, &oplprio, + IsPosfixOp(AtomBraces, &opprio, &oplprio, cmod PASS_REGS) && opprio <= prio && oplprio >= curprio) { - t = ParseArgs(AtomEmptyCurlyBrackets, TermEndCurlyBracket, FailBuff, t, + t = ParseArgs(AtomBraces, TermEndCurlyBracket, FailBuff, t, enc, cmod PASS_REGS); - t = MakeAccessor(t, FunctorEmptyCurlyBrackets PASS_REGS); + t = MakeAccessor(t, FunctorBraces PASS_REGS); curprio = opprio; continue; } } - if (LOCAL_tokptr->Tok <= Ord(WString_tok)) { + if (LOCAL_tokptr->Tok <= Ord(String_tok)) { syntax_msg("line %d: expected operator, got \'%s\'", LOCAL_tokptr->TokPos, Yap_tokRep(LOCAL_tokptr, enc)); FAIL; @@ -1026,6 +1026,7 @@ Term Yap_Parse(UInt prio, encoding_t enc, Term cmod) { Volatile Term t; JMPBUFF FailBuff; yhandle_t sls = Yap_StartSlots(); + LOCAL_toktide = LOCAL_tokptr; if (!sigsetjmp(FailBuff.JmpBuff, 0)) { @@ -1042,22 +1043,19 @@ Term Yap_Parse(UInt prio, encoding_t enc, Term cmod) { } #endif Yap_CloseSlots(sls); - if (LOCAL_tokptr != NULL && LOCAL_tokptr->Tok != Ord(eot_tok)) { - LOCAL_Error_TYPE = SYNTAX_ERROR; - LOCAL_ErrorMessage = "term does not end on . "; - t = 0; - } - if (t != 0 && LOCAL_Error_TYPE == SYNTAX_ERROR) { - LOCAL_Error_TYPE = YAP_NO_ERROR; - LOCAL_ErrorMessage = NULL; - } - // if (LOCAL_tokptr->Tok != Ord(eot_tok)) - // return (0L); - return t; } - Yap_CloseSlots(sls); - - return (0); + if (LOCAL_tokptr != NULL && LOCAL_tokptr->Tok != Ord(eot_tok)) { + LOCAL_Error_TYPE = SYNTAX_ERROR; + LOCAL_ErrorMessage = "term does not end on . "; + t = 0; + } + if (t != 0 && LOCAL_Error_TYPE == SYNTAX_ERROR) { + LOCAL_Error_TYPE = YAP_NO_ERROR; + LOCAL_ErrorMessage = NULL; + } + // if (LOCAL_tokptr->Tok != Ord(eot_tok)) + // return (0L); + return t; } //! @} diff --git a/C/scanner.c b/C/scanner.c index db66bba17..0b661653a 100755 --- a/C/scanner.c +++ b/C/scanner.c @@ -1202,7 +1202,8 @@ Term Yap_scan_num(StreamDesc *inp) { ef->TokNext = NULL; LOCAL_tokptr = tokptr; LOCAL_toktide = e; - LOCAL_ErrorMessage = Yap_syntax_error(e, inp - GLOBAL_Stream); + Yap_JumpToEnv( + Yap_syntax_error(e, inp - GLOBAL_Stream) ); LOCAL_Error_TYPE = SYNTAX_ERROR; } } @@ -1237,21 +1238,18 @@ const char *Yap_tokRep(void *tokptre, encoding_t encoding) { case Ponctuation_tok: case String_tok: case BQString_tok: - case WString_tok: - case WBQString_tok: { return Yap_TermToString(info, &length, encoding, flags); - } - case Var_tok: { + case Var_tok: + { VarEntry *varinfo = (VarEntry *)info; varinfo->VarAdr = TermNil; - return varinfo->VarRep; + return RepAtom(varinfo->VarRep)->StrOfAE; } case Error_tok: return ""; case eot_tok: return ""; case QuasiQuotes_tok: - case WQuasiQuotes_tok: return ""; } } @@ -1445,7 +1443,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments, } t->Tok = Ord(kind = Var_tok); } - + } break; case NU: { @@ -1923,7 +1921,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments, qq->end.byteno = fseek(inp_stream->file, 0, 0); } else { qq->end.byteno = inp_stream->charcount - 1; - } + } qq->end.lineno = inp_stream->linecount; qq->end.linepos = inp_stream->linepos - 1; qq->end.charno = inp_stream->charcount - 1; @@ -1977,7 +1975,6 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments, return (l); } -int vsc_count; void Yap_clean_tokenizer(TokEntry *tokstart, VarEntry *vartable, VarEntry *anonvartable) { diff --git a/C/text.c b/C/text.c index 5d3e440af..6034c3e1d 100644 --- a/C/text.c +++ b/C/text.c @@ -52,19 +52,16 @@ typedef struct TextBuffer_manager { } text_buffer_t; int push_text_stack(USES_REGS1) { - printf("push %d\n", LOCAL_TextBuffer->lvl); return LOCAL_TextBuffer->lvl++; } int pop_text_stack(int i) { - printf("pop %d\n", i); int lvl = LOCAL_TextBuffer->lvl; while (lvl > i) { struct mblock *p = LOCAL_TextBuffer->first[lvl]; while (p) { struct mblock *np = p->next; free(p); - printf("----------> %p free\n", p); p = np; } LOCAL_TextBuffer->first[lvl] = NULL; @@ -95,7 +92,6 @@ void *Malloc(size_t sz USES_REGS) { o->next = NULL; o->sz = sz; o->lvl = lvl; - printf("%p malloc %d\n", o, sz); return o + 1; } @@ -115,7 +111,6 @@ void *Realloc(void *pt, size_t sz USES_REGS) { if (LOCAL_TextBuffer->last[lvl] == old) { LOCAL_TextBuffer->last[lvl] = o; } - printf("%p realloc %ld\n", o, sz); return o + 1; } @@ -136,7 +131,6 @@ void Free(void *pt USES_REGS) { LOCAL_TextBuffer->last[lvl] = o->prev; } free(o); - printf("%p free\n", o); } void *Yap_InitTextAllocator(void) { @@ -392,7 +386,7 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) { // this is a term, extract to a buffer, and representation is wide // Yap_DebugPlWriteln(inp->val.t); Atom at = AtomOfTerm(inp->val.t); - inp->val.uc = at->UStrOfAE; + return at->UStrOfAE; } if (IsStringTerm(inp->val.t) && inp->type & YAP_STRING_STRING) { // this is a term, extract to a buffer, and representation is wide @@ -636,7 +630,7 @@ static Term write_codes(void *s0, seq_tv_t *out, size_t leng USES_REGS) { static Atom write_atom(void *s0, seq_tv_t *out, size_t leng USES_REGS) { unsigned char *s = s0; int32_t ch; - if (strlen_utf8(s0) <= leng) { + if (!leng || strlen_utf8(s0) <= leng) { return Yap_LookupAtom(s0); } else { size_t n = get_utf8(s, 1, &ch); @@ -729,15 +723,17 @@ static Term write_number(unsigned char *s, seq_tv_t *out, int size USES_REGS) { static Term string_to_term(void *s, seq_tv_t *out, size_t leng USES_REGS) { Term o; - int i = push_text_stack(); o = out->val.t = Yap_StringToTerm(s, strlen(s) + 1, &out->enc, GLOBAL_MaxPriority, NULL); - pop_text_stack(i); return o; } bool write_Text(unsigned char *inp, seq_tv_t *out, size_t leng USES_REGS) { /* we know what the term is */ + if (out->type == 0) { + return true; + } + if (out->type & YAP_STRING_TERM) { if ((out->val.t = string_to_term(inp, out, leng PASS_REGS)) != 0L) return out->val.t != 0; @@ -753,7 +749,7 @@ bool write_Text(unsigned char *inp, seq_tv_t *out, size_t leng USES_REGS) { return false; } if (out->type & (YAP_STRING_ATOM)) { - if (write_atom(inp, out, leng PASS_REGS) != NIL) { + if ((out->val.a = write_atom(inp, out, leng PASS_REGS)) != NIL) { Atom at = out->val.a; if (at && (out->type & YAP_STRING_OUTPUT_TERM)) out->val.t = MkAtomTerm(at); @@ -797,7 +793,7 @@ bool write_Text(unsigned char *inp, seq_tv_t *out, size_t leng USES_REGS) { out->val.t = write_number(inp, out, leng PASS_REGS); // Yap_DebugPlWriteln(out->val.t); return out->val.t != 0; - default: {} + default: { return true ; } } return false; } @@ -833,7 +829,6 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) { bool rc; size_t leng; - int l = push_text_stack(PASS_REGS1); /* f//printfmark(stderr, "[ %d ", n++) ; if (inp->type & (YAP_STRING_TERM|YAP_STRING_ATOM|YAP_STRING_ATOMS_CODES @@ -858,26 +853,22 @@ bool Yap_CVT_Text(seq_tv_t *inp, seq_tv_t *out USES_REGS) { } if (!buf) { - pop_text_stack( l); return 0L; } if (out->type & (YAP_STRING_UPCASE | YAP_STRING_DOWNCASE)) { if (out->type & YAP_STRING_UPCASE) { if (!upcase(buf, out)) { - pop_text_stack( l); return false; } } if (out->type & YAP_STRING_DOWNCASE) { if (!downcase(buf, out)) { - pop_text_stack( l); return false; } } } rc = write_Text(buf, out, leng PASS_REGS); - pop_text_stack(l); /* fprintf(stderr, " -> "); if (!rc) fprintf(stderr, "NULL"); else if (out->type & @@ -919,9 +910,7 @@ static unsigned char *concat(int n, unsigned char *sv[] USES_REGS) { buf = Malloc(room + 1); buf0 = (unsigned char *)buf; for (i = 0; i < n; i++) { - char *s = (char *)sv[i]; - buf = strcpy(buf, s); - buf += strlen(s); + buf = stpcpy(buf, sv[i]); } return buf0; } @@ -945,12 +934,11 @@ static void *slice(size_t min, size_t max, unsigned char *buf USES_REGS) { bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) { unsigned char **bufv; unsigned char *buf; - size_t leng; int i; - int l = push_text_stack(PASS_REGS1); + size_t leng; + bufv = Malloc(tot * sizeof(unsigned char *)); if (!bufv) { - pop_text_stack( l); return NULL; } for (i = 0; i < tot; i++) { @@ -958,14 +946,12 @@ bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) { unsigned char *nbuf = Yap_readText(inp + i, &leng PASS_REGS); if (!nbuf) { - pop_text_stack( l); return NULL; } bufv[i] = nbuf; } buf = concat(tot, bufv PASS_REGS); - bool rc = write_Text(buf, out, leng PASS_REGS); - pop_text_stack(l); + bool rc = write_Text(buf, out, 0 PASS_REGS); return rc; } @@ -973,14 +959,11 @@ bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) { bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp, seq_tv_t outv[] USES_REGS) { unsigned char *buf; - int lvl = push_text_stack(PASS_REGS1); size_t l; inp->type |= YAP_STRING_IN_TMP; buf = Yap_readText(inp, &l PASS_REGS); if (!buf) { - pop_text_stack( l); - return false; } if (!cuts) { @@ -991,11 +974,9 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp, if (outv[0].val.t) { buf0 = Yap_readText(outv, &l0 PASS_REGS); if (!buf0) { - pop_text_stack( l); return false; } if (cmp_Text(buf, buf0, l0) != 0) { - pop_text_stack( l); return false; } l1 = l - l0; @@ -1003,26 +984,21 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp, buf1 = slice(l0, l, buf PASS_REGS); bool rc = write_Text(buf1, outv + 1, l1 PASS_REGS); if (!rc) { - pop_text_stack( l); return false; } - pop_text_stack(lvl); return rc; } else /* if (outv[1].val.t) */ { buf1 = Yap_readText(outv + 1, &l1 PASS_REGS); if (!buf1) { - pop_text_stack( l); return false; } l0 = l - l1; if (cmp_Text(skip_utf8((const unsigned char *)buf, l0), buf1, l1) != 0) { - pop_text_stack( l); return false; } buf0 = slice(0, l0, buf PASS_REGS); bool rc = write_Text(buf0, outv, l0 PASS_REGS); - pop_text_stack((rc ? 0 : lvl)); return rc; } } @@ -1033,14 +1009,14 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp, next = 0; else next = cuts[i - 1]; + if (cuts[i] == 0) + break; void *bufi = slice(next, cuts[i], buf PASS_REGS); if (!write_Text(bufi, outv + i, cuts[i] - next PASS_REGS)) { - pop_text_stack( l); return false; } } - pop_text_stack(l); - + return true; } diff --git a/C/write.c b/C/write.c index a0c0768e4..c9b8ada28 100644 --- a/C/write.c +++ b/C/write.c @@ -1012,7 +1012,7 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg, } } else if (!wglb->Ignore_ops && (Arity == 1 || - ((atom == AtomEmptyBrackets || atom == AtomEmptyCurlyBrackets || + ((atom == AtomEmptyBrackets || atom == AtomCurly || atom == AtomEmptySquareBrackets) && Yap_IsListTerm(ArgOfTerm(1, t)))) && Yap_IsPosfixOp(atom, &op, &lp)) { @@ -1047,7 +1047,7 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg, wrputc('(', wglb->stream); } else if (atom == AtomEmptySquareBrackets) { wrputc('[', wglb->stream); - } else if (atom == AtomEmptyCurlyBrackets) { + } else if (atom == AtomCurly) { wrputc('{', wglb->stream); } lastw = separator; @@ -1056,7 +1056,7 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg, wrputc(')', wglb->stream); } else if (atom == AtomEmptySquareBrackets) { wrputc(']', wglb->stream); - } else if (atom == AtomEmptyCurlyBrackets) { + } else if (atom == AtomCurly) { wrputc('}', wglb->stream); } lastw = separator; diff --git a/CXX/yapa.hh b/CXX/yapa.hh index e1b955817..924238099 100644 --- a/CXX/yapa.hh +++ b/CXX/yapa.hh @@ -23,8 +23,6 @@ enum PropTag { MUTEX_TAG = MutexProperty, // 0xFFF6, /// A typed array, may be in-db or in-stack deped ARRAY_TAG = ArrayProperty, // 0xFFF7, - /// atom does not fit ISO-LATIN-1 - WIDE_TAG = WideAtomProperty, // 0xFFF8, /// module MODULE_TAG = ModProperty, // 0xFFFA, /// the original SICStus blackboard @@ -59,14 +57,12 @@ class YAPAtom { /// construct new YAPAtom from Atom YAPAtom( Atom at ) { a = at; } public: - /// construct new YAPAtom from string + /// construct new YAPAtom from UTF-8 string YAPAtom( const char * s) { a = Yap_LookupAtom( s ); } /// construct new YAPAtom from wide string -YAPAtom( const wchar_t * s) { a = Yap_LookupMaybeWideAtom( s ); } + //YAPAtom( const wchar_t * s) { a = Yap_LookupMaybeWideAtom( s ); } /// construct new YAPAtom from max-length string YAPAtom( const char * s, size_t len) { a = Yap_LookupAtomWithLength( s, len ); } - /// construct new YAPAtom from max-length wide string - YAPAtom( const wchar_t * s, size_t len) { a = Yap_LookupMaybeWideAtomWithLength( s, len ); } /// get name of atom const char *getName(void); /// get name of (other way) diff --git a/H/ATOMS b/H/ATOMS index 71f4b341b..81f0ad055 100644 --- a/H/ATOMS +++ b/H/ATOMS @@ -37,7 +37,6 @@ A BeginCurlyBracket N "{" A EndCurlyBracket N "}" A EmptyBrackets N "()" A EmptySquareBrackets N "[]" -A EmptyCurlyBrackets N "{}" A Asserta N "asserta" A AssertaStatic N "asserta_static" A Assertz N "assertz" @@ -498,7 +497,6 @@ F Dot8 Dot 8 F Dot9 Dot 9 F DoubleSlash DoubleSlash 2 F EmptySquareBrackets EmptySquareBrackets 2 -F EmptyCurlyBrackets EmptyCurlyBrackets 2 F Eq Eq 2 F Error Error 2 F EvaluationError EvaluationError 1 diff --git a/H/ScannerTypes.h b/H/ScannerTypes.h index e760a67cb..c1667f7d9 100644 --- a/H/ScannerTypes.h +++ b/H/ScannerTypes.h @@ -3,13 +3,10 @@ typedef enum TokenKinds { Number_tok, Var_tok, String_tok, - WString_tok, BQString_tok, - WBQString_tok, Ponctuation_tok, Error_tok, QuasiQuotes_tok, - WQuasiQuotes_tok, eot_tok } tkinds; @@ -29,5 +26,5 @@ typedef struct VARSTRUCT { CELL hv; UInt refs; struct VARSTRUCT *VarLeft, *VarRight; - char VarRep[1]; + Atom VarRep; } VarEntry; diff --git a/H/YapGFlagInfo.h b/H/YapGFlagInfo.h index a544e9066..84e7a2e92 100644 --- a/H/YapGFlagInfo.h +++ b/H/YapGFlagInfo.h @@ -524,7 +524,7 @@ and _Patch_ is the patch number. */ YAP_FLAG(VERSION_DATA_FLAG, "version_data", false, ro, YAP_TVERSION, NULL), /**< -`version ` Read-only flag that returns an a compound term with the +`version ` Read-only flag that returns a compound term with the current version of YAP. The term will have the name `yap` and arity 4, the first argument will be the major version, the second the minor version, the third the patch number, and the diff --git a/H/YapText.h b/H/YapText.h index d2c5fe412..c6c501b3b 100644 --- a/H/YapText.h +++ b/H/YapText.h @@ -190,7 +190,7 @@ inline static utf8proc_ssize_t strlen_utf8(const utf8proc_uint8_t *pt) { return rc; else if (b > 0) { pt += l; - rc += l; + rc ++; } else { pt++; } diff --git a/H/generated/iatoms.h b/H/generated/iatoms.h index 8ec395dce..3507ac20e 100644 --- a/H/generated/iatoms.h +++ b/H/generated/iatoms.h @@ -32,7 +32,6 @@ AtomEndCurlyBracket = Yap_LookupAtom("}"); TermEndCurlyBracket = MkAtomTerm(AtomEndCurlyBracket); AtomEmptyBrackets = Yap_LookupAtom("()"); TermEmptyBrackets = MkAtomTerm(AtomEmptyBrackets); AtomEmptySquareBrackets = Yap_LookupAtom("[]"); TermEmptySquareBrackets = MkAtomTerm(AtomEmptySquareBrackets); - AtomEmptyCurlyBrackets = Yap_LookupAtom("{}"); TermEmptyCurlyBrackets = MkAtomTerm(AtomEmptyCurlyBrackets); AtomAsserta = Yap_LookupAtom("asserta"); TermAsserta = MkAtomTerm(AtomAsserta); AtomAssertaStatic = Yap_LookupAtom("asserta_static"); TermAssertaStatic = MkAtomTerm(AtomAssertaStatic); AtomAssertz = Yap_LookupAtom("assertz"); TermAssertz = MkAtomTerm(AtomAssertz); @@ -493,7 +492,6 @@ FunctorDot9 = Yap_MkFunctor(AtomDot,9); FunctorDoubleSlash = Yap_MkFunctor(AtomDoubleSlash,2); FunctorEmptySquareBrackets = Yap_MkFunctor(AtomEmptySquareBrackets,2); - FunctorEmptyCurlyBrackets = Yap_MkFunctor(AtomEmptyCurlyBrackets,2); FunctorEq = Yap_MkFunctor(AtomEq,2); FunctorError = Yap_MkFunctor(AtomError,2); FunctorEvaluationError = Yap_MkFunctor(AtomEvaluationError,1); diff --git a/H/generated/ratoms.h b/H/generated/ratoms.h index 84cf03699..e8f1fd332 100644 --- a/H/generated/ratoms.h +++ b/H/generated/ratoms.h @@ -32,7 +32,6 @@ AtomEndCurlyBracket = AtomAdjust(AtomEndCurlyBracket); TermEndCurlyBracket = MkAtomTerm(AtomEndCurlyBracket); AtomEmptyBrackets = AtomAdjust(AtomEmptyBrackets); TermEmptyBrackets = MkAtomTerm(AtomEmptyBrackets); AtomEmptySquareBrackets = AtomAdjust(AtomEmptySquareBrackets); TermEmptySquareBrackets = MkAtomTerm(AtomEmptySquareBrackets); - AtomEmptyCurlyBrackets = AtomAdjust(AtomEmptyCurlyBrackets); TermEmptyCurlyBrackets = MkAtomTerm(AtomEmptyCurlyBrackets); AtomAsserta = AtomAdjust(AtomAsserta); TermAsserta = MkAtomTerm(AtomAsserta); AtomAssertaStatic = AtomAdjust(AtomAssertaStatic); TermAssertaStatic = MkAtomTerm(AtomAssertaStatic); AtomAssertz = AtomAdjust(AtomAssertz); TermAssertz = MkAtomTerm(AtomAssertz); @@ -493,7 +492,6 @@ FunctorDot9 = FuncAdjust(FunctorDot9); FunctorDoubleSlash = FuncAdjust(FunctorDoubleSlash); FunctorEmptySquareBrackets = FuncAdjust(FunctorEmptySquareBrackets); - FunctorEmptyCurlyBrackets = FuncAdjust(FunctorEmptyCurlyBrackets); FunctorEq = FuncAdjust(FunctorEq); FunctorError = FuncAdjust(FunctorError); FunctorEvaluationError = FuncAdjust(FunctorEvaluationError); diff --git a/H/generated/tatoms.h b/H/generated/tatoms.h index eef642851..3f061d0ab 100644 --- a/H/generated/tatoms.h +++ b/H/generated/tatoms.h @@ -32,7 +32,6 @@ EXTERNAL Atom AtomBeginCurlyBracket; EXTERNAL Term TermBeginCurlyBracket; EXTERNAL Atom AtomEndCurlyBracket; EXTERNAL Term TermEndCurlyBracket; EXTERNAL Atom AtomEmptyBrackets; EXTERNAL Term TermEmptyBrackets; EXTERNAL Atom AtomEmptySquareBrackets; EXTERNAL Term TermEmptySquareBrackets; -EXTERNAL Atom AtomEmptyCurlyBrackets; EXTERNAL Term TermEmptyCurlyBrackets; EXTERNAL Atom AtomAsserta; EXTERNAL Term TermAsserta; EXTERNAL Atom AtomAssertaStatic; EXTERNAL Term TermAssertaStatic; EXTERNAL Atom AtomAssertz; EXTERNAL Term TermAssertz; @@ -549,8 +548,6 @@ EXTERNAL Functor FunctorDoubleSlash; EXTERNAL Functor FunctorEmptySquareBrackets; -EXTERNAL Functor FunctorEmptyCurlyBrackets; - EXTERNAL Functor FunctorEq; EXTERNAL Functor FunctorError; diff --git a/include/YapError.h b/include/YapError.h index 22ebb3628..7fdb82142 100644 --- a/include/YapError.h +++ b/include/YapError.h @@ -41,11 +41,18 @@ struct yami *Yap_Error__(const char *file, const char *function, int lineno, yap_error_number err, YAP_Term wheret, ...); +void Yap_ThrowError__(const char *file, const char *function, int lineno, + yap_error_number err, YAP_Term wheret, ...); + + #define Yap_NilError(id, ...) \ Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, TermNil, __VA_ARGS__) #define Yap_Error(id, inp, ...) \ - Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, inp, __VA_ARGS__) +Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, inp, __VA_ARGS__) + +#define Yap_ThrowError(id, inp, ...) \ +Yap_ThrowError__(__FILE__, __FUNCTION__, __LINE__, id, inp, __VA_ARGS__) #ifdef YAP_TERM_H /** diff --git a/os/iopreds.c b/os/iopreds.c index f3255cbfa..a4e534d2e 100644 --- a/os/iopreds.c +++ b/os/iopreds.c @@ -1869,7 +1869,7 @@ void Yap_InitIOPreds(void) { Yap_InitReadTPreds(); Yap_InitFormat(); Yap_InitRandomPreds(); - #if USE_READLINE +#if USE_READLINE Yap_InitReadlinePreds(); #endif Yap_InitSockets(); diff --git a/os/iopreds.h b/os/iopreds.h index b547f11c0..5a60e64bf 100644 --- a/os/iopreds.h +++ b/os/iopreds.h @@ -151,7 +151,7 @@ bool Yap_DoPrompt(StreamDesc *s); Int Yap_peek(int sno); int Yap_MemPeekc(int sno); -char *Yap_syntax_error(TokEntry *tokptr, int sno); +Term Yap_syntax_error(TokEntry *tokptr, int sno); int console_post_process_read_char(int, StreamDesc *); int console_post_process_eof(StreamDesc *); diff --git a/os/readterm.c b/os/readterm.c index c5082664e..f1fea677c 100644 --- a/os/readterm.c +++ b/os/readterm.c @@ -95,7 +95,7 @@ static char SccsId[] = "%W% %G%"; #define SYSTEM_STAT stat #endif -static char *syntax_error(TokEntry *errtok, int sno, Term cmod); +static Term syntax_error(TokEntry *errtok, int sno, Term cmod); static void clean_vars(VarEntry *p) { if (p == NULL) @@ -215,7 +215,7 @@ static const param_t read_defs[] = {READ_DEFS()}; * Implicit arguments: * + */ -static char *syntax_error(TokEntry *errtok, int sno, Term cmod) { +static Term syntax_error(TokEntry *errtok, int sno, Term cmod) { CACHE_REGS Term info; Term startline, errline, endline; @@ -270,42 +270,21 @@ static char *syntax_error(TokEntry *errtok, int sno, Term cmod) { 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)); + ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomNumber, 1), 1, &info); break; 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); } 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); + ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &info); } 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); + ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &info); } break; case Error_tok: { ts[0] = MkAtomTerm(AtomError); @@ -361,10 +340,10 @@ static char *syntax_error(TokEntry *errtok, int sno, Term cmod) { Yap_DebugPlWriteln(terr); } #endif - return NULL; + return terr; } -char *Yap_syntax_error(TokEntry *errtok, int sno) { +Term Yap_syntax_error(TokEntry *errtok, int sno) { return syntax_error(errtok, sno, CurrentModule); } @@ -798,21 +777,28 @@ static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) { LOCAL_tokptr = LOCAL_toktide = Yap_tokenizer(GLOBAL_Stream + inp_stream, false, &fe->tpos); - if (LOCAL_ErrorMessage) - return YAP_SCANNING_ERROR; - if (LOCAL_tokptr->Tok != Ord(eot_tok)) { - // next step - return YAP_PARSING; +#if DEBUG + if (GLOBAL_Option[2]) { + TokEntry *t = LOCAL_tokptr; + int n = 0; + while (t) { + fprintf(stderr, "[Token %d %s %d]", Ord(t->Tok), + Yap_tokRep(t, ENC_ISO_UTF8), n++); + t = t->TokNext; + } } - if (LOCAL_tokptr->Tok == eot_tok && LOCAL_tokptr->TokInfo == TermNl) { - size_t len = strlen("Empty clause"); - char *out = malloc(len + 1); - strncpy(out, "Empty clause", len); - LOCAL_ErrorMessage = out; - LOCAL_Error_TYPE = SYNTAX_ERROR; - return YAP_PARSING_ERROR; - } - return scanEOF(fe, inp_stream); +#endif +if (LOCAL_ErrorMessage) + return YAP_SCANNING_ERROR; +if (LOCAL_tokptr->Tok != Ord(eot_tok)) { + // next step + return YAP_PARSING; +} +if (LOCAL_tokptr->Tok == eot_tok && LOCAL_tokptr->TokInfo == TermNl) { + LOCAL_Error_TYPE = SYNTAX_ERROR; + return YAP_PARSING_ERROR; +} +return scanEOF(fe, inp_stream); } static parser_state_t scanError(REnv *re, FEnv *fe, int inp_stream) { @@ -1282,13 +1268,15 @@ X_API Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp, CACHE_REGS Term bvar = MkVarTerm(), ctl; yhandle_t sl; + int lvl = push_text_stack(); if (len == 0) { Term rval = TermEof; if (rval && bindings) { *bindings = TermNil; } - return rval; + pop_text_stack(lvl); + return rval; } if (bindings) { ctl = Yap_MkApplTerm(Yap_MkFunctor(AtomVariableNames, 1), 1, &bvar); @@ -1307,6 +1295,7 @@ X_API Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp, if (rval && bindings) { *bindings = Yap_PopHandle(sl); } + pop_text_stack(lvl); return rval; } diff --git a/pl/boot.yap b/pl/boot.yap index 116261646..5b6972631 100644 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -174,7 +174,7 @@ list, since backtracking could not "pass through" the cut. system_module(_Mod, _SysExps, _Decls). % new_system_module(Mod). -use_system_module(_init, _SysExps). +use_system_module(Module, _SysExps). private(_). @@ -251,6 +251,7 @@ private(_). :- use_system_module( '$_strict_iso', ['$check_iso_strict_clause'/1, '$iso_check_goal'/2]). + '$early_print_message'(Level, Msg) :- '$pred_exists'(print_message(_,_), prolog), !, print_message( Level, Msg). @@ -658,7 +659,7 @@ number of steps. '$execute_command'(G, VL, Pos, Option, Source) :- '$continue_with_command'(Option, VL, Pos, G, Source). - + '$continue_with_command'(Where,V,'$stream_position'(C,_P,A1,A2,A3),'$source_location'(_F,L):G,Source) :- !, '$continue_with_command'(Where,V,'$stream_position'(C,L,A1,A2,A3),G,Source). @@ -1648,6 +1649,3 @@ log_event( String, Args ) :- /** @} */ - - - \ No newline at end of file diff --git a/pl/grammar.yap b/pl/grammar.yap index ec8a9382e..f073a3b73 100644 --- a/pl/grammar.yap +++ b/pl/grammar.yap @@ -109,7 +109,6 @@ prolog:'$translate_rule'(Rule, (NH :- B) ) :- ), t_tidy(B1, B). - t_head(V, _, _, _, _, G0) :- var(V), !, '$do_error'(instantiation_error,G0). t_head((H,List), NH, NGs, S, S1, G0) :- !, From b03e0634c7fc0fc2c9c5ea0987a8cf59207a1747 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Tue, 8 Nov 2016 01:37:36 -0600 Subject: [PATCH 04/41] fixes + win64 --- C/adtdefs.c | 3 +- C/arith1.c | 54 +- C/arith2.c | 54 +- C/atomic.c | 1581 +++++++++-------- C/cdmgr.c | 2 + C/cmppreds.c | 13 +- C/compiler.c | 6 +- C/errors.c | 9 +- C/eval.c | 38 +- C/exec.c | 48 +- C/globals.c | 3 +- C/gmp_support.c | 76 +- C/grow.c | 6 +- C/load_dll.c | 10 +- C/modules.c | 68 +- C/parser.c | 34 +- C/prim_absmi_insts.h | 244 +-- C/scanner.c | 263 ++- C/text.c | 72 +- C/write.c | 5 +- CMakeLists.txt | 23 +- CXX/yapa.hh | 6 +- CXX/yapdb.hh | 2 +- CXX/yapi.cpp | 44 +- CXX/yapt.hh | 8 +- H/ATOMS | 6 + H/YapText.h | 39 +- H/absmi.h | 4 +- H/arith2.h | 46 +- H/eval.h | 2 +- H/generated/iatoms.h | 6 + H/generated/ratoms.h | 6 + H/generated/tatoms.h | 11 + Prelims.cmake | 18 +- cmake/Config.cmake | 1 + config.h.cmake | 5 + include/YapError.h | 6 +- library/lineutils.yap | 43 + os/chartypes.c | 4 +- os/iopreds.h | 2 +- os/readterm.c | 99 +- os/sysbits.c | 61 +- os/writeterm.c | 2 +- os/yapio.h | 2 +- .../approx/simplecuddLPADs/simplecudd.c | 2 +- packages/myddas/sqlite3/myddas_sqlite3.c | 3 +- packages/swig/android/CMakeLists.txt | 22 +- pl/atoms.yap | 2 - pl/boot.yap | 15 +- pl/dbload.yap | 5 +- pl/errors.yap | 2 + pl/messages.yap | 42 +- pl/meta.yap | 6 +- pl/modules.yap | 4 +- pl/preddyns.yap | 1 + pl/signals.yap | 2 +- 56 files changed, 1612 insertions(+), 1529 deletions(-) diff --git a/C/adtdefs.c b/C/adtdefs.c index 617027a14..f067d5965 100755 --- a/C/adtdefs.c +++ b/C/adtdefs.c @@ -55,9 +55,8 @@ uint64_t HashFunction(const unsigned char *CHP) { static Prop GetFunctorProp(AtomEntry *ae, arity_t arity) { /* look property list of atom a for kind */ - FunctorEntry *pp; - PropEntry *p = RepFunctorProp(ae->PropsOfAE); + PropEntry *p = ae->PropsOfAE; while (p != NIL) { if (p->KindOfPE == FunctorProperty && RepFunctorProp(p)->ArityOfFE == arity) { diff --git a/C/arith1.c b/C/arith1.c index cb0a9cba6..8514804dd 100644 --- a/C/arith1.c +++ b/C/arith1.c @@ -326,7 +326,7 @@ msb(Int inp USES_REGS) /* calculate the most significant bit for an integer */ Int out = 0; if (inp < 0) { - return Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, MkIntegerTerm(inp), + Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, MkIntegerTerm(inp), "msb/1 received %d", inp); } @@ -363,7 +363,7 @@ lsb(Int inp USES_REGS) /* calculate the least significant bit for an integer */ Int out = 0; if (inp < 0) { - return Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, MkIntegerTerm(inp), + Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, MkIntegerTerm(inp), "msb/1 received %d", inp); } if (inp==0) @@ -387,7 +387,7 @@ popcount(Int inp USES_REGS) /* calculate the least significant bit for an intege Int c = 0, j = 0, m = ((CELL)1); if (inp < 0) { - return Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, MkIntegerTerm(inp), + Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, MkIntegerTerm(inp), "popcount/1 received %d", inp); } if (inp==0) @@ -434,7 +434,7 @@ eval1(Int fi, Term t USES_REGS) { case long_int_e: RINT(~IntegerOfTerm(t)); case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t, "\\(%f)", FloatOfTerm(t)); + Yap_ArithError(TYPE_ERROR_INTEGER, t, "\\(%f)", FloatOfTerm(t)); case big_int_e: #ifdef USE_GMP return Yap_gmp_unot_big(t); @@ -450,7 +450,7 @@ eval1(Int fi, Term t USES_REGS) { if (dbl >= 0) { RFLOAT(log(dbl)); } else { - return Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t, "log(%f)", dbl); + Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t, "log(%f)", dbl); } } case op_log10: @@ -459,7 +459,7 @@ eval1(Int fi, Term t USES_REGS) { if (dbl >= 0) { RFLOAT(log10(dbl)); } else { - return Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t, "log10(%f)", dbl); + Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t, "log10(%f)", dbl); } } case op_sqrt: @@ -468,7 +468,7 @@ eval1(Int fi, Term t USES_REGS) { out = sqrt(dbl); #if HAVE_ISNAN if (isnan(out)) { - return Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "sqrt(%f)", dbl); + Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t, "sqrt(%f)", dbl); } #endif RFLOAT(out); @@ -517,7 +517,7 @@ eval1(Int fi, Term t USES_REGS) { out = asin(dbl); #if HAVE_ISNAN if (isnan(out)) { - return Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t, "asin(%f)", dbl); + Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t, "asin(%f)", dbl); } #endif RFLOAT(out); @@ -530,7 +530,7 @@ eval1(Int fi, Term t USES_REGS) { out = acos(dbl); #if HAVE_ISNAN if (isnan(out)) { - return Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t, "acos(%f)", dbl); + Yap_ArithError(EVALUATION_ERROR_UNDEFINED, t, "acos(%f)", dbl); } #endif RFLOAT(out); @@ -543,7 +543,7 @@ eval1(Int fi, Term t USES_REGS) { out = atan(dbl); #if HAVE_ISNAN if (isnan(out)) { - return Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "atan(%f)", dbl); + Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "atan(%f)", dbl); } #endif RFLOAT(out); @@ -556,7 +556,7 @@ eval1(Int fi, Term t USES_REGS) { out = asinh(dbl); #if HAVE_ISNAN if (isnan(out)) { - return Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "asinh(%f)", dbl); + Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "asinh(%f)", dbl); } #endif RFLOAT(out); @@ -569,7 +569,7 @@ eval1(Int fi, Term t USES_REGS) { out = acosh(dbl); #if HAVE_ISNAN if (isnan(out)) { - return Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "acosh(%f)", dbl); + Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "acosh(%f)", dbl); } #endif RFLOAT(out); @@ -582,7 +582,7 @@ eval1(Int fi, Term t USES_REGS) { out = atanh(dbl); #if HAVE_ISNAN if (isnan(out)) { - return Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "atanh(%f)", dbl); + Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "atanh(%f)", dbl); } #endif RFLOAT(out); @@ -645,12 +645,12 @@ eval1(Int fi, Term t USES_REGS) { } #if HAVE_ISNAN if (isnan(dbl)) { - return Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "integer(%f)", dbl); + Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "integer(%f)", dbl); } #endif #if HAVE_ISINF if (isinf(dbl)) { - return Yap_ArithError(EVALUATION_ERROR_INT_OVERFLOW, MkFloatTerm(dbl), "integer\ + Yap_ArithError(EVALUATION_ERROR_INT_OVERFLOW, MkFloatTerm(dbl), "integer\ (%f)",dbl); } #endif @@ -674,12 +674,12 @@ eval1(Int fi, Term t USES_REGS) { } #if HAVE_ISNAN if (isnan(dbl)) { - return Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "integer(%f)", dbl); + Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "integer(%f)", dbl); } #endif #if HAVE_ISINF if (isinf(dbl)) { - return Yap_ArithError(EVALUATION_ERROR_INT_OVERFLOW, MkFloatTerm(dbl), "integer\ + Yap_ArithError(EVALUATION_ERROR_INT_OVERFLOW, MkFloatTerm(dbl), "integer\ (%f)",dbl); } #endif @@ -704,12 +704,12 @@ eval1(Int fi, Term t USES_REGS) { } #if HAVE_ISNAN if (isnan(dbl)) { - return Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "integer(%f)", dbl); + Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "integer(%f)", dbl); } #endif #if HAVE_ISINF if (isinf(dbl)) { - return Yap_ArithError(EVALUATION_ERROR_INT_OVERFLOW, MkFloatTerm(dbl), "integer\ + Yap_ArithError(EVALUATION_ERROR_INT_OVERFLOW, MkFloatTerm(dbl), "integer\ (%f)",dbl); } #endif @@ -734,12 +734,12 @@ eval1(Int fi, Term t USES_REGS) { } #if HAVE_ISNAN if (isnan(dbl)) { - return Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "integer(%f)", dbl); + Yap_ArithError(DOMAIN_ERROR_OUT_OF_RANGE, t, "integer(%f)", dbl); } #endif #if HAVE_ISINF if (isinf(dbl)) { - return Yap_ArithError(EVALUATION_ERROR_INT_OVERFLOW, MkFloatTerm(dbl), "integer (%f)",dbl); + Yap_ArithError(EVALUATION_ERROR_INT_OVERFLOW, MkFloatTerm(dbl), "integer (%f)",dbl); } #endif if (dbl < 0.0) @@ -804,7 +804,7 @@ eval1(Int fi, Term t USES_REGS) { case long_int_e: RINT(msb(IntegerOfTerm(t) PASS_REGS)); case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t, "msb(%f)", FloatOfTerm(t)); + Yap_ArithError(TYPE_ERROR_INTEGER, t, "msb(%f)", FloatOfTerm(t)); case big_int_e: #ifdef USE_GMP return Yap_gmp_msb(t); @@ -817,7 +817,7 @@ eval1(Int fi, Term t USES_REGS) { case long_int_e: RINT(lsb(IntegerOfTerm(t) PASS_REGS)); case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t, "lsb(%f)", FloatOfTerm(t)); + Yap_ArithError(TYPE_ERROR_INTEGER, t, "lsb(%f)", FloatOfTerm(t)); case big_int_e: #ifdef USE_GMP return Yap_gmp_lsb(t); @@ -830,7 +830,7 @@ eval1(Int fi, Term t USES_REGS) { case long_int_e: RINT(popcount(IntegerOfTerm(t) PASS_REGS)); case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t, "popcount(%f)", FloatOfTerm(t)); + Yap_ArithError(TYPE_ERROR_INTEGER, t, "popcount(%f)", FloatOfTerm(t)); case big_int_e: #ifdef USE_GMP return Yap_gmp_popcount(t); @@ -842,7 +842,7 @@ eval1(Int fi, Term t USES_REGS) { switch (ETypeOfTerm(t)) { case long_int_e: if (isoLanguageFlag()) { /* iso */ - return Yap_ArithError(TYPE_ERROR_FLOAT, t, "X is float_fractional_part(%f)", IntegerOfTerm(t)); + Yap_ArithError(TYPE_ERROR_FLOAT, t, "X is float_fractional_part(%f)", IntegerOfTerm(t)); } else { RFLOAT(0.0); } @@ -863,7 +863,7 @@ eval1(Int fi, Term t USES_REGS) { case op_fintp: switch (ETypeOfTerm(t)) { case long_int_e: - return Yap_ArithError(TYPE_ERROR_FLOAT, t, "X is float_integer_part(%f)", IntegerOfTerm(t)); + Yap_ArithError(TYPE_ERROR_FLOAT, t, "X is float_integer_part(%f)", IntegerOfTerm(t)); case double_e: RFLOAT(rint(FloatOfTerm(t))); break; @@ -901,7 +901,7 @@ eval1(Int fi, Term t USES_REGS) { case long_int_e: RINT(Yap_random()*IntegerOfTerm(t)); case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t, "random(%f)", FloatOfTerm(t)); + Yap_ArithError(TYPE_ERROR_INTEGER, t, "random(%f)", FloatOfTerm(t)); case big_int_e: #ifdef USE_GMP return Yap_gmp_mul_float_big(Yap_random(), t); diff --git a/C/arith2.c b/C/arith2.c index 4551bf8da..ddce481a5 100644 --- a/C/arith2.c +++ b/C/arith2.c @@ -150,7 +150,7 @@ p_mod(Term t1, Term t2 USES_REGS) { Int mod; if (i2 == 0) - return Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is " Int_FORMAT " mod 0", i1); + Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is " Int_FORMAT " mod 0", i1); if (i1 == Int_MIN && i2 == -1) { return MkIntTerm(0); } @@ -160,7 +160,7 @@ p_mod(Term t1, Term t2 USES_REGS) { RINT(mod); } case (CELL)double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, "mod/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t2, "mod/2"); case (CELL)big_int_e: #ifdef USE_GMP return Yap_gmp_mod_int_big(IntegerOfTerm(t1), t2); @@ -170,7 +170,7 @@ p_mod(Term t1, Term t2 USES_REGS) { break; } case (CELL)double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t1, "mod/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t1, "mod/2"); case (CELL)big_int_e: #ifdef USE_GMP switch (ETypeOfTerm(t2)) { @@ -180,14 +180,14 @@ p_mod(Term t1, Term t2 USES_REGS) { Int i2 = IntegerOfTerm(t2); if (i2 == 0) - return Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is ... mod 0"); + Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is ... mod 0"); return Yap_gmp_mod_big_int(t1, i2); } case (CELL)big_int_e: /* two bignums */ return Yap_gmp_mod_big_big(t1, t2); case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, "mod/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t2, "mod/2"); default: RERROR(); } @@ -210,12 +210,12 @@ p_div2(Term t1, Term t2 USES_REGS) { Int res, mod; if (i2 == 0) - return Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is " Int_FORMAT " div 0", i1); + Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is " Int_FORMAT " div 0", i1); if (i1 == Int_MIN && i2 == -1) { #ifdef USE_GMP return Yap_gmp_add_ints(Int_MAX, 1); #else - return Yap_ArithError(EVALUATION_ERROR_INT_OVERFLOW, t1, + Yap_ArithError(EVALUATION_ERROR_INT_OVERFLOW, t1, "// /2 with %d and %d", i1, i2); #endif } @@ -226,7 +226,7 @@ p_div2(Term t1, Term t2 USES_REGS) { RINT(res); } case (CELL)double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, "div/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t2, "div/2"); case (CELL)big_int_e: #ifdef USE_GMP return Yap_gmp_div_int_big(IntegerOfTerm(t1), t2); @@ -236,7 +236,7 @@ p_div2(Term t1, Term t2 USES_REGS) { break; } case (CELL)double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, "div/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t2, "div/2"); case (CELL)big_int_e: #ifdef USE_GMP switch (ETypeOfTerm(t2)) { @@ -246,14 +246,14 @@ p_div2(Term t1, Term t2 USES_REGS) { Int i2 = IntegerOfTerm(t2); if (i2 == 0) - return Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is ... div 0"); + Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is ... div 0"); return Yap_gmp_div2_big_int(t1, i2); } case (CELL)big_int_e: /* two bignums */ return Yap_gmp_div2_big_big(t1, t2); case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, "div/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t2, "div/2"); default: RERROR(); } @@ -275,14 +275,14 @@ p_rem(Term t1, Term t2 USES_REGS) { Int i2 = IntegerOfTerm(t2); if (i2 == 0) - return Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is " Int_FORMAT " rem 0", i1); + Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is " Int_FORMAT " rem 0", i1); if (i1 == Int_MIN && i2 == -1) { return MkIntTerm(0); } RINT(i1%i2); } case (CELL)double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, "rem/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t2, "rem/2"); case (CELL)big_int_e: #ifdef USE_GMP return Yap_gmp_rem_int_big(IntegerOfTerm(t1), t2); @@ -292,19 +292,19 @@ p_rem(Term t1, Term t2 USES_REGS) { } break; case (CELL)double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t1, "rem/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t1, "rem/2"); case (CELL)big_int_e: #ifdef USE_GMP switch (ETypeOfTerm(t2)) { case long_int_e: if (IntegerOfTerm(t2) == 0) - return Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is ... rem 0"); + Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is ... rem 0"); return Yap_gmp_rem_big_int(t1, IntegerOfTerm(t2)); case (CELL)big_int_e: /* two bignums */ return Yap_gmp_rem_big_big(t1, t2); case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, "rem/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t2, "rem/2"); default: RERROR(); } @@ -320,7 +320,7 @@ p_rdiv(Term t1, Term t2 USES_REGS) { #ifdef USE_GMP switch (ETypeOfTerm(t1)) { case (CELL)double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, "rdiv/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t2, "rdiv/2"); case (CELL)long_int_e: switch (ETypeOfTerm(t2)) { case (CELL)long_int_e: @@ -330,7 +330,7 @@ p_rdiv(Term t1, Term t2 USES_REGS) { Int i2 = IntegerOfTerm(t2); if (i2 == 0) - return Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is " Int_FORMAT " rdiv 0", i1); + Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is " Int_FORMAT " rdiv 0", i1); return Yap_gmq_rdiv_int_int(i1, i2); } case (CELL)big_int_e: @@ -344,13 +344,13 @@ p_rdiv(Term t1, Term t2 USES_REGS) { switch (ETypeOfTerm(t2)) { case long_int_e: if (IntegerOfTerm(t2) == 0) - return Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is ... rdiv 0"); + Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, t2, "X is ... rdiv 0"); /* I know the term is much larger, so: */ return Yap_gmq_rdiv_big_int(t1, IntegerOfTerm(t2)); case (CELL)big_int_e: return Yap_gmq_rdiv_big_big(t1, t2); case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, "rdiv/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t2, "rdiv/2"); default: RERROR(); } @@ -449,7 +449,7 @@ p_xor(Term t1, Term t2 USES_REGS) /* two integers */ RINT(IntegerOfTerm(t1) ^ IntegerOfTerm(t2)); case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, "#/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t2, "#/2"); case big_int_e: #ifdef USE_GMP return Yap_gmp_xor_int_big(IntegerOfTerm(t1), t2); @@ -459,7 +459,7 @@ p_xor(Term t1, Term t2 USES_REGS) } break; case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t1, "#/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t1, "#/2"); case big_int_e: #ifdef USE_GMP switch (ETypeOfTerm(t2)) { @@ -468,7 +468,7 @@ p_xor(Term t1, Term t2 USES_REGS) case big_int_e: return Yap_gmp_xor_big_big(t1, t2); case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, "#/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t2, "#/2"); default: RERROR(); } @@ -690,7 +690,7 @@ p_exp(Term t1, Term t2 USES_REGS) Int pow; if (i2 < 0) { - return Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2, + Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2, "%d ^ %d", i1, i2); } pow = ipow(i1,i2); @@ -836,7 +836,7 @@ p_gcd(Term t1, Term t2 USES_REGS) RINT(gcd(i1,i2 PASS_REGS)); } case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, "gcd/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t2, "gcd/2"); case big_int_e: #ifdef USE_GMP return Yap_gmp_gcd_int_big(IntegerOfTerm(t1), t2); @@ -846,7 +846,7 @@ p_gcd(Term t1, Term t2 USES_REGS) } break; case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t1, "gcd/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t1, "gcd/2"); case big_int_e: #ifdef USE_GMP switch (ETypeOfTerm(t2)) { @@ -855,7 +855,7 @@ p_gcd(Term t1, Term t2 USES_REGS) case big_int_e: return Yap_gmp_gcd_big_big(t1, t2); case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, "gcd/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t2, "gcd/2"); default: RERROR(); } diff --git a/C/atomic.c b/C/atomic.c index 2b274a134..b71049052 100644 --- a/C/atomic.c +++ b/C/atomic.c @@ -68,9 +68,21 @@ static Int hide_atom(USES_REGS1); static Int hidden_atom(USES_REGS1); static Int unhide_atom(USES_REGS1); -#define ReleaseAndReturn(r) { pop_text_stack(l); return r; } -#define release_cut_fail() { pop_text_stack(l); cut_fail(); } -#define release_cut_succeed() { pop_text_stack(l); cut_succeed(); } +#define ReleaseAndReturn(r) \ + { \ + pop_text_stack(l); \ + return r; \ + } +#define release_cut_fail() \ + { \ + pop_text_stack(l); \ + cut_fail(); \ + } +#define release_cut_succeed() \ + { \ + pop_text_stack(l); \ + cut_succeed(); \ + } static int AlreadyHidden(unsigned char *name) { AtomEntry *chain; @@ -240,7 +252,7 @@ static Int char_code(USES_REGS1) { Yap_Error(REPRESENTATION_ERROR_INT, t1, "char_code/2"); return (FALSE); } - size_t n = put_utf8( codes, code); + size_t n = put_utf8(codes, code); codes[n] = code; tout = MkAtomTerm(Yap_ULookupAtom(codes)); } else { @@ -266,7 +278,7 @@ static Int char_code(USES_REGS1) { return FALSE; } tf = MkIntTerm(v); - return Yap_unify(ARG2, tf); + return Yap_unify(ARG2, tf); } } @@ -274,30 +286,30 @@ static Int name(USES_REGS1) { /* name(?Atomic,?String) */ Term t = Deref(ARG2), NewT, AtomNameT = Deref(ARG1); LOCAL_MAX_SIZE = 1024; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: if (Yap_IsGroundTerm(AtomNameT)) { if (!IsVarTerm(t) && !IsPairTerm(t) && t != TermNil) { Yap_Error(TYPE_ERROR_LIST, ARG2, "name/2"); - pop_text_stack( l); - ReleaseAndReturn( FALSE ); + pop_text_stack(l); + ReleaseAndReturn(FALSE); } // verify if an atom, int, float or bi§gnnum NewT = Yap_AtomicToListOfCodes(AtomNameT PASS_REGS); if (NewT) { - pop_text_stack( l); - ReleaseAndReturn( Yap_unify(NewT, ARG2) ); + pop_text_stack(l); + ReleaseAndReturn(Yap_unify(NewT, ARG2)); } // else } else if (IsVarTerm(t)) { Yap_Error(INSTANTIATION_ERROR, t, "name/2"); - pop_text_stack( l); + pop_text_stack(l); return FALSE; } else { Term at = Yap_ListToAtomic(t PASS_REGS); if (at) { - pop_text_stack( l); - ReleaseAndReturn( Yap_unify(at, ARG1) ); + pop_text_stack(l); + ReleaseAndReturn(Yap_unify(at, ARG1)); } } if (LOCAL_Error_TYPE && Yap_HandleError("atom/2")) { @@ -305,30 +317,30 @@ restart_aux: t = Deref(ARG2); goto restart_aux; } - pop_text_stack( l); - ReleaseAndReturn( FALSE ); + pop_text_stack(l); + ReleaseAndReturn(FALSE); } static Int string_to_atomic( USES_REGS1) { /* string_to_atom(?String,?Atom) */ Term t2 = Deref(ARG2), t1 = Deref(ARG1); LOCAL_MAX_SIZE = 1024; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: if (IsStringTerm(t1)) { Term t; // verify if an atom, int, float or bignnum t = Yap_StringToAtomic(t1 PASS_REGS); if (t != 0L) { - pop_text_stack( l); - ReleaseAndReturn( Yap_unify(t, t2) ); + pop_text_stack(l); + ReleaseAndReturn(Yap_unify(t, t2)); } // else } else if (IsVarTerm(t1)) { Term t0 = Yap_AtomicToString(t2 PASS_REGS); if (t0) { - pop_text_stack( l); - ReleaseAndReturn( Yap_unify(t0, t1) ); + pop_text_stack(l); + ReleaseAndReturn(Yap_unify(t0, t1)); } } else { LOCAL_Error_TYPE = TYPE_ERROR_STRING; @@ -338,15 +350,15 @@ restart_aux: t2 = Deref(ARG2); goto restart_aux; } - pop_text_stack( l); - ReleaseAndReturn( FALSE ); + pop_text_stack(l); + ReleaseAndReturn(FALSE); } static Int string_to_atom( USES_REGS1) { /* string_to_atom(?String,?Atom) */ Term t2 = Deref(ARG2), t1 = Deref(ARG1); LOCAL_MAX_SIZE = 1024; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: if (IsStringTerm(t1)) { @@ -354,15 +366,15 @@ restart_aux: // verify if an atom, int, float or bignnum at = Yap_StringSWIToAtom(t1 PASS_REGS); if (at) { - pop_text_stack( l); - ReleaseAndReturn( Yap_unify(MkAtomTerm(at), t2) ); + pop_text_stack(l); + ReleaseAndReturn(Yap_unify(MkAtomTerm(at), t2)); } // else } else if (IsVarTerm(t1)) { Term t0 = Yap_AtomSWIToString(t2 PASS_REGS); if (t0) { - pop_text_stack( l); - ReleaseAndReturn( Yap_unify(t0, t1) ); + pop_text_stack(l); + ReleaseAndReturn(Yap_unify(t0, t1)); } } else { LOCAL_Error_TYPE = TYPE_ERROR_ATOM; @@ -372,26 +384,26 @@ restart_aux: t2 = Deref(ARG2); goto restart_aux; } - pop_text_stack( l); - ReleaseAndReturn( FALSE ); + pop_text_stack(l); + ReleaseAndReturn(FALSE); } static Int string_to_list(USES_REGS1) { Term list = Deref(ARG2), string = Deref(ARG1); LOCAL_MAX_SIZE = 1024; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: if (IsVarTerm(string)) { Term t1 = Yap_ListToString(list PASS_REGS); if (t1) { - pop_text_stack( l); - ReleaseAndReturn( Yap_unify(ARG1, t1) ); + pop_text_stack(l); + ReleaseAndReturn(Yap_unify(ARG1, t1)); } } else if (IsStringTerm(string)) { Term tf = Yap_StringToListOfCodes(string PASS_REGS); - pop_text_stack( l); - ReleaseAndReturn( Yap_unify(ARG2, tf) ); + pop_text_stack(l); + ReleaseAndReturn(Yap_unify(ARG2, tf)); } else { LOCAL_Error_TYPE = TYPE_ERROR_STRING; } @@ -400,14 +412,14 @@ restart_aux: list = Deref(ARG2); goto restart_aux; } - pop_text_stack( l); - ReleaseAndReturn( FALSE ); + pop_text_stack(l); + ReleaseAndReturn(FALSE); } static Int atom_string(USES_REGS1) { Term t1 = Deref(ARG1), t2 = Deref(ARG2); LOCAL_MAX_SIZE = 1024; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: if (IsVarTerm(t1)) { @@ -415,12 +427,12 @@ restart_aux: // verify if an atom, int, float or bignnum at = Yap_StringSWIToAtom(t2 PASS_REGS); if (at) - ReleaseAndReturn( Yap_unify(MkAtomTerm(at), t1) ); + ReleaseAndReturn(Yap_unify(MkAtomTerm(at), t1)); // else } else if (IsAtomTerm(t1)) { Term t0 = Yap_AtomSWIToString(t1 PASS_REGS); if (t0) - ReleaseAndReturn( Yap_unify(t0, t2) ); + ReleaseAndReturn(Yap_unify(t0, t2)); } else { LOCAL_Error_TYPE = TYPE_ERROR_ATOM; } @@ -429,26 +441,26 @@ restart_aux: t2 = Deref(ARG2); goto restart_aux; } - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } static Int atom_chars(USES_REGS1) { Term t1; LOCAL_MAX_SIZE = 1024; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); if (IsAtomTerm(t1)) { Term tf = Yap_AtomSWIToListOfAtoms(t1 PASS_REGS); if (tf) - ReleaseAndReturn( Yap_unify(ARG2, tf) ); + ReleaseAndReturn(Yap_unify(ARG2, tf)); } else if (IsVarTerm(t1)) { /* ARG1 unbound */ Term t = Deref(ARG2); Atom af = Yap_ListOfAtomsToAtom(t PASS_REGS); if (af) - ReleaseAndReturn( Yap_unify(ARG1, MkAtomTerm(af)) ); + ReleaseAndReturn(Yap_unify(ARG1, MkAtomTerm(af))); /* error handling */ } else { LOCAL_Error_TYPE = TYPE_ERROR_ATOM; @@ -456,24 +468,24 @@ restart_aux: if (LOCAL_Error_TYPE && Yap_HandleError("atom_chars/2")) { goto restart_aux; } - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } static Int atom_codes(USES_REGS1) { Term t1; t1 = Deref(ARG1); - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: if (IsAtomTerm(t1)) { Term tf = Yap_AtomToListOfCodes(t1 PASS_REGS); if (tf) - ReleaseAndReturn( Yap_unify(ARG2, tf) ); + ReleaseAndReturn(Yap_unify(ARG2, tf)); } else if (IsVarTerm(t1)) { /* ARG1 unbound */ Term t = Deref(ARG2); Atom af = Yap_ListToAtom(t PASS_REGS); if (af) - ReleaseAndReturn( Yap_unify(ARG1, MkAtomTerm(af)) ); + ReleaseAndReturn(Yap_unify(ARG1, MkAtomTerm(af))); } else if (IsVarTerm(t1)) { LOCAL_Error_TYPE = TYPE_ERROR_ATOM; } @@ -482,24 +494,24 @@ restart_aux: t1 = Deref(ARG1); goto restart_aux; } - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } static Int string_codes(USES_REGS1) { Term t1; t1 = Deref(ARG1); - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: if (IsStringTerm(t1)) { Term tf = Yap_StringSWIToListOfCodes(t1 PASS_REGS); if (tf) - ReleaseAndReturn( Yap_unify(ARG2, tf) ); + ReleaseAndReturn(Yap_unify(ARG2, tf)); } else if (IsVarTerm(t1)) { /* ARG1 unbound */ Term t = Deref(ARG2); Term tf = Yap_ListSWIToString(t PASS_REGS); if (tf) - ReleaseAndReturn( Yap_unify(ARG1, tf) ); + ReleaseAndReturn(Yap_unify(ARG1, tf)); } else { LOCAL_Error_TYPE = TYPE_ERROR_STRING; } @@ -508,24 +520,24 @@ restart_aux: t1 = Deref(ARG1); goto restart_aux; } - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } static Int string_chars(USES_REGS1) { Term t1; t1 = Deref(ARG1); - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: if (IsStringTerm(t1)) { Term tf = Yap_StringSWIToListOfAtoms(t1 PASS_REGS); if (tf) - ReleaseAndReturn( Yap_unify(ARG2, tf) ); + ReleaseAndReturn(Yap_unify(ARG2, tf)); } else if (IsVarTerm(t1)) { /* ARG1 unbound */ Term t = Deref(ARG2); Term tf = Yap_ListSWIToString(t PASS_REGS); if (tf) - ReleaseAndReturn( Yap_unify(ARG1, tf) ); + ReleaseAndReturn(Yap_unify(ARG1, tf)); } else { LOCAL_Error_TYPE = TYPE_ERROR_STRING; } @@ -534,7 +546,7 @@ restart_aux: t1 = Deref(ARG1); goto restart_aux; } - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } /** @pred number_chars(? _I_,? _L_) is iso @@ -547,7 +559,7 @@ characters of the external representation of _I_. */ static Int number_chars(USES_REGS1) { Term t1; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); if (IsNumTerm(t1)) { @@ -556,11 +568,11 @@ restart_aux: t1 = Yap_NumberToListOfAtoms(t1 PASS_REGS); } if (t1) { - ReleaseAndReturn( Yap_unify(t1, t2) ); + ReleaseAndReturn(Yap_unify(t1, t2)); } else { t2 = Yap_ListToNumber(t2 PASS_REGS); if (t2) { - ReleaseAndReturn( Yap_unify(t1, t2) ); + ReleaseAndReturn(Yap_unify(t1, t2)); } } } else if (IsVarTerm(t1)) { @@ -568,7 +580,7 @@ restart_aux: Term t = Deref(ARG2); Term tf = Yap_ListToNumber(t PASS_REGS); if (tf) { - ReleaseAndReturn( Yap_unify(ARG1, tf) ); + ReleaseAndReturn(Yap_unify(ARG1, tf)); } } else if (IsVarTerm(t1)) { LOCAL_Error_TYPE = TYPE_ERROR_NUMBER; @@ -577,12 +589,12 @@ restart_aux: if (LOCAL_Error_TYPE && Yap_HandleError("number_chars/2")) { goto restart_aux; } - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } static Int number_atom(USES_REGS1) { Term t1; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); if (IsNumTerm(t1)) { @@ -592,11 +604,11 @@ restart_aux: if (af) { if (IsVarTerm(t2)) { - ReleaseAndReturn( Yap_unify(t1, t2) ); + ReleaseAndReturn(Yap_unify(t1, t2)); } else { t2 = Yap_AtomToNumber(t2 PASS_REGS); if (t2) { - ReleaseAndReturn( Yap_unify(t1, t2) ); + ReleaseAndReturn(Yap_unify(t1, t2)); } } } @@ -604,32 +616,32 @@ restart_aux: /* ARG1 unbound */ Term t = Deref(ARG2); Term tf = Yap_AtomToNumber(t PASS_REGS); - ReleaseAndReturn( Yap_unify(ARG1, tf) ); + ReleaseAndReturn(Yap_unify(ARG1, tf)); } else if (IsVarTerm(t1)) { LOCAL_Error_TYPE = TYPE_ERROR_NUMBER; } /* error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("number_atom/2")) { goto restart_aux; } - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } static Int number_string(USES_REGS1) { Term t1; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); if (IsNumTerm(t1)) { Term tf; tf = Yap_NumberToString(t1 PASS_REGS); if (tf) - ReleaseAndReturn( Yap_unify(ARG2, tf) ); + ReleaseAndReturn(Yap_unify(ARG2, tf)); } else if (IsVarTerm(t1)) { /* ARG1 unbound */ Term t = Deref(ARG2); Term tf = Yap_StringToNumber(t PASS_REGS); if (tf) - ReleaseAndReturn( Yap_unify(ARG1, tf) ); + ReleaseAndReturn(Yap_unify(ARG1, tf)); } else { LOCAL_Error_TYPE = TYPE_ERROR_NUMBER; } @@ -637,25 +649,25 @@ restart_aux: if (LOCAL_Error_TYPE && Yap_HandleError("number_string/2")) { goto restart_aux; } - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } static Int number_codes(USES_REGS1) { Term t1; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); if (IsNumTerm(t1)) { Term tf; tf = Yap_NumberToListOfCodes(t1 PASS_REGS); if (tf) - ReleaseAndReturn( Yap_unify(ARG2, tf) ); + ReleaseAndReturn(Yap_unify(ARG2, tf)); } else if (IsVarTerm(t1)) { /* ARG1 unbound */ Term t = Deref(ARG2); Term tf = Yap_ListToNumber(t PASS_REGS); if (tf) - ReleaseAndReturn( Yap_unify(ARG1, tf) ); + ReleaseAndReturn(Yap_unify(ARG1, tf)); } else { LOCAL_Error_TYPE = TYPE_ERROR_NUMBER; } @@ -663,14 +675,14 @@ restart_aux: if (LOCAL_Error_TYPE && Yap_HandleError("number_codes/2")) { goto restart_aux; } - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } static Int cont_atom_concat3(USES_REGS1) { Term t3; Atom ats[2]; Int i, max; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t3 = Deref(ARG3); i = IntOfTerm(EXTRA_CBACK_ARG(3, 1)); @@ -681,8 +693,9 @@ restart_aux: release_cut_fail(); } else { if (i < max) { - ReleaseAndReturn( Yap_unify(ARG1, MkAtomTerm(ats[0])) && - Yap_unify(ARG2, MkAtomTerm(ats[1])) ); } + ReleaseAndReturn(Yap_unify(ARG1, MkAtomTerm(ats[0])) && + Yap_unify(ARG2, MkAtomTerm(ats[1]))); + } if (Yap_unify(ARG1, MkAtomTerm(ats[0])) && Yap_unify(ARG2, MkAtomTerm(ats[1]))) release_cut_succeed(); @@ -693,7 +706,7 @@ restart_aux: if (Yap_HandleError("atom_concat/3")) { goto restart_aux; } else { - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } } release_cut_fail(); @@ -704,7 +717,7 @@ static Int atom_concat3(USES_REGS1) { Term t2, t3, ot; Atom at; bool g1, g2, g3; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); t2 = Deref(ARG2); @@ -724,12 +737,12 @@ restart_aux: } else if (g3) { EXTRA_CBACK_ARG(3, 1) = MkIntTerm(0); EXTRA_CBACK_ARG(3, 2) = MkIntTerm(Yap_AtomToLength(t3 PASS_REGS)); - ReleaseAndReturn( cont_atom_concat3(PASS_REGS1) ); + ReleaseAndReturn(cont_atom_concat3(PASS_REGS1)); } else { LOCAL_Error_TYPE = INSTANTIATION_ERROR; at = NULL; } - pop_text_stack( l); + pop_text_stack(l); if (at) { if (Yap_unify(ot, MkAtomTerm(at))) { release_cut_succeed(); @@ -742,7 +755,7 @@ restart_aux: if (Yap_HandleError("atom_concat/3")) { goto restart_aux; } else { - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } } release_cut_fail(); @@ -761,7 +774,7 @@ static Int cont_atomic_concat3(USES_REGS1) { Term t3; Atom ats[2]; size_t i, max; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t3 = Deref(ARG3); i = IntOfTerm(EXTRA_CBACK_ARG(3, 1)); @@ -773,7 +786,7 @@ restart_aux: Term t1 = CastToNumeric(ats[0]); Term t2 = CastToNumeric(ats[1]); if (i < max) - ReleaseAndReturn( Yap_unify(ARG1, t1) && Yap_unify(ARG2, t2) ); + ReleaseAndReturn(Yap_unify(ARG1, t1) && Yap_unify(ARG2, t2)); if (Yap_unify(ARG1, t1) && Yap_unify(ARG2, t2)) release_cut_succeed(); release_cut_fail(); @@ -783,7 +796,7 @@ restart_aux: if (Yap_HandleError("string_concat/3")) { goto restart_aux; } else { - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } } release_cut_fail(); @@ -794,7 +807,7 @@ static Int atomic_concat3(USES_REGS1) { Term t2, t3, ot; Atom at = NULL; bool g1, g2, g3; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); t2 = Deref(ARG2); @@ -841,7 +854,7 @@ static Int cont_string_concat3(USES_REGS1) { Term t3; Term ts[2]; size_t i, max; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t3 = Deref(ARG3); i = IntOfTerm(EXTRA_CBACK_ARG(3, 1)); @@ -873,7 +886,7 @@ static Int string_concat3(USES_REGS1) { Term tf = 0; bool g1, g2, g3; Atom at; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); t2 = Deref(ARG2); @@ -901,7 +914,7 @@ restart_aux: if (tf) { if (Yap_unify(ot, tf)) { release_cut_succeed(); - } else { + } else { release_cut_fail(); } } @@ -910,7 +923,7 @@ restart_aux: if (Yap_HandleError("atom_concat/3")) { goto restart_aux; } else { - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } } release_cut_fail(); @@ -922,7 +935,7 @@ static Int cont_string_code3(USES_REGS1) { utf8proc_int32_t chr; const unsigned char *s; const unsigned char *s0; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t2 = Deref(ARG2); s0 = UStringOfTerm(t2); @@ -934,10 +947,11 @@ restart_aux: if (s[0]) { EXTRA_CBACK_ARG(3, 1) = MkIntTerm(s - s0); EXTRA_CBACK_ARG(3, 2) = MkIntTerm(j + 1); - ReleaseAndReturn( Yap_unify(MkIntegerTerm(chr), ARG3) && - Yap_unify(MkIntegerTerm(j + 1), ARG1) ); + ReleaseAndReturn(Yap_unify(MkIntegerTerm(chr), ARG3) && + Yap_unify(MkIntegerTerm(j + 1), ARG1)); } - if (Yap_unify(MkIntegerTerm(chr), ARG3) && Yap_unify(MkIntegerTerm(j), ARG1)) { + if (Yap_unify(MkIntegerTerm(chr), ARG3) && + Yap_unify(MkIntegerTerm(j), ARG1)) { release_cut_succeed(); } else { release_cut_fail(); @@ -947,7 +961,7 @@ restart_aux: if (Yap_HandleError("string_code/3")) { goto restart_aux; } else { - ReleaseAndReturn( FALSE ) ; + ReleaseAndReturn(FALSE); } } release_cut_fail(); @@ -957,7 +971,7 @@ static Int string_code3(USES_REGS1) { Term t1; Term t2; const unsigned char *s; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); t2 = Deref(ARG2); @@ -1001,7 +1015,7 @@ restart_aux: if (Yap_HandleError("string_code/3")) { goto restart_aux; } else { - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } } release_cut_fail(); @@ -1011,7 +1025,7 @@ static Int get_string_code3(USES_REGS1) { Term t1; Term t2; const unsigned char *s; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); t2 = Deref(ARG2); @@ -1036,20 +1050,20 @@ restart_aux: if (indx < 0) { LOCAL_Error_TYPE = DOMAIN_ERROR_NOT_LESS_THAN_ZERO; } else { - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } } else { indx -= 1; ns = skip_utf8(ns, indx); if (ns == NULL) { - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } else { get_utf8(ns, -1, &chr); if (chr != '\0') - ReleaseAndReturn( Yap_unify(ARG3, MkIntegerTerm(chr)) ); + ReleaseAndReturn(Yap_unify(ARG3, MkIntegerTerm(chr))); } } - ReleaseAndReturn( FALSE ); // replace by error cod )e + ReleaseAndReturn(FALSE); // replace by error cod )e } } /* Error handling */ @@ -1057,7 +1071,7 @@ restart_aux: if (Yap_HandleError("string_code/3")) { goto restart_aux; } else { - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } } release_cut_fail(); @@ -1067,7 +1081,7 @@ static Int atom_concat2(USES_REGS1) { Term t1; Term *tailp; Int n; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); n = Yap_SkipList(&t1, &tailp); @@ -1098,7 +1112,7 @@ restart_aux: free(inpv); at = out.val.a; if (at) - ReleaseAndReturn( Yap_unify(ARG2, MkAtomTerm(at)) ); + ReleaseAndReturn(Yap_unify(ARG2, MkAtomTerm(at))); } error: /* Error handling */ @@ -1106,7 +1120,7 @@ error: if (Yap_HandleError("atom_concat/2")) { goto restart_aux; } else { - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } } release_cut_fail(); @@ -1116,7 +1130,7 @@ static Int string_concat2(USES_REGS1) { Term t1; Term *tailp; Int n; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); n = Yap_SkipList(&t1, &tailp); @@ -1145,7 +1159,7 @@ restart_aux: } free(inpv); if (out.val.t) - ReleaseAndReturn( Yap_unify(ARG2, out.val.t) ); + ReleaseAndReturn(Yap_unify(ARG2, out.val.t)); } error: /* Error handling */ @@ -1153,7 +1167,7 @@ error: if (Yap_HandleError("string_code/3")) { goto restart_aux; } else { - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } } release_cut_fail(); @@ -1163,7 +1177,7 @@ static Int atomic_concat2(USES_REGS1) { Term t1; Term *tailp; Int n; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); n = Yap_SkipList(&t1, &tailp); @@ -1175,7 +1189,7 @@ restart_aux: Atom at; if (n == 1) - ReleaseAndReturn( Yap_unify(ARG2, HeadOfTerm(t1)) ); + ReleaseAndReturn(Yap_unify(ARG2, HeadOfTerm(t1))); if (!inpv) { LOCAL_Error_TYPE = RESOURCE_ERROR_HEAP; free(inpv); @@ -1198,7 +1212,7 @@ restart_aux: free(inpv); at = out.val.a; if (at) - ReleaseAndReturn( Yap_unify(ARG2, MkAtomTerm(at)) ); + ReleaseAndReturn(Yap_unify(ARG2, MkAtomTerm(at))); } error: /* Error handling */ @@ -1212,7 +1226,7 @@ static Int atomics_to_string2(USES_REGS1) { Term t1; Term *tailp; Int n; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); n = Yap_SkipList(&t1, &tailp); @@ -1244,21 +1258,21 @@ restart_aux: free(inpv); at = out.val.a; if (at) - ReleaseAndReturn( Yap_unify(ARG2, MkAtomTerm(at)) ); + ReleaseAndReturn(Yap_unify(ARG2, MkAtomTerm(at))); } error: /* Error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("atomics_to_string/2")) { goto restart_aux; } - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } static Int atomics_to_string3(USES_REGS1) { Term t1, t2; Term *tailp; Int n; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); t2 = Deref(ARG2); @@ -1295,14 +1309,14 @@ restart_aux: free(inpv); at = out.val.a; if (at) - ReleaseAndReturn( Yap_unify(ARG3, MkAtomTerm(at)) ); + ReleaseAndReturn(Yap_unify(ARG3, MkAtomTerm(at))); } error: /* Error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("atomics_to_string/3")) { goto restart_aux; } - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } static Int atom_length(USES_REGS1) { @@ -1310,34 +1324,34 @@ static Int atom_length(USES_REGS1) { Term t2 = Deref(ARG2); size_t len; - int l = push_text_stack( ); + int l = push_text_stack(); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } else if (!IsAtomTerm(t1)) { Yap_Error(TYPE_ERROR_ATOM, t1, "at first argument"); - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } if (Yap_IsGroundTerm(t2)) { if (!IsIntegerTerm(t2)) { Yap_Error(TYPE_ERROR_INTEGER, t2, "atom_length/2"); - ReleaseAndReturn( FALSE); + ReleaseAndReturn(FALSE); } else if ((Int)(len = IntegerOfTerm(t2)) < 0) { Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2, "atom_length/2"); - ReleaseAndReturn( FALSE); + ReleaseAndReturn(FALSE); } } restart_aux: len = Yap_AtomicToLength(t1 PASS_REGS); if (len != (size_t)-1) - ReleaseAndReturn( Yap_unify(ARG2, MkIntegerTerm(len)) ); + ReleaseAndReturn(Yap_unify(ARG2, MkIntegerTerm(len))); /* error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("atom_length/2")) { goto restart_aux; } - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } static Int atomic_length(USES_REGS1) { @@ -1345,31 +1359,31 @@ static Int atomic_length(USES_REGS1) { Term t2 = Deref(ARG2); size_t len; - int l = push_text_stack( ); + int l = push_text_stack(); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - ReleaseAndReturn( FALSE); + ReleaseAndReturn(FALSE); } if (IsNonVarTerm(t2)) { if (!IsIntegerTerm(t2)) { Yap_Error(TYPE_ERROR_INTEGER, t2, "atom_length/2"); - ReleaseAndReturn( FALSE); + ReleaseAndReturn(FALSE); } else if ((Int)(len = IntegerOfTerm(t2)) < 0) { Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2, "atom_length/2"); - ReleaseAndReturn( FALSE); + ReleaseAndReturn(FALSE); } } restart_aux: len = Yap_AtomicToLength(t1 PASS_REGS); if (len != (size_t)-1) - ReleaseAndReturn( Yap_unify(ARG2, MkIntegerTerm(len)) ); + ReleaseAndReturn(Yap_unify(ARG2, MkIntegerTerm(len))); /* error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("atomic_length/2")) { goto restart_aux; } - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } static Int string_length(USES_REGS1) { @@ -1377,28 +1391,28 @@ static Int string_length(USES_REGS1) { Term t2 = Deref(ARG2); size_t len; - int l = push_text_stack( ); + int l = push_text_stack(); if (Yap_IsGroundTerm(t2)) { if (!IsIntegerTerm(t2)) { Yap_Error(TYPE_ERROR_INTEGER, t2, "string_length/2"); - ReleaseAndReturn( FALSE); + ReleaseAndReturn(FALSE); } if (FALSE && (Int)(len = IntegerOfTerm(t2)) < 0) { Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2, "string_length/2"); - ReleaseAndReturn( FALSE); + ReleaseAndReturn(FALSE); } } restart_aux: t1 = Deref(ARG1); len = Yap_AtomicToLength(t1 PASS_REGS); if (len != (size_t)-1) - ReleaseAndReturn( Yap_unify(ARG2, MkIntegerTerm(len)) ); + ReleaseAndReturn(Yap_unify(ARG2, MkIntegerTerm(len))); /* error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("string_length/2")) { goto restart_aux; } - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } /** @pred downcase_text_to_atom(+Text, -Atom) @@ -1411,16 +1425,16 @@ static Int downcase_text_to_atom(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); - int l = push_text_stack( ); + int l = push_text_stack(); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } if (IsNonVarTerm(t2)) { if (!IsAtomTerm(t2)) { Yap_Error(TYPE_ERROR_ATOM, t2, "at second argument"); - ReleaseAndReturn( (FALSE) ); + ReleaseAndReturn((FALSE)); } } while (true) { @@ -1428,11 +1442,11 @@ static Int downcase_text_to_atom(USES_REGS1) { if (at == NULL) { if (LOCAL_Error_TYPE && Yap_HandleError("downcase_text_to_atom/2")) continue; - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } - ReleaseAndReturn( Yap_unify(MkAtomTerm(at), t2) ); + ReleaseAndReturn(Yap_unify(MkAtomTerm(at), t2)); } - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } /** @pred upcase_text_to_atom(+Text, -Atom) @@ -1445,16 +1459,16 @@ static Int upcase_text_to_atom(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); - int l = push_text_stack( ); + int l = push_text_stack(); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } if (IsNonVarTerm(t2)) { if (!IsAtomTerm(t2)) { Yap_Error(TYPE_ERROR_ATOM, t2, "at second argument"); - ReleaseAndReturn( (FALSE) ); + ReleaseAndReturn((FALSE)); } } while (true) { @@ -1462,11 +1476,11 @@ static Int upcase_text_to_atom(USES_REGS1) { if (at == NULL) { if (LOCAL_Error_TYPE && Yap_HandleError("upcase_text_to_atom/2")) continue; - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } - ReleaseAndReturn( Yap_unify(MkAtomTerm(at), t2) ); + ReleaseAndReturn(Yap_unify(MkAtomTerm(at), t2)); } - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } /** @pred downcase_text_to_string(+Text, -String) @@ -1479,16 +1493,16 @@ static Int downcase_text_to_string(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); - int l = push_text_stack( ); + int l = push_text_stack(); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } if (IsNonVarTerm(t2)) { if (!IsStringTerm(t2)) { Yap_Error(TYPE_ERROR_STRING, t2, "at second argument"); - ReleaseAndReturn( (FALSE) ); + ReleaseAndReturn((FALSE)); } } while (true) { @@ -1496,11 +1510,11 @@ static Int downcase_text_to_string(USES_REGS1) { if (t == TermZERO) { if (LOCAL_Error_TYPE && Yap_HandleError("downcase_text_to_string/2")) continue; - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } - ReleaseAndReturn( Yap_unify(t, t2) ); + ReleaseAndReturn(Yap_unify(t, t2)); } - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } /** @pred upcase_text_to_string(+Text, -String) @@ -1513,16 +1527,16 @@ static Int upcase_text_to_string(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); - int l = push_text_stack( ); + int l = push_text_stack(); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } if (IsNonVarTerm(t2)) { if (!IsStringTerm(t2)) { Yap_Error(TYPE_ERROR_STRING, t2, "at second argument"); - ReleaseAndReturn( (FALSE) ); + ReleaseAndReturn((FALSE)); } } while (true) { @@ -1530,11 +1544,11 @@ static Int upcase_text_to_string(USES_REGS1) { if (t == TermZERO) { if (LOCAL_Error_TYPE && Yap_HandleError("upcase_text_to_string/2")) continue; - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } - ReleaseAndReturn( Yap_unify(t, t2) ); + ReleaseAndReturn(Yap_unify(t, t2)); } - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } /** @pred downcase_text_to_codes(+Text, -Codes) @@ -1547,16 +1561,16 @@ static Int downcase_text_to_codes(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); - int l = push_text_stack( ); + int l = push_text_stack(); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } if (IsNonVarTerm(t2)) { if (!Yap_IsListTerm(t2)) { Yap_Error(TYPE_ERROR_LIST, t2, "at second argument"); - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } } while (true) { @@ -1564,11 +1578,11 @@ static Int downcase_text_to_codes(USES_REGS1) { if (t == TermZERO) { if (LOCAL_Error_TYPE && Yap_HandleError("downcase_text_to_codes/2")) continue; - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } - ReleaseAndReturn( Yap_unify(t, t2) ); + ReleaseAndReturn(Yap_unify(t, t2)); } - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } /** @pred upcase_text_to_codes(+Text, -Codes) @@ -1581,16 +1595,16 @@ static Int upcase_text_to_codes(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); - int l = push_text_stack( ); + int l = push_text_stack(); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } if (IsNonVarTerm(t2)) { if (!Yap_IsListTerm(t2)) { Yap_Error(TYPE_ERROR_LIST, t2, "at second argument"); - ReleaseAndReturn( (FALSE) ); + ReleaseAndReturn((FALSE)); } } while (true) { @@ -1598,11 +1612,11 @@ static Int upcase_text_to_codes(USES_REGS1) { if (t == TermZERO) { if (LOCAL_Error_TYPE && Yap_HandleError("upcase_text_to_codes/2")) continue; - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } - ReleaseAndReturn( Yap_unify(t, t2) ); + ReleaseAndReturn(Yap_unify(t, t2)); } - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } /** @pred downcase_text_to_chars(+Text, -Chars) @@ -1615,16 +1629,16 @@ static Int downcase_text_to_chars(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); - int l = push_text_stack( ); + int l = push_text_stack(); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } if (IsNonVarTerm(t2)) { if (!Yap_IsListTerm(t2)) { Yap_Error(TYPE_ERROR_LIST, t2, "at second argument"); - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } } while (true) { @@ -1632,11 +1646,11 @@ static Int downcase_text_to_chars(USES_REGS1) { if (t == TermZERO) { if (LOCAL_Error_TYPE && Yap_HandleError("downcase_text_to_to_chars/2")) continue; - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } - ReleaseAndReturn( Yap_unify(t, t2) ); + ReleaseAndReturn(Yap_unify(t, t2)); } - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } /** @pred upcase_text_to_chars(+Text, -Chars) @@ -1649,16 +1663,16 @@ static Int upcase_text_to_chars(USES_REGS1) { Term t1 = Deref(ARG1); Term t2 = Deref(ARG2); - int l = push_text_stack( ); + int l = push_text_stack(); if (!Yap_IsGroundTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "at first argument"); - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } if (IsNonVarTerm(t2)) { if (!Yap_IsListTerm(t2)) { Yap_Error(TYPE_ERROR_LIST, t2, "at second argument"); - ReleaseAndReturn( (FALSE) ); + ReleaseAndReturn((FALSE)); } } while (true) { @@ -1666,11 +1680,11 @@ static Int upcase_text_to_chars(USES_REGS1) { if (t == TermZERO) { if (LOCAL_Error_TYPE && Yap_HandleError("upcase_text_to_chars/2")) continue; - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } - ReleaseAndReturn( Yap_unify(t, t2) ); + ReleaseAndReturn(Yap_unify(t, t2)); } - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } /* split an atom into two sub-atoms */ @@ -1681,93 +1695,94 @@ static Int atom_split(USES_REGS1) { Term to1, to2; Atom at; - int l = push_text_stack( ); + int l = push_text_stack(); if (IsVarTerm(t1)) { Yap_Error(INSTANTIATION_ERROR, t1, "$atom_split/4"); - ReleaseAndReturn( (FALSE) ); + ReleaseAndReturn((FALSE)); } if (!IsAtomTerm(t1)) { Yap_Error(TYPE_ERROR_ATOM, t1, "$atom_split/4"); - ReleaseAndReturn( (FALSE) ); + ReleaseAndReturn((FALSE)); } if (IsVarTerm(t2)) { Yap_Error(INSTANTIATION_ERROR, t2, "$atom_split/4"); - ReleaseAndReturn( (FALSE) ); + ReleaseAndReturn((FALSE)); } if (!IsIntTerm(t2)) { Yap_Error(TYPE_ERROR_INTEGER, t2, "$atom_split/4"); - ReleaseAndReturn( (FALSE) ); + ReleaseAndReturn((FALSE)); } if ((Int)(len = IntOfTerm(t2)) < 0) { Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2, "$atom_split/4"); - ReleaseAndReturn( (FALSE) ); + ReleaseAndReturn((FALSE)); } at = AtomOfTerm(t1); - unsigned char *s, *s1, *s10; - s = RepAtom(at)->UStrOfAE; - if (len > (Int)strlen_utf8(s)) - ReleaseAndReturn( (FALSE) ); - s1 = s10 = Malloc(len); - if (s1 + len > (unsigned char *)ASP - 1024) - Yap_Error(RESOURCE_ERROR_STACK, t1, "$atom_split/4"); - size_t j; - for (j = 0; j < len; j++) { - int32_t val; - s += get_utf8(s,1,&val); - s1 += put_utf8(s,val); - } - s1[0] = '\0'; - to1 = MkAtomTerm(Yap_ULookupAtom(s10)); - to2 = MkAtomTerm(Yap_ULookupAtom(s)); - ReleaseAndReturn( (Yap_unify_constant(ARG3, to1) && Yap_unify_constant(ARG4, to2)) ); + unsigned char *s, *s1, *s10; + s = RepAtom(at)->UStrOfAE; + if (len > (Int)strlen_utf8(s)) + ReleaseAndReturn((FALSE)); + s1 = s10 = Malloc(len); + if (s1 + len > (unsigned char *)ASP - 1024) + Yap_Error(RESOURCE_ERROR_STACK, t1, "$atom_split/4"); + size_t j; + for (j = 0; j < len; j++) { + int32_t val; + s += get_utf8(s, 1, &val); + s1 += put_utf8(s, val); + } + s1[0] = '\0'; + to1 = MkAtomTerm(Yap_ULookupAtom(s10)); + to2 = MkAtomTerm(Yap_ULookupAtom(s)); + ReleaseAndReturn( + (Yap_unify_constant(ARG3, to1) && Yap_unify_constant(ARG4, to2))); } static Int atom_number(USES_REGS1) { Term t1; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); if (Yap_IsGroundTerm(t1)) { Term tf = Yap_AtomToNumber(t1 PASS_REGS); if (tf) - ReleaseAndReturn( Yap_unify(ARG2, tf) ); + ReleaseAndReturn(Yap_unify(ARG2, tf)); } else { /* ARG1 unbound */ Term t = Deref(ARG2); Atom af = Yap_NumberToAtom(t PASS_REGS); if (af) - ReleaseAndReturn( Yap_unify(ARG1, MkAtomTerm(af)) ); + ReleaseAndReturn(Yap_unify(ARG1, MkAtomTerm(af))); } /* error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("atom_number/2")) { t1 = Deref(ARG1); goto restart_aux; } - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } static Int string_number(USES_REGS1) { Term t1; - int l = push_text_stack( ); + int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); if (Yap_IsGroundTerm(t1)) { Term tf = Yap_StringToNumber(t1 PASS_REGS); if (tf) - ReleaseAndReturn( Yap_unify(ARG2, tf) ); + ReleaseAndReturn(Yap_unify(ARG2, tf)); } else { /* ARG1 unbound */ Term t = Deref(ARG2); Term tf = Yap_NumberToString(t PASS_REGS); if (tf) - ReleaseAndReturn( Yap_unify(ARG1, tf) ); + ReleaseAndReturn(Yap_unify(ARG1, tf)); } /* error handling */ if (LOCAL_Error_TYPE && Yap_HandleError("string_number/2")) { t1 = Deref(ARG1); goto restart_aux; } - ReleaseAndReturn( FALSE ); + ReleaseAndReturn(FALSE); } #define SUB_ATOM_HAS_MIN 1 @@ -1777,89 +1792,85 @@ restart_aux: #define SUB_ATOM_HAS_ATOM 16 #define SUB_ATOM_HAS_UTF8 32 - -static Term build_new_atomic(int mask, wchar_t *wp, const unsigned char *p, size_t minv,size_t len USES_REGS) -{ +static Term build_new_atomic(int mask, wchar_t *wp, const unsigned char *p, + size_t minv, size_t len USES_REGS) { int n; - seq_tv_t outv[5], inp; - size_t cuts[3]; - if (minv) { - cuts[0] = minv; - cuts[1] = minv+len; - cuts[2] = 0; - outv[0].type = 0; - n = 1; - } else { - cuts[0] = minv+len; - cuts[1] = 0; - n = 0; - } + seq_tv_t outv[5], inp; + size_t cuts[3]; + if (minv) { + cuts[0] = minv; + cuts[1] = minv + len; + cuts[2] = 0; + outv[0].type = 0; + n = 1; + } else { + cuts[0] = minv + len; + cuts[1] = 0; + n = 0; + } inp.type = YAP_STRING_CHARS; - inp.enc = ENC_ISO_UTF8; + inp.enc = ENC_ISO_UTF8; inp.val.uc0 = p; - outv[n+1].type = 0; + outv[n + 1].type = 0; if (mask & SUB_ATOM_HAS_ATOM) { outv[n].type = YAP_STRING_ATOM; } else { - outv[n].type = YAP_STRING_STRING; - outv[n].val.c = Malloc(512); + outv[n].type = YAP_STRING_STRING; + outv[n].val.c = Malloc(512); } int lvl = push_text_stack(PASS_REGS1); -bool rc = Yap_Splice_Text(2+n, cuts, &inp, outv PASS_REGS); - pop_text_stack(lvl); - if (!rc) - return( false ); - if (mask & SUB_ATOM_HAS_ATOM) - return( MkAtomTerm(outv[n].val.a) ); - return( outv[n].val.t ); + bool rc = Yap_Splice_Text(2 + n, cuts, &inp, outv PASS_REGS); + pop_text_stack(lvl); + if (!rc) + return (false); + if (mask & SUB_ATOM_HAS_ATOM) + return (MkAtomTerm(outv[n].val.a)); + return (outv[n].val.t); } - static int check_sub_atom_at(int minv, Atom at, Atom nat, size_t len) { - const unsigned char *p1; - const unsigned char *p2 = RepAtom(nat)->UStrOfAE; - p1 = skip_utf8(RepAtom(at)->UStrOfAE, minv); - return cmpn_utf8(p1, p2, len) == 0 ; + const unsigned char *p1; + const unsigned char *p2 = RepAtom(nat)->UStrOfAE; + p1 = skip_utf8(RepAtom(at)->UStrOfAE, minv); + return cmpn_utf8(p1, p2, len) == 0; } static int check_sub_string_at(int minv, const unsigned char *p1, const unsigned char *p2, size_t len) { p1 = skip_utf8((unsigned char *)p1, minv); - if (p1 == NULL || p2 == NULL) - return p1 == p2; + if (p1 == NULL || p2 == NULL) + return p1 == p2; return cmpn_utf8(p1, p2, len) == 0; } - static int check_sub_string_bef(int max, Term at, Term nat) { - size_t len = strlen_utf8(UStringOfTerm(nat)); - int minv = max - len; - const unsigned char *p1, *p2; - int c1; + size_t len = strlen_utf8(UStringOfTerm(nat)); + int minv = max - len; + const unsigned char *p1, *p2; + int c1; - if ((Int)(minv - len) < 0) - return FALSE; + if ((Int)(minv - len) < 0) + return FALSE; - p1 = skip_utf8((unsigned char *)UStringOfTerm(at), minv); - p2 = UStringOfTerm(nat); - while ((c1 = *p1++) == *p2++ && c1) - ; - return c1 == 0; + p1 = skip_utf8((unsigned char *)UStringOfTerm(at), minv); + p2 = UStringOfTerm(nat); + while ((c1 = *p1++) == *p2++ && c1) + ; + return c1 == 0; } - static int check_sub_atom_bef(int max, Atom at, Atom nat) { - const unsigned char *p1, *p2 = RepAtom(nat)->UStrOfAE; - size_t len = strlen_utf8(p2); - int minv = max - len; - int c1; + const unsigned char *p1, *p2 = RepAtom(nat)->UStrOfAE; + size_t len = strlen_utf8(p2); + int minv = max - len; + int c1; - if ((Int)(minv - len) < 0) - return false; - p1 = skip_utf8(RepAtom(at)->UStrOfAE, minv); - while ((c1 = *p1++) == *p2++ && c1) - ; - return c1 == 0; + if ((Int)(minv - len) < 0) + return false; + p1 = skip_utf8(RepAtom(at)->UStrOfAE, minv); + while ((c1 = *p1++) == *p2++ && c1) + ; + return c1 == 0; } static Int cont_sub_atomic(USES_REGS1) { @@ -1869,15 +1880,14 @@ static Int cont_sub_atomic(USES_REGS1) { size_t minv, len, after, sz; wchar_t *wp = NULL; const unsigned char *p = NULL, *p5 = NULL; - Term nat; - - int l = push_text_stack( ); + bool sub_atom = TRUE; + mask = IntegerOfTerm(EXTRA_CBACK_ARG(5, 1)); minv = IntegerOfTerm(EXTRA_CBACK_ARG(5, 2)); len = IntegerOfTerm(EXTRA_CBACK_ARG(5, 3)); after = IntegerOfTerm(EXTRA_CBACK_ARG(5, 4)); sz = IntegerOfTerm(EXTRA_CBACK_ARG(5, 5)); - + if (!IsVarTerm(tat1)) { if (IsAtomTerm(tat1)) { p = AtomOfTerm(tat1)->UStrOfAE; @@ -1893,544 +1903,551 @@ static Int cont_sub_atomic(USES_REGS1) { } } /* we can have one of two cases: A5 bound or unbound */ - if (mask & SUB_ATOM_HAS_VAL) { - int found = FALSE; - nat = Deref(ARG5); - { - const unsigned char *p1 = p; - - while (!found) { - p = skip_utf8(p1, minv); - if (cmpn_utf8(p, p5, len) == 0) { - Yap_unify(ARG2, MkIntegerTerm(minv)); - Yap_unify(ARG3, MkIntegerTerm(len)); - Yap_unify(ARG4, MkIntegerTerm(after)); - found = TRUE; - /* found one, check if there is any left */ - while (minv <= sz - len) { - int chr; - p += get_utf8((unsigned char *)p, -1, &chr); - after--; - minv++; - if (cmpn_utf8(p, UStringOfTerm(nat), len) == 0) - break; - } - } else { - if (minv == sz - len) - break; - after--; - minv++; + if (mask & SUB_ATOM_HAS_VAL) { + bool found = false; + { + const unsigned char *p1 = p; + + while (!found) { + p = skip_utf8(p1, minv); + if (cmpn_utf8(p, p5, len) == 0) { + Yap_unify(ARG2, MkIntegerTerm(minv)); + Yap_unify(ARG3, MkIntegerTerm(len)); + Yap_unify(ARG4, MkIntegerTerm(after)); + found = true; + /* found one, check if there is any left */ + while (minv <= sz - len) { + int chr; + p += get_utf8((unsigned char *)p, -1, &chr); + after--; + minv++; + if (cmpn_utf8(p, p5, len) == 0) + break; + } + } else { + if (minv == sz - len) + break; + after--; + minv++; + } + } } - } - } - if (found) { - if (minv > sz - len) - release_cut_succeed(); + if (found) { + if (minv > sz - len) + cut_succeed(); + } else { + cut_fail(); + } + } else if (mask & SUB_ATOM_HAS_SIZE) { + Term nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); + Yap_unify(ARG2, MkIntegerTerm(minv)); + Yap_unify(ARG4, MkIntegerTerm(after)); + Yap_unify(ARG5, nat); + minv++; + if (after-- == 0) + cut_succeed(); + } else if (mask & SUB_ATOM_HAS_MIN) { + after = sz - (minv + len); + Term nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); + Yap_unify(ARG3, MkIntegerTerm(len)); + Yap_unify(ARG4, MkIntegerTerm(after)); + Yap_unify(ARG5, nat); + len++; + if (after-- == 0) + cut_succeed(); + } else if (mask & SUB_ATOM_HAS_AFTER) { + len = sz - (minv + after); + Term nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); + Yap_unify(ARG2, MkIntegerTerm(minv)); + Yap_unify(ARG3, MkIntegerTerm(len)); + Yap_unify(ARG5, nat); + minv++; + if (len-- == 0) + cut_succeed(); } else { - release_cut_fail(); + Term nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); + Yap_unify(ARG2, MkIntegerTerm(minv)); + Yap_unify(ARG3, MkIntegerTerm(len)); + Yap_unify(ARG4, MkIntegerTerm(after)); + Yap_unify(ARG5, nat); + len++; + if (after-- == 0) { + if (minv == sz) + cut_succeed(); + minv++; + len = 0; + after = sz - minv; + } } - } else if (mask & SUB_ATOM_HAS_SIZE) { - nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); - Yap_unify(ARG2, MkIntegerTerm(minv)); - Yap_unify(ARG4, MkIntegerTerm(after)); - Yap_unify(ARG5, nat); - minv++; - if (after-- == 0) - release_cut_succeed(); - } else if (mask & SUB_ATOM_HAS_MIN) { - after = sz - (minv + len); - nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); - Yap_unify(ARG3, MkIntegerTerm(len)); - Yap_unify(ARG4, MkIntegerTerm(after)); - Yap_unify(ARG5, nat); - len++; - if (after-- == 0) - release_cut_succeed(); - } else if (mask & SUB_ATOM_HAS_AFTER) { - len = sz - (minv + after); - nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); - Yap_unify(ARG2, MkIntegerTerm(minv)); - Yap_unify(ARG3, MkIntegerTerm(len)); - Yap_unify(ARG5, nat); - minv++; - if (len-- == 0) - release_cut_succeed(); - } else { - nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); - Yap_unify(ARG2, MkIntegerTerm(minv)); - Yap_unify(ARG3, MkIntegerTerm(len)); - Yap_unify(ARG4, MkIntegerTerm(after)); - Yap_unify(ARG5, nat); - len++; - if (after-- == 0) { - if (minv == sz) - release_cut_succeed(); - minv++; - len = 0; - after = sz - minv; - } - } - EXTRA_CBACK_ARG(5, 1) = MkIntegerTerm(mask); - EXTRA_CBACK_ARG(5, 2) = MkIntegerTerm(minv); - EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(len); - EXTRA_CBACK_ARG(5, 4) = MkIntegerTerm(after); - EXTRA_CBACK_ARG(5, 5) = MkIntegerTerm(sz); - ReleaseAndReturn( TRUE ); + EXTRA_CBACK_ARG(5, 1) = MkIntegerTerm(mask); + EXTRA_CBACK_ARG(5, 2) = MkIntegerTerm(minv); + EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(len); + EXTRA_CBACK_ARG(5, 4) = MkIntegerTerm(after); + EXTRA_CBACK_ARG(5, 5) = MkIntegerTerm(sz); + return TRUE; } -static Int sub_atomic(bool sub_atom, bool sub_string USES_REGS) { - Term tat1, tbef, tsize, tafter, tout; - int mask = SUB_ATOM_HAS_UTF8; - size_t minv, len, after, sz; - wchar_t *wp = NULL; - const unsigned char *p = NULL; - int bnds = 0; - Term nat = 0L; - Atom at = NULL; - int l = push_text_stack( ); - if (sub_atom) - mask |= SUB_ATOM_HAS_ATOM; + static Int sub_atomic(bool sub_atom, bool sub_string USES_REGS) { + Term tat1, tbef, tsize, tafter, tout; + int mask = SUB_ATOM_HAS_UTF8; + size_t minv, len, after, sz; + wchar_t *wp = NULL; + const unsigned char *p = NULL; + int bnds = 0; + Term nat = 0L; + Atom at = NULL; + int l = push_text_stack(); + if (sub_atom) + mask |= SUB_ATOM_HAS_ATOM; - tat1 = Deref(ARG1); + tat1 = Deref(ARG1); - if (!IsVarTerm(tat1)) { - if (IsAtomTerm(tat1)) { - if (sub_atom) { + if (!IsVarTerm(tat1)) { + if (sub_atom) { + if (IsAtomTerm(tat1)) { p = AtomOfTerm(tat1)->UStrOfAE; sz = strlen_utf8(p); } else { Yap_Error(TYPE_ERROR_ATOM, tat1, "sub_atom/5"); - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } - } else if (IsStringTerm(tat1)) { - if (sub_string) { + } else if (sub_string) { + if (IsStringTerm(tat1)) { p = UStringOfTerm(tat1); sz = strlen_utf8(p); } else { Yap_Error(TYPE_ERROR_STRING, tat1, "sub_atom/5"); - ReleaseAndReturn( false ); + ReleaseAndReturn(false); } } - } else { - Yap_Error(INSTANTIATION_ERROR, tat1, "sub_atom/5: first variable\n"); - ReleaseAndReturn( false ); - } - EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(0); - tbef = Deref(ARG2); - if (IsVarTerm(tbef)) { - minv = 0; - } else if (!IsIntegerTerm(tbef)) { - Yap_Error(TYPE_ERROR_INTEGER, tbef, "sub_string/5"); - ReleaseAndReturn( FALSE ); - } else { - minv = IntegerOfTerm(tbef); - if ((Int)minv < 0) { - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, tbef, "sub_string/5"); - ReleaseAndReturn( FALSE ); - }; - mask |= SUB_ATOM_HAS_MIN; - bnds++; - } - if (IsVarTerm(tsize = Deref(ARG3))) { - len = 0; - } else if (!IsIntegerTerm(tsize)) { - Yap_Error(TYPE_ERROR_INTEGER, tsize, "sub_string/5"); - ReleaseAndReturn( FALSE ); - } else { - len = IntegerOfTerm(tsize); - if ((Int)len < 0) { - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, tsize, "sub_string/5"); - ReleaseAndReturn( FALSE ); - }; - mask |= SUB_ATOM_HAS_SIZE; - bnds++; - } - if (IsVarTerm(tafter = Deref(ARG4))) { - after = 0; - } else if (!IsIntegerTerm(tafter)) { - Yap_Error(TYPE_ERROR_INTEGER, tafter, "sub_string/5"); - ReleaseAndReturn( FALSE ); - } else { - after = IntegerOfTerm(tafter); - if ((Int)after < 0) { - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, tafter, "sub_string/5"); - ReleaseAndReturn( FALSE ); - }; - mask |= SUB_ATOM_HAS_AFTER; - bnds++; - } - if (!IsVarTerm(tout = Deref(ARG5))) { - if (sub_atom) { - if (!IsAtomTerm(tout)) { - Yap_Error(TYPE_ERROR_ATOM, tout, "sub_atom/5"); - ReleaseAndReturn( FALSE ); } else { - Atom oat; - mask |= SUB_ATOM_HAS_VAL | SUB_ATOM_HAS_SIZE; - oat = AtomOfTerm(tout); - len = strlen_utf8(RepAtom(oat)->UStrOfAE); + Yap_Error(INSTANTIATION_ERROR, tat1, "sub_atom/5: first variable\n"); + ReleaseAndReturn(false); } - } else { - if (!IsStringTerm(tout)) { - Yap_Error(TYPE_ERROR_STRING, tout, "sub_string/5"); - ReleaseAndReturn( FALSE ); - } else { - mask |= SUB_ATOM_HAS_VAL | SUB_ATOM_HAS_SIZE; - len = strlen_utf8(UStringOfTerm(tout)); - } - } - if (!Yap_unify(ARG3, MkIntegerTerm(len))) - release_cut_fail(); - bnds += 2; - } - /* the problem is deterministic if we have two cases */ - if (bnds > 1) { - int out = FALSE; - - if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) == - (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) { - if (minv + len > sz) - release_cut_fail(); - if ((Int)(after = (sz - (minv + len))) < 0) - release_cut_fail(); - nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); - if (!nat) - release_cut_fail(); - out = Yap_unify(ARG4, MkIntegerTerm(after)) && Yap_unify(ARG5, nat); - } else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_AFTER)) == - (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_AFTER)) { - if (sz < minv + after) - release_cut_fail(); - len = sz - (minv + after); - nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); - if (!nat) - release_cut_fail(); - out = Yap_unify(ARG3, MkIntegerTerm(len)) && Yap_unify(ARG5, nat); - } else if ((mask & (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_AFTER)) == - (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_AFTER)) { - if (len + after > sz) - release_cut_fail(); - minv = sz - (len + after); - nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); - if (!nat) - release_cut_fail(); - out = Yap_unify(ARG2, MkIntegerTerm(minv)) && Yap_unify(ARG5, nat); - } else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) == - (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) { - if (sub_atom) - out = check_sub_atom_at(minv, at, AtomOfTerm(nat), len); - else - out = check_sub_string_at(minv, p, UStringOfTerm(nat), len); - } else if ((mask & (SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) == - (SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) { - if (sub_atom) - out = check_sub_atom_bef(sz - after, at, AtomOfTerm(nat)); - else - out = check_sub_string_bef(sz - after, tat1, tout); - } else if ((mask & (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_VAL)) == - (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_VAL)) { - if (!sub_atom) { - out = (strlen_utf8(UStringOfTerm(tout)) == len); - if (!out) - release_cut_fail(); - } else { - out = (strlen_utf8(RepAtom(AtomOfTerm(tout))->UStrOfAE) - == len); - if (!out) - release_cut_fail(); - } - if (len == sz) { - out = out && Yap_unify(ARG1, ARG5) && - Yap_unify(ARG2, MkIntegerTerm(0)) && - Yap_unify(ARG4, MkIntegerTerm(0)); - } else if (len > sz) { - release_cut_fail(); - } else { - mask |= SUB_ATOM_HAS_SIZE; + EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(0); + tbef = Deref(ARG2); + if (IsVarTerm(tbef)) { minv = 0; - after = sz - len; - goto backtrackable; - } - } - if (out) - release_cut_succeed(); - release_cut_fail(); - } else { - if (!(mask & SUB_ATOM_HAS_MIN)) - minv = 0; - if (!(mask & SUB_ATOM_HAS_SIZE)) - len = 0; - if (!(mask & SUB_ATOM_HAS_AFTER)) - after = sz - (len + minv); - } -backtrackable: - EXTRA_CBACK_ARG(5, 1) = MkIntegerTerm(mask); - EXTRA_CBACK_ARG(5, 2) = MkIntegerTerm(minv); - EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(len); - EXTRA_CBACK_ARG(5, 4) = MkIntegerTerm(after); - EXTRA_CBACK_ARG(5, 5) = MkIntegerTerm(sz); - ReleaseAndReturn( cont_sub_atomic(PASS_REGS1) ); -} - -/** @pred sub_atom(+ _A_,? _Bef_, ? _Size_, ? _After_, ? _At_out_) is iso - - -True when _A_ and _At_out_ are atoms such that the name of - _At_out_ has size _Size_ and is a sub-string of the name of - _A_, such that _Bef_ is the number of characters before and - _After_ the number of characters afterwards. - -Note that _A_ must always be known, but _At_out_ can be unbound when -calling this built-in. If all the arguments for sub_atom/5 but _A_ -are unbound, the built-in will backtrack through all possible -sub-strings of _A_. - - */ -static Int sub_atom(USES_REGS1) { return( sub_atomic(true, false PASS_REGS) );} - -/** @pred sub_string(+ _S_,? _Bef_, ? _Size_, ? _After_, ? _S_out_) is iso - - -True when _S_ and _S_out_ are strings such that the - _S_out_ has size _Size_ and is a sub-string of - _S_, _Bef_ is the number of characters before, and - _After_ the number of characters afterwards. - -Note that _S_ must always be known, but _S_out_ can be unbound when -calling this built-in. If all the arguments for sub_string/5 but _S_ -are unbound, the built-in will generate all possible -sub-strings of _S_. - - */ -static Int sub_string(USES_REGS1) { return sub_atomic(false, true PASS_REGS); } - -static Int cont_current_atom(USES_REGS1) { - Atom catom; - Int i = IntOfTerm(EXTRA_CBACK_ARG(1, 2)); - AtomEntry *ap; /* nasty hack for gcc on hpux */ - - /* protect current hash table line */ - if (IsAtomTerm(EXTRA_CBACK_ARG(1, 1))) - catom = AtomOfTerm(EXTRA_CBACK_ARG(1, 1)); - else - catom = NIL; - if (catom == NIL) { - i++; - /* move away from current hash table line */ - while (i < AtomHashTableSize) { - READ_LOCK(HashChain[i].AERWLock); - catom = HashChain[i].Entry; - READ_UNLOCK(HashChain[i].AERWLock); - if (catom != NIL) { - break; - } - i++; - } - if (i == AtomHashTableSize) { - cut_fail(); - } - } - ap = RepAtom(catom); - if (Yap_unify_constant(ARG1, MkAtomTerm(catom))) { - READ_LOCK(ap->ARWLock); - if (ap->NextOfAE == NIL) { - READ_UNLOCK(ap->ARWLock); - i++; - while (i < AtomHashTableSize) { - READ_LOCK(HashChain[i].AERWLock); - catom = HashChain[i].Entry; - READ_UNLOCK(HashChain[i].AERWLock); - if (catom != NIL) { - break; - } - i++; - } - if (i == AtomHashTableSize) { - cut_fail(); + } else if (!IsIntegerTerm(tbef)) { + Yap_Error(TYPE_ERROR_INTEGER, tbef, "sub_string/5"); + ReleaseAndReturn(FALSE); } else { - EXTRA_CBACK_ARG(1, 1) = MkAtomTerm(catom); + minv = IntegerOfTerm(tbef); + if ((Int)minv < 0) { + Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, tbef, "sub_string/5"); + ReleaseAndReturn(FALSE); + }; + mask |= SUB_ATOM_HAS_MIN; + bnds++; } - } else { - EXTRA_CBACK_ARG(1, 1) = MkAtomTerm(ap->NextOfAE); - READ_UNLOCK(ap->ARWLock); + if (IsVarTerm(tsize = Deref(ARG3))) { + len = 0; + } else if (!IsIntegerTerm(tsize)) { + Yap_Error(TYPE_ERROR_INTEGER, tsize, "sub_string/5"); + ReleaseAndReturn(FALSE); + } else { + len = IntegerOfTerm(tsize); + if ((Int)len < 0) { + Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, tsize, "sub_string/5"); + ReleaseAndReturn(FALSE); + }; + mask |= SUB_ATOM_HAS_SIZE; + bnds++; + } + if (IsVarTerm(tafter = Deref(ARG4))) { + after = 0; + } else if (!IsIntegerTerm(tafter)) { + Yap_Error(TYPE_ERROR_INTEGER, tafter, "sub_string/5"); + ReleaseAndReturn(FALSE); + } else { + after = IntegerOfTerm(tafter); + if ((Int)after < 0) { + Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, tafter, "sub_string/5"); + ReleaseAndReturn(FALSE); + }; + mask |= SUB_ATOM_HAS_AFTER; + bnds++; + } + if (!IsVarTerm(tout = Deref(ARG5))) { + if (sub_atom) { + if (!IsAtomTerm(tout)) { + Yap_Error(TYPE_ERROR_ATOM, tout, "sub_atom/5"); + ReleaseAndReturn(FALSE); + } else { + Atom oat; + mask |= SUB_ATOM_HAS_VAL | SUB_ATOM_HAS_SIZE; + oat = AtomOfTerm(tout); + len = strlen_utf8(RepAtom(oat)->UStrOfAE); + } + } else { + if (!IsStringTerm(tout)) { + Yap_Error(TYPE_ERROR_STRING, tout, "sub_string/5"); + ReleaseAndReturn(FALSE); + } else { + mask |= SUB_ATOM_HAS_VAL | SUB_ATOM_HAS_SIZE; + len = strlen_utf8(UStringOfTerm(tout)); + } + } + if (!Yap_unify(ARG3, MkIntegerTerm(len))) + release_cut_fail(); + bnds += 2; + } + /* the problem is deterministic if we have two cases */ + if (bnds > 1) { + int out = FALSE; + + if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) == + (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) { + if (minv + len > sz) + release_cut_fail(); + if ((Int)(after = (sz - (minv + len))) < 0) + release_cut_fail(); + nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); + if (!nat) + release_cut_fail(); + out = Yap_unify(ARG4, MkIntegerTerm(after)) && Yap_unify(ARG5, nat); + } else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_AFTER)) == + (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_AFTER)) { + if (sz < minv + after) + release_cut_fail(); + len = sz - (minv + after); + nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); + if (!nat) + release_cut_fail(); + out = Yap_unify(ARG3, MkIntegerTerm(len)) && Yap_unify(ARG5, nat); + } else if ((mask & (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_AFTER)) == + (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_AFTER)) { + if (len + after > sz) + release_cut_fail(); + minv = sz - (len + after); + nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); + if (!nat) + release_cut_fail(); + out = Yap_unify(ARG2, MkIntegerTerm(minv)) && Yap_unify(ARG5, nat); + } else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) == + (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) { + if (sub_atom) + out = check_sub_atom_at(minv, at, AtomOfTerm(nat), len); + else + out = check_sub_string_at(minv, p, UStringOfTerm(nat), len); + } else if ((mask & (SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) == + (SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) { + if (sub_atom) + out = check_sub_atom_bef(sz - after, at, AtomOfTerm(nat)); + else + out = check_sub_string_bef(sz - after, tat1, tout); + } else if ((mask & (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_VAL)) == + (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_VAL)) { + if (!sub_atom) { + out = (strlen_utf8(UStringOfTerm(tout)) == len); + if (!out) + release_cut_fail(); + } else { + out = (strlen_utf8(RepAtom(AtomOfTerm(tout))->UStrOfAE) == len); + if (!out) + release_cut_fail(); + } + if (len == sz) { + out = out && Yap_unify(ARG1, ARG5) && + Yap_unify(ARG2, MkIntegerTerm(0)) && + Yap_unify(ARG4, MkIntegerTerm(0)); + } else if (len > sz) { + release_cut_fail(); + } else { + mask |= SUB_ATOM_HAS_SIZE; + minv = 0; + after = sz - len; + goto backtrackable; + } + } + if (out) + release_cut_succeed(); + release_cut_fail(); + } else { + if (!(mask & SUB_ATOM_HAS_MIN)) + minv = 0; + if (!(mask & SUB_ATOM_HAS_SIZE)) + len = 0; + if (!(mask & SUB_ATOM_HAS_AFTER)) + after = sz - (len + minv); + } + backtrackable: + EXTRA_CBACK_ARG(5, 1) = MkIntegerTerm(mask); + EXTRA_CBACK_ARG(5, 2) = MkIntegerTerm(minv); + EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(len); + EXTRA_CBACK_ARG(5, 4) = MkIntegerTerm(after); + EXTRA_CBACK_ARG(5, 5) = MkIntegerTerm(sz); + ReleaseAndReturn(cont_sub_atomic(PASS_REGS1)); } - EXTRA_CBACK_ARG(1, 2) = MkIntTerm(i); - return( TRUE ); - } else { - return( FALSE ); - } -} -static Int current_atom(USES_REGS1) { /* current_atom(?Atom) */ - Term t1 = Deref(ARG1); - if (!IsVarTerm(t1)) { - if (IsAtomTerm(t1)) - cut_succeed(); - else - cut_fail(); - } - READ_LOCK(HashChain[0].AERWLock); - if (HashChain[0].Entry != NIL) { - EXTRA_CBACK_ARG(1, 1) = MkAtomTerm(HashChain[0].Entry); - } else { - EXTRA_CBACK_ARG(1, 1) = MkIntTerm(0); - } - READ_UNLOCK(HashChain[0].AERWLock); - EXTRA_CBACK_ARG(1, 2) = MkIntTerm(0); - return (cont_current_atom(PASS_REGS1)); -} - -void Yap_InitBackAtoms(void) { - Yap_InitCPredBack("$current_atom", 1, 2, current_atom, cont_current_atom, - SafePredFlag | SyncPredFlag); - Yap_InitCPredBack("atom_concat", 3, 2, atom_concat3, cont_atom_concat3, 0); - Yap_InitCPredBack("atomic_concat", 3, 2, atomic_concat3, cont_atomic_concat3, - 0); - Yap_InitCPredBack("string_concat", 3, 2, string_concat3, cont_string_concat3, - 0); - Yap_InitCPredBack("sub_atom", 5, 5, sub_atom, cont_sub_atomic, 0); - Yap_InitCPredBack("sub_string", 5, 5, sub_string, cont_sub_atomic, 0); - Yap_InitCPredBack("string_code", 3, 1, string_code3, cont_string_code3, 0); -} - -void Yap_InitAtomPreds(void) { - Yap_InitCPred("name", 2, name, 0); - /** @pred name( _A_, _L_) + /** @pred sub_atom(+ _A_,? _Bef_, ? _Size_, ? _After_, ? _At_out_) is iso - The predicate holds when at least one of the arguments is ground - (otherwise, an error message will be displayed). The argument _A_ will - be unified with an atomic symbol and _L_ with the list of the ASCII - codes for the characters of the external representation of _A_. + True when _A_ and _At_out_ are atoms such that the name of + _At_out_ has size _Size_ and is a sub-string of the name of + _A_, such that _Bef_ is the number of characters before and + _After_ the number of characters afterwards. - ~~~~~{.prolog} - name(yap,L). - ~~~~~ - will return: + Note that _A_ must always be known, but _At_out_ can be unbound when + calling this built-in. If all the arguments for sub_atom/5 but _A_ + are unbound, the built-in will backtrack through all possible + sub-strings of _A_. - ~~~~~{.prolog} - L = [121,97,112]. - ~~~~~ - and + */ + static Int sub_atom(USES_REGS1) { + return (sub_atomic(true, false PASS_REGS)); + } - ~~~~~{.prolog} - name(3,L). - ~~~~~ - will return: - - ~~~~~{.prolog} - L = [51]. - ~~~~~ + /** @pred sub_string(+ _S_,? _Bef_, ? _Size_, ? _After_, ? _S_out_) is + iso + True when _S_ and _S_out_ are strings such that the + _S_out_ has size _Size_ and is a sub-string of + _S_, _Bef_ is the number of characters before, and + _After_ the number of characters afterwards. + + Note that _S_ must always be known, but _S_out_ can be unbound when + calling this built-in. If all the arguments for sub_string/5 but _S_ + are unbound, the built-in will generate all possible + sub-strings of _S_. + + */ + static Int sub_string(USES_REGS1) { + return sub_atomic(false, true PASS_REGS); + } + + static Int cont_current_atom(USES_REGS1) { + Atom catom; + Int i = IntOfTerm(EXTRA_CBACK_ARG(1, 2)); + AtomEntry *ap; /* nasty hack for gcc on hpux */ + + /* protect current hash table line */ + if (IsAtomTerm(EXTRA_CBACK_ARG(1, 1))) + catom = AtomOfTerm(EXTRA_CBACK_ARG(1, 1)); + else + catom = NIL; + if (catom == NIL) { + i++; + /* move away from current hash table line */ + while (i < AtomHashTableSize) { + READ_LOCK(HashChain[i].AERWLock); + catom = HashChain[i].Entry; + READ_UNLOCK(HashChain[i].AERWLock); + if (catom != NIL) { + break; + } + i++; + } + if (i == AtomHashTableSize) { + cut_fail(); + } + } + ap = RepAtom(catom); + if (Yap_unify_constant(ARG1, MkAtomTerm(catom))) { + READ_LOCK(ap->ARWLock); + if (ap->NextOfAE == NIL) { + READ_UNLOCK(ap->ARWLock); + i++; + while (i < AtomHashTableSize) { + READ_LOCK(HashChain[i].AERWLock); + catom = HashChain[i].Entry; + READ_UNLOCK(HashChain[i].AERWLock); + if (catom != NIL) { + break; + } + i++; + } + if (i == AtomHashTableSize) { + cut_fail(); + } else { + EXTRA_CBACK_ARG(1, 1) = MkAtomTerm(catom); + } + } else { + EXTRA_CBACK_ARG(1, 1) = MkAtomTerm(ap->NextOfAE); + READ_UNLOCK(ap->ARWLock); + } + EXTRA_CBACK_ARG(1, 2) = MkIntTerm(i); + return (TRUE); + } else { + return (FALSE); + } + } + + static Int current_atom(USES_REGS1) { /* current_atom(?Atom) + */ + Term t1 = Deref(ARG1); + if (!IsVarTerm(t1)) { + if (IsAtomTerm(t1)) + cut_succeed(); + else + cut_fail(); + } + READ_LOCK(HashChain[0].AERWLock); + if (HashChain[0].Entry != NIL) { + EXTRA_CBACK_ARG(1, 1) = MkAtomTerm(HashChain[0].Entry); + } else { + EXTRA_CBACK_ARG(1, 1) = MkIntTerm(0); + } + READ_UNLOCK(HashChain[0].AERWLock); + EXTRA_CBACK_ARG(1, 2) = MkIntTerm(0); + return (cont_current_atom(PASS_REGS1)); + } + + void Yap_InitBackAtoms(void) { + Yap_InitCPredBack("$current_atom", 1, 2, current_atom, cont_current_atom, + SafePredFlag | SyncPredFlag); + Yap_InitCPredBack("atom_concat", 3, 2, atom_concat3, cont_atom_concat3, + 0); + Yap_InitCPredBack("atomic_concat", 3, 2, atomic_concat3, + cont_atomic_concat3, 0); + Yap_InitCPredBack("string_concat", 3, 2, string_concat3, + cont_string_concat3, 0); + Yap_InitCPredBack("sub_atom", 5, 5, sub_atom, cont_sub_atomic, 0); + Yap_InitCPredBack("sub_string", 5, 5, sub_string, cont_sub_atomic, 0); + Yap_InitCPredBack("string_code", 3, 1, string_code3, cont_string_code3, + 0); + } + + void Yap_InitAtomPreds(void) { + Yap_InitCPred("name", 2, name, 0); + /** @pred name( _A_, _L_) + + + The predicate holds when at least one of the arguments is ground + (otherwise, an error message will be displayed). The argument _A_ will + be unified with an atomic symbol and _L_ with the list of the ASCII + codes for the characters of the external representation of _A_. + + ~~~~~{.prolog} + name(yap,L). + ~~~~~ + will return: + + ~~~~~{.prolog} + L = [121,97,112]. + ~~~~~ + and + + ~~~~~{.prolog} + name(3,L). + ~~~~~ + will return: + + ~~~~~{.prolog} + L = [51]. + ~~~~~ + + + */ + Yap_InitCPred("string_to_atom", 2, string_to_atom, 0); + Yap_InitCPred("atom_string", 2, atom_string, 0); + Yap_InitCPred("string_to_atomic", 2, string_to_atomic, 0); + Yap_InitCPred("string_to_list", 2, string_to_list, 0); + Yap_InitCPred("char_code", 2, char_code, SafePredFlag); + /** @pred char_code(? _A_,? _I_) is iso + + + The built-in succeeds with _A_ bound to character represented as an + atom, and _I_ bound to the character code represented as an + integer. At least, one of either _A_ or _I_ must be bound before + the call. + + + */ + Yap_InitCPred("atom_chars", 2, atom_chars, 0); + /** @pred atom_chars(? _A_,? _L_) is iso + + + The predicate holds when at least one of the arguments is ground + (otherwise, an error message will be displayed). The argument _A_ must + be unifiable with an atom, and the argument _L_ with the list of the + characters of _A_. + + + */ + Yap_InitCPred("atom_codes", 2, atom_codes, 0); + Yap_InitCPred("string_codes", 2, string_codes, 0); + Yap_InitCPred("string_chars", 2, string_chars, 0); + Yap_InitCPred("atom_length", 2, atom_length, SafePredFlag); + /** @pred atom_length(+ _A_,? _I_) is iso + + + The predicate holds when the first argument is an atom, and the second + unifies with the number of characters forming that atom. + + + */ + Yap_InitCPred("atomic_length", 2, atomic_length, SafePredFlag); + Yap_InitCPred("string_length", 2, string_length, SafePredFlag); + Yap_InitCPred("$atom_split", 4, atom_split, SafePredFlag); + Yap_InitCPred("number_chars", 2, number_chars, 0); + Yap_InitCPred("number_atom", 2, number_atom, 0); + /** @pred number_atom(? _I_,? _L_) + + + + The predicate holds when at least one of the arguments is ground + (otherwise, an error message will be displayed). The argument _I_ must + be unifiable with a number, and the argument _L_ must be unifiable + with an atom representing the number. + + + */ + Yap_InitCPred("number_string", 2, number_string, 0); + Yap_InitCPred("number_codes", 2, number_codes, 0); + Yap_InitCPred("atom_number", 2, atom_number, 0); + /** @pred atom_number(? _Atom_,? _Number_) + + + The predicate holds when at least one of the arguments is ground + (otherwise, an error message will be displayed). If the argument + _Atom_ is an atom, _Number_ must be the number corresponding + to the characters in _Atom_, otherwise the characters in + _Atom_ must encode a number _Number_. + + + */ + Yap_InitCPred("string_number", 2, string_number, 0); + Yap_InitCPred("$atom_concat", 2, atom_concat2, 0); + Yap_InitCPred("$string_concat", 2, string_concat2, 0); + Yap_InitCPred("atomic_concat", 2, atomic_concat2, 0); + /** @pred atomic_concat(+ _As_,? _A_) + + + The predicate holds when the first argument is a list of atomic terms, + and + the second unifies with the atom obtained by concatenating all the + atomic terms in the first list. The first argument thus may contain + atoms or numbers. + + + */ + Yap_InitCPred("atomics_to_string", 2, atomics_to_string2, 0); + Yap_InitCPred("atomics_to_string", 3, atomics_to_string3, 0); + Yap_InitCPred("get_string_code", 3, get_string_code3, 0); + + Yap_InitCPred("downcase_text_to_atom", 2, downcase_text_to_atom, 0); + Yap_InitCPred("downcase_atom", 2, downcase_text_to_atom, 0); + Yap_InitCPred("upcase_text_to_atom", 2, upcase_text_to_atom, 0); + Yap_InitCPred("upcase_atom", 2, upcase_text_to_atom, 0); + Yap_InitCPred("downcase_text_to_string", 2, downcase_text_to_string, 0); + Yap_InitCPred("upcase_text_to_string", 2, upcase_text_to_string, 0); + Yap_InitCPred("downcase_text_to_codes", 2, downcase_text_to_codes, 0); + Yap_InitCPred("upcase_text_to_codes", 2, upcase_text_to_codes, 0); + Yap_InitCPred("downcase_text_to_chars", 2, downcase_text_to_chars, 0); + Yap_InitCPred("upcase_text_to_chars", 2, upcase_text_to_chars, 0); + + /* hiding and unhiding some predicates */ + Yap_InitCPred("hide_atom", 1, hide_atom, SafePredFlag | SyncPredFlag); + Yap_InitCPred("hide", 1, hide_atom, SafePredFlag | SyncPredFlag); + Yap_InitCPred("unhide_atom", 1, unhide_atom, SafePredFlag | SyncPredFlag); + Yap_InitCPred("$hidden_atom", 1, hidden_atom, + HiddenPredFlag | SafePredFlag | SyncPredFlag); + } + + /** + @} */ - Yap_InitCPred("string_to_atom", 2, string_to_atom, 0); - Yap_InitCPred("atom_string", 2, atom_string, 0); - Yap_InitCPred("string_to_atomic", 2, string_to_atomic, 0); - Yap_InitCPred("string_to_list", 2, string_to_list, 0); - Yap_InitCPred("char_code", 2, char_code, SafePredFlag); - /** @pred char_code(? _A_,? _I_) is iso - - - The built-in succeeds with _A_ bound to character represented as an - atom, and _I_ bound to the character code represented as an - integer. At least, one of either _A_ or _I_ must be bound before - the call. - - - */ - Yap_InitCPred("atom_chars", 2, atom_chars, 0); - /** @pred atom_chars(? _A_,? _L_) is iso - - - The predicate holds when at least one of the arguments is ground - (otherwise, an error message will be displayed). The argument _A_ must - be unifiable with an atom, and the argument _L_ with the list of the - characters of _A_. - - - */ - Yap_InitCPred("atom_codes", 2, atom_codes, 0); - Yap_InitCPred("string_codes", 2, string_codes, 0); - Yap_InitCPred("string_chars", 2, string_chars, 0); - Yap_InitCPred("atom_length", 2, atom_length, SafePredFlag); - /** @pred atom_length(+ _A_,? _I_) is iso - - - The predicate holds when the first argument is an atom, and the second - unifies with the number of characters forming that atom. - - - */ - Yap_InitCPred("atomic_length", 2, atomic_length, SafePredFlag); - Yap_InitCPred("string_length", 2, string_length, SafePredFlag); - Yap_InitCPred("$atom_split", 4, atom_split, SafePredFlag); - Yap_InitCPred("number_chars", 2, number_chars, 0); - Yap_InitCPred("number_atom", 2, number_atom, 0); - /** @pred number_atom(? _I_,? _L_) - - - - The predicate holds when at least one of the arguments is ground - (otherwise, an error message will be displayed). The argument _I_ must - be unifiable with a number, and the argument _L_ must be unifiable - with an atom representing the number. - - - */ - Yap_InitCPred("number_string", 2, number_string, 0); - Yap_InitCPred("number_codes", 2, number_codes, 0); - Yap_InitCPred("atom_number", 2, atom_number, 0); - /** @pred atom_number(? _Atom_,? _Number_) - - - The predicate holds when at least one of the arguments is ground - (otherwise, an error message will be displayed). If the argument - _Atom_ is an atom, _Number_ must be the number corresponding - to the characters in _Atom_, otherwise the characters in - _Atom_ must encode a number _Number_. - - - */ - Yap_InitCPred("string_number", 2, string_number, 0); - Yap_InitCPred("$atom_concat", 2, atom_concat2, 0); - Yap_InitCPred("$string_concat", 2, string_concat2, 0); - Yap_InitCPred("atomic_concat", 2, atomic_concat2, 0); - /** @pred atomic_concat(+ _As_,? _A_) - - - The predicate holds when the first argument is a list of atomic terms, and - the second unifies with the atom obtained by concatenating all the - atomic terms in the first list. The first argument thus may contain - atoms or numbers. - - - */ - Yap_InitCPred("atomics_to_string", 2, atomics_to_string2, 0); - Yap_InitCPred("atomics_to_string", 3, atomics_to_string3, 0); - Yap_InitCPred("get_string_code", 3, get_string_code3, 0); - - Yap_InitCPred("downcase_text_to_atom", 2, downcase_text_to_atom, 0); - Yap_InitCPred("downcase_atom", 2, downcase_text_to_atom, 0); - Yap_InitCPred("upcase_text_to_atom", 2, upcase_text_to_atom, 0); - Yap_InitCPred("upcase_atom", 2, upcase_text_to_atom, 0); - Yap_InitCPred("downcase_text_to_string", 2, downcase_text_to_string, 0); - Yap_InitCPred("upcase_text_to_string", 2, upcase_text_to_string, 0); - Yap_InitCPred("downcase_text_to_codes", 2, downcase_text_to_codes, 0); - Yap_InitCPred("upcase_text_to_codes", 2, upcase_text_to_codes, 0); - Yap_InitCPred("downcase_text_to_chars", 2, downcase_text_to_chars, 0); - Yap_InitCPred("upcase_text_to_chars", 2, upcase_text_to_chars, 0); - - /* hiding and unhiding some predicates */ - Yap_InitCPred("hide_atom", 1, hide_atom, SafePredFlag | SyncPredFlag); - Yap_InitCPred("hide", 1, hide_atom, SafePredFlag | SyncPredFlag); - Yap_InitCPred("unhide_atom", 1, unhide_atom, SafePredFlag | SyncPredFlag); - Yap_InitCPred("$hidden_atom", 1, hidden_atom, - HiddenPredFlag | SafePredFlag | SyncPredFlag); -} - -/** -@} -*/ diff --git a/C/cdmgr.c b/C/cdmgr.c index 892459b53..858e304be 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -1453,6 +1453,8 @@ static void addcl_permission_error(AtomEntry *ap, Int Arity, int in_use) { ti[1] = MkIntegerTerm(Arity); t = Yap_MkApplTerm(FunctorSlash, 2, ti); LOCAL_Error_TYPE = PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE; + LOCAL_ErrorMessage = Malloc( 256 ); + if (in_use) { if (Arity == 0) sprintf(LOCAL_ErrorMessage, "static predicate %s is in use", ap->StrOfAE); diff --git a/C/cmppreds.c b/C/cmppreds.c index d650e4410..093412031 100644 --- a/C/cmppreds.c +++ b/C/cmppreds.c @@ -379,7 +379,6 @@ inline static Int compare(Term t1, Term t2) /* compare terms t1 and t2 */ if (IsExtensionFunctor(f)) return 1; else { - int out; if (f != FunctorDot) return strcmp(".", RepAtom(NameOfFunctor(f))->StrOfAE); else { @@ -596,10 +595,10 @@ inline static Int flt_cmp(Float dif) { static Int a_cmp(Term t1, Term t2 USES_REGS) { if (IsVarTerm(t1)) { - Yap_ThrowError( INSTANTIATION_ERROR, t1, "while doing arithmetic comparison" ); + Yap_ThrowError( INSTANTIATION_ERROR, t1, 4, "while doing arithmetic comparison" ); } if (IsVarTerm(t2)) { - Yap_ThrowError( INSTANTIATION_ERROR, t1, "while doing arithmetic comparison" ); + Yap_ThrowError( INSTANTIATION_ERROR, t1, 4, "while doing arithmetic comparison" ); } if (IsFloatTerm(t1) && IsFloatTerm(t2)) { return flt_cmp(FloatOfTerm(t1) - FloatOfTerm(t2)); @@ -622,7 +621,7 @@ static Int a_cmp(Term t1, Term t2 USES_REGS) { Float f2 = FloatOfTerm(t2); #if HAVE_ISNAN if (isnan(f2)) { - Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t2, "trying to evaluate nan" ); + Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t2, 4, "trying to evaluate nan" ); } #endif return flt_cmp(i1 - f2); @@ -637,7 +636,7 @@ static Int a_cmp(Term t1, Term t2 USES_REGS) { Float f1 = FloatOfTerm(t1); #if HAVE_ISNAN if (isnan(f1)) { - Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t1, "trying to evaluate nan" ); + Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t1, 4, "trying to evaluate nan" ); } #endif t2 = Yap_Eval(t2); @@ -653,7 +652,7 @@ static Int a_cmp(Term t1, Term t2 USES_REGS) { Float f2 = FloatOfTerm(t2); #if HAVE_ISNAN if (isnan(f2)) { - Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t2, "trying to evaluate nan" ); + Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t2, 4, "trying to evaluate nan" ); } #endif return flt_cmp(f1 - f2); @@ -675,7 +674,7 @@ static Int a_cmp(Term t1, Term t2 USES_REGS) { Float f2 = FloatOfTerm(t2); #if HAVE_ISNAN if (isnan(f2)) { - Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t2, "trying to evaluate nan" ); + Yap_ThrowError( EVALUATION_ERROR_UNDEFINED, t2, 4, "trying to evaluate nan" ); } #endif return Yap_gmp_cmp_big_float(t1, f2); diff --git a/C/compiler.c b/C/compiler.c index 29735c82e..77d8906a3 100644 --- a/C/compiler.c +++ b/C/compiler.c @@ -1103,16 +1103,14 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Int i2; if (!IsIntegerTerm(t2)) { - char s[32]; - Yap_ThrowError( TYPE_ERROR_INTEGER, t2, "compiling functor/3"); + Yap_Error( TYPE_ERROR_INTEGER, t2, "compiling functor/3"); save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, 1); } i2 = IntegerOfTerm(t2); if (i2 < 0) { - char s[32]; - Yap_ThrowError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO , t2, "compiling functor/3"); + Yap_ThrowError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO , t2,4, "compiling functor/3"); save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, 1); } diff --git a/C/errors.c b/C/errors.c index 3e00393b1..6d8aac85b 100755 --- a/C/errors.c +++ b/C/errors.c @@ -311,11 +311,11 @@ yap_error_descriptor_t *Yap_popErrorContext(void) { } void Yap_ThrowError__(const char *file, const char *function, int lineno, - yap_error_number type, Term where, ...) { + yap_error_number type, Term where, int code, ...) { va_list ap; char tmpbuf[MAXPATHLEN]; - va_start(ap, where); + va_start(ap, code); char *format = va_arg(ap, char *); if (format != NULL) { #if HAVE_VSNPRINTF @@ -328,7 +328,7 @@ Yap_Error__(file, function, lineno, type, where, tmpbuf); } else { Yap_Error__(file, function, lineno, type, where); } - siglongjmp(LOCAL_RestartEnv, 2); + siglongjmp(LOCAL_RestartEnv, code); } /** @@ -560,8 +560,7 @@ 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_ErrorMessage, (char *)RepAtom(AtomOfTerm(nt[0]))->StrOfAE, - MAX_ERROR_MSG_SIZE); + LOCAL_ErrorMessage = RepAtom(AtomOfTerm(nt[0]))->StrOfAE; } else { LOCAL_ErrorMessage = (char *)RepAtom(NameOfFunctor(FunctorOfTerm(nt[0])))->StrOfAE; diff --git a/C/eval.c b/C/eval.c index 72eecf918..b4c08d13d 100644 --- a/C/eval.c +++ b/C/eval.c @@ -93,7 +93,7 @@ static Term get_matrix_element(Term t1, Term t2 USES_REGS) { static Term Eval(Term t USES_REGS) { if (IsVarTerm(t)) { - return Yap_ArithError(INSTANTIATION_ERROR, t, "in arithmetic"); + Yap_ArithError(INSTANTIATION_ERROR, t, "in arithmetic"); } else if (IsNumTerm(t)) { return t; } else if (IsAtomTerm(t)) { @@ -101,7 +101,7 @@ static Term Eval(Term t USES_REGS) { Atom name = AtomOfTerm(t); if (EndOfPAEntr(p = RepExpProp(Yap_GetExpProp(name, 0)))) { - return Yap_ArithError(TYPE_ERROR_EVALUABLE, takeIndicator(t), + Yap_ArithError(TYPE_ERROR_EVALUABLE, takeIndicator(t), "atom %s in arithmetic expression", RepAtom(name)->StrOfAE); } @@ -112,10 +112,10 @@ static Term Eval(Term t USES_REGS) { const char *s = (const char *)StringOfTerm(t); if (s[1] == '\0') return MkIntegerTerm(s[0]); - return Yap_ArithError(TYPE_ERROR_EVALUABLE, t, + Yap_ArithError(TYPE_ERROR_EVALUABLE, t, "string in arithmetic expression"); } else if ((Atom)fun == AtomFoundVar) { - return Yap_ArithError(TYPE_ERROR_EVALUABLE, TermNil, + Yap_ArithError(TYPE_ERROR_EVALUABLE, TermNil, "cyclic term in arithmetic expression"); } else { Int n = ArityOfFunctor(fun); @@ -124,7 +124,7 @@ static Term Eval(Term t USES_REGS) { Term t1, t2; if (EndOfPAEntr(p = RepExpProp(Yap_GetExpProp(name, n)))) { - return Yap_ArithError(TYPE_ERROR_EVALUABLE, takeIndicator(t), + Yap_ArithError(TYPE_ERROR_EVALUABLE, takeIndicator(t), "functor %s/%d for arithmetic expression", RepAtom(name)->StrOfAE, n); } @@ -153,7 +153,7 @@ static Term Eval(Term t USES_REGS) { } /* else if (IsPairTerm(t)) */ { if (TailOfTerm(t) != TermNil) { - return Yap_ArithError(TYPE_ERROR_EVALUABLE, t, + Yap_ArithError(TYPE_ERROR_EVALUABLE, t, "string must contain a single character to be " "evaluated as an arithmetic expression"); } @@ -369,32 +369,6 @@ static Int p_logsum(USES_REGS1) { /* X is Y */ } } -Int Yap_ArithError__(const char *file, const char *function, int lineno, - yap_error_number type, Term where, ...) { - CACHE_REGS - va_list ap; - char *format; - char buf[MAX_ERROR_MSG_SIZE]; - - LOCAL_Error_TYPE = type; - LOCAL_Error_File = file; - LOCAL_Error_Function = function; - LOCAL_Error_Lineno = lineno; - va_start(ap, where); - format = va_arg(ap, char *); - if (format != NULL) { -#if HAVE_VSNPRINTF - (void)vsnprintf(buf, MAX_ERROR_MSG_SIZE, format, ap); -#else - (void)vsprintf(buf, format, ap); -#endif - } else { - buf[0] = '\0'; - } - va_end(ap); - return 0L; -} - yamop *Yap_EvalError__(const char *file, const char *function, int lineno, yap_error_number type, Term where, ...) { CACHE_REGS diff --git a/C/exec.c b/C/exec.c index b6f61030b..fa669c67a 100755 --- a/C/exec.c +++ b/C/exec.c @@ -292,7 +292,7 @@ inline static bool do_execute(Term t, Term mod USES_REGS) { Term t2 = ArgOfTerm(2, t); if (IsVarTerm(t2)) return CallMetaCall(t, mod PASS_REGS); - if (!CommaCall(t2, mod)) + if (1 || !CommaCall(t2, mod)) return CallMetaCall(t, mod PASS_REGS); Term t1 = ArgOfTerm(1, t); @@ -315,6 +315,9 @@ inline static bool do_execute(Term t, Term mod USES_REGS) { /* I cannot use the standard macro here because otherwise I would dereference the argument and might skip a svar */ + if (pen->PredFlags & MetaPredFlag) { + return CallMetaCall(t, mod PASS_REGS); + } pt = RepAppl(t) + 1; for (i = 1; i <= arity; i++) { #if YAPOR_SBA @@ -1441,19 +1444,23 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) { LOCAL_PrologMode = UserMode; P = (yamop *)FAILCODE; } break; - case 2: { - /* arithmetic exception */ - /* must be done here, otherwise siglongjmp will clobber all the - * registers - */ - Yap_Error(LOCAL_Error_TYPE, TermNil, NULL); - /* reset the registers so that we don't have trash in abstract - * machine */ - Yap_set_fpu_exceptions( - getAtomicGlobalPrologFlag(ARITHMETIC_EXCEPTIONS_FLAG)); - P = (yamop *)FAILCODE; - LOCAL_PrologMode = UserMode; - } break; + case 2: { + /* arithmetic exception */ + /* must be done here, otherwise siglongjmp will clobber all the + * registers + */ + Yap_Error(LOCAL_Error_TYPE, TermNil, NULL); + /* reset the registers so that we don't have trash in abstract + * machine */ + Yap_set_fpu_exceptions( + getAtomicGlobalPrologFlag(ARITHMETIC_EXCEPTIONS_FLAG)); + P = (yamop *)FAILCODE; + LOCAL_PrologMode = UserMode; + } break; + case 4: { + P = (yamop *)FAILCODE; + LOCAL_PrologMode = UserMode; + } break; case 3: { /* saved state */ LOCAL_CBorder = OldBorder; return false; @@ -2074,16 +2081,15 @@ static Int jump_env(USES_REGS1) { Yap_Error(INSTANTIATION_ERROR, t, "throw ball must be bound"); return false; } else if (IsApplTerm(t) && FunctorOfTerm(t) == FunctorError) { - Term t2; + Term t2, te; Yap_find_prolog_culprit(PASS_REGS1); - LOCAL_Error_TYPE = ERROR_EVENT; - t = ArgOfTerm(1, t); - if (IsApplTerm(t) && IsAtomTerm((t2 = ArgOfTerm(1, t)))) { + te = ArgOfTerm(1, t); + if (IsApplTerm(te) && IsAtomTerm((t2 = ArgOfTerm(1, te)))) { LOCAL_ActiveError->errorAsText = AtomOfTerm(t2); - LOCAL_ActiveError->classAsText = NameOfFunctor(FunctorOfTerm(t)); - } else if (IsAtomTerm(t)) { - LOCAL_ActiveError->errorAsText = AtomOfTerm(t); + LOCAL_ActiveError->classAsText = NameOfFunctor(FunctorOfTerm(te)); + } else if (IsAtomTerm(te)) { + LOCAL_ActiveError->errorAsText = AtomOfTerm(te); LOCAL_ActiveError->classAsText = NULL; } } else { diff --git a/C/globals.c b/C/globals.c index 07b74511c..9897a3221 100644 --- a/C/globals.c +++ b/C/globals.c @@ -1654,7 +1654,8 @@ static Int p_nb_queue_close(USES_REGS1) { return Yap_unify(ARG3, ARG2); } out = Yap_unify(ARG3, qp[QUEUE_TAIL]) && Yap_unify(ARG2, qp[QUEUE_HEAD]); - qp[QUEUE_HEAD] = qp[QUEUE_TAIL] = RESET_VARIABLE(qp + QUEUE_TAIL); + RESET_VARIABLE(qp + QUEUE_TAIL); + qp[QUEUE_HEAD] = qp[QUEUE_TAIL] = (CELL)(qp + QUEUE_TAIL); qp[QUEUE_SIZE] = MkIntTerm(0); return out; } diff --git a/C/gmp_support.c b/C/gmp_support.c index 5de3d4f8b..167802cb1 100644 --- a/C/gmp_support.c +++ b/C/gmp_support.c @@ -32,7 +32,7 @@ MkBigAndClose(MP_INT *new) Term t = Yap_MkBigIntTerm(new); mpz_clear(new); if (t == TermNil) { - return Yap_ArithError(RESOURCE_ERROR_STACK, t, ">>/2"); + Yap_ArithError(RESOURCE_ERROR_STACK, t, ">>/2"); } return t; } @@ -43,7 +43,7 @@ MkRatAndClose(MP_RAT *new) Term t = Yap_MkBigRatTerm(new); mpq_clear(new); if (t == TermNil) { - return Yap_ArithError(RESOURCE_ERROR_STACK, t, ">>/2"); + Yap_ArithError(RESOURCE_ERROR_STACK, t, ">>/2"); } return t; } @@ -243,7 +243,7 @@ Yap_gmp_div_big_int(Term t, Int i) if (i > 0) { mpz_tdiv_q_ui(&new, &new, i); } else if (i == 0) { - return Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, MkIntTerm(0), "// /2"); + Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, MkIntTerm(0), "// /2"); } else { /* we do not handle MIN_INT */ mpz_tdiv_q_ui(&new, &new, -i); @@ -253,7 +253,7 @@ Yap_gmp_div_big_int(Term t, Int i) if (i > 0) { mpz_fdiv_q_ui(&new, &new, i); } else if (i == 0) { - return Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, MkIntTerm(0), "// /2"); + Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, MkIntTerm(0), "// /2"); } else { /* we do not handle MIN_INT */ mpz_fdiv_q_ui(&new, &new, -i); @@ -285,7 +285,7 @@ Yap_gmp_div2_big_int(Term t, Int i) if (i > 0) { mpz_fdiv_q_ui(&new, &new, i); } else if (i == 0) { - return Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, MkIntTerm(0), "// /2"); + Yap_ArithError(EVALUATION_ERROR_ZERO_DIVISOR, MkIntTerm(0), "// /2"); } else { /* we do not handle MIN_INT */ mpz_fdiv_q_ui(&new, &new, -i); @@ -311,7 +311,7 @@ Yap_gmp_and_int_big(Int i, Term t) CELL *pt = RepAppl(t); MP_INT *b; if (pt[1] != BIG_INT) { - return Yap_ArithError(TYPE_ERROR_INTEGER, t, "/\\/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t, "/\\/2"); } b = Yap_BigIntOfTerm(t); @@ -328,7 +328,7 @@ Yap_gmp_ior_int_big(Int i, Term t) CELL *pt = RepAppl(t); MP_INT *b; if (pt[1] != BIG_INT) { - return Yap_ArithError(TYPE_ERROR_INTEGER, t, "\\/ /2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t, "\\/ /2"); } b = Yap_BigIntOfTerm(t); @@ -367,7 +367,7 @@ Yap_gmp_xor_int_big(Int i, Term t) CELL *pt = RepAppl(t); MP_INT *b; if (pt[1] != BIG_INT) { - return Yap_ArithError(TYPE_ERROR_INTEGER, t, "#/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t, "#/2"); } b = Yap_BigIntOfTerm(t); @@ -394,7 +394,7 @@ Yap_gmp_sll_big_int(Term t, Int i) mpz_init(&new); if (i == Int_MIN) { CACHE_REGS - return Yap_ArithError(RESOURCE_ERROR_HUGE_INT, MkIntegerTerm(i), "< 0) { @@ -992,7 +992,7 @@ Yap_gmp_exp_int_big(Int i, Term t) CACHE_REGS CELL *pt = RepAppl(t); if (pt[1] == BIG_INT) { - return Yap_ArithError(RESOURCE_ERROR_HUGE_INT, t, "^/2"); + Yap_ArithError(RESOURCE_ERROR_HUGE_INT, t, "^/2"); } else { MP_INT *b = Yap_BigIntOfTerm(t); Float dbl = mpz_get_d(b); @@ -1009,7 +1009,7 @@ Yap_gmp_exp_big_big(Term t1, Term t2) Float dbl1, dbl2; if (pt1[1] == BIG_INT && pt2[1] == BIG_INT) { - return Yap_ArithError(RESOURCE_ERROR_HUGE_INT, t2, "^/2"); + Yap_ArithError(RESOURCE_ERROR_HUGE_INT, t2, "^/2"); } else { if (pt1[1] != BIG_INT) { dbl1 = mpz_get_d(Yap_BigIntOfTerm(t1)); @@ -1476,7 +1476,7 @@ Yap_gmp_unot_big(Term t) mpz_com(&new, &new); return MkBigAndClose(&new); } else { - return Yap_ArithError(TYPE_ERROR_INTEGER, t, "#/1"); + Yap_ArithError(TYPE_ERROR_INTEGER, t, "#/1"); } } @@ -1571,7 +1571,7 @@ Yap_gmp_float_fractional_part(Term t) { CELL *pt = RepAppl(t); if (pt[1] == BIG_INT) { - return Yap_ArithError(TYPE_ERROR_FLOAT, t, "X is float_fractional_part(%f)", FloatOfTerm(t)); + Yap_ArithError(TYPE_ERROR_FLOAT, t, "X is float_fractional_part(%f)", FloatOfTerm(t)); } else { MP_RAT *b = Yap_BigRatOfTerm(t); MP_RAT new; @@ -1591,7 +1591,7 @@ Yap_gmp_float_integer_part(Term t) { CELL *pt = RepAppl(t); if (pt[1] == BIG_INT) { - return Yap_ArithError(TYPE_ERROR_FLOAT, t, "X is float_integer_part(%f)", FloatOfTerm(t)); + Yap_ArithError(TYPE_ERROR_FLOAT, t, "X is float_integer_part(%f)", FloatOfTerm(t)); } else { MP_RAT *b = Yap_BigRatOfTerm(t); MP_INT new; @@ -1624,12 +1624,12 @@ Yap_gmp_lsb(Term t) if (pt[1] == BIG_INT) { MP_INT *big = Yap_BigIntOfTerm(t); if ( mpz_sgn(big) <= 0 ) { - return Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t, + Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t, "lsb/1 received negative bignum"); } return MkIntegerTerm(mpz_scan1(big,0)); } else { - return Yap_ArithError(TYPE_ERROR_INTEGER, t, "lsb"); + Yap_ArithError(TYPE_ERROR_INTEGER, t, "lsb"); } } @@ -1641,12 +1641,12 @@ Yap_gmp_msb(Term t) if (pt[1] == BIG_INT) { MP_INT *big = Yap_BigIntOfTerm(t); if ( mpz_sgn(big) <= 0 ) { - return Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t, + Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t, "msb/1 received negative bignum"); } return MkIntegerTerm(mpz_sizeinbase(big,2)); } else { - return Yap_ArithError(TYPE_ERROR_INTEGER, t, "popcount"); + Yap_ArithError(TYPE_ERROR_INTEGER, t, "popcount"); } } @@ -1658,17 +1658,17 @@ Yap_gmp_popcount(Term t) if (pt[1] == BIG_INT) { MP_INT *big = Yap_BigIntOfTerm(t); if ( mpz_sgn(big) <= 0 ) { - return Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t, + Yap_ArithError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t, "popcount/1 received negative bignum"); } return MkIntegerTerm(mpz_popcount(big)); } else { - return Yap_ArithError(TYPE_ERROR_INTEGER, t, "popcount"); + Yap_ArithError(TYPE_ERROR_INTEGER, t, "popcount"); } } char * -Yap_mpz_to_string(MP_INT *b, char *s, size_t sz, int base) +Yap_mpz_to_string( MP_INT *b, char *s, size_t sz, int base) { if (s) { size_t size = mpz_sizeinbase(b, base); diff --git a/C/grow.c b/C/grow.c index e3e373d62..13e30ad11 100755 --- a/C/grow.c +++ b/C/grow.c @@ -832,7 +832,7 @@ static_growheap(size_t esize, bool fix_code, struct intermediates *cip, tr_fr_pt fprintf( stderr, "%% Worker Id %d:\n", worker_id); #endif fprintf( stderr, "%% Database Overflow %d\n", LOCAL_heap_overflows); - fprintf( stderr, "%% growing the heap %ld bytes\n", size); + fprintf( stderr, "%% growing the heap " Int_FORMAT " bytes\n", size); } /* CreepFlag is set to force heap expansion */ if ( Yap_only_has_signal( YAP_CDOVF_SIGNAL) ) { @@ -976,7 +976,7 @@ static_growglobal(size_t request, CELL **ptr, CELL *hsplit USES_REGS) fprintf(stderr, "%% Worker Id %d:\n", worker_id); #endif fprintf(stderr, "%% %cO %s Overflow %d\n", vb_msg1, vb_msg2, LOCAL_delay_overflows); - fprintf(stderr, "%% %cO growing the stacks %ld bytes\n", vb_msg1, size); + fprintf(stderr, "%% %cO growing the stacks " UInt_FORMAT " bytes\n", vb_msg1, size); } ASP -= 256; YAPEnterCriticalSection(); @@ -1794,7 +1794,7 @@ static int do_growtrail(size_t esize, bool contiguous_only, bool in_parser, tr_f fprintf(stderr, "%% Trail:%8ld cells (%p-%p)\n", (unsigned long int)(TR-(tr_fr_ptr)LOCAL_TrailBase),LOCAL_TrailBase,TR); #endif - fprintf(stderr, "%% growing the trail %ld bytes\n", size); + fprintf(stderr, "%% growing the trail " UInt_FORMAT " bytes\n", size); } LOCAL_ErrorMessage = NULL; if (!GLOBAL_AllowTrailExpansion) { diff --git a/C/load_dll.c b/C/load_dll.c index 98facdb65..ea881df06 100755 --- a/C/load_dll.c +++ b/C/load_dll.c @@ -45,10 +45,10 @@ Yap_LoadForeignFile(char *file, int flags) void *ptr= (void *)LoadLibrary(file); if (!ptr) { CACHE_REGS - LOCAL_ErrorSay[0]='\0'; + LOCAL_ErrorMessage = NULL; FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), LOCAL_ErrorSay, 256, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), LOCAL_ErrorMessage, 256, NULL); } return ptr; @@ -86,13 +86,13 @@ LoadForeign(StringList ofiles, StringList libs, if (!Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true, true) && (handle=LoadLibrary(LOCAL_FileNameBuf)) != 0) { - LOCAL_ErrorSay[0]=~'\0'; + LOCAL_ErrorMessage = NULL; if (*init_proc == NULL) *init_proc = (YapInitProc)GetProcAddress((HMODULE)handle, proc_name); } else { FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, GetLastError(), - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), LOCAL_ErrorSay, 256, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), LOCAL_ErrorMessage, 256, NULL); //fprintf(stderr,"WinError: %s\n", LOCAL_ErrorSay); } @@ -124,7 +124,7 @@ LoadForeign(StringList ofiles, StringList libs, } if(*init_proc == NULL) { - strcpy(LOCAL_ErrorSay,"Could not locate initialization routine"); + LOCAL_ErrorMessage = "Could not locate initialization routine"; return LOAD_FAILLED; } diff --git a/C/modules.c b/C/modules.c index 5709ba07f..a35cd917b 100644 --- a/C/modules.c +++ b/C/modules.c @@ -370,16 +370,57 @@ static Int new_system_module(USES_REGS1) { } static Int strip_module(USES_REGS1) { - Term t1 = Deref(ARG1), tmod = CurrentModule; - if (tmod == PROLOG_MODULE) { - tmod = TermProlog; - } - t1 = Yap_StripModule(t1, &tmod); - if (!t1) { + Term t1 = Deref(ARG1), tmod = CurrentModule; + if (tmod == PROLOG_MODULE) { + tmod = TermProlog; + } + t1 = Yap_StripModule(t1, &tmod); + if (!t1) { + Yap_Error(TYPE_ERROR_CALLABLE, t1, "trying to obtain module"); + return FALSE; + } + return Yap_unify(ARG3, t1) && Yap_unify(ARG2, tmod); +} + +static Int yap_strip_clause(USES_REGS1) { + Functor f; + Term t1 = Deref(ARG1), tmod = LOCAL_SourceModule; + if (tmod == PROLOG_MODULE) { + tmod = TermProlog; + } + t1 = Yap_StripModule(t1, &tmod); + if (IsVarTerm(t1)) { + Yap_Error(INSTANTIATION_ERROR, t1, "trying to obtain module"); + return false; + } else if (IsVarTerm(tmod)) { + Yap_Error(INSTANTIATION_ERROR, tmod, "trying to obtain module"); + return false; + } else if (IsIntTerm(t1) || (IsApplTerm(t1) && IsExtensionFunctor((f = FunctorOfTerm(t1))))) { Yap_Error(TYPE_ERROR_CALLABLE, t1, "trying to obtain module"); - return FALSE; - } - return Yap_unify(ARG3, t1) && Yap_unify(ARG2, tmod); + return false; + } else if (!IsAtomTerm(tmod)) { + Yap_Error(TYPE_ERROR_ATOM, tmod, "trying to obtain module"); + return false; + } + if (f == FunctorAssert || f == FunctorDoubleArrow) { + Term thmod = tmod; + Term th = ArgOfTerm(1, t1); + th = Yap_StripModule(th, &thmod); + if (IsVarTerm(th)) { + Yap_Error(INSTANTIATION_ERROR, t1, "trying to obtain module"); + return false; + } else if (IsVarTerm(thmod)) { + Yap_Error(INSTANTIATION_ERROR, thmod, "trying to obtain module"); + return false; + } else if (IsIntTerm(th) || (IsApplTerm(th) && IsExtensionFunctor(FunctorOfTerm(t1)))) { + Yap_Error(TYPE_ERROR_CALLABLE, t1, "trying to obtain module"); + return false; + }else if (!IsAtomTerm(thmod)) { + Yap_Error(TYPE_ERROR_ATOM, thmod, "trying to obtain module"); + return false; + } + } + return Yap_unify(ARG3, t1) && Yap_unify(ARG2, tmod); } Term Yap_YapStripModule(Term t, Term *modp) { @@ -564,13 +605,14 @@ void Yap_InitModulesC(void) { SafePredFlag | SyncPredFlag); Yap_InitCPred("$change_module", 1, change_module, SafePredFlag | SyncPredFlag); - Yap_InitCPred("strip_module", 3, strip_module, SafePredFlag | SyncPredFlag); + Yap_InitCPred("strip_module", 3, strip_module, SafePredFlag | SyncPredFlag); + Yap_InitCPred("$yap_strip_module", 3, yap_strip_module, SafePredFlag | SyncPredFlag); Yap_InitCPred("source_module", 1, source_module, SafePredFlag | SyncPredFlag); Yap_InitCPred("current_source_module", 2, current_source_module, SafePredFlag | SyncPredFlag); - Yap_InitCPred("$yap_strip_module", 3, yap_strip_module, - SafePredFlag | SyncPredFlag); - Yap_InitCPred("context_module", 1, context_module, 0); + Yap_InitCPred("$yap_strip_clause", 3, yap_strip_clause, + SafePredFlag | SyncPredFlag); + Yap_InitCPred("context_module", 1, context_module, 0); Yap_InitCPred("$is_system_module", 1, is_system_module, SafePredFlag); Yap_InitCPred("$copy_operators", 2, copy_operators, 0); Yap_InitCPred("new_system_module", 1, new_system_module, SafePredFlag); diff --git a/C/parser.c b/C/parser.c index b8c0c794e..e4001d273 100755 --- a/C/parser.c +++ b/C/parser.c @@ -168,7 +168,8 @@ static Term ParseArgs(Atom, Term, JMPBUFF *, Term, encoding_t, Term CACHE_TYPE); static Term ParseList(JMPBUFF *, encoding_t, Term CACHE_TYPE); static Term ParseTerm(int, JMPBUFF *, encoding_t, Term CACHE_TYPE); -const char *Yap_tokRep(void *tokptr, encoding_t enc); +extern Term Yap_tokRep(void* tokptr); +extern const char * Yap_tokText(void *tokptr); static void syntax_msg(const char *msg, ...) { CACHE_REGS @@ -366,6 +367,7 @@ static Term Variables(VarEntry *p, Term l USES_REGS) { Term Yap_Variables(VarEntry *p, Term l) { CACHE_REGS + l = Variables(LOCAL_AnonVarTable, l PASS_REGS); return Variables(p, l PASS_REGS); } @@ -466,7 +468,7 @@ inline static void checkfor(Term c, JMPBUFF *FailBuff, encoding_t enc USES_REGS) { if (LOCAL_tokptr->Tok != Ord(Ponctuation_tok) || LOCAL_tokptr->TokInfo != c) { char s[1024]; - strncpy(s, Yap_tokRep(LOCAL_tokptr, enc), 1023); + strncpy(s, Yap_tokText(LOCAL_tokptr), 1023); syntax_msg("line %d: expected to find " "\'%c....................................\', found %s", LOCAL_tokptr->TokPos, c, s); @@ -654,7 +656,7 @@ loop: } } else { syntax_msg("line %d: looking for symbol ',','|' got symbol '%s'", - LOCAL_tokptr->TokPos, Yap_tokRep(LOCAL_tokptr, enc)); + LOCAL_tokptr->TokPos, Yap_tokText(LOCAL_tokptr)); FAIL; } return (o); @@ -675,7 +677,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, NextToken; /* special rules apply for +1, -2.3, etc... */ if (LOCAL_tokptr->Tok == Number_tok) { - if ((Atom)t == AtomMinus) { + if (t == TermMinus) { t = LOCAL_tokptr->TokInfo; if (IsIntTerm(t)) t = MkIntTerm(-IntOfTerm(t)); @@ -698,7 +700,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, if (LOCAL_tokptr->Tok == Name_tok) { Atom at = AtomOfTerm(LOCAL_tokptr->TokInfo); #ifndef _MSC_VER - if ((Atom)t == AtomPlus) { + if (t == TermPlus) { if (at == AtomInf) { t = MkFloatTerm(INFINITY); NextToken; @@ -708,7 +710,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, NextToken; break; } - } else if ((Atom)t == AtomMinus) { + } else if (t == TermMinus) { if (at == AtomInf) { t = MkFloatTerm(-INFINITY); NextToken; @@ -764,7 +766,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, case Error_tok: syntax_msg("line %d: found ill-formed \"%s\"", LOCAL_tokptr->TokPos, - Yap_tokRep(LOCAL_tokptr, enc)); + Yap_tokText(LOCAL_tokptr)); FAIL; case Ponctuation_tok: @@ -806,7 +808,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, break; default: syntax_msg("line %d: unexpected ponctuation signal %s", - LOCAL_tokptr->TokPos, Yap_tokRep(LOCAL_tokptr, enc)); + LOCAL_tokptr->TokPos, Yap_tokRep(LOCAL_tokptr)); FAIL; } break; @@ -851,12 +853,12 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, t = ParseTerm(GLOBAL_MaxPriority, FailBuff, enc, cmod PASS_REGS); if (LOCAL_tokptr->Tok != QuasiQuotes_tok) { syntax_msg("expected to find quasi quotes, got \"%s\"", , - Yap_tokRep(LOCAL_tokptr, enc)); + Yap_tokText(LOCAL_tokptr)); FAIL; } if (!(is_quasi_quotation_syntax(t, &at))) { syntax_msg("bad quasi quotation syntax, at \"%s\"", - Yap_tokRep(LOCAL_tokptr, enc)); + Yap_tokText(LOCAL_tokptr)); FAIL; } /* Arg 2: the content */ @@ -866,7 +868,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, if (!get_quasi_quotation(Yap_InitSlot(ArgOfTerm(2, tn)), &qq->text, qq->text + strlen((const char *)qq->text))) { syntax_msg("could not get quasi quotation, at \"%s\"", - Yap_tokRep(LOCAL_tokptr, enc)); + Yap_tokText(LOCAL_tokptr)); FAIL; } if (positions) { @@ -878,7 +880,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, qq->mid.charno + 2, /* end of | token */ PL_INTPTR, qqend - 2)) /* end minus "|}" */ syntax_msg("failed to unify quasi quotation, at \"%s\"", - Yap_tokRep(LOCAL_tokptr, enc)); + Yap_tokText(LOCAL_tokptr)); FAIL; } @@ -898,7 +900,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, break; default: syntax_msg("line %d: expected operator, got \'%s\'", LOCAL_tokptr->TokPos, - Yap_tokRep(LOCAL_tokptr, enc)); + Yap_tokText(LOCAL_tokptr)); FAIL; } @@ -1013,7 +1015,7 @@ static Term ParseTerm(int prio, JMPBUFF *FailBuff, encoding_t enc, } if (LOCAL_tokptr->Tok <= Ord(String_tok)) { syntax_msg("line %d: expected operator, got \'%s\'", LOCAL_tokptr->TokPos, - Yap_tokRep(LOCAL_tokptr, enc)); + Yap_tokText(LOCAL_tokptr)); FAIL; } break; @@ -1046,7 +1048,11 @@ Term Yap_Parse(UInt prio, encoding_t enc, Term cmod) { } if (LOCAL_tokptr != NULL && LOCAL_tokptr->Tok != Ord(eot_tok)) { LOCAL_Error_TYPE = SYNTAX_ERROR; + if (LOCAL_tokptr->TokNext) { + LOCAL_ErrorMessage = "operator misssing . "; + } else { LOCAL_ErrorMessage = "term does not end on . "; + } t = 0; } if (t != 0 && LOCAL_Error_TYPE == SYNTAX_ERROR) { diff --git a/C/prim_absmi_insts.h b/C/prim_absmi_insts.h index 00358ba10..fc10ba1a4 100644 --- a/C/prim_absmi_insts.h +++ b/C/prim_absmi_insts.h @@ -33,13 +33,13 @@ BEGP(pt0); deref_body(d0, pt0, plus_vv_unk, plus_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR, d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, plus_vv_nvar_unk, plus_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR, d1); FAIL(); ENDP(pt0); ENDD(d1); @@ -67,7 +67,7 @@ BEGP(pt0); deref_body(d0, pt0, plus_vc_unk, plus_vc_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR, d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -101,13 +101,13 @@ BEGP(pt0); deref_body(d0, pt0, plus_y_vv_unk, plus_y_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR, d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, plus_y_vv_nvar_unk, plus_y_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR, d1); FAIL(); ENDP(pt0); ENDD(d1); @@ -138,7 +138,7 @@ BEGP(pt0); deref_body(d0, pt0, plus_y_vc_unk, plus_y_vc_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR, d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -169,13 +169,13 @@ BEGP(pt0); deref_body(d0, pt0, minus_vv_unk, minus_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, minus_vv_nvar_unk, minus_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR, d0); FAIL(); ENDP(pt0); ENDD(d1); @@ -203,7 +203,7 @@ BEGP(pt0); deref_body(d0, pt0, minus_cv_unk, minus_cv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR, d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -237,13 +237,13 @@ BEGP(pt0); deref_body(d0, pt0, minus_y_vv_unk, minus_y_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR, d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, minus_y_vv_nvar_unk, minus_y_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR, d1); FAIL(); ENDP(pt0); ENDD(d1); @@ -274,7 +274,7 @@ BEGP(pt0); deref_body(d0, pt0, minus_y_cv_unk, minus_y_cv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -304,13 +304,13 @@ BEGP(pt0); deref_body(d0, pt0, times_vv_unk, times_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, times_vv_nvar_unk, times_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); FAIL(); ENDP(pt0); ENDD(d1); @@ -338,7 +338,7 @@ BEGP(pt0); deref_body(d0, pt0, times_vc_unk, times_vc_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -372,13 +372,13 @@ BEGP(pt0); deref_body(d0, pt0, times_y_vv_unk, times_y_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, times_y_vv_nvar_unk, times_y_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); FAIL(); ENDP(pt0); ENDD(d1); @@ -409,7 +409,7 @@ BEGP(pt0); deref_body(d0, pt0, times_y_vc_unk, times_y_vc_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -430,7 +430,7 @@ if (IsIntTerm(d0) && IsIntTerm(d1)) { Int div = IntOfTerm(d1); if (div == 0) { - Yap_AsmError(EVALUATION_ERROR_ZERO_DIVISOR); + Yap_AsmError(EVALUATION_ERROR_ZERO_DIVISOR,d1); } d0 = MkIntTerm(IntOfTerm(d0) / div); } else { @@ -444,13 +444,13 @@ BEGP(pt0); deref_body(d0, pt0, div_vv_unk, div_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, div_vv_nvar_unk, div_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); FAIL(); ENDP(pt0); ENDD(d1); @@ -478,7 +478,7 @@ BEGP(pt0); deref_body(d0, pt0, div_vc_unk, div_vc_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -494,7 +494,7 @@ if (IsIntTerm(d0)) { Int div = IntOfTerm(d0); if (div == 0) { - Yap_AsmError(EVALUATION_ERROR_ZERO_DIVISOR); + Yap_AsmError(EVALUATION_ERROR_ZERO_DIVISOR,d0); FAIL(); } d0 = MkIntegerTerm(d1 / div); @@ -509,7 +509,7 @@ BEGP(pt0); deref_body(d0, pt0, div_cv_unk, div_cv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -530,7 +530,7 @@ if (IsIntTerm(d0) && IsIntTerm(d1)) { Int div = IntOfTerm(d1); if (div == 0) { - Yap_AsmError(EVALUATION_ERROR_ZERO_DIVISOR); + Yap_AsmError(EVALUATION_ERROR_ZERO_DIVISOR, d0); FAIL(); } d0 = MkIntTerm(IntOfTerm(d0) / div); @@ -548,13 +548,13 @@ BEGP(pt0); deref_body(d0, pt0, div_y_vv_unk, div_y_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, div_y_vv_nvar_unk, div_y_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); FAIL(); ENDP(pt0); ENDD(d1); @@ -585,7 +585,7 @@ BEGP(pt0); deref_body(d0, pt0, div_y_vc_unk, div_y_vc_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -601,7 +601,7 @@ if (IsIntTerm(d0)) { Int div = IntOfTerm(d0); if (div == 0) { - Yap_AsmError(EVALUATION_ERROR_ZERO_DIVISOR); + Yap_AsmError(EVALUATION_ERROR_ZERO_DIVISOR,d0); FAIL(); } d0 = MkIntegerTerm(d1 / div); @@ -651,13 +651,13 @@ BEGP(pt0); deref_body(d0, pt0, and_vv_unk, and_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, and_vv_nvar_unk, and_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); FAIL(); ENDP(pt0); ENDD(d1); @@ -719,13 +719,13 @@ BEGP(pt0); deref_body(d0, pt0, and_y_vv_unk, and_y_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, and_y_vv_nvar_unk, and_y_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); FAIL(); ENDP(pt0); ENDD(d1); @@ -787,13 +787,13 @@ BEGP(pt0); deref_body(d0, pt0, or_vv_unk, or_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, or_vv_nvar_unk, or_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); FAIL(); ENDP(pt0); ENDD(d1); @@ -854,13 +854,13 @@ BEGP(pt0); deref_body(d0, pt0, or_y_vv_unk, or_y_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, or_y_vv_nvar_unk, or_y_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); FAIL(); ENDP(pt0); ENDD(d1); @@ -926,13 +926,13 @@ BEGP(pt0); deref_body(d0, pt0, sll_vv_unk, sll_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, sll_vv_nvar_unk, sll_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); FAIL(); ENDP(pt0); ENDD(d1); @@ -960,7 +960,7 @@ BEGP(pt0); deref_body(d0, pt0, sll_vc_unk, sll_vc_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -991,7 +991,7 @@ BEGP(pt0); deref_body(d0, pt0, sll_cv_unk, sll_cv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -1029,13 +1029,13 @@ BEGP(pt0); deref_body(d0, pt0, sll_y_vv_unk, sll_y_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, sll_y_vv_nvar_unk, sll_y_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); FAIL(); ENDP(pt0); ENDD(d1); @@ -1066,7 +1066,7 @@ BEGP(pt0); deref_body(d0, pt0, sll_y_vc_unk, sll_y_vc_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -1100,7 +1100,7 @@ BEGP(pt0); deref_body(d0, pt0, sll_y_cv_unk, sll_y_cv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -1135,13 +1135,13 @@ BEGP(pt0); deref_body(d0, pt0, slr_vv_unk, slr_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, slr_vv_nvar_unk, slr_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); FAIL(); ENDP(pt0); ENDD(d1); @@ -1169,7 +1169,7 @@ BEGP(pt0); deref_body(d0, pt0, slr_vc_unk, slr_vc_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -1200,7 +1200,7 @@ BEGP(pt0); deref_body(d0, pt0, slr_cv_unk, slr_cv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -1238,13 +1238,13 @@ BEGP(pt0); deref_body(d0, pt0, slr_y_vv_unk, slr_y_vv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); BEGP(pt0); deref_body(d1, pt0, slr_y_vv_nvar_unk, slr_y_vv_nvar_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); FAIL(); ENDP(pt0); ENDD(d1); @@ -1275,7 +1275,7 @@ BEGP(pt0); deref_body(d0, pt0, slr_y_vc_unk, slr_y_vc_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); ENDP(pt0); ENDD(d0); ENDOp(); @@ -1300,7 +1300,7 @@ } } if (d0 == 0L) { - Yap_AsmError(LOCAL_Error_TYPE); + Yap_AsmError(LOCAL_Error_TYPE,d0); FAIL(); } BEGP(pt0); @@ -1312,7 +1312,7 @@ BEGP(pt0); deref_body(d0, pt0, slr_y_cv_unk, slr_y_cv_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); FAIL(); ENDP(pt0); ENDD(d0); @@ -1968,7 +1968,7 @@ } else { if (IsBigIntTerm(d0)) FAIL(); - Yap_AsmError(TYPE_ERROR_INTEGER); + Yap_AsmError(TYPE_ERROR_INTEGER, d0); FAIL(); } @@ -1984,7 +1984,7 @@ pt0 = RepAppl(d1); d1 = *pt0; if (IsExtensionFunctor((Functor)d1)) { - Yap_AsmError(TYPE_ERROR_COMPOUND); + Yap_AsmError(TYPE_ERROR_COMPOUND, AbsAppl(pt0)); FAIL(); } if ((Int)d0 <= 0 || (Int)d0 > ArityOfFunctor((Functor)d1)) { @@ -2007,7 +2007,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); pt0 = RepPair(d1); if (d0 != 1 && d0 != 2) { if ((Int)d0 < 0) { - Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, MkIntegerTerm(d0) ); } FAIL(); } @@ -2016,14 +2016,14 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); GONext(); ENDP(pt0); } else { - Yap_AsmError(TYPE_ERROR_COMPOUND); + Yap_AsmError(TYPE_ERROR_COMPOUND, d1); FAIL(); } BEGP(pt0); deref_body(d1, pt0, arg_arg2_unk, arg_arg2_nvar); saveregs(); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); ; setregs(); ENDP(pt0); @@ -2033,7 +2033,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); BEGP(pt0); deref_body(d0, pt0, arg_arg1_unk, arg_arg1_nvar); saveregs(); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); ; setregs(); ENDP(pt0); @@ -2068,7 +2068,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); pt0 = RepAppl(d1); d1 = *pt0; if (IsExtensionFunctor((Functor)d1)) { - Yap_AsmError(TYPE_ERROR_COMPOUND); + Yap_AsmError(TYPE_ERROR_COMPOUND,XREG(PREG->y_u.xxn.xi)); FAIL(); } if ((Int)d0 <= 0 || (Int)d0 > ArityOfFunctor((Functor)d1)) { @@ -2092,7 +2092,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); if (d0 != 1 && d0 != 2) { if ((Int)d0 < 0) { saveregs(); - Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, XREG(PREG->y_u.xxn.xi)); } FAIL(); } @@ -2101,13 +2101,13 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); GONext(); ENDP(pt0); } else { - Yap_AsmError(TYPE_ERROR_COMPOUND); + Yap_AsmError(TYPE_ERROR_COMPOUND, XREG(PREG->y_u.xxn.xi)); FAIL(); } BEGP(pt0); deref_body(d1, pt0, arg_arg2_vc_unk, arg_arg2_vc_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR, XREG(PREG->y_u.xxn.xi)); ENDP(pt0); FAIL(); ENDD(d1); @@ -2138,7 +2138,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); } else { if (IsBigIntTerm(d0)) FAIL(); - Yap_AsmError(TYPE_ERROR_INTEGER); + Yap_AsmError(TYPE_ERROR_INTEGER, XREG(PREG->y_u.yxx.x1)); FAIL(); } @@ -2154,7 +2154,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); pt0 = RepAppl(d1); d1 = *pt0; if (IsExtensionFunctor((Functor)d1)) { - Yap_AsmError(TYPE_ERROR_COMPOUND); + Yap_AsmError(TYPE_ERROR_COMPOUND,XREG(PREG->y_u.yxx.x2)); FAIL(); } if ((Int)d0 <= 0 || (Int)d0 > ArityOfFunctor((Functor)d1)) { @@ -2181,7 +2181,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); if (d0 != 1 && d0 != 2) { if ((Int)d0 < 0) { saveregs(); - Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, YREG[PREG->y_u.yxx.y]); } FAIL(); } @@ -2193,20 +2193,20 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); ENDP(pt1); ENDP(pt0); } else { - Yap_AsmError(TYPE_ERROR_COMPOUND); + Yap_AsmError(TYPE_ERROR_COMPOUND, d1); FAIL(); } BEGP(pt0); deref_body(d1, pt0, arg_y_arg2_unk, arg_y_arg2_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); ENDP(pt0); FAIL(); ENDD(d1); BEGP(pt0); deref_body(d0, pt0, arg_y_arg1_unk, arg_y_arg1_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); ENDP(pt0); FAIL(); ENDD(d0); @@ -2240,7 +2240,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); pt0 = RepAppl(d1); d1 = *pt0; if (IsExtensionFunctor((Functor)d1)) { - Yap_AsmError(TYPE_ERROR_COMPOUND); + Yap_AsmError(TYPE_ERROR_COMPOUND, XREG(PREG->y_u.yxn.xi)); FAIL(); } if ((Int)d0 <= 0 || (Int)d0 > ArityOfFunctor((Functor)d1)) { @@ -2264,7 +2264,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); if (d0 != 1 && d0 != 2) { if ((Int)d0 < 0) { saveregs(); - Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, YREG[PREG->y_u.yxn.y]); } FAIL(); } @@ -2276,13 +2276,13 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); GONext(); ENDP(pt0); } else { - Yap_AsmError(TYPE_ERROR_COMPOUND); + Yap_AsmError(TYPE_ERROR_COMPOUND,YREG[PREG->y_u.yxn.y]); FAIL(); } BEGP(pt0); deref_body(d1, pt0, arg_y_arg2_vc_unk, arg_y_arg2_vc_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); ENDP(pt0); FAIL(); ENDD(d1); @@ -2320,15 +2320,15 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); saveregs(); if (IsBigIntTerm(d1)) { setregs(); - Yap_AsmError(RESOURCE_ERROR_STACK); + Yap_AsmError(RESOURCE_ERROR_STACK,d1); } else { setregs(); - Yap_AsmError(TYPE_ERROR_INTEGER); + Yap_AsmError(TYPE_ERROR_INTEGER,d1); } FAIL(); } if (!IsAtomicTerm(d0)) { - Yap_AsmError(TYPE_ERROR_ATOM); + Yap_AsmError(TYPE_ERROR_ATOM, d0); FAIL(); } /* We made it!!!!! we got in d0 the name, in d1 the arity and @@ -2346,7 +2346,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); } else if ((Int)d1 > 0) { /* now let's build a compound term */ if (!IsAtomTerm(d0)) { - Yap_AsmError(TYPE_ERROR_ATOM); + Yap_AsmError(TYPE_ERROR_ATOM, d0); FAIL(); } BEGP(pt1); @@ -2363,7 +2363,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); if (!Yap_gcl((1 + d1) * sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG, xxx), Osbpp))) { setregs(); - Yap_AsmError(RESOURCE_ERROR_STACK); + Yap_AsmError(RESOURCE_ERROR_STACK, d1 ); JMPNext(); } else { setregs(); @@ -2387,12 +2387,12 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxx), Osbpp), l); GONext(); } else { - Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, MkIntegerTerm(d1)); } BEGP(pt1); deref_body(d1, pt1, func2s_unk2, func2s_nvar2); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); ENDP(pt1); /* Oops, third argument was unbound */ FAIL(); @@ -2400,7 +2400,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); BEGP(pt1); deref_body(d0, pt1, func2s_unk, func2s_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -2435,10 +2435,10 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); saveregs(); if (IsBigIntTerm(d1)) { setregs(); - Yap_AsmError(RESOURCE_ERROR_STACK); + Yap_AsmError(RESOURCE_ERROR_STACK, d1); } else { setregs(); - Yap_AsmError(TYPE_ERROR_INTEGER); + Yap_AsmError(TYPE_ERROR_INTEGER, d1); } FAIL(); } @@ -2457,7 +2457,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); } else if ((Int)d1 > 0) { /* now let's build a compound term */ if (!IsAtomTerm(d0)) { - Yap_AsmError(TYPE_ERROR_ATOM); + Yap_AsmError(TYPE_ERROR_ATOM, d0); FAIL(); } BEGP(pt1); @@ -2474,7 +2474,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); if (!Yap_gcl((1 + d1) * sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG, xxc), Osbpp))) { setregs(); - Yap_AsmError(RESOURCE_ERROR_STACK); + Yap_AsmError(RESOURCE_ERROR_STACK, d1); JMPNext(); } else { setregs(); @@ -2498,12 +2498,12 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); PREG = NEXTOP(NEXTOP(NEXTOP(PREG, xxc), Osbpp), l); GONext(); } else { - Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO,d1); } BEGP(pt1); deref_body(d1, pt1, func2s_unk2_cv, func2s_nvar2_cv); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); ENDP(pt1); /* Oops, third argument was unbound */ FAIL(); @@ -2537,7 +2537,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); BEGD(d1); d1 = PREG->y_u.xxn.c; if (!IsAtomicTerm(d0)) { - Yap_AsmError(TYPE_ERROR_ATOM); + Yap_AsmError(TYPE_ERROR_ATOM,d0); FAIL(); } /* We made it!!!!! we got in d0 the name, in d1 the arity and @@ -2560,7 +2560,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); GONext(); } if (!IsAtomTerm(d0)) { - Yap_AsmError(TYPE_ERROR_ATOM); + Yap_AsmError(TYPE_ERROR_ATOM, d0); FAIL(); } BEGP(pt1); @@ -2576,7 +2576,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); saveregs(); if (!Yap_gc(0, YREG, NEXTOP(NEXTOP(PREG, xxn), Osbpp))) { setregs(); - Yap_AsmError(RESOURCE_ERROR_STACK); + Yap_AsmError(INSTANTIATION_ERROR,d1); JMPNext(); } else { setregs(); @@ -2599,7 +2599,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); BEGP(pt1); deref_body(d0, pt1, func2s_unk_vc, func2s_nvar_vc); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -2636,15 +2636,15 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); saveregs(); if (IsBigIntTerm(d1)) { setregs(); - Yap_AsmError(RESOURCE_ERROR_STACK); + Yap_AsmError(RESOURCE_ERROR_STACK, d1); } else { setregs(); - Yap_AsmError(TYPE_ERROR_INTEGER); + Yap_AsmError(TYPE_ERROR_INTEGER, d1); } FAIL(); } if (!IsAtomicTerm(d0)) { - Yap_AsmError(TYPE_ERROR_ATOM); + Yap_AsmError(TYPE_ERROR_ATOM, d0); FAIL(); } /* We made it!!!!! we got in d0 the name, in d1 the arity and @@ -2663,7 +2663,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); } else if ((Int)d1 > 0) { /* now let's build a compound term */ if (!IsAtomTerm(d0)) { - Yap_AsmError(TYPE_ERROR_ATOM); + Yap_AsmError(TYPE_ERROR_ATOM, d0); FAIL(); } BEGP(pt1); @@ -2680,7 +2680,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); if (!Yap_gcl((1 + d1) * sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG, yxx), Osbpp))) { setregs(); - Yap_AsmError(RESOURCE_ERROR_STACK); + Yap_AsmError(RESOURCE_ERROR_STACK, d1); JMPNext(); } else { setregs(); @@ -2710,12 +2710,12 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); ENDP(pt1); GONext(); } else { - Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, MkIntegerTerm(d1)); } BEGP(pt1); deref_body(d1, pt1, func2s_y_unk2, func2s_y_nvar2); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); ENDP(pt1); /* Oops, third argument was unbound */ FAIL(); @@ -2723,7 +2723,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); BEGP(pt1); deref_body(d0, pt1, func2s_y_unk, func2s_y_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -2756,9 +2756,9 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); d1 = IntegerOfTerm(d1); } else { if (IsBigIntTerm(d1)) { - Yap_AsmError(RESOURCE_ERROR_STACK); + Yap_AsmError(RESOURCE_ERROR_STACK, d1); } else { - Yap_AsmError(TYPE_ERROR_INTEGER); + Yap_AsmError(TYPE_ERROR_INTEGER, d1); } FAIL(); } @@ -2780,7 +2780,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); } else if ((Int)d1 > 0) { /* now let's build a compound term */ if (!IsAtomTerm(d0)) { - Yap_AsmError(TYPE_ERROR_ATOM); + Yap_AsmError(TYPE_ERROR_ATOM,d0); FAIL(); } if (!IsAtomTerm(d0)) { @@ -2797,7 +2797,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); if (!Yap_gcl((1 + d1) * sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG, yxc), Osbpp))) { setregs(); - Yap_AsmError(RESOURCE_ERROR_STACK); + Yap_AsmError(RESOURCE_ERROR_STACK, d1); JMPNext(); } else { setregs(); @@ -2827,12 +2827,12 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); ENDP(pt1); GONext(); } else { - Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, MkIntegerTerm(d1)); } BEGP(pt1); deref_body(d1, pt1, func2s_y_unk_cv, func2s_y_nvar_cv); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); ENDP(pt1); /* Oops, third argument was unbound */ FAIL(); @@ -2866,7 +2866,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); BEGD(d1); d1 = PREG->y_u.yxn.c; if (!IsAtomicTerm(d0)) { - Yap_AsmError(TYPE_ERROR_ATOM); + Yap_AsmError(TYPE_ERROR_ATOM,d0); FAIL(); } /* We made it!!!!! we got in d0 the name, in d1 the arity and @@ -2894,12 +2894,12 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); GONext(); } if (!IsAtomTerm(d0)) { - Yap_AsmError(TYPE_ERROR_ATOM); + Yap_AsmError(TYPE_ERROR_ATOM,d0); FAIL(); } /* now let's build a compound term */ if (!IsAtomTerm(d0)) { - Yap_AsmError(TYPE_ERROR_ATOM); + Yap_AsmError(TYPE_ERROR_ATOM,d0); FAIL(); } BEGP(pt1); @@ -2916,7 +2916,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); if (!Yap_gcl((1 + d1) * sizeof(CELL), 0, YREG, NEXTOP(NEXTOP(PREG, yxn), Osbpp))) { setregs(); - Yap_AsmError(RESOURCE_ERROR_STACK); + Yap_AsmError(RESOURCE_ERROR_STACK, d1); JMPNext(); } else { setregs(); @@ -2942,7 +2942,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); BEGP(pt1); deref_body(d0, pt1, func2s_y_unk_vc, func2s_y_nvar_vc); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -2990,7 +2990,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); BEGP(pt1); deref_body(d0, pt1, func2f_xx_unk, func2f_xx_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -3041,7 +3041,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); BEGP(pt1); deref_body(d0, pt1, func2f_xy_unk, func2f_xy_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -3092,7 +3092,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); BEGP(pt1); deref_body(d0, pt1, func2f_yx_unk, func2f_yx_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -3146,7 +3146,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); BEGP(pt1); deref_body(d0, pt1, func2f_yy_unk, func2f_yy_nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); @@ -3250,11 +3250,11 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); if (IsIntTerm(d1)) d1 = IntOfTerm(d1); else { - Yap_AsmError(TYPE_ERROR_INTEGER); + Yap_AsmError(TYPE_ERROR_INTEGER, d1); FAIL(); } if (!IsAtomicTerm(d0)) { - Yap_AsmError(TYPE_ERROR_ATOM); + Yap_AsmError(TYPE_ERROR_ATOM,d0); FAIL(); } /* We made it!!!!! we got in d0 the name, in d1 the arity and * in pt0 the variable to bind it to. */ @@ -3266,7 +3266,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); } else if ((Int)d1 > 0) { /* now let's build a compound term */ if (!IsAtomTerm(d0)) { - Yap_AsmError(TYPE_ERROR_ATOM); + Yap_AsmError(TYPE_ERROR_ATOM,d0); FAIL(); } BEGP(pt1); @@ -3283,7 +3283,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); if (!Yap_gcl((1 + d1) * sizeof(CELL), 3, YREG, NEXTOP(NEXTOP(PREG, e), Osbmp))) { setregs(); - Yap_AsmError(RESOURCE_ERROR_STACK); + Yap_AsmError(INSTANTIATION_ERROR,d1); } else { setregs(); } @@ -3297,7 +3297,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); HR = pt1; ENDP(pt1); } else if ((Int)d1 < 0) { - Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO); + Yap_AsmError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, MkIntegerTerm(d1)); FAIL(); } /* else if arity is 0 just pass d0 through */ @@ -3308,7 +3308,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); BEGP(pt1); deref_body(d1, pt1, func_var_3unk, func_var_3nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d1); ENDP(pt1); /* Oops, third argument was unbound */ FAIL(); @@ -3316,7 +3316,7 @@ Yap_AsmError( DOMAIN_ERROR_NOT_LESS_THAN_ZERO ); BEGP(pt1); deref_body(d0, pt1, func_var_2unk, func_var_2nvar); - Yap_AsmError(INSTANTIATION_ERROR); + Yap_AsmError(INSTANTIATION_ERROR,d0); ENDP(pt1); /* Oops, second argument was unbound too */ FAIL(); diff --git a/C/scanner.c b/C/scanner.c index 0b661653a..015d7c72b 100755 --- a/C/scanner.c +++ b/C/scanner.c @@ -457,6 +457,7 @@ static void Yap_setCurrentSourceLocation(struct stream_desc *s) { char_kind_t Yap_chtype0[NUMBER_OF_CHARS + 1] = { EF, /* nul soh stx etx eot enq ack bel bs ht nl vt np cr so si + */ BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, BS, @@ -630,18 +631,6 @@ static char *AllocScannerMemory(unsigned int size) { return AuxSpScan; } -static void PopScannerMemory(char *block, unsigned int size) { - CACHE_REGS - if (block == LOCAL_ScannerStack - size) { - LOCAL_ScannerStack -= size; - } else if (block == (char *)(LOCAL_ScannerExtraBlocks + 1)) { - struct scanner_extra_alloc *ptr = LOCAL_ScannerExtraBlocks; - - LOCAL_ScannerExtraBlocks = ptr->next; - free(ptr); - } -} - char *Yap_AllocScannerMemory(unsigned int size) { /* I assume memory has been initialized */ return AllocScannerMemory(size); @@ -1111,13 +1100,12 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) { /* given a function getchr scan until we either find the number or end of file */ -Term Yap_scan_num(StreamDesc *inp) { +Term Yap_scan_num(StreamDesc *inp, bool error_on) { CACHE_REGS Term out; int sign = 1; int ch, cherr; - char *ptr, *mp; - int kind; + char *ptr; void *old_tr = TR; InitScannerMemory(); @@ -1127,8 +1115,8 @@ Term Yap_scan_num(StreamDesc *inp) { LOCAL_Error_TYPE = RESOURCE_ERROR_TRAIL; return 0; } -#if HAVE_ISWBLANK - while (iswblank(ch = getchr(inp))) +#if HAVE_ISWSPACE + while (iswspace(ch = getchr(inp))) ; #else while (isspace(ch = getchr(inp))) @@ -1151,64 +1139,22 @@ Term Yap_scan_num(StreamDesc *inp) { return 0; } out = get_num(&ch, &cherr, inp, sign); /* */ - } - if (LOCAL_ErrorMessage != NULL || ch != -1 || cherr) { - CACHE_REGS - char *s = ptr; - int sign = 1; - + } else { out = 0; - if (s[0] == '+') { - s++; - } - if (s[0] == '-') { - s++; - sign = -1; - } - if (strcmp(s, "inf") == 0) { - if (sign > 0) { - out = MkFloatTerm(INFINITY); - } else { - out = MkFloatTerm(-INFINITY); - } - } - if (strcmp(s, "nan") == 0) { - if (sign > 0) { - out = MkFloatTerm(NAN); - } else { - out = MkFloatTerm(-NAN); - } - } - if (out == 0) { - TokEntry *e, *ef; - size_t len = strlen(ptr); - mp = AllocScannerMemory(len + 1); - tokptr->Tok = Ord(kind = String_tok); - tokptr->TokInfo = MkStringTerm(mp); - e = (TokEntry *)AllocScannerMemory(sizeof(TokEntry)); - ef = (TokEntry *)AllocScannerMemory(sizeof(TokEntry)); - tokptr->TokNext = e; - e->Tok = Error_tok; - if (!LOCAL_ErrorMessage) { - LOCAL_ErrorMessage = - "syntax error while converting from a string to a number"; - } - e->TokInfo = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage)); - e->TokPos = GetCurInpPos(inp); - e->TokNext = ef; - ef->Tok = Ord(kind = eot_tok); - ef->TokInfo = TermSyntaxError; - ef->TokPos = GetCurInpPos(inp); - ef->TokNext = NULL; - LOCAL_tokptr = tokptr; - LOCAL_toktide = e; - Yap_JumpToEnv( - Yap_syntax_error(e, inp - GLOBAL_Stream) ); - LOCAL_Error_TYPE = SYNTAX_ERROR; - } } - PopScannerMemory(ptr, 4096); - Yap_clean_tokenizer(old_tr, NULL, NULL); +#if HAVE_ISWSPACE + while (iswspace(ch = getchr(inp))) + ; +#else + while (isspace(ch = getchr(inp))) + ; +#endif + if (LOCAL_ErrorMessage != NULL || ch != -1 || cherr) { + Yap_clean_tokenizer(old_tr, NULL, NULL); + if (error_on) + Yap_Error(SYNTAX_ERROR, ARG2, "converting number"); + return 0; + } return out; } @@ -1225,35 +1171,86 @@ Term Yap_scan_num(StreamDesc *inp) { return l; \ } -const char *Yap_tokRep(void *tokptre, encoding_t encoding) { - CACHE_REGS - TokEntry *tokptr = tokptre; - Term info = tokptr->TokInfo; - size_t length; - UInt flags = 0; - - switch (tokptr->Tok) { - case Name_tok: - case Number_tok: - case Ponctuation_tok: - case String_tok: - case BQString_tok: - return Yap_TermToString(info, &length, encoding, flags); - case Var_tok: - { - VarEntry *varinfo = (VarEntry *)info; - varinfo->VarAdr = TermNil; - return RepAtom(varinfo->VarRep)->StrOfAE; - } - case Error_tok: - return ""; - case eot_tok: - return ""; - case QuasiQuotes_tok: - return ""; - } +Term Yap_tokRep(void *tokptre) { + CACHE_REGS + TokEntry *tokptr = tokptre; + Term info = tokptr->TokInfo; + + switch (tokptr->Tok) { + case Name_tok: + if (!info) { + info = TermNil; + } + return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info); + case QuasiQuotes_tok: + info = MkAtomTerm(Yap_LookupAtom("")); + return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info); + case Number_tok: + return Yap_MkApplTerm(Yap_MkFunctor(AtomAtom, 1), 1, &info); + break; + case Var_tok: { + Term t[2]; + VarEntry *varinfo = (VarEntry *)info; + if ((t[0]= varinfo->VarAdr) == TermNil) { + t[0] = varinfo->VarAdr = MkVarTerm(); + } + t[1] = MkAtomTerm((Atom)(varinfo->VarRep)); + return Yap_MkApplTerm(Yap_MkFunctor(AtomGVar, 2), 2, t); + } + case String_tok: + return Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &info); + case BQString_tok: + return Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &info); + case Error_tok: + return MkAtomTerm(AtomError); + case eot_tok: + return MkAtomTerm(Yap_LookupAtom("EOT")); + case Ponctuation_tok: + return info; + } + return TermDot; } + +const char * Yap_tokText(void *tokptre) { + CACHE_REGS + TokEntry *tokptr = tokptre; + Term info = tokptr->TokInfo; + + switch (tokptr->Tok) { + case eot_tok: + return "EOT"; + case Ponctuation_tok: + case Error_tok: + case BQString_tok: + case String_tok: + case Name_tok: + return AtomOfTerm(info)->StrOfAE; + case QuasiQuotes_tok: + return ""; + case Number_tok: + if (IsIntegerTerm(info)) { + char *s = Malloc(36); + snprintf(s, 35, Int_FORMAT, IntegerOfTerm(info)); + return s; + }else if (IsFloatTerm(info)) { + char *s = Malloc( 64); + snprintf(s, 63, "%6g", FloatOfTerm(info)); + return s; + } else { + size_t len = Yap_gmp_to_size(info,10); + char *s = Malloc(len+2); + return Yap_gmp_to_string(info,s, len+1,10); + } + break; + case Var_tok: + if (info == 0) return "[]"; + return ((Atom)info)->StrOfAE; + } + return "."; +} + + static void open_comment(int ch, StreamDesc *inp_stream USES_REGS) { CELL *h0 = HR; HR += 5; @@ -1314,6 +1311,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments, int solo_flag = TRUE; int32_t ch, och; struct qq_struct_t *cur_qq = NULL; + int sign = 1; InitScannerMemory(); LOCAL_VarTable = NULL; @@ -1331,7 +1329,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments, do { int quote, isvar; unsigned char *charp, *mp; - unsigned int len; + size_t len; unsigned char *TokImage = NULL; t = (TokEntry *)AllocScannerMemory(sizeof(TokEntry)); @@ -1396,8 +1394,8 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments, int32_t och = ch; ch = getchr(inp_stream); size_t sz = 512; - scan_name: TokImage = Malloc(sz PASS_REGS); + scan_name: charp = (unsigned char *)TokImage; isvar = (chtype(och) != LC); add_ch_to_buff(och); @@ -1446,13 +1444,16 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments, } break; - case NU: { + case NU: { int cherr; - int cha = ch; + int cha; + sign = 1; - cherr = 0; + scan_number: + cha = ch; + cherr = 0; CHECK_SPACE(); - if ((t->TokInfo = get_num(&cha, &cherr, inp_stream, 1)) == 0L) { + if ((t->TokInfo = get_num(&cha, &cherr, inp_stream, sign)) == 0L) { if (p) { p->Tok = eot_tok; t->TokInfo = TermError; @@ -1479,7 +1480,8 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments, case 'e': case 'E': och = cherr; - goto scan_name; + TokImage = Malloc(1024 PASS_REGS); + goto scan_name; break; case '=': case '_': @@ -1511,6 +1513,13 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments, { TokEntry *e2; + if (chtype(ch) == NU) { + if (och == '-') + sign = -1; + else + sign = 1; + goto scan_number; + } t->Tok = Name_tok; if (ch == '(') solo_flag = FALSE; @@ -1558,7 +1567,9 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments, LOCAL_ErrorMessage = "layout character \n inside quotes"; break; } - + if (ch == EOFCHAR) { + break; + } if (ch == quote) { ch = getchrq(inp_stream); if (ch != quote) @@ -1627,23 +1638,16 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments, break; case SY: { int pch; - if (ch == '.' && (pch = Yap_peek(inp_stream - GLOBAL_Stream)) && - (chtype(pch) == BS || chtype(pch) == EF || pch == '%')) { - t->Tok = Ord(kind = eot_tok); - // consume... - if (pch == '%') { - t->TokInfo = TermNewLine; - return l; + if (ch == '.' && (pch = Yap_peek(inp_stream - GLOBAL_Stream)) && + (chtype(pch) == BS || chtype(pch) == EF || pch == '%')) { + t->Tok = Ord(kind = eot_tok); + // consume... + if (pch == '%') { + t->TokInfo = TermNewLine; + return l; + } + return l; } - ch = getchr(inp_stream); - if (chtype(ch) == EF) { - mark_eof(inp_stream); - t->TokInfo = TermEof; - } else { - t->TokInfo = TermNewLine; - } - return l; - } if (ch == '`') goto quoted_string; och = ch; @@ -1664,7 +1668,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments, return l; } } - if (och == '/' && ch == '*') { + if (och == '/' && ch == '*') { if (store_comments) { CHECK_SPACE(); open_comment('/', inp_stream PASS_REGS); @@ -1721,7 +1725,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments, return l; } else { Atom ae; - size_t sz = 1024; + sz = 1024; TokImage = Malloc(sz); charp = TokImage; add_ch_to_buff(och); @@ -1949,13 +1953,6 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments, t->Tok = Ord(kind = eot_tok); t->TokInfo = TermEof; } -#if DEBUG - if (GLOBAL_Option[2]) { - static int n; - fprintf(stderr, "[Token %d %s %d]", Ord(kind), - Yap_tokRep(t, inp_stream->encoding), n++); - } -#endif if (LOCAL_ErrorMessage) { /* insert an error token to inform the system of what happened */ TokEntry *e = (TokEntry *)AllocScannerMemory(sizeof(TokEntry)); diff --git a/C/text.c b/C/text.c index 6034c3e1d..d6f361ebf 100644 --- a/C/text.c +++ b/C/text.c @@ -206,7 +206,7 @@ static Int SkipListCodes(unsigned char **bufp, Term *l, Term **tailp, (*atoms)++; if (*atoms < length) { *tailp = l; - return -TYPE_ERROR_NUMBER; + return -REPRESENTATION_ERROR_CHARACTER_CODE; } else { AtomEntry *ae = RepAtom(AtomOfTerm(hd)); if ((ae->StrOfAE)[1] != '\0') { @@ -219,10 +219,10 @@ static Int SkipListCodes(unsigned char **bufp, Term *l, Term **tailp, } else if (IsIntegerTerm(hd)) { ch = IntegerOfTerm(hd); if (*atoms) - length = -TYPE_ERROR_ATOM; + length = -REPRESENTATION_ERROR_CHARACTER; else if (ch < 0) { *tailp = l; - length = -DOMAIN_ERROR_NOT_LESS_THAN_ZERO; + length = -REPRESENTATION_ERROR_CHARACTER_CODE; } else { *wide |= ch > 0x80; } @@ -386,30 +386,34 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) { // this is a term, extract to a buffer, and representation is wide // Yap_DebugPlWriteln(inp->val.t); Atom at = AtomOfTerm(inp->val.t); + if (lengp) + *lengp = strlen_utf8(at->UStrOfAE); return at->UStrOfAE; } if (IsStringTerm(inp->val.t) && inp->type & YAP_STRING_STRING) { // this is a term, extract to a buffer, and representation is wide // Yap_DebugPlWriteln(inp->val.t); - return (unsigned char *)UStringOfTerm(inp->val.t); + if (lengp) + *lengp = strlen_utf8(UStringOfTerm(inp->val.t)); + return (unsigned char *)UStringOfTerm(inp->val.t); } if (((inp->type & (YAP_STRING_CODES | YAP_STRING_ATOMS)) == (YAP_STRING_CODES | YAP_STRING_ATOMS)) && IsPairOrNilTerm(inp->val.t)) { // Yap_DebugPlWriteln(inp->val.t); - return inp->val.uc = + return Yap_ListToBuffer(s0, inp->val.t, inp, &wide, lengp PASS_REGS); // this is a term, extract to a sfer, and representation is wide } if (inp->type & YAP_STRING_CODES && IsPairOrNilTerm(inp->val.t)) { // Yap_DebugPlWriteln(inp->val.t); - return inp->val.uc = Yap_ListOfCodesToBuffer(s0, inp->val.t, inp, &wide, + return Yap_ListOfCodesToBuffer(s0, inp->val.t, inp, &wide, lengp PASS_REGS); // this is a term, extract to a sfer, and representation is wide } if (inp->type & YAP_STRING_ATOMS && IsPairOrNilTerm(inp->val.t)) { // Yap_DebugPlWriteln(inp->val.t); - return inp->val.uc = Yap_ListOfAtomsToBuffer(s0, inp->val.t, inp, &wide, + return Yap_ListOfAtomsToBuffer(s0, inp->val.t, inp, &wide, lengp PASS_REGS); // this is a term, extract to a buffer, and representation is wide } @@ -426,22 +430,23 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) { AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), s, char); } *lengp = strlen(s); - Malloc(*lengp); - return inp->val.uc = (unsigned char *)s; + return (unsigned char *)s; } if (inp->type & YAP_STRING_FLOAT && IsFloatTerm(inp->val.t)) { char *s; + size_t sz = 1024; // Yap_DebugPlWriteln(inp->val.t); if (s0) - s = (char *)s0; + { s = (char *)s0; sz = strlen(s);} else - s = Malloc(0); + s = Malloc(sz); + if (!s) AUX_ERROR(inp->val.t, MaxTmp(PASS_REGS1), s, char); - if (!Yap_FormatFloat(FloatOfTerm(inp->val.t), &s, MaxTmp() - 1)) { - AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), s, char); + while (!Yap_FormatFloat(FloatOfTerm(inp->val.t), &s, sz - 1)) { + if (s0) { s = Malloc(sz=1024); s0 = NULL; } + else s = Realloc(s, sz+1024); } *lengp = strlen(s); - Malloc(*lengp); return inp->val.uc = (unsigned char *)s; } #if USE_GMP @@ -595,8 +600,7 @@ static Term write_codes(void *s0, seq_tv_t *out, size_t leng USES_REGS) { unsigned char *s = s0, *lim = s + strlen((char *)s); unsigned char *cp = s; - wchar_t w[2]; - w[1] = '\0'; + LOCAL_TERM_ERROR(t, 2 * (lim - s)); while (*cp) { utf8proc_int32_t chr; @@ -630,8 +634,11 @@ static Term write_codes(void *s0, seq_tv_t *out, size_t leng USES_REGS) { static Atom write_atom(void *s0, seq_tv_t *out, size_t leng USES_REGS) { unsigned char *s = s0; int32_t ch; - if (!leng || strlen_utf8(s0) <= leng) { - return Yap_LookupAtom(s0); + if ( leng == 0) { + return Yap_LookupAtom(""); + } + if ( strlen_utf8(s0) <= leng) { + return Yap_LookupAtom(s0); } else { size_t n = get_utf8(s, 1, &ch); unsigned char *buf = Malloc(n + 1); @@ -713,10 +720,10 @@ static size_t write_length(const unsigned char *s0, seq_tv_t *out, return leng; } -static Term write_number(unsigned char *s, seq_tv_t *out, int size USES_REGS) { +static Term write_number(unsigned char *s, seq_tv_t *out, int size, bool error_on USES_REGS) { Term t; int i = push_text_stack(); - t = Yap_StringToNumberTerm((char *)s, &out->enc); + t = Yap_StringToNumberTerm((char *)s, &out->enc, error_on); pop_text_stack(i); return t; } @@ -739,7 +746,7 @@ bool write_Text(unsigned char *inp, seq_tv_t *out, size_t leng USES_REGS) { return out->val.t != 0; } if (out->type & (YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG)) { - if ((out->val.t = write_number(inp, out, leng PASS_REGS)) != 0L) { + if ((out->val.t = write_number(inp, out, leng,!(out->type & YAP_STRING_ATOM) PASS_REGS)) != 0L) { // Yap_DebugPlWriteln(out->val.t); return true; @@ -790,7 +797,7 @@ bool write_Text(unsigned char *inp, seq_tv_t *out, size_t leng USES_REGS) { // Yap_DebugPlWriteln(out->val.t); return out->val.a != NULL; case YAP_STRING_INT | YAP_STRING_FLOAT | YAP_STRING_BIG: - out->val.t = write_number(inp, out, leng PASS_REGS); + out->val.t = write_number(inp, out, leng, true PASS_REGS); // Yap_DebugPlWriteln(out->val.t); return out->val.t != 0; default: { return true ; } @@ -898,8 +905,8 @@ static int cmp_Text(const unsigned char *s1, const unsigned char *s2, int l) { return 0; } -static unsigned char *concat(int n, unsigned char *sv[] USES_REGS) { - char *buf; +static unsigned char *concat(int n, void *sv[] USES_REGS) { + void *buf; unsigned char *buf0; size_t room = 0; int i; @@ -908,9 +915,14 @@ static unsigned char *concat(int n, unsigned char *sv[] USES_REGS) { room += strlen((char *)sv[i]); } buf = Malloc(room + 1); - buf0 = (unsigned char *)buf; + buf0 = buf; for (i = 0; i < n; i++) { +#if _WIN32 + strcpy(buf, sv[i]); + buf = (char*)buf + strlen(buf); +#else buf = stpcpy(buf, sv[i]); +#endif } return buf0; } @@ -932,7 +944,7 @@ static void *slice(size_t min, size_t max, unsigned char *buf USES_REGS) { // // Out must be an atom or a string bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) { - unsigned char **bufv; + void **bufv; unsigned char *buf; int i; size_t leng; @@ -951,7 +963,7 @@ bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) { bufv[i] = nbuf; } buf = concat(tot, bufv PASS_REGS); - bool rc = write_Text(buf, out, 0 PASS_REGS); + bool rc = write_Text(buf, out, strlen_utf8(buf) PASS_REGS); return rc; } @@ -1009,7 +1021,7 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp, next = 0; else next = cuts[i - 1]; - if (cuts[i] == 0) + if (i>0 && cuts[i] == 0) break; void *bufi = slice(next, cuts[i], buf PASS_REGS); if (!write_Text(bufi, outv + i, cuts[i] - next PASS_REGS)) { @@ -1022,7 +1034,7 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp, /** * Function to convert a generic text term (string, atom, list of codes, list -of +of< atoms) into a buff er. * @@ -1073,7 +1085,7 @@ const char *Yap_TextTermToText(Term t, char *buf, size_t len, encoding_t enc) { const char *Yap_PredIndicatorToUTF8String(PredEntry *ap) { CACHE_REGS Atom at; - arity_t arity; + arity_t arity = 0; Functor f; char *s, *smax, *s0; s = s0 = malloc(1024); diff --git a/C/write.c b/C/write.c index c9b8ada28..91064bdd7 100644 --- a/C/write.c +++ b/C/write.c @@ -565,9 +565,12 @@ static void write_string(const unsigned char *s, qt = '"'; wrputc(qt, stream); do { - ptr += get_utf8(ptr, -1, &chr); + int delta; + ptr += (delta = get_utf8(ptr, -1, &chr) ); + if (chr == '\0') break; + if (delta == 0) {chr = *ptr++; } write_quoted(chr, qt, stream); } while (TRUE); wrputc(qt, stream); diff --git a/CMakeLists.txt b/CMakeLists.txt index f89ffc07a..5a8c3097e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,11 +8,15 @@ project( YAP ) +if (ANDROID) + set(YAP_APP_DIR "$CMAKE_SOURCE_DIR/../..") + cmake_policy(VERSION 3.4) +else () cmake_minimum_required(VERSION 2.8) include(CMakeToolsHelpers OPTIONAL) -# cmake_policy(VERSION 3.4) +endif() set( CMAKE_MODULE_PATH @@ -43,6 +47,7 @@ include(Model NO_POLICY_SCOPE) include_directories ( utf8proc packages/myddas packages/myddas/sqlite3 ) if (ANDROID) + include_directories ( packages/myddas/sqlite3/Android/jni/sqlite/nativehelper packages/myddas/sqlite3/Android/jni/sqlite ) endif (ANDROID) add_definitions(-DUSE_MYDDAS=1 -DMYDDAS_SQLITE3=1) @@ -69,18 +74,12 @@ if (ANDROID) # # -set (SWIG_SOURCES ${CMAKE_SOURCE_DIR}/packages/swig/yap.i) -set (SWIG_CXX ${CMAKE_BINARY_DIR}/yap_swig.cpp) -find_host_package (SWIG) -macro_log_feature (SWIG_FOUND "Swig" - "Use SWIG Language Interface " -"http://www.swig.org" ON) - add_custom_command (OUTPUT ${SWIG_CXX} - COMMAND ${SWIG_EXECUTABLE} -c++ -java -package pt.up.yap.lib -outdir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/../../../../../src/generated/java -I${CMAKE_SOURCE_DIR}/CXX -o ${SWIG_CXX} - ${SWIG_SOURCES} - ) +set (SWIG_CXX ${CMAKE_BINARY_DIR}/packages/swig/android/yap_swig.cpp) + + +add_subdirectory("packages/swig") ADD_SUBDIRECTORY(os) ADD_SUBDIRECTORY(OPTYap) @@ -132,7 +131,7 @@ endif (USE_READLINE) if (ANDROID) - add_dependencies(libYap plmyddas) + add_dependencies(libYap plmyddas swig) target_link_libraries(libYap android log) diff --git a/CXX/yapa.hh b/CXX/yapa.hh index 924238099..212d40492 100644 --- a/CXX/yapa.hh +++ b/CXX/yapa.hh @@ -57,8 +57,10 @@ class YAPAtom { /// construct new YAPAtom from Atom YAPAtom( Atom at ) { a = at; } public: - /// construct new YAPAtom from UTF-8 string - YAPAtom( const char * s) { a = Yap_LookupAtom( s ); } + /// construct new YAPAtom from UTF-8 string + YAPAtom( const char * s) { a = Yap_LookupAtom( s ); } + /// construct new YAPAtom from UTF-8 string + YAPAtom( const wchar_t * s) { CACHE_REGS a = UTF32ToAtom( s PASS_REGS ); } /// construct new YAPAtom from wide string //YAPAtom( const wchar_t * s) { a = Yap_LookupMaybeWideAtom( s ); } /// construct new YAPAtom from max-length string diff --git a/CXX/yapdb.hh b/CXX/yapdb.hh index f80ae3fd4..2be2fb58f 100644 --- a/CXX/yapdb.hh +++ b/CXX/yapdb.hh @@ -97,7 +97,7 @@ public: /// Note: Python confuses the 3 constructors, /// use YAPFunctorFromWideString inline YAPFunctor(const wchar_t *s, uintptr_t arity) { - f = Yap_MkFunctor(Yap_LookupWideAtom(s), arity); + CACHE_REGS f = Yap_MkFunctor(UTF32ToAtom(s PASS_REGS), arity); } ~YAPFunctor(){}; /// Getter: extract name of functor as an atom diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp index 22dbdf9a0..63e32092c 100644 --- a/CXX/yapi.cpp +++ b/CXX/yapi.cpp @@ -412,31 +412,6 @@ YAPTerm YAPListTerm::car() { } } -YAPTerm::YAPTerm(YAPFunctor f, YAPTerm ts[]) { - CACHE_REGS - BACKUP_H(); - Functor fun = f.f; - arity_t arity = ArityOfFunctor(fun); - while (HR + arity > ASP - 1024) { - RECOVER_H(); - if (!Yap_dogc(0, NULL PASS_REGS)) { - t = TermNil; - } - BACKUP_H(); - } - if (fun == FunctorDot) { - t = AbsPair(HR); - HR[0] = ts[0].term(); - HR[1] = ts[1].term(); - } else { - t = AbsAppl(HR); - *HR++ = (CELL)fun; - for (arity_t i = 0; i < arity; i++) { - HR[i] = ts[i].term(); - } - RECOVER_H(); - } -} YAPListTerm::YAPListTerm(YAPTerm ts[], arity_t n) { CACHE_REGS @@ -519,12 +494,8 @@ bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) { } return false; } - // don't forget, on success these l); -if (!result) { + // don't forget, on success these bindings will still be there); YAP_LeaveGoal(false, &q); - } else { - YAP_LeaveGoal(FALSE, &q); - } RECOVER_MACHINE_REGS(); return result; } @@ -595,7 +566,7 @@ Term YAPEngine::fun(Term t) { BACKUP_MACHINE_REGS(); Term tmod = CurrentModule, *ts = nullptr; PredEntry *ap ; - arity_t arity = arity; + arity_t arity; Functor f; jmp_buf q_env; Atom name; @@ -612,9 +583,11 @@ Term YAPEngine::fun(Term t) { } else if (IsAtomTerm(t)) { name = AtomOfTerm(t); f = nullptr; + arity = 0; } else if (IsPairTerm(t)) { XREGS[1] = ts[0]; XREGS[2] = ts[1]; + arity = 2; name = AtomDot; f = FunctorDot; } else { @@ -653,12 +626,11 @@ Term YAPEngine::fun(Term t) { } __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", result); - Term result; t = Yap_GetFromSlot(q.CurSlot); Yap_CloseHandles(q.CurSlot); if (!t) { YAP_LeaveGoal(false, &q); - result = 0; + t = 0; } RECOVER_MACHINE_REGS(); return t; @@ -668,7 +640,7 @@ YAPQuery::YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm ts[]) : YAPPredicate(f, mod) { /* ignore flags for now */ BACKUP_MACHINE_REGS(); - goal = YAPTerm(f, ts); + goal = YAPApplTerm(f, ts); vnames = YAPListTerm(); openQuery(); RECOVER_MACHINE_REGS(); @@ -677,7 +649,7 @@ YAPQuery::YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm ts[]) YAPQuery::YAPQuery(YAPFunctor f, YAPTerm ts[]) : YAPPredicate(f) { /* ignore flags for now */ BACKUP_MACHINE_REGS(); - goal = YAPTerm(f, ts); + goal = YAPApplTerm(f, ts); vnames = YAPListTerm(); openQuery(); RECOVER_MACHINE_REGS(); @@ -685,7 +657,7 @@ YAPQuery::YAPQuery(YAPFunctor f, YAPTerm ts[]) : YAPPredicate(f) { YAPQuery::YAPQuery(YAPPredicate p, YAPTerm ts[]) : YAPPredicate(p.ap) { BACKUP_MACHINE_REGS(); - goal = YAPTerm(YAPFunctor(ap->FunctorOfPred), ts); + goal = YAPApplTerm(YAPFunctor(ap->FunctorOfPred), ts); vnames = YAPListTerm(); openQuery(); RECOVER_MACHINE_REGS(); diff --git a/CXX/yapt.hh b/CXX/yapt.hh index 0edd8d949..b375743be 100644 --- a/CXX/yapt.hh +++ b/CXX/yapt.hh @@ -39,12 +39,12 @@ public: } /// construct a term out of an integer (if you know object type use /// YAPIntegerTerm) - YAPTerm(long int num) { mk(MkIntegerTerm(num)); } + /// YAPTerm(long int num) { mk(MkIntegerTerm(num)); } /// construct a term out of an integer (if you know object type use /// YAPIntegerTerm) - YAPTerm(double num) { mk(MkFloatTerm(num)); } + /// YAPTerm(double num) { mk(MkFloatTerm(num)); } /// parse string s and construct a term. - YAPTerm(YAPFunctor f, YAPTerm ts[]); + /// YAPTerm(YAPFunctor f, YAPTerm ts[]); /// extract the tag of a term, after dereferencing. YAP_tag_t tag(); /// copy the term ( term copy ) @@ -322,8 +322,6 @@ class YAPAtomTerm : public YAPTerm { // Constructor: receives a C-atom; YAPAtomTerm(Atom a) { mk(MkAtomTerm(a)); } YAPAtomTerm(Term t) : YAPTerm(t) { IsAtomTerm(t); } - // Getter for Prolog atom - Term getTerm() { return t; } public: // Constructor: receives an atom; diff --git a/H/ATOMS b/H/ATOMS index 81f0ad055..07ac71035 100644 --- a/H/ATOMS +++ b/H/ATOMS @@ -196,6 +196,7 @@ A Id N "id" A Ignore N "ignore" A Inf N "inf" A Infinity N "infinity" +A Info N "info" A InitGoal F "$init_goal" A InitProlog F "$init_prolog" A InStackExpansion N "in stack expansion" @@ -495,6 +496,7 @@ F Dot6 Dot 6 F Dot7 Dot 7 F Dot8 Dot 8 F Dot9 Dot 9 +F DoubleArrow DoubleArrow 2 F DoubleSlash DoubleSlash 2 F EmptySquareBrackets EmptySquareBrackets 2 F Eq Eq 2 @@ -523,6 +525,10 @@ F HandleThrow HandleThrow 3 F Hat Hat 2 F I I 2 F Id Id 1 +F Info1 Info 1 +F Info2 Info 2 +F Info3 Info 3 +F Info4 Info 4 F Is Is 2 F J J 2 F LastExecuteWithin LastExecuteWithin 1 diff --git a/H/YapText.h b/H/YapText.h index c6c501b3b..57f16f969 100644 --- a/H/YapText.h +++ b/H/YapText.h @@ -40,7 +40,9 @@ extern void Free(void *buf USES_REGS); extern int push_text_stack( USES_REGS1 ); extern int pop_text_stack( int lvl USES_REGS ); +#ifndef min #define min(x,y) (x>/2"); + Yap_ArithError(RESOURCE_ERROR_HUGE_INT, t2, ">>/2"); } RINT(SLR(IntegerOfTerm(t1), -i2)); } return do_sll(IntegerOfTerm(t1), i2 PASS_REGS); } case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, "<>/2"); + Yap_ArithError(RESOURCE_ERROR_HUGE_INT, t2, ">>/2"); case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, "<>/2"); + Yap_ArithError(RESOURCE_ERROR_HUGE_INT, t2, ">>/2"); } return do_sll(IntegerOfTerm(t1), -i2 PASS_REGS); } RINT(SLR(IntegerOfTerm(t1), i2)); } case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, ">>/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t2, ">>/2"); case big_int_e: #ifdef USE_GMP - return Yap_ArithError(RESOURCE_ERROR_HUGE_INT, t2, ">>/2"); + Yap_ArithError(RESOURCE_ERROR_HUGE_INT, t2, ">>/2"); #endif default: RERROR(); } break; case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t1, ">>/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t1, ">>/2"); case big_int_e: #ifdef USE_GMP switch (ETypeOfTerm(t2)) { case long_int_e: return Yap_gmp_sll_big_int(t1, -IntegerOfTerm(t2)); case big_int_e: - return Yap_ArithError(RESOURCE_ERROR_HUGE_INT, t2, ">>/2"); + Yap_ArithError(RESOURCE_ERROR_HUGE_INT, t2, ">>/2"); case double_e: - return Yap_ArithError(TYPE_ERROR_INTEGER, t2, ">>/2"); + Yap_ArithError(TYPE_ERROR_INTEGER, t2, ">>/2"); default: RERROR(); } diff --git a/H/eval.h b/H/eval.h index 2d670f6d1..f61be284b 100644 --- a/H/eval.h +++ b/H/eval.h @@ -407,7 +407,7 @@ 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__) + Yap_ThrowError__(__FILE__, __FUNCTION__, __LINE__, id, t, 2, __VA_ARGS__) #define Yap_BinError(id) \ Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, 0L, "") #define Yap_AbsmiError(id) \ diff --git a/H/generated/iatoms.h b/H/generated/iatoms.h index 3507ac20e..9ebbb212f 100644 --- a/H/generated/iatoms.h +++ b/H/generated/iatoms.h @@ -191,6 +191,7 @@ AtomIgnore = Yap_LookupAtom("ignore"); TermIgnore = MkAtomTerm(AtomIgnore); AtomInf = Yap_LookupAtom("inf"); TermInf = MkAtomTerm(AtomInf); AtomInfinity = Yap_LookupAtom("infinity"); TermInfinity = MkAtomTerm(AtomInfinity); + AtomInfo = Yap_LookupAtom("info"); TermInfo = MkAtomTerm(AtomInfo); AtomInitGoal = Yap_FullLookupAtom("$init_goal"); TermInitGoal = MkAtomTerm(AtomInitGoal); AtomInitProlog = Yap_FullLookupAtom("$init_prolog"); TermInitProlog = MkAtomTerm(AtomInitProlog); AtomInStackExpansion = Yap_LookupAtom("in stack expansion"); TermInStackExpansion = MkAtomTerm(AtomInStackExpansion); @@ -490,6 +491,7 @@ FunctorDot7 = Yap_MkFunctor(AtomDot,7); FunctorDot8 = Yap_MkFunctor(AtomDot,8); FunctorDot9 = Yap_MkFunctor(AtomDot,9); + FunctorDoubleArrow = Yap_MkFunctor(AtomDoubleArrow,2); FunctorDoubleSlash = Yap_MkFunctor(AtomDoubleSlash,2); FunctorEmptySquareBrackets = Yap_MkFunctor(AtomEmptySquareBrackets,2); FunctorEq = Yap_MkFunctor(AtomEq,2); @@ -518,6 +520,10 @@ FunctorHat = Yap_MkFunctor(AtomHat,2); FunctorI = Yap_MkFunctor(AtomI,2); FunctorId = Yap_MkFunctor(AtomId,1); + FunctorInfo1 = Yap_MkFunctor(AtomInfo,1); + FunctorInfo2 = Yap_MkFunctor(AtomInfo,2); + FunctorInfo3 = Yap_MkFunctor(AtomInfo,3); + FunctorInfo4 = Yap_MkFunctor(AtomInfo,4); FunctorIs = Yap_MkFunctor(AtomIs,2); FunctorJ = Yap_MkFunctor(AtomJ,2); FunctorLastExecuteWithin = Yap_MkFunctor(AtomLastExecuteWithin,1); diff --git a/H/generated/ratoms.h b/H/generated/ratoms.h index e8f1fd332..1c5d5f8d8 100644 --- a/H/generated/ratoms.h +++ b/H/generated/ratoms.h @@ -191,6 +191,7 @@ AtomIgnore = AtomAdjust(AtomIgnore); TermIgnore = MkAtomTerm(AtomIgnore); AtomInf = AtomAdjust(AtomInf); TermInf = MkAtomTerm(AtomInf); AtomInfinity = AtomAdjust(AtomInfinity); TermInfinity = MkAtomTerm(AtomInfinity); + AtomInfo = AtomAdjust(AtomInfo); TermInfo = MkAtomTerm(AtomInfo); AtomInitGoal = AtomAdjust(AtomInitGoal); TermInitGoal = MkAtomTerm(AtomInitGoal); AtomInitProlog = AtomAdjust(AtomInitProlog); TermInitProlog = MkAtomTerm(AtomInitProlog); AtomInStackExpansion = AtomAdjust(AtomInStackExpansion); TermInStackExpansion = MkAtomTerm(AtomInStackExpansion); @@ -490,6 +491,7 @@ FunctorDot7 = FuncAdjust(FunctorDot7); FunctorDot8 = FuncAdjust(FunctorDot8); FunctorDot9 = FuncAdjust(FunctorDot9); + FunctorDoubleArrow = FuncAdjust(FunctorDoubleArrow); FunctorDoubleSlash = FuncAdjust(FunctorDoubleSlash); FunctorEmptySquareBrackets = FuncAdjust(FunctorEmptySquareBrackets); FunctorEq = FuncAdjust(FunctorEq); @@ -518,6 +520,10 @@ FunctorHat = FuncAdjust(FunctorHat); FunctorI = FuncAdjust(FunctorI); FunctorId = FuncAdjust(FunctorId); + FunctorInfo1 = FuncAdjust(FunctorInfo1); + FunctorInfo2 = FuncAdjust(FunctorInfo2); + FunctorInfo3 = FuncAdjust(FunctorInfo3); + FunctorInfo4 = FuncAdjust(FunctorInfo4); FunctorIs = FuncAdjust(FunctorIs); FunctorJ = FuncAdjust(FunctorJ); FunctorLastExecuteWithin = FuncAdjust(FunctorLastExecuteWithin); diff --git a/H/generated/tatoms.h b/H/generated/tatoms.h index 3f061d0ab..24d966852 100644 --- a/H/generated/tatoms.h +++ b/H/generated/tatoms.h @@ -191,6 +191,7 @@ EXTERNAL Atom AtomId; EXTERNAL Term TermId; EXTERNAL Atom AtomIgnore; EXTERNAL Term TermIgnore; EXTERNAL Atom AtomInf; EXTERNAL Term TermInf; EXTERNAL Atom AtomInfinity; EXTERNAL Term TermInfinity; +EXTERNAL Atom AtomInfo; EXTERNAL Term TermInfo; EXTERNAL Atom AtomInitGoal; EXTERNAL Term TermInitGoal; EXTERNAL Atom AtomInitProlog; EXTERNAL Term TermInitProlog; EXTERNAL Atom AtomInStackExpansion; EXTERNAL Term TermInStackExpansion; @@ -544,6 +545,8 @@ EXTERNAL Functor FunctorDot8; EXTERNAL Functor FunctorDot9; +EXTERNAL Functor FunctorDoubleArrow; + EXTERNAL Functor FunctorDoubleSlash; EXTERNAL Functor FunctorEmptySquareBrackets; @@ -600,6 +603,14 @@ EXTERNAL Functor FunctorI; EXTERNAL Functor FunctorId; +EXTERNAL Functor FunctorInfo1; + +EXTERNAL Functor FunctorInfo2; + +EXTERNAL Functor FunctorInfo3; + +EXTERNAL Functor FunctorInfo4; + EXTERNAL Functor FunctorIs; EXTERNAL Functor FunctorJ; diff --git a/Prelims.cmake b/Prelims.cmake index f7c9de1db..83aafe7b3 100644 --- a/Prelims.cmake +++ b/Prelims.cmake @@ -141,18 +141,20 @@ if(POLICY CMP0043) endif(POLICY CMP0043) +if (ANDROID) + set ( prefix ${YAP_APP_DIR}/app/build/generated ) + set ( datarootdir ${YAP_APP_DIR}/app/build/generated/assets ) +set ( includedir "${prefix}/assets/include") + set ( libpl ${YAP_APP_DIR}/app/build/generated/assets/Yap) +else() set ( prefix "${CMAKE_INSTALL_PREFIX}") +set ( datarootdir "${prefix}/share") + set ( libpl "${datarootdir}/Yap") +set ( includedir "${prefix}/include") +endif() set ( exec_prefix "${prefix}") set ( libdir "${exec_prefix}/lib") set ( dlls "${exec_prefix}/lib/Yap") -set ( includedir "${prefix}/include") -set ( datarootdir "${prefix}/share") -if (ANDROID) - set ( libpl "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/../../../../../build/generated/assets/Yap") -else() - set ( libpl "${datarootdir}/Yap") - -endif() set ( datadir "${datarootdir}") set ( mandir "${datarootdir}/man") set ( bindir "${exec_prefix}/bin") diff --git a/cmake/Config.cmake b/cmake/Config.cmake index 9c0abcae4..86ce9e31f 100644 --- a/cmake/Config.cmake +++ b/cmake/Config.cmake @@ -255,6 +255,7 @@ check_function_exists(__builtin_ffsll HAVE___BUILTIN_FFSLL) check_function_exists(fgetpos HAVE_FGETPOS) check_function_exists(finite HAVE_FINITE) check_function_exists(iswblank HAVE_ISWBLANK) +check_function_exists(iswspace HAVE_ISWSPACE) check_symbol_exists(flsl HAVE_FLSL) check_symbol_exists(flsll HAVE_FLSLL) check_function_exists(fmemopen HAVE_FMEMOPEN) diff --git a/config.h.cmake b/config.h.cmake index 9f34be495..02fab125e 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -586,6 +586,11 @@ function. */ #cmakedefine HAVE_ISWBLANK ${HAVE_ISWBLANK} #endif +/* Define to 1 if you have the `iswspace' function. */ +#ifndef HAVE_ISWSPACE +#cmakedefine HAVE_ISWSPACE ${HAVE_ISWSPACE} +#endif + /* Define to 1 if you have the header file. */ #ifndef HAVE_JUDY_H #cmakedefine HAVE_JUDY_H ${HAVE_JUDY_H} diff --git a/include/YapError.h b/include/YapError.h index 7fdb82142..9c68dbcce 100644 --- a/include/YapError.h +++ b/include/YapError.h @@ -42,7 +42,7 @@ struct yami *Yap_Error__(const char *file, const char *function, int lineno, yap_error_number err, YAP_Term wheret, ...); void Yap_ThrowError__(const char *file, const char *function, int lineno, - yap_error_number err, YAP_Term wheret, ...); + yap_error_number err, YAP_Term wheret, int code, ...) __attribute__ ((noreturn)); #define Yap_NilError(id, ...) \ @@ -51,8 +51,8 @@ void Yap_ThrowError__(const char *file, const char *function, int lineno, #define Yap_Error(id, inp, ...) \ Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, inp, __VA_ARGS__) -#define Yap_ThrowError(id, inp, ...) \ -Yap_ThrowError__(__FILE__, __FUNCTION__, __LINE__, id, inp, __VA_ARGS__) +#define Yap_ThrowError(id, inp, code, ...) \ +Yap_ThrowError__(__FILE__, __FUNCTION__, __LINE__, id, inp, code, __VA_ARGS__) #ifdef YAP_TERM_H /** diff --git a/library/lineutils.yap b/library/lineutils.yap index 1dbc2320f..8119a2f04 100644 --- a/library/lineutils.yap +++ b/library/lineutils.yap @@ -248,6 +248,49 @@ split_within(SplitCodes, DoubleQs, C-SingleQs, Strings, C) --> split_within(SplitCodes, DoubleQs, SingleQs, [[C|String]|Strings], C) --> split_within(SplitCodes, DoubleQs, SingleQs, [String|Strings]). +/** @pred split_unquoted(+ _Line_,+ _Separators_,- _Split_) + + + +Unify _Words_ with a set of strings obtained from _Line_ by +using the character codes in _Separators_ as separators, but treat text wi +thin double quotes as a single unit. As an +example, consider: + +~~~~~{.prolog} +?- split("Hello * I \"am free\""," *",S). + +S = ["Hello","I","am free"] ? + +no +~~~~~ + +*/ +split_unquoted(String, SplitCodes, Strings) :- + split_unquoted_at_blank(SplitCodes, Strings, String, []). + +split_unquoted_at_blank(SplitCodes, [[0'"|New]|More]) --> %0'" + "\"", + split_quoted(New, More), + split_unquoted_at_blank(SplitCodes, More). +split_unquoted_at_blank(SplitCodes, More) --> + [C], + { member(C, SplitCodes) }, !, + split_unquoted_at_blank(SplitCodes, More). +split_unquoted_at_blank(SplitCodes, [[C|New]| More]) --> + [C], !, + split_unquoted(SplitCodes, New, More). +split_unquoted_at_blank(_, []) --> []. + +split_unquoted(SplitCodes, [], More) --> + [C], + { member(C, SplitCodes) }, !, + split_unquoted_at_blank(SplitCodes, More). +split_unquoted(SplitCodes, [C|New], Set) --> + [C], !, + split_unquoted(SplitCodes, New, Set). +split_unquoted(_, [], []) --> []. + /** @pred split_quoted(+ _Line_,+ _Separators_, GroupQuotes, SingleQuotes, - _Split_) diff --git a/os/chartypes.c b/os/chartypes.c index b8e574e2a..f7019b3b9 100644 --- a/os/chartypes.c +++ b/os/chartypes.c @@ -79,7 +79,7 @@ static char SccsId[] = "%W% %G%"; static Int p_change_type_of_char(USES_REGS1); -Term Yap_StringToNumberTerm(const char *s, encoding_t *encp) { +Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, bool error_on) { CACHE_REGS int sno; Term t; @@ -95,7 +95,7 @@ Term Yap_StringToNumberTerm(const char *s, encoding_t *encp) { while (*s && isblank(*s) && Yap_wide_chtype(*s) == BS) s++; #endif - t = Yap_scan_num(GLOBAL_Stream + sno); + t = Yap_scan_num(GLOBAL_Stream + sno, error_on); if (LOCAL_Error_TYPE == SYNTAX_ERROR) LOCAL_Error_TYPE = YAP_NO_ERROR; Yap_CloseStream(sno); diff --git a/os/iopreds.h b/os/iopreds.h index 5a60e64bf..680562834 100644 --- a/os/iopreds.h +++ b/os/iopreds.h @@ -109,7 +109,7 @@ extern void Yap_plwrite(Term, struct stream_desc *, int, int, int); extern void Yap_WriteAtom(struct stream_desc *s, Atom atom); extern bool Yap_WriteTerm( int output_stream, Term t, Term opts USES_REGS); -extern Term Yap_scan_num(struct stream_desc *); +extern Term Yap_scan_num(struct stream_desc *, bool); extern void Yap_DefaultStreamOps(StreamDesc *st); extern void Yap_PipeOps(StreamDesc *st); diff --git a/os/readterm.c b/os/readterm.c index f1fea677c..34c63ae62 100644 --- a/os/readterm.c +++ b/os/readterm.c @@ -217,26 +217,26 @@ static const param_t read_defs[] = {READ_DEFS()}; */ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) { CACHE_REGS - Term info; Term startline, errline, endline; - Term tf[4]; - Term *tailp = tf + 3; + Term tf[3]; + Term tm; + Term *tailp = tf + 2; CELL *Hi = HR; TokEntry *tok = LOCAL_tokptr; Int cline = tok->TokPos; startline = MkIntegerTerm(cline); - if (errtok != LOCAL_toktide) { + endline = MkIntegerTerm(cline); + if (errtok != LOCAL_toktide) { errtok = LOCAL_toktide; } LOCAL_Error_TYPE = YAP_NO_ERROR; errline = MkIntegerTerm(errtok->TokPos); if (LOCAL_ErrorMessage) - tf[0] = MkStringTerm(LOCAL_ErrorMessage); + tm = MkStringTerm(LOCAL_ErrorMessage); else - tf[0] = MkStringTerm(""); + tm = MkStringTerm("syntax error"); while (tok) { - Term ts[2]; if (HR > ASP - 1024) { errline = MkIntegerTerm(0); @@ -254,57 +254,7 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) { *tailp = MkPairTerm(MkAtomTerm(AtomError), TermNil); tailp = RepPair(*tailp) + 1; } - info = tok->TokInfo; - switch (tok->Tok) { - case Name_tok: { - Term t0[1]; - if (info) { - t0[0] = MkAtomTerm((Atom)info); - } else { - 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 Number_tok: - ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomNumber, 1), 1, &info); - break; - case Var_tok: { - Term t[2]; - VarEntry *varinfo = (VarEntry *)info; - - 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: { - ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &info); - } break; - case BQString_tok: { - ts[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomString, 1), 1, &info); - } 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)); - } - } + Term rep = Yap_tokRep(tok ); if (tok->TokNext) { tok = tok->TokNext; } else { @@ -312,7 +262,7 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) { tok = NULL; break; } - *tailp = MkPairTerm(ts[0], TermNil); + *tailp = MkPairTerm(rep , TermNil); tailp = RepPair(*tailp) + 1; } { @@ -320,19 +270,18 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) { t[0] = startline; t[1] = errline; t[2] = endline; - tf[1] = Yap_MkApplTerm(Yap_MkFunctor(AtomBetween, 3), 3, t); + tf[0] = Yap_MkApplTerm(Yap_MkFunctor(AtomBetween, 3), 3, t); } - /* 0: id */ - /* 1: strat, error, end line */ + /* 0: strat, error, end line */ /*2 msg */ - /* file */ - tf[2] = Yap_StreamUserName(sno); + /* 1: file */ + tf[1] = Yap_StreamUserName(sno); clean_vars(LOCAL_VarTable); clean_vars(LOCAL_AnonVarTable); - Term terr = Yap_MkApplTerm(FunctorSyntaxError, 4, tf); + Term terr = Yap_MkApplTerm(FunctorInfo3, 3, tf); Term tn[2]; - tn[0] = Yap_MkApplTerm(FunctorShortSyntaxError, 1, &terr); - tn[1] = TermNil; + tn[0] = Yap_MkApplTerm(FunctorShortSyntaxError, 1, &tm); + tn[1] = terr; terr = Yap_MkApplTerm(FunctorError, 2, tn); #if DEBUG if (Yap_ExecutionMode == YAP_BOOT_MODE) { @@ -401,7 +350,6 @@ static xarg *setReadEnv(Term opts, FEnv *fe, struct renv *re, int inp_stream) { fe->cmod = PROLOG_MODULE; if (args[READ_BACKQUOTED_STRING].used) { if (!setBackQuotesFlag(args[READ_BACKQUOTED_STRING].tvalue)) { - free(args); return false; } } @@ -695,7 +643,7 @@ 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; + 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 */ @@ -782,10 +730,11 @@ static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) { TokEntry *t = LOCAL_tokptr; int n = 0; while (t) { - fprintf(stderr, "[Token %d %s %d]", Ord(t->Tok), - Yap_tokRep(t, ENC_ISO_UTF8), n++); + fprintf(stderr, "[Token %d %s %d]", + Ord(t->Tok),Yap_tokText(t), n++); t = t->TokNext; } + fprintf(stderr, "\n"); } #endif if (LOCAL_ErrorMessage) @@ -856,14 +805,12 @@ static parser_state_t parseError(REnv *re, FEnv *fe, int inp_stream) { LOCAL_Error_TYPE = YAP_NO_ERROR; return YAP_PARSING_FINISHED; } else { - char *s = syntax_error(fe->toklast, inp_stream, fe->cmod); + Term t = syntax_error(fe->toklast, inp_stream, fe->cmod); if (ParserErrorStyle == TermError) { - LOCAL_ErrorMessage = s; + LOCAL_ActiveError->errorTerm = Yap_StoreTermInDB( t, 4); LOCAL_Error_TYPE = SYNTAX_ERROR; - return YAP_PARSING_FINISHED; // dec-10 - } else if (Yap_PrintWarning(MkStringTerm(s))) { - free(s); + } else if (Yap_PrintWarning(t)) { LOCAL_Error_TYPE = YAP_NO_ERROR; return YAP_SCANNING; } diff --git a/os/sysbits.c b/os/sysbits.c index 1480cf946..c5a8ee9c0 100644 --- a/os/sysbits.c +++ b/os/sysbits.c @@ -1926,34 +1926,8 @@ static HKEY reg_open_key(const wchar_t *which, int create) { #define MAXREGSTRLEN 1024 -static void recover_space(wchar_t *k, Atom At) { - if (At->WStrOfAE != k) - Yap_FreeCodeSpace((char *)k); -} - static wchar_t *WideStringFromAtom(Atom KeyAt USES_REGS) { - if (IsWideAtom(KeyAt)) { - return KeyAt->WStrOfAE; - } else { - int len = strlen(KeyAt->StrOfAE); - int sz = sizeof(wchar_t) * (len + 1); - char *chp = KeyAt->StrOfAE; - wchar_t *kptr, *k; - - k = (wchar_t *)Yap_AllocCodeSpace(sz); - while (k == NULL) { - if (!Yap_growheap(false, sz, NULL)) { - Yap_Error(RESOURCE_ERROR_HEAP, MkIntegerTerm(sz), - "generating key in win_registry_get_value/3"); - return false; - } - k = (wchar_t *)Yap_AllocCodeSpace(sz); - } - kptr = k; - while ((*kptr++ = *chp++)) - ; - return k; - } + return Yap_AtomToWide( KeyAt ); } static Int p_win_registry_get_value(USES_REGS1) { @@ -1965,24 +1939,29 @@ static Int p_win_registry_get_value(USES_REGS1) { Term Key = Deref(ARG1); Term Name = Deref(ARG2); Atom KeyAt, NameAt; + int l = push_text_stack(); if (IsVarTerm(Key)) { Yap_Error(INSTANTIATION_ERROR, Key, "argument to win_registry_get_value unbound"); - return FALSE; + pop_text_stack(l); + return FALSE; } if (!IsAtomTerm(Key)) { Yap_Error(TYPE_ERROR_ATOM, Key, "argument to win_registry_get_value"); - return FALSE; + pop_text_stack(l); + return FALSE; } KeyAt = AtomOfTerm(Key); if (IsVarTerm(Name)) { Yap_Error(INSTANTIATION_ERROR, Key, "argument to win_registry_get_value unbound"); - return FALSE; + pop_text_stack(l); + return FALSE; } if (!IsAtomTerm(Name)) { Yap_Error(TYPE_ERROR_ATOM, Key, "argument to win_registry_get_value"); +pop_text_stack(l); return FALSE; } NameAt = AtomOfTerm(Name); @@ -1990,7 +1969,7 @@ static Int p_win_registry_get_value(USES_REGS1) { k = WideStringFromAtom(KeyAt PASS_REGS); if (!(key = reg_open_key(k, FALSE))) { Yap_Error(EXISTENCE_ERROR_KEY, Key, "argument to win_registry_get_value"); - recover_space(k, KeyAt); +pop_text_stack(l); return FALSE; } name = WideStringFromAtom(NameAt PASS_REGS); @@ -1999,26 +1978,22 @@ static Int p_win_registry_get_value(USES_REGS1) { RegCloseKey(key); switch (type) { case REG_SZ: - recover_space(k, KeyAt); - recover_space(name, NameAt); ((wchar_t *)data)[len] = '\0'; - return Yap_unify(MkAtomTerm(Yap_LookupMaybeWideAtom((wchar_t *)data)), - ARG3); + Atom at = Yap_NWCharsToAtom((wchar_t *)data, len PASS_REGS); + pop_text_stack(l); + return Yap_unify(MkAtomTerm(at),ARG3); case REG_DWORD: - recover_space(k, KeyAt); - recover_space(name, NameAt); - { + { DWORD *d = (DWORD *)data; +pop_text_stack(l); return Yap_unify(MkIntegerTerm((Int)d[0]), ARG3); } default: - recover_space(k, KeyAt); - recover_space(name, NameAt); - return FALSE; + pop_text_stack(l); + return FALSE; } } - recover_space(k, KeyAt); - recover_space(name, NameAt); +pop_text_stack(l); return FALSE; } diff --git a/os/writeterm.c b/os/writeterm.c index 381c5dea1..e35dea94c 100644 --- a/os/writeterm.c +++ b/os/writeterm.c @@ -224,7 +224,7 @@ static bool write_term(int output_stream, Term t, xarg *args USES_REGS) { flags |= AttVar_Dots_f; } else if (ctl != TermIgnore) { Yap_Error( - DOMAIN_ERROR_OUT_OF_RANGE, ctl, + DOMAIN_ERROR_WRITE_OPTION, ctl, "write attributes should be one of {dots,ignore,portray,write}"); rc = false; goto end; diff --git a/os/yapio.h b/os/yapio.h index cd1e83f34..8ce7d80ca 100644 --- a/os/yapio.h +++ b/os/yapio.h @@ -107,7 +107,7 @@ extern char *Yap_MemStreamBuf(int sno); extern X_API Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp, int prio, Term *bindings_p); -extern Term Yap_StringToNumberTerm(const char *s, encoding_t *encp); +extern Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, bool error_on); extern int Yap_FormatFloat(Float f, char **s, size_t sz); extern int Yap_open_buf_read_stream(const char *buf, size_t nchars, encoding_t *encp, memBufSource src); diff --git a/packages/cplint/approx/simplecuddLPADs/simplecudd.c b/packages/cplint/approx/simplecuddLPADs/simplecudd.c index 17fd46949..234ef9c4f 100644 --- a/packages/cplint/approx/simplecuddLPADs/simplecudd.c +++ b/packages/cplint/approx/simplecuddLPADs/simplecudd.c @@ -388,7 +388,7 @@ int simpleNamedBDDtoDot(DdManager *manager, namedvars varmap, DdNode *bdd, perror(filename); return -1; } - const char *vs = varmap.vars; + const char **vs = varmap.vars; ret = Cudd_DumpDot(manager, 1, f, vs, NULL, fd); fclose(fd); return ret; diff --git a/packages/myddas/sqlite3/myddas_sqlite3.c b/packages/myddas/sqlite3/myddas_sqlite3.c index 80954c466..1db67f3c5 100644 --- a/packages/myddas/sqlite3/myddas_sqlite3.c +++ b/packages/myddas/sqlite3/myddas_sqlite3.c @@ -586,8 +586,7 @@ static Int c_sqlite3_row(USES_REGS1) { } else if (res == SQLITE_ROW) { list = arg_list_args; - Term tf; - + Term tf = 0; for (i = 0; i < arity; i++) { /* convert data types here */ head = HeadOfTerm(list); diff --git a/packages/swig/android/CMakeLists.txt b/packages/swig/android/CMakeLists.txt index fa2e4c4c1..f4dc3b56c 100644 --- a/packages/swig/android/CMakeLists.txt +++ b/packages/swig/android/CMakeLists.txt @@ -1,25 +1,21 @@ # This is a CMake example for Python and Java - INCLUDE(UseJava) - - - - # set(ANDROID_SO_OUTDIR ${libdir}) - # set(CMAKE_SWIG_OUTDIR ${CMAKE_SOURCE_DIR}/android/yaplib/build/generated/source/pt/up/yap/lib) - #set(CMAKE_SWIG_OUTDIR ${CMAKE_CURRENT_BINARY_DIR}/derived) + set(CMAKE_SWIG_OUTDIR ${YAP_APP_DIR}/app/src/main/java/pt/up/yap/lib ) + set ( SWIG_SOURCES ../yap.i ) SET_SOURCE_FILES_PROPERTIES(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON) include_directories ( ${CMAKE_SOURCE_DIR}/CXX - ${JAVA_INCLUDE_DIRS} - ${JNI_INCLUDE_DIRS} + ) + + add_custom_target ( swig ALL + DEPENDS ${SWIG_CXX} ) - - add_custom_command (OUTPUT ${SWIG_CXX} - COMMAND ${SWIG} -java -outdir ${CMAKE_CURRENT_BINARY_DIR} -c++ -addextern -I${CMAKE_SOURCE_DIR}/CXX ${SWIG_SOURCES} -o ${SWIG_CXX} - ${SWIG_SOURCES} + add_custom_command (OUTPUT ${SWIG_CXX} + COMMAND ${SWIG} -java -outdir ${CMAKE_SWIG_OUTDIR} -c++ -addextern -I${CMAKE_SOURCE_DIR}/CXX -o ${SWIG_CXX}${SWIG_SOURCES} ) + diff --git a/pl/atoms.yap b/pl/atoms.yap index 23e5d2e61..f3dd5d967 100644 --- a/pl/atoms.yap +++ b/pl/atoms.yap @@ -165,8 +165,6 @@ current_atom(A) :- % check atom(A), !. current_atom(A) :- % generate '$current_atom'(A). -current_atom(A) :- % generate - '$current_wide_atom'(A). string_concat(Xs,At) :- ( var(At) -> diff --git a/pl/boot.yap b/pl/boot.yap index 5b6972631..106d9a0dd 100644 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -1,3 +1,4 @@ + /************************************************************************* * * * YAP Prolog * @@ -174,7 +175,7 @@ list, since backtracking could not "pass through" the cut. system_module(_Mod, _SysExps, _Decls). % new_system_module(Mod). -use_system_module(Module, _SysExps). +use_system_module(_Module, _SysExps). private(_). @@ -291,8 +292,9 @@ private(_). '$bootstrap_predicate'(print_message(Context, Msg), _M, _) :- !, '$early_print_message'(Context, Msg). '$bootstrap_predicate'(print_message(Context, Msg), _M, _) :- !, - '$early_print_message'(Context, Msg). -'$bootstrap_predicate'(prolog_file_type(A,B), _, prolog_file_type(A,B)) :- !, B = prolog. + '$early_print_message'(Context, Msg). +'$bootstrap_predicate'(prolog_file_type(A,prolog), _, _) :- !, + ( A = yap ; A = pl ; A = prolog ). '$bootstrap_predicate'(file_search_path(_A,_B), _, _ ) :- !, fail. '$bootstrap_predicate'(meta_predicate(G), M, _) :- !, strip_module(M:G, M1, G1), @@ -446,7 +448,6 @@ live :- W1 is W-1, '$start_orp_threads'(W1). - % Start file for yap /* I/O predicates */ @@ -1428,7 +1429,7 @@ Command = (H --> B) -> '$check_head_and_body'(MH, M, H, true, P) :- '$yap_strip_module'(MH,M,H), - error:is_callable(M:H,P). + is_callable(M:H,P). % term expansion % % return two arguments: Expanded0 is the term after "USER" expansion. @@ -1453,8 +1454,8 @@ Command = (H --> B) -> '$precompile_term'(Term, Term, Term). '$expand_clause'(InputCl, C1, CO) :- - source_module(SM), - '$yap_strip_module'(SM:InputCl, M, ICl), + source_module(SM), + '$yap_strip_clause'(SM:InputCl, M, ICl), '$expand_a_clause'( M:ICl, SM, C1, CO), !. '$expand_clause'(Cl, Cl, Cl). diff --git a/pl/dbload.yap b/pl/dbload.yap index 4506db1d1..6e2dd3781 100644 --- a/pl/dbload.yap +++ b/pl/dbload.yap @@ -29,10 +29,7 @@ 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, Type, Lines). '$input_lines'(R, csv, yeLines ) :- '$process_lines'(R, Lines, Type ), diff --git a/pl/errors.yap b/pl/errors.yap index a273e1125..231c54833 100644 --- a/pl/errors.yap +++ b/pl/errors.yap @@ -138,6 +138,8 @@ system_error(Type,Goal,Culprit) :- throw(error(permission_error(module,redefined,A),B)). '$process_error'(error(Msg, Where), _) :- print_message(error,error(Msg, Where)), !. +'$process_error'(error(Msg, Where), _) :- + print_message(error,error(Msg, [g|Where])), !. '$process_error'(Throw, _) :- print_message(error,error(unhandled_exception,Throw)). diff --git a/pl/messages.yap b/pl/messages.yap index 3f574e35a..14553d528 100644 --- a/pl/messages.yap +++ b/pl/messages.yap @@ -65,6 +65,34 @@ messages that do not produce output but that can be intercepted by hooks. The next table shows the main predicates and hooks associated to message handling in YAP: + +An error record comsists of An ISO compatible descriptor of the format + +error(errror_kind(Culprit,..), Info) + +In YAP, the infoo field describes: + +- what() more detauls on the event + +- input_stream, may be ine of; + + - loop_sream + - file() + - none + + - prolog_source(_) a record containing file, line, predicate, and clause + that activated the goal, or a list therof. YAP tries to search for the user + code generatinng the error. + + - c_source(0), a record containing the line of C-code thhat caused the event. This + is reported under systm debugging mode, or if this is user code. + + - stream_source() - a record containg data on the the I/O stream datum causisng the evwnt. + + - user_message () - ttext on the event. + + + @{ */ @@ -210,11 +238,11 @@ compose_message(Term, Level) --> main_message( Term, Level, LC), [nl,nl]. -location(error(syntax_error(syntax_error(_,between(_,LN,_),FileName,_)),_), _ , _) --> - !, - [ '~a:~d:0 ' - [FileName,LN] ] . +location(error(syntax_error(_),info(between(_,LN,_), FileName, _)), _ , _) --> + !, + [ '~a:~d:~d ' - [FileName,LN,0] ] . + location(error(style_check(style_check(_,LN,FileName,_ ) ),_), _ , _) --> - % { stream_position_data( line_count, LN) }, !, [ '~a:~d:0 ' - [FileName,LN] ] . location( error(_,Term), Level, LC ) --> @@ -231,7 +259,7 @@ location( error(_,Term), Level, LC ) --> %message(loaded(Past,AbsoluteFileName,user,Msec,Bytes), Prefix, Suffix) :- !, main_message(error(Msg,Info), _, _) --> {var(Info)}, !, [ ' error: uninstantiated message ~w~n.' - [Msg], nl ]. -main_message( error(syntax_error(syntax_error(Msg,between(L0,LM,LF),_Stream,Term)),_), Level, LC ) --> +main_message( error(syntax_error(Msg),info(between(L0,LM,LF),_Stream,Term)), Level, LC ) --> !, [' ~a: syntax error ~s' - [Level,Msg]], [nl], @@ -602,7 +630,7 @@ list_of_preds([P|L]) --> list_of_preds(L). syntax_error_term(between(_I,_J,_L),LTaL,LC) --> - ['error found at line ~d to line ~d' - [_I,_L], nl ], + ['term between lines ~d and ~d' - [_I,_L], nl ], syntax_error_tokens(LTaL, LC). syntax_error_tokens([], _LC) --> []. @@ -615,7 +643,7 @@ syntax_error_token(atom(A), _LC) --> !, syntax_error_token(number(N), _LC) --> !, [ '~w' - [N] ]. syntax_error_token(var(_,S), _LC) --> !, - [ '~s' - [S] ]. + [ '~a' - [S] ]. syntax_error_token(string(S), _LC) --> !, [ '`~s`' - [S] ]. syntax_error_token(error, _LC) --> !, diff --git a/pl/meta.yap b/pl/meta.yap index ed4732567..e5a4dd814 100644 --- a/pl/meta.yap +++ b/pl/meta.yap @@ -284,14 +284,14 @@ meta_predicate declaration nonvar(G), G = (A = B), !. -'$expand_goals'(\+A,\+A1,(AO-> false;true),HM,SM,BM,HVars) :- !, +'$expand_goals'(\+A,\+A1,('$current_choice_point'(CP),AO,'$$cut_by'(CP)-> false;true),HM,SM,BM,HVars) :- !, '$expand_goals'(A,A1,AO,HM,SM,BM,HVars). '$expand_goals'(once(A),once(A1), ('$current_choice_point'(CP),AO,'$$cut_by'(CP)),HM,SM,BM,HVars) :- !, '$expand_goals'(A,A1,AO0,HM,SM,BM,HVars), '$clean_cuts'(AO0, CP, AO). '$expand_goals'(ignore(A),ignore(A1), - (AO -> true ; true),HM,SM,BM,HVars) :- !, + ('$current_choice_point'(CP),AO,'$$cut_by'(CP)-> true ; true),HM,SM,BM,HVars) :- !, '$expand_goals'(A,A1,AO0,HM,SM,BM,HVars), '$clean_cuts'(AO0, AO). '$expand_goals'(forall(A,B),forall(A1,B1), @@ -299,7 +299,7 @@ meta_predicate declaration '$expand_goals'(A,A1,AO0,HM,SM,BM,HVars), '$expand_goals'(B,B1,BO,HM,SM,BM,HVars), '$clean_cuts'(AO0, AO). -'$expand_goals'(not(A),not(A1),(AO -> fail; true),HM,SM,BM,HVars) :- !, +'$expand_goals'(not(A),not(A1),('$current_choice_point'(CP),AO,'$$cut_by'(CP) -> fail; true),HM,SM,BM,HVars) :- !, '$expand_goals'(A,A1,AO,HM,SM,BM,HVars). '$expand_goals'(if(A,B,C),if(A1,B1,C1), ('$current_choicepoint'(DCP),AO,yap_hacks:cut_at(DCP),BO; CO),HM,SM,BM,HVars) :- !, diff --git a/pl/modules.yap b/pl/modules.yap index 60fd7e62e..6f9f70e6a 100644 --- a/pl/modules.yap +++ b/pl/modules.yap @@ -338,8 +338,8 @@ system_module(Mod) :- '$pred_exists'(Pred, Mod), !. '$continue_imported'(FM,Mod,FPred,Pred) :- - recorded('$import','$import'(IM,Mod,IPred,Pred,_,_),_), !, - '$continue_imported'(FM, IM, FPred, IPred). + recorded('$import','$import'(IM,Mod,IPred,Pred,_,_),_), + '$continue_imported'(FM, IM, FPred, IPred), !. '$continue_imported'(FM,Mod,FPred,Pred) :- prolog:'$parent_module'(Mod,IM), '$continue_imported'(FM, IM, FPred, Pred). diff --git a/pl/preddyns.yap b/pl/preddyns.yap index 95f5e7091..13a202837 100644 --- a/pl/preddyns.yap +++ b/pl/preddyns.yap @@ -51,6 +51,7 @@ assert(Clause) :- '$assert'(Clause, assertz, _). '$assert'(Clause, Where, R) :- +'$yap_strip_clause'(Clause, _, _Clause0), '$expand_clause'(Clause,C0,C), '$$compile'(C, Where, C0, R). diff --git a/pl/signals.yap b/pl/signals.yap index 1729c9510..9990ff2c0 100644 --- a/pl/signals.yap +++ b/pl/signals.yap @@ -192,7 +192,7 @@ order of dispatch. '$hacks':'$stack_dump', '$execute0'(G,M). '$do_signal'(sig_fpe,G) :- - '$signal_handler'(sig_fpe, G) + '$signal_handler'(sig_fpe, G). '$do_signal'(sig_alarm, G) :- '$signal_handler'(sig_alarm, G). '$do_signal'(sig_vtalarm, G) :- From c49165a7af1a65546ae15d1f76020f2db2d803e9 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 11 Nov 2016 01:23:34 -0600 Subject: [PATCH 05/41] Android aupport --- C/text.c | 2 +- CMakeLists.txt | 44 +++++++++-------- CXX/yapi.cpp | 11 +++-- CXX/yapq.hh | 2 +- OPTYap/opt.preds.c | 2 +- OPTYap/opt.structs.h | 9 ++-- Prelims.cmake | 20 ++------ libYap.cmake | 2 +- packages/myddas/CMakeLists.txt | 1 - packages/myddas/pl/CMakeLists.txt | 10 ++-- packages/myddas/sqlite3/CMakeLists.txt | 65 ++++++++++++-------------- packages/swig/android/CMakeLists.txt | 8 ++-- 12 files changed, 81 insertions(+), 95 deletions(-) diff --git a/C/text.c b/C/text.c index d6f361ebf..727783149 100644 --- a/C/text.c +++ b/C/text.c @@ -917,7 +917,7 @@ static unsigned char *concat(int n, void *sv[] USES_REGS) { buf = Malloc(room + 1); buf0 = buf; for (i = 0; i < n; i++) { -#if _WIN32 +#if _WIN32 || defined( __ANDROID__ ) strcpy(buf, sv[i]); buf = (char*)buf + strlen(buf); #else diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a8c3097e..e8dc34a2f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,8 +9,9 @@ project( YAP ) if (ANDROID) - set(YAP_APP_DIR "$CMAKE_SOURCE_DIR/../..") + set(YAP_APP_DIR "${CMAKE_SOURCE_DIR}/../..") cmake_policy(VERSION 3.4) + else () cmake_minimum_required(VERSION 2.8) include(CMakeToolsHelpers OPTIONAL) @@ -38,6 +39,19 @@ include (GNUInstallDirs) # You can define multiple libraries, and CMake builds it for you. # Gradle automatically packages shared libraries with your APK. +#cross-compilation support +# Search packages for host system instead of packages for target system +# in case of cross compilation these macro should be defined by toolchain file +if(NOT COMMAND find_host_package) + macro(find_host_package) + find_package(${ARGN}) + endmacro() +endif() +if(NOT COMMAND find_host_program) + macro(find_host_program) + find_program(${ARGN}) + endmacro() +endif() include(Prelims NO_POLICY_SCOPE) @@ -45,11 +59,10 @@ include(Sources NO_POLICY_SCOPE) include(Model NO_POLICY_SCOPE) -include_directories ( utf8proc packages/myddas packages/myddas/sqlite3 ) -if (ANDROID) - - include_directories ( packages/myddas/sqlite3/Android/jni/sqlite/nativehelper packages/myddas/sqlite3/Android/jni/sqlite ) -endif (ANDROID) +include_directories ( utf8proc packages/myddas packages/myddas/sqlite3 + packages/myddas/sqlite3/Android/jni/sqlite + packages/myddas/sqlite3/Android/jni/sqlite/nativehelper + ) add_definitions(-DUSE_MYDDAS=1 -DMYDDAS_SQLITE3=1) if (MYSQL_FOUND) @@ -66,21 +79,6 @@ if (MYSQL_POSTGRES) if (ANDROID) - # - # SWIG_FOUND - set to true if SWIG is found - # SWIG_DIR - t he directory where swig is installed - # SWIG_EXECUTABLE - the path to the swig executable - # SWIG_VERSION - the version number of the swig executable - # - - # - - -set (SWIG_CXX ${CMAKE_BINARY_DIR}/packages/swig/android/yap_swig.cpp) - - -add_subdirectory("packages/swig") - ADD_SUBDIRECTORY(os) ADD_SUBDIRECTORY(OPTYap) ADD_SUBDIRECTORY(packages/myddas) @@ -114,7 +112,7 @@ add_library( # Sets the name of the library. SHARED ${ENGINE_SOURCES} - ${SWIG_CXX} + ${CMAKE_SOURCE_DIR}/../generated/jni/yap_wrap.cpp ${C_INTERFACE_SOURCES} ${STATIC_SOURCES} ${ALL_SOURCES} @@ -131,7 +129,7 @@ endif (USE_READLINE) if (ANDROID) - add_dependencies(libYap plmyddas swig) + add_dependencies(libYap plmyddas ) target_link_libraries(libYap android log) diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp index 63e32092c..180a89b3f 100644 --- a/CXX/yapi.cpp +++ b/CXX/yapi.cpp @@ -480,8 +480,9 @@ bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) { YAP_dogoalinfo q; Term terr; jmp_buf q_env; + for (arity_t i = 0; i < arity; i++) - Yap_XREGS[i + 1] = ts[i].term(); + XREGS[i + 1] = ts[i].term(); q.CurSlot = Yap_StartSlots(); q.p = P; q.cp = CP; @@ -624,7 +625,7 @@ Term YAPEngine::fun(Term t) { Yap_CloseHandles(q.CurSlot); throw YAPError(); } - __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", result); + __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %ld", o); t = Yap_GetFromSlot(q.CurSlot); Yap_CloseHandles(q.CurSlot); @@ -665,14 +666,14 @@ YAPQuery::YAPQuery(YAPPredicate p, YAPTerm ts[]) : YAPPredicate(p.ap) { YAPListTerm YAPQuery::namedVars() { CACHE_REGS - __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %s %d", + __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %s %ld", vnames.text(), LOCAL_CurSlot); return vnames; // should be o } YAPListTerm YAPQuery::namedVarsCopy() { CACHE_REGS - __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %s %d", + __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %s %ld", vnames.text(), LOCAL_CurSlot); return YAPListTerm(YAP_CopyTerm(vnames.term())); // should be o } @@ -703,7 +704,7 @@ bool YAPQuery::next() { result = (bool)YAP_RetryGoal(&q_h); } if (result) { - __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %d %s %d", + __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %d %s %ld", q_state, vnames.text(), LOCAL_CurSlot); } else { __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "fail"); diff --git a/CXX/yapq.hh b/CXX/yapq.hh index fc9ee6fed..31c007bfd 100644 --- a/CXX/yapq.hh +++ b/CXX/yapq.hh @@ -54,7 +54,7 @@ public: /// goal. inline YAPQuery(const char *s) : YAPPredicate(s, tgoal, names) { BACKUP_H(); - __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %d", + __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %ld", LOCAL_CurSlot); if (!ap) return; diff --git a/OPTYap/opt.preds.c b/OPTYap/opt.preds.c index c21652ec4..77d4182e8 100644 --- a/OPTYap/opt.preds.c +++ b/OPTYap/opt.preds.c @@ -120,7 +120,7 @@ struct page_statistics { #ifdef USE_PAGES_MALLOC long pages_in_use; /* same as struct pages (opt.structs.h) */ #endif /* USE_PAGES_MALLOC */ - long structs_in_use; /* same as struct pages (opt.structs.h) */ + size_t structs_in_use; /* same as struct pages (opt.structs.h) */ long bytes_in_use; }; diff --git a/OPTYap/opt.structs.h b/OPTYap/opt.structs.h index 566aa4907..e5b8684fd 100644 --- a/OPTYap/opt.structs.h +++ b/OPTYap/opt.structs.h @@ -95,7 +95,7 @@ struct threads_dependency_frame { #ifdef USE_PAGES_MALLOC typedef struct page_header { - volatile int structs_in_use; + volatile size_t structs_in_use; void *allocated_area; void *first_free_struct; struct page_header *previous; @@ -125,7 +125,7 @@ struct global_page_entry { int structs_per_page; volatile long pages_in_use; #endif /* USE_PAGES_MALLOC */ - volatile long structs_in_use; + volatile size_t structs_in_use; }; struct local_page_entry { @@ -133,9 +133,10 @@ struct local_page_entry { struct page_header *first_page; struct page_header *last_page; int structs_per_page; - long pages_in_use; + + size_t pages_in_use; #endif /* USE_PAGES_MALLOC */ - long structs_in_use; + size_t structs_in_use; }; #define PgEnt_lock(X) ((X).lock) diff --git a/Prelims.cmake b/Prelims.cmake index 83aafe7b3..d07f05a50 100644 --- a/Prelims.cmake +++ b/Prelims.cmake @@ -105,20 +105,6 @@ else() endif() -#cross-compilation support -# Search packages for host system instead of packages for target system -# in case of cross compilation these macro should be defined by toolchain file -if(NOT COMMAND find_host_package) - macro(find_host_package) - find_package(${ARGN}) - endmacro() -endif() -if(NOT COMMAND find_host_program) - macro(find_host_program) - find_program(${ARGN}) - endmacro() -endif() - # where we have most scripts # set path to additional CMake modules @@ -142,10 +128,10 @@ endif(POLICY CMP0043) if (ANDROID) - set ( prefix ${YAP_APP_DIR}/app/build/generated ) - set ( datarootdir ${YAP_APP_DIR}/app/build/generated/assets ) + set ( prefix ${YAP_APP_DIR}/app/src/generated ) + set ( datarootdir ${YAP_APP_DIR}/app/src/generated/assets ) set ( includedir "${prefix}/assets/include") - set ( libpl ${YAP_APP_DIR}/app/build/generated/assets/Yap) + set ( libpl ${YAP_APP_DIR}/app/src/generated/assets/Yap) else() set ( prefix "${CMAKE_INSTALL_PREFIX}") set ( datarootdir "${prefix}/share") diff --git a/libYap.cmake b/libYap.cmake index fbc85ed73..4a1c0df8c 100644 --- a/libYap.cmake +++ b/libYap.cmake @@ -60,7 +60,7 @@ include_directories (H include_directories (BEFORE ${CMAKE_BINARY_DIR}) if (ANDROID) -include_directories (CXX) +include_directories (CXX ${CMAKE_SOURCE_DIR}/../generated/src/jni) endif() find_package (GMP) diff --git a/packages/myddas/CMakeLists.txt b/packages/myddas/CMakeLists.txt index 8f8866358..cff032477 100644 --- a/packages/myddas/CMakeLists.txt +++ b/packages/myddas/CMakeLists.txt @@ -11,7 +11,6 @@ set(MYDDAS_SOURCES myddas_shared.c myddas_statistics.c myddas_top_level.c - ) include_directories(. sqlite3) diff --git a/packages/myddas/pl/CMakeLists.txt b/packages/myddas/pl/CMakeLists.txt index 5b084802d..6cdce4d52 100644 --- a/packages/myddas/pl/CMakeLists.txt +++ b/packages/myddas/pl/CMakeLists.txt @@ -9,9 +9,9 @@ set(MYDDAS_YPP myddas_prolog2sql_optimizer.ypp) set(MYDDAS_DRIVERS - myddas_driver.ypp + "myddas_driver.ypp" ) - +message("libpl ${libpl}") if (ANDROID) set (PREFIX ${libpl} ) else() @@ -30,7 +30,7 @@ function(cpp_compile output filename) OUTPUT ${outfile} COMMAND ${CMAKE_C_COMPILER} ${MYDDAS_FLAGS} /EP /P ${outfile} ${CMAKE_CURRENT_SOURCE_DIR}/${filename} DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${filename}") - else () + ELSE (MSVC) add_custom_command( OUTPUT ${outfile} COMMAND ${CMAKE_C_COMPILER} ${MYDDAS_FLAGS} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/${filename} -o ${outfile} @@ -40,7 +40,11 @@ function(cpp_compile output filename) endfunction() function(cpp_driver output dbms filename) + if (ANDROID) + set(outfile ${libpl}/myddas_${dbms}.yap) + else() set(outfile ${CMAKE_CURRENT_BINARY_DIR}/myddas_${dbms}.yap) + endif() set(${output} ${${output}} ${outfile} PARENT_SCOPE) IF (MSVC) add_custom_command( diff --git a/packages/myddas/sqlite3/CMakeLists.txt b/packages/myddas/sqlite3/CMakeLists.txt index bdeaae65b..e644c83f5 100644 --- a/packages/myddas/sqlite3/CMakeLists.txt +++ b/packages/myddas/sqlite3/CMakeLists.txt @@ -1,3 +1,4 @@ +message( " * Sqlite3 Data-Base (http://www.sqlite3ql.org), distributed with MYDDAS" ) set( YAPSQLITE3_SOURCES myddas_sqlite3.c @@ -5,8 +6,30 @@ set( YAPSQLITE3_SOURCES sqlite3.h ) +#sqlite3 is now in the system + +set (SQLITE3_FOUND ON CACHE PRIVATE "") + +include_directories ( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/..) + +add_definitions(-DSQLITE_ENABLE_COLUMN_METADATA=1 ) + +add_definitions(-DSQLITE_ENABLE_JSON1=1 ) + +add_definitions(-DSQLITE_ENABLE_RBU=1 ) + +add_definitions(-DSQLITE_ENABLE_RTREE=1 ) + +add_definitions(-DSQLITE_ENABLE_FTS5=1 ) + + if (ANDROID) -set( YAPSQLITE3_ANDROID_SOURCES + + include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. Android/jni/sqlite Android/jni/sqlite/nativehelper ) + + +set(YAPSQLITE3_SOURCES + ${YAPSQLITE3_SOURCES} Android/jni/sqlite/JNIHelp.cpp Android/jni/sqlite/JniConstants.cpp Android/jni/sqlite/android_database_SQLiteCommon.cpp @@ -14,39 +37,13 @@ Android/jni/sqlite/android_database_SQLiteCommon.h Android/jni/sqlite/android_database_SQLiteConnection.cpp Android/jni/sqlite/android_database_SQLiteDebug.cpp Android/jni/sqlite/android_database_SQLiteGlobal.cpp +Android/jni/sqlite/nativehelper/jni.h +Android/jni/sqlite/nativehelper/jniConstants.h +Android/jni/sqlite/nativehelper/JNIHelp.h +Android/jni/sqlite/nativehelper/ScopedLocalRef.h ) -set( YAPSQLITE3_ANDROID_DIRS - Android/jni/sqlite - Android/jni/sqlite/nativehelper - ) + +add_component( sqlite3 + ${YAPSQLITE3_SOURCES} ) endif (ANDROID) -#sqlite3 is now in the system - -set (SQLITE3_FOUND ON CACHE PRIVATE "") - message ( - " * Sqlite3 Data-Base (http://www.sqlite3ql.org) is distributed with - MYDDAS" ) - - list (APPEND MYDDAS_FLAGS -DMYDDAS_SQLITE3=1) -set (MYDDAS_FLAGS ${MYDDAS_FLAGS} ON PARENT_SCOPE) -set_property(GLOBAL APPEND PROPERTY COMPILE_DEFINITIONS - -DMYDDAS_SQLITE3=1) - - include_directories ( ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR} ${YAPSQLITE3_ANDROID_DIRS}) - - - add_component (Yapsqlite3 ${YAPSQLITE3_SOURCES} ${YAPSQLITE3_ANDROID_SOURCES}) - if (NOT ANDROID) - #target_link_libraries(Yapsqlite3 libYap) - set_target_properties (Yapsqlite3 PROPERTIES - POSITION_INDEPENDENT_CODE ON - PREFIX "" - ) - - # install(TARGETS Yapsqlite3 - # LIBRARY DESTINATION ${dlls} - # ARCHIVE DESTINATION ${dlls} - # ) - endif() - diff --git a/packages/swig/android/CMakeLists.txt b/packages/swig/android/CMakeLists.txt index f4dc3b56c..21a74b8e8 100644 --- a/packages/swig/android/CMakeLists.txt +++ b/packages/swig/android/CMakeLists.txt @@ -11,11 +11,11 @@ ${CMAKE_SOURCE_DIR}/CXX ) - add_custom_target ( swig ALL - DEPENDS ${SWIG_CXX} + add_custom_command (OUTPUT yap_swig.cpp + COMMAND ${SWIG} -java -outdir ${CMAKE_SWIG_OUTDIR} -outcurrentdir -addextern -I${CMAKE_SOURCE_DIR}/CXX ${SWIG_SOURCES} -o yap_swig.cpp ) - add_custom_command (OUTPUT ${SWIG_CXX} - COMMAND ${SWIG} -java -outdir ${CMAKE_SWIG_OUTDIR} -c++ -addextern -I${CMAKE_SOURCE_DIR}/CXX -o ${SWIG_CXX}${SWIG_SOURCES} + add_custom_target ( swig ALL + DEPENDS yap_swig.cpp ) From 0be43c652539458ff06daad1b8110f524e35f190 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 11 Nov 2016 09:53:09 -0600 Subject: [PATCH 06/41] fix scripts --- CMakeLists.txt | 11 +++++-- logtalk_tester_logs/errors.all | 0 logtalk_tester_logs/tester_versions.txt | 43 ------------------------- os/readline.c | 2 +- packages/myddas/sqlite3/CMakeLists.txt | 5 +-- 5 files changed, 13 insertions(+), 48 deletions(-) delete mode 100644 logtalk_tester_logs/errors.all delete mode 100644 logtalk_tester_logs/tester_versions.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index e8dc34a2f..34f61d613 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,10 +59,15 @@ include(Sources NO_POLICY_SCOPE) include(Model NO_POLICY_SCOPE) -include_directories ( utf8proc packages/myddas packages/myddas/sqlite3 +include_directories ( utf8proc packages/myddas packages/myddas/sqlite3) + +if (ANDROID) + include_directories ( packages/myddas/sqlite3/Android/jni/sqlite packages/myddas/sqlite3/Android/jni/sqlite/nativehelper ) + endif (ANDROID) + add_definitions(-DUSE_MYDDAS=1 -DMYDDAS_SQLITE3=1) if (MYSQL_FOUND) @@ -87,6 +92,8 @@ if (ANDROID) ADD_SUBDIRECTORY(utf8proc) ADD_SUBDIRECTORY(CXX) +set (SWIG_FILES ${CMAKE_SOURCE_DIR}/../generated/jni/yap_wrap.cpp ) + else () set(YLIBS $ @@ -112,7 +119,7 @@ add_library( # Sets the name of the library. SHARED ${ENGINE_SOURCES} - ${CMAKE_SOURCE_DIR}/../generated/jni/yap_wrap.cpp + ${SWIG_FILES} ${C_INTERFACE_SOURCES} ${STATIC_SOURCES} ${ALL_SOURCES} diff --git a/logtalk_tester_logs/errors.all b/logtalk_tester_logs/errors.all deleted file mode 100644 index e69de29bb..000000000 diff --git a/logtalk_tester_logs/tester_versions.txt b/logtalk_tester_logs/tester_versions.txt deleted file mode 100644 index a305f6bc1..000000000 --- a/logtalk_tester_logs/tester_versions.txt +++ /dev/null @@ -1,43 +0,0 @@ -The environment variable LOGTALKHOME should be defined first, pointing -to your Logtalk installation directory! -Trying the default locations for the Logtalk installation... -... using Logtalk installation found at /Users/vsc/share/logtalk - -The environment variable LOGTALKUSER should be defined first, pointing -to your Logtalk user directory! -Trying the default location for the Logtalk user directory... - - - -Logtalk 3.6.3-rc9 -Copyright (c) 1998-2016 Paulo Moura - -% Default lint compilation flags: -% unknown_predicates: warning, undefined_predicates: warning -% portability: silent, unknown_entities: warning -% missing_directives: warning, redefined_built_ins: silent -% singleton_variables: warning, underscore_variables: singletons -% Default optional features compiler flags: -% complements: deny, dynamic_declarations: deny -% context_switching_calls: allow, events: deny -% Other default compilation flags: -% report: on, scratch_directory: ./.lgt_tmp/ -% source_data: on, code_prefix: $, hook: (none) -% optimize: off, debug: off, clean: on, reload: changed -% Backend Prolog compiler flags: -% prolog_compiler: [] -% prolog_loader: [silent(true),compilation_mode(compact)] -% Read-only compilation flags (backend Prolog compiler features): -% prolog_dialect: yap, modules: supported, threads: unsupported -% tabling: unsupported, coinduction: supported -% unicode: full, encoding_directive: full -% -% No settings file found in the startup or Logtalk user directories. -% Using default flag values set in the backend Prolog compiler adapter file. -% -% For Logtalk help, use ?- {help(loader)}. or ?- logtalk_load(help(loader)). -% -***** Logtalk version: 3.6.3-rc9 -***** Prolog version: 6.3.4 -% [ /Users/vsc/logtalk/library/tester_versions.lgt loaded ] -% (0 warnings) diff --git a/os/readline.c b/os/readline.c index 5f2aa2f90..ca300a911 100644 --- a/os/readline.c +++ b/os/readline.c @@ -264,7 +264,7 @@ bool Yap_ReadlineOps(StreamDesc *s) { static int prolog_complete(int ignore, int key) { if (rl_point > 0 && rl_line_buffer[rl_point - 1] != ' ') { -#if HAVE_DECL_RL_CATCH_SIGNALS_ /* actually version >= 1.2, or true readline \ +#if HAVE_DECL_RL_CATCH_SIGNALS /* actually version >= 1.2, or true readline \ */ rl_begin_undo_group(); rl_complete(ignore, key); diff --git a/packages/myddas/sqlite3/CMakeLists.txt b/packages/myddas/sqlite3/CMakeLists.txt index e644c83f5..dc0a32306 100644 --- a/packages/myddas/sqlite3/CMakeLists.txt +++ b/packages/myddas/sqlite3/CMakeLists.txt @@ -43,7 +43,8 @@ Android/jni/sqlite/nativehelper/JNIHelp.h Android/jni/sqlite/nativehelper/ScopedLocalRef.h ) -add_component( sqlite3 - ${YAPSQLITE3_SOURCES} ) endif (ANDROID) +add_component( Yapsqlite3 + ${YAPSQLITE3_SOURCES} ) + From da65d7bd3caad5450b0d2d671c71cff4b8d5b27c Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 16 Nov 2016 17:06:37 -0600 Subject: [PATCH 07/41] fix bug in sb_atom --- C/atomic.c | 1056 ++++++++++++++++++++++++++-------------------------- 1 file changed, 524 insertions(+), 532 deletions(-) diff --git a/C/atomic.c b/C/atomic.c index b71049052..96e5baeaa 100644 --- a/C/atomic.c +++ b/C/atomic.c @@ -1874,580 +1874,572 @@ static int check_sub_atom_bef(int max, Atom at, Atom nat) { } static Int cont_sub_atomic(USES_REGS1) { - Term tat1 = Deref(ARG1); - Term tat5 = Deref(ARG5); - int mask; - size_t minv, len, after, sz; - wchar_t *wp = NULL; - const unsigned char *p = NULL, *p5 = NULL; - bool sub_atom = TRUE; - - mask = IntegerOfTerm(EXTRA_CBACK_ARG(5, 1)); - minv = IntegerOfTerm(EXTRA_CBACK_ARG(5, 2)); - len = IntegerOfTerm(EXTRA_CBACK_ARG(5, 3)); - after = IntegerOfTerm(EXTRA_CBACK_ARG(5, 4)); - sz = IntegerOfTerm(EXTRA_CBACK_ARG(5, 5)); - - if (!IsVarTerm(tat1)) { - if (IsAtomTerm(tat1)) { - p = AtomOfTerm(tat1)->UStrOfAE; - } else { - p = UStringOfTerm(tat1); - } - } - if (!IsVarTerm(tat5)) { - if (IsAtomTerm(tat5)) { - p5 = AtomOfTerm(tat5)->UStrOfAE; - } else { - p5 = UStringOfTerm(tat5); - } - } - /* we can have one of two cases: A5 bound or unbound */ - if (mask & SUB_ATOM_HAS_VAL) { - bool found = false; - { - const unsigned char *p1 = p; - - while (!found) { - p = skip_utf8(p1, minv); - if (cmpn_utf8(p, p5, len) == 0) { - Yap_unify(ARG2, MkIntegerTerm(minv)); - Yap_unify(ARG3, MkIntegerTerm(len)); - Yap_unify(ARG4, MkIntegerTerm(after)); - found = true; - /* found one, check if there is any left */ - while (minv <= sz - len) { - int chr; - p += get_utf8((unsigned char *)p, -1, &chr); - after--; - minv++; - if (cmpn_utf8(p, p5, len) == 0) - break; - } - } else { - if (minv == sz - len) - break; - after--; - minv++; - } - } - } - if (found) { - if (minv > sz - len) - cut_succeed(); - } else { - cut_fail(); - } - } else if (mask & SUB_ATOM_HAS_SIZE) { - Term nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); - Yap_unify(ARG2, MkIntegerTerm(minv)); - Yap_unify(ARG4, MkIntegerTerm(after)); - Yap_unify(ARG5, nat); - minv++; - if (after-- == 0) - cut_succeed(); - } else if (mask & SUB_ATOM_HAS_MIN) { - after = sz - (minv + len); - Term nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); - Yap_unify(ARG3, MkIntegerTerm(len)); - Yap_unify(ARG4, MkIntegerTerm(after)); - Yap_unify(ARG5, nat); - len++; - if (after-- == 0) - cut_succeed(); - } else if (mask & SUB_ATOM_HAS_AFTER) { - len = sz - (minv + after); - Term nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); - Yap_unify(ARG2, MkIntegerTerm(minv)); - Yap_unify(ARG3, MkIntegerTerm(len)); - Yap_unify(ARG5, nat); - minv++; - if (len-- == 0) - cut_succeed(); + Term tat1 = Deref(ARG1); + Term tat5 = Deref(ARG5); + int mask; + size_t minv, len, after, sz; + wchar_t *wp = NULL; + const unsigned char *p = NULL, *p5 = NULL; + + mask = IntegerOfTerm(EXTRA_CBACK_ARG(5, 1)); + minv = IntegerOfTerm(EXTRA_CBACK_ARG(5, 2)); + len = IntegerOfTerm(EXTRA_CBACK_ARG(5, 3)); + after = IntegerOfTerm(EXTRA_CBACK_ARG(5, 4)); + sz = IntegerOfTerm(EXTRA_CBACK_ARG(5, 5)); + + if (!IsVarTerm(tat1)) { + if (IsAtomTerm(tat1)) { + p = AtomOfTerm(tat1)->UStrOfAE; } else { - Term nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); - Yap_unify(ARG2, MkIntegerTerm(minv)); - Yap_unify(ARG3, MkIntegerTerm(len)); - Yap_unify(ARG4, MkIntegerTerm(after)); - Yap_unify(ARG5, nat); - len++; - if (after-- == 0) { - if (minv == sz) - cut_succeed(); - minv++; - len = 0; - after = sz - minv; - } + p = UStringOfTerm(tat1); } - EXTRA_CBACK_ARG(5, 1) = MkIntegerTerm(mask); - EXTRA_CBACK_ARG(5, 2) = MkIntegerTerm(minv); - EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(len); - EXTRA_CBACK_ARG(5, 4) = MkIntegerTerm(after); - EXTRA_CBACK_ARG(5, 5) = MkIntegerTerm(sz); - return TRUE; + } + if (!IsVarTerm(tat5)) { + if (IsAtomTerm(tat5)) { + p5 = AtomOfTerm(tat5)->UStrOfAE; + } else { + p5 = UStringOfTerm(tat5); + } + } + /* we can have one of two cases: A5 bound or unbound */ + if (mask & SUB_ATOM_HAS_VAL) { + bool found = false; + { + const unsigned char *p1 = p; + + while (!found) { + p = skip_utf8(p1, minv); + if (cmpn_utf8(p, p5, len) == 0) { + Yap_unify(ARG2, MkIntegerTerm(minv)); + Yap_unify(ARG3, MkIntegerTerm(len)); + Yap_unify(ARG4, MkIntegerTerm(after)); + found = true; + /* found one, check if there is any left */ + while (minv <= sz - len) { + int chr; + p += get_utf8((unsigned char *)p, -1, &chr); + after--; + minv++; + if (cmpn_utf8(p, p5, len) == 0) + break; + } + } else { + if (minv == sz - len) + break; + after--; + minv++; + } + } + } + if (found) { + if (minv > sz - len) + cut_succeed(); + } else { + cut_fail(); + } + } else if (mask & SUB_ATOM_HAS_SIZE) { + Term nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); + Yap_unify(ARG2, MkIntegerTerm(minv)); + Yap_unify(ARG4, MkIntegerTerm(after)); + Yap_unify(ARG5, nat); + minv++; + if (after-- == 0) + cut_succeed(); + } else if (mask & SUB_ATOM_HAS_MIN) { + after = sz - (minv + len); + Term nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); + Yap_unify(ARG3, MkIntegerTerm(len)); + Yap_unify(ARG4, MkIntegerTerm(after)); + Yap_unify(ARG5, nat); + len++; + if (after-- == 0) + cut_succeed(); + } else if (mask & SUB_ATOM_HAS_AFTER) { + len = sz - (minv + after); + Term nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); + Yap_unify(ARG2, MkIntegerTerm(minv)); + Yap_unify(ARG3, MkIntegerTerm(len)); + Yap_unify(ARG5, nat); + minv++; + if (len-- == 0) + cut_succeed(); + } else { + Term nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); + Yap_unify(ARG2, MkIntegerTerm(minv)); + Yap_unify(ARG3, MkIntegerTerm(len)); + Yap_unify(ARG4, MkIntegerTerm(after)); + Yap_unify(ARG5, nat); + len++; + if (after-- == 0) { + if (minv == sz) + cut_succeed(); + minv++; + len = 0; + after = sz - minv; + } + } + EXTRA_CBACK_ARG(5, 1) = MkIntegerTerm(mask); + EXTRA_CBACK_ARG(5, 2) = MkIntegerTerm(minv); + EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(len); + EXTRA_CBACK_ARG(5, 4) = MkIntegerTerm(after); + EXTRA_CBACK_ARG(5, 5) = MkIntegerTerm(sz); + return TRUE; } +static Int sub_atomic(bool sub_atom, bool sub_string USES_REGS) { + Term tat1, tbef, tsize, tafter, tout; + int mask = SUB_ATOM_HAS_UTF8; + size_t minv, len, after, sz; + wchar_t *wp = NULL; + const unsigned char *p = NULL; + int bnds = 0; + Term nat = 0L; + Atom at = NULL; - static Int sub_atomic(bool sub_atom, bool sub_string USES_REGS) { - Term tat1, tbef, tsize, tafter, tout; - int mask = SUB_ATOM_HAS_UTF8; - size_t minv, len, after, sz; - wchar_t *wp = NULL; - const unsigned char *p = NULL; - int bnds = 0; - Term nat = 0L; - Atom at = NULL; + int l = push_text_stack(); + if (sub_atom) + mask |= SUB_ATOM_HAS_ATOM; - int l = push_text_stack(); - if (sub_atom) - mask |= SUB_ATOM_HAS_ATOM; + tat1 = Deref(ARG1); - tat1 = Deref(ARG1); - - if (!IsVarTerm(tat1)) { - if (sub_atom) { - if (IsAtomTerm(tat1)) { - p = AtomOfTerm(tat1)->UStrOfAE; - sz = strlen_utf8(p); - } else { - Yap_Error(TYPE_ERROR_ATOM, tat1, "sub_atom/5"); - ReleaseAndReturn(false); - } - } else if (sub_string) { - if (IsStringTerm(tat1)) { - p = UStringOfTerm(tat1); - sz = strlen_utf8(p); - } else { - Yap_Error(TYPE_ERROR_STRING, tat1, "sub_atom/5"); - ReleaseAndReturn(false); - } - } + if (!IsVarTerm(tat1)) { + if (sub_atom) { + if (IsAtomTerm(tat1)) { + p = AtomOfTerm(tat1)->UStrOfAE; + sz = strlen_utf8(p); } else { - Yap_Error(INSTANTIATION_ERROR, tat1, "sub_atom/5: first variable\n"); + Yap_Error(TYPE_ERROR_ATOM, tat1, "sub_atom/5"); ReleaseAndReturn(false); } - EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(0); - tbef = Deref(ARG2); - if (IsVarTerm(tbef)) { - minv = 0; - } else if (!IsIntegerTerm(tbef)) { - Yap_Error(TYPE_ERROR_INTEGER, tbef, "sub_string/5"); + } else if (sub_string) { + if (IsStringTerm(tat1)) { + p = UStringOfTerm(tat1); + sz = strlen_utf8(p); + } else { + Yap_Error(TYPE_ERROR_STRING, tat1, "sub_atom/5"); + ReleaseAndReturn(false); + } + } + } else { + Yap_Error(INSTANTIATION_ERROR, tat1, "sub_atom/5: first variable\n"); + ReleaseAndReturn(false); + } + EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(0); + tbef = Deref(ARG2); + if (IsVarTerm(tbef)) { + minv = 0; + } else if (!IsIntegerTerm(tbef)) { + Yap_Error(TYPE_ERROR_INTEGER, tbef, "sub_string/5"); + ReleaseAndReturn(FALSE); + } else { + minv = IntegerOfTerm(tbef); + if ((Int)minv < 0) { + Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, tbef, "sub_string/5"); + ReleaseAndReturn(FALSE); + }; + mask |= SUB_ATOM_HAS_MIN; + bnds++; + } + if (IsVarTerm(tsize = Deref(ARG3))) { + len = 0; + } else if (!IsIntegerTerm(tsize)) { + Yap_Error(TYPE_ERROR_INTEGER, tsize, "sub_string/5"); + ReleaseAndReturn(FALSE); + } else { + len = IntegerOfTerm(tsize); + if ((Int)len < 0) { + Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, tsize, "sub_string/5"); + ReleaseAndReturn(FALSE); + }; + mask |= SUB_ATOM_HAS_SIZE; + bnds++; + } + if (IsVarTerm(tafter = Deref(ARG4))) { + after = 0; + } else if (!IsIntegerTerm(tafter)) { + Yap_Error(TYPE_ERROR_INTEGER, tafter, "sub_string/5"); + ReleaseAndReturn(FALSE); + } else { + after = IntegerOfTerm(tafter); + if ((Int)after < 0) { + Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, tafter, "sub_string/5"); + ReleaseAndReturn(FALSE); + }; + mask |= SUB_ATOM_HAS_AFTER; + bnds++; + } + if (!IsVarTerm(tout = Deref(ARG5))) { + if (sub_atom) { + if (!IsAtomTerm(tout)) { + Yap_Error(TYPE_ERROR_ATOM, tout, "sub_atom/5"); ReleaseAndReturn(FALSE); } else { - minv = IntegerOfTerm(tbef); - if ((Int)minv < 0) { - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, tbef, "sub_string/5"); - ReleaseAndReturn(FALSE); - }; - mask |= SUB_ATOM_HAS_MIN; - bnds++; + Atom oat; + mask |= SUB_ATOM_HAS_VAL | SUB_ATOM_HAS_SIZE; + oat = AtomOfTerm(tout); + len = strlen_utf8(RepAtom(oat)->UStrOfAE); } - if (IsVarTerm(tsize = Deref(ARG3))) { - len = 0; - } else if (!IsIntegerTerm(tsize)) { - Yap_Error(TYPE_ERROR_INTEGER, tsize, "sub_string/5"); + } else { + if (!IsStringTerm(tout)) { + Yap_Error(TYPE_ERROR_STRING, tout, "sub_string/5"); ReleaseAndReturn(FALSE); } else { - len = IntegerOfTerm(tsize); - if ((Int)len < 0) { - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, tsize, "sub_string/5"); - ReleaseAndReturn(FALSE); - }; - mask |= SUB_ATOM_HAS_SIZE; - bnds++; + mask |= SUB_ATOM_HAS_VAL | SUB_ATOM_HAS_SIZE; + len = strlen_utf8(UStringOfTerm(tout)); } - if (IsVarTerm(tafter = Deref(ARG4))) { - after = 0; - } else if (!IsIntegerTerm(tafter)) { - Yap_Error(TYPE_ERROR_INTEGER, tafter, "sub_string/5"); - ReleaseAndReturn(FALSE); - } else { - after = IntegerOfTerm(tafter); - if ((Int)after < 0) { - Yap_Error(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, tafter, "sub_string/5"); - ReleaseAndReturn(FALSE); - }; - mask |= SUB_ATOM_HAS_AFTER; - bnds++; - } - if (!IsVarTerm(tout = Deref(ARG5))) { - if (sub_atom) { - if (!IsAtomTerm(tout)) { - Yap_Error(TYPE_ERROR_ATOM, tout, "sub_atom/5"); - ReleaseAndReturn(FALSE); - } else { - Atom oat; - mask |= SUB_ATOM_HAS_VAL | SUB_ATOM_HAS_SIZE; - oat = AtomOfTerm(tout); - len = strlen_utf8(RepAtom(oat)->UStrOfAE); - } - } else { - if (!IsStringTerm(tout)) { - Yap_Error(TYPE_ERROR_STRING, tout, "sub_string/5"); - ReleaseAndReturn(FALSE); - } else { - mask |= SUB_ATOM_HAS_VAL | SUB_ATOM_HAS_SIZE; - len = strlen_utf8(UStringOfTerm(tout)); - } - } - if (!Yap_unify(ARG3, MkIntegerTerm(len))) - release_cut_fail(); - bnds += 2; - } - /* the problem is deterministic if we have two cases */ - if (bnds > 1) { - int out = FALSE; + } + if (!Yap_unify(ARG3, MkIntegerTerm(len))) + release_cut_fail(); + bnds += 2; + } + /* the problem is deterministic if we have two cases */ + if (bnds > 1) { + int out = FALSE; - if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) == - (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) { - if (minv + len > sz) - release_cut_fail(); - if ((Int)(after = (sz - (minv + len))) < 0) - release_cut_fail(); - nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); - if (!nat) - release_cut_fail(); - out = Yap_unify(ARG4, MkIntegerTerm(after)) && Yap_unify(ARG5, nat); - } else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_AFTER)) == - (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_AFTER)) { - if (sz < minv + after) - release_cut_fail(); - len = sz - (minv + after); - nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); - if (!nat) - release_cut_fail(); - out = Yap_unify(ARG3, MkIntegerTerm(len)) && Yap_unify(ARG5, nat); - } else if ((mask & (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_AFTER)) == - (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_AFTER)) { - if (len + after > sz) - release_cut_fail(); - minv = sz - (len + after); - nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); - if (!nat) - release_cut_fail(); - out = Yap_unify(ARG2, MkIntegerTerm(minv)) && Yap_unify(ARG5, nat); - } else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) == - (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) { - if (sub_atom) - out = check_sub_atom_at(minv, at, AtomOfTerm(nat), len); - else - out = check_sub_string_at(minv, p, UStringOfTerm(nat), len); - } else if ((mask & (SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) == - (SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) { - if (sub_atom) - out = check_sub_atom_bef(sz - after, at, AtomOfTerm(nat)); - else - out = check_sub_string_bef(sz - after, tat1, tout); - } else if ((mask & (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_VAL)) == - (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_VAL)) { - if (!sub_atom) { - out = (strlen_utf8(UStringOfTerm(tout)) == len); - if (!out) - release_cut_fail(); - } else { - out = (strlen_utf8(RepAtom(AtomOfTerm(tout))->UStrOfAE) == len); - if (!out) - release_cut_fail(); - } - if (len == sz) { - out = out && Yap_unify(ARG1, ARG5) && - Yap_unify(ARG2, MkIntegerTerm(0)) && - Yap_unify(ARG4, MkIntegerTerm(0)); - } else if (len > sz) { - release_cut_fail(); - } else { - mask |= SUB_ATOM_HAS_SIZE; - minv = 0; - after = sz - len; - goto backtrackable; - } - } - if (out) - release_cut_succeed(); + if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) == + (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_SIZE)) { + if (minv + len > sz) + release_cut_fail(); + if ((Int)(after = (sz - (minv + len))) < 0) + release_cut_fail(); + nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); + if (!nat) + release_cut_fail(); + out = Yap_unify(ARG4, MkIntegerTerm(after)) && Yap_unify(ARG5, nat); + } else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_AFTER)) == + (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_AFTER)) { + if (sz < minv + after) + release_cut_fail(); + len = sz - (minv + after); + nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); + if (!nat) + release_cut_fail(); + out = Yap_unify(ARG3, MkIntegerTerm(len)) && Yap_unify(ARG5, nat); + } else if ((mask & (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_AFTER)) == + (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_AFTER)) { + if (len + after > sz) + release_cut_fail(); + minv = sz - (len + after); + nat = build_new_atomic(mask, wp, p, minv, len PASS_REGS); + if (!nat) + release_cut_fail(); + out = Yap_unify(ARG2, MkIntegerTerm(minv)) && Yap_unify(ARG5, nat); + } else if ((mask & (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) == + (SUB_ATOM_HAS_MIN | SUB_ATOM_HAS_VAL)) { + if (sub_atom) + out = check_sub_atom_at(minv, at, AtomOfTerm(nat), len); + else + out = check_sub_string_at(minv, p, UStringOfTerm(nat), len); + } else if ((mask & (SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) == + (SUB_ATOM_HAS_AFTER | SUB_ATOM_HAS_VAL)) { + if (sub_atom) + out = check_sub_atom_bef(sz - after, at, AtomOfTerm(nat)); + else + out = check_sub_string_bef(sz - after, tat1, tout); + } else if ((mask & (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_VAL)) == + (SUB_ATOM_HAS_SIZE | SUB_ATOM_HAS_VAL)) { + if (!sub_atom) { + out = (strlen_utf8(UStringOfTerm(tout)) == len); + if (!out) + release_cut_fail(); + } else { + out = (strlen_utf8(RepAtom(AtomOfTerm(tout))->UStrOfAE) == len); + if (!out) + release_cut_fail(); + } + if (len == sz) { + out = out && Yap_unify(ARG1, ARG5) && + Yap_unify(ARG2, MkIntegerTerm(0)) && + Yap_unify(ARG4, MkIntegerTerm(0)); + } else if (len > sz) { release_cut_fail(); } else { - if (!(mask & SUB_ATOM_HAS_MIN)) - minv = 0; - if (!(mask & SUB_ATOM_HAS_SIZE)) - len = 0; - if (!(mask & SUB_ATOM_HAS_AFTER)) - after = sz - (len + minv); + mask |= SUB_ATOM_HAS_SIZE; + minv = 0; + after = sz - len; + goto backtrackable; } - backtrackable: - EXTRA_CBACK_ARG(5, 1) = MkIntegerTerm(mask); - EXTRA_CBACK_ARG(5, 2) = MkIntegerTerm(minv); - EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(len); - EXTRA_CBACK_ARG(5, 4) = MkIntegerTerm(after); - EXTRA_CBACK_ARG(5, 5) = MkIntegerTerm(sz); - ReleaseAndReturn(cont_sub_atomic(PASS_REGS1)); } + if (out) + release_cut_succeed(); + release_cut_fail(); + } else { + if (!(mask & SUB_ATOM_HAS_MIN)) + minv = 0; + if (!(mask & SUB_ATOM_HAS_SIZE)) + len = 0; + if (!(mask & SUB_ATOM_HAS_AFTER)) + after = sz - (len + minv); + } +backtrackable: + EXTRA_CBACK_ARG(5, 1) = MkIntegerTerm(mask); + EXTRA_CBACK_ARG(5, 2) = MkIntegerTerm(minv); + EXTRA_CBACK_ARG(5, 3) = MkIntegerTerm(len); + EXTRA_CBACK_ARG(5, 4) = MkIntegerTerm(after); + EXTRA_CBACK_ARG(5, 5) = MkIntegerTerm(sz); + ReleaseAndReturn(cont_sub_atomic(PASS_REGS1)); +} - /** @pred sub_atom(+ _A_,? _Bef_, ? _Size_, ? _After_, ? _At_out_) is iso +/** @pred sub_atom(+ _A_,? _Bef_, ? _Size_, ? _After_, ? _At_out_) is iso - True when _A_ and _At_out_ are atoms such that the name of - _At_out_ has size _Size_ and is a sub-string of the name of - _A_, such that _Bef_ is the number of characters before and - _After_ the number of characters afterwards. +True when _A_ and _At_out_ are atoms such that the name of + _At_out_ has size _Size_ and is a sub-string of the name of + _A_, such that _Bef_ is the number of characters before and + _After_ the number of characters afterwards. - Note that _A_ must always be known, but _At_out_ can be unbound when - calling this built-in. If all the arguments for sub_atom/5 but _A_ - are unbound, the built-in will backtrack through all possible - sub-strings of _A_. +Note that _A_ must always be known, but _At_out_ can be unbound when +calling this built-in. If all the arguments for sub_atom/5 but _A_ +are unbound, the built-in will backtrack through all possible +sub-strings of _A_. - */ - static Int sub_atom(USES_REGS1) { - return (sub_atomic(true, false PASS_REGS)); + */ +static Int sub_atom(USES_REGS1) { return (sub_atomic(true, false PASS_REGS)); } + +/** @pred sub_string(+ _S_,? _Bef_, ? _Size_, ? _After_, ? _S_out_) is +iso + + +True when _S_ and _S_out_ are strings such that the + _S_out_ has size _Size_ and is a sub-string of + _S_, _Bef_ is the number of characters before, and + _After_ the number of characters afterwards. + +Note that _S_ must always be known, but _S_out_ can be unbound when +calling this built-in. If all the arguments for sub_string/5 but _S_ +are unbound, the built-in will generate all possible +sub-strings of _S_. + + */ +static Int sub_string(USES_REGS1) { return sub_atomic(false, true PASS_REGS); } + +static Int cont_current_atom(USES_REGS1) { + Atom catom; + Int i = IntOfTerm(EXTRA_CBACK_ARG(1, 2)); + AtomEntry *ap; /* nasty hack for gcc on hpux */ + + /* protect current hash table line */ + if (IsAtomTerm(EXTRA_CBACK_ARG(1, 1))) + catom = AtomOfTerm(EXTRA_CBACK_ARG(1, 1)); + else + catom = NIL; + if (catom == NIL) { + i++; + /* move away from current hash table line */ + while (i < AtomHashTableSize) { + READ_LOCK(HashChain[i].AERWLock); + catom = HashChain[i].Entry; + READ_UNLOCK(HashChain[i].AERWLock); + if (catom != NIL) { + break; + } + i++; } - - /** @pred sub_string(+ _S_,? _Bef_, ? _Size_, ? _After_, ? _S_out_) is - iso - - - True when _S_ and _S_out_ are strings such that the - _S_out_ has size _Size_ and is a sub-string of - _S_, _Bef_ is the number of characters before, and - _After_ the number of characters afterwards. - - Note that _S_ must always be known, but _S_out_ can be unbound when - calling this built-in. If all the arguments for sub_string/5 but _S_ - are unbound, the built-in will generate all possible - sub-strings of _S_. - - */ - static Int sub_string(USES_REGS1) { - return sub_atomic(false, true PASS_REGS); + if (i == AtomHashTableSize) { + cut_fail(); } - - static Int cont_current_atom(USES_REGS1) { - Atom catom; - Int i = IntOfTerm(EXTRA_CBACK_ARG(1, 2)); - AtomEntry *ap; /* nasty hack for gcc on hpux */ - - /* protect current hash table line */ - if (IsAtomTerm(EXTRA_CBACK_ARG(1, 1))) - catom = AtomOfTerm(EXTRA_CBACK_ARG(1, 1)); - else - catom = NIL; - if (catom == NIL) { + } + ap = RepAtom(catom); + if (Yap_unify_constant(ARG1, MkAtomTerm(catom))) { + READ_LOCK(ap->ARWLock); + if (ap->NextOfAE == NIL) { + READ_UNLOCK(ap->ARWLock); + i++; + while (i < AtomHashTableSize) { + READ_LOCK(HashChain[i].AERWLock); + catom = HashChain[i].Entry; + READ_UNLOCK(HashChain[i].AERWLock); + if (catom != NIL) { + break; + } i++; - /* move away from current hash table line */ - while (i < AtomHashTableSize) { - READ_LOCK(HashChain[i].AERWLock); - catom = HashChain[i].Entry; - READ_UNLOCK(HashChain[i].AERWLock); - if (catom != NIL) { - break; - } - i++; - } - if (i == AtomHashTableSize) { - cut_fail(); - } } - ap = RepAtom(catom); - if (Yap_unify_constant(ARG1, MkAtomTerm(catom))) { - READ_LOCK(ap->ARWLock); - if (ap->NextOfAE == NIL) { - READ_UNLOCK(ap->ARWLock); - i++; - while (i < AtomHashTableSize) { - READ_LOCK(HashChain[i].AERWLock); - catom = HashChain[i].Entry; - READ_UNLOCK(HashChain[i].AERWLock); - if (catom != NIL) { - break; - } - i++; - } - if (i == AtomHashTableSize) { - cut_fail(); - } else { - EXTRA_CBACK_ARG(1, 1) = MkAtomTerm(catom); - } - } else { - EXTRA_CBACK_ARG(1, 1) = MkAtomTerm(ap->NextOfAE); - READ_UNLOCK(ap->ARWLock); - } - EXTRA_CBACK_ARG(1, 2) = MkIntTerm(i); - return (TRUE); + if (i == AtomHashTableSize) { + cut_fail(); } else { - return (FALSE); + EXTRA_CBACK_ARG(1, 1) = MkAtomTerm(catom); } + } else { + EXTRA_CBACK_ARG(1, 1) = MkAtomTerm(ap->NextOfAE); + READ_UNLOCK(ap->ARWLock); } + EXTRA_CBACK_ARG(1, 2) = MkIntTerm(i); + return (TRUE); + } else { + return (FALSE); + } +} - static Int current_atom(USES_REGS1) { /* current_atom(?Atom) - */ - Term t1 = Deref(ARG1); - if (!IsVarTerm(t1)) { - if (IsAtomTerm(t1)) - cut_succeed(); - else - cut_fail(); - } - READ_LOCK(HashChain[0].AERWLock); - if (HashChain[0].Entry != NIL) { - EXTRA_CBACK_ARG(1, 1) = MkAtomTerm(HashChain[0].Entry); - } else { - EXTRA_CBACK_ARG(1, 1) = MkIntTerm(0); - } - READ_UNLOCK(HashChain[0].AERWLock); - EXTRA_CBACK_ARG(1, 2) = MkIntTerm(0); - return (cont_current_atom(PASS_REGS1)); - } +static Int current_atom(USES_REGS1) { /* current_atom(?Atom) + */ + Term t1 = Deref(ARG1); + if (!IsVarTerm(t1)) { + if (IsAtomTerm(t1)) + cut_succeed(); + else + cut_fail(); + } + READ_LOCK(HashChain[0].AERWLock); + if (HashChain[0].Entry != NIL) { + EXTRA_CBACK_ARG(1, 1) = MkAtomTerm(HashChain[0].Entry); + } else { + EXTRA_CBACK_ARG(1, 1) = MkIntTerm(0); + } + READ_UNLOCK(HashChain[0].AERWLock); + EXTRA_CBACK_ARG(1, 2) = MkIntTerm(0); + return (cont_current_atom(PASS_REGS1)); +} - void Yap_InitBackAtoms(void) { - Yap_InitCPredBack("$current_atom", 1, 2, current_atom, cont_current_atom, - SafePredFlag | SyncPredFlag); - Yap_InitCPredBack("atom_concat", 3, 2, atom_concat3, cont_atom_concat3, - 0); - Yap_InitCPredBack("atomic_concat", 3, 2, atomic_concat3, - cont_atomic_concat3, 0); - Yap_InitCPredBack("string_concat", 3, 2, string_concat3, - cont_string_concat3, 0); - Yap_InitCPredBack("sub_atom", 5, 5, sub_atom, cont_sub_atomic, 0); - Yap_InitCPredBack("sub_string", 5, 5, sub_string, cont_sub_atomic, 0); - Yap_InitCPredBack("string_code", 3, 1, string_code3, cont_string_code3, - 0); - } +void Yap_InitBackAtoms(void) { + Yap_InitCPredBack("$current_atom", 1, 2, current_atom, cont_current_atom, + SafePredFlag | SyncPredFlag); + Yap_InitCPredBack("atom_concat", 3, 2, atom_concat3, cont_atom_concat3, 0); + Yap_InitCPredBack("atomic_concat", 3, 2, atomic_concat3, cont_atomic_concat3, + 0); + Yap_InitCPredBack("string_concat", 3, 2, string_concat3, cont_string_concat3, + 0); + Yap_InitCPredBack("sub_atom", 5, 5, sub_atom, cont_sub_atomic, 0); + Yap_InitCPredBack("sub_string", 5, 5, sub_string, cont_sub_atomic, 0); + Yap_InitCPredBack("string_code", 3, 1, string_code3, cont_string_code3, 0); +} - void Yap_InitAtomPreds(void) { - Yap_InitCPred("name", 2, name, 0); - /** @pred name( _A_, _L_) +void Yap_InitAtomPreds(void) { + Yap_InitCPred("name", 2, name, 0); + /** @pred name( _A_, _L_) - The predicate holds when at least one of the arguments is ground - (otherwise, an error message will be displayed). The argument _A_ will - be unified with an atomic symbol and _L_ with the list of the ASCII - codes for the characters of the external representation of _A_. + The predicate holds when at least one of the arguments is ground + (otherwise, an error message will be displayed). The argument _A_ will + be unified with an atomic symbol and _L_ with the list of the ASCII + codes for the characters of the external representation of _A_. - ~~~~~{.prolog} - name(yap,L). - ~~~~~ - will return: + ~~~~~{.prolog} + name(yap,L). + ~~~~~ + will return: - ~~~~~{.prolog} - L = [121,97,112]. - ~~~~~ - and + ~~~~~{.prolog} + L = [121,97,112]. + ~~~~~ + and - ~~~~~{.prolog} - name(3,L). - ~~~~~ - will return: + ~~~~~{.prolog} + name(3,L). + ~~~~~ + will return: - ~~~~~{.prolog} - L = [51]. - ~~~~~ + ~~~~~{.prolog} + L = [51]. + ~~~~~ - */ - Yap_InitCPred("string_to_atom", 2, string_to_atom, 0); - Yap_InitCPred("atom_string", 2, atom_string, 0); - Yap_InitCPred("string_to_atomic", 2, string_to_atomic, 0); - Yap_InitCPred("string_to_list", 2, string_to_list, 0); - Yap_InitCPred("char_code", 2, char_code, SafePredFlag); - /** @pred char_code(? _A_,? _I_) is iso - - - The built-in succeeds with _A_ bound to character represented as an - atom, and _I_ bound to the character code represented as an - integer. At least, one of either _A_ or _I_ must be bound before - the call. - - - */ - Yap_InitCPred("atom_chars", 2, atom_chars, 0); - /** @pred atom_chars(? _A_,? _L_) is iso - - - The predicate holds when at least one of the arguments is ground - (otherwise, an error message will be displayed). The argument _A_ must - be unifiable with an atom, and the argument _L_ with the list of the - characters of _A_. - - - */ - Yap_InitCPred("atom_codes", 2, atom_codes, 0); - Yap_InitCPred("string_codes", 2, string_codes, 0); - Yap_InitCPred("string_chars", 2, string_chars, 0); - Yap_InitCPred("atom_length", 2, atom_length, SafePredFlag); - /** @pred atom_length(+ _A_,? _I_) is iso - - - The predicate holds when the first argument is an atom, and the second - unifies with the number of characters forming that atom. - - - */ - Yap_InitCPred("atomic_length", 2, atomic_length, SafePredFlag); - Yap_InitCPred("string_length", 2, string_length, SafePredFlag); - Yap_InitCPred("$atom_split", 4, atom_split, SafePredFlag); - Yap_InitCPred("number_chars", 2, number_chars, 0); - Yap_InitCPred("number_atom", 2, number_atom, 0); - /** @pred number_atom(? _I_,? _L_) - - - - The predicate holds when at least one of the arguments is ground - (otherwise, an error message will be displayed). The argument _I_ must - be unifiable with a number, and the argument _L_ must be unifiable - with an atom representing the number. - - - */ - Yap_InitCPred("number_string", 2, number_string, 0); - Yap_InitCPred("number_codes", 2, number_codes, 0); - Yap_InitCPred("atom_number", 2, atom_number, 0); - /** @pred atom_number(? _Atom_,? _Number_) - - - The predicate holds when at least one of the arguments is ground - (otherwise, an error message will be displayed). If the argument - _Atom_ is an atom, _Number_ must be the number corresponding - to the characters in _Atom_, otherwise the characters in - _Atom_ must encode a number _Number_. - - - */ - Yap_InitCPred("string_number", 2, string_number, 0); - Yap_InitCPred("$atom_concat", 2, atom_concat2, 0); - Yap_InitCPred("$string_concat", 2, string_concat2, 0); - Yap_InitCPred("atomic_concat", 2, atomic_concat2, 0); - /** @pred atomic_concat(+ _As_,? _A_) - - - The predicate holds when the first argument is a list of atomic terms, - and - the second unifies with the atom obtained by concatenating all the - atomic terms in the first list. The first argument thus may contain - atoms or numbers. - - - */ - Yap_InitCPred("atomics_to_string", 2, atomics_to_string2, 0); - Yap_InitCPred("atomics_to_string", 3, atomics_to_string3, 0); - Yap_InitCPred("get_string_code", 3, get_string_code3, 0); - - Yap_InitCPred("downcase_text_to_atom", 2, downcase_text_to_atom, 0); - Yap_InitCPred("downcase_atom", 2, downcase_text_to_atom, 0); - Yap_InitCPred("upcase_text_to_atom", 2, upcase_text_to_atom, 0); - Yap_InitCPred("upcase_atom", 2, upcase_text_to_atom, 0); - Yap_InitCPred("downcase_text_to_string", 2, downcase_text_to_string, 0); - Yap_InitCPred("upcase_text_to_string", 2, upcase_text_to_string, 0); - Yap_InitCPred("downcase_text_to_codes", 2, downcase_text_to_codes, 0); - Yap_InitCPred("upcase_text_to_codes", 2, upcase_text_to_codes, 0); - Yap_InitCPred("downcase_text_to_chars", 2, downcase_text_to_chars, 0); - Yap_InitCPred("upcase_text_to_chars", 2, upcase_text_to_chars, 0); - - /* hiding and unhiding some predicates */ - Yap_InitCPred("hide_atom", 1, hide_atom, SafePredFlag | SyncPredFlag); - Yap_InitCPred("hide", 1, hide_atom, SafePredFlag | SyncPredFlag); - Yap_InitCPred("unhide_atom", 1, unhide_atom, SafePredFlag | SyncPredFlag); - Yap_InitCPred("$hidden_atom", 1, hidden_atom, - HiddenPredFlag | SafePredFlag | SyncPredFlag); - } - - /** - @} */ + Yap_InitCPred("string_to_atom", 2, string_to_atom, 0); + Yap_InitCPred("atom_string", 2, atom_string, 0); + Yap_InitCPred("string_to_atomic", 2, string_to_atomic, 0); + Yap_InitCPred("string_to_list", 2, string_to_list, 0); + Yap_InitCPred("char_code", 2, char_code, SafePredFlag); + /** @pred char_code(? _A_,? _I_) is iso + + + The built-in succeeds with _A_ bound to character represented as an + atom, and _I_ bound to the character code represented as an + integer. At least, one of either _A_ or _I_ must be bound before + the call. + + + */ + Yap_InitCPred("atom_chars", 2, atom_chars, 0); + /** @pred atom_chars(? _A_,? _L_) is iso + + + The predicate holds when at least one of the arguments is ground + (otherwise, an error message will be displayed). The argument _A_ must + be unifiable with an atom, and the argument _L_ with the list of the + characters of _A_. + + + */ + Yap_InitCPred("atom_codes", 2, atom_codes, 0); + Yap_InitCPred("string_codes", 2, string_codes, 0); + Yap_InitCPred("string_chars", 2, string_chars, 0); + Yap_InitCPred("atom_length", 2, atom_length, SafePredFlag); + /** @pred atom_length(+ _A_,? _I_) is iso + + + The predicate holds when the first argument is an atom, and the second + unifies with the number of characters forming that atom. + + + */ + Yap_InitCPred("atomic_length", 2, atomic_length, SafePredFlag); + Yap_InitCPred("string_length", 2, string_length, SafePredFlag); + Yap_InitCPred("$atom_split", 4, atom_split, SafePredFlag); + Yap_InitCPred("number_chars", 2, number_chars, 0); + Yap_InitCPred("number_atom", 2, number_atom, 0); + /** @pred number_atom(? _I_,? _L_) + + + + The predicate holds when at least one of the arguments is ground + (otherwise, an error message will be displayed). The argument _I_ must + be unifiable with a number, and the argument _L_ must be unifiable + with an atom representing the number. + + + */ + Yap_InitCPred("number_string", 2, number_string, 0); + Yap_InitCPred("number_codes", 2, number_codes, 0); + Yap_InitCPred("atom_number", 2, atom_number, 0); + /** @pred atom_number(? _Atom_,? _Number_) + + + The predicate holds when at least one of the arguments is ground + (otherwise, an error message will be displayed). If the argument + _Atom_ is an atom, _Number_ must be the number corresponding + to the characters in _Atom_, otherwise the characters in + _Atom_ must encode a number _Number_. + + + */ + Yap_InitCPred("string_number", 2, string_number, 0); + Yap_InitCPred("$atom_concat", 2, atom_concat2, 0); + Yap_InitCPred("$string_concat", 2, string_concat2, 0); + Yap_InitCPred("atomic_concat", 2, atomic_concat2, 0); + /** @pred atomic_concat(+ _As_,? _A_) + + + The predicate holds when the first argument is a list of atomic terms, + and + the second unifies with the atom obtained by concatenating all the + atomic terms in the first list. The first argument thus may contain + atoms or numbers. + + + */ + Yap_InitCPred("atomics_to_string", 2, atomics_to_string2, 0); + Yap_InitCPred("atomics_to_string", 3, atomics_to_string3, 0); + Yap_InitCPred("get_string_code", 3, get_string_code3, 0); + + Yap_InitCPred("downcase_text_to_atom", 2, downcase_text_to_atom, 0); + Yap_InitCPred("downcase_atom", 2, downcase_text_to_atom, 0); + Yap_InitCPred("upcase_text_to_atom", 2, upcase_text_to_atom, 0); + Yap_InitCPred("upcase_atom", 2, upcase_text_to_atom, 0); + Yap_InitCPred("downcase_text_to_string", 2, downcase_text_to_string, 0); + Yap_InitCPred("upcase_text_to_string", 2, upcase_text_to_string, 0); + Yap_InitCPred("downcase_text_to_codes", 2, downcase_text_to_codes, 0); + Yap_InitCPred("upcase_text_to_codes", 2, upcase_text_to_codes, 0); + Yap_InitCPred("downcase_text_to_chars", 2, downcase_text_to_chars, 0); + Yap_InitCPred("upcase_text_to_chars", 2, upcase_text_to_chars, 0); + + /* hiding and unhiding some predicates */ + Yap_InitCPred("hide_atom", 1, hide_atom, SafePredFlag | SyncPredFlag); + Yap_InitCPred("hide", 1, hide_atom, SafePredFlag | SyncPredFlag); + Yap_InitCPred("unhide_atom", 1, unhide_atom, SafePredFlag | SyncPredFlag); + Yap_InitCPred("$hidden_atom", 1, hidden_atom, + HiddenPredFlag | SafePredFlag | SyncPredFlag); +} + +/** +@} +*/ From cc7c0ebac89bd11d10fc8a859c0f147b9d7124d1 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 16 Nov 2016 17:09:06 -0600 Subject: [PATCH 08/41] error handling --- C/compiler.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/C/compiler.c b/C/compiler.c index 77d8906a3..f7966b165 100644 --- a/C/compiler.c +++ b/C/compiler.c @@ -1081,7 +1081,8 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, char s[32]; Yap_bip_name(Op, s); - Yap_ThrowError( TYPE_ERROR_NUMBER, t2, "compiling %s/2 with output bound", s); + Yap_ThrowError(TYPE_ERROR_NUMBER, t2, 1, + "compiling %s/2 with output bound", s); save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, 1); } @@ -1093,7 +1094,7 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, char s[32]; Yap_bip_name(Op, s); - Yap_ThrowError(INSTANTIATION_ERROR , t2, "compiling %s/3", s); + Yap_ThrowError(INSTANTIATION_ERROR, t2, 1, "compiling %s/3", s); save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, 1); } @@ -1103,14 +1104,15 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, Int i2; if (!IsIntegerTerm(t2)) { - Yap_Error( TYPE_ERROR_INTEGER, t2, "compiling functor/3"); + Yap_ThrowError(TYPE_ERROR_INTEGER, t2, 1, "compiling functor/3"); save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, 1); } i2 = IntegerOfTerm(t2); if (i2 < 0) { - Yap_ThrowError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO , t2,4, "compiling functor/3"); + Yap_ThrowError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO, t2, 4, + "compiling functor/3"); save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, 1); } @@ -1121,9 +1123,8 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, } else if (!IsAtomTerm(t1)) { char s[32]; - LOCAL_Error_TYPE = TYPE_ERROR_ATOM; Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling functor/3"); + Yap_ThrowError(TYPE_ERROR_ATOM, t2, 4, "compiling functor/3"); save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, 1); } @@ -1177,9 +1178,8 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, else { char s[32]; - LOCAL_Error_TYPE = TYPE_ERROR_INTEGER; Yap_bip_name(Op, s); - sprintf(LOCAL_ErrorMessage, "compiling %s/2", s); + Yap_ThrowError(TYPE_ERROR_INTEGER, t1, 1, "compiling %s/2", s); save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, 1); } @@ -1189,6 +1189,8 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, LOCAL_Error_TYPE = TYPE_ERROR_COMPOUND; Yap_bip_name(Op, s); + Yap_ThrowError(TYPE_ERROR_COMPOUND, t2, 1, "compiling %s/2", 1, s); + save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, 1); } else if (IsApplTerm(t2)) { @@ -1475,7 +1477,7 @@ static void c_goal(Term Goal, Term mod, compiler_struct *cglobs) { PredEntry *p; Prop p0; - Goal = Yap_YapStripModule( Goal, &mod); + Goal = Yap_YapStripModule(Goal, &mod); if (IsVarTerm(Goal)) { Goal = Yap_MkApplTerm(FunctorCall, 1, &Goal); } else if (IsNumTerm(Goal)) { From 56905d86ae3bce1610e466eddb4767962b28ee04 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 16 Nov 2016 17:15:12 -0600 Subject: [PATCH 09/41] more Android adjusts --- CMakeLists.txt | 2 -- Packages.cmake | 4 +++- Prelims.cmake | 12 ++++++------ library/CMakeLists.txt | 2 ++ 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 34f61d613..478c0e5d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -87,8 +87,6 @@ if (ANDROID) ADD_SUBDIRECTORY(os) ADD_SUBDIRECTORY(OPTYap) ADD_SUBDIRECTORY(packages/myddas) - ADD_SUBDIRECTORY(library/random) - ADD_SUBDIRECTORY(library/system) ADD_SUBDIRECTORY(utf8proc) ADD_SUBDIRECTORY(CXX) diff --git a/Packages.cmake b/Packages.cmake index 97b5c7ce8..d680ac503 100644 --- a/Packages.cmake +++ b/Packages.cmake @@ -50,7 +50,9 @@ add_subDIRECTORY (packages/swig) option (WITH_DOCS "generate YAP docs" OFF) - # add_subDIRECTORY (docs) + IF (WITH_DOCS) + add_subDIRECTORY (docs) + ENDIF (WITH_DOCS) # add_subDIRECTORY (packages/cuda) diff --git a/Prelims.cmake b/Prelims.cmake index d07f05a50..d560169a7 100644 --- a/Prelims.cmake +++ b/Prelims.cmake @@ -128,16 +128,16 @@ endif(POLICY CMP0043) if (ANDROID) - set ( prefix ${YAP_APP_DIR}/app/src/generated ) - set ( datarootdir ${YAP_APP_DIR}/app/src/generated/assets ) -set ( includedir "${prefix}/assets/include") - set ( libpl ${YAP_APP_DIR}/app/src/generated/assets/Yap) + set ( prefix ${YAP_APP_DIR}/generated ) + set ( datarootdir ${YAP_APP_DIR}/generated/assets ) +#set ( includedir "${prefix}/assets/include") + set ( libpl ${YAP_APP_DIR}/generated/assets/Yap) else() set ( prefix "${CMAKE_INSTALL_PREFIX}") -set ( datarootdir "${prefix}/share") + set ( datarootdir ${prefix}/share ) set ( libpl "${datarootdir}/Yap") -set ( includedir "${prefix}/include") endif() +set ( includedir "${prefix}/include") set ( exec_prefix "${prefix}") set ( libdir "${exec_prefix}/lib") set ( dlls "${exec_prefix}/lib/Yap") diff --git a/library/CMakeLists.txt b/library/CMakeLists.txt index 4aa4301fb..811f05438 100644 --- a/library/CMakeLists.txt +++ b/library/CMakeLists.txt @@ -72,6 +72,8 @@ MY_add_subdirectory(rltree) MY_add_subdirectory(system) MY_add_subdirectory(tries) MY_add_subdirectory(ytest) + + if (ANDROID) file(INSTALL ${LIBRARY_PL} DESTINATION ${libpl}) else() From 8d1cc35a8a2bbe17bb2bc0a8284cb98ef00dbbd8 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 16 Nov 2016 17:17:33 -0600 Subject: [PATCH 10/41] docsc --- .gitignore | 2 + C/attvar.c | 7 +- PrologCommons/PROLOGCOMMONS.md | 3 +- README.md | 25 +- docs/Doxyfile | 7 +- docs/Doxyfile.in | 5 +- docs/builtins.md | 31 ++ docs/download.md | 17 + docs/extensions.md | 21 + docs/fli.md | 16 + docs/install.md | 0 docs/library.md | 58 +++ docs/load_files.md | 11 + docs/packages.md | 28 + docs/run.md | 19 +- docs/swi.md | 182 +++++++ docs/syntax.md | 33 +- docs/yap.md | 601 +--------------------- library/atts.yap | 6 +- misc/PROLOGCOMMONS.md | 2 + os/readterm.c | 94 +++- packages/bdd/{README => bdd.md} | 13 +- {docs => packages/chr}/chr.md | 4 - packages/chr/chr.yap | 536 ------------------- {docs => packages/clpqr}/clpqr.md | 5 +- packages/clpqr/clpr.pl | 5 +- packages/gecode/{DOC.txt => gecode.md} | 22 +- packages/myddas/myddas.md | 574 +++++++++++++++++++++ packages/myddas/pl/myddas.ypp | 685 +------------------------ packages/raptor/README.md | 8 +- packages/real/README.md | 227 +++++++- packages/real/real.pl | 223 -------- packages/udi/udi.md | 5 +- pl/attributes.md | 14 +- pl/modules.md | 5 +- run.md | 193 +++++++ 36 files changed, 1523 insertions(+), 2164 deletions(-) delete mode 100644 docs/install.md create mode 100644 docs/library.md create mode 100644 docs/load_files.md rename packages/bdd/{README => bdd.md} (67%) rename {docs => packages/chr}/chr.md (99%) rename {docs => packages/clpqr}/clpqr.md (97%) rename packages/gecode/{DOC.txt => gecode.md} (91%) create mode 100644 packages/myddas/myddas.md create mode 100644 run.md diff --git a/.gitignore b/.gitignore index e9a3c5a7c..634f7d844 100644 --- a/.gitignore +++ b/.gitignore @@ -203,3 +203,5 @@ packages/python/yap_kernel/x/__init__.py packages/python/yap_kernel/x/__main__.py *.gch +mxe +build diff --git a/C/attvar.c b/C/attvar.c index a2627a09e..e6045e8d8 100644 --- a/C/attvar.c +++ b/C/attvar.c @@ -28,10 +28,11 @@ static char SccsId[] = "%W% %G%"; #define NULL (void *)0 #endif -/** @{ */ +/** @file attvars.c + @{ */ -/** @defgroup AttributeVariables_Builtins Implementation of Attribute - Declarations +/** + * @defgroup AttributeVariables_Builtins Implementation of Attribute Declarations @ingroup AttributeVariables */ diff --git a/PrologCommons/PROLOGCOMMONS.md b/PrologCommons/PROLOGCOMMONS.md index a2d50cd9d..ecb96a348 100644 --- a/PrologCommons/PROLOGCOMMONS.md +++ b/PrologCommons/PROLOGCOMMONS.md @@ -1,4 +1,5 @@ - +Prolog Commons {#prolog_commons} +============= This directory should hold files from the Prolog Commons project. Please see diff --git a/README.md b/README.md index 610b8d187..756627999 100644 --- a/README.md +++ b/README.md @@ -3,12 +3,12 @@ ![The YAP Logo](docs/icons/yap_128x128x32.png) -README for YAP6 +User Manual for YAP6 (#main) ==================== -NOTE: this version of YAP is stil experimental, documentation may be out of date. +NOTE: this version of YAP is still experimental, documentation may be out of date. -## Introduction +## Introduction This document provides User information on version 6.3.4 of YAP (Yet Another Prolog). The YAP Prolog System is a @@ -94,22 +94,3 @@ DTAI group of KULeuven. + The [R](http://stoics.org.uk/~nicos/sware/packs/real/) interface package developed by Nicos Angelopoulos, Vítor Santos Costa, João Azevedo, Jan Wielemaker, and Rui Camacho. - - -Downloading YAP {#download} -============== - -The latest development version of Yap-6 is yap-6.3.4 and can be -obtained from the repositories - - - -and - - - -YAP-6.3.4 does not use modules. Please just use `git clone` to obtain the distribution. - -Most of these repositories are basically copies of the original -repositories at the SWI-Prolog site. YAP-6 will work either with or -without these packages. diff --git a/docs/Doxyfile b/docs/Doxyfile index b56d7949a..59e828927 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -785,9 +785,8 @@ INPUT = /Users/vsc/git/yap-6.3/pl \ /Users/vsc/git/yap-6.3/library \ /Users/vsc/git/yap-6.3/packages \ /Users/vsc/git/yap-6.3/swi/library \ - /Users/vsc/git/yap-6.3/docs/yap.md \ - /Users/vsc/git/yap-6.3/docs/chr.md \ - /Users/vsc/git/yap-6.3/docs/clpqr.md \ + /Users/vsc/git/yap-6.3/docs/*.md \ + /Users/vsc/git/yap-6.3/*.md \ # This tag can be used to specify the character encoding of the source files @@ -937,7 +936,7 @@ FILTER_SOURCE_PATTERNS = # (index.html). This can be useful if you have a project on for instance GitHub # and want to reuse the introduction page also for the doxygen output. -USE_MDFILE_AS_MAINPAGE = +USE_MDFILE_AS_MAINPAGE = #--------------------------------------------------------------------------- # Configuration options related to source browsing diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in index f18062fa2..e53fe508f 100644 --- a/docs/Doxyfile.in +++ b/docs/Doxyfile.in @@ -785,9 +785,8 @@ INPUT = @PROJECT_SOURCE_DIR@/pl \ @PROJECT_SOURCE_DIR@/library \ @PROJECT_SOURCE_DIR@/packages \ @PROJECT_SOURCE_DIR@/swi/library \ - @PROJECT_SOURCE_DIR@/docs/yap.md \ - @PROJECT_SOURCE_DIR@/docs/chr.md \ - @PROJECT_SOURCE_DIR@/docs/clpqr.md \ + @PROJECT_SOURCE_DIR@/docs/*.md \ + @PROJECT_SOURCE_DIR@/*.md # This tag can be used to specify the character encoding of the source files diff --git a/docs/builtins.md b/docs/builtins.md index e69de29bb..5625441b5 100644 --- a/docs/builtins.md +++ b/docs/builtins.md @@ -0,0 +1,31 @@ +YAP Built-ins {#builtins} +================= + +This chapter describes the core predicates that control the execution of +Prolog programs, provide fundamental functionality such as termm manipulation or arithmetic, and support interaction with external +resources, Many of the predicates described here have been standardised by the ISO. The standartised subset of Proloh also known as ISO-Prolog. + +In the description of the arguments of functors the following notation +will be used: + ++ a preceding plus sign will denote an argument as an "input +argument" - it cannot be a free variable at the time of the call; ++ a preceding minus sign will denote an "output argument"; ++ an argument with no preceding symbol can be used in both ways. ++ @ref YAPControl + ++ @ref Arithmetic + ++ @ref YAPChars + ++ @ref YAP_Terms + ++ @ref InputOutput + ++ @ref AbsoluteFileName + ++ @ref YAPOS + ++ @ref Internal_Database + ++ @ref Sets diff --git a/docs/download.md b/docs/download.md index e69de29bb..492a0ce6c 100644 --- a/docs/download.md +++ b/docs/download.md @@ -0,0 +1,17 @@ +Downloading YAP {#download} +============== + +The latest development version of Yap-6 is yap-6.3.4 and can be +obtained from the repositories + + + +and + + + +YAP-6.3.4 does not use modules. Please just use `git clone` to obtain the distribution. + +Most of these repositories are basically copies of the original +repositories at the SWI-Prolog site. YAP-6 will work either with or +without these packages. diff --git a/docs/extensions.md b/docs/extensions.md index e69de29bb..844c2e302 100644 --- a/docs/extensions.md +++ b/docs/extensions.md @@ -0,0 +1,21 @@ +Extensions to core Prolog. {#extensions} +========================= + +YAP includes a number of extensions over the original Prolog +language. Next, we discuss how to use the most important ones. + + + @ref Rational_Trees + + + @ref AttributedVariables + + + @ref DepthLimited + + + @ref Tabling + + + @ref Threads + + + @ref Profiling + + + @ref YAPArrays + + + @ref Parallelism diff --git a/docs/fli.md b/docs/fli.md index e69de29bb..31df4b1ea 100644 --- a/docs/fli.md +++ b/docs/fli.md @@ -0,0 +1,16 @@ +The Foreign Code Interface {#fli} +=========================== + +YAP provides the user with three facilities for writing +predicates in a language other than Prolog. Under Unix systems, +most language implementations were linkable to `C`, and the first interface exported the YAP machinery to the C language. YAP also implements most of the SWI-Prolog foreign language interface. +This gives portability with a number of SWI-Prolog packages and avoids garnage collection by using @ref slotInterface. Last, a new C++ based interface is +being designed to work with the swig (www.swig.orgv) interface compiler. + ++ The @ref c-interface exports the YAP engine. + ++ The @ref swi-c-interface emulates Jan Wielemaker's SWI foreign language interface. + ++ The @ref yap-cplus-interface is desiged to interface with the SWIG package by using Object-Oriented concepts + ++ The @ref LoadInterface handles the setup of foreign files diff --git a/docs/install.md b/docs/install.md deleted file mode 100644 index e69de29bb..000000000 diff --git a/docs/library.md b/docs/library.md new file mode 100644 index 000000000..7e69e0d2a --- /dev/null +++ b/docs/library.md @@ -0,0 +1,58 @@ +The YAP Library (#library) +============== + + Library files reside in the library_directory path (set by the + `LIBDIR` variable in the Makefile for YAP). Several files in the + library are originally from the public-domain Edinburgh Prolog library. + +- @ref apply +- @ref apply_macros +- @ref arg +- @ref Association_Lists +- @ref avl +- @ref bhash +- @ref block_diagram +- @ref c_alarms +- @ref charsio +- @ref clauses +- @ref cleanup +- @ref dbqueues +- @ref dbusage +- @ref dgraphs +- @ref exo_interval +- @ref flags +- @ref gensym +- @ref yap_hacks +- @ref heaps +- @ref lam_mpi +- @ref line_utils +- @ref swi_listing +- @ref lists +- @ref mapargs +- @ref maplist +- @ref matlab +- @ref matrix +- @ref nb +- @ref Ordered_Sets +- @ref parameters +- @ref queues +- @ref random +- @ref Pseudo_Random +- @ref rbtrees +- @ref regexp +- @ref rltrees +- @ref Splay_Trees +- @ref operating_system_support, +- @ref Terms +- @ref timeout +- @ref trees +- @ref tries +- @ref ugraphs +- @ref undgraphs +- @ref varnumbers +- @ref wdgraphs +- @ref wdgraphs +- @ref wdgraphs +- @ref wgraphs +- @ref wundgraphs +- @ref ypp diff --git a/docs/load_files.md b/docs/load_files.md new file mode 100644 index 000000000..9a95f40cf --- /dev/null +++ b/docs/load_files.md @@ -0,0 +1,11 @@ +Loading and Oganising YAP Programs {#consult} +=================================== + + Next, we present the main predicates and directives available to load + files and to control the Prolog environment. + + + @ref YAPConsulting + + + @subpage YAPModules + + + @ref YAPSaving diff --git a/docs/packages.md b/docs/packages.md index e69de29bb..076093040 100644 --- a/docs/packages.md +++ b/docs/packages.md @@ -0,0 +1,28 @@ +YAP packages files {#packages} +=================== + ++ @subpage real + ++ @ref BDDs + ++ @subpage ecode + ++ @subpage myddas + ++ @ref PFL/CLP(BN) + ++ @ref ProbLog1 + ++ @ref Python + ++ @subpage YAPRaptor + ++ @ref YAP-LBFGS + ++ @subpage yap-udi-indexers + +Leuven packages ported from SWI-Prolog: + ++ @subpage chr + ++ @subpage clpqr diff --git a/docs/run.md b/docs/run.md index e9b724366..e442df2b6 100644 --- a/docs/run.md +++ b/docs/run.md @@ -1,4 +1,4 @@ -Running YAP +Running YAP {#run} =========== We next describe how to invoke YAP in Unix systems. @@ -24,7 +24,7 @@ specify M bytes. allocate _Size_ KBytes for heap and auxiliary stacks + -t _Size_ allocate _Size_ KBytes for the trail stack -+ -L _Size_ ++ -L _Size_ SWI-compatible option to allocate _Size_ K bytes for local and global stacks, the local stack cannot be expanded. To avoid confusion with the load option, _Size_ must immediately follow the letter `L`. @@ -62,34 +62,34 @@ through the unix/1 built-in predicate. Note that YAP will output an error message on the following conditions: -+ ++ a file name was given but the file does not exist or is not a saved YAP state; -+ ++ the necessary amount of memory could not be allocated; -+ ++ the allocated memory is not enough to restore the state. - + When restoring a saved state, YAP will allocate the same amount of memory as that in use when the state was saved, unless a different amount is specified by flags in the command line. By default, YAP restores the file startup.yss from the current directory or from the YAP library. -+ ++ YAP usually boots from a saved state. The saved state will use the default installation directory to search for the YAP binary unless you define the environment variable YAPBINDIR. -+ ++ YAP always tries to find saved states from the current directory first. If it cannot it will use the environment variable YAPLIBDIR, if defined, or search the default library directory. -+ ++ YAP will try to find library files from the YAPSHAREDIR/library directory. @@ -188,4 +188,3 @@ they must be sent directly to the argv built-in. Hence, running ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ will write `test` on the standard output. - diff --git a/docs/swi.md b/docs/swi.md index e69de29bb..c82a99624 100644 --- a/docs/swi.md +++ b/docs/swi.md @@ -0,0 +1,182 @@ +Compatibility with other Prolog systems {#swi} +======================================= + +YAP has been designed to be as compatible as possible with other +Prolog systems, originally with C-Prolog\cite x and SICStus +Prolog~\cite x . More recent work on YAP has striven at making YAP +compatible with the ISO-Prolog standard\cite x , and with Jan +Wielemaker's SWI-Prolog\cite x . + +SWI-Prolog and YAP have collaborated at improved compatibility \cite x . This +resulted in Prolog extensions such as the `dialect` feature. YAP +currently supports most of the SWI-Prolog foreign interface. The following SWI +libraries have been adapted to YAP: + + + @ref aggregate + + @ref base64 + + @ref broadcast + + @ref ctypes + + @ref date + + @ref prolog_debug + + @ref prolog_edit + + @ref error + + @ref nb_set + + @ref prolog_operator + + @ref swi_option + + @ref pairs + + @ref pio + + @ref predicate_options, + + @ref predopts + + @ref prolog_clause + + @ref prolog_colour + + @ref prolog_source + + @ref prolog_xref + + @ref pure_input + + @ref quasi_quotations + + @ref read_util + + @ref record + + @ref settings + + @ref shlib + + @ref thread_pool + + @ref url + + @ref utf8 + + @ref win_menu + + @ref www_browser + + +Note that in general SWI code may be from an earlier version than the +one available with SWI-Prolog. SWI-Prolog are obviously not +responsible for any incompatibilities and/or bugs in the YAP port. + +Please do refer to the SWI-Prolog home page: + + + +for more information on SWI-Prolog and the SWI packages. + +Compatibility with the C-Prolog interpreter {#ChYProlog} +------------------------------------------- + +YAP was designed so that most C-Prolog programs should run under YAP +without changes. +The most important difference between YAP and C-Prolog is that, being +YAP a compiler, some changes should be made if predicates such as +assert/1, clause/1 and retract/1 are used. First +predicates which will change during execution should be declared as +`dynamic` by using commands like: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +:- dynamic f/n. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + where `f` is the predicate name and n is the arity of the +predicate. Note that several such predicates can be declared in a +single command: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + :- dynamic f/2, ..., g/1. +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Primitive predicates such as `retract` apply only to dynamic +predicates. Finally note that not all the C-Prolog primitive predicates +are implemented in YAP. They can easily be detected using the +`unknown` system predicate provided by YAP. + +Last, by default YAP enables character escapes in strings. You can +disable the special interpretation for the escape character by using: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +:- yap_flag(character_escapes,off). +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +or by using: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +:- yap_flag(language,cprolog). +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + +Compatibility with the Quintus and SICStus Prolog systems +--------------------------------------------------------- + +The Quintus Prolog system was the first Prolog compiler to use Warren's +Abstract Machine. This system was very influential in the Prolog +community. Quintus Prolog implemented compilation into an abstract +machine code, which was then emulated. Quintus Prolog also included +several new built-ins, an extensive library, and in later releases a +garbage collector. The SICStus Prolog system, developed at SICS (Swedish +Institute of Computer Science), is an emulator based Prolog system +largely compatible with Quintus Prolog. SICStus Prolog has evolved +through several versions. The current version includes several +extensions, such as an object implementation, co-routining, and +constraints. + +Both YAP and SICStus Prolog obey the Edinburgh Syntax and are based on +the WAM. Even so, there are major important differences: + + + Differently from SICStus Prolog, both consulted and dynamic code in YAP + are compiled, not interpreted. All code in YAP is compiled. + + + The following SICStus Prolog v3 built-ins are not (currently) +implemented in YAP (note that this is only a partial list): +stream_interrupt/3, reinitialize/0, help/0, help/1, +trimcore/0, and require/1. + + + The consult/1 predicate in YAP follows C-Prolog +semantics. That is, it adds clauses to the data base, even for +preexisting procedures. This is different from consult/1 in +SICStus Prolog or SWI-Prolog. + + + This list is incomplete. + +Compatibility with the ISO Prolog standard +------------------------------------------ + +The Prolog standard was developed by ISO/IEC JTC1/SC22/WG17, the +international standardization working group for the programming language +Prolog. The book "Prolog: The Standard" by Deransart, Ed-Dbali and +Cervoni gives a complete description of this standard. Development in +YAP from YAP4.1.6 onwards have striven at making YAP +compatible with ISO Prolog. As such: + + + YAP now supports all of the built-ins required by the +ISO-standard, and, + + Error-handling is as required by the standard. + + +YAP by default is not fully ISO standard compliant. You can set the +language flag to `iso` to obtain better +compatibility. Setting this flag changes the following: + + + + By default, YAP implements the +atom_chars/2 (see Testing Terms), and +number_chars/2, (see Testing Terms), +built-ins as per the original Quintus Prolog definition, and +not as per the ISO definition. + +Calling `set_prolog_flag(to_chars_mode,iso)` will switch +YAP to use the ISO definition for +atom_chars/2 and number_chars/2. + + + By default, YAP allows executable goals in directives. In ISO mode +most directives can only be called from top level (the exceptions are +set_prolog_flag/2 and op/3). + + + Error checking for meta-calls under ISO Prolog mode is stricter +than by default. + + + The strict_iso flag automatically enables the ISO Prolog +standard. This feature should disable all features not present in the +standard. + +The following incompatibilities between YAP and the ISO standard are +known to still exist (please check Ulrich Neumerkel's page for more details): + +
    + +
  • Currently, YAP does not handle overflow errors in integer +operations, and handles floating-point errors only in some +architectures. Otherwise, YAP follows IEEE arithmetic. + +Please inform the authors on other incompatibilities that may still +exist. diff --git a/docs/syntax.md b/docs/syntax.md index 1dd73cb2c..6c46eac77 100644 --- a/docs/syntax.md +++ b/docs/syntax.md @@ -1,6 +1,5 @@ - - -@file syntax.md +YAP Syntax (#YAPSyntax) +============ @defgroup YAPSyntax YAP Syntax @ingroup mainpage @@ -198,11 +197,11 @@ YAP supports four different textual elements: data-base. They are stored either in ISO-LATIN-1 (first 256 code points), or as UTF-32. + Strings are atomic representations of text. The back-quote character is used to identify these objects in the program. Strings exist as stack objects, in the same way as other Prolog terms. As Prolog unification cannot be used to manipulate strings, YAP includes built-ins such as string_arg/3, sub_string/5, or string_concat to manipulate them efficiently. Strings are stored as opaque objects containing a - + + Lists of codes represent text as a list of numbers, where each number is a character code. A string of _N_ bytes requires _N_ pairs, that is _2N_ cells, leading to a total of 16 bytes per character on 64 byte machines. Thus, they are a very expensive, but very flexible representation, as one can use unification to construct and access string elements. - + + Lists of atoms represent text as a list of atoms, where each number has a single character code. A string of _N_ bytes also requires _2N_ pairs. They have similar properties to lists of codes. - + The flags `double_quotes` and `backquoted_string` change the interpretation of text strings, they can take the values `atom`, `string`, `codes`, and `chars`. @@ -213,7 +212,7 @@ Examples: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The first string is an empty string, the last string shows the use of -double-quoting. +double-quoting. Escape sequences can be used to include the non-printable characters `a` (alert), `b` (backspace), `r` (carriage return), @@ -346,7 +345,7 @@ atoms. If the text fits in ISO Latin-1, it is represented as an array of 8-bit characters. Otherwise the text is represented as an array of wide chars, which may take 16 or 32 bits. This representational issue is completely transparent to the Prolog user. Users of the foreign -language interface sometimes need to be aware of these issues though. Notice that this will likely +language interface sometimes need to be aware of these issues though. Notice that this will likely change in the future, we probably will use an UTF-8 based representation. Character coding comes into view when characters of strings need to be @@ -359,7 +358,7 @@ as well as I/O through network sockets. @ingroup WideChars The UCS standard describes all possible characters (or code points, as they include -ideograms, ligatures, and other symbols). The current version, Unicode 8.0, allows +ideograms, ligatures, and other symbols). The current version, Unicode 8.0, allows code points up to 0x10FFFF, and thus allows for 1,114,112 code points. See [Unicode Charts](http://unicode.org/charts/) for the supported languages. Notice that most symbols are rarely used. Encodings represent the Unicode characters in a way @@ -367,23 +366,23 @@ that is more suited for communication. The most popular encoding, especially in UTF-8. UTF-8 is compact and as it uses bytes, does not have different endianesses. Bytes 0...127 represent simply the corresponding US-ASCII character, while bytes 128...255 are used for multi-byte -encoding of characters placed higher in the UCS space. +encoding of characters placed higher in the UCS space. Especially on MS-Windows and Java the 16-bit Unicode standard, represented by pairs of bytes is -also popular. Originally, Microsoft supported a UCS-2 with 16 bits that +also popular. Originally, Microsoft supported a UCS-2 with 16 bits that could represent only up to 64k characters. This was later extended to support the full Unicode, we will call the latter version UTF-16. The extension uses a hole in the first 64K code points. Characters above 0xFFFF are divided into two 2-byte words, each one in that hole. There are two versions of UTF-16: big and low endian. By default, UTF-16 is big endian, in practice most often it is used on Intel hardware that is naturally little endian. - - UTF-32, often called UCS-4, provides a natural interface where a code point is coded as + + UTF-32, often called UCS-4, provides a natural interface where a code point is coded as four octets. Unfortunately, it is also more expensive, so it is not as widely used. - + Last, other encodings are also commonly used. One such legacy encoding is ISO-LATIN-1, that supported latin based languages in western europe. YAP currently uses either ISO-LATIN-1 or UTF-32 internally. - + Prolog supports the default encoding used by the Operating System, Namely, YAP checks the variables LANG, LC_ALL and LC_TYPE. Say, if at boot YAP detects that the environment variable `LANG` ends in "UTF-8", this encoding is @@ -419,7 +418,7 @@ but generates errors and warnings on encountering values above 8-bit encoding supporting many western languages. This causes the stream to be read and written fully untranslated. - + `text` + + `text` C-library default locale encoding for text files. Files are read and written using the C-library functions `mbrtowc()` and `wcrtomb()`. This may be the same as one of the other locales, @@ -484,7 +483,7 @@ writing, writing a BOM can be requested using the option `bom(true)` with `open/4`. YAP will parse an UTF-8 file for a BOM only if explicitly required to do so. Do notice that YAP will write a BOM by default on UTF-16 (including UCS-2) and UTF-32; otherwise the default is not to write a BOM. BOMs are not avaliable for ASCII and ISO-LATIN-1. - + = @addgroup Operators Summary of YAP Predefined Operators @ingroup YapSyntax diff --git a/docs/yap.md b/docs/yap.md index 5736afc26..e4d98d156 100644 --- a/docs/yap.md +++ b/docs/yap.md @@ -1,31 +1,31 @@ YAP 6-3.4 Manual {#mainpage} ==================== -This file documents the YAP Prolog System version 6.3.4, a high-performance Prolog compiler developed at LIACC, Universidade do Porto. YAP is based on David H. D. Warren's WAM (Warren Abstract Machine), with several optimizations for better performance. YAP follows the Edinburgh tradition, and is largely compatible with DEC-10 Prolog, Quintus Prolog, and especially with C-Prolog. +This file documents the YAP Prolog System version 6.3.4, a high-performance Prolog compiler developed at LIACC, Universidade do Porto. YAP is based on David H. D. Warren's WAM (Warren Abstract Machine), with several optimizations for better performance. YAP follows the Edinburgh tradition, and is largely compatible with DEC-10 Prolog, Quintus Prolog, and originally with C-Prolog. -+ @ref download +The manual is organised as follows: -+ @ref install -+ @ref run ++ @subpage download -+ @ref YAPSyntax ++ @subpage install -+ @ref consult ++ @subpage run -+ @ref builtins ++ @subpage builtins -+ @ref extensions ++ @subpage extensions -+ @ref library ++ @subpage library -+ @ref packages ++ @subpage swi -+ @ref swi ++ @subpage packages -+ @ref YAPProgramming ++ @subpage YAPProgramming + ++ @subpage Fli -+ @ref fli @@ -51,578 +51,3 @@ originally from the SWI-Prolog manual, with the gracious authorization from Jan Wielemaker. We would also like to gratefully acknowledge the contributions from Ashwin Srinivasian. - - - -Loading and Organising YAP Programs {#consult} -=================================== - - @ingroup main - - Next, we present the main predicates and directives available to load - files and to control the Prolog environment. - - + @ref YAPConsulting - - + @ref YAPModules - - +@ref YAPSaving - - - This chapter describes the predicates controlling the execution of - Prolog programs. - - In the description of the arguments of functors the following notation - will be used: - - + a preceding plus sign will denote an argument as an "input - argument" - it cannot be a free variable at the time of the call; - + a preceding minus sign will denote an "output argument"; - + an argument with no preceding symbol can be used in both ways. - -Running YAP {#run} -=========== - -We next describe how to invoke YAP in Unix systems. - -Running YAP Interactively -------------------------- - -Most often you will want to use YAP in interactive mode. Assuming that -YAP is in the user's search path, the top-level can be invoked under -Unix with the following command: - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -yap [-s n] [-h n] [-a n] [-c IP_HOST port ] [filename] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -All the arguments and flags are optional and have the following meaning: - -+ -? -print a short error message. -+ -s _Size_ -allocate _Size_ KBytes for local and global stacks. The user may -specify M bytes. -+ -h _Size_ -allocate _Size_ KBytes for heap and auxiliary stacks -+ -t _Size_ -allocate _Size_ KBytes for the trail stack -+ -L _Size_ -SWI-compatible option to allocate _Size_ K bytes for local and global stacks, the local stack -cannot be expanded. To avoid confusion with the load option, _Size_ -must immediately follow the letter `L`. -+ -G _Size_ -SWI-compatible option to allocate _Size_ K bytes for local and global stacks; the global -stack cannot be expanded -+ -T _Size_ -SWI-compatible option to allocate _Size_ K bytes for the trail stack; the trail cannot be expanded. -+ -l _YAP_FILE_ -compile the Prolog file _YAP_FILE_ before entering the top-level. -+ -L _YAP_FILE_ -compile the Prolog file _YAP_FILE_ and then halt. This option is -useful for implementing scripts. -+ -g _Goal_ -run the goal _Goal_ before top-level. The goal is converted from -an atom to a Prolog term. -+ -z _Goal_ -run the goal _Goal_ as top-level. The goal is converted from -an atom to a Prolog term. -+ -b _BOOT_FILE_ -boot code is in Prolog file _BOOT_FILE_. The filename must define -the predicate `'$live'/0`. -+ -c IP_HOST port -connect standard streams to host IP_HOST at port port -+ filename -restore state saved in the given file -+ -f -do not consult initial files -+ -q -do not print informational messages -+ -- -separator for arguments to Prolog code. These arguments are visible -through the unix/1 built-in predicate. - - -Note that YAP will output an error message on the following conditions: - -+ -a file name was given but the file does not exist or is not a saved -YAP state; - -+ -the necessary amount of memory could not be allocated; - -+ -the allocated memory is not enough to restore the state. - - - When restoring a saved state, YAP will allocate the -same amount of memory as that in use when the state was saved, unless a -different amount is specified by flags in the command line. By default, -YAP restores the file startup.yss from the current directory or from -the YAP library. - -+ -YAP usually boots from a saved state. The saved state will use the default -installation directory to search for the YAP binary unless you define -the environment variable YAPBINDIR. - -+ -YAP always tries to find saved states from the current directory - first. If it cannot it will use the environment variable YAPLIBDIR, if - defined, or search the default library directory. - -+ -YAP will try to find library files from the YAPSHAREDIR/library -directory. - - -Prolog Scripts --------------- - -YAP can also be used to run Prolog files as scripts, at least in -Unix-like environments. A simple example is shown next (do not forget -that the shell comments are very important): - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#!/usr/local/bin/yap -L -- -# -# Hello World script file using YAP -# -# put a dot because of syntax errors . - -:- write('Hello World'), nl. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -The `#!` characters specify that the script should call the binary -file YAP. Notice that many systems will require the complete path to the -YAP binary. The `-L` flag indicates that YAP should consult the -current file when booting and then halt. The remaining arguments are -then passed to YAP. Note that YAP will skip the first lines if they -start with `#` (the comment sign for Unix's shell). YAP will -consult the file and execute any commands. - -A slightly more sophisticated example is: - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#!/usr/bin/yap -L -- -# -# Hello World script file using YAP -# . - -:- initialization(main). - -main :- write('Hello World'), nl. - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -The `initialization` directive tells YAP to execute the goal main -after consulting the file. Source code is thus compiled and `main` -executed at the end. The `.` is useful while debugging the script -as a Prolog program: it guarantees that the syntax error will not -propagate to the Prolog code. - -Notice that the `--` is required so that the shell passes the extra -arguments to YAP. As an example, consider the following script -`dump_args`: - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#!/usr/bin/yap -L -- -#. - -main( [] ). -main( [H|T] ) :- - write( H ), nl, - main( T ). - -:- unix( argv(AllArgs) ), main( AllArgs ). - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -If you this run this script with the arguments: - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -./dump_args -s 10000 -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -the script will start an YAP process with stack size `10MB`, and -the list of arguments to the process will be empty. - -Often one wants to run the script as any other program, and for this it -is convenient to ignore arguments to YAP. This is possible by using -`L --` as in the next version of `dump_args`: - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -#!/usr/bin/yap -L -- - -main( [] ). -main( [H|T] ) :- - write( H ), nl, - main( T ). - -:- unix( argv(AllArgs) ), main( AllArgs ). - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -The `--` indicates the next arguments are not for YAP. Instead, -they must be sent directly to the argv built-in. Hence, running - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -./dump_args test -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -will write `test` on the standard output. - -YAP Built-ins {#builtins} -============= - - + @ref YAPControl - - + @ref arithmetic - - + @ref YAPChars - - + @ref YAP_Terms - - + @ref InputOutput - - + @ref AbsoluteFileName - - + @ref YAPOS - - + @ref Internal_Database - - + @ref Sets - -Extensions to core Prolog. {#extensions} -========================== - -YAP includes a number of extensions over the original Prolog -language. Next, we discuss how to use the most important ones. - - + @ref Rational_Trees - - + @ref AttributedVariables - - + @ref DepthLimited - - + @ref Tabling - - + @ref Threads - - + @ref Profiling - - + @ref YAPArrays - - + @ref Parallelism - -The YAP Library {#library} -=============== - -@defgroup library YAP library files -@{ - - Library files reside in the library_directory path (set by the - `LIBDIR` variable in the Makefile for YAP). Several files in the - library are originally from the public-domain Edinburgh Prolog library. - -- @ref apply -- @ref apply_macros -- @ref arg -- @ref Association_Lists -- @ref avl -- @ref bhash -- @ref block_diagram -- @ref c_alarms -- @ref charsio -- @ref clauses -- @ref cleanup -- @ref dbqueues -- @ref dbusage -- @ref dgraphs -- @ref exo_interval -- @ref flags -- @ref gensym -- @ref yap_hacks -- @ref heaps -- @ref lam_mpi -- @ref line_utils -- @ref swi_listing -- @ref lists -- @ref mapargs -- @ref maplist -- @ref matlab -- @ref matrix -- @ref nb -- @ref Ordered_Sets -- @ref parameters -- @ref queues -- @ref random -- @ref Pseudo_Random -- @ref rbtrees -- @ref regexp -- @ref rltrees -- @ref Splay_Trees -- @ref operating_system_support, -- @ref Terms -- @ref timeout -- @ref trees -- @ref tries -- @ref ugraphs -- @ref undgraphs -- @ref varnumbers -- @ref wdgraphs -- @ref wdgraphs -- @ref wdgraphs -- @ref wgraphs -- @ref wundgraphs -- @ref ypp -@} - -The YAP Packages {#packages} -================ - -@defgroup packages YAP packages files -@{ - -+ @ref real - -+ @ref BDDs - -+ @ref Gecode - -+ @ref MYDDAS - -+ @ref PFL - -+ @ref ProbLog1 - -+ @ref python - -+ @ref YAPRaptor - -+ @ref YAP-LBFGS - -+ @subpage yap-udi-indexers - -Leuven packages ported from SWI-Prolog: - -+ @subpage chr - -+ @subpage clpqr - -@} - -Compatibility {#swi} -============= - - -@defgroup swi Compatibility -@{ - - -YAP has been designed to be as compatible as possible with other -Prolog systems, originally with C-Prolog\cite x and SICStus -Prolog~\cite x . More recent work on YAP has striven at making YAP -compatible with the ISO-Prolog standard\cite x , and with Jan -Wielemaker's SWI-Prolog\cite x . - -SWI-Prolog and YAP have collaborated at improved compatibility \cite x . This -resulted in Prolog extensions such as the `dialect` feature. YAP -currently supports most of the SWI-Prolog foreign interface. The following SWI -libraries have worked on YAP: - - + @ref aggregate - + @ref base64 - + @ref broadcast - + @ref ctypes - + @ref date - + @ref prolog_debug - + @ref prolog_edit - + @ref error - + @ref nb_set - + @ref prolog_operator - + @ref swi_option - + @ref pairs - + @ref pio - + @ref predicate_options, - + @ref predopts - + @ref prolog_clause - + @ref prolog_colour - + @ref prolog_source - + @ref prolog_xref - + @ref pure_input - + @ref quasi_quotations - + @ref read_util - + @ref record - + @ref settings - + @ref shlib - + @ref thread_pool - + @ref url - + @ref utf8 - + @ref win_menu - + @ref www_browser - - -Note that in general SWI code may be from an earlier version than the -one available with SWI-Prolog. SWI-Prolog are obviously not -responsible for any incompatibilities and/or bugs in the YAP port. - -Please do refer to the SWI-Prolog home page: - - - -for more information on SWI-Prolog and the SWI packages. - -Compatibility with the C-Prolog interpreter {#ChYProlog} -------------------------------------------- - -YAP was designed so that most C-Prolog programs should run under YAP -without changes. -The most important difference between YAP and C-Prolog is that, being -YAP a compiler, some changes should be made if predicates such as -assert/1, clause/1 and retract/1 are used. First -predicates which will change during execution should be declared as -`dynamic` by using commands like: - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -:- dynamic f/n. -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - where `f` is the predicate name and n is the arity of the -predicate. Note that several such predicates can be declared in a -single command: - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - :- dynamic f/2, ..., g/1. -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -Primitive predicates such as `retract` apply only to dynamic -predicates. Finally note that not all the C-Prolog primitive predicates -are implemented in YAP. They can easily be detected using the -`unknown` system predicate provided by YAP. - -Last, by default YAP enables character escapes in strings. You can -disable the special interpretation for the escape character by using: - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -:- yap_flag(character_escapes,off). -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -or by using: - -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -:- yap_flag(language,cprolog). -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - -Compatibility with the Quintus and SICStus Prolog systems ---------------------------------------------------------- - -The Quintus Prolog system was the first Prolog compiler to use Warren's -Abstract Machine. This system was very influential in the Prolog -community. Quintus Prolog implemented compilation into an abstract -machine code, which was then emulated. Quintus Prolog also included -several new built-ins, an extensive library, and in later releases a -garbage collector. The SICStus Prolog system, developed at SICS (Swedish -Institute of Computer Science), is an emulator based Prolog system -largely compatible with Quintus Prolog. SICStus Prolog has evolved -through several versions. The current version includes several -extensions, such as an object implementation, co-routining, and -constraints. - -Both YAP and SICStus Prolog obey the Edinburgh Syntax and are based on -the WAM. Even so, there are major important differences: - - + Differently from SICStus Prolog, both consulted and dynamic code in YAP - are compiled, not interpreted. All code in YAP is compiled. - - + The following SICStus Prolog v3 built-ins are not (currently) -implemented in YAP (note that this is only a partial list): -stream_interrupt/3, reinitialize/0, help/0, help/1, -trimcore/0, and require/1. - - + The consult/1 predicate in YAP follows C-Prolog -semantics. That is, it adds clauses to the data base, even for -preexisting procedures. This is different from consult/1 in -SICStus Prolog or SWI-Prolog. - - + This list is incomplete. - -Compatibility with the ISO Prolog standard ------------------------------------------- - -The Prolog standard was developed by ISO/IEC JTC1/SC22/WG17, the -international standardization working group for the programming language -Prolog. The book "Prolog: The Standard" by Deransart, Ed-Dbali and -Cervoni gives a complete description of this standard. Development in -YAP from YAP4.1.6 onwards have striven at making YAP -compatible with ISO Prolog. As such: - - + YAP now supports all of the built-ins required by the -ISO-standard, and, - + Error-handling is as required by the standard. - - -YAP by default is not fully ISO standard compliant. You can set the -language flag to `iso` to obtain better -compatibility. Setting this flag changes the following: - - - + By default, YAP implements the -atom_chars/2 (see Testing Terms), and -number_chars/2, (see Testing Terms), -built-ins as per the original Quintus Prolog definition, and -not as per the ISO definition. - -Calling `set_prolog_flag(to_chars_mode,iso)` will switch -YAP to use the ISO definition for -atom_chars/2 and number_chars/2. - - + By default, YAP allows executable goals in directives. In ISO mode -most directives can only be called from top level (the exceptions are -set_prolog_flag/2 and op/3). - - + Error checking for meta-calls under ISO Prolog mode is stricter -than by default. - - + The strict_iso flag automatically enables the ISO Prolog -standard. This feature should disable all features not present in the -standard. - -The following incompatibilities between YAP and the ISO standard are -known to still exist (please check Ulrich Neumerkel's page for more details): - -
      - -
    • Currently, YAP does not handle overflow errors in integer -operations, and handles floating-point errors only in some -architectures. Otherwise, YAP follows IEEE arithmetic. - -Please inform the authors on other incompatibilities that may still -exist. - -@} - -Foreign Language interface for YAP {#fli} -================================== - -@defgroup fli Foreigd Code Interfacing - -@{ - -YAP provides the user with three facilities for writing -predicates in a language other than Prolog. Under Unix systems, -most language implementations were linkable to `C`, and the first interface exported the YAP machinery to the C language. YAP also implements most of the SWI-Prolog foreign language interface. -This gives portability with a number of SWI-Prolog packages and avoids garnage collection by using @ref slotInterface. Last, a new C++ based interface is -being designed to work with the swig (www.swig.orgv) interface compiler. - -+ The @ref c-interface exports the YAP engine. - -+ The @ref swi-c-interface emulates Jan Wielemaker's SWI foreign language interface. - -+ The @ref yap-cplus-interface is desiged to interface with the SWIG package by using Object-Oriented concepts - -+ The @ref LoadInterface handles the setup of foreign files - -@} - diff --git a/library/atts.yap b/library/atts.yap index 8fe204cf8..bdffdf880 100644 --- a/library/atts.yap +++ b/library/atts.yap @@ -17,13 +17,13 @@ :- module(attributes, [op(1150, fx, attribute)]). -%% @{ - /** @addtogroup attributes -SICStus style attribute declarations are activated through loading the +%% @{ + + SICStus style attribute declarations are activated through loading the library atts. The command ~~~~~ diff --git a/misc/PROLOGCOMMONS.md b/misc/PROLOGCOMMONS.md index 4af3410a9..470b3c5fd 100644 --- a/misc/PROLOGCOMMONS.md +++ b/misc/PROLOGCOMMONS.md @@ -1,3 +1,5 @@ +Prolog Commons {#prolog_comons} +============= This directory should hold files from the Prolog Commons project. Please see diff --git a/os/readterm.c b/os/readterm.c index 34c63ae62..96cc0604a 100644 --- a/os/readterm.c +++ b/os/readterm.c @@ -219,15 +219,15 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) { CACHE_REGS Term startline, errline, endline; Term tf[3]; - Term tm; + Term tm; Term *tailp = tf + 2; CELL *Hi = HR; TokEntry *tok = LOCAL_tokptr; Int cline = tok->TokPos; startline = MkIntegerTerm(cline); - endline = MkIntegerTerm(cline); - if (errtok != LOCAL_toktide) { + endline = MkIntegerTerm(cline); + if (errtok != LOCAL_toktide) { errtok = LOCAL_toktide; } LOCAL_Error_TYPE = YAP_NO_ERROR; @@ -254,7 +254,7 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) { *tailp = MkPairTerm(MkAtomTerm(AtomError), TermNil); tailp = RepPair(*tailp) + 1; } - Term rep = Yap_tokRep(tok ); + Term rep = Yap_tokRep(tok); if (tok->TokNext) { tok = tok->TokNext; } else { @@ -262,7 +262,7 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) { tok = NULL; break; } - *tailp = MkPairTerm(rep , TermNil); + *tailp = MkPairTerm(rep, TermNil); tailp = RepPair(*tailp) + 1; } { @@ -280,8 +280,8 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod) { clean_vars(LOCAL_AnonVarTable); Term terr = Yap_MkApplTerm(FunctorInfo3, 3, tf); Term tn[2]; - tn[0] = Yap_MkApplTerm(FunctorShortSyntaxError, 1, &tm); - tn[1] = terr; + tn[0] = Yap_MkApplTerm(FunctorShortSyntaxError, 1, &tm); + tn[1] = terr; terr = Yap_MkApplTerm(FunctorError, 2, tn); #if DEBUG if (Yap_ExecutionMode == YAP_BOOT_MODE) { @@ -643,7 +643,7 @@ 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; + 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 */ @@ -730,24 +730,23 @@ static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) { TokEntry *t = LOCAL_tokptr; int n = 0; while (t) { - fprintf(stderr, "[Token %d %s %d]", - Ord(t->Tok),Yap_tokText(t), n++); + fprintf(stderr, "[Token %d %s %d]", Ord(t->Tok), Yap_tokText(t), n++); t = t->TokNext; } fprintf(stderr, "\n"); } #endif -if (LOCAL_ErrorMessage) - return YAP_SCANNING_ERROR; -if (LOCAL_tokptr->Tok != Ord(eot_tok)) { - // next step - return YAP_PARSING; -} -if (LOCAL_tokptr->Tok == eot_tok && LOCAL_tokptr->TokInfo == TermNl) { - LOCAL_Error_TYPE = SYNTAX_ERROR; - return YAP_PARSING_ERROR; -} -return scanEOF(fe, inp_stream); + if (LOCAL_ErrorMessage) + return YAP_SCANNING_ERROR; + if (LOCAL_tokptr->Tok != Ord(eot_tok)) { + // next step + return YAP_PARSING; + } + if (LOCAL_tokptr->Tok == eot_tok && LOCAL_tokptr->TokInfo == TermNl) { + LOCAL_Error_TYPE = SYNTAX_ERROR; + return YAP_PARSING_ERROR; + } + return scanEOF(fe, inp_stream); } static parser_state_t scanError(REnv *re, FEnv *fe, int inp_stream) { @@ -807,7 +806,7 @@ static parser_state_t parseError(REnv *re, FEnv *fe, int inp_stream) { } else { Term t = syntax_error(fe->toklast, inp_stream, fe->cmod); if (ParserErrorStyle == TermError) { - LOCAL_ActiveError->errorTerm = Yap_StoreTermInDB( t, 4); + LOCAL_ActiveError->errorTerm = Yap_StoreTermInDB(t, 4); LOCAL_Error_TYPE = SYNTAX_ERROR; // dec-10 } else if (Yap_PrintWarning(t)) { @@ -1081,6 +1080,47 @@ static Int read_clause( return out && Yap_unify(tf, out); } +/** + * start input for a meta-clause. Should obtain: + * - predicate name + * - predicate arity + * - address for 256 cluses. + * + * @param ARG1 input stream + * @param ARG2 Adress of predicate. + * @param ARG3 Term read. + * @return [description] + */ +#if 0 +static Int start_mega(USES_REGS1) { + int inp_stream; + Term out; + Term t3 = Deref(ARG3); + yhandle_t h = Yap_InitSlot(ARG2); + TokENtry *tok; + arity_t srity = 0; + /* needs to change LOCAL_output_stream for write */ + inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read_exo/3"); + if (inp_stream < 0) + return false; + /* preserve value of H after scanning: otherwise we may lose strings + and floats */ + LOCAL_tokptr = LOCAL_toktide = + x Yap_tokenizer(GLOBAL_Stream + inp_stream, false, &tpos); + if (tokptr->Tok == Name_tok && (next = tokptr->TokNext) != NULL && + next->Tok == Ponctuation_tok && next->TokInfo == TermOpenBracket) { + bool start = true; + while((tokptr = next->TokNext)) { + + if (IsAtomOrIntTerm(t=*tp)) { + ip->opc = Yap_opcode(get_atom); + ip->y_u.x_c.c = t. + ip->y_u.x_c.x = tp++; /() c */ + } else if (IsAtomOrIntTerm(t=*tp)) { + (IsAtom(tok->Tokt)||IsIntTerm(XREGS+(i+1)))extra[arity] + ] +} +#endif /** * @pred source_location( - _File_ , _Line_ ) * @@ -1094,6 +1134,8 @@ static Int read_clause( * @param - _File_ * @param - _Line_ * + * + * * @note SWI-Prolog built-in. */ static Int source_location(USES_REGS1) { @@ -1215,15 +1257,15 @@ X_API Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp, CACHE_REGS Term bvar = MkVarTerm(), ctl; yhandle_t sl; - int lvl = push_text_stack(); + int lvl = push_text_stack(); if (len == 0) { Term rval = TermEof; if (rval && bindings) { *bindings = TermNil; } - pop_text_stack(lvl); - return rval; + pop_text_stack(lvl); + return rval; } if (bindings) { ctl = Yap_MkApplTerm(Yap_MkFunctor(AtomVariableNames, 1), 1, &bvar); @@ -1242,7 +1284,7 @@ X_API Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp, if (rval && bindings) { *bindings = Yap_PopHandle(sl); } - pop_text_stack(lvl); + pop_text_stack(lvl); return rval; } diff --git a/packages/bdd/README b/packages/bdd/bdd.md similarity index 67% rename from packages/bdd/README rename to packages/bdd/bdd.md index 2eb20f2cd..689c259ff 100644 --- a/packages/bdd/README +++ b/packages/bdd/bdd.md @@ -1,5 +1,7 @@ +Boolean Decision Making in YAP (#BDDs) +============================== -This is an experimental interface to BDD libraries. It is not as +This is an experimental interface to BDD libraries. It is not as sophisticated as simplecudd, but it should be fun to play around with bdds. It currently works with cudd only, although it should be possible to @@ -9,10 +11,7 @@ with cudd binaries. This works: - in fedora with standard package - in osx with hand-compiled and ports package -In ubuntu, you may want to install the fedora rpm, or just contact me -for instructions. - -Good Luck! - -Vitor +In ubuntu, you may want to install the fedora rpm, or just download the package from the original + and compile it. + . diff --git a/docs/chr.md b/packages/chr/chr.md similarity index 99% rename from docs/chr.md rename to packages/chr/chr.md index d736e988a..9a674a047 100644 --- a/docs/chr.md +++ b/packages/chr/chr.md @@ -1,8 +1,6 @@ - CHR: Constraint Handling Rules {#chr} ============================== -@ingroup packages This chapter is written by Tom Schrijvers, K.U. Leuven for the hProlog system. Adjusted by Jan Wielemaker to fit the SWI-Prolog documentation @@ -528,5 +526,3 @@ share one or more variables. Provide mode and type declarations to get more efficient program execution. Make sure to disable debug (`-nodebug`) and enable optimization (`-O`). - - diff --git a/packages/chr/chr.yap b/packages/chr/chr.yap index fc0854697..d302ad81f 100644 --- a/packages/chr/chr.yap +++ b/packages/chr/chr.yap @@ -1,538 +1,2 @@ -% -% chr.pl is generated automatically. -% This package is just here to work as a stub for YAP analysis. -% - -/** - -@defgroup CHR CHR: Constraint Handling Rules - -@ingroup swi - -This chapter is written by Tom Schrijvers, K.U. Leuven for the hProlog -system. Adjusted by Jan Wielemaker to fit the SWI-Prolog documentation -infrastructure and remove hProlog specific references. - -The CHR system of SWI-Prolog is the K.U.Leuven CHR system. The runtime -environment is written by Christian Holzbaur and Tom Schrijvers while the -compiler is written by Tom Schrijvers. Both are integrated with SWI-Prolog -and licenced under compatible conditions with permission from the authors. - -The main reference for SWI-Prolog's CHR system is: - -+ T. Schrijvers, and B. Demoen, The K.U.Leuven CHR System: Implementation and Application, First Workshop on Constraint Handling Rules: Selected -Contributions (Fruwirth, T. and Meister, M., eds.), pp. 1--5, 2004. - -# Introduction - -Constraint Handling Rules (CHR) is a committed-choice bottom-up language -embedded in Prolog. It is designed for writing constraint solvers and is -particularily useful for providing application-specific constraints. -It has been used in many kinds of applications, like scheduling, -model checking, abduction, type checking among many others. - -CHR has previously been implemented in other Prolog systems (SICStus, -Eclipse, Yap), Haskell and Java. This CHR system is based on the -compilation scheme and runtime environment of CHR in SICStus. - -In this documentation we restrict ourselves to giving a short overview -of CHR in general and mainly focus on elements specific to this -implementation. For a more thorough review of CHR we refer the reader to -[Freuhwirth:98]. More background on CHR can be found at the CHR web site. - -### Syntax and Semantics - -We present informally the syntax and semantics of CHR. - - -#### CHR Syntax - -The syntax of CHR rules in hProlog is the following: - -~~~~~ -rules --> rule, rules. -rules --> []. - -rule --> name, actual_rule, pragma, [atom(`.`)]. - -name --> atom, [atom(`@`)]. -name --> []. - -actual_rule --> simplification_rule. -actual_rule --> propagation_rule. -actual_rule --> simpagation_rule. - -simplification_rule --> constraints, [atom(`<=>`)], guard, body. -propagation_rule --> constraints, [atom(`==>`)], guard, body. -simpagation_rule --> constraints, [atom(`\`)], constraints, [atom(`<=>`)], - guard, body. - -constraints --> constraint, constraint_id. -constraints --> constraint, [atom(`,`)], constraints. - -constraint --> compound_term. - -constraint_id --> []. -constraint_id --> [atom(`#`)], variable. - -guard --> []. -guard --> goal, [atom(`|`)]. - -body --> goal. - -pragma --> []. -pragma --> [atom(`pragma`)], actual_pragmas. - -actual_pragmas --> actual_pragma. -actual_pragmas --> actual_pragma, [atom(`,`)], actual_pragmas. - -actual_pragma --> [atom(`passive(`)], variable, [atom(`)`)]. - -~~~~~ - -Additional syntax-related terminology: - -+ *head:* the constraints in an `actual_rule` before -the arrow (either `<=>` or `==>`) - - -#### Semantics Semantics - -In this subsection the operational semantics of CHR in Prolog are presented -informally. They do not differ essentially from other CHR systems. - -When a constraint is called, it is considered an active constraint and -the system will try to apply the rules to it. Rules are tried and executed -sequentially in the order they are written. - -A rule is conceptually tried for an active constraint in the following -way. The active constraint is matched with a constraint in the head of -the rule. If more constraints appear in the head they are looked for -among the suspended constraints, which are called passive constraints in -this context. If the necessary passive constraints can be found and all -match with the head of the rule and the guard of the rule succeeds, then -the rule is committed and the body of the rule executed. If not all the -necessary passive constraint can be found, the matching fails or the -guard fails, then the body is not executed and the process of trying and -executing simply continues with the following rules. If for a rule, -there are multiple constraints in the head, the active constraint will -try the rule sequentially multiple times, each time trying to match with -another constraint. - -This process ends either when the active constraint disappears, i.e. it -is removed by some rule, or after the last rule has been processed. In -the latter case the active constraint becomes suspended. - -A suspended constraint is eligible as a passive constraint for an active -constraint. The other way it may interact again with the rules, is when -a variable appearing in the constraint becomes bound to either a nonvariable -or another variable involved in one or more constraints. In that case the -constraint is triggered, i.e. it becomes an active constraint and all -the rules are tried. - -### Rules - -There are three different kinds of rules, each with their specific semantics: - -+ simplification -The simplification rule removes the constraints in its head and calls its body. - -+ propagation -The propagation rule calls its body exactly once for the constraints in -its head. - -+ simpagation -The simpagation rule removes the constraints in its head after the -`\` and then calls its body. It is an optimization of -simplification rules of the form: \[constraints_1, constraints_2 <=> -constraints_1, body \] Namely, in the simpagation form: - -~~~~~ -constraints1 \ constraints2 <=> body -~~~~~ - _constraints1_ -constraints are not called in the body. - - - -#### Rule Names - -Naming a rule is optional and has no semantical meaning. It only functions -as documentation for the programmer. - -### Pragmas - -The semantics of the pragmas are: - -+ passive(Identifier) -The constraint in the head of a rule _Identifier_ can only act as a -passive constraint in that rule. - - -Additional pragmas may be released in the future. - -### CHR_Options Options - -It is possible to specify options that apply to all the CHR rules in the module. -Options are specified with the `option/2` declaration: - -~~~~~ - option(Option,Value). -~~~~~ - -Available options are: - -+ check_guard_bindings -This option controls whether guards should be checked for illegal -variable bindings or not. Possible values for this option are -`on`, to enable the checks, and `off`, to disable the -checks. - -+ optimize -This is an experimental option controlling the degree of optimization. -Possible values are `full`, to enable all available -optimizations, and `off` (default), to disable all optimizations. -The default is derived from the SWI-Prolog flag `optimise`, where -`true` is mapped to `full`. Therefore the commandline -option `-O` provides full CHR optimization. -If optimization is enabled, debugging should be disabled. - -+ debug -This options enables or disables the possibility to debug the CHR code. -Possible values are `on` (default) and `off`. See -`debugging` for more details on debugging. The default is -derived from the prolog flag `generate_debug_info`, which -is `true` by default. See `-nodebug`. -If debugging is enabled, optimization should be disabled. - -+ mode -This option specifies the mode for a particular constraint. The -value is a term with functor and arity equal to that of a constraint. -The arguments can be one of `-`, `+` or `?`. -The latter is the default. The meaning is the following: - -+ - -The corresponding argument of every occurrence -of the constraint is always unbound. -+ + -The corresponding argument of every occurrence -of the constraint is always ground. -+ ? -The corresponding argument of every occurrence -of the constraint can have any instantiation, which may change -over time. This is the default value. - -The declaration is used by the compiler for various optimizations. -Note that it is up to the user the ensure that the mode declaration -is correct with respect to the use of the constraint. -This option may occur once for each constraint. - -+ type_declaration -This option specifies the argument types for a particular constraint. The -value is a term with functor and arity equal to that of a constraint. -The arguments can be a user-defined type or one of -the built-in types: - -+ int -The corresponding argument of every occurrence -of the constraint is an integer number. -+ float -...{} a floating point number. -+ number -...{} a number. -+ natural -...{} a positive integer. -+ any -The corresponding argument of every occurrence -of the constraint can have any type. This is the default value. - - -Currently, type declarations are only used to improve certain -optimizations (guard simplification, occurrence subsumption, ...{}). - -+ type_definition -This option defines a new user-defined type which can be used in -type declarations. The value is a term of the form -`type(` _name_`,` _list_`)`, where - _name_ is a term and _list_ is a list of alternatives. -Variables can be used to define generic types. Recursive definitions -are allowed. Examples are - -~~~~~ -type(bool,[true,false]). -type(complex_number,[float + float * i]). -type(binary_tree(T),[ leaf(T) | node(binary_tree(T),binary_tree(T)) ]). -type(list(T),[ [] | [T | list(T)]). -~~~~~ - - - -The mode, type_declaration and type_definition options are provided -for backward compatibility. The new syntax is described below. - - - -### CHR in Prolog Programs - - -The CHR constraints defined in a particulary chr file are -associated with a module. The default module is `user`. One should -never load different chr files with the same CHR module name. - - - -#### Constraint Declarations - - -Every constraint used in CHR rules has to be declared. -There are two ways to do this. The old style is as follows: - -~~~~~ -option(type_definition,type(list(T),[ [] , [T|list(T)] ]). -option(mode,foo(+,?)). -option(type_declaration,foo(list(int),float)). -:- constraints foo/2, bar/0. -~~~~~ - -The new style is as follows: - -~~~~~ -:- chr_type list(T) ---> [] ; [T|list(T)]. -:- constraints foo(+list(int),?float), bar. -~~~~~ - - - -#### Compilation - -The - SWI-Prolog CHR compiler exploits term_expansion/2 rules to translate -the constraint handling rules to plain Prolog. These rules are loaded -from the library chr. They are activated if the compiled file -has the chr extension or after finding a declaration of the -format below. - -~~~~~ -:- constraints ... -~~~~~ - -It is adviced to define CHR rules in a module file, where the module -declaration is immediately followed by including the chr -library as examplified below: - -~~~~~ -:- module(zebra, [ zebra/0 ]). -:- use_module(library(chr)). - -:- constraints ... -~~~~~ - -Using this style CHR rules can be defined in ordinary Prolog -pl files and the operator definitions required by CHR do not -leak into modules where they might cause conflicts. - - - - - -#### CHR Debugging - -The CHR debugging facilities are currently rather limited. Only tracing -is currently available. To use the CHR debugging facilities for a CHR -file it must be compiled for debugging. Generating debug info is -controlled by the CHR option debug, whose default is derived -from the SWI-Prolog flag `generate_debug_info`. Therefore debug -info is provided unless the `-nodebug` is used. - -#### Ports - -For CHR constraints the four standard ports are defined: - -+ call -A new constraint is called and becomes active. -+ exit -An active constraint exits: it has either been inserted in the store after -trying all rules or has been removed from the constraint store. -+ fail -An active constraint fails. -+ redo -An active constraint starts looking for an alternative solution. - - -In addition to the above ports, CHR constraints have five additional -ports: - -+ wake -A suspended constraint is woken and becomes active. -+ insert -An active constraint has tried all rules and is suspended in -the constraint store. -+ remove -An active or passive constraint is removed from the constraint -store, if it had been inserted. -+ try -An active constraints tries a rule with possibly -some passive constraints. The try port is entered -just before committing to the rule. -+ apply -An active constraints commits to a rule with possibly -some passive constraints. The apply port is entered -just after committing to the rule. - -#### Tracing - -Tracing is enabled with the chr_trace/0 predicate -and disabled with the chr_notrace/0 predicate. - -When enabled the tracer will step through the `call`, -`exit`, `fail`, `wake` and `apply` ports, -accepting debug commands, and simply write out the other ports. - -The following debug commans are currently supported: - -~~~~~ - CHR debug options: - - creep c creep - s skip - g ancestors - n nodebug - b break - a abort - f fail - ? help h help -~~~~~ - -Their meaning is: - -+ creep -Step to the next port. -+ skip -Skip to exit port of this call or wake port. -+ ancestors -Print list of ancestor call and wake ports. -+ nodebug -Disable the tracer. -+ break -Enter a recursive Prolog toplevel. See break/0. -+ abort -Exit to the toplevel. See abort/0. -+ fail -Insert failure in execution. -+ help -Print the above available debug options. - - -#### CHR Debugging Predicates - - -The chr module contains several predicates that allow -inspecting and printing the content of the constraint store. - -+ chr_trace -Activate the CHR tracer. By default the CHR tracer is activated and -deactivated automatically by the Prolog predicates trace/0 and -notrace/0. - -### CHR_Examples Examples - -Here are two example constraint solvers written in CHR. - -+ -The program below defines a solver with one constraint, -`leq/2`, which is a less-than-or-equal constraint. - -~~~~~ -:- module(leq,[cycle/3, leq/2]). -:- use_module(library(chr)). - -:- constraints leq/2. -reflexivity @ leq(X,X) <=> true. -antisymmetry @ leq(X,Y), leq(Y,X) <=> X = Y. -idempotence @ leq(X,Y) \ leq(X,Y) <=> true. -transitivity @ leq(X,Y), leq(Y,Z) ==> leq(X,Z). - -cycle(X,Y,Z):- - leq(X,Y), - leq(Y,Z), - leq(Z,X). -~~~~~ - -+ -The program below implements a simple finite domain -constraint solver. - -~~~~~ -:- module(dom,[dom/2]). -:- use_module(library(chr)). - -:- constraints dom/2. - -dom(X,[]) <=> fail. -dom(X,[Y]) <=> X = Y. -dom(X,L1), dom(X,L2) <=> intersection(L1,L2,L3), dom(X,L3). - -intersection([],_,[]). -intersection([H|T],L2,[H|L3]) :- - member(H,L2), !, - intersection(T,L2,L3). -intersection([_|T],L2,L3) :- - intersection(T,L2,L3). -~~~~~ - - - -### Compatibility with SICStus CHR - - -There are small differences between CHR in SWI-Prolog and newer -YAPs and SICStus and older versions of YAP. Besides differences in -available options and pragmas, the following differences should be -noted: - -+ [The handler/1 declaration] -In SICStus every CHR module requires a `handler/1` -declaration declaring a unique handler name. This declaration is valid -syntax in SWI-Prolog, but will have no effect. A warning will be given -during compilation. - -+ [The rules/1 declaration] -In SICStus, for every CHR module it is possible to only enable a subset -of the available rules through the `rules/1` declaration. The -declaration is valid syntax in SWI-Prolog, but has no effect. A -warning is given during compilation. - -+ [Sourcefile naming] -SICStus uses a two-step compiler, where chr files are -first translated into pl files. For SWI-Prolog CHR -rules may be defined in a file with any extension. - -### Guidelines - -In this section we cover several guidelines on how to use CHR to write -constraint solvers and how to do so efficiently. - -+ [Set semantics] -The CHR system allows the presence of identical constraints, i.e. -multiple constraints with the same functor, arity and arguments. For -most constraint solvers, this is not desirable: it affects efficiency -and possibly termination. Hence appropriate simpagation rules should be -added of the form: - -~~~~~ -{constraint \ constraint <=> true}. -~~~~~ - -+ [Multi-headed rules] -Multi-headed rules are executed more efficiently when the constraints -share one or more variables. - -+ [Mode and type declarations] -Provide mode and type declarations to get more efficient program execution. -Make sure to disable debug (`-nodebug`) and enable optimization -(`-O`). - -*/ :- include(chr_op). - diff --git a/docs/clpqr.md b/packages/clpqr/clpqr.md similarity index 97% rename from docs/clpqr.md rename to packages/clpqr/clpqr.md index 073386784..db838adeb 100644 --- a/docs/clpqr.md +++ b/packages/clpqr/clpqr.md @@ -1,8 +1,6 @@ -Constraint Logic Programming over Rationals and Reals {#clpqr} + Constraint Logic Programming over Rationals and Reals {#clpqr} ===================================================== -@ingroup paackages - YAP now uses the CLP(R) package developed by Leslie De Koninck, K.U. Leuven as part of a thesis with supervisor Bart Demoen and daily advisor Tom Schrijvers, and distributed with SWI-Prolog. @@ -119,4 +117,3 @@ X = sin(Y) when X is ground or // 1 = sin(Y) X = cos(Y) Y is ground // X = sin(1.5707) X = tan(Y) ~~~~~ - diff --git a/packages/clpqr/clpr.pl b/packages/clpqr/clpr.pl index 1e9fb9b00..e065bb960 100644 --- a/packages/clpqr/clpr.pl +++ b/packages/clpqr/clpr.pl @@ -38,7 +38,10 @@ the GNU General Public License. */ - +/** @defgroup clpr_implementation CLP(QR) Predicates + @ingroup clpqr + + */ /** @pred bb_inf(+ _Ints_,+ _Expression_,- _Inf_) The same as bb_inf/5 but without returning the values of the integers diff --git a/packages/gecode/DOC.txt b/packages/gecode/gecode.md similarity index 91% rename from packages/gecode/DOC.txt rename to packages/gecode/gecode.md index 601934345..6c106f45a 100644 --- a/packages/gecode/DOC.txt +++ b/packages/gecode/gecode.md @@ -1,16 +1,24 @@ -USING THE GECODE MODULE +USING THE GECODE MODULE (#Gecode) ======================= +There are two ways to use the gecode interface from YAP. The original approach, +designed by Denys Duchier, requires loading the library: + :- use_module(library(gecode)). +A second approach is closer to CLP(FD), and is described in: + + - \ref Gecode_and_ClPbBFDbC + +In what follows, we refer the reader to the~\cite{gecode} manual for the necessary background. CREATING A SPACE -================ +---------------- Space := space CREATING VARIABLES -================== +----------------- Unlike in Gecode, variable objects are not bound to a specific Space. Each one actually contains an index with which it is possible to access a Space-bound @@ -49,7 +57,7 @@ kept. Thus marking variables as "kept" is purely an optimization. CONSTRAINTS AND BRANCHINGS -========================== +--------------------------- all constraint and branching posting functions are available just like in Gecode. Wherever a XXXArgs or YYYSharedArray is expected, simply use a list. @@ -68,7 +76,7 @@ represented by atoms with the same name as the Gecode constant (e.g. 'INT_VAR_SIZE_MIN'). SEARCHING FOR SOLUTIONS -======================= +-------------------- SolSpace := search(Space) @@ -90,7 +98,7 @@ a_d=N to set the adaptive distance for recomputation EXTRACTING INFO FROM A SOLUTION -=============================== +------------------------------ An advantage of non Space-bound variables, is that you can use them both to post constraints in the original space AND to consult their values in @@ -126,7 +134,7 @@ variables, and returns resp. either a value, or a list of values: Val := unknown_values(Space,V) DISJUNCTORS -=========== +----------- Disjunctors provide support for disjunctions of clauses, where each clause is a conjunction of constraints: diff --git a/packages/myddas/myddas.md b/packages/myddas/myddas.md new file mode 100644 index 000000000..056e514fa --- /dev/null +++ b/packages/myddas/myddas.md @@ -0,0 +1,574 @@ + The MYDDAS Data-base interface {#myddas} + ============================== + + The MYDDAS database project was developed within a FCT project aiming at + the development of a highly efficient deductive database system, based + on the coupling of the MySQL relational database system with the YAP + Prolog system. MYDDAS was later expanded to support the ODBC interface. + + + @defgroup Requirements_and_Installation_Guide Requirements and Installation Guide + ee + Next, we describe how to usen of the YAP with the MYDDAS System. The + use of this system is entirely depend of the MySQL development libraries + or the ODBC development libraries. At least one of the this development + libraries must be installed on the computer system, otherwise MYDDAS + will not compile. The MySQL development libraries from MySQL 3.23 an + above are know to work. We recommend the usage of MySQL versus ODBC, + but it is possible to have both options installed + + At the same time, without any problem. The MYDDAS system automatically + controls the two options. Currently, MYDDAS is know to compile without + problems in Linux. The usage of this system on Windows has not been + tested yet. MYDDAS must be enabled at configure time. This can be done + with the following options: + + + --enable-myddas + + This option will detect which development libraries are installed on the computer system, MySQL, ODBC or both, and will compile the Yap system with the support for which libraries it detects; + + + --enable-myddas-stats + + This option is only available in MySQL. It includes code to get + statistics from the MYDDAS system; + + + + --enable-top-level + + This option is only available in MySQL. It enables the option to interact with the MySQL server in + two different ways. As if we were on the MySQL Client Shell, and as if + we were using Datalog. + + @defgroup MYDDAS_Architecture MYDDAS Architecture + + The system includes four main blocks that are put together through the + MYDDAS interface: the Yap Prolog compiler, the MySQL database system, an + ODBC level and a Prolog to SQL compiler. Current effort is put on the + MySQL interface rather than on the ODBC interface. If you want to use + the full power of the MYDDAS interface we recommend you to use a MySQL + database. Other databases, such as Oracle, PostGres or Microsoft SQL + Server, can be interfaced through the ODBC layer, but with limited + performance and features support. + + The main structure of the MYDDAS interface is simple. Prolog queries + involving database goals are translated to SQL using the Prolog to SQL + compiler; then the SQL expression is sent to the database system, which + returns the set of tuples satisfying the query; and finally those tuples + are made available to the Prolog engine as terms. For recursive queries + involving database goals, the YapTab tabling engine provides the + necessary support for an efficient evaluation of such queries. + + An important aspect of the MYDDAS interface is that for the programmer + the use of predicates which are defined in database relations is + completely transparent. An example of this transparent support is the + Prolog cut operator, which has exactly the same behaviour from + predicates defined in the Prolog program source code, or from predicates + defined in database as relations. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Name = 'John Doe', + Number = 123456789 ? + yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Backtracking can then be used to retrieve the next row + of the relation phonebook. Records with particular field values may be + selected in the same way as in Prolog. (In particular, no mode + specification for database predicates is required). For instance: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- phonebook(Letter,'John Doe',Letter). + Letter = 'D', + Number = 123456789 ? + yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + generates the query + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + SELECT A.Letter , 'John Doe' , A.Number + FROM 'phonebook' A + WHERE A.Name = 'John Doe'; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + + @defgroup View_Level_Interface View Level Interface + + @pred db view(+,+,+). + + + + @pred db view(+,+). + + + If we import a database relation, such as an edge relation representing the edges of a directed graph, through + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_import('Edge',edge). + yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + sqliand we then write a query to retrieve all the direct cycles in the + graph, such as + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- edge(A,B), edge(B,A). + A = 10, + B = 20 ? + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + this is clearly inefficient [3], because of relation-level + access. Relation-level access means that a separate SQL query will be + generated for every goal in the body of the clause. For the second + `edge/2` goal, a SQL query is generated using the variable bindings that + result from the first `edge/2` goal execution. If the second + `edge/2` goal + fails, or if alternative solutions are demanded, backtracking access the + next tuple for the first `edge/2` goal and another SQL query will be + generated for the second `edge/2` goal. The generation of this large + number of queries and the communication overhead with the database + system for each of them, makes the relation-level approach inefficient. + To solve this problem the view level interface can be used for the + definition of rules whose bodies includes only imported database + predicates. One can use the view level interface through the predicates + db_view/3 and `db_view/2`: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_view(Conn,PredName(Arg_1,...,Arg_n),DbGoal). + ?- db_view(PredName(Arg_1,...,Arg_n),DbGoal). + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + All arguments are standard Prolog terms. _Arg1_ through _Argn_ + define the attributes to be retrieved from the database, while + _DbGoal_ defines the selection restrictions and join + conditions. _Conn_ is the connection identifier, which again can be + dropped. Calling predicate `PredName/n` will retrieve database + tuples using a single SQL query generated for the _DbGoal_. We next show + an example of a view definition for the direct cycles discussed + above. Assuming the declaration: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_import('Edge',edge). + yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + we + write: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_view(direct_cycle(A,B),(edge(A,B), edge(B,A))). + yes + ?- direct_cycle(A,B)). + A = 10, + B = 20 ? + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + This call generates the SQL + statement: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + SELECT A.attr1 , A.attr2 + FROM Edge A , Edge B + WHERE B.attr1 = A.attr2 AND B.attr2 = A.attr1; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Backtracking, as in relational level interface, can be used to retrieve the next row of the view. + The view interface also supports aggregate function predicates such as + `sum`, `avg`, `count`, `min` and `max`. For + instance: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_view(count(X),(X is count(B, B^edge(10,B)))). + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + generates the query : + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + SELECT COUNT(A.attr2) + FROM Edge A WHERE A.attr1 = 10; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + To know how to use db `view/3`, please refer to Draxler's Prolog to + SQL Compiler Manual. + + @defgroup Accessing_Tables_in_Data_Sources_Using_SQL Accessing Tables in Data Sources Using SQL + + + @pred db_sql(+,+,?). + + + + @pred db_sql(+,?). + + + + It is also possible to explicitly send a SQL query to the database server using + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_sql(Conn,SQL,List). + ?- db_sql(SQL,List). + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + where _SQL_ is an arbitrary SQL expression, and _List_ is a list + holding the first tuple of result set returned by the server. The result + set can also be navigated through backtracking. + + Example: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_sql('SELECT * FROM phonebook',LA). + LA = ['D','John Doe',123456789] ? + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +@defgroup Insertion_of_Rows Insertion of Rows + @ingroup MYDDAS + + @pred db_assert(+,+). + @pred db_assert(+). + + + + + Assuming you have imported the related base table using + `db_import/2` or db_import/3, you can insert to that table + by using db_assert/2 predicate any given fact. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_assert(Conn,Fact). + ?- db_assert(Fact). + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + The second argument must be declared with all of its arguments bound to + constants. For example assuming `helloWorld` is imported through + `db_import/2`: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_import('Hello World',helloWorld). + yes + ?- db_assert(helloWorld('A' ,'Ana',31)). + yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + This, would generate the following query + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + INSERT INTO helloWorld + VALUES ('A','Ana',3) + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + which would insert into the helloWorld, the following row: + `A,Ana,31`. If we want to insert `NULL` values into the + relation, we call db_assert/2 with a uninstantiated variable in + the data base imported predicate. For example, the following query on + the YAP-prolog system: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_assert(helloWorld('A',NULL,31)). + yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Would insert the row: `A,null value,31` into the relation + `Hello World`, assuming that the second row allows null values. + +*/ + +/** @pred db insert(+,+,+). + @pred db insert(+,+). + + + + This predicate would create a new database predicate, which will insert + any given tuple into the database. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_insert(Conn,RelationName,PredName). + ?- db_insert(RelationName,PredName). + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + This would create a new predicate with name _PredName_, that will + insert tuples into the relation _RelationName_. is the connection + identifier. For example, if we wanted to insert the new tuple + `('A',null,31)` into the relation `Hello World`, we do: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_insert('Hello World',helloWorldInsert). + yes + ?- helloWorldInsert('A',NULL,31). + yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +@defgroup Types_of_Attributes Types of AttributesL + + + @pred db_get_attributes_types(+,+,?). + + + + @pred db_get_attributes_types(+,?). + + + + + The prototype for this predicate is the following: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_get_attributes_types(Conn,RelationName,ListOfFields). + ?- db_get_attributes_types(RelationName,ListOfFields). + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + You can use the + predicate `db_get_attributes types/2` or db_get_attributes_types/3, to + know what are the names and attributes types of the fields of a given + relation. For example: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_get_attributes_types(myddas,'Hello World',LA). + LA = ['Number',integer,'Name',string,'Letter',string] ? + yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + where Hello World is the name of the relation and myddas is the + connection identifier. + + @defgroup Number_of_Fields Number of Fields + + + @pred db_number_of_fields(+,?). + @pred db_number_of_fields(+,+,?). + + + + The prototype for this + predicate is the following: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_number_of_fields(Conn,RelationName,Arity). + ?- db_number_of_fields(RelationName,Arity). + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can use the predicate db_number_of_fields/2 or + `db_number_of_fields/3` to know what is the arity of a given + relation. Example: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_number_of_fields(myddas,'Hello World',Arity). + Arity = 3 ? + yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + where `Hello World` is the name of the + relation and `myddas` is the connection identifier. + + @defgroup Describing_a_Relation Describing a Relation + + @pred db_datalog_describe(+,+). + @pred db_datalog_describe(+). + + + + The db `datalog_describe/2` predicate does not really returns any + value. It simply prints to the screen the result of the MySQL describe + command, the same way as `DESCRIBE` in the MySQL prompt would. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_datalog_describe(myddas,'Hello World'). + +----------+----------+------+-----+---------+-------+ + | Field | Type | Null | Key | Default | Extra | + +----------+----------+------+-----+---------+-------+ + + Number | int(11) | YES | | NULL | | + + Name | char(10) | YES | | NULL | | + + Letter | char(1) | YES | | NULL | | + +----------+----------+------+-----+---------+-------+ + yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + @pred db_describe(+,+). + + + + @pred db_describe(+) + + The `db_describe/3` predicate does the same action as + db_datalog_describe/2 predicate but with one major + difference. The results are returned by backtracking. For example, the + last query: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_describe(myddas,'Hello World',Term). + Term = tableInfo('Number',int(11),'YES','',null(0),'') ? ; + Term = tableInfo('Name',char(10),'YES','',null(1),'' ? ; + Term = tableInfo('Letter',char(1),'YES','',null(2),'') ? ; + no + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + @defgroup Enumerating_Relations Enumeration Relations Describing_a_Relation Describing a Relation + + +/@pred db_datalog_show_tables(+). + @pred db_datalog_show_tables + + + If we need to know what relations exists in a given MySQL Schema, we can use + the `db_datalog_show_tables/1` predicate. As db_datalog_describe/2, + it does not returns any value, but instead prints to the screen the result of the + `SHOW TABLES` command, the same way as it would be in the MySQL prompt. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_datalog_show_tables(myddas). + +-----------------+ + | Tables_in_guest | + +-----------------+ + | Hello World | + +-----------------+ + yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + @pred db_show_tables(+, ?). + + + + @pred db_show_tables(?) + + + + + The db_show_tables/2 predicate does the same action as + `db_show_tables/1` predicate but with one major difference. The + results are returned by backtracking. For example, given the last query: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_show_tables(myddas,Table). + Table = table('Hello World') ? ; + no + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + @defgroup The_MYDDAS_MySQL_Top_Level The MYDDAS MySQL Top Level + + @pred db_top_level(+,+,+,+,+). + @pred db_top_level(+,+,+,+). + + + + + Through MYDDAS is also possible to access the MySQL Database Server, in + the same wthe mysql client. In this mode, is possible to query the + SQL server by just using the standard SQL language. This mode is exactly the same as + different from the standard mysql client. We can use this + mode, by invoking the db top level/5. as one of the following: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_top_level(mysql,Connection,Host/Database,User,Password). + ?- db_top_level(mysql,Connection,Host/Database/Port,User,Password). + ?- db_top_level(mysql,Connection,Host/Database/UnixSocket,User,Password). + ?- db_top_level(mysql,Connection,Host/Database/Port/UnixSocket,User,Password). + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + Usage is similar as the one described for the db_open/5 predicate + discussed above. If the login is successful, automatically the prompt of + the mysql client will be used. For example: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_top_level(mysql,con1,localhost/guest_db,guest,''). + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + opens a + connection identified by the `con1` atom, to an instance of a MySQL server + running on host `localhost`, using database guest `db` and user `guest` with + empty password. After this is possible to use MYDDAS as the mysql + client. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_top_level(mysql,con1,localhost/guest_db,guest,''). + Reading table information for completion of table and column names + You can turn off this feature to get a quicker startup with -A + + Welcome to the MySQL monitor. + Commands end with ; or \g. + + Your MySQL connection id is 4468 to server version: 4.0.20 + Type 'help;' or '\h' for help. + Type '\c' to clear the buffer. + mysql> exit + Bye + yes + ?- + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + @defgroup Other_MYDDAS_Properties Other MYDDAS Properties + + @pred db_verbose(+). + + + When we ask a question to YAP, using a predicate asserted by + db_import/3, or by db_view/3, this will generate a SQL + `QUERY`. If we want to see that query, we must to this at a given + point in our session on YAP. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_verbose(1). + yes + ?- + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + If we want to + disable this feature, we must call the `db_verbose/1` predicate with the value 0. + + @pred db_top_level(+,+,+,+). + + @pred db_module(?). + + + + + + When we create a new database predicate, by using db_import/3, + db_view/3 or db_insert/3, that predicate will be asserted + by default on the `user` module. If we want to change this value, we can + use the db_module/1 predicate to do so. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_module(lists). + yes + ?- + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + By executing this predicate, all of the predicates asserted by the + predicates enumerated earlier will created in the lists module. + If we want to put back the value on default, we can manually put the + value user. Example: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_module(user). + yes + ?- + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + We can also see in what module the predicates are being asserted by doing: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_module(X). + X=user + yes + ?- + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + @pred db_my_result_set(?). + + The MySQL C API permits two modes for transferring the data generated by + a query to the client, in our case YAP. The first mode, and the default + mode used by the MYDDAS-MySQL, is to store the result. This mode copies all the + information generated to the client side. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_my_result_set(X). + X=store_result + yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + + The other mode that we can use is use result. This one uses the result + set created directly from the server. If we want to use this mode, he + simply do + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- db_my_result_set(use_result). + yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + After this command, all + of the database predicates will use use result by default. We can change + this by doing again `db_my_result_set(store_result)`. + + @pred db_my_sql_mode(+Conn,?SQL_Mode). + + + + @pred db_my_sql_mode(?SQL_Mode). + + + + + The MySQL server allows the user to change the SQL mode. This can be + very useful for debugging proposes. For example, if we want MySQL server + not to ignore the INSERT statement warnings and instead of taking + action, report an error, we could use the following SQL mode. + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?-db_my_sql_mode(traditional). yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + You can see the available SQL Modes at the MySQL homepage at + . diff --git a/packages/myddas/pl/myddas.ypp b/packages/myddas/pl/myddas.ypp index 54019eabd..3d9a271c4 100644 --- a/packages/myddas/pl/myddas.ypp +++ b/packages/myddas/pl/myddas.ypp @@ -104,685 +104,6 @@ ]). -/** - - @defgroup MYDDAS The MYDDAS Data-base interface. - @ingroup YAPPackages - @{ - - The MYDDAS database project was developed within a FCT project aiming at - the development of a highly efficient deductive database system, based - on the coupling of the MySQL relational database system with the YAP - Prolog system. MYDDAS was later expanded to support the ODBC interface. - -*/ - -/** @defgroup Requirements_and_Installation_Guide Requirements and Installation Guide - ee - Next, we describe how to usen of the YAP with the MYDDAS System. The - use of this system is entirely depend of the MySQL development libraries - or the ODBC development libraries. At least one of the this development - libraries must be installed on the computer system, otherwise MYDDAS - will not compile. The MySQL development libraries from MySQL 3.23 an - above are know to work. We recommend the usage of MySQL versus ODBC, - but it is possible to have both options installed - - At the same time, without any problem. The MYDDAS system automatically - controls the two options. Currently, MYDDAS is know to compile without - problems in Linux. The usage of this system on Windows has not been - tested yet. MYDDAS must be enabled at configure time. This can be done - with the following options: - - + --enable-myddas - - This option will detect which development libraries are installed on the computer system, MySQL, ODBC or both, and will compile the Yap system with the support for which libraries it detects; - - + --enable-myddas-stats - - This option is only available in MySQL. It includes code to get - statistics from the MYDDAS system; - - - + --enable-top-level - - This option is only available in MySQL. It enables the option to interact with the MySQL server in - two different ways. As if we were on the MySQL Client Shell, and as if - we were using Datalog. - -*/ - -%% @} - -/** @defgroup MYDDAS_Architecture MYDDAS Architecture - @ingroup MYDDAS - @{ - - The system includes four main blocks that are put together through the - MYDDAS interface: the Yap Prolog compiler, the MySQL database system, an - ODBC level and a Prolog to SQL compiler. Current effort is put on the - MySQL interface rather than on the ODBC interface. If you want to use - the full power of the MYDDAS interface we recommend you to use a MySQL - database. Other databases, such as Oracle, PostGres or Microsoft SQL - Server, can be interfaced through the ODBC layer, but with limited - performance and features support. - - The main structure of the MYDDAS interface is simple. Prolog queries - involving database goals are translated to SQL using the Prolog to SQL - compiler; then the SQL expression is sent to the database system, which - returns the set of tuples satisfying the query; and finally those tuples - are made available to the Prolog engine as terms. For recursive queries - involving database goals, the YapTab tabling engine provides the - necessary support for an efficient evaluation of such queries. - - An important aspect of the MYDDAS interface is that for the programmer - the use of predicates which are defined in database relations is - completely transparent. An example of this transparent support is the - Prolog cut operator, which has exactly the same behaviour from - predicates defined in the Prolog program source code, or from predicates - defined in database as relations. - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - Name = 'John Doe', - Number = 123456789 ? - yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Backtracking can then be used to retrieve the next row - of the relation phonebook. Records with particular field values may be - selected in the same way as in Prolog. (In particular, no mode - specification for database predicates is required). For instance: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- phonebook(Letter,'John Doe',Letter). - Letter = 'D', - Number = 123456789 ? - yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - generates the query - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - SELECT A.Letter , 'John Doe' , A.Number - FROM 'phonebook' A - WHERE A.Name = 'John Doe'; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -*/ - -%% @} - - -/** @defgroup View_Level_Interface View Level Interface - @ingroup MYDDAS - @{ - -*/ - -/** - @pred db view(+,+,+). - - - - @pred db view(+,+). - - - If we import a database relation, such as an edge relation representing the edges of a directed graph, through - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_import('Edge',edge). - yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - sqliand we then write a query to retrieve all the direct cycles in the - graph, such as - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- edge(A,B), edge(B,A). - A = 10, - B = 20 ? - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - this is clearly inefficient [3], because of relation-level - access. Relation-level access means that a separate SQL query will be - generated for every goal in the body of the clause. For the second - `edge/2` goal, a SQL query is generated using the variable bindings that - result from the first `edge/2` goal execution. If the second - `edge/2` goal - fails, or if alternative solutions are demanded, backtracking access the - next tuple for the first `edge/2` goal and another SQL query will be - generated for the second `edge/2` goal. The generation of this large - number of queries and the communication overhead with the database - system for each of them, makes the relation-level approach inefficient. - To solve this problem the view level interface can be used for the - definition of rules whose bodies includes only imported database - predicates. One can use the view level interface through the predicates - db_view/3 and `db_view/2`: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_view(Conn,PredName(Arg_1,...,Arg_n),DbGoal). - ?- db_view(PredName(Arg_1,...,Arg_n),DbGoal). - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - All arguments are standard Prolog terms. _Arg1_ through _Argn_ - define the attributes to be retrieved from the database, while - _DbGoal_ defines the selection restrictions and join - conditions. _Conn_ is the connection identifier, which again can be - dropped. Calling predicate `PredName/n` will retrieve database - tuples using a single SQL query generated for the _DbGoal_. We next show - an example of a view definition for the direct cycles discussed - above. Assuming the declaration: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_import('Edge',edge). - yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - we - write: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_view(direct_cycle(A,B),(edge(A,B), edge(B,A))). - yes - ?- direct_cycle(A,B)). - A = 10, - B = 20 ? - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - This call generates the SQL - statement: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - SELECT A.attr1 , A.attr2 - FROM Edge A , Edge B - WHERE B.attr1 = A.attr2 AND B.attr2 = A.attr1; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - Backtracking, as in relational level interface, can be used to retrieve the next row of the view. - The view interface also supports aggregate function predicates such as - `sum`, `avg`, `count`, `min` and `max`. For - instance: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_view(count(X),(X is count(B, B^edge(10,B)))). - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - generates the query : - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - SELECT COUNT(A.attr2) - FROM Edge A WHERE A.attr1 = 10; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - To know how to use db `view/3`, please refer to Draxler's Prolog to - SQL Compiler Manual. - -*/ - -%% @} - -/** @defgroup Accessing_Tables_in_Data_Sources_Using_SQL Accessing Tables in Data Sources Using SQL - @ingroup MYDDAS - @{ - -*/ - -/** @pred db_sql(+,+,?). - - - - @pred db_sql(+,?). - - - - It is also possible to explicitly send a SQL query to the database server using - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_sql(Conn,SQL,List). - ?- db_sql(SQL,List). - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - where _SQL_ is an arbitrary SQL expression, and _List_ is a list - holding the first tuple of result set returned by the server. The result - set can also be navigated through backtracking. - - Example: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_sql('SELECT * FROM phonebook',LA). - LA = ['D','John Doe',123456789] ? - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -*/ - -%% @} - -/** @defgroup Insertion_of_Rows Insertion of Rows - @ingroup MYDDAS - @{ - -*/ - -/** @pred db_assert(+,+). - @pred db_assert(+). - - - - - Assuming you have imported the related base table using - `db_import/2` or db_import/3, you can insert to that table - by using db_assert/2 predicate any given fact. - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_assert(Conn,Fact). - ?- db_assert(Fact). - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - The second argument must be declared with all of its arguments bound to - constants. For example assuming `helloWorld` is imported through - `db_import/2`: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_import('Hello World',helloWorld). - yes - ?- db_assert(helloWorld('A' ,'Ana',31)). - yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - This, would generate the following query - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - INSERT INTO helloWorld - VALUES ('A','Ana',3) - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - which would insert into the helloWorld, the following row: - `A,Ana,31`. If we want to insert `NULL` values into the - relation, we call db_assert/2 with a uninstantiated variable in - the data base imported predicate. For example, the following query on - the YAP-prolog system: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_assert(helloWorld('A',NULL,31)). - yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - Would insert the row: `A,null value,31` into the relation - `Hello World`, assuming that the second row allows null values. - -*/ - -/** @pred db insert(+,+,+). - @pred db insert(+,+). - - - - This predicate would create a new database predicate, which will insert - any given tuple into the database. - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_insert(Conn,RelationName,PredName). - ?- db_insert(RelationName,PredName). - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - This would create a new predicate with name _PredName_, that will - insert tuples into the relation _RelationName_. is the connection - identifier. For example, if we wanted to insert the new tuple - `('A',null,31)` into the relation `Hello World`, we do: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_insert('Hello World',helloWorldInsert). - yes - ?- helloWorldInsert('A',NULL,31). - yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -*/ - -%% @} - -/** @defgroup Types_of_Attributes Types of AttributesL - @ingroup MYDDAS - @{ - -*/ - -/** @pred db_get_attributes_types(+,+,?). - - - - @pred db_get_attributes_types(+,?). - - - - - The prototype for this predicate is the following: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_get_attributes_types(Conn,RelationName,ListOfFields). - ?- db_get_attributes_types(RelationName,ListOfFields). - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - You can use the - predicate `db_get_attributes types/2` or db_get_attributes_types/3, to - know what are the names and attributes types of the fields of a given - relation. For example: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_get_attributes_types(myddas,'Hello World',LA). - LA = ['Number',integer,'Name',string,'Letter',string] ? - yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - where Hello World is the name of the relation and myddas is the - connection identifier. -*/ - -%% @} - - -/** @defgroup Number_of_Fields Number of Fields - @ingroup MYDDAS - @{ - -*/ - -/** @pred db_number_of_fields(+,?). - @pred db_number_of_fields(+,+,?). - - - - The prototype for this - predicate is the following: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_number_of_fields(Conn,RelationName,Arity). - ?- db_number_of_fields(RelationName,Arity). - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - You can use the predicate db_number_of_fields/2 or - `db_number_of_fields/3` to know what is the arity of a given - relation. Example: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_number_of_fields(myddas,'Hello World',Arity). - Arity = 3 ? - yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - where `Hello World` is the name of the - relation and `myddas` is the connection identifier. - - -*/ - -%% @} - - -/** @defgroup Describing_a_Relation Describing a Relation - @ingroup MYDDAS - @{ - -*/ - -/** @pred db_datalog_describe(+,+). - @pred db_datalog_describe(+). - - - - The db `datalog_describe/2` predicate does not really returns any - value. It simply prints to the screen the result of the MySQL describe - command, the same way as `DESCRIBE` in the MySQL prompt would. - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_datalog_describe(myddas,'Hello World'). - +----------+----------+------+-----+---------+-------+ - | Field | Type | Null | Key | Default | Extra | - +----------+----------+------+-----+---------+-------+ - + Number | int(11) | YES | | NULL | | - + Name | char(10) | YES | | NULL | | - + Letter | char(1) | YES | | NULL | | - +----------+----------+------+-----+---------+-------+ - yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -*/ - -/** @pred db_describe(+,+). - - - - @pred db_describe(+) - - The `db_describe/3` predicate does the same action as - db_datalog_describe/2 predicate but with one major - difference. The results are returned by backtracking. For example, the - last query: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_describe(myddas,'Hello World',Term). - Term = tableInfo('Number',int(11),'YES','',null(0),'') ? ; - Term = tableInfo('Name',char(10),'YES','',null(1),'' ? ; - Term = tableInfo('Letter',char(1),'YES','',null(2),'') ? ; - no - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - -*/ -%% @} - - -/** @defgroup Enumerating_Relations Enumeration Relations Describing_a_Relation Describing a Relation - @ingroup MYDDAS - @{ - -*/ - -/** @pred db_datalog_show_tables(+). - @pred db_datalog_show_tables - - - If we need to know what relations exists in a given MySQL Schema, we can use - the `db_datalog_show_tables/1` predicate. As db_datalog_describe/2, - it does not returns any value, but instead prints to the screen the result of the - `SHOW TABLES` command, the same way as it would be in the MySQL prompt. - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_datalog_show_tables(myddas). - +-----------------+ - | Tables_in_guest | - +-----------------+ - | Hello World | - +-----------------+ - yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -*/ - -/** @pred db_show_tables(+, ?). - - - - @pred db_show_tables(?) - - - - - The db_show_tables/2 predicate does the same action as - `db_show_tables/1` predicate but with one major difference. The - results are returned by backtracking. For example, given the last query: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_show_tables(myddas,Table). - Table = table('Hello World') ? ; - no - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -*/ - -%%@} - - -/** @defgroup The_MYDDAS_MySQL_Top_Level The MYDDAS MySQL Top Level - @ingroup MYDDAS - @{ - -*/ - -/** - @pred db_top_level(+,+,+,+,+). - @pred db_top_level(+,+,+,+). - - - - - Through MYDDAS is also possible to access the MySQL Database Server, in - the same wthe mysql client. In this mode, is possible to query the - SQL server by just using the standard SQL language. This mode is exactly the same as - different from the standard mysql client. We can use this - mode, by invoking the db top level/5. as one of the following: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_top_level(mysql,Connection,Host/Database,User,Password). - ?- db_top_level(mysql,Connection,Host/Database/Port,User,Password). - ?- db_top_level(mysql,Connection,Host/Database/UnixSocket,User,Password). - ?- db_top_level(mysql,Connection,Host/Database/Port/UnixSocket,User,Password). - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - Usage is similar as the one described for the db_open/5 predicate - discussed above. If the login is successful, automatically the prompt of - the mysql client will be used. For example: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_top_level(mysql,con1,localhost/guest_db,guest,''). - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - opens a - connection identified by the `con1` atom, to an instance of a MySQL server - running on host `localhost`, using database guest `db` and user `guest` with - empty password. After this is possible to use MYDDAS as the mysql - client. - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_top_level(mysql,con1,localhost/guest_db,guest,''). - Reading table information for completion of table and column names - You can turn off this feature to get a quicker startup with -A - - Welcome to the MySQL monitor. - Commands end with ; or \g. - - Your MySQL connection id is 4468 to server version: 4.0.20 - Type 'help;' or '\h' for help. - Type '\c' to clear the buffer. - mysql> exit - Bye - yes - ?- - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -*/ - -%%@} - - -/** @defgroup Other_MYDDAS_Properties Other MYDDAS Properties - @ingroup MYDDAS - @{ - -*/ - -/** - @pred db_verbose(+). - - - When we ask a question to YAP, using a predicate asserted by - db_import/3, or by db_view/3, this will generate a SQL - `QUERY`. If we want to see that query, we must to this at a given - point in our session on YAP. - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_verbose(1). - yes - ?- - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - If we want to - disable this feature, we must call the `db_verbose/1` predicate with the value 0. - \ -*/ - -/** - @pred db_top_level(+,+,+,+). - - -*/ - -/** @pred db_module(?). - - - - - - When we create a new database predicate, by using db_import/3, - db_view/3 or db_insert/3, that predicate will be asserted - by default on the `user` module. If we want to change this value, we can - use the db_module/1 predicate to do so. - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_module(lists). - yes - ?- - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - By executing this predicate, all of the predicates asserted by the - predicates enumerated earlier will created in the lists module. - If we want to put back the value on default, we can manually put the - value user. Example: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_module(user). - yes - ?- - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - We can also see in what module the predicates are being asserted by doing: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_module(X). - X=user - yes - ?- - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -*/ - -/** @pred db_my_result_set(?). - - The MySQL C API permits two modes for transferring the data generated by - a query to the client, in our case YAP. The first mode, and the default - mode used by the MYDDAS-MySQL, is to store the result. This mode copies all the - information generated to the client side. - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_my_result_set(X). - X=store_result - yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - - The other mode that we can use is use result. This one uses the result - set created directly from the server. If we want to use this mode, he - simply do - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- db_my_result_set(use_result). - yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - After this command, all - of the database predicates will use use result by default. We can change - this by doing again `db_my_result_set(store_result)`. - -*/ - -/** @pred db_my_sql_mode(+Conn,?SQL_Mode). - - - - @pred db_my_sql_mode(?SQL_Mode). - - - - - The MySQL server allows the user to change the SQL mode. This can be - very useful for debugging proposes. For example, if we want MySQL server - not to ignore the INSERT statement warnings and instead of taking - action, report an error, we could use the following SQL mode. - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?-db_my_sql_mode(traditional). yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - You can see the available SQL Modes at the MySQL homepage at - . - -*/ %% @} @@ -837,7 +158,7 @@ c_sqlite3_query/5, sqlite3_result_set/1, c_sqlite3_number_of_fields/3 - + ]). #endif /* MYDDAS_MYSQL */ @@ -1089,7 +410,7 @@ db_open(odbc,Connection,ODBCEntry,User,Password) :- set_value(Connection,Con). #endif #ifdef MYDDAS_SQLITE3 -db_open(sqlite3,Connection,File,User,Password) :- +db_open(sqlite3,Connection,File,User,Password) :- '$error_checks'(db_open(sqlite3,Connection,File,User,Password)), c_sqlite3_connect(File,User,Password,Con), set_value(Connection,Con). @@ -1456,7 +777,7 @@ db_update(Connection,WherePred-SetPred):- ( ConType == mysql -> db_my_result_set(Mode), c_db_my_query(SQL,_,Conn,Mode,_) - ; + ; ConType == mysql -> postgres_result_set(Mode), c_postgres_query(SQL,_,Conn,Mode,_) diff --git a/packages/raptor/README.md b/packages/raptor/README.md index affb558ce..cd3086a95 100644 --- a/packages/raptor/README.md +++ b/packages/raptor/README.md @@ -1,7 +1,5 @@ -@defgroup YAPRaptor An RDF Reader for YAP. -@ingroup YAPPackages - -#YAP raptor Interface +WWW Reader/Writers for YAP. (#YAPRaptor) +########################### This provides YAP a rdf reader using [raptor](http://librdf.org/raptor/). The library is available for @@ -21,3 +19,5 @@ Predicate = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#type', Subject = 'http://www.example.org/law_and_order_ci' ? ~~~~{.prolog} + +The code also includes a library under developent to connect Yap and libXML2. diff --git a/packages/real/README.md b/packages/real/README.md index 2f96c15de..129f44ce8 100644 --- a/packages/real/README.md +++ b/packages/real/README.md @@ -1,10 +1,228 @@ +The R Prolog Progrmming Interface (#real) +=================================== -Real ---- +@file real.pl +@author Nicos Angelopoulos +@author Vitor Santos Costa +@version 1:0:4, 2013/12/25, sinter_class +@license Perl Artistic License + @defgroup libReal An interface to the R statistical software. +@ingroup packages -Real is a c-based interface for connecting R to Prolog. -YAP introduces a development version of real, developed to experiment +This library enables the communication with an R process started as a shared library. +It is the result of the efforts of two research groups that have worked in parallel. +The syntactic emphasis on a minimalistic interface. + +In the doc/ directory of the distribution there is user's guide, a published paper +and html documentation from PlDoc (doc/html/real.html). There is large number +of examples in `examples/for_real.pl`. + +A single predicate (<-/2,<-/1) channels +the bulk of the interactions. In addition to using R as a shared library, real uses +the c-interfaces of SWI/Yap and R to pass objects in both directions. +The usual mode of operation is to load Prolog values on to R variables and then call +R functions on these values. The return value of the called function can be either placed +on R variable or passed back to Prolog. It has been tested extensively on current +SWI and YAP on Linux machines but it should also compile and work on MS operating systems and Macs. + +The main modes for utilising the interface are +~~~~ + <- +Rexpr + <- +Rvar +~~~~ + + Print Rvar or evaluate expression Rexpr in R +~~~~ + +Rvar <- +PLdata + +Rexpr <- +PLdata + -PLvar <- +Rvar + -PLvar <- +Rexpr + +Rexpr1 <- +Rexpr2 +~~~~ + +Pass Prolog data to R, pass R data to Prolog or assign an R expression to +an assignable R expression. + +@defgroup TestingR Testing Real + +There is a raft of examples packed in a singl```e file that test the library. + +~~~~ + ?- [pack(real/examples/for_real)]. + + ?- for_real. + + ?- edit( pack(real/examples/for_real) ). +~~~~ + +@defgroup RSyntax Prolog and R Syntax + +There are syntactic conventions in R that make unparsable prolog code. +Notably function and variable names are allowed to contain dots, square brackets are used +to access parts of vectors and arrays and functions are allowed empty argument tuples. +We have introduced relevant syntax which allows for easy transition between prolog and R. +Prolog constructs are converted by the library as follows: + + +* =|..|= within atoms -> =|.|= (ex. =| as..integer(c(1,2,3)) -> as.integer(c(1,2,3))|= ) +* =|^[]|= after atoms -> =|[]|= (ex. =|a^[2] -> a[2] |=) +* =|(.)|= at the end of atoms that are known R functions -> =|()|= (ex. =|dev..off(.) -> dev.off()|= ) +* =|[]|= -> c() (which equal to R's NULL value) +* ( f(x) :- (..)) -> f(x) (...) +* Lists of lists are converted to matrices. All first level lists must have the same length. +* Filenames must be given as Prolog strings. +* R specific operators (eg. %*% should be quoted in Prolog. +* + prepends strings, for (Prolog) atoms: +'String' +* Expressions that pose difficulty in translation can always be passed as unquoted Prolog atoms or strings. + ]]* since 0:1:2 foo() is valid syntax: =|<- dev..off() |= works now (with no need for dev..off(.)) + * since 0:1:2 mat[1] is valid syntax: =|m[1] <- 4|= works now (with no need for m^[...]) + +@defgroup RDataTransfer Mapping Data betweenn Prolog and R + +R vectors are mapped to prolog lists and matrices are mapped to nested lists. +The convention works the other way around too. + +There are two ways to pass prolog data to R. The more efficient one is by using +~~~~ + Rvar <- PLdata +~~~~ + +Where Pldata is one of the basic data types (number,boolean) a list or a c/n term. +This transfers via C data between R and Prolog. In what follows atomic PLval data +are simply considered as singleton lists. +Flat Pldata lists are translated to R vectors and lists of one level of nesting to R matrices +(which are 2 dimensional arrays in R parlance). The type of values of the vector or matrice is +taken to be the type of the first data element of the Pldata according to the following : + + * integer -> integer + * float -> double + * atom -> char + * boolean -> logical + +Booleans are represented in prolog as true/false atoms. +Currently arrays of aribtrary dimensions are not supported in the low-level interface. +Note that in R a scalar is just a one element vector. When passing non-scalars the +interface will assume the type of the object is that of the first scalar until it encounters +something different. +Real will currently re-start and repopulate partial integers for floats as illustrated +below: + +~~~~ +r <- [1,2,3]. % pass 1,2,3 to an R vector r +R <- r. % pass contents of R vector r to Prolog variable R +R = [1, 2, 3]. + +i <- [1,2,3.1]. % r is now a vector of floats, rather than integers +I <- i. +I = [1.0, 2.0, 3.1]. + + +~~~~ + +However, not all possible "corrections" are currently supported. For instance, + +~~~~ +?- c <- [a,b,c,1]. +ERROR: real:set_R_variable/2: Type error: `boolean' expected, found `a' +~~~~ + +In the data passing mode we map Prolog atoms to R strings- + +~~~~ +?- x <- [abc,def]. +true. + +?- <- x. +[1] "abc" "def" +true. + +?- X <- x. +X = [abc, def]. + +~~~~ + +In addition, Prolog data can be passed through the expression mechanism. +That is, data appearing in an arbitrary R expression will be parsed and be part of the long +string that will be passed from Prolog to R for evaluation. +This is only advisable for short data structures. For instance, + +~~~~ + tut_4a :- + state <- c(+"tas", +"sa", +"qld", +"nsw", +"nsw"), + <- state. + + tut_4b :- + state <- c(+tas, +sa, +qld, +nsw, +nsw), + <- state. +~~~~ + +Through this interface it is more convenient to be explicit about R chars by Prolog prepending +atoms or codes with + as in the above example. + +@defgroup RealExamples Examples + +~~~~ + +?- e <- numeric(.). +yes +?- e^[3] <- 17. +yes +?- e[3] <- 17. +yes +?- Z <- e. +Z = ['$NaN','$NaN',17.0] +?- e^[10] <- 12. +yes +?- Z <- e. +Z = ['$NaN','$NaN',17.0,'$NaN','$NaN','$NaN','$NaN','$NaN','$NaN',12.0] + +rtest :- + y <- rnorm(50), % get 50 random samples from normal distribution + <- y, % print the values via R + x <- rnorm(y), % get an equal number of normal samples + <- x11(width=5,height=3.5), % create a plotting window + <- plot(x,y) % plot the two samples + r_wait, % wait for user to hit Enter + % <- dev..off(.). % old syntax, still supported + <- dev.off(). % close the plotting window. foo() now acceptable in supported Prologs + +tut6 :- + d <- outer(0:9, 0:9), + fr <- table(outer(d, d, "-")), + <- plot(as..numeric(names(fr)), fr, type="h", xlab="Determinant", ylab="Frequency"). + +tut4b :- + state <- [tas,sa,qld,nsw,nsw,nt,wa], + statef <- factor(state), + incmeans <- tapply( c(60, 49, 40, 61, 64, 60, 59), statef, mean ), + <- incmeans. + +logical :- + t <- [1,2,3,4,5,1], + s <- t~~~~1, + <- s, + S <- s, + write( s(S) ), nl. + +~~~~ + +#### Info + +@see http://stoics.org.uk/~nicos/sware/real +@see pack(real/examples/for_real) +@see pack(real/doc/real.html) +@see pack(real/doc/guide.pdf) +@see pack(real/doc/padl2013-real.pdf) +@see http://www.r-project.org/ + +Also @subpaage yap-real describes the YAP specfic details in real. + +*/Development of real in YAP (#yap-real) +--------------------------- + + +YAP includes a development version of real, designed to experiment with the internals of the implementation of R. It includes major changes and is likely to be much less stable than the version maintained by Nicos ANgelopoulos. We refer to the version herein as @@ -56,4 +274,3 @@ March, 2014 Updates: Vitor Santos Costa Dec. 2015 - diff --git a/packages/real/real.pl b/packages/real/real.pl index 19985c71d..972b8777f 100755 --- a/packages/real/real.pl +++ b/packages/real/real.pl @@ -10,15 +10,6 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -/** - -@file real.pl -@author Nicos Angelopoulos -@author Vitor Santos Costa -@version 1:0:4, 2013/12/25, sinter_class -@license Perl Artistic License - -*/ :- module(real, [ start_r/0, @@ -76,220 +67,6 @@ %:- set_prolog_flag(double_quotes, string ). -/** @defgroup libReal An interface to the R statistical software. -@ingroup packages - -#### Introduction - -This library enables the communication with an R process started as a shared library. -It is the result of the efforts of two research groups that have worked in parallel. -The syntactic emphasis on a minimalistic interface. - -In the doc/ directory of the distribution there is user's guide, a published paper -and html documentation from PlDoc (doc/html/real.html). There is large number -of examples in `examples/for_real.pl`. - -A single predicate (<-/2,<-/1) channels -the bulk of the interactions. In addition to using R as a shared library, real uses -the c-interfaces of SWI/Yap and R to pass objects in both directions. -The usual mode of operation is to load Prolog values on to R variables and then call -R functions on these values. The return value of the called function can be either placed -on R variable or passed back to Prolog. It has been tested extensively on current -SWI and YAP on Linux machines but it should also compile and work on MS operating systems and Macs. - -The main modes for utilising the interface are -~~~~ - <- +Rexpr - <- +Rvar -~~~~ - - Print Rvar or evaluate expression Rexpr in R -~~~~ - +Rvar <- +PLdata - +Rexpr <- +PLdata - -PLvar <- +Rvar - -PLvar <- +Rexpr - +Rexpr1 <- +Rexpr2 -~~~~ - -Pass Prolog data to R, pass R data to Prolog or assign an R expression to -an assignable R expression. - -#### Testing - -There is a raft of examples packed in a singl```e file that test the library. - -~~~~ - ?- [pack(real/examples/for_real)]. - - ?- for_real. - - ?- edit( pack(real/examples/for_real) ). -~~~~ - -#### Syntax - -There are syntactic conventions in R that make unparsable prolog code. -Notably function and variable names are allowed to contain dots, square brackets are used -to access parts of vectors and arrays and functions are allowed empty argument tuples. -We have introduced relevant syntax which allows for easy transition between prolog and R. -Prolog constructs are converted by the library as follows: - - -* =|..|= within atoms -> =|.|= (ex. =| as..integer(c(1,2,3)) -> as.integer(c(1,2,3))|= ) -* =|^[]|= after atoms -> =|[]|= (ex. =|a^[2] -> a[2] |=) -* =|(.)|= at the end of atoms that are known R functions -> =|()|= (ex. =|dev..off(.) -> dev.off()|= ) -* =|[]|= -> c() (which equal to R's NULL value) -* ( f(x) :- (..)) -> f(x) (...) -* Lists of lists are converted to matrices. All first level lists must have the same length. -* Filenames must be given as Prolog strings. -* R specific operators (eg. %*% should be quoted in Prolog. -* + prepends strings, for (Prolog) atoms: +'String' -* Expressions that pose difficulty in translation can always be passed as unquoted Prolog atoms or strings. - ]]* since 0:1:2 foo() is valid syntax: =|<- dev..off() |= works now (with no need for dev..off(.)) - * since 0:1:2 mat[1] is valid syntax: =|m[1] <- 4|= works now (with no need for m^[...]) - - -#### Data transfers - -R vectors are mapped to prolog lists and matrices are mapped to nested lists. -The convention works the other way around too. - -There are two ways to pass prolog data to R. The more efficient one is by using -~~~~ - Rvar <- PLdata -~~~~ - -Where Pldata is one of the basic data types (number,boolean) a list or a c/n term. -This transfers via C data between R and Prolog. In what follows atomic PLval data -are simply considered as singleton lists. -Flat Pldata lists are translated to R vectors and lists of one level of nesting to R matrices -(which are 2 dimensional arrays in R parlance). The type of values of the vector or matrice is -taken to be the type of the first data element of the Pldata according to the following : - - * integer -> integer - * float -> double - * atom -> char - * boolean -> logical - -Booleans are represented in prolog as true/false atoms. -Currently arrays of aribtrary dimensions are not supported in the low-level interface. -Note that in R a scalar is just a one element vector. When passing non-scalars the -interface will assume the type of the object is that of the first scalar until it encounters -something different. -Real will currently re-start and repopulate partial integers for floats as illustrated -below: - -~~~~ -r <- [1,2,3]. % pass 1,2,3 to an R vector r -R <- r. % pass contents of R vector r to Prolog variable R -R = [1, 2, 3]. - -i <- [1,2,3.1]. % r is now a vector of floats, rather than integers -I <- i. -I = [1.0, 2.0, 3.1]. - - -~~~~ - -However, not all possible "corrections" are currently supported. For instance, - -~~~~ -?- c <- [a,b,c,1]. -ERROR: real:set_R_variable/2: Type error: `boolean' expected, found `a' -~~~~ - -In the data passing mode we map Prolog atoms to R strings- - -~~~~ -?- x <- [abc,def]. -true. - -?- <- x. -[1] "abc" "def" -true. - -?- X <- x. -X = [abc, def]. - -~~~~ - -In addition, Prolog data can be passed through the expression mechanism. -That is, data appearing in an arbitrary R expression will be parsed and be part of the long -string that will be passed from Prolog to R for evaluation. -This is only advisable for short data structures. For instance, - -~~~~ - tut_4a :- - state <- c(+"tas", +"sa", +"qld", +"nsw", +"nsw"), - <- state. - - tut_4b :- - state <- c(+tas, +sa, +qld, +nsw, +nsw), - <- state. -~~~~ - -Through this interface it is more convenient to be explicit about R chars by Prolog prepending -atoms or codes with + as in the above example. - -#### Examples - -~~~~ - -?- e <- numeric(.). -yes -?- e^[3] <- 17. -yes -?- e[3] <- 17. -yes -?- Z <- e. -Z = ['$NaN','$NaN',17.0] -?- e^[10] <- 12. -yes -?- Z <- e. -Z = ['$NaN','$NaN',17.0,'$NaN','$NaN','$NaN','$NaN','$NaN','$NaN',12.0] - -rtest :- - y <- rnorm(50), % get 50 random samples from normal distribution - <- y, % print the values via R - x <- rnorm(y), % get an equal number of normal samples - <- x11(width=5,height=3.5), % create a plotting window - <- plot(x,y) % plot the two samples - r_wait, % wait for user to hit Enter - % <- dev..off(.). % old syntax, still supported - <- dev.off(). % close the plotting window. foo() now acceptable in supported Prologs - -tut6 :- - d <- outer(0:9, 0:9), - fr <- table(outer(d, d, "-")), - <- plot(as..numeric(names(fr)), fr, type="h", xlab="Determinant", ylab="Frequency"). - -tut4b :- - state <- [tas,sa,qld,nsw,nsw,nt,wa], - statef <- factor(state), - incmeans <- tapply( c(60, 49, 40, 61, 64, 60, 59), statef, mean ), - <- incmeans. - -logical :- - t <- [1,2,3,4,5,1], - s <- t~~~~1, - <- s, - S <- s, - write( s(S) ), nl. - -~~~~ - -#### Info - -@see http://stoics.org.uk/~nicos/sware/real -@see pack(real/examples/for_real) -@see pack(real/doc/real.html) -@see pack(real/doc/guide.pdf) -@see pack(real/doc/padl2013-real.pdf) -@see http://www.r-project.org/ - -*/ - %%% init_r_env :- diff --git a/packages/udi/udi.md b/packages/udi/udi.md index 459d88f65..25d5e1e4b 100644 --- a/packages/udi/udi.md +++ b/packages/udi/udi.md @@ -1,5 +1,4 @@ -User Defined Indexers. -====================== +User-Defined Indexing (#yap-udi-indexers) +===================== YAP UDI indexers. - diff --git a/pl/attributes.md b/pl/attributes.md index eb005c854..876ac1569 100644 --- a/pl/attributes.md +++ b/pl/attributes.md @@ -1,4 +1,5 @@ -@{ + Attributed Variables and Co-Routining {#AttributedVariables} +======================================= @defgroup AttributedVariables Attributed Variables and Co-Routining @ingroup extensions @@ -27,15 +28,12 @@ work with. Most packages included in YAP that use attributed variables, such as CHR, CLP(FD), and CLP(QR), rely on the SWI-Prolog interface. -+ @ref attributes ++ @ewd attributes + @ref New_Style_Attribute_Declarations + @ref CohYroutining + @ref AttributeVariables_Builtins -@{ - -@defgroup attributes SICStus Style attribute declarations. -@ingroup AttributedVariables +@section attributes SICStus Style attribute declarations. The YAP library `atts` implements attribute variables in the style of SICStus Prolog. Attributed variables work as follows: @@ -282,7 +280,6 @@ Module:get_atts/2`. @{ @defgroup New_Style_Attribute_Declarations hProlog and SWI-Prolog style Attribute Declarations -@ingroup AttributedVariables The following documentation is taken from the SWI-Prolog manual. @@ -305,7 +302,7 @@ Module:get_atts/2`. get_attr(X, domain, Dom). domain(X, List) :- list_to_ord_set(List, Domain), - put_attr(Y, domain, Domain), +v put_attr(Y, domain, Domain), X = Y. % An attributed variable with attribute value Domain has been % @@ -355,7 +352,6 @@ Module:get_atts/2`. @{ @defgroup CohYroutining Co-routining -@ingroup AttributedVariables Prolog uses a simple left-to-right flow of control. It is sometimes convenient to change this control so that goals will only execute when diff --git a/pl/modules.md b/pl/modules.md index 7c9cccacd..299d6d0ef 100644 --- a/pl/modules.md +++ b/pl/modules.md @@ -1,7 +1,8 @@ +# The YAP Module system -@defgroup YAPModules The YAP Module system + The YAP Module system (#YAPModules) + - -@ingroup consult The YAP module system is based on the Quintus/SISCtus module system ˜\cite quintus . In this design, modules are named collections of predicates, diff --git a/run.md b/run.md new file mode 100644 index 000000000..262859f4e --- /dev/null +++ b/run.md @@ -0,0 +1,193 @@ +Running YAP (#run) +============== + + +We next describe how to invoke YAP in Unix systems. + +Running YAP Interactively (#interactive_run) +------------------------- + +Most often you will want to use YAP in interactive mode. Assuming that +YAP is in the user's search path, the top-level can be invoked under +Unix with the following command: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +yap [-s n] [-h n] [-a n] [-c IP_HOST port ] [filename] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +All the arguments and flags are optional and have the following meaning: + ++ -? +print a short error message. ++ -s _Size_ +allocate _Size_ KBytes for local and global stacks. The user may +specify M bytes. ++ -h _Size_ +allocate _Size_ KBytes for heap and auxiliary stacks ++ -t _Size_ +allocate _Size_ KBytes for the trail stack ++ -L _Size_ +SWI-compatible option to allocate _Size_ K bytes for local and global stacks, the local stack +cannot be expanded. To avoid confusion with the load option, _Size_ +must immediately follow the letter `L`. ++ -G _Size_ +SWI-compatible option to allocate _Size_ K bytes for local and global stacks; the global +stack cannot be expanded ++ -T _Size_ +SWI-compatible option to allocate _Size_ K bytes for the trail stack; the trail cannot be expanded. ++ -l _YAP_FILE_ +compile the Prolog file _YAP_FILE_ before entering the top-level. ++ -L _YAP_FILE_ +compile the Prolog file _YAP_FILE_ and then halt. This option is +useful for implementing scripts. ++ -g _Goal_ +run the goal _Goal_ before top-level. The goal is converted from +an atom to a Prolog term. ++ -z _Goal_ +run the goal _Goal_ as top-level. The goal is converted from +an atom to a Prolog term. ++ -b _BOOT_FILE_ +boot code is in Prolog file _BOOT_FILE_. The filename must define +the predicate `'$live'/0`. ++ -c IP_HOST port +connect standard streams to host IP_HOST at port port ++ filename +restore state saved in the given file ++ -f +do not consult initial files ++ -q +do not print informational messages ++ -- +separator for arguments to Prolog code. These arguments are visible +through the unix/1 built-in predicate. + + +Note that YAP will output an error message on the following conditions: + ++ +a file name was given but the file does not exist or is not a saved +YAP state; + ++ +the necessary amount of memory could not be allocated; + ++ +the allocated memory is not enough to restore the state. + + + When restoring a saved state, YAP will allocate the +same amount of memory as that in use when the state was saved, unless a +different amount is specified by flags in the command line. By default, +YAP restores the file startup.yss from the current directory or from +the YAP library. + ++ +YAP usually boots from a saved state. The saved state will use the default +installation directory to search for the YAP binary unless you define +the environment variable YAPBINDIR. + ++ +YAP always tries to find saved states from the current directory + first. If it cannot it will use the environment variable YAPLIBDIR, if + defined, or search the default library directory. + ++ +YAP will try to find library files from the YAPSHAREDIR/library +directory. + +Prolog Scripts +-------------- + +YAP can also be used to run Prolog files as scripts, at least in +Unix-like environments. A simple example is shown next (do not forget +that the shell comments are very important): + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +#!/usr/local/bin/yap -L -- +# +# Hello World script file using YAP +# +# put a dot because of syntax errors . + +:- write('Hello World'), nl. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The `#!` characters specify that the script should call the binary +file YAP. Notice that many systems will require the complete path to the +YAP binary. The `-L` flag indicates that YAP should consult the +current file when booting and then halt. The remaining arguments are +then passed to YAP. Note that YAP will skip the first lines if they +start with `#` (the comment sign for Unix's shell). YAP will +consult the file and execute any commands. + +A slightly more sophisticated example is: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +#!/usr/bin/yap -L -- +# +# Hello World script file using YAP +# . + +:- initialization(main). + +main :- write('Hello World'), nl. + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The `initialization` directive tells YAP to execute the goal main +after consulting the file. Source code is thus compiled and `main` +executed at the end. The `.` is useful while debugging the script +as a Prolog program: it guarantees that the syntax error will not +propagate to the Prolog code. + +Notice that the `--` is required so that the shell passes the extra +arguments to YAP. As an example, consider the following script +`dump_args`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +#!/usr/bin/yap -L -- +#. + +main( [] ). +main( [H|T] ) :- + write( H ), nl, + main( T ). + +:- unix( argv(AllArgs) ), main( AllArgs ). + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +If you this run this script with the arguments: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +./dump_args -s 10000 +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +the script will start an YAP process with stack size `10MB`, and +the list of arguments to the process will be empty. + +Often one wants to run the script as any other program, and for this it +is convenient to ignore arguments to YAP. This is possible by using +`L --` as in the next version of `dump_args`: + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +#!/usr/bin/yap -L -- + +main( [] ). +main( [H|T] ) :- + write( H ), nl, + main( T ). + +:- unix( argv(AllArgs) ), main( AllArgs ). + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The `--` indicates the next arguments are not for YAP. Instead, +they must be sent directly to the argv built-in. Hence, running + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +./dump_args test +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +will write `test` on the standard output. +@} From f44ef18fedb1bcf05a785987ff3a012905e27631 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 23 Nov 2016 17:23:59 -0600 Subject: [PATCH 11/41] fix atom_to_term and increase sharing on CUDD stuff --- C/atomic.c | 81 ++- C/c_interface.c | 13 +- C/cdmgr.c | 4 - C/compiler.c | 5 +- C/errors.c | 6 +- C/exec.c | 6 +- C/flags.c | 18 +- C/text.c | 6 +- CMakeLists.txt | 2 + CXX/yapdb.hh | 2 +- GIT | 10 - Untitled | 337 ---------- callcount.yap | 152 ----- cmake/Config.cmake | 25 +- cmake/cudd.cmake | 7 +- {packages/bdd => cmake}/cudd_config.h.cmake | 0 example.py | 14 - heap_top_ | 0 include/YapError.h | 6 +- libYap.cmake | 2 +- os/fmem.c | 3 +- os/readterm.c | 156 ++--- os/yapio.h | 3 +- packages/bdd/CMakeLists.txt | 5 - packages/bdd/simplecudd/simplecudd.c | 222 +------ packages/bdd/simplecudd/simplecudd.h | 3 +- packages/bdd/simplecudd_lfi/simplecudd.h | 3 +- packages/cplint/CMakeLists.txt | 8 +- packages/myddas/sqlite3/CMakeLists.txt | 8 +- pl/dbload.yap | 10 +- x.py | 652 -------------------- x.tgz | Bin 15374 -> 0 bytes 32 files changed, 190 insertions(+), 1579 deletions(-) delete mode 100644 GIT delete mode 100644 Untitled delete mode 100644 callcount.yap rename {packages/bdd => cmake}/cudd_config.h.cmake (100%) delete mode 100644 example.py delete mode 100644 heap_top_ delete mode 100644 x.py delete mode 100644 x.tgz diff --git a/C/atomic.c b/C/atomic.c index b71049052..30e7221aa 100644 --- a/C/atomic.c +++ b/C/atomic.c @@ -885,7 +885,6 @@ static Int string_concat3(USES_REGS1) { Term t2, t3, ot; Term tf = 0; bool g1, g2, g3; - Atom at; int l = push_text_stack(); restart_aux: t1 = Deref(ARG1); @@ -909,7 +908,6 @@ restart_aux: return cont_string_concat3(PASS_REGS1); } else { LOCAL_Error_TYPE = INSTANTIATION_ERROR; - at = NULL; } if (tf) { if (Yap_unify(ot, tf)) { @@ -1880,14 +1878,13 @@ static Int cont_sub_atomic(USES_REGS1) { size_t minv, len, after, sz; wchar_t *wp = NULL; const unsigned char *p = NULL, *p5 = NULL; - bool sub_atom = TRUE; - + mask = IntegerOfTerm(EXTRA_CBACK_ARG(5, 1)); minv = IntegerOfTerm(EXTRA_CBACK_ARG(5, 2)); len = IntegerOfTerm(EXTRA_CBACK_ARG(5, 3)); after = IntegerOfTerm(EXTRA_CBACK_ARG(5, 4)); sz = IntegerOfTerm(EXTRA_CBACK_ARG(5, 5)); - + if (!IsVarTerm(tat1)) { if (IsAtomTerm(tat1)) { p = AtomOfTerm(tat1)->UStrOfAE; @@ -1907,7 +1904,7 @@ static Int cont_sub_atomic(USES_REGS1) { bool found = false; { const unsigned char *p1 = p; - + while (!found) { p = skip_utf8(p1, minv); if (cmpn_utf8(p, p5, len) == 0) { @@ -2219,6 +2216,73 @@ static Int cont_sub_atomic(USES_REGS1) { return sub_atomic(false, true PASS_REGS); } + + static Int atomic_to_term(USES_REGS1) { + Term t1 = Deref(ARG1), rc; + const char *s; + size_t len; + if (IsVarTerm(t1)) { + Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3"); + return (FALSE); + } else if (!IsAtomicTerm(t1)) { + Yap_Error(TYPE_ERROR_ATOMIC, t1, "read_term_from_atomic/3"); + return (FALSE); + } else { + Term t = Yap_AtomicToString(t1 PASS_REGS); + s = (const char *)UStringOfTerm(t); + len = strlen_utf8((unsigned char *)s); + } + encoding_t enc = ENC_ISO_UTF8; + rc = Yap_StringToTerm(s, len, &enc, 1200, ARG3); + if (!rc) + return false; + return Yap_unify(rc, ARG2); + } + + static Int atom_to_term(USES_REGS1) { + Term t1 = Deref(ARG1), rc; + const char *s; + size_t len; + if (IsVarTerm(t1)) { + Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3"); + return (FALSE); + } else if (!IsAtomTerm(t1)) { + Yap_Error(TYPE_ERROR_ATOM, t1, "read_term_from_atomic/3"); + return (FALSE); + } else { + Term t = Yap_AtomicToString(t1 PASS_REGS); + s = StringOfTerm(t); + len = strlen_utf8((const unsigned char *)s); + } + encoding_t enc = ENC_ISO_UTF8; + rc = Yap_StringToTerm(s, len, &enc, 1200, ARG3); + if (!rc) + return false; + return Yap_unify(rc, ARG2); + } + + + static Int string_to_term(USES_REGS1) { + Term t1 = Deref(ARG1), rc; + const char *s; + size_t len; + if (IsVarTerm(t1)) { + Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3"); + return (FALSE); + } else if (!IsStringTerm(t1)) { + Yap_Error(TYPE_ERROR_STRING, t1, "read_term_from_string/3"); + return (FALSE); + } else { + s = StringOfTerm(t1); + len = strlen_utf8((const unsigned char *)s); + } + encoding_t enc = ENC_ISO_UTF8; + rc = Yap_StringToTerm(s, len, &enc, 1200, ARG3); + if (!rc) + return false; + return Yap_unify(rc, ARG2); + } + static Int cont_current_atom(USES_REGS1) { Atom catom; Int i = IntOfTerm(EXTRA_CBACK_ARG(1, 2)); @@ -2357,6 +2421,11 @@ static Int cont_sub_atomic(USES_REGS1) { */ + + Yap_InitCPred("atom_to_term", 3, atom_to_term, 0); + Yap_InitCPred("atomic_to_term", 3, atomic_to_term, 0); + Yap_InitCPred("string_to_term", 3, string_to_term, 0); + Yap_InitCPred("atom_chars", 2, atom_chars, 0); /** @pred atom_chars(? _A_,? _L_) is iso diff --git a/C/c_interface.c b/C/c_interface.c index 54f18ccc6..17ec56df9 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -452,7 +452,7 @@ X_API Atom YAP_LookupAtom(const char *c) { X_API Atom YAP_LookupWideAtom(const wchar_t *c) { CACHE_REGS Atom a; - + while (TRUE) { a = Yap_NWCharsToAtom(c, -1 USES_REGS); @@ -1187,10 +1187,10 @@ Int YAP_ExecuteOnCut(PredEntry *pe, CPredicate exec_code, Yap_CloseSlots(CurSlot); PP = NULL; // B = LCL0-(CELL*)oB; - if (false && Yap_RaiseException()) { + if (!val && Yap_RaiseException()) { return false; } else { /* TRUE */ - return true; + return val; } } @@ -1373,12 +1373,13 @@ X_API Term YAP_NWideBufferToString(const wchar_t *s, size_t len) { /* copy a string to a buffer */ X_API Term YAP_ReadBuffer(const char *s, Term *tp) { CACHE_REGS - Term t; + Term tv, t; BACKUP_H(); + if (*tp) tv = *tp; else tv = 0; LOCAL_ErrorMessage = NULL; while (!(t = Yap_StringToTerm(s, strlen(s) + 1, &LOCAL_encoding, - GLOBAL_MaxPriority, tp))) { + GLOBAL_MaxPriority,tv))) { if (LOCAL_ErrorMessage) { if (!strcmp(LOCAL_ErrorMessage, "Stack Overflow")) { if (!Yap_dogc(0, NULL PASS_REGS)) { @@ -2306,7 +2307,7 @@ YAP_file_type_t YAP_Init(YAP_init_args *yap_init) { GLOBAL_PrologShouldHandleInterrupts = yap_init->PrologShouldHandleInterrupts; Yap_InitSysbits(0); /* init signal handling and time, required by later functions */ - GLOBAL_argv = yap_init->Argv; + GLOBAL_argv = yap_init->Argv; GLOBAL_argc = yap_init->Argc; if (0 && ((YAP_QLY && yap_init->SavedState) || (YAP_BOOT_PL && (yap_init->YapPrologBootFile)))) { diff --git a/C/cdmgr.c b/C/cdmgr.c index 858e304be..65acb4b91 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -1447,11 +1447,7 @@ static int not_was_reconsulted(PredEntry *p, Term t, int mode) { static void addcl_permission_error(AtomEntry *ap, Int Arity, int in_use) { CACHE_REGS - Term t, ti[2]; - ti[0] = MkAtomTerm(AbsAtom(ap)); - ti[1] = MkIntegerTerm(Arity); - t = Yap_MkApplTerm(FunctorSlash, 2, ti); LOCAL_Error_TYPE = PERMISSION_ERROR_MODIFY_STATIC_PROCEDURE; LOCAL_ErrorMessage = Malloc( 256 ); diff --git a/C/compiler.c b/C/compiler.c index 77d8906a3..868c588bf 100644 --- a/C/compiler.c +++ b/C/compiler.c @@ -1093,7 +1093,7 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, char s[32]; Yap_bip_name(Op, s); - Yap_ThrowError(INSTANTIATION_ERROR , t2, "compiling %s/3", s); + Yap_ThrowError(INSTANTIATION_ERROR , t2, "compiling %s/3", s); save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, 1); } @@ -1110,9 +1110,10 @@ static void c_bifun(basic_preds Op, Term t1, Term t2, Term t3, Term Goal, i2 = IntegerOfTerm(t2); if (i2 < 0) { - Yap_ThrowError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO , t2,4, "compiling functor/3"); + Yap_ThrowError(DOMAIN_ERROR_NOT_LESS_THAN_ZERO , t2, "compiling functor/3"); save_machine_regs(); siglongjmp(cglobs->cint.CompilerBotch, 1); + } if (IsNumTerm(t1)) { /* we will always fail */ diff --git a/C/errors.c b/C/errors.c index 6d8aac85b..7f749141b 100755 --- a/C/errors.c +++ b/C/errors.c @@ -311,11 +311,11 @@ yap_error_descriptor_t *Yap_popErrorContext(void) { } void Yap_ThrowError__(const char *file, const char *function, int lineno, - yap_error_number type, Term where, int code, ...) { + yap_error_number type, Term where, ...) { va_list ap; char tmpbuf[MAXPATHLEN]; - va_start(ap, code); + va_start(ap, where); char *format = va_arg(ap, char *); if (format != NULL) { #if HAVE_VSNPRINTF @@ -328,7 +328,7 @@ Yap_Error__(file, function, lineno, type, where, tmpbuf); } else { Yap_Error__(file, function, lineno, type, where); } - siglongjmp(LOCAL_RestartEnv, code); + siglongjmp(LOCAL_RestartEnv, 4); } /** diff --git a/C/exec.c b/C/exec.c index fa669c67a..681e8e408 100755 --- a/C/exec.c +++ b/C/exec.c @@ -1023,7 +1023,6 @@ static Int protect_stack(USES_REGS1) { static Int setup_call_catcher_cleanup(USES_REGS1) { Term Setup = Deref(ARG1); - Term cmod = CurrentModule; Int oENV = LCL0 - ENV; choiceptr B0 = B; Term t3, t4; @@ -1051,8 +1050,6 @@ static Int setup_call_catcher_cleanup(USES_REGS1) { prune_inner_computation(B0); } // at this point starts actual goal execution.... - cmod = CurrentModule; - rc = Yap_RunTopGoal(Yap_GetFromSlot(h2), false); complete_inner_computation(B); t4 = Yap_GetFromSlot(h4); @@ -2010,7 +2007,7 @@ bool is_cleanup_cp(choiceptr cp_b) { } static Int JumpToEnv() { - choiceptr handler = B, oh = NULL; + choiceptr handler = B; /* just keep the throwm object away, we don't need to care about it */ /* careful, previous step may have caused a stack shift, @@ -2028,7 +2025,6 @@ static Int JumpToEnv() { handler->cp_b == NULL)) { break; } - oh = handler; handler = handler->cp_b; } if (LOCAL_PrologMode & AsyncIntMode) { diff --git a/C/flags.c b/C/flags.c index d185a38ae..bf04be85c 100644 --- a/C/flags.c +++ b/C/flags.c @@ -182,7 +182,7 @@ static Term stream(Term inp) { } -static bool +static bool set_error_stream( Term inp ) { if( IsVarTerm(inp) ) return Yap_unify( inp, Yap_StreamUserName( LOCAL_c_error_stream ) ); @@ -191,7 +191,7 @@ set_error_stream( Term inp ) { return true; } -static bool +static bool set_input_stream( Term inp ) { if( IsVarTerm(inp) ) return Yap_unify( inp, Yap_StreamUserName( LOCAL_c_input_stream ) ); @@ -199,7 +199,7 @@ set_input_stream( Term inp ) { return true; } -static bool +static bool set_output_stream( Term inp ) { if( IsVarTerm(inp) ) return Yap_unify( inp, Yap_StreamUserName( LOCAL_c_output_stream ) ); @@ -870,7 +870,7 @@ static Int cont_prolog_flag(USES_REGS1) { } EXTRA_CBACK_ARG(3, 1) = MkIntTerm(++i); flag = getYapFlag(f); - if (!Yap_unify(f, ARG2)) + if (!Yap_unify(flag, ARG2)) return false; return setYapFlag(f, Deref(ARG3)); } @@ -1175,7 +1175,7 @@ static Int source_mode(USES_REGS1) { if (!current && !Yap_unify_constant(ARG1, TermFalse)) return false; targ = Deref(ARG2); - setYapFlag(TermSource, ARG2); + setYapFlag(TermSource, targ); return true; } @@ -1319,7 +1319,7 @@ static bool setInitialValue(bool bootstrap, flag_func f, const char *s, CACHE_REGS encoding_t encoding = ENC_ISO_UTF8; t0 = - Yap_StringToTerm(s, strlen(s) + 1, &encoding, GLOBAL_MaxPriority, NULL); + Yap_StringToTerm(s, strlen(s) + 1, &encoding, GLOBAL_MaxPriority, 0L); if (!t0) return false; if (IsAtomTerm(t0) || IsIntTerm(t0)) { @@ -1434,7 +1434,7 @@ do_prolog_flag_property(Term tflag, } } // UNLOCK(GLOBAL_Prolog_Flag[sno].prolog_flaglock); - free(args); + free(args); return rc; } @@ -1540,7 +1540,7 @@ static Int do_create_prolog_flag(USES_REGS1) { if (fv) { if (args[PROLOG_FLAG_PROPERTY_KEEP].used && args[PROLOG_FLAG_PROPERTY_KEEP].tvalue == TermTrue) { - free(args); + free(args); return true; } } else { @@ -1633,7 +1633,7 @@ void Yap_InitFlags(bool bootstrap) { if (GLOBAL_Stream[StdInStream].status & Readline_Stream_f) { setBooleanGlobalPrologFlag(READLINE_FLAG, true); } - + if (!bootstrap) { Yap_InitCPredBack("current_prolog_flag", 2, 1, current_prolog_flag, cont_yap_flag, 0); diff --git a/C/text.c b/C/text.c index 727783149..66b83dbea 100644 --- a/C/text.c +++ b/C/text.c @@ -731,7 +731,7 @@ static Term write_number(unsigned char *s, seq_tv_t *out, int size, bool error_o static Term string_to_term(void *s, seq_tv_t *out, size_t leng USES_REGS) { Term o; o = out->val.t = - Yap_StringToTerm(s, strlen(s) + 1, &out->enc, GLOBAL_MaxPriority, NULL); + Yap_StringToTerm(s, strlen(s) + 1, &out->enc, GLOBAL_MaxPriority, 0L); return o; } @@ -740,7 +740,7 @@ bool write_Text(unsigned char *inp, seq_tv_t *out, size_t leng USES_REGS) { if (out->type == 0) { return true; } - + if (out->type & YAP_STRING_TERM) { if ((out->val.t = string_to_term(inp, out, leng PASS_REGS)) != 0L) return out->val.t != 0; @@ -948,7 +948,7 @@ bool Yap_Concat_Text(int tot, seq_tv_t inp[], seq_tv_t *out USES_REGS) { unsigned char *buf; int i; size_t leng; - + bufv = Malloc(tot * sizeof(unsigned char *)); if (!bufv) { return NULL; diff --git a/CMakeLists.txt b/CMakeLists.txt index 34f61d613..5589a888f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,6 +53,8 @@ if(NOT COMMAND find_host_program) endmacro() endif() +option(BUILD_SHARED_LIBS "Build shared library" ON) + include(Prelims NO_POLICY_SCOPE) include(Sources NO_POLICY_SCOPE) diff --git a/CXX/yapdb.hh b/CXX/yapdb.hh index 2be2fb58f..8375ab9ef 100644 --- a/CXX/yapdb.hh +++ b/CXX/yapdb.hh @@ -138,7 +138,7 @@ protected: BACKUP_MACHINE_REGS(); Term *modp = NULL; - out = Yap_StringToTerm(s0, strlen(s0) + 1, &LOCAL_encoding, 1200, &names); + out = Yap_StringToTerm(s0, strlen(s0) + 1, &LOCAL_encoding, 1200, names); // extern char *s0; // fprintf(stderr,"ap=%p arity=%d text=%s", ap, ap->ArityOfPE, s); // Yap_DebugPlWrite(out); diff --git a/GIT b/GIT deleted file mode 100644 index 6bd7e5185..000000000 --- a/GIT +++ /dev/null @@ -1,10 +0,0 @@ - -You need at least git-1.6 to install the development version. - -Please proceed as follows for the main branch: - -git clone git://gitorious.org/yap-git/mainline.git yap -cd yap-6 -git submodule init -git submodule update - diff --git a/Untitled b/Untitled deleted file mode 100644 index 1b2556d6c..000000000 --- a/Untitled +++ /dev/null @@ -1,337 +0,0 @@ -Process: Python [88916] -Path: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -Identifier: Python -Version: 2.7.10 (2.7.10) -Code Type: X86-64 (Native) -Parent Process: Atom Helper [88821] -Responsible: Atom [88817] -User ID: 501 - -Date/Time: 2016-06-12 12:40:34.078 +0100 -OS Version: Mac OS X 10.11.5 (15F34) -Report Version: 11 -Anonymous UUID: B8085CAA-5C3C-7B89-D7A4-E30E7D5EAC9C - -Sleep/Wake UUID: ABD12798-599D-4E2A-8BAF-24F5ACC919E7 - -Time Awake Since Boot: 220000 seconds -Time Since Wake: 4000 seconds - -System Integrity Protection: enabled - -Crashed Thread: 0 Dispatch queue: com.apple.main-thread - -Exception Type: EXC_BAD_ACCESS (SIGSEGV) -Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000008 - -VM Regions Near 0x8: ---> - __TEXT 0000000105287000-0000000105288000 [ 4K] r-x/rwx SM=COW /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python - -Thread 0 Crashed:: Dispatch queue: com.apple.main-thread -0 org.python.python 0x000000010532ffce 0x10528f000 + 659406 -1 org.python.python 0x0000000105330481 PyGILState_Ensure + 55 -2 com.apple.LLDB.framework 0x0000000108b1e37a lldb_private::ScriptInterpreterPython::Locker::DoAcquireLock() + 28 -3 com.apple.LLDB.framework 0x0000000108b23a6b lldb_private::ScriptInterpreterPython::Clear() + 37 -4 com.apple.LLDB.framework 0x000000010885e510 lldb_private::Debugger::Clear() + 266 -5 com.apple.LLDB.framework 0x000000010885f8ec lldb_private::Debugger::~Debugger() + 28 -6 com.apple.LLDB.framework 0x000000010885fc0e lldb_private::Debugger::~Debugger() + 14 -7 libc++.1.dylib 0x00007fff91f31cb8 std::__1::__shared_weak_count::__release_shared() + 44 -8 com.apple.LLDB.framework 0x00000001068a06cf std::__1::__vector_base, std::__1::allocator > >::~__vector_base() + 49 -9 libsystem_c.dylib 0x00007fff9321246b __cxa_finalize_ranges + 345 -10 libsystem_c.dylib 0x00007fff9321276f exit + 55 -11 org.python.python 0x000000010533200c 0x10528f000 + 667660 -12 org.python.python 0x0000000105331c45 PyErr_PrintEx + 41 -13 org.python.python 0x0000000105331668 PyRun_SimpleFileExFlags + 750 -14 org.python.python 0x0000000105343011 Py_Main + 3137 -15 libdyld.dylib 0x00007fff8d16d5ad start + 1 - -Thread 1: -0 libsystem_kernel.dylib 0x00007fff9af6bf72 mach_msg_trap + 10 -1 libsystem_kernel.dylib 0x00007fff9af6b3b3 mach_msg + 55 -2 com.apple.CoreFoundation 0x00007fff95f861c4 __CFRunLoopServiceMachPort + 212 -3 com.apple.CoreFoundation 0x00007fff95f8568c __CFRunLoopRun + 1356 -4 com.apple.CoreFoundation 0x00007fff95f84ed8 CFRunLoopRunSpecific + 296 -5 com.apple.CoreFoundation 0x00007fff95fc69b1 CFRunLoopRun + 97 -6 com.apple.DebugSymbols 0x00007fff87a2c69a SpotlightQueryThread(void*) + 346 -7 libsystem_pthread.dylib 0x00007fff9490e99d _pthread_body + 131 -8 libsystem_pthread.dylib 0x00007fff9490e91a _pthread_start + 168 -9 libsystem_pthread.dylib 0x00007fff9490c351 thread_start + 13 - -Thread 2: -0 libsystem_kernel.dylib 0x00007fff9af725e2 __workq_kernreturn + 10 -1 libsystem_pthread.dylib 0x00007fff9490e578 _pthread_wqthread + 1283 -2 libsystem_pthread.dylib 0x00007fff9490c341 start_wqthread + 13 - -Thread 3: -0 libsystem_kernel.dylib 0x00007fff9af725e2 __workq_kernreturn + 10 -1 libsystem_pthread.dylib 0x00007fff9490e578 _pthread_wqthread + 1283 -2 libsystem_pthread.dylib 0x00007fff9490c341 start_wqthread + 13 - -Thread 4:: Dispatch queue: com.apple.libdispatch-manager -0 libsystem_kernel.dylib 0x00007fff9af72efa kevent_qos + 10 -1 libdispatch.dylib 0x00007fff87927165 _dispatch_mgr_invoke + 216 -2 libdispatch.dylib 0x00007fff87926dcd _dispatch_mgr_thread + 52 - -Thread 5: -0 libsystem_kernel.dylib 0x00007fff9af725e2 __workq_kernreturn + 10 -1 libsystem_pthread.dylib 0x00007fff9490e578 _pthread_wqthread + 1283 -2 libsystem_pthread.dylib 0x00007fff9490c341 start_wqthread + 13 - -Thread 6: -0 libsystem_kernel.dylib 0x00007fff9af725e2 __workq_kernreturn + 10 -1 libsystem_pthread.dylib 0x00007fff9490e578 _pthread_wqthread + 1283 -2 libsystem_pthread.dylib 0x00007fff9490c341 start_wqthread + 13 - -Thread 7: -0 libsystem_kernel.dylib 0x00007fff9af725e2 __workq_kernreturn + 10 -1 libsystem_pthread.dylib 0x00007fff9490e578 _pthread_wqthread + 1283 -2 libsystem_pthread.dylib 0x00007fff9490c341 start_wqthread + 13 - -Thread 0 crashed with X86 Thread State (64-bit): - rax: 0x0000000000000001 rbx: 0x00007fb1e266bdb0 rcx: 0x00000b0000000000 rdx: 0x00007fb1e2403388 - rdi: 0x00007fb1e2403368 rsi: 0x00000b0000000b00 rbp: 0x00007fff5a9785a0 rsp: 0x00007fff5a978580 - r8: 0x00000000fffffffc r9: 0x00007fb1e2403380 r10: 0x00000000ffffffff r11: 0xffffffff00000000 - r12: 0x0000000000000001 r13: 0x0000000000000000 r14: 0x0000000000000000 r15: 0x0000000000000001 - rip: 0x000000010532ffce rfl: 0x0000000000010206 cr2: 0x0000000000000008 - -Logical CPU: 6 -Error Code: 0x00000004 -Trap Number: 14 - - -Binary Images: - 0x105287000 - 0x105287fff org.python.python (2.7.10 - 2.7.10) <307E6E15-ECF7-3BB2-AF06-3E8D23DFDECA> /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python - 0x10528f000 - 0x105380ff7 org.python.python (2.7.10 - 2.7.10) <83AFAAA7-BDFA-354D-8A7A-8F40A30ACB91> /System/Library/Frameworks/Python.framework/Versions/2.7/Python - 0x105746000 - 0x105747fff _locale.so (94) <4394AC91-22AE-3D7D-85C4-792A4F35F3F2> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_locale.so - 0x10580c000 - 0x10580dff7 time.so (94) <94E8BF2A-7841-32AD-8722-6B2526999CA1> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/time.so - 0x105814000 - 0x105816fff select.so (94) <22170D1C-40EF-303A-8BB7-A48E783F9350> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/select.so - 0x10581d000 - 0x10581efff fcntl.so (94) <419069D5-A61F-3925-B320-EA7B9E38F44B> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/fcntl.so - 0x105823000 - 0x105826fff _struct.so (94) <0DCC6B47-A763-3AA6-82C5-B6A58073286B> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_struct.so - 0x10582d000 - 0x10582ffff binascii.so (94) <9044E1C3-221F-3B79-847A-C9C3D8FEA9FD> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/binascii.so - 0x105834000 - 0x105835fff cStringIO.so (94) /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/cStringIO.so - 0x10596c000 - 0x10596dfff libpanel.5.4.dylib (46) /usr/lib/libpanel.5.4.dylib - 0x1059a2000 - 0x1059b0fff _ctypes.so (94) <57C51BC5-542B-3E78-94AC-0AC3DDEAFE8F> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_ctypes.so - 0x1059bd000 - 0x1059c1fff itertools.so (94) <889782F7-5414-3881-BAAB-83CACDFDF0C5> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/itertools.so - 0x1059cb000 - 0x1059cefff operator.so (94) /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/operator.so - 0x1059d5000 - 0x1059d6ff7 readline.so (94) <9761BEFB-EF61-3542-B6D7-D4EE20F4FCF2> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/readline.so - 0x1059dd000 - 0x1059dffff _collections.so (94) <5FEB3871-0B8F-3233-876C-0E81CF581963> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_collections.so - 0x1059e6000 - 0x1059e7fff _heapq.so (94) <9200023E-75BA-3F20-843C-398C3709CA88> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_heapq.so - 0x1059ed000 - 0x1059f4ff7 _socket.so (94) <0995C171-1F75-3087-89BE-EC0F68FB1231> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_socket.so - 0x1059ff000 - 0x105a00fff _functools.so (94) <49B479ED-A07D-322D-9A29-AFF4CA084219> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_functools.so - 0x105a05000 - 0x105a0efff _ssl.so (94) <027A0AA6-E941-32D2-A091-47C3A43DD846> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_ssl.so - 0x105a1a000 - 0x105a25fff cPickle.so (94) /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/cPickle.so - 0x105a2c000 - 0x105a3bfff _io.so (94) <39FEF2EC-8D20-33A6-B91F-EF7B2FAE9009> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_io.so - 0x105a4c000 - 0x105a4fff7 math.so (94) <216DBA90-4498-361D-8321-B41F9A3B121C> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/math.so - 0x105a56000 - 0x105a57fff _hashlib.so (94) /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_hashlib.so - 0x105a5d000 - 0x105a5eff7 _random.so (94) <5A3C615E-01F8-37C2-A3F2-B1EDEB31C954> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_random.so - 0x105a63000 - 0x105a66ff7 strop.so (94) <44D8B4D6-D536-31EE-94EA-4F3C0FC773FA> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/strop.so - 0x105a6c000 - 0x105a6cfff _scproxy.so (94) <07D4037C-CB1A-3850-9C0A-A29446A772CE> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_scproxy.so - 0x105ab1000 - 0x105ab5fff _json.so (94) <8DF51919-72DB-335D-B4F5-D8B3B7A96A89> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_json.so - 0x105ac0000 - 0x105ac9ff7 datetime.so (94) <94EF278A-0BE1-3990-A13B-2A5F36F64263> /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/datetime.so - 0x10687c000 - 0x10941cff7 com.apple.LLDB.framework (1.350.0.21.9 - 350.0.21.9) <7862FFB0-5204-36DE-A5FA-9BE017CC7E45> /Applications/Xcode.app/Contents/SharedFrameworks/LLDB.framework/Versions/A/LLDB - 0x7fff6497b000 - 0x7fff649b225f dyld (360.22) /usr/lib/dyld - 0x7fff87008000 - 0x7fff872a2ff3 com.apple.security (7.0 - 57337.50.23) <8B6CF71D-A63E-34C9-9227-0AACAB643584> /System/Library/Frameworks/Security.framework/Versions/A/Security - 0x7fff875a4000 - 0x7fff875a6ff7 com.apple.xpc.ServiceManagement (1.0 - 1) /System/Library/Frameworks/ServiceManagement.framework/Versions/A/ServiceManagement - 0x7fff875d7000 - 0x7fff875dbfff libGIF.dylib (1450) /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libGIF.dylib - 0x7fff8767e000 - 0x7fff87686fff com.apple.CoreServices.FSEvents (1223.10.1 - 1223.10.1) <7F5B7A23-BC1D-3FA9-A9B8-D534F1E1979A> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/FSEvents.framework/Versions/A/FSEvents - 0x7fff87765000 - 0x7fff877a7ff7 com.apple.Metal (56.6 - 56.6) <2B2C0F78-20B8-3878-B9B1-DE18BB92919D> /System/Library/Frameworks/Metal.framework/Versions/A/Metal - 0x7fff877a8000 - 0x7fff8780eff7 libsystem_network.dylib (583.50.1) /usr/lib/system/libsystem_network.dylib - 0x7fff8780f000 - 0x7fff8791efe7 libvDSP.dylib (563.5) <9AB6CA3C-4F0E-35E6-9184-9DF86E7C3DAD> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvDSP.dylib - 0x7fff8791f000 - 0x7fff8794cfff libdispatch.dylib (501.40.12) /usr/lib/system/libdispatch.dylib - 0x7fff87961000 - 0x7fff87964fff libCoreVMClient.dylib (119.5) <560D70FB-709F-3030-96C9-F249FCB7DA6D> /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libCoreVMClient.dylib - 0x7fff87a2b000 - 0x7fff87a65ff7 com.apple.DebugSymbols (132 - 132) <23A42C53-B941-3871-9EE2-4C87A46005B5> /System/Library/PrivateFrameworks/DebugSymbols.framework/Versions/A/DebugSymbols - 0x7fff87a66000 - 0x7fff87a6fff7 com.apple.CommonAuth (4.0 - 2.0) <4B8673E1-3697-3FE2-8D30-AC7AC5D4F8BF> /System/Library/PrivateFrameworks/CommonAuth.framework/Versions/A/CommonAuth - 0x7fff87a9f000 - 0x7fff87abbff3 libresolv.9.dylib (60) /usr/lib/libresolv.9.dylib - 0x7fff87b6d000 - 0x7fff87c5fff7 libiconv.2.dylib (44) /usr/lib/libiconv.2.dylib - 0x7fff87c60000 - 0x7fff87c60fff com.apple.Accelerate.vecLib (3.10 - vecLib 3.10) <054DFE32-737D-3211-9A14-0FC5E1A880E3> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/vecLib - 0x7fff87dcf000 - 0x7fff87e76fff com.apple.LanguageModeling (1.0 - 1) <58C18A47-BDE7-3CBE-81C0-797029D170A1> /System/Library/PrivateFrameworks/LanguageModeling.framework/Versions/A/LanguageModeling - 0x7fff87e77000 - 0x7fff87f27fe7 libvMisc.dylib (563.5) <6D73C20D-D1C4-3BA5-809B-4B597C15AA86> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvMisc.dylib - 0x7fff87f5a000 - 0x7fff882aefff com.apple.Foundation (6.9 - 1259) <71A9D3A0-0B1F-3E3A-86F3-1486365A6EF2> /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation - 0x7fff88488000 - 0x7fff88488fff com.apple.CoreServices (728.12 - 728.12) /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices - 0x7fff884b9000 - 0x7fff8850afff com.apple.audio.CoreAudio (4.3.0 - 4.3.0) /System/Library/Frameworks/CoreAudio.framework/Versions/A/CoreAudio - 0x7fff8874d000 - 0x7fff88755ffb libsystem_dnssd.dylib (625.50.5) <4D10E12B-59B5-386F-82DA-326F18028F0A> /usr/lib/system/libsystem_dnssd.dylib - 0x7fff88756000 - 0x7fff8876cff7 libLinearAlgebra.dylib (1162.2) /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLinearAlgebra.dylib - 0x7fff8876d000 - 0x7fff8879efff com.apple.GSS (4.0 - 2.0) /System/Library/Frameworks/GSS.framework/Versions/A/GSS - 0x7fff88c4f000 - 0x7fff88d3efff libxml2.2.dylib (29.7) <32BBF51E-B084-3FC2-AE9C-C008BE84102B> /usr/lib/libxml2.2.dylib - 0x7fff88ef9000 - 0x7fff88f01fff libcopyfile.dylib (127) /usr/lib/system/libcopyfile.dylib - 0x7fff88f71000 - 0x7fff88fa7fff libssl.0.9.8.dylib (59.40.2) <523FEBFA-4BF7-3A69-83B7-164265BE7F4D> /usr/lib/libssl.0.9.8.dylib - 0x7fff88fa8000 - 0x7fff88faaff7 libRadiance.dylib (1450) /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libRadiance.dylib - 0x7fff893ee000 - 0x7fff89417ff7 libxslt.1.dylib (14.2) <6E8D0F06-9086-32D3-9D87-3870A1CE9E99> /usr/lib/libxslt.1.dylib - 0x7fff8949d000 - 0x7fff894b7ff3 liblzma.5.dylib (10) /usr/lib/liblzma.5.dylib - 0x7fff894b8000 - 0x7fff894dcfff libJPEG.dylib (1450) <1775E59E-D82C-3F7A-8E4F-B0C13F88F691> /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libJPEG.dylib - 0x7fff894dd000 - 0x7fff894e0fff com.apple.IOSurface (108.2.1 - 108.2.1) /System/Library/Frameworks/IOSurface.framework/Versions/A/IOSurface - 0x7fff89742000 - 0x7fff89747fff com.apple.TCC (1.0 - 1) /System/Library/PrivateFrameworks/TCC.framework/Versions/A/TCC - 0x7fff89b44000 - 0x7fff89b46fff libsystem_coreservices.dylib (19.2) <1B3F5AFC-FFCD-3ECB-8B9A-5538366FB20D> /usr/lib/system/libsystem_coreservices.dylib - 0x7fff89bdd000 - 0x7fff89bddff7 libunc.dylib (29) /usr/lib/system/libunc.dylib - 0x7fff89bde000 - 0x7fff89c09ffb libarchive.2.dylib (33.20.2) <6C370A21-63FD-3A68-B4B3-5333F24B770B> /usr/lib/libarchive.2.dylib - 0x7fff8a0fc000 - 0x7fff8a16bfff com.apple.SearchKit (1.4.0 - 1.4.0) /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/SearchKit.framework/Versions/A/SearchKit - 0x7fff8a170000 - 0x7fff8a174fff libcache.dylib (75) <9548AAE9-2AB7-3525-9ECE-A2A7C4688447> /usr/lib/system/libcache.dylib - 0x7fff8a1e1000 - 0x7fff8a1fdff7 libsystem_malloc.dylib (67.40.1) <5748E8B2-F81C-34C6-8B13-456213127678> /usr/lib/system/libsystem_malloc.dylib - 0x7fff8a245000 - 0x7fff8a245fff libmetal_timestamp.dylib (600.0.44.1) <6576F284-BACA-332A-A6E7-FA1C347636E3> /System/Library/PrivateFrameworks/GPUCompiler.framework/libmetal_timestamp.dylib - 0x7fff8a2d9000 - 0x7fff8a2dafff liblangid.dylib (122) <9CC4F0D1-5C51-3B69-BC8F-EE3A51FD0822> /usr/lib/liblangid.dylib - 0x7fff8a2db000 - 0x7fff8a2e9fff com.apple.opengl (12.1.0 - 12.1.0) /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL - 0x7fff8ae82000 - 0x7fff8aeabff7 libxpc.dylib (765.50.8) <54D1328E-054E-3DAA-89E2-375722F9D18F> /usr/lib/system/libxpc.dylib - 0x7fff8aeac000 - 0x7fff8b2a8fff libLAPACK.dylib (1162.2) <987E42B0-5108-3065-87F0-9DF7616A8A06> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libLAPACK.dylib - 0x7fff8b3a2000 - 0x7fff8b648ff7 com.apple.CoreData (120 - 641.3) /System/Library/Frameworks/CoreData.framework/Versions/A/CoreData - 0x7fff8b649000 - 0x7fff8b678ffb libsystem_m.dylib (3105) <08E1A4B2-6448-3DFE-A58C-ACC7335BE7E4> /usr/lib/system/libsystem_m.dylib - 0x7fff8be57000 - 0x7fff8be6efff libmarisa.dylib (4) /usr/lib/libmarisa.dylib - 0x7fff8c64b000 - 0x7fff8c778ff3 com.apple.CoreText (352.0 - 494.11) <08E8640E-6602-3A00-BC28-94235FD311B4> /System/Library/Frameworks/CoreText.framework/Versions/A/CoreText - 0x7fff8c794000 - 0x7fff8c7e9fff com.apple.AE (701 - 701) /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/AE - 0x7fff8c83b000 - 0x7fff8c83dfff com.apple.loginsupport (1.0 - 1) <9B2F5F9B-ED38-313F-B798-D2B667BCD6B5> /System/Library/PrivateFrameworks/login.framework/Versions/A/Frameworks/loginsupport.framework/Versions/A/loginsupport - 0x7fff8cb98000 - 0x7fff8cb9bfff libsystem_sandbox.dylib (460.50.4) <150A9D3D-F69E-32F7-8C7B-8E72CAAFF7E4> /usr/lib/system/libsystem_sandbox.dylib - 0x7fff8cb9c000 - 0x7fff8cb9cff7 libkeymgr.dylib (28) <8371CE54-5FDD-3CE9-B3DF-E98C761B6FE0> /usr/lib/system/libkeymgr.dylib - 0x7fff8cbff000 - 0x7fff8cc00fff com.apple.TrustEvaluationAgent (2.0 - 25) <0239494E-FEFE-39BC-9FC7-E251BA5128F1> /System/Library/PrivateFrameworks/TrustEvaluationAgent.framework/Versions/A/TrustEvaluationAgent - 0x7fff8cc01000 - 0x7fff8cc01fff libOpenScriptingUtil.dylib (169.1) /usr/lib/libOpenScriptingUtil.dylib - 0x7fff8d16a000 - 0x7fff8d16dffb libdyld.dylib (360.22) /usr/lib/system/libdyld.dylib - 0x7fff8d245000 - 0x7fff8d246fff libffi.dylib (18.1) <5BA9612C-747E-33CE-9DB1-3C01ECF3041D> /usr/lib/libffi.dylib - 0x7fff8d2e2000 - 0x7fff8d378fff com.apple.ColorSync (4.9.0 - 4.9.0) <8FC37E20-6579-3CB2-9D49-BC39FC38DF87> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ColorSync.framework/Versions/A/ColorSync - 0x7fff8d6fd000 - 0x7fff8d771ff7 com.apple.Heimdal (4.0 - 2.0) <5D365381-8B5E-3259-8867-FC4A7D307BDE> /System/Library/PrivateFrameworks/Heimdal.framework/Versions/A/Heimdal - 0x7fff8d772000 - 0x7fff8d773fff libDiagnosticMessagesClient.dylib (100) <4243B6B4-21E9-355B-9C5A-95A216233B96> /usr/lib/libDiagnosticMessagesClient.dylib - 0x7fff8d7e3000 - 0x7fff8d808ff7 libPng.dylib (1450) /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libPng.dylib - 0x7fff8ebb0000 - 0x7fff8ed56ff7 com.apple.audio.toolbox.AudioToolbox (1.13 - 1.13) <082319FC-59F2-3D36-AC9B-94759724E302> /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox - 0x7fff8f074000 - 0x7fff8f090ff7 libextension.dylib (78) /usr/lib/libextension.dylib - 0x7fff8f127000 - 0x7fff8f137fff libbsm.0.dylib (34) <7E14504C-A8B0-3574-B6EB-5D5FABC72926> /usr/lib/libbsm.0.dylib - 0x7fff8f177000 - 0x7fff903c5fe7 com.apple.CoreGraphics (1.600.0 - 957) /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics - 0x7fff903c6000 - 0x7fff904eafff libsqlite3.dylib (216.4) <280D67B8-F93D-3587-A146-19F36C817548> /usr/lib/libsqlite3.dylib - 0x7fff90521000 - 0x7fff9055fff7 libGLImage.dylib (12.1) /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLImage.dylib - 0x7fff90622000 - 0x7fff90667ff7 com.apple.coreservices.SharedFileList (24.4 - 24.5) <1D2AD77B-778F-3253-A295-3D0A32A8121C> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/SharedFileList.framework/Versions/A/SharedFileList - 0x7fff90709000 - 0x7fff90717fff libxar.1.dylib (302) <03207F66-2C4A-3DBD-8D81-70F4C85903C4> /usr/lib/libxar.1.dylib - 0x7fff90e64000 - 0x7fff90e73ffb com.apple.LangAnalysis (1.7.0 - 1.7.0) <18D21123-A3E7-3851-974A-08E5D4540475> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/LangAnalysis.framework/Versions/A/LangAnalysis - 0x7fff90f0b000 - 0x7fff90f57fff com.apple.print.framework.PrintCore (11.2 - 472.2) <5AE8AA6B-CE09-397D-B0D4-0F9CCBF1F77D> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/PrintCore.framework/Versions/A/PrintCore - 0x7fff90f96000 - 0x7fff90fbafff com.apple.MultitouchSupport.framework (304.12 - 304.12) <65CB7653-EACD-3ADB-ABB6-2E0671708301> /System/Library/PrivateFrameworks/MultitouchSupport.framework/Versions/A/MultitouchSupport - 0x7fff91154000 - 0x7fff91165ff7 libsystem_trace.dylib (201.10.3) /usr/lib/system/libsystem_trace.dylib - 0x7fff911f6000 - 0x7fff91254fff com.apple.SystemConfiguration (1.14 - 1.14) /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/SystemConfiguration - 0x7fff919db000 - 0x7fff919f2ff7 libsystem_coretls.dylib (83.40.5) /usr/lib/system/libsystem_coretls.dylib - 0x7fff919f3000 - 0x7fff919f3fff com.apple.ApplicationServices (48 - 48) /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices - 0x7fff91b86000 - 0x7fff91bd2ffb com.apple.HIServices (1.22 - 550) <6B76B41C-CF5A-34C4-89F4-EFD7CA3D1C9D> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/HIServices.framework/Versions/A/HIServices - 0x7fff91c23000 - 0x7fff91c64ff7 libGLU.dylib (12.1) /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGLU.dylib - 0x7fff91c65000 - 0x7fff91c96ff7 libncurses.5.4.dylib (46) /usr/lib/libncurses.5.4.dylib - 0x7fff91ef6000 - 0x7fff91f49ff7 libc++.1.dylib (120.1) <8FC3D139-8055-3498-9AC5-6467CB7F4D14> /usr/lib/libc++.1.dylib - 0x7fff91f8c000 - 0x7fff91f8eff7 libquarantine.dylib (80) <0F4169F0-0C84-3A25-B3AE-E47B3586D908> /usr/lib/system/libquarantine.dylib - 0x7fff91fc3000 - 0x7fff91fddfff com.apple.Kerberos (3.0 - 1) <1B4744BF-E5AE-38E2-AA56-E22D3270F2E8> /System/Library/Frameworks/Kerberos.framework/Versions/A/Kerberos - 0x7fff9233c000 - 0x7fff9269ef3f libobjc.A.dylib (680) <7489D2D6-1EFD-3414-B18D-2AECCCC90286> /usr/lib/libobjc.A.dylib - 0x7fff926df000 - 0x7fff926f0fff libcmph.dylib (6) /usr/lib/libcmph.dylib - 0x7fff92756000 - 0x7fff9279bff3 libFontRegistry.dylib (155.2) /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/Resources/libFontRegistry.dylib - 0x7fff927b9000 - 0x7fff927c4ff7 libcommonCrypto.dylib (60075.50.1) <93732261-34B4-3914-B7A2-90A81A182DBA> /usr/lib/system/libcommonCrypto.dylib - 0x7fff927c5000 - 0x7fff927c6ffb libremovefile.dylib (41) <552EF39E-14D7-363E-9059-4565AC2F894E> /usr/lib/system/libremovefile.dylib - 0x7fff93126000 - 0x7fff93131ff7 libChineseTokenizer.dylib (16) <79B8C67A-3061-3C78-92CD-4650719E68D4> /usr/lib/libChineseTokenizer.dylib - 0x7fff93132000 - 0x7fff9313cfff com.apple.NetAuth (6.0 - 6.0) /System/Library/PrivateFrameworks/NetAuth.framework/Versions/A/NetAuth - 0x7fff931b3000 - 0x7fff93240fff libsystem_c.dylib (1082.50.1) /usr/lib/system/libsystem_c.dylib - 0x7fff93250000 - 0x7fff935e5fdb com.apple.vImage (8.0 - 8.0) <4BAC9B6F-7482-3580-8787-AB0A5B4D331B> /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vImage.framework/Versions/A/vImage - 0x7fff9394a000 - 0x7fff939bffff com.apple.framework.IOKit (2.0.2 - 1179.50.2) /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit - 0x7fff939e9000 - 0x7fff93a02fff com.apple.CFOpenDirectory (10.11 - 194) <11F95672-55E0-3F9D-9171-5E8C56AEE948> /System/Library/Frameworks/OpenDirectory.framework/Versions/A/Frameworks/CFOpenDirectory.framework/Versions/A/CFOpenDirectory - 0x7fff93ad9000 - 0x7fff93ae1fff libGFXShared.dylib (12.1) <5A0C2493-200C-30BE-97D5-8E8C0B8E604D> /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGFXShared.dylib - 0x7fff93ae2000 - 0x7fff93aeafff libsystem_networkextension.dylib (385.40.36) <66095DC7-6539-38F2-95EE-458F15F6D014> /usr/lib/system/libsystem_networkextension.dylib - 0x7fff93d66000 - 0x7fff93d83ff7 com.apple.AppleVPAFramework (2.1.2 - 2.1.2) <41378C0B-B56A-3A73-9BD0-E06FA1F87B8C> /System/Library/PrivateFrameworks/AppleVPA.framework/Versions/A/AppleVPA - 0x7fff94496000 - 0x7fff9449efff com.apple.NetFS (6.0 - 4.0) <842A5346-24C3-3F22-9ECF-E586A10EA1F2> /System/Library/Frameworks/NetFS.framework/Versions/A/NetFS - 0x7fff9449f000 - 0x7fff944a4ff7 libmacho.dylib (875.1) <318264FA-58F1-39D8-8285-1F6254EE410E> /usr/lib/system/libmacho.dylib - 0x7fff944a5000 - 0x7fff944cefff libsystem_info.dylib (477.50.4) /usr/lib/system/libsystem_info.dylib - 0x7fff945f8000 - 0x7fff9466ffeb libcorecrypto.dylib (335.50.1) /usr/lib/system/libcorecrypto.dylib - 0x7fff94672000 - 0x7fff9467afef libsystem_platform.dylib (74.40.2) <29A905EF-6777-3C33-82B0-6C3A88C4BA15> /usr/lib/system/libsystem_platform.dylib - 0x7fff947a8000 - 0x7fff94835dd7 com.apple.AppleJPEG (1.0 - 1) <558ACADA-C41F-3EEF-82A0-C2D7B13C5428> /System/Library/PrivateFrameworks/AppleJPEG.framework/Versions/A/AppleJPEG - 0x7fff9490b000 - 0x7fff94914ff7 libsystem_pthread.dylib (138.10.4) <3DD1EF4C-1D1B-3ABF-8CC6-B3B1CEEE9559> /usr/lib/system/libsystem_pthread.dylib - 0x7fff94915000 - 0x7fff94923ff7 libbz2.1.0.dylib (38) <28E54258-C0FE-38D4-AB76-1734CACCB344> /usr/lib/libbz2.1.0.dylib - 0x7fff949d8000 - 0x7fff949e4fff com.apple.speech.synthesis.framework (5.4.12 - 5.4.12) <71DA00B8-5EA2-326B-8814-59DB25512F65> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/SpeechSynthesis.framework/Versions/A/SpeechSynthesis - 0x7fff949e5000 - 0x7fff94a43fff com.apple.CoreServices.OSServices (728.12 - 728.12) <776EBD4F-7052-377F-A70D-E2FDBD465A5E> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/OSServices.framework/Versions/A/OSServices - 0x7fff94c55000 - 0x7fff94c6dfef libcompression.dylib (28) /usr/lib/libcompression.dylib - 0x7fff94d75000 - 0x7fff94d81ff7 com.apple.OpenDirectory (10.11 - 194) <31A67AD5-5CC2-350A-96D7-821DF4BC4196> /System/Library/Frameworks/OpenDirectory.framework/Versions/A/OpenDirectory - 0x7fff94dd2000 - 0x7fff94de9ff7 libsystem_asl.dylib (323.50.1) <41F8E11F-1BD0-3F1D-BA3A-AA1577ED98A9> /usr/lib/system/libsystem_asl.dylib - 0x7fff95efc000 - 0x7fff96372fff com.apple.CoreFoundation (6.9 - 1258.1) <943A1383-DA6A-3DC0-ABCD-D9AEB3D0D34D> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation - 0x7fff96a8b000 - 0x7fff96a8cffb libSystem.B.dylib (1226.10.1) /usr/lib/libSystem.B.dylib - 0x7fff96b0b000 - 0x7fff96b67fff libTIFF.dylib (1450) <14EB7C03-7DDA-3276-BAC5-D597913AC9C4> /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libTIFF.dylib - 0x7fff9788c000 - 0x7fff97900ff3 com.apple.securityfoundation (6.0 - 55126) <130656AE-2711-3914-8736-D8B021C93FE0> /System/Library/Frameworks/SecurityFoundation.framework/Versions/A/SecurityFoundation - 0x7fff97901000 - 0x7fff9796fff7 com.apple.ApplicationServices.ATS (377 - 394.4) <9779E916-0788-3CAC-B1EC-F68BCB12A2B6> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/ATS - 0x7fff97970000 - 0x7fff979c1ff7 libcups.2.dylib (435.2) <91584A40-214D-33E8-A613-CE22289037C8> /usr/lib/libcups.2.dylib - 0x7fff97acb000 - 0x7fff97ad4ff3 libsystem_notify.dylib (150.40.1) /usr/lib/system/libsystem_notify.dylib - 0x7fff97c56000 - 0x7fff97c58fff libCVMSPluginSupport.dylib (12.1) /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libCVMSPluginSupport.dylib - 0x7fff97c59000 - 0x7fff97c5cff7 libCoreFSCache.dylib (119.5) <2389D7DA-B8EF-3EB4-AAAF-FBEDE01CDECA> /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libCoreFSCache.dylib - 0x7fff97d7b000 - 0x7fff97d80ff7 libheimdal-asn1.dylib (453.40.10) <981DE40B-FA16-36F7-BE92-8C8A115D6CD9> /usr/lib/libheimdal-asn1.dylib - 0x7fff97d81000 - 0x7fff97d9fffb libedit.3.dylib (43) <1D3E3152-4001-3C19-B56A-7543F1BBA47C> /usr/lib/libedit.3.dylib - 0x7fff987b2000 - 0x7fff989bffff libicucore.A.dylib (551.51.3) <5BC80F94-C90D-3175-BD96-FF1DC222EC9C> /usr/lib/libicucore.A.dylib - 0x7fff989c0000 - 0x7fff989c0ff7 liblaunch.dylib (765.50.8) <834ED605-5114-3641-AA4D-ECF31B801C50> /usr/lib/system/liblaunch.dylib - 0x7fff98b55000 - 0x7fff98b8ffff com.apple.QD (3.12 - 302) <0FE53180-2895-3D14-A1E7-F82DE1D106E1> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/QD.framework/Versions/A/QD - 0x7fff98be1000 - 0x7fff98be1fff libenergytrace.dylib (10.40.1) <0A491CA7-3451-3FD5-999A-58AB4362682B> /usr/lib/libenergytrace.dylib - 0x7fff98c36000 - 0x7fff98c41fff libGL.dylib (12.1) <70D51643-04AC-3400-8F11-A6FC25985289> /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib - 0x7fff98c77000 - 0x7fff98ca0fff libc++abi.dylib (125) /usr/lib/libc++abi.dylib - 0x7fff98cb0000 - 0x7fff98cdfff7 com.apple.DictionaryServices (1.2 - 250.3) <30250542-CBAA-39C1-91AA-B57A5DE17594> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/DictionaryServices.framework/Versions/A/DictionaryServices - 0x7fff98ce0000 - 0x7fff98ce7ff7 libcompiler_rt.dylib (62) /usr/lib/system/libcompiler_rt.dylib - 0x7fff98d10000 - 0x7fff98fa6fff libmecabra.dylib (696.5) /usr/lib/libmecabra.dylib - 0x7fff99bdb000 - 0x7fff99bdbfff com.apple.Accelerate (1.10 - Accelerate 1.10) <185EC96A-5AF0-3620-A4ED-4D3654D25B39> /System/Library/Frameworks/Accelerate.framework/Versions/A/Accelerate - 0x7fff99bdc000 - 0x7fff99bddfff libsystem_blocks.dylib (65) <1244D9D5-F6AA-35BB-B307-86851C24B8E5> /usr/lib/system/libsystem_blocks.dylib - 0x7fff99d2d000 - 0x7fff99e94fff libBLAS.dylib (1162.2) /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib - 0x7fff99f74000 - 0x7fff9a259ffb com.apple.CoreServices.CarbonCore (1136.2 - 1136.2) <2DBAFC9A-6CD6-351D-B1F4-87D81AA6D640> /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/CarbonCore.framework/Versions/A/CarbonCore - 0x7fff9a2cc000 - 0x7fff9a312ff7 libauto.dylib (186) <999E610F-41FC-32A3-ADCA-5EC049B65DFB> /usr/lib/libauto.dylib - 0x7fff9a359000 - 0x7fff9a35ffff com.apple.IOAccelerator (205.10 - 205.10) /System/Library/PrivateFrameworks/IOAccelerator.framework/Versions/A/IOAccelerator - 0x7fff9a40b000 - 0x7fff9a410ff3 libunwind.dylib (35.3) /usr/lib/system/libunwind.dylib - 0x7fff9a833000 - 0x7fff9a923fff libJP2.dylib (1450) /System/Library/Frameworks/ImageIO.framework/Versions/A/Resources/libJP2.dylib - 0x7fff9ab94000 - 0x7fff9aba5fff libSparseBLAS.dylib (1162.2) /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libSparseBLAS.dylib - 0x7fff9abea000 - 0x7fff9ac8afff com.apple.Metadata (10.7.0 - 972.34) /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Metadata - 0x7fff9af5b000 - 0x7fff9af79ff7 libsystem_kernel.dylib (3248.50.21) <78E54D59-D2B0-3F54-9A4A-0A68D671F253> /usr/lib/system/libsystem_kernel.dylib - 0x7fff9b073000 - 0x7fff9b159ff7 libcrypto.0.9.8.dylib (59.40.2) <2486D801-C756-3488-B519-1AA6807E8948> /usr/lib/libcrypto.0.9.8.dylib - 0x7fff9b3c1000 - 0x7fff9b4bdff7 libFontParser.dylib (158.6) <267A9AE4-4138-3112-8D73-BDFDC96568FF> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/Frameworks/ATS.framework/Versions/A/Resources/libFontParser.dylib - 0x7fff9b4c2000 - 0x7fff9b4ddff7 libCRFSuite.dylib (34) <078B4CD8-6A8C-3067-B2BA-0C2A0BAB8AC3> /usr/lib/libCRFSuite.dylib - 0x7fff9b625000 - 0x7fff9b8acff3 com.apple.CFNetwork (760.5.1 - 760.5.1) /System/Library/Frameworks/CFNetwork.framework/Versions/A/CFNetwork - 0x7fff9b928000 - 0x7fff9baeefe7 com.apple.ImageIO.framework (3.3.0 - 1450) <18ABA1F4-43EC-3990-9777-C91FD3D6AF71> /System/Library/Frameworks/ImageIO.framework/Versions/A/ImageIO - 0x7fff9bdf0000 - 0x7fff9be24ff7 com.apple.CoreVideo (1.8 - 191.3) <1AA24A1B-CB84-3F6B-B6DE-11494542649C> /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo - 0x7fff9bf5b000 - 0x7fff9bf60fff com.apple.DiskArbitration (2.7 - 2.7) /System/Library/Frameworks/DiskArbitration.framework/Versions/A/DiskArbitration - 0x7fff9bf61000 - 0x7fff9c086fff com.apple.LaunchServices (728.12 - 728.12) /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/LaunchServices - 0x7fff9c0e4000 - 0x7fff9c0effff libkxld.dylib (3248.50.21) <99195052-038E-3490-ACF8-76F9AC43897E> /usr/lib/system/libkxld.dylib - 0x7fff9d382000 - 0x7fff9d386fff libpam.2.dylib (20) /usr/lib/libpam.2.dylib - 0x7fff9d4b7000 - 0x7fff9d4c8ff7 libz.1.dylib (61.20.1) /usr/lib/libz.1.dylib - 0x7fff9d4ca000 - 0x7fff9d4f8ff7 com.apple.CoreServicesInternal (248.2 - 248.2) <6E111F0A-D7F1-3738-ADE7-CF983BD4EC8B> /System/Library/PrivateFrameworks/CoreServicesInternal.framework/Versions/A/CoreServicesInternal - 0x7fff9d4f9000 - 0x7fff9d4fbff7 libsystem_configuration.dylib (802.40.13) <3DEB7DF9-6804-37E1-BC83-0166882FF0FF> /usr/lib/system/libsystem_configuration.dylib - 0x7fff9d5ab000 - 0x7fff9d5acfff libsystem_secinit.dylib (20) <32B1A8C6-DC84-3F4F-B8CE-9A52B47C3E6B> /usr/lib/system/libsystem_secinit.dylib - -External Modification Summary: - Calls made by other processes targeting this process: - task_for_pid: 11 - thread_create: 0 - thread_set_state: 0 - Calls made by this process: - task_for_pid: 0 - thread_create: 0 - thread_set_state: 0 - Calls made by all processes on this machine: - task_for_pid: 199747 - thread_create: 0 - thread_set_state: 9181 - -VM Region Summary: -ReadOnly portion of Libraries: Total=231.3M resident=0K(0%) swapped_out_or_unallocated=231.3M(100%) -Writable regions: Total=112.3M written=0K(0%) resident=0K(0%) swapped_out=0K(0%) unallocated=112.3M(100%) - - VIRTUAL REGION -REGION TYPE SIZE COUNT (non-coalesced) -=========== ======= ======= -Activity Tracing 2048K 2 -Dispatch continuations 16.0M 2 -Kernel Alloc Once 4K 2 -MALLOC 75.5M 22 -MALLOC guard page 32K 7 -STACK GUARD 56.0M 9 -Stack 11.1M 16 -VM_ALLOCATE 7448K 21 -__DATA 11.8M 183 -__LINKEDIT 101.5M 32 -__TEXT 129.8M 182 -__UNICODE 552K 2 -mapped file 47.0M 49 -shared memory 324K 9 -=========== ======= ======= -TOTAL 458.9M 524 - -Model: MacBookPro11,5, BootROM MBP114.0172.B09, 4 processors, Intel Core i7, 2,5 GHz, 16 GB, SMC 2.30f2 -Graphics: AMD Radeon R9 M370X, AMD Radeon R9 M370X, PCIe, 2048 MB -Graphics: Intel Iris Pro, Intel Iris Pro, Built-In -Memory Module: BANK 0/DIMM0, 8 GB, DDR3, 1600 MHz, 0x80AD, 0x484D54343147533642465238412D50422020 -Memory Module: BANK 1/DIMM0, 8 GB, DDR3, 1600 MHz, 0x80AD, 0x484D54343147533642465238412D50422020 -AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0x152), Broadcom BCM43xx 1.0 (7.21.95.175.1a6) -Bluetooth: Version 4.4.5f3 17904, 3 services, 27 devices, 1 incoming serial ports -Network Service: Wi-Fi, AirPort, en0 -Serial ATA Device: APPLE SSD SM0512G, 500,28 GB -USB Device: USB 3.0 Bus -USB Device: Card Reader -USB Device: Apple Internal Keyboard / Trackpad -USB Device: Bluetooth USB Host Controller -Thunderbolt Bus: MacBook Pro, Apple Inc., 27.1 diff --git a/callcount.yap b/callcount.yap deleted file mode 100644 index f8be21661..000000000 --- a/callcount.yap +++ /dev/null @@ -1,152 +0,0 @@ -/************************************************************************* -* * -* YAP Prolog * -* * -* Yap Prolog was developed at NCCUP - Universidade do Porto * -* * -* Copyright L.Damas, V.S.Costa and Universidade do Porto 1985-1997 * -* * -************************************************************************** -* * -* File: callcount.yap * -* Last rev: 8/2/02 * -* mods: * -* comments: Some profiling predicates available in yap * -* * -*************************************************************************/ - -%% @{ - -/** @defgroup Profiling Profiling Prolog Programs -@ingroup extensions - -YAP includes two profilers. The count profiler keeps information on the -number of times a predicate was called. This information can be used to -detect what are the most commonly called predicates in the program. The -count profiler can be compiled by setting YAP's flag profiling -to `on`. The time-profiler is a `gprof` profiler, and counts -how many ticks are being spent on specific predicates, or on other -system functions such as internal data-base accesses or garbage collects. - -The YAP profiling sub-system is currently under -development. Functionality for this sub-system will increase with newer -implementation. - - - */ - -%% @{ - -/** @defgroup Call_Counting Counting Calls -@ingroup Profiling - -Predicates compiled with YAP's flag call_counting set to -`on` update counters on the numbers of calls and of -retries. Counters are actually decreasing counters, so that they can be -used as timers. Three counters are available: - -+ `calls`: number of predicate calls since execution started or since -system was reset; -+ `retries`: number of retries for predicates called since -execution started or since counters were reset; -+ `calls_and_retries`: count both on predicate calls and -retries. - -These counters can be used to find out how many calls a certain -goal takes to execute. They can also be used as timers. - -The code for the call counters piggybacks on the profiling -code. Therefore, activating the call counters also activates the profiling -counters. - -These are the predicates that access and manipulate the call counters. -*/ - -:- system_module( '$_callcount', [call_count/3, - call_count_data/3, - call_count_reset/0], []). - -:- use_system_module( '$_errors', ['$do_error'/2]). - - -/** @pred call_count_data(- _Calls_, - _Retries_, - _CallsAndRetries_) - - -Give current call count data. The first argument gives the current value -for the _Calls_ counter, next the _Retries_ counter, and last -the _CallsAndRetries_ counter. - -*/ -call_count_data(Calls, Retries, Both) :- - '$call_count_info'(Calls, Retries, Both). - -/** @pred call_count_reset - - -Reset call count counters. All timers are also reset. - -*/ -call_count_reset :- - '$call_count_reset'. - -/** @pred call_count(? _CallsMax_, ? _RetriesMax_, ? _CallsAndRetriesMax_) - - -Set call counters as timers. YAP will generate an exception -if one of the instantiated call counters decreases to 0: - -+ _CallsMax_ - - throw the exception `call_counter` when the -counter `calls` reaches 0; - -+ _RetriesMax_ - - throw the exception `retry_counter` when the -counter `retries` reaches 0; - -+ _CallsAndRetriesMax_ - - throw the exception -`call_and_retry_counter` when the counter `calls_and_retries` -reaches 0. - - YAP will ignore counters that are called with unbound arguments. - -Next, we show a simple example of how to use call counters: - -~~~~~{.prolog} - ?- yap_flag(call_counting,on), [-user]. l :- l. end_of_file. yap_flag(call_counting,off). - -yes - -yes - ?- catch((call_count(10000,_,_),l),call_counter,format("limit_exceeded.~n",[])). - -limit_exceeded. - -yes -~~~~~ -Notice that we first compile the looping predicate `l/0` with -call_counting `on`. Next, we catch/3 to handle an -exception when `l/0` performs more than 10000 reductions. - - - */ -call_count(Calls, Retries, Both) :- - '$check_if_call_count_on'(Calls, CallsOn), - '$check_if_call_count_on'(Retries, RetriesOn), - '$check_if_call_count_on'(Both, BothOn), - '$call_count_set'(Calls, CallsOn, Retries, RetriesOn, Both, BothOn). - -'$check_if_call_count_on'(Calls, 1) :- integer(Calls), !. -'$check_if_call_count_on'(Calls, 0) :- var(Calls), !. -'$check_if_call_count_on'(Calls, A) :- - '$do_error'(type_error(integer,Calls),call_count(A)). - -%% @} - -/** -@} -*/ - diff --git a/cmake/Config.cmake b/cmake/Config.cmake index 86ce9e31f..a3f476fc9 100644 --- a/cmake/Config.cmake +++ b/cmake/Config.cmake @@ -15,13 +15,15 @@ include(TestBigEndian) include(GetGitRevisionDescription) # modern systems do this. + set(MALLOC_T "void *") OPTION(WITH_SYSTEM_MALLOC "use malloc to allocate memory" ON) OPTION(WITH_DL_MALLOC "use malloc to allocate memory" OFF) OPTION(WITH_YAP_MALLOC - "use malloc to allocate memory" OFF) + "use malloc to allocate mem + ory" OFF) if (WITH_SYSTEM_MALLOC) set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS USE_SYSTEM_MALLOC=1) @@ -144,6 +146,7 @@ endif (HAVE_LIBDL) if (WIN32) check_library_exists(comdlg32 FindText "" HAVE_LIBCOMDLG32) if (HAVE_LIBCOMDLG32) + set(EXTRALIBS ${EXTRALIBS} comdlg32) endif (HAVE_LIBCOMDLG32) check_library_exists(msvcrt strtok "" HAVE_LIBMSCRT) @@ -215,6 +218,7 @@ if (HAVE_LIBPTHREAD) endif (HAVE_LIBPTHREAD) + check_library_exists(unicode main "" HAVE_LIBUNICODE) if (HAVE_LIBUNICODE) set(EXTRALIBS ${EXTRALIBS} unicode) @@ -261,10 +265,8 @@ check_symbol_exists(flsll HAVE_FLSLL) check_function_exists(fmemopen HAVE_FMEMOPEN) check_function_exists(fpclass HAVE_FPCLASS) check_function_exists(ftime HAVE_FTIME) -check_function_exists(ftruncate HAVE_FTRUNCATE) -check_function_exists(funopen HAVE_FUNOPEN) -check_function_exists(gcc HAVE_GCC) -check_function_exists(getcwd HAVE_GETCWD) +check_function_exists(ftru +wd HAVE_GETCWD) check_function_exists(getenv HAVE_GETENV) check_function_exists(getexecname HAVE_GETEXECNAME) check_function_exists(gethostbyname HAVE_GETHOSTBYNAME) @@ -321,7 +323,8 @@ check_function_exists(setlocale HAVE_SETLOCALE) check_function_exists(setsid HAVE_SETSID) check_function_exists(shmat HAVE_SHMAT) check_function_exists(sigaction HAVE_SIGACTION) -check_symbol_exists(SIGFPE signal.h HAVE_SIGFPE) +check_symbol_exists(SI +GFPE signal.h HAVE_SIGFPE) check_function_exists(siggetmask HAVE_SIGGETMASK) check_symbol_exists(SIGINFO signal.h HAVE_SIGINFO) check_function_exists(siginterrupt HAVE_SIGINTERRUPT) @@ -396,5 +399,13 @@ configure_file(${CMAKE_CURRENT_LIST_DIR}/../YapTermConfig.h.cmake configure_file(${CMAKE_CURRENT_LIST_DIR}/../config.h.cmake ${CMAKE_BINARY_DIR}/config.h) configure_file(${CMAKE_CURRENT_LIST_DIR}/../GitSHA1.c.in GitSHA1.c @ONLY) - configure_file(${CMAKE_CURRENT_LIST_DIR}/../os/YapIOConfig.h.cmake ${CMAKE_BINARY_DIR}/os/YapIOConfig.h) + +check_include_files( "stdio.h;cudd.h" HAVE_CTYPE_HUDD_H ) + +check_include_files( "stdio.h;cuddI.h" HAVE_CUDD_H ) +check_include_files( "cudd.h;cuddInt.h" HAVE_CUDDINT_H ) +check_include_files( "stdio.h;cudd/cudd.h" HAVE_CUDD_CUDD_H ) +check_include_files( "stdio.h;cudd/cuddInt.h" HAVE_CUDD_CUDDINT_H ) +configure_file (cmake/cudd_config.h.cmake + "${CMAKE_CURRENT_BINARY_DIR}/cudd_config.h" ) diff --git a/cmake/cudd.cmake b/cmake/cudd.cmake index de2d30096..7345e360d 100644 --- a/cmake/cudd.cmake +++ b/cmake/cudd.cmake @@ -1,5 +1,5 @@ - + option (WITH_CUDD "BDD CUDD package" ON) if (WITH_CUDD) @@ -18,10 +18,7 @@ if (CUDD_FOUND) set( CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${CUDD_INCLUDE_DIR} ) -check_include_files( "stdio.h;cudd.h" HAVE_CUDD_H ) -check_include_files( "stdio.h;cudd/cudd.h" HAVE_CUDD_CUDD_H ) -check_include_files( "cuddInt.h" HAVE_CUDDINT_H ) -check_include_files( "cudd/cuddInt.h" HAVE_CUDD_CUDDINT_H ) endif (CUDD_FOUND) + endif(WITH_CUDD) diff --git a/packages/bdd/cudd_config.h.cmake b/cmake/cudd_config.h.cmake similarity index 100% rename from packages/bdd/cudd_config.h.cmake rename to cmake/cudd_config.h.cmake diff --git a/example.py b/example.py deleted file mode 100644 index 92e2246d6..000000000 --- a/example.py +++ /dev/null @@ -1,14 +0,0 @@ -# python commands - -import yap - -engine = yap.YAPEngine(); -# engine = yap.YAPEngine(yap.YAPParams()); - -while True: - s = raw_input("Prolog Query: ") - q = engine.query(s) - print "success" - while q.next(): - ar = q.namedVars(); - print ar diff --git a/heap_top_ b/heap_top_ deleted file mode 100644 index e69de29bb..000000000 diff --git a/include/YapError.h b/include/YapError.h index 9c68dbcce..a9ea6810f 100644 --- a/include/YapError.h +++ b/include/YapError.h @@ -42,7 +42,7 @@ struct yami *Yap_Error__(const char *file, const char *function, int lineno, yap_error_number err, YAP_Term wheret, ...); void Yap_ThrowError__(const char *file, const char *function, int lineno, - yap_error_number err, YAP_Term wheret, int code, ...) __attribute__ ((noreturn)); + yap_error_number err, YAP_Term wheret, ...) __attribute__ ((noreturn)); #define Yap_NilError(id, ...) \ @@ -51,8 +51,8 @@ void Yap_ThrowError__(const char *file, const char *function, int lineno, #define Yap_Error(id, inp, ...) \ Yap_Error__(__FILE__, __FUNCTION__, __LINE__, id, inp, __VA_ARGS__) -#define Yap_ThrowError(id, inp, code, ...) \ -Yap_ThrowError__(__FILE__, __FUNCTION__, __LINE__, id, inp, code, __VA_ARGS__) +#define Yap_ThrowError(id, inp, ...) \ +Yap_ThrowError__(__FILE__, __FUNCTION__, __LINE__, id, inp, __VA_ARGS__) #ifdef YAP_TERM_H /** diff --git a/libYap.cmake b/libYap.cmake index 4a1c0df8c..5cdddcc92 100644 --- a/libYap.cmake +++ b/libYap.cmake @@ -57,7 +57,7 @@ ENDIF("${isSystemDir}" STREQUAL "-1") include_directories (H H/generated include os OPTYap utf8proc JIT/HPP) -include_directories (BEFORE ${CMAKE_BINARY_DIR}) +include_directories (BEFORE ${CMAKE_BINARY_DIR} ${CMAKE_TOP_BINARY_DIR}) if (ANDROID) include_directories (CXX ${CMAKE_SOURCE_DIR}/../generated/src/jni) diff --git a/os/fmem.c b/os/fmem.c index a2cf28a85..6362602c7 100644 --- a/os/fmem.c +++ b/os/fmem.c @@ -110,11 +110,10 @@ static char SccsId[] = "%W% %G%"; bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, size_t nchars) { FILE *f; - stream_flags_t flags; // like any file stream. st->file = f = fmemopen((void *)buf, nchars, "r"); - flags = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f; + st->status = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f; Yap_DefaultStreamOps(st); return true; } diff --git a/os/readterm.c b/os/readterm.c index 34c63ae62..bc9c9cc7f 100644 --- a/os/readterm.c +++ b/os/readterm.c @@ -1211,26 +1211,23 @@ static Int style_checker(USES_REGS1) { } X_API Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp, - int prio, Term *bindings) { + int prio, Term bindings) { CACHE_REGS - Term bvar = MkVarTerm(), ctl; - yhandle_t sl; - int lvl = push_text_stack(); + Term ctl; + int lvl = push_text_stack(); if (len == 0) { Term rval = TermEof; if (rval && bindings) { - *bindings = TermNil; + rval = Yap_unify(bindings , TermNil ); } pop_text_stack(lvl); return rval; } if (bindings) { - ctl = Yap_MkApplTerm(Yap_MkFunctor(AtomVariableNames, 1), 1, &bvar); - sl = Yap_PushHandle(bvar); + ctl = Yap_MkApplTerm(Yap_MkFunctor(AtomVariableNames, 1), 1, &bindings); } else { ctl = TermNil; - sl = 0; } Term rval; @@ -1239,9 +1236,6 @@ X_API Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp, rval = Yap_read_term(stream, ctl, 3); Yap_CloseStream(stream); UNLOCK(GLOBAL_Stream[stream].streamlock); - if (rval && bindings) { - *bindings = Yap_PopHandle(sl); - } pop_text_stack(lvl); return rval; } @@ -1290,107 +1284,6 @@ Term Yap_AtomToTerm(Atom a, Term opts) { return rval; } -/** - * @pred read_term_from_string( +_String_ , - _T_ , + _Options_ - * - * read a term _T_ stored in constant _String_ according to _Options_ - * - * @param _String_ the source _String_ - * @param _T_ the output term _T_, may be any term - * @param _Options_ read_term/3 options. - * - * @notes Idea from SWI-Prolog, in YAP only works with strings - * Check read_term_from_atomic/3 for the general version. - */ -static Int read_term_from_string(USES_REGS1) { - Term t1 = Deref(ARG1), rc; - const unsigned char *s; - size_t len; - if (IsVarTerm(t1)) { - Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3"); - return (FALSE); - } else if (!IsStringTerm(t1)) { - Yap_Error(TYPE_ERROR_STRING, t1, "read_term_from_string/3"); - return (FALSE); - } else { - s = UStringOfTerm(t1); - len = strlen_utf8(s); - } - char *ss = (char *)s; - encoding_t enc = ENC_ISO_UTF8; - int sno = Yap_open_buf_read_stream(ss, len, &enc, MEM_BUF_USER); - rc = Yap_read_term(sno, Deref(ARG3), 3); - Yap_CloseStream(sno); - if (!rc) - return false; - return Yap_unify(rc, ARG2); -} - -static Int string_to_term(USES_REGS1) { - Term t1 = Deref(ARG1), rc; - const char *s; - size_t len; - if (IsVarTerm(t1)) { - Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3"); - return (FALSE); - } else if (!IsStringTerm(t1)) { - Yap_Error(TYPE_ERROR_STRING, t1, "read_term_from_string/3"); - return (FALSE); - } else { - s = StringOfTerm(t1); - len = strlen_utf8((const unsigned char *)s); - } - encoding_t enc = ENC_ISO_UTF8; - rc = Yap_StringToTerm(s, len, &enc, 1200, &ARG3); - if (!rc) - return false; - return Yap_unify(rc, ARG2); -} - -static Int atomic_to_term(USES_REGS1) { - Term t1 = Deref(ARG1), rc; - const char *s; - size_t len; - if (IsVarTerm(t1)) { - Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3"); - return (FALSE); - } else if (!IsAtomicTerm(t1)) { - Yap_Error(TYPE_ERROR_ATOMIC, t1, "read_term_from_atomic/3"); - return (FALSE); - } else { - Term t = Yap_AtomicToString(t1 PASS_REGS); - s = (const char *)UStringOfTerm(t); - len = strlen_utf8((unsigned char *)s); - } - encoding_t enc = ENC_ISO_UTF8; - rc = Yap_StringToTerm(s, len, &enc, 1200, &ARG3); - if (!rc) - return false; - return Yap_unify(rc, ARG2); -} - -static Int atom_to_term(USES_REGS1) { - Term t1 = Deref(ARG1), rc; - const char *s; - size_t len; - if (IsVarTerm(t1)) { - Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3"); - return (FALSE); - } else if (!IsAtomTerm(t1)) { - Yap_Error(TYPE_ERROR_ATOM, t1, "read_term_from_atomic/3"); - return (FALSE); - } else { - Term t = Yap_AtomicToString(t1 PASS_REGS); - s = StringOfTerm(t); - len = strlen_utf8((const unsigned char *)s); - } - encoding_t enc = ENC_ISO_UTF8; - rc = Yap_StringToTerm(s, len, &enc, 1200, &ARG3); - if (!rc) - return false; - return Yap_unify(rc, ARG2); -} - /** * @pred read_term_from_atomic( +_Atomic_ , - _T_ , + _Options_ ) * @@ -1430,6 +1323,42 @@ static Int read_term_from_atomic(USES_REGS1) { return Yap_unify(rc, ARG2); } +/** + * @pred read_term_from_string( +_String_ , - _T_ , + _Options_ + * + * read a term _T_ stored in constant _String_ according to _Options_ + * + * @param _String_ the source _String_ + * @param _T_ the output term _T_, may be any term + * @param _Options_ read_term/3 options. + * + * @notes Idea from SWI-Prolog, in YAP only works with strings + * Check read_term_from_atomic/3 for the general version. + */ +static Int read_term_from_string(USES_REGS1) { + Term t1 = Deref(ARG1), rc; + const unsigned char *s; + size_t len; + if (IsVarTerm(t1)) { + Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3"); + return (FALSE); + } else if (!IsStringTerm(t1)) { + Yap_Error(TYPE_ERROR_STRING, t1, "read_term_from_string/3"); + return (FALSE); + } else { + s = UStringOfTerm(t1); + len = strlen_utf8(s); + } + char *ss = (char *)s; + encoding_t enc = ENC_ISO_UTF8; + int sno = Yap_open_buf_read_stream(ss, len, &enc, MEM_BUF_USER); + rc = Yap_read_term(sno, Deref(ARG3), 3); + Yap_CloseStream(sno); + if (!rc) + return false; + return Yap_unify(rc, ARG2); +} + void Yap_InitReadTPreds(void) { Yap_InitCPred("read", 1, read1, SyncPredFlag); Yap_InitCPred("read", 2, read2, SyncPredFlag); @@ -1440,9 +1369,6 @@ void Yap_InitReadTPreds(void) { Yap_InitCPred("read_term_from_atom", 3, read_term_from_atom, 0); Yap_InitCPred("read_term_from_atomic", 3, read_term_from_atomic, 0); Yap_InitCPred("read_term_from_string", 3, read_term_from_string, 0); - Yap_InitCPred("atom_to_term", 3, atom_to_term, 0); - Yap_InitCPred("atomic_to_term", 3, atomic_to_term, 0); - Yap_InitCPred("string_to_term", 3, string_to_term, 0); Yap_InitCPred("fileerrors", 0, fileerrors, SyncPredFlag); Yap_InitCPred("nofileeleerrors", 0, nofileerrors, SyncPredFlag); diff --git a/os/yapio.h b/os/yapio.h index 8ce7d80ca..755609c92 100644 --- a/os/yapio.h +++ b/os/yapio.h @@ -105,8 +105,7 @@ typedef enum mem_buf_source { extern char *Yap_MemStreamBuf(int sno); -extern X_API Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp, - int prio, Term *bindings_p); +extern X_API Term Yap_StringToTerm(const char *s, size_t len, encoding_t *encp,int prio, Term bindings); extern Term Yap_StringToNumberTerm(const char *s, encoding_t *encp, bool error_on); extern int Yap_FormatFloat(Float f, char **s, size_t sz); extern int Yap_open_buf_read_stream(const char *buf, size_t nchars, diff --git a/packages/bdd/CMakeLists.txt b/packages/bdd/CMakeLists.txt index 388bef694..36cc5ac02 100644 --- a/packages/bdd/CMakeLists.txt +++ b/packages/bdd/CMakeLists.txt @@ -32,10 +32,6 @@ IF (CUDD_FOUND) ${CMAKE_CURRENT_BINARY_DIR} ) - configure_file ("${PROJECT_SOURCE_DIR}/cudd_config.h.cmake" - "${CMAKE_CURRENT_BINARY_DIR}/cudd_config.h" ) - - if(DEFINED YAP_MAJOR_VERSION) TARGET_LINK_LIBRARIES(cudd ${CUDD_LIBRARIES} @@ -66,4 +62,3 @@ IF (CUDD_FOUND) INSTALL(FILES trie_sp.yap DESTINATION ${libpl}) ENDIF (CUDD_FOUND) - diff --git a/packages/bdd/simplecudd/simplecudd.c b/packages/bdd/simplecudd/simplecudd.c index e9b082c25..6327b502d 100644 --- a/packages/bdd/simplecudd/simplecudd.c +++ b/packages/bdd/simplecudd/simplecudd.c @@ -1,224 +1,4 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -/****************************************************************************** \ +/*********************************************************************vii * * * SimpleCUDD library (www.cs.kuleuven.be/~theo/tools/simplecudd.html) * * SimpleCUDD was developed at Katholieke Universiteit Leuven(www.kuleuven.be) * diff --git a/packages/bdd/simplecudd/simplecudd.h b/packages/bdd/simplecudd/simplecudd.h index 64a3f8ea0..746d9423f 100644 --- a/packages/bdd/simplecudd/simplecudd.h +++ b/packages/bdd/simplecudd/simplecudd.h @@ -193,7 +193,7 @@ #include #include #include "config.h" -#include "../cudd_config.h" +#include "cudd_config.h" #if HAVE_CUDD_UTIL_H #include @@ -352,4 +352,3 @@ void ExpandNodes(hisqueue *Nodes, int index, int nodenum); int simpleBDDtoDot(DdManager *manager, DdNode *bdd, char *filename); int simpleNamedBDDtoDot(DdManager *manager, namedvars varmap, DdNode *bdd, char *filename); - diff --git a/packages/bdd/simplecudd_lfi/simplecudd.h b/packages/bdd/simplecudd_lfi/simplecudd.h index b5b78d239..bdca14271 100644 --- a/packages/bdd/simplecudd_lfi/simplecudd.h +++ b/packages/bdd/simplecudd_lfi/simplecudd.h @@ -192,7 +192,7 @@ #include #include "pqueue.h" #include "config.h" -#include "../cudd_config.h" +#include "cudd_config.h" #if HAVE_CUDD_UTIL_H #include #elif HAVE_UTIL_H @@ -353,4 +353,3 @@ void ExpandNodes(hisqueue *Nodes, int index, int nodenum); int simpleBDDtoDot(DdManager *manager, DdNode *bdd, const char *filename); int simpleNamedBDDtoDot(DdManager *manager, namedvars varmap, DdNode *bdd, const char *filename); - diff --git a/packages/cplint/CMakeLists.txt b/packages/cplint/CMakeLists.txt index 5e7a968fb..83b8353a6 100644 --- a/packages/cplint/CMakeLists.txt +++ b/packages/cplint/CMakeLists.txt @@ -1,4 +1,4 @@ - + # Be sure to also update these in Makefile! set(SO_MAJOR 1) set(SO_MINOR 0) @@ -63,7 +63,7 @@ IF (CUDD_FOUND) slipcover/revise_sl.pl slipcover/slipcover.pl ) - + set (CPLINT_TEST_PROGRAMS testcpl.pl testlpad.pl @@ -151,7 +151,7 @@ IF (CUDD_FOUND) ARCHIVE DESTINATION ${dlls} ) - + add_library (cplint SHARED ${CPLINT_SOURCES} ) @@ -162,7 +162,7 @@ IF (CUDD_FOUND) ) TARGET_LINK_LIBRARIES(cplint - ${CUDD_LIBRARIES} + ${CUDD_LIBRARIES} libYap ) diff --git a/packages/myddas/sqlite3/CMakeLists.txt b/packages/myddas/sqlite3/CMakeLists.txt index dc0a32306..17daa9a1c 100644 --- a/packages/myddas/sqlite3/CMakeLists.txt +++ b/packages/myddas/sqlite3/CMakeLists.txt @@ -45,6 +45,12 @@ Android/jni/sqlite/nativehelper/ScopedLocalRef.h endif (ANDROID) -add_component( Yapsqlite3 +add_component( Yapsqlite3 ${YAPSQLITE3_SOURCES} ) + MY_set_target_properties(Yapsqlite3 + PROPERTIES + # RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION} + # SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION} + POSITION_INDEPENDENT_CODE TRUE + ) diff --git a/pl/dbload.yap b/pl/dbload.yap index 6e2dd3781..757b2e0cf 100644 --- a/pl/dbload.yap +++ b/pl/dbload.yap @@ -25,11 +25,11 @@ :- use_system_module( attributes, [get_module_atts/2, put_module_atts/2]). -:- dynamic dbloading/6, dbprocess/2. - -dbload_from_stream(R, M0, rdf, term ) :- - '$lines_in_file'(R, Lines), - '$input_lines'(R, Type, Lines). +load_mega_clause( Stream ) :- + line_spec( Stream, Line), + repeat, + ( fact( Stream ), fail ; + stream_property(Stream, at_end_of_file( on )). '$input_lines'(R, csv, yeLines ) :- '$process_lines'(R, Lines, Type ), diff --git a/x.py b/x.py deleted file mode 100644 index 995318a69..000000000 --- a/x.py +++ /dev/null @@ -1,652 +0,0 @@ -#! /usr/bin/env python3 -# -# druwid is machine learning tool for adverse drug discovery -# -# It relies on the Aleph ILP learner, written and maintained by Ashwin Srinivasan\ -# -# Authos: Vitor Santos Costa, David Page -# Bugs are from Vitor Santos Costa -# - -import matplotlib -import matplotlib.image as mpimg -#matplotlib.use('Agg') - -import argparse -import csv -import heapq -import logging -import networkx as nx -import os -import numpy as np -import pandas as pd -import sys -import threading -import time -import yap - -graphics_ability = False - -if graphics_ability: - import PIL - def display_pdf(id): - im = Image.open(self.shown_clause[id]) - im.show() - - -logging.basicConfig(level=logging.DEBUG, - format='[%(levelname)s] (%(threadName)-10s) %(message)s', - ) - - -from collections import namedtuple -from enum import IntEnum -from queue import Queue -from dru.druplot import plotClause -from dru.shell import alephShell - -# class Console(InteractiveConsole): - -# def __init__(*args): InteractiveConsole.__init__(*args) - -compile = namedtuple('consult', 'FileName') -ensure_loaded = namedtuple('ensure_loaded', 'FileName') -loadFile = namedtuple('load_file', 'FileName Opts') -add_example = namedtuple('add_example', 'polarity case id b e') -set = namedtuple('set', 'key val') -setting = namedtuple('setting', ' key') -clsrc = namedtuple('clsrc', ' key ids') -clgraph = namedtuple('clgraph', ' key') -clhist = namedtuple('clhist', ' key first pos') -clause_info = namedtuple('clause_info', ' key Text Symbs H1Pos H2Pos CH1Pos CH2Pos ') -learn = namedtuple('learn', 'example') -learn_in_thread = namedtuple('learn_in_thread', 'example') -#learner = namedtuple('learn', 'class') -# assert = namedtuple('assert', 'fact') -load_ptable = namedtuple('load_ptable', 'File') -load_files = namedtuple('load_files', 'File Opts') - - -# prolog engine -class y: - E = None - - def run(g): - y.E.goal(g) - - def f(g): - y.E.fun(g) - - -# Schema information on Marshfiel mode table ( 2016 data ) -# -# TBD: make it match/ genrate a mode declaration -# - -# column headers, StudyId refers to the study participant -# -class DiagFields: - StudyID = 0 - DX_CODE= 1 - AGE= 2 - FACILITY_NUM= 3 - PROV_ID= 4 - DX_DESC= 5 - DX_TYPE_ID= 6 - DX_TYPE_DESC= 7 - DX_SUB_TYPE_ID= 8 - DX_SUB_TYPE_DESC= 9 - DX_CODE_CATEGORY= 10 - DX_CODE_CATEGORY_DESC= 11 - DX_CODE_SUBCATEGORY= 12 - DX_CODE_SUBCATEGORY_DESC= 13 - DATA_SOURCE= 14 - -# -# operations to fetch data from meds -# -class DiagOps(DiagFields): - ''' Selects age, id, and one descriptor: we chose to use DX_DESC so that people - can understand the rules easily. ''' - - def import_row( self ): - return ( DiagFields.StudyID, DiagFields.AGE, DiagFields.DX_DESC ) - - def pred(self): - return yap.YAPPrologPredicate( self.name, 3 ) - - def __init__(self, name, ids): - self.name = name - self.ids = ids - -# column headers, StudyId refers to the study participant -# -class MedFields( IntEnum ): - StudyID = 0 - AGE = 1 - GCN_SEQ_NUM= 2 - DRUG_NAME= 3 - GENERIC_NAME= 4 - DOSAGE= 5 - FREQUENCY= 6 - ACTION_ATTRIBUTE_DESC= 7 - ACTION_VALUE_DESC = 8 - ACTION_IN_PLAN_CODE= 9 - THERAPEUTIC_GENERIC_ID= 10 - THERAPEUTIC_GENERIC_DESC= 11 - THERAPEUTIC_SPECIFIC_ID= 12 - THERAPEUTIC_SPECIFIC_DESC= 13 - DRUG_SOURCE= 14 - DATA_SOURCE = 15 - - # - # operations to fetch data from meds - # -class MedOps: - ''' Operations as designed for the Marshfield meds table''' - - arity = 3 - - def import_row( self ): - return ( MedFields.StudyID, MedFields.AGE, MedFields.DRUG_NAME ) - - def pred( self ): - return yap.YAPPredicate( self.name, 3 ) - - def __init__(self, name, ids): - self.name = name - self.ids = ids - -class PrologTable: - '''Access tables in Prolog format''' - - def query( self ): - args = [ 0 for x in range(self.arity) ] - return self.pname._make( args ) - - def __init__(self, p, name): - self.p = p - self.name = name - self.arity = p.arity() - ArgNames = [ "A" + str(x+1) for x in range(self.arity) ] - self.pname = namedtuple(self.name, ArgNames) - - def __iter__(self): - goal = self.pname._make( ) - return PrologTableIter(self, e, goal) - -class PrologTableIter: - - def __init__(self, e, goal): - try: - self.e = e - self.q = e.YAPQuery(goal) - except: - print('Error') - - def __iter__(self): - # Iterators are iterables too. - # Adding this functions to make them so. - return self - - def next(self): - if self.q.next(): - return goal - else: - self.q.close() - self.q = None - raise StopIteration() - -class DBStore: - '''store operations: csv to pl, and so on''' - - def filter ( self, row ): - id = int(row[self.StudyID]) - - if id in self.ids: - ex1 = self.ids[ id ] - ex2 = self.ids[ -id ] - - age = int(float(row[self.AGE])*1000) - if ex2[1] <= age and age <= ex2[2]: - id = -id - elif ex1[1] > age or age > ex1[2]: - return None - desc = row[self.DESC] - return id, age, desc - - def __init__(self, File, dbi, ids ): - self.ids = ids - OFile = "data/" + dbi.name + '.yap' - if os.path.isfile(OFile) : - print("loading db from "+OFile) - y.run( load_files( OFile , []) ) - return - with open(File) as csvfile: - print("Converting db from "+File+ " to "+OFile) - with open( OFile, "w") as out: - csvfile.seek(0) - reader = csv.reader(csvfile, delimiter = '|', quoting = csv.QUOTE_MINIMAL ) - ( self.StudyID, self.AGE, self.DESC ) = dbi.import_row() - P = dbi.pred() - reader.__next__() - for row in reader: - tuple = self.filter( row ) - if tuple: - out.write( dbi.name + "( " + str(tuple[0]) +" , " + str(tuple[1])+ ", \'" + str(tuple[2]) + "\').\n" ) - print("loading db from "+OFile) - y.E.reSet() - y.run( load_ptable( OFile ) ) - - def save_table(self, File, name): - p = self.YAPPredicate(name, 3) - with open(File, 'w', newline='') as csvfile: - fieldnames = ['Id', 'Age', 'Attribute' ] - writer = csv.writer(csvfile, delimiter='|', fieldnames=fieldnames) - writer.writerows(PrologTable(p, name)) - -class Examples: - ''' Support for the manipulation and processing of examples. - - So far, only loadng examples''' - - ids = {} - - def __init__(self, File): - if File.lower().endswith(('.yap','.pl','.pro','.prolog')): - E.run( add_prolog( File ) ) - return - print("loading examples from "+File) - with open(File) as csvfile: - dialect = csv.Sniffer().sniff(csvfile.read(1024)) - dialect.delimiter = '|' - dialect.quoting = csv.QUOTE_MINIMAL - csvfile.seek(0) - reader = csv.reader(csvfile, dialect) - reader.__next__() - for row in reader: - ( cdb, pdb, id, b, e ) = row - case = cdb == "1" or cdb == 't' or cdb == '+' - Type = pdb == "1" or pdb == 't' or pdb == '+' - if Type: - id = int(id) - ti = 1 - else: - id = -int(id) - ti = 0 - if case: - ci = 1 - else: - ci = 0 - b = int(float(b)*1000) - e = int(float(e)*1000) - y.run( add_example(ti, ci, id, b, e) ) - self.ids[id] = ( case, b, e ) - -cols = ['Id', 'Ref', 'Parent', 'TPP', 'TPN', 'TNN', ' CPP', 'CPN', 'CNN'] -indx= ['Id'] - - - -class ClauseQueue: - '''Auxiliary class that represents the list of visited clauses.''' - - ''' queue size ''' - size = 1024*256 - best = 8 - q = [] - count = 0 - - def parentText(self, parent): - [row] = self.DF.loc[self.DF.Id==parent].values.tolist( ) - return "Parent "+str(parent)+", cases " +repr(row[3:6])+", controls " +repr(row[6:9]) - - def showQueue(self, n): - L = heapq.nlargest(n, self.q) - S = "[ *********************************************************************\nbest rules at " + repr(self.count) +" nodes:\n" - S += "Node".rjust(6) + "Score".rjust(10) + "Parent".rjust(6) +" | " +"Matches on Cases".center(24) +" | " +"Matches on Controls".center(24) + '|\n' - S += "".rjust(6) + "".rjust(10) + "".rjust(6) + " | " +"Generic".center(8) + "Both".center(8) + "Brand".center(8) + " | " +"Generic".center(8) + "Both".center(8) + "Brand".center(8) + '|\n' - S += "".rjust(6) + "".rjust(10) + "".rjust(6) + " | " + "Only".center(8) + "".center(8) + "Only".center(8) + " | " +"Only".center(8) + "".center(8) + "Only".center(8) + '|\n' - for cl in L: - S += self.clauseToStringRow( cl ) - S += "\n[ ********************************************************************* ]\n\n" - for cl in L: - S += self.PrintClbyId( cl ) - return S - - - def loadHists(self): - hists = {} - if self.ipcs[0]: - hists["case_after_first"] = self.histpcs[0][0:self.ipcs[0]] - if self.ipcs[1]: - hists["case_after_last"] = self.histpcs[1][0:self.ipcs[1]] - if self.ipcs[2]: - hists["case_bef_first"] = self.histpcs[2][0:self.ipcs[2]] - if self.ipcs[3]: - hists["case_bef_last"] = self.histpcs[3][0:self.ipcs[3]] - if self.ipcs[4]: - hists["control_after_first"] = self.histpcs[4][0:self.ipcs[4]] - if self.ipcs[5]: - hists["control_after_last"] = self.histpcs[5][0:self.ipcs[5]] - if self.ipcs[6]: - hists["control_bef_first"] = self.histpcs[6][0:self.ipcs[6]] - if self.ipcs[7]: - hists["control_bef_last"] = self.histpcs[7][0:self.ipcs[7]] - return hists - - def attendRequests(self): - while not self.command_q.empty(): - msg = self.command_q.get() - if msg[0] == "show_clause": - row = msg[1] - y.run( clsrc( row[1], self ) ) - parent = row[2] - parentDesc = self.parentText(parent) - self.hists = self.loadHists() - print( hists) - self.reply_q.put( ("show_clause", parentDesc ) ) - - - # this method implements PrintCl if YAP is running - def printClWithThreads(self, row): - try: - id = row[0] - # if id in self.shown_clause: - # im = Image.open(self.shown_clause[id]) - # im.show() - # return - #Prolog does the firat half - self.queue.prolog_q.put( ( "show_clause" , row ) ) - ( x, parentDesc )= self.queue.reply_q.get() - self.shown_clause[id] = plotClause(row[0],parentDesc, row[3:6], row[3:9], Text, (self.GraphV,self.d), self.hists) - except Exception as e: - print( 'trieref = ' + trieref ) - raise - - # this method implements PrintCl if YAP is not running - def printClNoThreads(self, row): - try: - id = row[0] - if graphics_ability and id in self.shown_clause: - display_pdf( id ) - im = Image.open(self.shown_clause[id]) - im.show() - return - #Prolog does the real work - y.run( clsrc( row[1], self ) ) - parent = row[2] - self.hists = self.loadHists() - parentDesc = self.parentText(parent) - # and then sealib - self.shown_clause[id] = plotClause(row[0],parentDesc, row[3:6], row[6:9], self.Text ) - except Exception as e: - print( 'trieref = ' + trieref ) - raise - - def clauseToStringRow(self, id): - try: - [row] = self.DF.loc[self.DF.Id==id].values.tolist( ) - S = "" + repr(id).rjust(6) + "{:10.3f}".format(cl[0]) + repr(row[2]).rjust(6) +" | " + repr(row[3]).rjust(6) + repr(row[4]).rjust(6) + repr(row[5]).rjust(6) + ' | '+ repr(row[6]).rjust(6) + repr(row[7]).rjust(6) + repr(row[8]).rjust(6) + '|\n' - return S - except Exception as e: - print( str(e) ) - raise - - def printClauseAsRow(self, id): - print( self.clauseToStringRow( id ) ) - - - def printClbyId(self, id): - try: - [row] = self.DF.loc[self.DF.Id==id].values.tolist( ) - self.printClause( row ) - except Exception as e: - print( str(e) ) - raise - - def printClbyTrieRef(self, trieref): - try: - [row] = self.DF.loc[self.DF.Ref==trieref].values.tolist() - self.printClause( row ) - except Exception as e: - print( str(e) ) - raise - - def idFromTrieRef( self, trieref ): - try: - row = self.DF.loc[self.DF.Ref==trieref] - return int(row.at['Id','Id' ]) - except Exception as e: - print("node = "+str(trieref)) - print(self.DF) - raise - - def add(self, parent, score, trieref, c): - try: - #import pdb - #pdb.set_trace() - self.count += 1 - k = [self.count,trieref,parent,c[0],c[1],c[2],c[3],c[4],c[5]] - heapq.heappush(self.q, (score, self.count)) - self.DF = self.DF.append(pd.DataFrame([k],columns=cols,index=indx)) - if not self.command_q.empty(): - self.attendRequests() - except Exception as e: - print("new node = "+str(self.count)) - print("parent = "+str(parent)) - print(self.DF) - raise - - def link(self, parent, trieref): - try: - row = self.DF.loc[self.DF.Ref==trieref] - if not self.command_q.empty(): - self.attendRequests() - except Exception as e: - print("new node = "+str(trieref)) - print("parent = "+str(parent)) - print(self.DF) - raise - - def pushHistogram( self, i, val): - try: - x = self.ipcs[i] - self.histpcs[i][x] = val - self.ipcs[i] = x+1 - except Exception as e: - print("i = "+str(i)) - print("x = "+str(x)) - print(self.DF) - raise - - - def initHistograms( self ): - self.histpcs = ( [None]*2400, [None]*2400, [None]*2400, [None]*2400, - [None]*2400, [None]*2400, [None]*2400, [None]*2400) - self.resetHistograms() - - def resetHistograms( self ): - self.ipcs = [ 0, 0, 0, 0, 0, 0, 0, 0 ] - - def setClauseText( self, txt ): - self.Text = txt - - def setClauseGraph( self, labels,edges ): - G=nx.DiGraph() - dict = {} - for (i,l) in labels: - G.add_node(i,label=i) - dict[i] = l.strip()[0].lower() - for (i,j) in edges: - G.add_edge(i,j) - self.GraphV = G - self.d = dict - return G - - def __repr__(self): - l = heapq.nlargest(self.q, 10) - for i in l: - print( l ) - - def __init__(self): - self.command_q = Queue() - self.reply_q = Queue() - self.GraphV=nx.Graph() - self.count = 0 - self.DF = pd.DataFrame([[0,88998993,0,4,3,2,1,160,400]],columns=cols, index=indx) - self.shown_clause = {} - -class LineSettings: - '''Isolate interface with argparse ''' - - - - opts = None - - def __init__(self): - parser = argparse.ArgumentParser(description='''Search for ADRs using EHR data. - The arguments are CSV files for the databases, with at least 3 fields: - - an integer giving the patient id, called key - - a float point giving the patient\'s age in years, called age - - a string describing the diagnosis, called data -dppb - The case and control files are alos in CSV form, withe the following fields: - Key,AgeBefStart,AgeStartEnd,AgeAfterStart,AGeAfterEnd - -p ''') - parser.add_argument('--save-db', dest='save', default=None, help="save the processed DB in Prolog, CSV, pickle") - parser.add_argument('--meds', dest='meds', default="data/meds.csv", help="CSV or Tab like with the medications database") - parser.add_argument('--diags', dest='diags', default="data/diags.csv", help="CSV or Tab like with the medications database") - parser.add_argument('--examples', dest='examples', default="data/exs.csv" , help="CSV or Tab like with the cases and controls") - parser.add_argument('--labs', type=argparse.FileType('r'), default=None, help="unsupported for now") - parser.add_argument('--min_examples', type=int, default=20, help="minimal number of examples to cover") - parser.add_argument('--seed', type=int, default=0, help="examples to start search, 0 if tries to cinsider all") - parser.add_argument('-f', default=" " , help="jupyter notebook") - parser.add_argument('--interactive', type = bool, default=True, help="run as line mode, or run as closed script ()") - self.opts = parser.parse_args() - - def map(self): - return vars(self.opts) - - -class Aleph: - - e = None - - def add_db(self, p, t): - queue.addClause(t) - - def set_options( self, xargs): - - if 'min-examples' in xargs: - self.set('minpos', xargs[ 'min_examples' ] ) - if 'verbosity' in xargs: - self.set('verbosity', xargs[ 'verbosity' ] ) - if 'search' in xargs: - self.set('search', xargs[ 'search' ] ) - if 'nodes' in xargs: - self.set('nodes', xargs[ 'nodes' ] ) - - def set( self, parameter, value): - '''Set an integer parameter, eg nodes, seeds or noise''' - y.run(set(parameter, value)) - - def setting( self, parameter): - '''Return the Aleph setting for parameter p, or show all - the current settings''' - if parameter: - value = yap.YAPVarTerm() - y.run(setting(parameter, value)) - # return value - y.run( settings ) - - def induce( self, index = 0): - '''Learn clauses''' - y.run( learn( index ) ) - - def induceInThread( self, index = 0): - '''Learn clauses as a separe thread''' - if self.learning: - print("Already learning" ) - return - self.learning = True - y.run( learn_in_thread( index ) ) - - def query_prolog( self, y, Query): - y.run( Query ) - - def rule( self, id ): - self.queue.printClause( id ) - - def histogram( self, Dict ): - pass - - def induceInThread( self, index = 0 ): - kw = {} - kw["index"] = index - t = threading.Thread(target=self.induceInThread, kwargs=kw) - t.setDaemon = True - self.queue.printClause = self.queue.printClWithThreads - t.start() - self.queue.printClause = self.queue.printClNoThreads - - def rules( self, count = 100 ): - self.queue.showQueue() - - def golearn( self ): - - try: - # import pdb - # pdb.set_trace() - self.learning = False - alephShell( self ).cmdloop() - q.close() - - except SyntaxError as err: - print("Syntax Error error: {0}".format(err)) - print( sys.exc_info()[0] ) - except EOFError: - return - except RuntimeError as err: - print("YAP Execution Error: {0}".format(err)) - print( sys.exc_info()[0] ) - except ValueError as err: - print("Could not convert data to an integer: {0}.", format(rr)) - print( sys.exc_info()[0] ) - except NameError as err: - print("Bad Name: {0}.", format(err)) - print( sys.exc_info()[0] ) - except Exception as err: - print("Unexpected error:" + sys.exc_info() ) - print( sys.exc_info()[0] ) - - - def learn( self ): - - while True: - self.golearn() - - def __init__(self, queue): - ''' Initialize Aleph by loading the data-bases and the example''' - - if y.E == None: - y.E = yap.YAPEngine() - y.run( ensure_loaded( sys.druwid_root +'/druwid.yap' ) ) - y.E.reSet() - x_args = LineSettings().map() - exf = x_args['examples'] - exs = Examples(exf) - di = x_args['diags'] - exmap = exs.ids - diags = DBStore( di, DiagOps( "diags", exmap ), exmap ) - md = x_args['meds'] - meds = DBStore(md, MedOps( "meds", exmap ) , exmap ) - y.E.reSet() - save_db = x_args['save'] - self.set_options( x_args ) - self.interactive = x_args['interactive'] - self.queue = queue - self.learning = False - self.queue.initHistograms( ) - self.queue.printClause = self.queue.printClNoThreads diff --git a/x.tgz b/x.tgz deleted file mode 100644 index 6979758002aa4b056d83fde552f1929ed1aa8e60..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 15374 zcmV+pJn_RHiwFQCY6e&U1MPk3dfP^_==>F*qT`wIkkm#hw&Ss4&!s48xuHmnNX3)! z_`?U0po9?!FaRi7nfU)XPjVmRzR7u#TUEWF8w(d%i<2vUiAAEjtE+44>gq!G!RAl) zr0;x+H!l8gU!Pj7_Ugq8hJU|%^^*S9w)pQ_t-kf*yR90le+yqWcg@{K0-|9JAvv@Pc!u zKQ}6Y@X0#YcEpCxmE#2yXUOcBb(+o7W46vtefP=(WiHw=St zW1tnb?I>oUbMuDr>(_e2aWIVDn6L)HcO-#loXSbg^P zE!$Fc@maIG+p>-t|6sLGBlwj5=y;J+RHI%Kb^M__DwQ^?C01qq3pZjTAT{HSA~v>N zpAGHUUXS8%I*6yC!$v{KVlaR@~xz?hih`seUt6S4LO-V|i#*~Z4^G#P7)d1GwgHkEJ0dWS3@D3T8+MVfWAP_U&^gWdA8Kb``ioRy~`J)>w5ChuiQd za({8Gm_@(PkHXf~35d#e=`)SNI^%`$Hqw9-K{a7O4cqgAfsNt-+GexC1rj6}u`_sl z2@2D{aBi3#IyN>9ok0K;;o2BqI1H%EfOGgY4sAd3>=>xELDXT)^*!Va4aN1{*rLwL zt{*cjs4yDo^#wAd-0n6TZ7V@;{T+^jRjAI)@dnr~4%@9xIcltO7z_ zE`xG})kHckc^jLL=8E31W~i64L^6st&ML>(@* z#r?2q1?sKVO~545s{N|4Re6d?)nsAlfZ_F3!)=Dz$8xm^yI6h80gGk0|;}4(v#lwV`ZFl);P}l73K88=HO0i`v1p(X4X{WiNQy&^>o!{`l`O{j!(* zaRk#HjQ{6pAo18mfUiWOV0vbj_I`rW?|5nNW_%WS8d-S_#PzkP0j^%UeCG!!|0^%w zfr3jXj@WZB&MwS1k*L!{S^%xEj%WLq{Bdg!AJ^$|3m6VF8M;UL*;yBJRURKRIFag2bbDA$R6Dk!JTSy0+3C?1M=4wUvxDE$n(b*L+I@9qPl4a-&T$mVj)1@GFPG>=CryzMm=%qk(Qy}tqG!w$HB=7OmhouMk z&TF{p@WE{g(x7_nS)g|FKn?BaA`RuISx|a;P+t-n+Kcuk` z7OR9HrhbHrVptV|V@Z1Qmk3S$bnGyDZNR1xEd3m{g8aY#r?iZj>UC3nFHOULN}26B z6YwHHZ@8h#$Xag}kaiYG;y^73<2VZgznq8mB+b;BfSOHnZUuu7hu}pmVYr)nCJ69^ zL9~{F&@&-`5QM?Gol%q7K)NQ7N$6f7h-uam?8_CmMxoD(xPtE)0pkb&eu%^U`_fhRhQ$}iyoE$8ibK!w=drAS+~I)eSx9pc zgp9+fb6alb*g~_G=klRBK~3|S>7b5!2Q_%^jjq;Z@0b+sm)&(y>2alGiY%O$$Jt!qBcdx#*?{oM}0PliyLmOJ;20|ga8~r)IPFr-U79@ z;9F)cr{Z-{y1mpqR?nHpJlcg#<|v6nUExqyI2c&eB^LFM#tf!_ewzilrGReb1KpB9 zw+ev1$O8RV0sS@~=(iH+w-Tt3#=0hiP@bpTHNNw(iA$gQt0WNIZZ&pc#j)3G^;x+* z6-=(wKJC7))u6lNQ5kotF+JqnJ65k%DhfpJ^yH+w4+|*?=XRfe0kQ@Lytfnzgx2@p zBL+qhlr(EKj9ruHCtDbCaCzcP%KhN71#8nAR)q(&W+44{{c{jA_=*8-pbn^^KeWRk zS~)0-a&|s&)2i1$Iqd9*wSZJ>z6H24sJ>pPa%!6|2_~-G(dY!>~f1CqF!|2tTfu&pMb-ilVWIy7A}8@<2l6P6t1OE8VMji zvv1PGIPCN}K~yMbe_aW2|X6bxL7dJ*AqOVtgg5$>~Lbi>A|pvQu;PiQY1j)`8Ek|Cz-vp zTb=#>f!56n*^TSN!uk#KNXi%`uY7Wb+bo#IR3Pk-q#U8bE1NxZ5Im7Dp}(Mn>;v4~ zAk<;|01NqVLh83pjwC@fSO93>@tqK6TcqL|4jBe}foe)N`rN&8Qp4Uo+}jh9lmaz$ zQ3}C;IHV=1u_RLbqNa0|+#RmkFo4a_iKbqvZU5x7)0C9ZMUjDv2b5sYbA70mSs@@yWRI41!7BqSRBA% z$Lb#)C&N!Lh@J5y2yK|5cu4rdj@X&w_(|H638{P9KR)dzLjIcPZUUt13utxi{3Ucq zi7_T#`b_he6*)g!sNS?)EN8Y;3`QCyM%vp?$C#VZ`vLl>?d|O)?Z9lqaB)i91B({3 z5xN`*i~Po;W3r@Gau@YUc~DE9s5Qeif5-6zxzoz2hlxsOQDZXk$_FRt zJ~4oWKK)x(rhKJ6+;9rQ9s$uJ);vyUcADZTsE#!XgRw#Z0mAY{EL6S?7s zVXLqp&^m^SIbBmq6>a&c-qN9zbe0y!Ci-Op{T`fP(!@56UJf04H*>fqS_+qF2Sfu0 z7QUk&OYN%%C#$Pa((;GBi33x%7a_VTFI2IS(l#`?=1!d~$LeHu2UmA9UkFr#I>ksRv+*zV*HnA5ov=T9*M_W&IshAZ>$n4X^#2?e4Vy zPX3r&_Q>6fl(+V4fr+ElOtOSB!1CI~fcc+U5cqb>Ow4+z^;FuEm&>cWVbR&okHMs! z<`4J5Bm(^iZ5jRDk$kIMk- zO+0ttn85f*2Gck)VIiI~qgkpd^m_H-qtP+46IL;yNV$Xg5?2`E2wbSNp(mdJk;5(3EmFD6bL*AYfb)KU@95;G`e#X{yt!>W1L_a%c zCeASEbn?WX`TXIlntSICaUrEX+_!sT&^*NNMTPR5*$k6TCr>VyxT*p%@dzB+Y!;?p90dLVTYi!?)_Xp`oNLD_Av zM=)-WpfLs1EhMEN^_PnOV-fdZXZQOiF5)%C%&E?4yFF+AzITde*7py(y8lW@jcDBa zT0LdP@70LQ0WCp;FEgLw?fFW1z22_m5X76O?Dua+Z$XnsFnYcBhqooglC&_jCQm!R zTo?5urea99)Yu*$@`JJF{%50Gi0H%25-B?HS606k5)?U>Dam|jA}t-`yI(5tKM$-j zWX9MeLz$l&^8=r({)7O84(gf|+77 z^Yfb^?E|`|25q^I{`;lv1H1irHp2|kehGnQ&?BK=tJAa&dtJigv5BJ09w&-s^->vS zOOj=JZ*+MS8@KC@M#Z`)@|A7ZTlT%wuU<9jy_D?siEJ=*@nl3C`9rJkY>q6)2F1Rw zMD^zoJ(qQl!HM@XwL`rxu`D}o&5-Lk40&&8z}H0g+j$3KQT)|-sm1Hp0s`Kvm?l}) zJcLDd1N-2w?!;^C3#NS=Mq$UrbkSp4x3R?e<^t&z$qaSbHsP7p-LIzLCojffJ>vwG zf+qY`xNWm14av`U$-cn?!j2J%ylEE}ii_BnyVHs}h8`ELw3yA+q6Om(kD)Iag75r3 z30@Fjcnp#&?^|0#-{YpWTEouvtnZ8tWN9lB!ZL2RL63Xhph;0gi1zYZGD}3g9!8H1 zBHm+?_8hT#OdlYnVC0_OqkFi!RAn8iQUdeS0q8KdsL(^*^zrlMY``P z>Q;n!*tk$a26ynF31+>#{MB3LoZNLvYwAtihf~g5n6SHJ#gc?y*yKGh1s`LF{jP-h z!MDkgWcQv9ve*XgVp(Ym`>=%&Qp)`mbBD|GBW5sskyw8XX$XRXkC%gR7ZiN#M1szY zOoHUlg~ejy_a00!Dc#B0y2!>;mPz5GGfQ#259gv~HYf5@6jGF3cBkUuc8=zfKmFR> z;ohEX@EChTow*qdODn-|L>COF@P6ceAsV!$HtrAH)q&JKk}?b}$I z+fBN6E999F`%+sNkI9bg{>5*e9m_a656ytY@u9W&9S4a7f9^6Y|JX4kNvHdGSM0&a z^?-SMCcWr{4p4=ZDN6ljg>n>Fdz{rS}0J$?M~!yZ0j(Zn4dE@1`+D z1KJq)&7VB6{M+siknnJu^C@(}yw}ZIlMY!oY4I)BuOj^+hlKZjQd6-gB`12^86|FW z%tszk9^}ZR1s#@07LhMF@Z!Rd14Y0~JD*EXZ?Pjv<_Y4LX8Ao>tb>#D@y~p@KY~6~at>XBgTT92PDmG5 z;7d(Abb}S0soS(8r%bi*a-KAiGjAj3+{XjW5E*e#YgN4{#jmKFj-80^<%q8Xx?Yf7 z*jEm-y=(i17ew}$&lB6!EORgE;3DKD>UR1_ToVc<;-XOa#59!H^{tBD_0O z-4G7|WYOoGH`wxC#7@LAA>eOBG|h&|8)i$0s}UN>dr9st<(Mx1n)f1d-Zp!h4+8Gd zrI_CULOH4|@@nm@AmCEd;&SiCF3OFE-OzZiZM5sbx!di_E=rNom+pZ-k}vgM+Xue` zYAq^03()E-dIK**t%3;fJ?h$5`of4c1J)(eIqwd<+2)~K^Pe)}qiw(j5ose9|y=q*;H>LrjRIr$hke%(@& zB(zdj+(13J)ZCtzORhbZrRObns_5!CZH){>6lX&4i{sQia*J%UCU>S5av;E4<&Xm~ z8bnsVsBY^cKB2F4v*~~{i5}GP0ba&B(?!n&Kk9Z+u!l?Xt*=}ewZ&*IP?#0QQ&G&#$^TrA9-dm^;1a2Jb_U#AAP ztIgs`SzZ}Q^j@Aji2~^ym{0J&?RsB3!E3jpH|Nts5WH4Q@FX-!-5a4OMeJLctvfPY z^J1*au+Nw-=1wUKn9MIUUwmfCvs$qz$QZ3y<7|=5N;s<7tbD$HsS@1@AC|COSq|Ql z?MhGjIs@ht9BtNbgWz*4S24Zs+ID3LUegKAuMo#b>;L@se<6bX)<62zL8+vN#Z=@H zNZk(z7f$uH2>*aT>{%x&RfAQ+Yt9qT)>RaD_``sT{?LLu`pDAck2&h~| zvuOa;Mxzi0H9oj>O4Fh%@gmI9C#hSt7CUnm)V%FZ+wZ}GS%8whYXZvvw zK_M`Z+5Rve9IOBJ^~?43EY$lV58HD+=grCrzw18Q7-&U&E|Frg}#x%YN!Z!@mfcCC|QB(B5eeIV;R(6duJ#@NDD{oe?`|{MfSIH+!9St5cGh7ko07 z?xyQo_*G6puCn<5h8b76$}an!{hR%bx$F%TY_rd$KLUINcRh%Fm>kNzHP)#l;5utq zLIp5$@%bphtJCNx0PvlaYa2DT$>85?-J`}otm8)i;GokuYN=MnQ&tBPts3H{WeF#x zL*I>&at+T520;C=%(p!&rT++z9H=-Q#0)F(ojYr6`}R2qYt?tI$#uoHM4Vt$F05Wz zmG~e!)h#A=7a0RE>+dEY*IKYDc^>2LBz?s_*0-#<2k;G`-fCU8Z+DxGww2W5aCC2r zrrLckII}%u2>rZD`%~nR97aFdAB3|#SDQQig`bVs~Ng}q}3 zC+zuiW<30!wVUmlgt6oLL#qv3@QkKw?C4VVT@f_XagbdmC?w-M^kde$bm?#ez9E;| znMMC)B3zEDC%;tjz3a)0B^ko4qOO8TJ_`bmRjYgsLBX#iP6s8D&b-nQ zm)e@3AN(^6tRd3WE?=!NpauV7P5n#t-3PO6^Sy6QBLGA%s7L$@KF7{+FD0gbY6^v_ z$KJlB!F60O!G*8X{_?NdU$zbBRhOj0=-76-1XMjGb3~_$Ar1zYV?tn{0tdt!O38tG zs-fy+{jk&PH#+^pM*pzev05i5-4ovUGyRKM2qBm+hj~G83AU7tf{+p4H!&R{`kSnF zeF1Y3%xIL9Ft8(#1!xsr1XFLw&Ujh?$RJFDP$LYc=TIWn{LnfI3Tt1xAT9`W1Md z^}QI7*(|M3S>!Ytc219WS|@t7&#Ar+qxWDaD8`5X2-QGj)7_f1P9PvL^V+Y!dk@R- z?x@kKU?}AquDWTcEHQNJC#~a?RRW2Oo$A%&0xK;uTV={Y&G$IAbeCgG_c@Tf zGF8w+g{wyBQ>NSl({qqkUvnJh*n8QQcad^fa?El2u-BLE(*BI_vVe-P?k67%hM)1D zN*NX=E^Nxf^WdSs#W|xpn`%i`MG%wR49qihm7wnWJH9urZ4VI7c~f%RLR^)pssq9p z>QrI+=aEu5YoxoNC5jj|G{Dh{f>4kg>sA_~V<*G<9zf9H!#E|#N83Go9r3y3Kvi3v$CRFS*{tXEexUJ6`j7=`?y_4T6sQKS&dU`2}S zN&#=G>;=(5COMfby}lhs5^gR{e2sE>WM7PgJcBsGaCbQgIjm{BU2A!xN|smKMclx| zHJ)voZ7&1Osa4zjjksjN2VB)wf^!>c5|CLOHe2mBtA<(x03rLy0uH&NL>>6eUl%4= zQed-V93)Kk;j6h6evTE^*mI!3^Kgxc<*XPNu3ybWKg7b(Y^6Z<;9?Vdf z%wf$ta~U?5&?&N;dZ@E+Sx7S&i0l$;B$(i6P3W+|_ios=jSGJmVuZ0ys*_MBkx&|8 zyvDN=1s9$Rrcj4EI~E|PI7I$;K+dfhV2U=ghBu=r|5MahOLEYf>toB2Hxk6c!N_G# z@i0HD?Uo#C8anon@(Gq+#zZyEOCqa@mWe#2%_0nmiAIS=eP~RRi7fA~skIWbu(m zHOY>nGtFaO7Rf?!UF`OU>?gp8>Yd^Jgh^mqQdUq%i!6|#gQ$ z^C4=nq%1@uh_;Br=gmfs!V;N}kbc+rl#e2xM{=y?;>n?Kf=rx+MH?tJpJB~3;w>?1 zExf1BNJtbvy^4uyYe@^~=RfCr**xH6#sKECGMdjwN$LX8;bc=`-TR_V_LivmG+AxQ;T(`k_>(qIEUVm@> z^)i$eZf-JlL@H!WhbRbp7Ktq=H2qq!k=P;H`xCHy@d(c@(36nZI;&F%)7tBv95wnm zyfL@*jG-HwQ;pMq@L9dAvwe$ISy}I~0u# z6qD9iy*8IokIy8&^qwJ8(Di!CkHl&@J+*|c;{lF;i+x+%IvNxUnV{n}sh zR?T_l6(_YziiT&6sk4L6)fyUr=PqM9IYF-e$!Vu)gt+w9nZ}ZLynCuDUf-M9n0i5b zEL(sF0sks!GzJ|SWd`P)B860}dhQs%vQ<{*Ep?TMcoqoXkf9xNH@0G7Y&DyhvtK?S zQCy=f9U`X4q6SkX%&hcl5QB9ly5igH@UJxrgR$!C;H08$og;7DJzCYK^K<@Jtj^?%j)|qtybdNIHOgYlpZ|~q^3R4wLUSeXnmDq zo*sv0;zVMT&Wn4o8TY03z&m=WMETWZ28&gi^ibr@T#Hwsulei1Qq&exbs>jRi*abs z#e8MvDINonxyKcAo;K6jbRw}-%6I74m%PTcc$r%EFu+{90}+xvIKd9KWC^c&bg3e% zv~&-G%jx9EzBzMLaPnGayFweHPD&av5lm_udBMLRh8jl|f_Y-42?kzwr^^oqq|8Mu z#RA;OjB9;x@?o8jOI}`)byJ#bghmUx(NrP7mz1t#wMxbu<4S>5p!|d8QsV)6ugdyX)vQ&Uloat}D=?*@s{Mmkrk zQCg8jUeHY$H(Qj}IuvC1ALs8%pV^_su> zcr6kb)n1zxNx4?Js+n}eoI_=2(Na$!o^e*JnMbVWzw0mjn2E(nD!f*SMn`_GLO}#% zQ~|d_^pG|f3ny$O!nSGHZQA%VEIa?nkF4da;*y)6AiJCp7q3UxSQx;1$nl4AHX;)^T2Tsq7U!{pV4>8PfKS+o#JO&84TCFL?Nz%rW~ zixB^JDK)|dXzyMpVpQgGgxpY;$8fdiWil4T7fz_o?}_Mj>1aBc1Yzt9H_|{kx3maq zGB+enl`%Q-_o2$Ur>ZX%Or14*Y42VYtloIOa%PUqOp$2ru%rAn91ebLhnE&~Ft{ue zkL1K|-l9RCx)#`YF11$Nc@)J#=;&Z%=5_{u9^s-Hckh$R&@dc#*aF;)%{hC>w%57vXeFIkkSw zhxx3>#7r*XrEn7yJAuzMj+pRIjC3Sg1@Kj~@eUhLZ_Y7UceH=TV+9C5@k4Xh#5`mk zUAhx3`GML=_fV>>OHsKpHlSsGlIKByd?Qj%wdKhr_!&E641f9rpZ>ursu-Vtz$fO} zZakGclQX0aTQh@HMd?TK?FneGBn_kwoIX%t>Vwk9&L9>GO)c-mI7@ln0^{_!+32-Q zj_!8fckt;Vo1(mZ>U=dZ1JNj;o$>0~48%3$)dDFY_UC!1D6~yvl(oNmbci$IKzRhD zShAa3e<0l*qQlJ|!W^Zo9$SCMo*5D6Z^A*wY_MmDby6=+Ceuc4o~lm%%dX*)87npigG$rH4;hE_44JW!I9KO8@ddf=#b% z^JtEYK@QCG=fPhX^Fz-I!j9lL{I=L0Jf1lrc3!AGW zm|PlV5aQXpbjSl9!Rx^voY%QpLJK`ce7%);K3j5kwr*CbCsm}u7ikD}m@25D8EVi< zQVvmV#*rEWx;2Oneeg5q`$ShCKBnCw!yC%_NO}&82msVHLgi4(Hz-AIRAS0CJu z%F#1sMczWpielfQ=!VnTeP^@UsasBb-ly1bf;mhj5k4TU!H2Uxe5QVF8KB1DGd4y)+#=o#KQ3KSP=`>mI&JIStzS>Ee9cRoMOD^hH?bqa1QN%I z%%*=MR(yBh5t&mR2&j@i{gx47iuD_VJ}!1TntA0)#&XXV#96|ZEcuFfUA!90S&A*- z^y_k&*;)7oiK095e(FSIIi?!0Mjm z$u8f!{g1}6IsSRRhn_x~RCz~o?T2Hn@r|H6?#@GR$%FaCt0_tmImnBmd5kDcXyg*2 zNQLU+>KxjQgl-Cnh%1CU9a9=WS>mA|GOX#VXwUs{SlK8^sVhmTZkobU&l480@j7d) z*z~SBSd$#AZ|6%^yoA-bgkj^{b{RPU z7=NSLgT0ZmS(_~r+R|Cf<7>=^?&tfP6iqYIWU(E~dx=#P&}`u1>!-pi<<2Aw)K!$i zs%xU=$9#(MtWASZu2Mx;HHLnuUwxx_nMqjVtfWuQ)Oc0VU+huA+s$gV1U}B*)F04k z0WpT1@w%EAyti|_zy^G2ykv?e2b8%(#}Ck4qr>#*P8-~|;y+8lsKgJxCN{~#2}(}5 z0Ucpq|7&80HfH(bN2VQU1xQL>AWt;_LXxb=a}F>^f#*0nLw@D~)}BUqrw-jKPzs%a zXS>XeHMrnHaB)WnICp7fm?OqiY7Z;ZF$UNTj5qMly&E7Lzu0H!3@dUVl9(E*Ac=&k z>+@YBAkN5ky=mxdu)`6Hg0)2jNZ1@SsFjd(F1OXOV(lN?Rd^80B(R?Pq61G2_oABZ(7{jM5O(4xvW z5cyVOlI)E)KJizjMA9nyK=2G7ajO9|#6)>mV;m7RyCcL=avzH;nlzI3(||}Ebk)V0 zNn9q%L}kRQDLgt7v3L57Eg0E>RUi!K*&7*mP95k~u(lNM6J%e3N%|33Je$y+bO2xL zH;F1?->Syq7~ub#n;?`x?rXjmYl8&a9vg9X2|}g`jGo8g?v8cT-92r$bf*MsVvRj< zLM2a!+})AS672DK+e_z0urCS+8z6L_4u{ec(9gV)^uRdrGj@D(I6Us3tYP!C8TE zc(cK#tfCf(&899le2ki%k7_dvJb8-3#VWsEKXbu%ARjR1*Vn>8FKjK5fo3T?LP%Dh zZb7xk6#vhE|JO`&4dt3ANex8>`i?NLO2(wqgtEEpHLaMst6$WbwdQG$iPtlx%iOn- z$t{YKSfc5`O*X!Tm{lE3v%cuK)AL0Z4 zNG}G9$SteffuS4q@J68_!+SnGVSz6&M1~90>ma-Y8`|qPPWsmS?#U0W6N}^sqvZe) z>W!lkObmE)Ebcnt4pBsp@yXj-QU*?cs<56E^5gHdvMru0hTo%LaOuR6zSk! zF9LLZi)JTl>_m}$?x;$en}p|S1mioqA;S*t+;|d46ur1`2A60P;rR`{qGONnvRxam z1I7DZRlvY!c8QW!v8{F?As-VhtQ#*34pQiyo1~N*he0sHVTd=QiZVvwT=Zb4K9Z@~?etFD zeXG0kzk!KOUa6-EjRpdg&mB+4Ok78TQCr9JC}xs@E)`ZlY}ylhz%2x~N_bgsFyWD3 zz3CjxOkoEgu##TCw$VJ}>vlR7=7DMl*9jzaYw_2Qc8JR_Zdu9{EUnZk$_V#@X*h7? zdN*k@(zy?2sFi2GG|QVgtHC(OO>84YBXW@ZT^q zt8TPLU06GfFq~lOMyAYED6qFwLs?L9Nj7{iz-BoZb^=o24f2gBa`5$3lu|X|g8KdO zL{yU%afU+c&>Psk?}R;M@=6Yvh?iS*CNbaIuC6fAs)Y}C;L&BIngUTbg&#r(NQ8k$ zwjYmi1)fte7b(vjyRn$VuP@vIzaW^G(KZ0y22PGZa~-!KHk6^<3BsXN=MwJ`*SLxN z!u!-vr zolmIP7mhb!Lp!$rrn)*rnm5D*Of7EgaWJWJ+Y*dgzRnS0Qg#D?c8b@*b7kLyMLR0Sj5y^8t9C zxbdWPb+C`yStMTzb-h10z7PhhxUy2}L6h5A)dq>Dm4Z?vG9jnYAl@JJ-La~lnVP7^ zi8BbU9HE(7bJTCMy;jic=>>@=GjaSz7}__9NTDHyNx%kS_Rqn&Js+U$6`*49A3Y1L zbEbP<6nI0|Q8r4LguzAN;@w-&rI>!KouosB3|OBl>tJUkr|4k6)k#060(TN~uSjB# z2PA{EfzS@i`%S!XquoIn%2P8PUDP$nX_YB}FbK`1+R7PK+GHj@}#>r{a*b zRafwr1$ft%te?^Qp$n!q99l8@m1MX%@xj6oBnzbPf*bUe73~Qr&<7yTQRBzPNzXcH z^bV}v;Xhj+`GlTsTve@2G-lLO{=PA%LTLEXs(~B3i0jtNS8`A`YObRE?u~Dc-2tg{q=p4{>NpPQVM`b((VAz*S_Y6F zJu3#$GeK}qNMXQD;g8ZUN&(=d5(y!}4ctD#XtMh}LeZv}1$a0%IfQ#) z%vcZj0`ol1+IYTOICh3EZX-5f{e$+dgx^ zsQ?_S+?>Nt!ZKyKPnEqlDj37a@1ghpaQ&F}z?d_hdiExaB?z?K1`b3lL{WBB%kyfJ8iljPV~t!4kj^P%7}=sXy3to#olocl$e>R%<+)4 z?%QWaAZvV!8Ie^O;&5}d(Q zc`V6<*Y3Wz+N~d3ZJ2}_&DM!ICyVJ9e8gBx4$?J}u{pkovOMR?@%Ts#nU7cq%XU~c zpq%qPbVgo1_s*rACZUpxIx=Ol#Eh~SMMl6RTOwi}Jop7vr63|Bp+N^47YTS>x=5SD zOWhsj*wGDso!Ak@07deE19fnb;SG@$$%UNIdJv)?5n8BV+|j4(3#7!rIIl0iRb{PS zA;+F*%*}!AGv^aJJ(Na8SG3TkSbPx%*QJt}Xi(M;yE_56%PVS}{ot}CEGlsDl6x5W zWw9${j|zcbst~W#iryQLXRgNvx0#oSnCeXvXiQNU-(pf+H!hZu5a7r`~I=5Ij7 zIV~~fhV!ap!=nEZt6?CXwU97s78HE=*`FR+K!@WvZTd24qYyVmYc?cHS99!?T| zuwu@(o11t=mlFb`RMXVFtsn#z)y3VIv5OND$F_fR+S1_tJasW91{gV^lr-lPhLHI< zl9ie8Ay~CV#TbV?fI=|SuAlZF%_=lU^u*$$Hmg!+I_7muOhi6ZF)|{(Wez@CEe)j% zM(JvVR0gLc&{>R@O4&;g%frj4HVdYTE@1h7S9P}peHprEU}Y-e(E{*1cU=dZ^~j&!E#1VOv)2MXA7vRFXo`zT`Q8LQ* z!r&Lj=WFpOr@TX8Wm82Le7d9J=IG@L5F#u9_#A-)_sNOWXs=ysjE|tbDAEY7Rw;aY zj;Gd&PG!-dKk%k1F+#kgP|{Wrm|KD2PAbQ=Xdd?VFt&sXKJ-Md;V(}78?^P9Z0KM# z{e2QlFO`t6G}H*ZG-JQ4)avY-88wfcA@uZl`aFG}K2M*g&(r7W^YnT8Jbj)%PoJmH s)92~)^m+O`eV#r~pQq2$=jrqGdHOtko<2{X-@@nr0gAm!hyZ8-0I{U%#Q*>R From 6c96a8e35b52b14b8fc03ed319f39d634ef098fc Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 23 Nov 2016 18:07:15 -0600 Subject: [PATCH 12/41] include CLP(QR) --- Packages.cmake | 2 ++ packages/clpqr/CMakeLists.txt | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 packages/clpqr/CMakeLists.txt diff --git a/Packages.cmake b/Packages.cmake index 97b5c7ce8..9cb5b6a14 100644 --- a/Packages.cmake +++ b/Packages.cmake @@ -68,6 +68,8 @@ add_subDIRECTORY (packages/ProbLog) add_subDIRECTORY (packages/swi-minisat2) +add_subDIRECTORY (packages/clpqr) + #todo: use cmake target builds # option (USE_MAXPERFORMANCE diff --git a/packages/clpqr/CMakeLists.txt b/packages/clpqr/CMakeLists.txt new file mode 100644 index 000000000..f040f695d --- /dev/null +++ b/packages/clpqr/CMakeLists.txt @@ -0,0 +1,27 @@ +################################################################ +# SWI-Prolog CLPQR package +# Author: Jan Wielemaker. jan@swi.psy.uva.nl +# Copyright: LGPL (see COPYING or www.gnu.org +################################################################ + + +set (CLPRPRIV clpr/bb_r.pl clpr/bv_r.pl + clpr/fourmotz_r.pl clpr/ineq_r.pl + clpr/itf_r.pl clpr/nf_r.pl + clpr/store_r.pl ) +set(CLPQPRIV clpq/bb_q.pl clpq/bv_q.pl + clpq/fourmotz_q.pl clpq/ineq_q.pl + clpq/itf_q.pl clpq/nf_q.pl + clpq/store_q.pl) +set (CLPQRPRIV clpqr/class.pl clpqr/dump.pl + clpqr/geler.pl clpqr/itf.pl + clpqr/ordering.pl + clpqr/project.pl clpqr/redund.pl) +set (LIBPL clpr.pl clpq.pl ${CLPRPRIV} ${CLPQPRIV} ${CLPQRPRIV} ) + +install ( FILES ${LIBPL} DESTINATION ${libpl} ) + +# $(PL) -q -f $(srcdir)/clpr_test.pl -g test,halt -t 'halt(1)' + + + From d37e198c123cf91390603d8068f00ac30192b1e0 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Wed, 23 Nov 2016 22:35:39 -0600 Subject: [PATCH 13/41] signals doc support --- C/c_interface.c | 53 +- C/exec.c | 44 +- C/signals.c | 29 +- C/yap-args.c | 7 +- CMakeLists.txt | 6 +- H/ATOMS | 2 +- H/generated/iatoms.h | 2 +- Prelims.cmake | 10 +- docs/Doxyfile | 4 +- docs/Doxyfile.in | 14 +- docs/builtins.md | 31 - docs/download.md | 17 - docs/extensions.md | 21 - docs/fli.md | 16 - docs/jquery-2.0.3.min.js | 6 - docs/library.md | 58 - docs/load_files.md | 11 - {pl => docs/md}/attributes.md | 4 - {pl => docs/md}/modules.md | 6 +- docs/packages.md | 28 - docs/run.md | 190 -- docs/swi.md | 182 -- docs/syntax.md | 566 ------ docs/yap.md | 53 - include/YapDefs.h | 5 +- include/YapInterface.h | 1533 ----------------- library/CMakeLists.txt | 11 +- library/log2md.yap | 6 +- os/sig.c | 6 +- os/yapio.h | 6 +- packages/bdd/bdd.md | 2 +- packages/gecode/gecode.md | 2 +- packages/myddas/pl/CMakeLists.txt | 10 +- packages/myddas/sqlite3/CMakeLists.txt | 31 +- .../{ => src}/Android/AndroidManifest.xml | 0 .../sqlite3/{ => src}/Android/ant.properties | 0 .../sqlite3/{ => src}/Android/build.xml | 0 .../sqlite3/{ => src}/Android/jni/Android.mk | 0 .../{ => src}/Android/jni/Application.mk | 0 .../{ => src}/Android/jni/sqlite/ALog-priv.h | 0 .../{ => src}/Android/jni/sqlite/Android.mk | 0 .../{ => src}/Android/jni/sqlite/JNIHelp.cpp | 0 .../Android/jni/sqlite/JniConstants.cpp | 0 .../{ => src}/Android/jni/sqlite/README | 0 .../sqlite/android_database_SQLiteCommon.cpp | 0 .../sqlite/android_database_SQLiteCommon.h | 0 .../android_database_SQLiteConnection.cpp | 0 .../sqlite/android_database_SQLiteDebug.cpp | 0 .../sqlite/android_database_SQLiteGlobal.cpp | 0 .../Android/jni/sqlite/nativehelper/JNIHelp.h | 0 .../jni/sqlite/nativehelper/JniConstants.h | 0 .../jni/sqlite/nativehelper/ScopedLocalRef.h | 0 .../Android/jni/sqlite/nativehelper/jni.h | 0 .../{ => src}/Android/local.properties | 0 .../{ => src}/Android/proguard-project.txt | 0 .../{ => src}/Android/project.properties | 0 .../Android/res/drawable-hdpi/ic_launcher.png | Bin .../Android/res/drawable-ldpi/ic_launcher.png | Bin .../Android/res/drawable-mdpi/ic_launcher.png | Bin .../res/drawable-xhdpi/ic_launcher.png | Bin .../{ => src}/Android/res/layout/main.xml | 0 .../{ => src}/Android/res/values/strings.xml | 0 .../sqlite/app/customsqlite/CustomSqlite.java | 0 .../sqlite/database/DatabaseErrorHandler.java | 0 .../database/DefaultDatabaseErrorHandler.java | 0 .../src/org/sqlite/database/ExtraUtils.java | 0 .../src/org/sqlite/database/SQLException.java | 0 .../sqlite/database/sqlite/CloseGuard.java | 0 .../DatabaseObjectNotClosedException.java | 0 .../database/sqlite/SQLiteAbortException.java | 0 .../sqlite/SQLiteAccessPermException.java | 0 ...eBindOrColumnIndexOutOfRangeException.java | 0 .../sqlite/SQLiteBlobTooBigException.java | 0 .../SQLiteCantOpenDatabaseException.java | 0 .../database/sqlite/SQLiteClosable.java | 0 .../database/sqlite/SQLiteConnection.java | 0 .../database/sqlite/SQLiteConnectionPool.java | 0 .../sqlite/SQLiteConstraintException.java | 0 .../sqlite/database/sqlite/SQLiteCursor.java | 0 .../database/sqlite/SQLiteCursorDriver.java | 0 .../database/sqlite/SQLiteCustomFunction.java | 0 .../database/sqlite/SQLiteDatabase.java | 0 .../sqlite/SQLiteDatabaseConfiguration.java | 0 .../SQLiteDatabaseCorruptException.java | 0 .../sqlite/SQLiteDatabaseLockedException.java | 0 .../SQLiteDatatypeMismatchException.java | 0 .../sqlite/database/sqlite/SQLiteDebug.java | 0 .../sqlite/SQLiteDirectCursorDriver.java | 0 .../sqlite/SQLiteDiskIOException.java | 0 .../database/sqlite/SQLiteDoneException.java | 0 .../database/sqlite/SQLiteException.java | 0 .../database/sqlite/SQLiteFullException.java | 0 .../sqlite/database/sqlite/SQLiteGlobal.java | 0 .../sqlite/SQLiteMisuseException.java | 0 .../database/sqlite/SQLiteOpenHelper.java | 0 .../sqlite/SQLiteOutOfMemoryException.java | 0 .../sqlite/database/sqlite/SQLiteProgram.java | 0 .../sqlite/database/sqlite/SQLiteQuery.java | 0 .../database/sqlite/SQLiteQueryBuilder.java | 0 .../SQLiteReadOnlyDatabaseException.java | 0 .../sqlite/database/sqlite/SQLiteSession.java | 0 .../database/sqlite/SQLiteStatement.java | 0 .../database/sqlite/SQLiteStatementInfo.java | 0 .../sqlite/SQLiteTableLockedException.java | 0 .../sqlite/SQLiteTransactionListener.java | 0 .../sqlite/database/sqlite/SqliteWrapper.java | 0 .../sqlite3/{ => src}/Android/www/index.wiki | 0 packages/myddas/sqlite3/{ => src}/sqlite3.c | 0 packages/myddas/sqlite3/{ => src}/sqlite3.h | 0 .../myddas/sqlite3/{ => src}/sqlite3ext.h | 0 packages/raptor/README.md | 4 +- packages/real/README.md | 2 +- packages/swig/java/#CMakeLists.txt# | 2 +- packages/udi/udi.md | 2 +- pl/CMakeLists.txt | 6 - 115 files changed, 133 insertions(+), 2855 deletions(-) delete mode 100644 docs/builtins.md delete mode 100644 docs/download.md delete mode 100644 docs/extensions.md delete mode 100644 docs/fli.md delete mode 100644 docs/jquery-2.0.3.min.js delete mode 100644 docs/library.md delete mode 100644 docs/load_files.md rename {pl => docs/md}/attributes.md (99%) rename {pl => docs/md}/modules.md (99%) delete mode 100644 docs/packages.md delete mode 100644 docs/run.md delete mode 100644 docs/swi.md delete mode 100644 docs/syntax.md delete mode 100644 docs/yap.md rename packages/myddas/sqlite3/{ => src}/Android/AndroidManifest.xml (100%) rename packages/myddas/sqlite3/{ => src}/Android/ant.properties (100%) rename packages/myddas/sqlite3/{ => src}/Android/build.xml (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/Android.mk (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/Application.mk (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/sqlite/ALog-priv.h (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/sqlite/Android.mk (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/sqlite/JNIHelp.cpp (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/sqlite/JniConstants.cpp (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/sqlite/README (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/sqlite/android_database_SQLiteCommon.cpp (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/sqlite/android_database_SQLiteCommon.h (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/sqlite/android_database_SQLiteConnection.cpp (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/sqlite/android_database_SQLiteDebug.cpp (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/sqlite/android_database_SQLiteGlobal.cpp (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/sqlite/nativehelper/JNIHelp.h (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/sqlite/nativehelper/JniConstants.h (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/sqlite/nativehelper/ScopedLocalRef.h (100%) rename packages/myddas/sqlite3/{ => src}/Android/jni/sqlite/nativehelper/jni.h (100%) rename packages/myddas/sqlite3/{ => src}/Android/local.properties (100%) rename packages/myddas/sqlite3/{ => src}/Android/proguard-project.txt (100%) rename packages/myddas/sqlite3/{ => src}/Android/project.properties (100%) rename packages/myddas/sqlite3/{ => src}/Android/res/drawable-hdpi/ic_launcher.png (100%) rename packages/myddas/sqlite3/{ => src}/Android/res/drawable-ldpi/ic_launcher.png (100%) rename packages/myddas/sqlite3/{ => src}/Android/res/drawable-mdpi/ic_launcher.png (100%) rename packages/myddas/sqlite3/{ => src}/Android/res/drawable-xhdpi/ic_launcher.png (100%) rename packages/myddas/sqlite3/{ => src}/Android/res/layout/main.xml (100%) rename packages/myddas/sqlite3/{ => src}/Android/res/values/strings.xml (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/app/customsqlite/CustomSqlite.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/DatabaseErrorHandler.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/DefaultDatabaseErrorHandler.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/ExtraUtils.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/SQLException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/CloseGuard.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/DatabaseObjectNotClosedException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteAbortException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteAccessPermException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteBindOrColumnIndexOutOfRangeException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteBlobTooBigException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteCantOpenDatabaseException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteClosable.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteConnection.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteConnectionPool.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteConstraintException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteCursor.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteCursorDriver.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteCustomFunction.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteDatabase.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteDatabaseConfiguration.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteDatabaseCorruptException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteDatabaseLockedException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteDatatypeMismatchException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteDebug.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteDirectCursorDriver.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteDiskIOException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteDoneException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteFullException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteGlobal.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteMisuseException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteOpenHelper.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteOutOfMemoryException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteProgram.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteQuery.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteQueryBuilder.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteReadOnlyDatabaseException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteSession.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteStatement.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteStatementInfo.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteTableLockedException.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SQLiteTransactionListener.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/src/org/sqlite/database/sqlite/SqliteWrapper.java (100%) rename packages/myddas/sqlite3/{ => src}/Android/www/index.wiki (100%) rename packages/myddas/sqlite3/{ => src}/sqlite3.c (100%) rename packages/myddas/sqlite3/{ => src}/sqlite3.h (100%) rename packages/myddas/sqlite3/{ => src}/sqlite3ext.h (100%) diff --git a/C/c_interface.c b/C/c_interface.c index 54f18ccc6..f2ea41463 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -399,11 +399,11 @@ X_API Term YAP_MkAtomTerm(Atom n) { X_API Atom YAP_AtomOfTerm(Term t) { return (AtomOfTerm(t)); } X_API bool YAP_IsWideAtom(Atom a) { - const unsigned char *s = RepAtom(a)->UStrOfAE; -int32_t v; + const unsigned char *s = RepAtom(a)->UStrOfAE; + int32_t v; while (*s) { - size_t n = get_utf8(s,1,&v); - if (n>1) + size_t n = get_utf8(s, 1, &v); + if (n > 1) return true; } return false; @@ -419,15 +419,15 @@ X_API const char *YAP_AtomName(Atom a) { X_API const wchar_t *YAP_WideAtomName(Atom a) { int32_t v; const unsigned char *s = RepAtom(a)->UStrOfAE; - size_t n = strlen_utf8( s ); - wchar_t *dest = Malloc( (n+1)* sizeof(wchar_t)), *o = dest; + size_t n = strlen_utf8(s); + wchar_t *dest = Malloc((n + 1) * sizeof(wchar_t)), *o = dest; while (*s) { - size_t n = get_utf8(s,1,&v); - if (n==0) - return NULL; + size_t n = get_utf8(s, 1, &v); + if (n == 0) + return NULL; *o++ = v; } - o[0] = '\0'; + o[0] = '\0'; return dest; } @@ -452,10 +452,9 @@ X_API Atom YAP_LookupAtom(const char *c) { X_API Atom YAP_LookupWideAtom(const wchar_t *c) { CACHE_REGS Atom a; - while (TRUE) { - a = Yap_NWCharsToAtom(c, -1 USES_REGS); + a = Yap_NWCharsToAtom(c, -1 USES_REGS); if (a == NIL || Yap_get_signal(YAP_CDOVF_SIGNAL)) { if (!Yap_locked_growheap(FALSE, 0, NULL)) { Yap_Error(RESOURCE_ERROR_HEAP, TermNil, "YAP failed to grow heap: %s", @@ -490,10 +489,9 @@ X_API size_t YAP_AtomNameLength(Atom at) { if (IsBlob(at)) { return RepAtom(at)->rep.blob->length; } - unsigned char *c = RepAtom(at)->UStrOfAE; - - return strlen_utf8(c); + unsigned char *c = RepAtom(at)->UStrOfAE; + return strlen_utf8(c); } X_API Term YAP_MkVarTerm(void) { @@ -2303,10 +2301,11 @@ YAP_file_type_t YAP_Init(YAP_init_args *yap_init) { #if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA) Yap_init_yapor_global_local_memory(); #endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */ - GLOBAL_PrologShouldHandleInterrupts = yap_init->PrologShouldHandleInterrupts; + GLOBAL_PrologShouldHandleInterrupts = + !yap_init->PrologCannotHandleInterrupts && !Yap_embedded; Yap_InitSysbits(0); /* init signal handling and time, required by later functions */ - GLOBAL_argv = yap_init->Argv; + GLOBAL_argv = yap_init->Argv; GLOBAL_argc = yap_init->Argc; if (0 && ((YAP_QLY && yap_init->SavedState) || (YAP_BOOT_PL && (yap_init->YapPrologBootFile)))) { @@ -2367,10 +2366,10 @@ YAP_file_type_t YAP_Init(YAP_init_args *yap_init) { // CACHE_REGS - if (Yap_embedded) - if (yap_init->QuietMode) { - setVerbosity(TermSilent); - } + if (Yap_embedded) + if (yap_init->QuietMode) { + setVerbosity(TermSilent); + } { if (yap_init->YapPrologRCFile != NULL) { /* @@ -3208,10 +3207,10 @@ size_t YAP_UTF8_TextLength(Term t) { Term hd = HeadOfTerm(t); if (IsAtomTerm(hd)) { Atom at = AtomOfTerm(hd); - unsigned char *s = RepAtom(at)->UStrOfAE; - int32_t ch; - get_utf8(s, 1, &ch); - c = ch; + unsigned char *s = RepAtom(at)->UStrOfAE; + int32_t ch; + get_utf8(s, 1, &ch); + c = ch; } else if (IsIntegerTerm(hd)) { c = IntegerOfTerm(hd); } else { @@ -3222,8 +3221,8 @@ size_t YAP_UTF8_TextLength(Term t) { } } else if (IsAtomTerm(t)) { Atom at = AtomOfTerm(t); - sz = strlen(RepAtom(at)->StrOfAE); - } else if (IsStringTerm(t)) { + sz = strlen(RepAtom(at)->StrOfAE); + } else if (IsStringTerm(t)) { sz = strlen(StringOfTerm(t)); } return sz; diff --git a/C/exec.c b/C/exec.c index fa669c67a..374cd906b 100755 --- a/C/exec.c +++ b/C/exec.c @@ -315,9 +315,9 @@ inline static bool do_execute(Term t, Term mod USES_REGS) { /* I cannot use the standard macro here because otherwise I would dereference the argument and might skip a svar */ - if (pen->PredFlags & MetaPredFlag) { - return CallMetaCall(t, mod PASS_REGS); - } + if (pen->PredFlags & MetaPredFlag) { + return CallMetaCall(t, mod PASS_REGS); + } pt = RepAppl(t) + 1; for (i = 1; i <= arity; i++) { #if YAPOR_SBA @@ -1444,27 +1444,31 @@ static bool exec_absmi(bool top, yap_reset_t reset_mode USES_REGS) { LOCAL_PrologMode = UserMode; P = (yamop *)FAILCODE; } break; - case 2: { - /* arithmetic exception */ - /* must be done here, otherwise siglongjmp will clobber all the - * registers - */ - Yap_Error(LOCAL_Error_TYPE, TermNil, NULL); - /* reset the registers so that we don't have trash in abstract - * machine */ - Yap_set_fpu_exceptions( - getAtomicGlobalPrologFlag(ARITHMETIC_EXCEPTIONS_FLAG)); - P = (yamop *)FAILCODE; - LOCAL_PrologMode = UserMode; - } break; - case 4: { - P = (yamop *)FAILCODE; - LOCAL_PrologMode = UserMode; - } break; + case 2: { + /* arithmetic exception */ + /* must be done here, otherwise siglongjmp will clobber all the + * registers + */ + Yap_Error(LOCAL_Error_TYPE, TermNil, NULL); + /* reset the registers so that we don't have trash in abstract + * machine */ + Yap_set_fpu_exceptions( + getAtomicGlobalPrologFlag(ARITHMETIC_EXCEPTIONS_FLAG)); + P = (yamop *)FAILCODE; + LOCAL_PrologMode = UserMode; + } break; case 3: { /* saved state */ LOCAL_CBorder = OldBorder; return false; } + case 4: { + /* abort */ + /* can be called from anywgerre, must reset registers, + */ + Yap_JumpToEnv(TermDAbort); + P = (yamop *)FAILCODE; + LOCAL_PrologMode = UserMode; + } break; default: /* do nothing */ LOCAL_PrologMode = UserMode; diff --git a/C/signals.c b/C/signals.c index 9fe5c8d60..cdc3f36cd 100755 --- a/C/signals.c +++ b/C/signals.c @@ -25,18 +25,18 @@ static char SccsId[] = "%W% %G%"; #include #endif #if _WIN32 -#include #include +#include #endif -#include "Yatom.h" #include "YapHeap.h" +#include "Yatom.h" #include "eval.h" #include "yapio.h" #ifdef TABLING #include "tab.macros.h" #endif /* TABLING */ -#include #include +#include #if HAVE_STRING_H #include #endif @@ -63,7 +63,11 @@ static yap_signals InteractSIGINT(int ch) { #endif switch (ch) { case 'a': - /* abort computation */ +/* abort computation */ +#if PUSH_REGS +// restore_absmi_regs(&Yap_standard_regs); +#endif + siglongjmp(LOCAL_RestartEnv, 4); return YAP_ABORT_SIGNAL; case 'b': /* continue */ @@ -183,35 +187,32 @@ inline static bool get_signal(yap_signals sig USES_REGS) { #endif } -bool Yap_DisableInterrupts(int wid) -{ +bool Yap_DisableInterrupts(int wid) { LOCAL_InterruptsDisabled = true; YAPEnterCriticalSection(); return true; } -bool Yap_EnableInterrupts(int wid) -{ +bool Yap_EnableInterrupts(int wid) { LOCAL_InterruptsDisabled = false; YAPLeaveCriticalSection(); return true; } - /** Function called to handle delayed interrupts. */ -int Yap_HandleInterrupts(void) { +bool Yap_HandleSIGINT(void) { CACHE_REGS yap_signals sig; - if (get_signal(YAP_INT_SIGNAL PASS_REGS)) { + do { if ((sig = ProcessSIGINT()) != YAP_NO_SIGNAL) do_signal(worker_id, sig PASS_REGS); LOCAL_PrologMode &= ~InterruptMode; - return 1; - } - return 0; + return true; + } while (get_signal(YAP_INT_SIGNAL PASS_REGS)); + return false; } static Int p_creep(USES_REGS1) { diff --git a/C/yap-args.c b/C/yap-args.c index 27af5bdce..7ec1cc274 100755 --- a/C/yap-args.c +++ b/C/yap-args.c @@ -369,8 +369,7 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[], p++; } } else { - YAP_SetOutputMessage(); - + YAP_SetOutputMessage(); } break; #endif @@ -446,13 +445,13 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[], break; case 'n': if (!strcmp("nosignals", p)) { - iap->PrologShouldHandleInterrupts = FALSE; + iap->PrologCannotHandleInterrupts = true; break; } break; case '-': if (!strcmp("-nosignals", p)) { - iap->PrologShouldHandleInterrupts = FALSE; + iap->PrologCannotHandleInterrupts = true; break; } else if (!strncmp("-home=", p, strlen("-home="))) { GLOBAL_Home = p + strlen("-home="); diff --git a/CMakeLists.txt b/CMakeLists.txt index 478c0e5d3..bb7b02000 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,12 +59,12 @@ include(Sources NO_POLICY_SCOPE) include(Model NO_POLICY_SCOPE) -include_directories ( utf8proc packages/myddas packages/myddas/sqlite3) +include_directories ( utf8proc packages/myddas packages/myddas/sqlite3/src) if (ANDROID) include_directories ( - packages/myddas/sqlite3/Android/jni/sqlite - packages/myddas/sqlite3/Android/jni/sqlite/nativehelper + packages/myddas/sqlite3/src/Android/jni/sqlite + packages/myddas/sqlite3/src/Android/jni/sqlite/nativehelper ) endif (ANDROID) diff --git a/H/ATOMS b/H/ATOMS index 07ac71035..c55df189e 100644 --- a/H/ATOMS +++ b/H/ATOMS @@ -95,7 +95,7 @@ A Csult F "$csult" A CurrentModule F "$current_module" A Cut N "!" A CutBy F "$cut_by" -A DAbort F "$abort" +A DAbort N "abort" A DBLoad F "$db_load" A DBREF N "DBRef" A DBReference N "db_reference" diff --git a/H/generated/iatoms.h b/H/generated/iatoms.h index 9ebbb212f..2c247dad5 100644 --- a/H/generated/iatoms.h +++ b/H/generated/iatoms.h @@ -90,7 +90,7 @@ AtomCurrentModule = Yap_FullLookupAtom("$current_module"); TermCurrentModule = MkAtomTerm(AtomCurrentModule); AtomCut = Yap_LookupAtom("!"); TermCut = MkAtomTerm(AtomCut); AtomCutBy = Yap_FullLookupAtom("$cut_by"); TermCutBy = MkAtomTerm(AtomCutBy); - AtomDAbort = Yap_FullLookupAtom("$abort"); TermDAbort = MkAtomTerm(AtomDAbort); + AtomDAbort = Yap_LookupAtom("abort"); TermDAbort = MkAtomTerm(AtomDAbort); AtomDBLoad = Yap_FullLookupAtom("$db_load"); TermDBLoad = MkAtomTerm(AtomDBLoad); AtomDBREF = Yap_LookupAtom("DBRef"); TermDBREF = MkAtomTerm(AtomDBREF); AtomDBReference = Yap_LookupAtom("db_reference"); TermDBReference = MkAtomTerm(AtomDBReference); diff --git a/Prelims.cmake b/Prelims.cmake index d560169a7..ccc7ca5ad 100644 --- a/Prelims.cmake +++ b/Prelims.cmake @@ -128,15 +128,13 @@ endif(POLICY CMP0043) if (ANDROID) - set ( prefix ${YAP_APP_DIR}/generated ) - set ( datarootdir ${YAP_APP_DIR}/generated/assets ) -#set ( includedir "${prefix}/assets/include") - set ( libpl ${YAP_APP_DIR}/generated/assets/Yap) + set ( prefix ${YAP_APP_DIR}/build ) + set ( datarootdir ${prefix}/assets ) else() set ( prefix "${CMAKE_INSTALL_PREFIX}") set ( datarootdir ${prefix}/share ) - set ( libpl "${datarootdir}/Yap") endif() + set ( libpl ${datarootdir}/Yap) set ( includedir "${prefix}/include") set ( exec_prefix "${prefix}") set ( libdir "${exec_prefix}/lib") @@ -144,7 +142,7 @@ set ( dlls "${exec_prefix}/lib/Yap") set ( datadir "${datarootdir}") set ( mandir "${datarootdir}/man") set ( bindir "${exec_prefix}/bin") -set ( docdir "${exec_prefix}/doc/Yap") +set ( docdir "${datarootdir}/doc/Yap") set(YAP_ROOTDIR ${prefix}) diff --git a/docs/Doxyfile b/docs/Doxyfile index 59e828927..b7bd6c4c3 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -785,8 +785,8 @@ INPUT = /Users/vsc/git/yap-6.3/pl \ /Users/vsc/git/yap-6.3/library \ /Users/vsc/git/yap-6.3/packages \ /Users/vsc/git/yap-6.3/swi/library \ - /Users/vsc/git/yap-6.3/docs/*.md \ - /Users/vsc/git/yap-6.3/*.md \ + /Users/vsc/git/yap-6.3/docs/md \ + /Users/vsc/git/yap-6.3/INSTALL.md \ # This tag can be used to specify the character encoding of the source files diff --git a/docs/Doxyfile.in b/docs/Doxyfile.in index e53fe508f..c4338c1e1 100644 --- a/docs/Doxyfile.in +++ b/docs/Doxyfile.in @@ -384,7 +384,7 @@ INLINE_GROUPED_CLASSES = NO # with only public data fields or simple typedef fields will be shown inline in # the documentation of the scope in which they are defined (i.e. file, # namespace, or group documentation), provided this scope is documented. If set -v# to NO, structs, classes, and unions are shown on a separate page (for HTML and +# to NO, structs, classes, and unions are shown on a separate page (for HTML and # Man pages) or section (for LaTeX and RTF). # The default value is: NO. @@ -785,8 +785,8 @@ INPUT = @PROJECT_SOURCE_DIR@/pl \ @PROJECT_SOURCE_DIR@/library \ @PROJECT_SOURCE_DIR@/packages \ @PROJECT_SOURCE_DIR@/swi/library \ - @PROJECT_SOURCE_DIR@/docs/*.md \ - @PROJECT_SOURCE_DIR@/*.md + @PROJECT_SOURCE_DIR@/docs/md \ + @PROJECT_SOURCE_DIR@/INSTALL.md # This tag can be used to specify the character encoding of the source files @@ -827,7 +827,11 @@ RECURSIVE = YES # Note that relative paths are relative to the directory from which doxygen is # run. -EXCLUDE = *pltotex.pl +EXCLUDE = *pltotex.pl \ +@PROJECT_SOURCE_DIR@/packages/myddas/sqlite3/src \ +@PROJECT_SOURCE_DIR@/packages/gecode/4.0.* \ +@PROJECT_SOURCE_DIR@/packages/gecode/3,* \ +@PROJECT_SOURCE_DIR@/C/traced_absmi_insts.h # The EXCLUDE_SYMLINKS tag can be used to select whether or not files or # directories that are symbolic links (a Unix file system feature) are excluded @@ -1133,7 +1137,7 @@ HTML_STYLESHEET = # list). For an example see the documentation. # This tag requires that the tag GENERATE_HTML is set to YES. -HTML_EXTRA_STYLESHEET = +HTML_EXTRA_STYLESHEET = @CMAKE_SOURCE_DIR@/docs/solarized-light.css # @CMAKE_SOURCE_DIR@/docs/solarized-light.css diff --git a/docs/builtins.md b/docs/builtins.md deleted file mode 100644 index 5625441b5..000000000 --- a/docs/builtins.md +++ /dev/null @@ -1,31 +0,0 @@ -YAP Built-ins {#builtins} -================= - -This chapter describes the core predicates that control the execution of -Prolog programs, provide fundamental functionality such as termm manipulation or arithmetic, and support interaction with external -resources, Many of the predicates described here have been standardised by the ISO. The standartised subset of Proloh also known as ISO-Prolog. - -In the description of the arguments of functors the following notation -will be used: - -+ a preceding plus sign will denote an argument as an "input -argument" - it cannot be a free variable at the time of the call; -+ a preceding minus sign will denote an "output argument"; -+ an argument with no preceding symbol can be used in both ways. -+ @ref YAPControl - -+ @ref Arithmetic - -+ @ref YAPChars - -+ @ref YAP_Terms - -+ @ref InputOutput - -+ @ref AbsoluteFileName - -+ @ref YAPOS - -+ @ref Internal_Database - -+ @ref Sets diff --git a/docs/download.md b/docs/download.md deleted file mode 100644 index 492a0ce6c..000000000 --- a/docs/download.md +++ /dev/null @@ -1,17 +0,0 @@ -Downloading YAP {#download} -============== - -The latest development version of Yap-6 is yap-6.3.4 and can be -obtained from the repositories - - - -and - - - -YAP-6.3.4 does not use modules. Please just use `git clone` to obtain the distribution. - -Most of these repositories are basically copies of the original -repositories at the SWI-Prolog site. YAP-6 will work either with or -without these packages. diff --git a/docs/extensions.md b/docs/extensions.md deleted file mode 100644 index 844c2e302..000000000 --- a/docs/extensions.md +++ /dev/null @@ -1,21 +0,0 @@ -Extensions to core Prolog. {#extensions} -========================= - -YAP includes a number of extensions over the original Prolog -language. Next, we discuss how to use the most important ones. - - + @ref Rational_Trees - - + @ref AttributedVariables - - + @ref DepthLimited - - + @ref Tabling - - + @ref Threads - - + @ref Profiling - - + @ref YAPArrays - - + @ref Parallelism diff --git a/docs/fli.md b/docs/fli.md deleted file mode 100644 index 31df4b1ea..000000000 --- a/docs/fli.md +++ /dev/null @@ -1,16 +0,0 @@ -The Foreign Code Interface {#fli} -=========================== - -YAP provides the user with three facilities for writing -predicates in a language other than Prolog. Under Unix systems, -most language implementations were linkable to `C`, and the first interface exported the YAP machinery to the C language. YAP also implements most of the SWI-Prolog foreign language interface. -This gives portability with a number of SWI-Prolog packages and avoids garnage collection by using @ref slotInterface. Last, a new C++ based interface is -being designed to work with the swig (www.swig.orgv) interface compiler. - -+ The @ref c-interface exports the YAP engine. - -+ The @ref swi-c-interface emulates Jan Wielemaker's SWI foreign language interface. - -+ The @ref yap-cplus-interface is desiged to interface with the SWIG package by using Object-Oriented concepts - -+ The @ref LoadInterface handles the setup of foreign files diff --git a/docs/jquery-2.0.3.min.js b/docs/jquery-2.0.3.min.js deleted file mode 100644 index 2be209dd2..000000000 --- a/docs/jquery-2.0.3.min.js +++ /dev/null @@ -1,6 +0,0 @@ -/*! jQuery v2.0.3 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license -//@ sourceMappingURL=jquery-2.0.3.min.map -*/ -(function(e,undefined){var t,n,r=typeof undefined,i=e.location,o=e.document,s=o.documentElement,a=e.jQuery,u=e.$,l={},c=[],p="2.0.3",f=c.concat,h=c.push,d=c.slice,g=c.indexOf,m=l.toString,y=l.hasOwnProperty,v=p.trim,x=function(e,n){return new x.fn.init(e,n,t)},b=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,w=/\S+/g,T=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,C=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,k=/^-ms-/,N=/-([\da-z])/gi,E=function(e,t){return t.toUpperCase()},S=function(){o.removeEventListener("DOMContentLoaded",S,!1),e.removeEventListener("load",S,!1),x.ready()};x.fn=x.prototype={jquery:p,constructor:x,init:function(e,t,n){var r,i;if(!e)return this;if("string"==typeof e){if(r="<"===e.charAt(0)&&">"===e.charAt(e.length-1)&&e.length>=3?[null,e,null]:T.exec(e),!r||!r[1]&&t)return!t||t.jquery?(t||n).find(e):this.constructor(t).find(e);if(r[1]){if(t=t instanceof x?t[0]:t,x.merge(this,x.parseHTML(r[1],t&&t.nodeType?t.ownerDocument||t:o,!0)),C.test(r[1])&&x.isPlainObject(t))for(r in t)x.isFunction(this[r])?this[r](t[r]):this.attr(r,t[r]);return this}return i=o.getElementById(r[2]),i&&i.parentNode&&(this.length=1,this[0]=i),this.context=o,this.selector=e,this}return e.nodeType?(this.context=this[0]=e,this.length=1,this):x.isFunction(e)?n.ready(e):(e.selector!==undefined&&(this.selector=e.selector,this.context=e.context),x.makeArray(e,this))},selector:"",length:0,toArray:function(){return d.call(this)},get:function(e){return null==e?this.toArray():0>e?this[this.length+e]:this[e]},pushStack:function(e){var t=x.merge(this.constructor(),e);return t.prevObject=this,t.context=this.context,t},each:function(e,t){return x.each(this,e,t)},ready:function(e){return x.ready.promise().done(e),this},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(e){var t=this.length,n=+e+(0>e?t:0);return this.pushStack(n>=0&&t>n?[this[n]]:[])},map:function(e){return this.pushStack(x.map(this,function(t,n){return e.call(t,n,t)}))},end:function(){return this.prevObject||this.constructor(null)},push:h,sort:[].sort,splice:[].splice},x.fn.init.prototype=x.fn,x.extend=x.fn.extend=function(){var e,t,n,r,i,o,s=arguments[0]||{},a=1,u=arguments.length,l=!1;for("boolean"==typeof s&&(l=s,s=arguments[1]||{},a=2),"object"==typeof s||x.isFunction(s)||(s={}),u===a&&(s=this,--a);u>a;a++)if(null!=(e=arguments[a]))for(t in e)n=s[t],r=e[t],s!==r&&(l&&r&&(x.isPlainObject(r)||(i=x.isArray(r)))?(i?(i=!1,o=n&&x.isArray(n)?n:[]):o=n&&x.isPlainObject(n)?n:{},s[t]=x.extend(l,o,r)):r!==undefined&&(s[t]=r));return s},x.extend({expando:"jQuery"+(p+Math.random()).replace(/\D/g,""),noConflict:function(t){return e.$===x&&(e.$=u),t&&e.jQuery===x&&(e.jQuery=a),x},isReady:!1,readyWait:1,holdReady:function(e){e?x.readyWait++:x.ready(!0)},ready:function(e){(e===!0?--x.readyWait:x.isReady)||(x.isReady=!0,e!==!0&&--x.readyWait>0||(n.resolveWith(o,[x]),x.fn.trigger&&x(o).trigger("ready").off("ready")))},isFunction:function(e){return"function"===x.type(e)},isArray:Array.isArray,isWindow:function(e){return null!=e&&e===e.window},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},type:function(e){return null==e?e+"":"object"==typeof e||"function"==typeof e?l[m.call(e)]||"object":typeof e},isPlainObject:function(e){if("object"!==x.type(e)||e.nodeType||x.isWindow(e))return!1;try{if(e.constructor&&!y.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(t){return!1}return!0},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},error:function(e){throw Error(e)},parseHTML:function(e,t,n){if(!e||"string"!=typeof e)return null;"boolean"==typeof t&&(n=t,t=!1),t=t||o;var r=C.exec(e),i=!n&&[];return r?[t.createElement(r[1])]:(r=x.buildFragment([e],t,i),i&&x(i).remove(),x.merge([],r.childNodes))},parseJSON:JSON.parse,parseXML:function(e){var t,n;if(!e||"string"!=typeof e)return null;try{n=new DOMParser,t=n.parseFromString(e,"text/xml")}catch(r){t=undefined}return(!t||t.getElementsByTagName("parsererror").length)&&x.error("Invalid XML: "+e),t},noop:function(){},globalEval:function(e){var t,n=eval;e=x.trim(e),e&&(1===e.indexOf("use strict")?(t=o.createElement("script"),t.text=e,o.head.appendChild(t).parentNode.removeChild(t)):n(e))},camelCase:function(e){return e.replace(k,"ms-").replace(N,E)},nodeName:function(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()},each:function(e,t,n){var r,i=0,o=e.length,s=j(e);if(n){if(s){for(;o>i;i++)if(r=t.apply(e[i],n),r===!1)break}else for(i in e)if(r=t.apply(e[i],n),r===!1)break}else if(s){for(;o>i;i++)if(r=t.call(e[i],i,e[i]),r===!1)break}else for(i in e)if(r=t.call(e[i],i,e[i]),r===!1)break;return e},trim:function(e){return null==e?"":v.call(e)},makeArray:function(e,t){var n=t||[];return null!=e&&(j(Object(e))?x.merge(n,"string"==typeof e?[e]:e):h.call(n,e)),n},inArray:function(e,t,n){return null==t?-1:g.call(t,e,n)},merge:function(e,t){var n=t.length,r=e.length,i=0;if("number"==typeof n)for(;n>i;i++)e[r++]=t[i];else while(t[i]!==undefined)e[r++]=t[i++];return e.length=r,e},grep:function(e,t,n){var r,i=[],o=0,s=e.length;for(n=!!n;s>o;o++)r=!!t(e[o],o),n!==r&&i.push(e[o]);return i},map:function(e,t,n){var r,i=0,o=e.length,s=j(e),a=[];if(s)for(;o>i;i++)r=t(e[i],i,n),null!=r&&(a[a.length]=r);else for(i in e)r=t(e[i],i,n),null!=r&&(a[a.length]=r);return f.apply([],a)},guid:1,proxy:function(e,t){var n,r,i;return"string"==typeof t&&(n=e[t],t=e,e=n),x.isFunction(e)?(r=d.call(arguments,2),i=function(){return e.apply(t||this,r.concat(d.call(arguments)))},i.guid=e.guid=e.guid||x.guid++,i):undefined},access:function(e,t,n,r,i,o,s){var a=0,u=e.length,l=null==n;if("object"===x.type(n)){i=!0;for(a in n)x.access(e,t,a,n[a],!0,o,s)}else if(r!==undefined&&(i=!0,x.isFunction(r)||(s=!0),l&&(s?(t.call(e,r),t=null):(l=t,t=function(e,t,n){return l.call(x(e),n)})),t))for(;u>a;a++)t(e[a],n,s?r:r.call(e[a],a,t(e[a],n)));return i?e:l?t.call(e):u?t(e[0],n):o},now:Date.now,swap:function(e,t,n,r){var i,o,s={};for(o in t)s[o]=e.style[o],e.style[o]=t[o];i=n.apply(e,r||[]);for(o in t)e.style[o]=s[o];return i}}),x.ready.promise=function(t){return n||(n=x.Deferred(),"complete"===o.readyState?setTimeout(x.ready):(o.addEventListener("DOMContentLoaded",S,!1),e.addEventListener("load",S,!1))),n.promise(t)},x.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(e,t){l["[object "+t+"]"]=t.toLowerCase()});function j(e){var t=e.length,n=x.type(e);return x.isWindow(e)?!1:1===e.nodeType&&t?!0:"array"===n||"function"!==n&&(0===t||"number"==typeof t&&t>0&&t-1 in e)}t=x(o),function(e,undefined){var t,n,r,i,o,s,a,u,l,c,p,f,h,d,g,m,y,v="sizzle"+-new Date,b=e.document,w=0,T=0,C=st(),k=st(),N=st(),E=!1,S=function(e,t){return e===t?(E=!0,0):0},j=typeof undefined,D=1<<31,A={}.hasOwnProperty,L=[],q=L.pop,H=L.push,O=L.push,F=L.slice,P=L.indexOf||function(e){var t=0,n=this.length;for(;n>t;t++)if(this[t]===e)return t;return-1},R="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",W="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",$=W.replace("w","w#"),B="\\["+M+"*("+W+")"+M+"*(?:([*^$|!~]?=)"+M+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+$+")|)|)"+M+"*\\]",I=":("+W+")(?:\\(((['\"])((?:\\\\.|[^\\\\])*?)\\3|((?:\\\\.|[^\\\\()[\\]]|"+B.replace(3,8)+")*)|.*)\\)|)",z=RegExp("^"+M+"+|((?:^|[^\\\\])(?:\\\\.)*)"+M+"+$","g"),_=RegExp("^"+M+"*,"+M+"*"),X=RegExp("^"+M+"*([>+~]|"+M+")"+M+"*"),U=RegExp(M+"*[+~]"),Y=RegExp("="+M+"*([^\\]'\"]*)"+M+"*\\]","g"),V=RegExp(I),G=RegExp("^"+$+"$"),J={ID:RegExp("^#("+W+")"),CLASS:RegExp("^\\.("+W+")"),TAG:RegExp("^("+W.replace("w","w*")+")"),ATTR:RegExp("^"+B),PSEUDO:RegExp("^"+I),CHILD:RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:RegExp("^(?:"+R+")$","i"),needsContext:RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Q=/^[^{]+\{\s*\[native \w/,K=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,Z=/^(?:input|select|textarea|button)$/i,et=/^h\d$/i,tt=/'|\\/g,nt=RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),rt=function(e,t,n){var r="0x"+t-65536;return r!==r||n?t:0>r?String.fromCharCode(r+65536):String.fromCharCode(55296|r>>10,56320|1023&r)};try{O.apply(L=F.call(b.childNodes),b.childNodes),L[b.childNodes.length].nodeType}catch(it){O={apply:L.length?function(e,t){H.apply(e,F.call(t))}:function(e,t){var n=e.length,r=0;while(e[n++]=t[r++]);e.length=n-1}}}function ot(e,t,r,i){var o,s,a,u,l,f,g,m,x,w;if((t?t.ownerDocument||t:b)!==p&&c(t),t=t||p,r=r||[],!e||"string"!=typeof e)return r;if(1!==(u=t.nodeType)&&9!==u)return[];if(h&&!i){if(o=K.exec(e))if(a=o[1]){if(9===u){if(s=t.getElementById(a),!s||!s.parentNode)return r;if(s.id===a)return r.push(s),r}else if(t.ownerDocument&&(s=t.ownerDocument.getElementById(a))&&y(t,s)&&s.id===a)return r.push(s),r}else{if(o[2])return O.apply(r,t.getElementsByTagName(e)),r;if((a=o[3])&&n.getElementsByClassName&&t.getElementsByClassName)return O.apply(r,t.getElementsByClassName(a)),r}if(n.qsa&&(!d||!d.test(e))){if(m=g=v,x=t,w=9===u&&e,1===u&&"object"!==t.nodeName.toLowerCase()){f=gt(e),(g=t.getAttribute("id"))?m=g.replace(tt,"\\$&"):t.setAttribute("id",m),m="[id='"+m+"'] ",l=f.length;while(l--)f[l]=m+mt(f[l]);x=U.test(e)&&t.parentNode||t,w=f.join(",")}if(w)try{return O.apply(r,x.querySelectorAll(w)),r}catch(T){}finally{g||t.removeAttribute("id")}}}return kt(e.replace(z,"$1"),t,r,i)}function st(){var e=[];function t(n,r){return e.push(n+=" ")>i.cacheLength&&delete t[e.shift()],t[n]=r}return t}function at(e){return e[v]=!0,e}function ut(e){var t=p.createElement("div");try{return!!e(t)}catch(n){return!1}finally{t.parentNode&&t.parentNode.removeChild(t),t=null}}function lt(e,t){var n=e.split("|"),r=e.length;while(r--)i.attrHandle[n[r]]=t}function ct(e,t){var n=t&&e,r=n&&1===e.nodeType&&1===t.nodeType&&(~t.sourceIndex||D)-(~e.sourceIndex||D);if(r)return r;if(n)while(n=n.nextSibling)if(n===t)return-1;return e?1:-1}function pt(e){return function(t){var n=t.nodeName.toLowerCase();return"input"===n&&t.type===e}}function ft(e){return function(t){var n=t.nodeName.toLowerCase();return("input"===n||"button"===n)&&t.type===e}}function ht(e){return at(function(t){return t=+t,at(function(n,r){var i,o=e([],n.length,t),s=o.length;while(s--)n[i=o[s]]&&(n[i]=!(r[i]=n[i]))})})}s=ot.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return t?"HTML"!==t.nodeName:!1},n=ot.support={},c=ot.setDocument=function(e){var t=e?e.ownerDocument||e:b,r=t.defaultView;return t!==p&&9===t.nodeType&&t.documentElement?(p=t,f=t.documentElement,h=!s(t),r&&r.attachEvent&&r!==r.top&&r.attachEvent("onbeforeunload",function(){c()}),n.attributes=ut(function(e){return e.className="i",!e.getAttribute("className")}),n.getElementsByTagName=ut(function(e){return e.appendChild(t.createComment("")),!e.getElementsByTagName("*").length}),n.getElementsByClassName=ut(function(e){return e.innerHTML="
      ",e.firstChild.className="i",2===e.getElementsByClassName("i").length}),n.getById=ut(function(e){return f.appendChild(e).id=v,!t.getElementsByName||!t.getElementsByName(v).length}),n.getById?(i.find.ID=function(e,t){if(typeof t.getElementById!==j&&h){var n=t.getElementById(e);return n&&n.parentNode?[n]:[]}},i.filter.ID=function(e){var t=e.replace(nt,rt);return function(e){return e.getAttribute("id")===t}}):(delete i.find.ID,i.filter.ID=function(e){var t=e.replace(nt,rt);return function(e){var n=typeof e.getAttributeNode!==j&&e.getAttributeNode("id");return n&&n.value===t}}),i.find.TAG=n.getElementsByTagName?function(e,t){return typeof t.getElementsByTagName!==j?t.getElementsByTagName(e):undefined}:function(e,t){var n,r=[],i=0,o=t.getElementsByTagName(e);if("*"===e){while(n=o[i++])1===n.nodeType&&r.push(n);return r}return o},i.find.CLASS=n.getElementsByClassName&&function(e,t){return typeof t.getElementsByClassName!==j&&h?t.getElementsByClassName(e):undefined},g=[],d=[],(n.qsa=Q.test(t.querySelectorAll))&&(ut(function(e){e.innerHTML="",e.querySelectorAll("[selected]").length||d.push("\\["+M+"*(?:value|"+R+")"),e.querySelectorAll(":checked").length||d.push(":checked")}),ut(function(e){var n=t.createElement("input");n.setAttribute("type","hidden"),e.appendChild(n).setAttribute("t",""),e.querySelectorAll("[t^='']").length&&d.push("[*^$]="+M+"*(?:''|\"\")"),e.querySelectorAll(":enabled").length||d.push(":enabled",":disabled"),e.querySelectorAll("*,:x"),d.push(",.*:")})),(n.matchesSelector=Q.test(m=f.webkitMatchesSelector||f.mozMatchesSelector||f.oMatchesSelector||f.msMatchesSelector))&&ut(function(e){n.disconnectedMatch=m.call(e,"div"),m.call(e,"[s!='']:x"),g.push("!=",I)}),d=d.length&&RegExp(d.join("|")),g=g.length&&RegExp(g.join("|")),y=Q.test(f.contains)||f.compareDocumentPosition?function(e,t){var n=9===e.nodeType?e.documentElement:e,r=t&&t.parentNode;return e===r||!(!r||1!==r.nodeType||!(n.contains?n.contains(r):e.compareDocumentPosition&&16&e.compareDocumentPosition(r)))}:function(e,t){if(t)while(t=t.parentNode)if(t===e)return!0;return!1},S=f.compareDocumentPosition?function(e,r){if(e===r)return E=!0,0;var i=r.compareDocumentPosition&&e.compareDocumentPosition&&e.compareDocumentPosition(r);return i?1&i||!n.sortDetached&&r.compareDocumentPosition(e)===i?e===t||y(b,e)?-1:r===t||y(b,r)?1:l?P.call(l,e)-P.call(l,r):0:4&i?-1:1:e.compareDocumentPosition?-1:1}:function(e,n){var r,i=0,o=e.parentNode,s=n.parentNode,a=[e],u=[n];if(e===n)return E=!0,0;if(!o||!s)return e===t?-1:n===t?1:o?-1:s?1:l?P.call(l,e)-P.call(l,n):0;if(o===s)return ct(e,n);r=e;while(r=r.parentNode)a.unshift(r);r=n;while(r=r.parentNode)u.unshift(r);while(a[i]===u[i])i++;return i?ct(a[i],u[i]):a[i]===b?-1:u[i]===b?1:0},t):p},ot.matches=function(e,t){return ot(e,null,null,t)},ot.matchesSelector=function(e,t){if((e.ownerDocument||e)!==p&&c(e),t=t.replace(Y,"='$1']"),!(!n.matchesSelector||!h||g&&g.test(t)||d&&d.test(t)))try{var r=m.call(e,t);if(r||n.disconnectedMatch||e.document&&11!==e.document.nodeType)return r}catch(i){}return ot(t,p,null,[e]).length>0},ot.contains=function(e,t){return(e.ownerDocument||e)!==p&&c(e),y(e,t)},ot.attr=function(e,t){(e.ownerDocument||e)!==p&&c(e);var r=i.attrHandle[t.toLowerCase()],o=r&&A.call(i.attrHandle,t.toLowerCase())?r(e,t,!h):undefined;return o===undefined?n.attributes||!h?e.getAttribute(t):(o=e.getAttributeNode(t))&&o.specified?o.value:null:o},ot.error=function(e){throw Error("Syntax error, unrecognized expression: "+e)},ot.uniqueSort=function(e){var t,r=[],i=0,o=0;if(E=!n.detectDuplicates,l=!n.sortStable&&e.slice(0),e.sort(S),E){while(t=e[o++])t===e[o]&&(i=r.push(o));while(i--)e.splice(r[i],1)}return e},o=ot.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(1===i||9===i||11===i){if("string"==typeof e.textContent)return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=o(e)}else if(3===i||4===i)return e.nodeValue}else for(;t=e[r];r++)n+=o(t);return n},i=ot.selectors={cacheLength:50,createPseudo:at,match:J,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace(nt,rt),e[3]=(e[4]||e[5]||"").replace(nt,rt),"~="===e[2]&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),"nth"===e[1].slice(0,3)?(e[3]||ot.error(e[0]),e[4]=+(e[4]?e[5]+(e[6]||1):2*("even"===e[3]||"odd"===e[3])),e[5]=+(e[7]+e[8]||"odd"===e[3])):e[3]&&ot.error(e[0]),e},PSEUDO:function(e){var t,n=!e[5]&&e[2];return J.CHILD.test(e[0])?null:(e[3]&&e[4]!==undefined?e[2]=e[4]:n&&V.test(n)&&(t=gt(n,!0))&&(t=n.indexOf(")",n.length-t)-n.length)&&(e[0]=e[0].slice(0,t),e[2]=n.slice(0,t)),e.slice(0,3))}},filter:{TAG:function(e){var t=e.replace(nt,rt).toLowerCase();return"*"===e?function(){return!0}:function(e){return e.nodeName&&e.nodeName.toLowerCase()===t}},CLASS:function(e){var t=C[e+" "];return t||(t=RegExp("(^|"+M+")"+e+"("+M+"|$)"))&&C(e,function(e){return t.test("string"==typeof e.className&&e.className||typeof e.getAttribute!==j&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r){var i=ot.attr(r,e);return null==i?"!="===t:t?(i+="","="===t?i===n:"!="===t?i!==n:"^="===t?n&&0===i.indexOf(n):"*="===t?n&&i.indexOf(n)>-1:"$="===t?n&&i.slice(-n.length)===n:"~="===t?(" "+i+" ").indexOf(n)>-1:"|="===t?i===n||i.slice(0,n.length+1)===n+"-":!1):!0}},CHILD:function(e,t,n,r,i){var o="nth"!==e.slice(0,3),s="last"!==e.slice(-4),a="of-type"===t;return 1===r&&0===i?function(e){return!!e.parentNode}:function(t,n,u){var l,c,p,f,h,d,g=o!==s?"nextSibling":"previousSibling",m=t.parentNode,y=a&&t.nodeName.toLowerCase(),x=!u&&!a;if(m){if(o){while(g){p=t;while(p=p[g])if(a?p.nodeName.toLowerCase()===y:1===p.nodeType)return!1;d=g="only"===e&&!d&&"nextSibling"}return!0}if(d=[s?m.firstChild:m.lastChild],s&&x){c=m[v]||(m[v]={}),l=c[e]||[],h=l[0]===w&&l[1],f=l[0]===w&&l[2],p=h&&m.childNodes[h];while(p=++h&&p&&p[g]||(f=h=0)||d.pop())if(1===p.nodeType&&++f&&p===t){c[e]=[w,h,f];break}}else if(x&&(l=(t[v]||(t[v]={}))[e])&&l[0]===w)f=l[1];else while(p=++h&&p&&p[g]||(f=h=0)||d.pop())if((a?p.nodeName.toLowerCase()===y:1===p.nodeType)&&++f&&(x&&((p[v]||(p[v]={}))[e]=[w,f]),p===t))break;return f-=i,f===r||0===f%r&&f/r>=0}}},PSEUDO:function(e,t){var n,r=i.pseudos[e]||i.setFilters[e.toLowerCase()]||ot.error("unsupported pseudo: "+e);return r[v]?r(t):r.length>1?(n=[e,e,"",t],i.setFilters.hasOwnProperty(e.toLowerCase())?at(function(e,n){var i,o=r(e,t),s=o.length;while(s--)i=P.call(e,o[s]),e[i]=!(n[i]=o[s])}):function(e){return r(e,0,n)}):r}},pseudos:{not:at(function(e){var t=[],n=[],r=a(e.replace(z,"$1"));return r[v]?at(function(e,t,n,i){var o,s=r(e,null,i,[]),a=e.length;while(a--)(o=s[a])&&(e[a]=!(t[a]=o))}):function(e,i,o){return t[0]=e,r(t,null,o,n),!n.pop()}}),has:at(function(e){return function(t){return ot(e,t).length>0}}),contains:at(function(e){return function(t){return(t.textContent||t.innerText||o(t)).indexOf(e)>-1}}),lang:at(function(e){return G.test(e||"")||ot.error("unsupported lang: "+e),e=e.replace(nt,rt).toLowerCase(),function(t){var n;do if(n=h?t.lang:t.getAttribute("xml:lang")||t.getAttribute("lang"))return n=n.toLowerCase(),n===e||0===n.indexOf(e+"-");while((t=t.parentNode)&&1===t.nodeType);return!1}}),target:function(t){var n=e.location&&e.location.hash;return n&&n.slice(1)===t.id},root:function(e){return e===f},focus:function(e){return e===p.activeElement&&(!p.hasFocus||p.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},enabled:function(e){return e.disabled===!1},disabled:function(e){return e.disabled===!0},checked:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&!!e.checked||"option"===t&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},empty:function(e){for(e=e.firstChild;e;e=e.nextSibling)if(e.nodeName>"@"||3===e.nodeType||4===e.nodeType)return!1;return!0},parent:function(e){return!i.pseudos.empty(e)},header:function(e){return et.test(e.nodeName)},input:function(e){return Z.test(e.nodeName)},button:function(e){var t=e.nodeName.toLowerCase();return"input"===t&&"button"===e.type||"button"===t},text:function(e){var t;return"input"===e.nodeName.toLowerCase()&&"text"===e.type&&(null==(t=e.getAttribute("type"))||t.toLowerCase()===e.type)},first:ht(function(){return[0]}),last:ht(function(e,t){return[t-1]}),eq:ht(function(e,t,n){return[0>n?n+t:n]}),even:ht(function(e,t){var n=0;for(;t>n;n+=2)e.push(n);return e}),odd:ht(function(e,t){var n=1;for(;t>n;n+=2)e.push(n);return e}),lt:ht(function(e,t,n){var r=0>n?n+t:n;for(;--r>=0;)e.push(r);return e}),gt:ht(function(e,t,n){var r=0>n?n+t:n;for(;t>++r;)e.push(r);return e})}},i.pseudos.nth=i.pseudos.eq;for(t in{radio:!0,checkbox:!0,file:!0,password:!0,image:!0})i.pseudos[t]=pt(t);for(t in{submit:!0,reset:!0})i.pseudos[t]=ft(t);function dt(){}dt.prototype=i.filters=i.pseudos,i.setFilters=new dt;function gt(e,t){var n,r,o,s,a,u,l,c=k[e+" "];if(c)return t?0:c.slice(0);a=e,u=[],l=i.preFilter;while(a){(!n||(r=_.exec(a)))&&(r&&(a=a.slice(r[0].length)||a),u.push(o=[])),n=!1,(r=X.exec(a))&&(n=r.shift(),o.push({value:n,type:r[0].replace(z," ")}),a=a.slice(n.length));for(s in i.filter)!(r=J[s].exec(a))||l[s]&&!(r=l[s](r))||(n=r.shift(),o.push({value:n,type:s,matches:r}),a=a.slice(n.length));if(!n)break}return t?a.length:a?ot.error(e):k(e,u).slice(0)}function mt(e){var t=0,n=e.length,r="";for(;n>t;t++)r+=e[t].value;return r}function yt(e,t,n){var i=t.dir,o=n&&"parentNode"===i,s=T++;return t.first?function(t,n,r){while(t=t[i])if(1===t.nodeType||o)return e(t,n,r)}:function(t,n,a){var u,l,c,p=w+" "+s;if(a){while(t=t[i])if((1===t.nodeType||o)&&e(t,n,a))return!0}else while(t=t[i])if(1===t.nodeType||o)if(c=t[v]||(t[v]={}),(l=c[i])&&l[0]===p){if((u=l[1])===!0||u===r)return u===!0}else if(l=c[i]=[p],l[1]=e(t,n,a)||r,l[1]===!0)return!0}}function vt(e){return e.length>1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function xt(e,t,n,r,i){var o,s=[],a=0,u=e.length,l=null!=t;for(;u>a;a++)(o=e[a])&&(!n||n(o,r,i))&&(s.push(o),l&&t.push(a));return s}function bt(e,t,n,r,i,o){return r&&!r[v]&&(r=bt(r)),i&&!i[v]&&(i=bt(i,o)),at(function(o,s,a,u){var l,c,p,f=[],h=[],d=s.length,g=o||Ct(t||"*",a.nodeType?[a]:a,[]),m=!e||!o&&t?g:xt(g,f,e,a,u),y=n?i||(o?e:d||r)?[]:s:m;if(n&&n(m,y,a,u),r){l=xt(y,h),r(l,[],a,u),c=l.length;while(c--)(p=l[c])&&(y[h[c]]=!(m[h[c]]=p))}if(o){if(i||e){if(i){l=[],c=y.length;while(c--)(p=y[c])&&l.push(m[c]=p);i(null,y=[],l,u)}c=y.length;while(c--)(p=y[c])&&(l=i?P.call(o,p):f[c])>-1&&(o[l]=!(s[l]=p))}}else y=xt(y===s?y.splice(d,y.length):y),i?i(null,s,y,u):O.apply(s,y)})}function wt(e){var t,n,r,o=e.length,s=i.relative[e[0].type],a=s||i.relative[" "],l=s?1:0,c=yt(function(e){return e===t},a,!0),p=yt(function(e){return P.call(t,e)>-1},a,!0),f=[function(e,n,r){return!s&&(r||n!==u)||((t=n).nodeType?c(e,n,r):p(e,n,r))}];for(;o>l;l++)if(n=i.relative[e[l].type])f=[yt(vt(f),n)];else{if(n=i.filter[e[l].type].apply(null,e[l].matches),n[v]){for(r=++l;o>r;r++)if(i.relative[e[r].type])break;return bt(l>1&&vt(f),l>1&&mt(e.slice(0,l-1).concat({value:" "===e[l-2].type?"*":""})).replace(z,"$1"),n,r>l&&wt(e.slice(l,r)),o>r&&wt(e=e.slice(r)),o>r&&mt(e))}f.push(n)}return vt(f)}function Tt(e,t){var n=0,o=t.length>0,s=e.length>0,a=function(a,l,c,f,h){var d,g,m,y=[],v=0,x="0",b=a&&[],T=null!=h,C=u,k=a||s&&i.find.TAG("*",h&&l.parentNode||l),N=w+=null==C?1:Math.random()||.1;for(T&&(u=l!==p&&l,r=n);null!=(d=k[x]);x++){if(s&&d){g=0;while(m=e[g++])if(m(d,l,c)){f.push(d);break}T&&(w=N,r=++n)}o&&((d=!m&&d)&&v--,a&&b.push(d))}if(v+=x,o&&x!==v){g=0;while(m=t[g++])m(b,y,l,c);if(a){if(v>0)while(x--)b[x]||y[x]||(y[x]=q.call(f));y=xt(y)}O.apply(f,y),T&&!a&&y.length>0&&v+t.length>1&&ot.uniqueSort(f)}return T&&(w=N,u=C),b};return o?at(a):a}a=ot.compile=function(e,t){var n,r=[],i=[],o=N[e+" "];if(!o){t||(t=gt(e)),n=t.length;while(n--)o=wt(t[n]),o[v]?r.push(o):i.push(o);o=N(e,Tt(i,r))}return o};function Ct(e,t,n){var r=0,i=t.length;for(;i>r;r++)ot(e,t[r],n);return n}function kt(e,t,r,o){var s,u,l,c,p,f=gt(e);if(!o&&1===f.length){if(u=f[0]=f[0].slice(0),u.length>2&&"ID"===(l=u[0]).type&&n.getById&&9===t.nodeType&&h&&i.relative[u[1].type]){if(t=(i.find.ID(l.matches[0].replace(nt,rt),t)||[])[0],!t)return r;e=e.slice(u.shift().value.length)}s=J.needsContext.test(e)?0:u.length;while(s--){if(l=u[s],i.relative[c=l.type])break;if((p=i.find[c])&&(o=p(l.matches[0].replace(nt,rt),U.test(u[0].type)&&t.parentNode||t))){if(u.splice(s,1),e=o.length&&mt(u),!e)return O.apply(r,o),r;break}}}return a(e,f)(o,t,!h,r,U.test(e)),r}n.sortStable=v.split("").sort(S).join("")===v,n.detectDuplicates=E,c(),n.sortDetached=ut(function(e){return 1&e.compareDocumentPosition(p.createElement("div"))}),ut(function(e){return e.innerHTML="","#"===e.firstChild.getAttribute("href")})||lt("type|href|height|width",function(e,t,n){return n?undefined:e.getAttribute(t,"type"===t.toLowerCase()?1:2)}),n.attributes&&ut(function(e){return e.innerHTML="",e.firstChild.setAttribute("value",""),""===e.firstChild.getAttribute("value")})||lt("value",function(e,t,n){return n||"input"!==e.nodeName.toLowerCase()?undefined:e.defaultValue}),ut(function(e){return null==e.getAttribute("disabled")})||lt(R,function(e,t,n){var r;return n?undefined:(r=e.getAttributeNode(t))&&r.specified?r.value:e[t]===!0?t.toLowerCase():null}),x.find=ot,x.expr=ot.selectors,x.expr[":"]=x.expr.pseudos,x.unique=ot.uniqueSort,x.text=ot.getText,x.isXMLDoc=ot.isXML,x.contains=ot.contains}(e);var D={};function A(e){var t=D[e]={};return x.each(e.match(w)||[],function(e,n){t[n]=!0}),t}x.Callbacks=function(e){e="string"==typeof e?D[e]||A(e):x.extend({},e);var t,n,r,i,o,s,a=[],u=!e.once&&[],l=function(p){for(t=e.memory&&p,n=!0,s=i||0,i=0,o=a.length,r=!0;a&&o>s;s++)if(a[s].apply(p[0],p[1])===!1&&e.stopOnFalse){t=!1;break}r=!1,a&&(u?u.length&&l(u.shift()):t?a=[]:c.disable())},c={add:function(){if(a){var n=a.length;(function s(t){x.each(t,function(t,n){var r=x.type(n);"function"===r?e.unique&&c.has(n)||a.push(n):n&&n.length&&"string"!==r&&s(n)})})(arguments),r?o=a.length:t&&(i=n,l(t))}return this},remove:function(){return a&&x.each(arguments,function(e,t){var n;while((n=x.inArray(t,a,n))>-1)a.splice(n,1),r&&(o>=n&&o--,s>=n&&s--)}),this},has:function(e){return e?x.inArray(e,a)>-1:!(!a||!a.length)},empty:function(){return a=[],o=0,this},disable:function(){return a=u=t=undefined,this},disabled:function(){return!a},lock:function(){return u=undefined,t||c.disable(),this},locked:function(){return!u},fireWith:function(e,t){return!a||n&&!u||(t=t||[],t=[e,t.slice?t.slice():t],r?u.push(t):l(t)),this},fire:function(){return c.fireWith(this,arguments),this},fired:function(){return!!n}};return c},x.extend({Deferred:function(e){var t=[["resolve","done",x.Callbacks("once memory"),"resolved"],["reject","fail",x.Callbacks("once memory"),"rejected"],["notify","progress",x.Callbacks("memory")]],n="pending",r={state:function(){return n},always:function(){return i.done(arguments).fail(arguments),this},then:function(){var e=arguments;return x.Deferred(function(n){x.each(t,function(t,o){var s=o[0],a=x.isFunction(e[t])&&e[t];i[o[1]](function(){var e=a&&a.apply(this,arguments);e&&x.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[s+"With"](this===r?n.promise():this,a?[e]:arguments)})}),e=null}).promise()},promise:function(e){return null!=e?x.extend(e,r):r}},i={};return r.pipe=r.then,x.each(t,function(e,o){var s=o[2],a=o[3];r[o[1]]=s.add,a&&s.add(function(){n=a},t[1^e][2].disable,t[2][2].lock),i[o[0]]=function(){return i[o[0]+"With"](this===i?r:this,arguments),this},i[o[0]+"With"]=s.fireWith}),r.promise(i),e&&e.call(i,i),i},when:function(e){var t=0,n=d.call(arguments),r=n.length,i=1!==r||e&&x.isFunction(e.promise)?r:0,o=1===i?e:x.Deferred(),s=function(e,t,n){return function(r){t[e]=this,n[e]=arguments.length>1?d.call(arguments):r,n===a?o.notifyWith(t,n):--i||o.resolveWith(t,n)}},a,u,l;if(r>1)for(a=Array(r),u=Array(r),l=Array(r);r>t;t++)n[t]&&x.isFunction(n[t].promise)?n[t].promise().done(s(t,l,n)).fail(o.reject).progress(s(t,u,a)):--i;return i||o.resolveWith(l,n),o.promise()}}),x.support=function(t){var n=o.createElement("input"),r=o.createDocumentFragment(),i=o.createElement("div"),s=o.createElement("select"),a=s.appendChild(o.createElement("option"));return n.type?(n.type="checkbox",t.checkOn=""!==n.value,t.optSelected=a.selected,t.reliableMarginRight=!0,t.boxSizingReliable=!0,t.pixelPosition=!1,n.checked=!0,t.noCloneChecked=n.cloneNode(!0).checked,s.disabled=!0,t.optDisabled=!a.disabled,n=o.createElement("input"),n.value="t",n.type="radio",t.radioValue="t"===n.value,n.setAttribute("checked","t"),n.setAttribute("name","t"),r.appendChild(n),t.checkClone=r.cloneNode(!0).cloneNode(!0).lastChild.checked,t.focusinBubbles="onfocusin"in e,i.style.backgroundClip="content-box",i.cloneNode(!0).style.backgroundClip="",t.clearCloneStyle="content-box"===i.style.backgroundClip,x(function(){var n,r,s="padding:0;margin:0;border:0;display:block;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box",a=o.getElementsByTagName("body")[0];a&&(n=o.createElement("div"),n.style.cssText="border:0;width:0;height:0;position:absolute;top:0;left:-9999px;margin-top:1px",a.appendChild(n).appendChild(i),i.innerHTML="",i.style.cssText="-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%",x.swap(a,null!=a.style.zoom?{zoom:1}:{},function(){t.boxSizing=4===i.offsetWidth}),e.getComputedStyle&&(t.pixelPosition="1%"!==(e.getComputedStyle(i,null)||{}).top,t.boxSizingReliable="4px"===(e.getComputedStyle(i,null)||{width:"4px"}).width,r=i.appendChild(o.createElement("div")),r.style.cssText=i.style.cssText=s,r.style.marginRight=r.style.width="0",i.style.width="1px",t.reliableMarginRight=!parseFloat((e.getComputedStyle(r,null)||{}).marginRight)),a.removeChild(n))}),t):t}({});var L,q,H=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,O=/([A-Z])/g;function F(){Object.defineProperty(this.cache={},0,{get:function(){return{}}}),this.expando=x.expando+Math.random()}F.uid=1,F.accepts=function(e){return e.nodeType?1===e.nodeType||9===e.nodeType:!0},F.prototype={key:function(e){if(!F.accepts(e))return 0;var t={},n=e[this.expando];if(!n){n=F.uid++;try{t[this.expando]={value:n},Object.defineProperties(e,t)}catch(r){t[this.expando]=n,x.extend(e,t)}}return this.cache[n]||(this.cache[n]={}),n},set:function(e,t,n){var r,i=this.key(e),o=this.cache[i];if("string"==typeof t)o[t]=n;else if(x.isEmptyObject(o))x.extend(this.cache[i],t);else for(r in t)o[r]=t[r];return o},get:function(e,t){var n=this.cache[this.key(e)];return t===undefined?n:n[t]},access:function(e,t,n){var r;return t===undefined||t&&"string"==typeof t&&n===undefined?(r=this.get(e,t),r!==undefined?r:this.get(e,x.camelCase(t))):(this.set(e,t,n),n!==undefined?n:t)},remove:function(e,t){var n,r,i,o=this.key(e),s=this.cache[o];if(t===undefined)this.cache[o]={};else{x.isArray(t)?r=t.concat(t.map(x.camelCase)):(i=x.camelCase(t),t in s?r=[t,i]:(r=i,r=r in s?[r]:r.match(w)||[])),n=r.length;while(n--)delete s[r[n]]}},hasData:function(e){return!x.isEmptyObject(this.cache[e[this.expando]]||{})},discard:function(e){e[this.expando]&&delete this.cache[e[this.expando]]}},L=new F,q=new F,x.extend({acceptData:F.accepts,hasData:function(e){return L.hasData(e)||q.hasData(e)},data:function(e,t,n){return L.access(e,t,n)},removeData:function(e,t){L.remove(e,t)},_data:function(e,t,n){return q.access(e,t,n)},_removeData:function(e,t){q.remove(e,t)}}),x.fn.extend({data:function(e,t){var n,r,i=this[0],o=0,s=null;if(e===undefined){if(this.length&&(s=L.get(i),1===i.nodeType&&!q.get(i,"hasDataAttrs"))){for(n=i.attributes;n.length>o;o++)r=n[o].name,0===r.indexOf("data-")&&(r=x.camelCase(r.slice(5)),P(i,r,s[r]));q.set(i,"hasDataAttrs",!0)}return s}return"object"==typeof e?this.each(function(){L.set(this,e)}):x.access(this,function(t){var n,r=x.camelCase(e);if(i&&t===undefined){if(n=L.get(i,e),n!==undefined)return n;if(n=L.get(i,r),n!==undefined)return n;if(n=P(i,r,undefined),n!==undefined)return n}else this.each(function(){var n=L.get(this,r);L.set(this,r,t),-1!==e.indexOf("-")&&n!==undefined&&L.set(this,e,t)})},null,t,arguments.length>1,null,!0)},removeData:function(e){return this.each(function(){L.remove(this,e)})}});function P(e,t,n){var r;if(n===undefined&&1===e.nodeType)if(r="data-"+t.replace(O,"-$1").toLowerCase(),n=e.getAttribute(r),"string"==typeof n){try{n="true"===n?!0:"false"===n?!1:"null"===n?null:+n+""===n?+n:H.test(n)?JSON.parse(n):n}catch(i){}L.set(e,t,n)}else n=undefined;return n}x.extend({queue:function(e,t,n){var r;return e?(t=(t||"fx")+"queue",r=q.get(e,t),n&&(!r||x.isArray(n)?r=q.access(e,t,x.makeArray(n)):r.push(n)),r||[]):undefined},dequeue:function(e,t){t=t||"fx";var n=x.queue(e,t),r=n.length,i=n.shift(),o=x._queueHooks(e,t),s=function(){x.dequeue(e,t) -};"inprogress"===i&&(i=n.shift(),r--),i&&("fx"===t&&n.unshift("inprogress"),delete o.stop,i.call(e,s,o)),!r&&o&&o.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return q.get(e,n)||q.access(e,n,{empty:x.Callbacks("once memory").add(function(){q.remove(e,[t+"queue",n])})})}}),x.fn.extend({queue:function(e,t){var n=2;return"string"!=typeof e&&(t=e,e="fx",n--),n>arguments.length?x.queue(this[0],e):t===undefined?this:this.each(function(){var n=x.queue(this,e,t);x._queueHooks(this,e),"fx"===e&&"inprogress"!==n[0]&&x.dequeue(this,e)})},dequeue:function(e){return this.each(function(){x.dequeue(this,e)})},delay:function(e,t){return e=x.fx?x.fx.speeds[e]||e:e,t=t||"fx",this.queue(t,function(t,n){var r=setTimeout(t,e);n.stop=function(){clearTimeout(r)}})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,t){var n,r=1,i=x.Deferred(),o=this,s=this.length,a=function(){--r||i.resolveWith(o,[o])};"string"!=typeof e&&(t=e,e=undefined),e=e||"fx";while(s--)n=q.get(o[s],e+"queueHooks"),n&&n.empty&&(r++,n.empty.add(a));return a(),i.promise(t)}});var R,M,W=/[\t\r\n\f]/g,$=/\r/g,B=/^(?:input|select|textarea|button)$/i;x.fn.extend({attr:function(e,t){return x.access(this,x.attr,e,t,arguments.length>1)},removeAttr:function(e){return this.each(function(){x.removeAttr(this,e)})},prop:function(e,t){return x.access(this,x.prop,e,t,arguments.length>1)},removeProp:function(e){return this.each(function(){delete this[x.propFix[e]||e]})},addClass:function(e){var t,n,r,i,o,s=0,a=this.length,u="string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).addClass(e.call(this,t,this.className))});if(u)for(t=(e||"").match(w)||[];a>s;s++)if(n=this[s],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(W," "):" ")){o=0;while(i=t[o++])0>r.indexOf(" "+i+" ")&&(r+=i+" ");n.className=x.trim(r)}return this},removeClass:function(e){var t,n,r,i,o,s=0,a=this.length,u=0===arguments.length||"string"==typeof e&&e;if(x.isFunction(e))return this.each(function(t){x(this).removeClass(e.call(this,t,this.className))});if(u)for(t=(e||"").match(w)||[];a>s;s++)if(n=this[s],r=1===n.nodeType&&(n.className?(" "+n.className+" ").replace(W," "):"")){o=0;while(i=t[o++])while(r.indexOf(" "+i+" ")>=0)r=r.replace(" "+i+" "," ");n.className=e?x.trim(r):""}return this},toggleClass:function(e,t){var n=typeof e;return"boolean"==typeof t&&"string"===n?t?this.addClass(e):this.removeClass(e):x.isFunction(e)?this.each(function(n){x(this).toggleClass(e.call(this,n,this.className,t),t)}):this.each(function(){if("string"===n){var t,i=0,o=x(this),s=e.match(w)||[];while(t=s[i++])o.hasClass(t)?o.removeClass(t):o.addClass(t)}else(n===r||"boolean"===n)&&(this.className&&q.set(this,"__className__",this.className),this.className=this.className||e===!1?"":q.get(this,"__className__")||"")})},hasClass:function(e){var t=" "+e+" ",n=0,r=this.length;for(;r>n;n++)if(1===this[n].nodeType&&(" "+this[n].className+" ").replace(W," ").indexOf(t)>=0)return!0;return!1},val:function(e){var t,n,r,i=this[0];{if(arguments.length)return r=x.isFunction(e),this.each(function(n){var i;1===this.nodeType&&(i=r?e.call(this,n,x(this).val()):e,null==i?i="":"number"==typeof i?i+="":x.isArray(i)&&(i=x.map(i,function(e){return null==e?"":e+""})),t=x.valHooks[this.type]||x.valHooks[this.nodeName.toLowerCase()],t&&"set"in t&&t.set(this,i,"value")!==undefined||(this.value=i))});if(i)return t=x.valHooks[i.type]||x.valHooks[i.nodeName.toLowerCase()],t&&"get"in t&&(n=t.get(i,"value"))!==undefined?n:(n=i.value,"string"==typeof n?n.replace($,""):null==n?"":n)}}}),x.extend({valHooks:{option:{get:function(e){var t=e.attributes.value;return!t||t.specified?e.value:e.text}},select:{get:function(e){var t,n,r=e.options,i=e.selectedIndex,o="select-one"===e.type||0>i,s=o?null:[],a=o?i+1:r.length,u=0>i?a:o?i:0;for(;a>u;u++)if(n=r[u],!(!n.selected&&u!==i||(x.support.optDisabled?n.disabled:null!==n.getAttribute("disabled"))||n.parentNode.disabled&&x.nodeName(n.parentNode,"optgroup"))){if(t=x(n).val(),o)return t;s.push(t)}return s},set:function(e,t){var n,r,i=e.options,o=x.makeArray(t),s=i.length;while(s--)r=i[s],(r.selected=x.inArray(x(r).val(),o)>=0)&&(n=!0);return n||(e.selectedIndex=-1),o}}},attr:function(e,t,n){var i,o,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return typeof e.getAttribute===r?x.prop(e,t,n):(1===s&&x.isXMLDoc(e)||(t=t.toLowerCase(),i=x.attrHooks[t]||(x.expr.match.bool.test(t)?M:R)),n===undefined?i&&"get"in i&&null!==(o=i.get(e,t))?o:(o=x.find.attr(e,t),null==o?undefined:o):null!==n?i&&"set"in i&&(o=i.set(e,n,t))!==undefined?o:(e.setAttribute(t,n+""),n):(x.removeAttr(e,t),undefined))},removeAttr:function(e,t){var n,r,i=0,o=t&&t.match(w);if(o&&1===e.nodeType)while(n=o[i++])r=x.propFix[n]||n,x.expr.match.bool.test(n)&&(e[r]=!1),e.removeAttribute(n)},attrHooks:{type:{set:function(e,t){if(!x.support.radioValue&&"radio"===t&&x.nodeName(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}}},propFix:{"for":"htmlFor","class":"className"},prop:function(e,t,n){var r,i,o,s=e.nodeType;if(e&&3!==s&&8!==s&&2!==s)return o=1!==s||!x.isXMLDoc(e),o&&(t=x.propFix[t]||t,i=x.propHooks[t]),n!==undefined?i&&"set"in i&&(r=i.set(e,n,t))!==undefined?r:e[t]=n:i&&"get"in i&&null!==(r=i.get(e,t))?r:e[t]},propHooks:{tabIndex:{get:function(e){return e.hasAttribute("tabindex")||B.test(e.nodeName)||e.href?e.tabIndex:-1}}}}),M={set:function(e,t,n){return t===!1?x.removeAttr(e,n):e.setAttribute(n,n),n}},x.each(x.expr.match.bool.source.match(/\w+/g),function(e,t){var n=x.expr.attrHandle[t]||x.find.attr;x.expr.attrHandle[t]=function(e,t,r){var i=x.expr.attrHandle[t],o=r?undefined:(x.expr.attrHandle[t]=undefined)!=n(e,t,r)?t.toLowerCase():null;return x.expr.attrHandle[t]=i,o}}),x.support.optSelected||(x.propHooks.selected={get:function(e){var t=e.parentNode;return t&&t.parentNode&&t.parentNode.selectedIndex,null}}),x.each(["tabIndex","readOnly","maxLength","cellSpacing","cellPadding","rowSpan","colSpan","useMap","frameBorder","contentEditable"],function(){x.propFix[this.toLowerCase()]=this}),x.each(["radio","checkbox"],function(){x.valHooks[this]={set:function(e,t){return x.isArray(t)?e.checked=x.inArray(x(e).val(),t)>=0:undefined}},x.support.checkOn||(x.valHooks[this].get=function(e){return null===e.getAttribute("value")?"on":e.value})});var I=/^key/,z=/^(?:mouse|contextmenu)|click/,_=/^(?:focusinfocus|focusoutblur)$/,X=/^([^.]*)(?:\.(.+)|)$/;function U(){return!0}function Y(){return!1}function V(){try{return o.activeElement}catch(e){}}x.event={global:{},add:function(e,t,n,i,o){var s,a,u,l,c,p,f,h,d,g,m,y=q.get(e);if(y){n.handler&&(s=n,n=s.handler,o=s.selector),n.guid||(n.guid=x.guid++),(l=y.events)||(l=y.events={}),(a=y.handle)||(a=y.handle=function(e){return typeof x===r||e&&x.event.triggered===e.type?undefined:x.event.dispatch.apply(a.elem,arguments)},a.elem=e),t=(t||"").match(w)||[""],c=t.length;while(c--)u=X.exec(t[c])||[],d=m=u[1],g=(u[2]||"").split(".").sort(),d&&(f=x.event.special[d]||{},d=(o?f.delegateType:f.bindType)||d,f=x.event.special[d]||{},p=x.extend({type:d,origType:m,data:i,handler:n,guid:n.guid,selector:o,needsContext:o&&x.expr.match.needsContext.test(o),namespace:g.join(".")},s),(h=l[d])||(h=l[d]=[],h.delegateCount=0,f.setup&&f.setup.call(e,i,g,a)!==!1||e.addEventListener&&e.addEventListener(d,a,!1)),f.add&&(f.add.call(e,p),p.handler.guid||(p.handler.guid=n.guid)),o?h.splice(h.delegateCount++,0,p):h.push(p),x.event.global[d]=!0);e=null}},remove:function(e,t,n,r,i){var o,s,a,u,l,c,p,f,h,d,g,m=q.hasData(e)&&q.get(e);if(m&&(u=m.events)){t=(t||"").match(w)||[""],l=t.length;while(l--)if(a=X.exec(t[l])||[],h=g=a[1],d=(a[2]||"").split(".").sort(),h){p=x.event.special[h]||{},h=(r?p.delegateType:p.bindType)||h,f=u[h]||[],a=a[2]&&RegExp("(^|\\.)"+d.join("\\.(?:.*\\.|)")+"(\\.|$)"),s=o=f.length;while(o--)c=f[o],!i&&g!==c.origType||n&&n.guid!==c.guid||a&&!a.test(c.namespace)||r&&r!==c.selector&&("**"!==r||!c.selector)||(f.splice(o,1),c.selector&&f.delegateCount--,p.remove&&p.remove.call(e,c));s&&!f.length&&(p.teardown&&p.teardown.call(e,d,m.handle)!==!1||x.removeEvent(e,h,m.handle),delete u[h])}else for(h in u)x.event.remove(e,h+t[l],n,r,!0);x.isEmptyObject(u)&&(delete m.handle,q.remove(e,"events"))}},trigger:function(t,n,r,i){var s,a,u,l,c,p,f,h=[r||o],d=y.call(t,"type")?t.type:t,g=y.call(t,"namespace")?t.namespace.split("."):[];if(a=u=r=r||o,3!==r.nodeType&&8!==r.nodeType&&!_.test(d+x.event.triggered)&&(d.indexOf(".")>=0&&(g=d.split("."),d=g.shift(),g.sort()),c=0>d.indexOf(":")&&"on"+d,t=t[x.expando]?t:new x.Event(d,"object"==typeof t&&t),t.isTrigger=i?2:3,t.namespace=g.join("."),t.namespace_re=t.namespace?RegExp("(^|\\.)"+g.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,t.result=undefined,t.target||(t.target=r),n=null==n?[t]:x.makeArray(n,[t]),f=x.event.special[d]||{},i||!f.trigger||f.trigger.apply(r,n)!==!1)){if(!i&&!f.noBubble&&!x.isWindow(r)){for(l=f.delegateType||d,_.test(l+d)||(a=a.parentNode);a;a=a.parentNode)h.push(a),u=a;u===(r.ownerDocument||o)&&h.push(u.defaultView||u.parentWindow||e)}s=0;while((a=h[s++])&&!t.isPropagationStopped())t.type=s>1?l:f.bindType||d,p=(q.get(a,"events")||{})[t.type]&&q.get(a,"handle"),p&&p.apply(a,n),p=c&&a[c],p&&x.acceptData(a)&&p.apply&&p.apply(a,n)===!1&&t.preventDefault();return t.type=d,i||t.isDefaultPrevented()||f._default&&f._default.apply(h.pop(),n)!==!1||!x.acceptData(r)||c&&x.isFunction(r[d])&&!x.isWindow(r)&&(u=r[c],u&&(r[c]=null),x.event.triggered=d,r[d](),x.event.triggered=undefined,u&&(r[c]=u)),t.result}},dispatch:function(e){e=x.event.fix(e);var t,n,r,i,o,s=[],a=d.call(arguments),u=(q.get(this,"events")||{})[e.type]||[],l=x.event.special[e.type]||{};if(a[0]=e,e.delegateTarget=this,!l.preDispatch||l.preDispatch.call(this,e)!==!1){s=x.event.handlers.call(this,e,u),t=0;while((i=s[t++])&&!e.isPropagationStopped()){e.currentTarget=i.elem,n=0;while((o=i.handlers[n++])&&!e.isImmediatePropagationStopped())(!e.namespace_re||e.namespace_re.test(o.namespace))&&(e.handleObj=o,e.data=o.data,r=((x.event.special[o.origType]||{}).handle||o.handler).apply(i.elem,a),r!==undefined&&(e.result=r)===!1&&(e.preventDefault(),e.stopPropagation()))}return l.postDispatch&&l.postDispatch.call(this,e),e.result}},handlers:function(e,t){var n,r,i,o,s=[],a=t.delegateCount,u=e.target;if(a&&u.nodeType&&(!e.button||"click"!==e.type))for(;u!==this;u=u.parentNode||this)if(u.disabled!==!0||"click"!==e.type){for(r=[],n=0;a>n;n++)o=t[n],i=o.selector+" ",r[i]===undefined&&(r[i]=o.needsContext?x(i,this).index(u)>=0:x.find(i,this,null,[u]).length),r[i]&&r.push(o);r.length&&s.push({elem:u,handlers:r})}return t.length>a&&s.push({elem:this,handlers:t.slice(a)}),s},props:"altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(e,t){return null==e.which&&(e.which=null!=t.charCode?t.charCode:t.keyCode),e}},mouseHooks:{props:"button buttons clientX clientY offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(e,t){var n,r,i,s=t.button;return null==e.pageX&&null!=t.clientX&&(n=e.target.ownerDocument||o,r=n.documentElement,i=n.body,e.pageX=t.clientX+(r&&r.scrollLeft||i&&i.scrollLeft||0)-(r&&r.clientLeft||i&&i.clientLeft||0),e.pageY=t.clientY+(r&&r.scrollTop||i&&i.scrollTop||0)-(r&&r.clientTop||i&&i.clientTop||0)),e.which||s===undefined||(e.which=1&s?1:2&s?3:4&s?2:0),e}},fix:function(e){if(e[x.expando])return e;var t,n,r,i=e.type,s=e,a=this.fixHooks[i];a||(this.fixHooks[i]=a=z.test(i)?this.mouseHooks:I.test(i)?this.keyHooks:{}),r=a.props?this.props.concat(a.props):this.props,e=new x.Event(s),t=r.length;while(t--)n=r[t],e[n]=s[n];return e.target||(e.target=o),3===e.target.nodeType&&(e.target=e.target.parentNode),a.filter?a.filter(e,s):e},special:{load:{noBubble:!0},focus:{trigger:function(){return this!==V()&&this.focus?(this.focus(),!1):undefined},delegateType:"focusin"},blur:{trigger:function(){return this===V()&&this.blur?(this.blur(),!1):undefined},delegateType:"focusout"},click:{trigger:function(){return"checkbox"===this.type&&this.click&&x.nodeName(this,"input")?(this.click(),!1):undefined},_default:function(e){return x.nodeName(e.target,"a")}},beforeunload:{postDispatch:function(e){e.result!==undefined&&(e.originalEvent.returnValue=e.result)}}},simulate:function(e,t,n,r){var i=x.extend(new x.Event,n,{type:e,isSimulated:!0,originalEvent:{}});r?x.event.trigger(i,null,t):x.event.dispatch.call(t,i),i.isDefaultPrevented()&&n.preventDefault()}},x.removeEvent=function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n,!1)},x.Event=function(e,t){return this instanceof x.Event?(e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||e.getPreventDefault&&e.getPreventDefault()?U:Y):this.type=e,t&&x.extend(this,t),this.timeStamp=e&&e.timeStamp||x.now(),this[x.expando]=!0,undefined):new x.Event(e,t)},x.Event.prototype={isDefaultPrevented:Y,isPropagationStopped:Y,isImmediatePropagationStopped:Y,preventDefault:function(){var e=this.originalEvent;this.isDefaultPrevented=U,e&&e.preventDefault&&e.preventDefault()},stopPropagation:function(){var e=this.originalEvent;this.isPropagationStopped=U,e&&e.stopPropagation&&e.stopPropagation()},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=U,this.stopPropagation()}},x.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){x.event.special[e]={delegateType:t,bindType:t,handle:function(e){var n,r=this,i=e.relatedTarget,o=e.handleObj;return(!i||i!==r&&!x.contains(r,i))&&(e.type=o.origType,n=o.handler.apply(this,arguments),e.type=t),n}}}),x.support.focusinBubbles||x.each({focus:"focusin",blur:"focusout"},function(e,t){var n=0,r=function(e){x.event.simulate(t,e.target,x.event.fix(e),!0)};x.event.special[t]={setup:function(){0===n++&&o.addEventListener(e,r,!0)},teardown:function(){0===--n&&o.removeEventListener(e,r,!0)}}}),x.fn.extend({on:function(e,t,n,r,i){var o,s;if("object"==typeof e){"string"!=typeof t&&(n=n||t,t=undefined);for(s in e)this.on(s,t,n,e[s],i);return this}if(null==n&&null==r?(r=t,n=t=undefined):null==r&&("string"==typeof t?(r=n,n=undefined):(r=n,n=t,t=undefined)),r===!1)r=Y;else if(!r)return this;return 1===i&&(o=r,r=function(e){return x().off(e),o.apply(this,arguments)},r.guid=o.guid||(o.guid=x.guid++)),this.each(function(){x.event.add(this,e,r,n,t)})},one:function(e,t,n,r){return this.on(e,t,n,r,1)},off:function(e,t,n){var r,i;if(e&&e.preventDefault&&e.handleObj)return r=e.handleObj,x(e.delegateTarget).off(r.namespace?r.origType+"."+r.namespace:r.origType,r.selector,r.handler),this;if("object"==typeof e){for(i in e)this.off(i,t,e[i]);return this}return(t===!1||"function"==typeof t)&&(n=t,t=undefined),n===!1&&(n=Y),this.each(function(){x.event.remove(this,e,n,t)})},trigger:function(e,t){return this.each(function(){x.event.trigger(e,t,this)})},triggerHandler:function(e,t){var n=this[0];return n?x.event.trigger(e,t,n,!0):undefined}});var G=/^.[^:#\[\.,]*$/,J=/^(?:parents|prev(?:Until|All))/,Q=x.expr.match.needsContext,K={children:!0,contents:!0,next:!0,prev:!0};x.fn.extend({find:function(e){var t,n=[],r=this,i=r.length;if("string"!=typeof e)return this.pushStack(x(e).filter(function(){for(t=0;i>t;t++)if(x.contains(r[t],this))return!0}));for(t=0;i>t;t++)x.find(e,r[t],n);return n=this.pushStack(i>1?x.unique(n):n),n.selector=this.selector?this.selector+" "+e:e,n},has:function(e){var t=x(e,this),n=t.length;return this.filter(function(){var e=0;for(;n>e;e++)if(x.contains(this,t[e]))return!0})},not:function(e){return this.pushStack(et(this,e||[],!0))},filter:function(e){return this.pushStack(et(this,e||[],!1))},is:function(e){return!!et(this,"string"==typeof e&&Q.test(e)?x(e):e||[],!1).length},closest:function(e,t){var n,r=0,i=this.length,o=[],s=Q.test(e)||"string"!=typeof e?x(e,t||this.context):0;for(;i>r;r++)for(n=this[r];n&&n!==t;n=n.parentNode)if(11>n.nodeType&&(s?s.index(n)>-1:1===n.nodeType&&x.find.matchesSelector(n,e))){n=o.push(n);break}return this.pushStack(o.length>1?x.unique(o):o)},index:function(e){return e?"string"==typeof e?g.call(x(e),this[0]):g.call(this,e.jquery?e[0]:e):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(e,t){var n="string"==typeof e?x(e,t):x.makeArray(e&&e.nodeType?[e]:e),r=x.merge(this.get(),n);return this.pushStack(x.unique(r))},addBack:function(e){return this.add(null==e?this.prevObject:this.prevObject.filter(e))}});function Z(e,t){while((e=e[t])&&1!==e.nodeType);return e}x.each({parent:function(e){var t=e.parentNode;return t&&11!==t.nodeType?t:null},parents:function(e){return x.dir(e,"parentNode")},parentsUntil:function(e,t,n){return x.dir(e,"parentNode",n)},next:function(e){return Z(e,"nextSibling")},prev:function(e){return Z(e,"previousSibling")},nextAll:function(e){return x.dir(e,"nextSibling")},prevAll:function(e){return x.dir(e,"previousSibling")},nextUntil:function(e,t,n){return x.dir(e,"nextSibling",n)},prevUntil:function(e,t,n){return x.dir(e,"previousSibling",n)},siblings:function(e){return x.sibling((e.parentNode||{}).firstChild,e)},children:function(e){return x.sibling(e.firstChild)},contents:function(e){return e.contentDocument||x.merge([],e.childNodes)}},function(e,t){x.fn[e]=function(n,r){var i=x.map(this,t,n);return"Until"!==e.slice(-5)&&(r=n),r&&"string"==typeof r&&(i=x.filter(r,i)),this.length>1&&(K[e]||x.unique(i),J.test(e)&&i.reverse()),this.pushStack(i)}}),x.extend({filter:function(e,t,n){var r=t[0];return n&&(e=":not("+e+")"),1===t.length&&1===r.nodeType?x.find.matchesSelector(r,e)?[r]:[]:x.find.matches(e,x.grep(t,function(e){return 1===e.nodeType}))},dir:function(e,t,n){var r=[],i=n!==undefined;while((e=e[t])&&9!==e.nodeType)if(1===e.nodeType){if(i&&x(e).is(n))break;r.push(e)}return r},sibling:function(e,t){var n=[];for(;e;e=e.nextSibling)1===e.nodeType&&e!==t&&n.push(e);return n}});function et(e,t,n){if(x.isFunction(t))return x.grep(e,function(e,r){return!!t.call(e,r,e)!==n});if(t.nodeType)return x.grep(e,function(e){return e===t!==n});if("string"==typeof t){if(G.test(t))return x.filter(t,e,n);t=x.filter(t,e)}return x.grep(e,function(e){return g.call(t,e)>=0!==n})}var tt=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,nt=/<([\w:]+)/,rt=/<|&#?\w+;/,it=/<(?:script|style|link)/i,ot=/^(?:checkbox|radio)$/i,st=/checked\s*(?:[^=]|=\s*.checked.)/i,at=/^$|\/(?:java|ecma)script/i,ut=/^true\/(.*)/,lt=/^\s*\s*$/g,ct={option:[1,""],thead:[1,"","
      "],col:[2,"","
      "],tr:[2,"","
      "],td:[3,"","
      "],_default:[0,"",""]};ct.optgroup=ct.option,ct.tbody=ct.tfoot=ct.colgroup=ct.caption=ct.thead,ct.th=ct.td,x.fn.extend({text:function(e){return x.access(this,function(e){return e===undefined?x.text(this):this.empty().append((this[0]&&this[0].ownerDocument||o).createTextNode(e))},null,e,arguments.length)},append:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=pt(this,e);t.appendChild(e)}})},prepend:function(){return this.domManip(arguments,function(e){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var t=pt(this,e);t.insertBefore(e,t.firstChild)}})},before:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this)})},after:function(){return this.domManip(arguments,function(e){this.parentNode&&this.parentNode.insertBefore(e,this.nextSibling)})},remove:function(e,t){var n,r=e?x.filter(e,this):this,i=0;for(;null!=(n=r[i]);i++)t||1!==n.nodeType||x.cleanData(mt(n)),n.parentNode&&(t&&x.contains(n.ownerDocument,n)&&dt(mt(n,"script")),n.parentNode.removeChild(n));return this},empty:function(){var e,t=0;for(;null!=(e=this[t]);t++)1===e.nodeType&&(x.cleanData(mt(e,!1)),e.textContent="");return this},clone:function(e,t){return e=null==e?!1:e,t=null==t?e:t,this.map(function(){return x.clone(this,e,t)})},html:function(e){return x.access(this,function(e){var t=this[0]||{},n=0,r=this.length;if(e===undefined&&1===t.nodeType)return t.innerHTML;if("string"==typeof e&&!it.test(e)&&!ct[(nt.exec(e)||["",""])[1].toLowerCase()]){e=e.replace(tt,"<$1>");try{for(;r>n;n++)t=this[n]||{},1===t.nodeType&&(x.cleanData(mt(t,!1)),t.innerHTML=e);t=0}catch(i){}}t&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(){var e=x.map(this,function(e){return[e.nextSibling,e.parentNode]}),t=0;return this.domManip(arguments,function(n){var r=e[t++],i=e[t++];i&&(r&&r.parentNode!==i&&(r=this.nextSibling),x(this).remove(),i.insertBefore(n,r))},!0),t?this:this.remove()},detach:function(e){return this.remove(e,!0)},domManip:function(e,t,n){e=f.apply([],e);var r,i,o,s,a,u,l=0,c=this.length,p=this,h=c-1,d=e[0],g=x.isFunction(d);if(g||!(1>=c||"string"!=typeof d||x.support.checkClone)&&st.test(d))return this.each(function(r){var i=p.eq(r);g&&(e[0]=d.call(this,r,i.html())),i.domManip(e,t,n)});if(c&&(r=x.buildFragment(e,this[0].ownerDocument,!1,!n&&this),i=r.firstChild,1===r.childNodes.length&&(r=i),i)){for(o=x.map(mt(r,"script"),ft),s=o.length;c>l;l++)a=r,l!==h&&(a=x.clone(a,!0,!0),s&&x.merge(o,mt(a,"script"))),t.call(this[l],a,l);if(s)for(u=o[o.length-1].ownerDocument,x.map(o,ht),l=0;s>l;l++)a=o[l],at.test(a.type||"")&&!q.access(a,"globalEval")&&x.contains(u,a)&&(a.src?x._evalUrl(a.src):x.globalEval(a.textContent.replace(lt,"")))}return this}}),x.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,t){x.fn[e]=function(e){var n,r=[],i=x(e),o=i.length-1,s=0;for(;o>=s;s++)n=s===o?this:this.clone(!0),x(i[s])[t](n),h.apply(r,n.get());return this.pushStack(r)}}),x.extend({clone:function(e,t,n){var r,i,o,s,a=e.cloneNode(!0),u=x.contains(e.ownerDocument,e);if(!(x.support.noCloneChecked||1!==e.nodeType&&11!==e.nodeType||x.isXMLDoc(e)))for(s=mt(a),o=mt(e),r=0,i=o.length;i>r;r++)yt(o[r],s[r]);if(t)if(n)for(o=o||mt(e),s=s||mt(a),r=0,i=o.length;i>r;r++)gt(o[r],s[r]);else gt(e,a);return s=mt(a,"script"),s.length>0&&dt(s,!u&&mt(e,"script")),a},buildFragment:function(e,t,n,r){var i,o,s,a,u,l,c=0,p=e.length,f=t.createDocumentFragment(),h=[];for(;p>c;c++)if(i=e[c],i||0===i)if("object"===x.type(i))x.merge(h,i.nodeType?[i]:i);else if(rt.test(i)){o=o||f.appendChild(t.createElement("div")),s=(nt.exec(i)||["",""])[1].toLowerCase(),a=ct[s]||ct._default,o.innerHTML=a[1]+i.replace(tt,"<$1>")+a[2],l=a[0];while(l--)o=o.lastChild;x.merge(h,o.childNodes),o=f.firstChild,o.textContent=""}else h.push(t.createTextNode(i));f.textContent="",c=0;while(i=h[c++])if((!r||-1===x.inArray(i,r))&&(u=x.contains(i.ownerDocument,i),o=mt(f.appendChild(i),"script"),u&&dt(o),n)){l=0;while(i=o[l++])at.test(i.type||"")&&n.push(i)}return f},cleanData:function(e){var t,n,r,i,o,s,a=x.event.special,u=0;for(;(n=e[u])!==undefined;u++){if(F.accepts(n)&&(o=n[q.expando],o&&(t=q.cache[o]))){if(r=Object.keys(t.events||{}),r.length)for(s=0;(i=r[s])!==undefined;s++)a[i]?x.event.remove(n,i):x.removeEvent(n,i,t.handle);q.cache[o]&&delete q.cache[o]}delete L.cache[n[L.expando]]}},_evalUrl:function(e){return x.ajax({url:e,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0})}});function pt(e,t){return x.nodeName(e,"table")&&x.nodeName(1===t.nodeType?t:t.firstChild,"tr")?e.getElementsByTagName("tbody")[0]||e.appendChild(e.ownerDocument.createElement("tbody")):e}function ft(e){return e.type=(null!==e.getAttribute("type"))+"/"+e.type,e}function ht(e){var t=ut.exec(e.type);return t?e.type=t[1]:e.removeAttribute("type"),e}function dt(e,t){var n=e.length,r=0;for(;n>r;r++)q.set(e[r],"globalEval",!t||q.get(t[r],"globalEval"))}function gt(e,t){var n,r,i,o,s,a,u,l;if(1===t.nodeType){if(q.hasData(e)&&(o=q.access(e),s=q.set(t,o),l=o.events)){delete s.handle,s.events={};for(i in l)for(n=0,r=l[i].length;r>n;n++)x.event.add(t,i,l[i][n])}L.hasData(e)&&(a=L.access(e),u=x.extend({},a),L.set(t,u))}}function mt(e,t){var n=e.getElementsByTagName?e.getElementsByTagName(t||"*"):e.querySelectorAll?e.querySelectorAll(t||"*"):[];return t===undefined||t&&x.nodeName(e,t)?x.merge([e],n):n}function yt(e,t){var n=t.nodeName.toLowerCase();"input"===n&&ot.test(e.type)?t.checked=e.checked:("input"===n||"textarea"===n)&&(t.defaultValue=e.defaultValue)}x.fn.extend({wrapAll:function(e){var t;return x.isFunction(e)?this.each(function(t){x(this).wrapAll(e.call(this,t))}):(this[0]&&(t=x(e,this[0].ownerDocument).eq(0).clone(!0),this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstElementChild)e=e.firstElementChild;return e}).append(this)),this)},wrapInner:function(e){return x.isFunction(e)?this.each(function(t){x(this).wrapInner(e.call(this,t))}):this.each(function(){var t=x(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)})},wrap:function(e){var t=x.isFunction(e);return this.each(function(n){x(this).wrapAll(t?e.call(this,n):e)})},unwrap:function(){return this.parent().each(function(){x.nodeName(this,"body")||x(this).replaceWith(this.childNodes)}).end()}});var vt,xt,bt=/^(none|table(?!-c[ea]).+)/,wt=/^margin/,Tt=RegExp("^("+b+")(.*)$","i"),Ct=RegExp("^("+b+")(?!px)[a-z%]+$","i"),kt=RegExp("^([+-])=("+b+")","i"),Nt={BODY:"block"},Et={position:"absolute",visibility:"hidden",display:"block"},St={letterSpacing:0,fontWeight:400},jt=["Top","Right","Bottom","Left"],Dt=["Webkit","O","Moz","ms"];function At(e,t){if(t in e)return t;var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=Dt.length;while(i--)if(t=Dt[i]+n,t in e)return t;return r}function Lt(e,t){return e=t||e,"none"===x.css(e,"display")||!x.contains(e.ownerDocument,e)}function qt(t){return e.getComputedStyle(t,null)}function Ht(e,t){var n,r,i,o=[],s=0,a=e.length;for(;a>s;s++)r=e[s],r.style&&(o[s]=q.get(r,"olddisplay"),n=r.style.display,t?(o[s]||"none"!==n||(r.style.display=""),""===r.style.display&&Lt(r)&&(o[s]=q.access(r,"olddisplay",Rt(r.nodeName)))):o[s]||(i=Lt(r),(n&&"none"!==n||!i)&&q.set(r,"olddisplay",i?n:x.css(r,"display"))));for(s=0;a>s;s++)r=e[s],r.style&&(t&&"none"!==r.style.display&&""!==r.style.display||(r.style.display=t?o[s]||"":"none"));return e}x.fn.extend({css:function(e,t){return x.access(this,function(e,t,n){var r,i,o={},s=0;if(x.isArray(t)){for(r=qt(e),i=t.length;i>s;s++)o[t[s]]=x.css(e,t[s],!1,r);return o}return n!==undefined?x.style(e,t,n):x.css(e,t)},e,t,arguments.length>1)},show:function(){return Ht(this,!0)},hide:function(){return Ht(this)},toggle:function(e){return"boolean"==typeof e?e?this.show():this.hide():this.each(function(){Lt(this)?x(this).show():x(this).hide()})}}),x.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=vt(e,"opacity");return""===n?"1":n}}}},cssNumber:{columnCount:!0,fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":"cssFloat"},style:function(e,t,n,r){if(e&&3!==e.nodeType&&8!==e.nodeType&&e.style){var i,o,s,a=x.camelCase(t),u=e.style;return t=x.cssProps[a]||(x.cssProps[a]=At(u,a)),s=x.cssHooks[t]||x.cssHooks[a],n===undefined?s&&"get"in s&&(i=s.get(e,!1,r))!==undefined?i:u[t]:(o=typeof n,"string"===o&&(i=kt.exec(n))&&(n=(i[1]+1)*i[2]+parseFloat(x.css(e,t)),o="number"),null==n||"number"===o&&isNaN(n)||("number"!==o||x.cssNumber[a]||(n+="px"),x.support.clearCloneStyle||""!==n||0!==t.indexOf("background")||(u[t]="inherit"),s&&"set"in s&&(n=s.set(e,n,r))===undefined||(u[t]=n)),undefined)}},css:function(e,t,n,r){var i,o,s,a=x.camelCase(t);return t=x.cssProps[a]||(x.cssProps[a]=At(e.style,a)),s=x.cssHooks[t]||x.cssHooks[a],s&&"get"in s&&(i=s.get(e,!0,n)),i===undefined&&(i=vt(e,t,r)),"normal"===i&&t in St&&(i=St[t]),""===n||n?(o=parseFloat(i),n===!0||x.isNumeric(o)?o||0:i):i}}),vt=function(e,t,n){var r,i,o,s=n||qt(e),a=s?s.getPropertyValue(t)||s[t]:undefined,u=e.style;return s&&(""!==a||x.contains(e.ownerDocument,e)||(a=x.style(e,t)),Ct.test(a)&&wt.test(t)&&(r=u.width,i=u.minWidth,o=u.maxWidth,u.minWidth=u.maxWidth=u.width=a,a=s.width,u.width=r,u.minWidth=i,u.maxWidth=o)),a};function Ot(e,t,n){var r=Tt.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function Ft(e,t,n,r,i){var o=n===(r?"border":"content")?4:"width"===t?1:0,s=0;for(;4>o;o+=2)"margin"===n&&(s+=x.css(e,n+jt[o],!0,i)),r?("content"===n&&(s-=x.css(e,"padding"+jt[o],!0,i)),"margin"!==n&&(s-=x.css(e,"border"+jt[o]+"Width",!0,i))):(s+=x.css(e,"padding"+jt[o],!0,i),"padding"!==n&&(s+=x.css(e,"border"+jt[o]+"Width",!0,i)));return s}function Pt(e,t,n){var r=!0,i="width"===t?e.offsetWidth:e.offsetHeight,o=qt(e),s=x.support.boxSizing&&"border-box"===x.css(e,"boxSizing",!1,o);if(0>=i||null==i){if(i=vt(e,t,o),(0>i||null==i)&&(i=e.style[t]),Ct.test(i))return i;r=s&&(x.support.boxSizingReliable||i===e.style[t]),i=parseFloat(i)||0}return i+Ft(e,t,n||(s?"border":"content"),r,o)+"px"}function Rt(e){var t=o,n=Nt[e];return n||(n=Mt(e,t),"none"!==n&&n||(xt=(xt||x("