diff --git a/C/cmppreds.c b/C/cmppreds.c index 0e066d7a3..956a02836 100644 --- a/C/cmppreds.c +++ b/C/cmppreds.c @@ -728,7 +728,7 @@ static Int p_acomp(USES_REGS1) { /* $a_compare(?R,+X,+Y) */ The value of the expression _X_ is equal to the value of expression _Y_. */ -/// @memberof =:=/2 + static Int a_eq(Term t1, Term t2) { CACHE_REGS /* A =:= B */ @@ -769,7 +769,6 @@ static Int a_eq(Term t1, Term t2) { The value of the expression _X_ is different from the value of expression _Y_. */ -/// @memberof =\\=/2 static Int a_dif(Term t1, Term t2) { CACHE_REGS Int out = a_cmp(Deref(t1), Deref(t2) PASS_REGS); @@ -809,7 +808,6 @@ static Int a_ge(Term t1, Term t2) { /* A >= B */ The value of the expression _X_ is less than the value of expression _Y_. */ -/// @memberof to_visit0) { \ - to_visit--; \ - to_visit->ptd0[0] = to_visit->d0; \ - } \ - pop_text_stack(lvl); \ - return true; \ +#define CYC_LIST \ + if (IS_VISIT_MARKER) { \ + while (to_visit > to_visit0) { \ + to_visit--; \ + to_visit->ptd0[0] = to_visit->d0; \ + } \ + pop_text_stack(lvl); \ + return true; \ } -#define CYC_APPL \ - if (IS_VISIT_MARKER) { \ - while (to_visit > to_visit0) { \ - to_visit--; \ - to_visit->ptd0[0] = to_visit->d0; \ - }\ -pop_text_stack(lvl); \ - return true; \ +#define CYC_APPL \ + if (IS_VISIT_MARKER) { \ + while (to_visit > to_visit0) { \ + to_visit--; \ + to_visit->ptd0[0] = to_visit->d0; \ + } \ + pop_text_stack(lvl); \ + return true; \ } /** @@ -311,7 +311,7 @@ static Term BREAK_LOOP(Int ddep) { @brief routine to locate all variables in a term, and its applications */ static int cycles_in_complex_term(register CELL *pt0, - register CELL *pt0_end USES_REGS) { + register CELL *pt0_end USES_REGS) { int lvl = push_text_stack(); int rc = 0; @@ -320,8 +320,8 @@ static int cycles_in_complex_term(register CELL *pt0, 1024 * sizeof(struct non_single_struct_t)), *to_visit0 = to_visit, *to_visit_max = to_visit + 1024; - ptf = HR; - HR++; + ptf = HR; + HR++; while (to_visit >= to_visit0) { CELL d0; CELL *ptd0; @@ -363,6 +363,11 @@ static int cycles_in_complex_term(register CELL *pt0, /* store the terms to visit */ ptd0 = RepAppl(d0); f = (Functor)(d0 = *ptd0); + if (IS_VISIT_MARKER) { + rc++; + *ptf++ = BREAK_LOOP(to_visit - to_visit0); + continue; + } if (IsExtensionFunctor(f)) { *ptf++ = d0; continue; @@ -370,11 +375,6 @@ static int cycles_in_complex_term(register CELL *pt0, if (to_visit + 32 >= to_visit_max) { goto aux_overflow; } - if (IS_VISIT_MARKER) { - rc++; - *ptf++ = BREAK_LOOP(to_visit - to_visit0); - continue; - } *ptf++ = AbsAppl(HR); to_visit->pt0 = pt0; to_visit->pt0_end = pt0_end; @@ -1359,78 +1359,95 @@ static Term UNFOLD_LOOP(Term t, Term * b) { Term os[2], o; os[0] = o = MkVarTerm(); os[1] = t; - Term ti = Yap_MkApplTerm(FunctorEq, 2, os); - *b = MkPairTerm(ti, *b); - + Term ti = Yap_MkApplTerm(FunctorEq, 2, os), t0 = *b; + *b = MkPairTerm(ti, t0); return o; } typedef struct block_connector { - Int me; //> index in the array; + CELL * parent; //> index in the array; Term source; //> source; CELL *copy; //> copy; CELL header; //> backup of first word of the source data; CELL reference; //> term used to refer the copy. } cl_connector; -static bool dataid(Term t, cl_connector * q, int max) { - if (!IsPrimitiveTerm(t)) return 0; - if (!IsAtomTerm(t)) return max; - cl_connector *d = (cl_connector *)AtomOfTerm(t); - if (d > q && d < q+max) +static Int t_ref(cl_connector *d, cl_connector * q, int max) { + if ( d >= q && d < q+max) return d-q; - return max; //&& d->source == (void *; + return -1; //&& d->source == (void *; } -static Int create_entry(Term t, Int i, Int j, cl_connector * q, Int max) { +static Int create_entry(Term t, Int i, Int j, cl_connector * q, Int max) { Term ref, h, *s, *ostart; bool pair = false; - Int k; ssize_t n; // first time, create a new term - ostart = HR; + if (IsVarTerm(t)) { + return -1; + } if (IsPairTerm(t)) { s = RepPair(t); + h = s[0]; + if (IsAtomTerm(h)) { + return t_ref((cl_connector*)AtomOfTerm(h),q,max); + } n = 2; pair = true; + ostart = HR; ref = AbsPair(ostart); + HR += 2; + q[max].header = Deref(s[0]); } else if (IsApplTerm(t)) { h = (CELL)FunctorOfTerm(t); + n = ArityOfFunctor((Functor)h); + if (IsExtensionFunctor((Functor)h)) { + return -1; + } + if (IsAtomTerm(h)) { + return t_ref((cl_connector*)AtomOfTerm(h),q,max); + } s = RepAppl(t); - n = ArityOfFunctor(FunctorOfTerm(t)); + q[max].header = s[0]; + ostart = HR; ref = AbsAppl(ostart); *ostart++ = s[0]; - } else if ((k = dataid(t, q, max))) { - return k; - } else { + HR=ostart+n; + } else if (IsAtomTerm(t) && + (max = t_ref((cl_connector*)AtomOfTerm(t),q,max)) >= 0) { return max; + } else { + return -1; } - - - q[max].me = max; + + q[max].parent = q[i].copy+j; q[max].source = t; q[max].copy = ostart; - q[max].header = s[0]; q[max].reference = ref; - s[0] = MkAtomTerm((void*)q); - HR += n; - return max; + s[0] = MkAtomTerm((void*)(q+max)); + return max+1; } Int cp_link(Term t, Int i, Int j, cl_connector * q, Int max, CELL * tailp) { Int me; - + t = Deref(t); if ((me = create_entry(t, i, j, q, max)) < max) { + if (me < 0) { + q[i].copy[j] = t; + return max; + } Term ref = Deref(q[me].reference); - if (IsVarTerm(ref)) { q[i].copy[j] = ref; } else { - q[i].copy[j] = q[me].reference = UNFOLD_LOOP(ref, tailp); + q[i].copy[j] = + q[me].parent[0] = + UNFOLD_LOOP(ref, tailp); } return max; } - return max + 1; + q[i].copy[j] = t; + return me; } Term Yap_BreakCycles(Term inp, UInt arity, Term * listp USES_REGS) { @@ -1444,12 +1461,13 @@ Term Yap_BreakCycles(Term inp, UInt arity, Term * listp USES_REGS) { Int i = 0; HB = HR; - if (IsVarTerm(t) || dataid(t, q, qlen) == 0) { + qlen = 0; + if (IsVarTerm(t) || IsPrimitiveTerm(t)) { return t; } else { // initialization - qlen = cp_link(t, 0, 0, q, qlen, listp); - while (i < qlen) { + qlen = create_entry(Deref(t), i, 0, q, qlen); + while(icp_h; @@ -1495,7 +1504,7 @@ Term Yap_BreakCycles(Term inp, UInt arity, Term * listp USES_REGS) { */ -static Int p_break_rational(USES_REGS1) { +static Int rational_term_to_tree(USES_REGS1) { Term t = Deref(ARG1); Term l = Deref(ARG4); if (IsVarTerm(l)) @@ -1505,7 +1514,7 @@ static Int p_break_rational(USES_REGS1) { } void Yap_InitTermCPreds(void) { - Yap_InitCPred("rational_term_to_tree", 4, p_break_rational, 0); + Yap_InitCPred("cycles_in_term", 2, cycles_in_term, 0); Yap_InitCPred("term_variables", 2, p_term_variables, 0); Yap_InitCPred("term_variables", 3, p_term_variables3, 0); Yap_InitCPred("$variables_in_term", 3, variables_in_term, 0); @@ -1518,8 +1527,8 @@ void Yap_InitTermCPreds(void) { Yap_InitCPred("variable_in_term", 2, variable_in_term, 0); Yap_InitCPred("variables_within_term", 3, p_variables_within_term, 0); Yap_InitCPred("new_variables_in_term", 3, p_new_variables_in_term, 0); - Yap_InitCPred("cyles_in_term", 4, cycles_in_term, 0); CurrentModule = PROLOG_MODULE; + Yap_InitCPred("rational_term_to_tree", 4, rational_term_to_tree, 0); Yap_InitCPred("$non_singletons_in_term", 3, p_non_singletons_in_term, 0); @@ -1529,3 +1538,4 @@ void Yap_InitTermCPreds(void) { Yap_InitCPred("numbervars", 3, p_numbervars, 0); Yap_InitCPred("largest_numbervar", 2, largest_numbervar, 0); } +//@} diff --git a/docs/md/lib.md b/docs/md/lib.md index a3e28e4e4..8a6a62155 100644 --- a/docs/md/lib.md +++ b/docs/md/lib.md @@ -1,5 +1,5 @@ -@file LIBRARY.md +@file lib.md @defgroup library YAP Prolog Library diff --git a/library/autoloader.yap b/library/autoloader.yap index 621ade734..486a38656 100644 --- a/library/autoloader.yap +++ b/library/autoloader.yap @@ -1,5 +1,5 @@ /** - * @file autoloader.yap + * */ :- module(autoloader,[make_library_index/0]). diff --git a/library/charsio.yap b/library/charsio.yap index 150e4b8e4..f6efc7ca8 100644 --- a/library/charsio.yap +++ b/library/charsio.yap @@ -24,7 +24,10 @@ * @{ * */ - +%% @file charsio.yap +%% +%% +%% @brief Input/Output to characters. :- module(system(charsio), [ format_to_chars/3, @@ -52,7 +55,7 @@ You can use the following directive to load the files. ~~~~~~~ -:- use_module(library(avl)). +:- use_module(library(charsio)). ~~~~~~~ It includes the following predicates: diff --git a/library/coinduction.yap b/library/coinduction.yap index 9552a72fd..c85d54c8d 100644 --- a/library/coinduction.yap +++ b/library/coinduction.yap @@ -154,6 +154,10 @@ co_term_expansion((H :- B), M, (NH :- B)) :- !, co_term_expansion(H, M, NH) :- coinductive(H, M, NH), !. +/** user:term_expansion(+M:Cl,-M:NCl ) + +rule preprocessor +*/ user:term_expansion(M:Cl,M:NCl ) :- !, co_term_expansion(Cl, M, NCl). diff --git a/library/ytest/preds.yap b/library/ytest/preds.yap index ef8f42949..c0d27e50a 100644 --- a/library/ytest/preds.yap +++ b/library/ytest/preds.yap @@ -52,6 +52,10 @@ functor(G, F, N), predicate_property(M:G, meta_predicate(P)). +/** user:term_expansion(+M:Cl,-M:NCl ) + +rule preprocessor +*/ user:term_expansion( ( :- '$meta_predicate'( _ ) ), [] ). user:goal_expansion(_:'_user_expand_goal'(A, M, B), user:user_expand_goal(A, M, B) ). diff --git a/packages/ProbLog/problog/flags.yap b/packages/ProbLog/problog/flags.yap index 975f4ae71..9564d7515 100644 --- a/packages/ProbLog/problog/flags.yap +++ b/packages/ProbLog/problog/flags.yap @@ -204,7 +204,7 @@ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% @file problog/flags +%% @file problog/flags.yap :-module(flags, [problog_define_flag/4, problog_define_flag/5, diff --git a/packages/gecode/gecode6_yap_hand_written.yap b/packages/gecode/gecode6_yap_hand_written.yap index 3eff8c69b..b61f5027a 100644 --- a/packages/gecode/gecode6_yap_hand_written.yap +++ b/packages/gecode/gecode6_yap_hand_written.yap @@ -1343,3 +1343,4 @@ keep_list_(_, X) :- (Space += keep(X)) :- !, keep_(Space,X). %! @} +%! @} diff --git a/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap b/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap index 4e1eab760..67f411aed 100644 --- a/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap +++ b/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap @@ -1,6 +1,6 @@ /** - * @file jupyter.yap4py + * @file jupyter.yap * * @brief JUpyter support. */ diff --git a/packages/python/yap_kernel/yap_ipython/prolog/verify.yap b/packages/python/yap_kernel/yap_ipython/prolog/verify.yap index 4bf8330b0..93cad3f1b 100644 --- a/packages/python/yap_kernel/yap_ipython/prolog/verify.yap +++ b/packages/python/yap_kernel/yap_ipython/prolog/verify.yap @@ -1,5 +1,5 @@ /** - * @file jupyter.yap4py + * @file verify.yap * * @brief JUpyter support. */ diff --git a/pl/attributes.yap b/pl/attributes.yap index 1a1ff8aec..d81047d4a 100644 --- a/pl/attributes.yap +++ b/pl/attributes.yap @@ -18,7 +18,7 @@ /** @file attributes.yap -@defgroup New_Style_Attribute_Declarations SWI Compatible attributes +@defgroup New_Style_Attribute_Declarations hProlog and SWI-Prolog style Attribute Declarations @ingroup attributes @{ diff --git a/pl/boot.yap b/pl/boot.yap index 49b5d1ae9..3e6660197 100644 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -114,6 +114,10 @@ print_message(Type,error(_,exception(Desc))) :- '$get_exception'(Desc), print_boot_message(Type,Error,Desc), '$print_exception'(Desc), +print_message(Type,warning(_,exception(Desc))) :- + '$get_exception'(Desc), + print_boot_message(Type,Error,Desc), + '$print_exception'(Desc), !. print_message(Type,Error) :- format( user_error, '~w while bootstraping: event is ~q~n',[Type,Error]). diff --git a/pl/consult.yap b/pl/consult.yap index 2d57cfb09..ef4654cbd 100644 --- a/pl/consult.yap +++ b/pl/consult.yap @@ -862,7 +862,6 @@ nb_setval('$if_level',0). '__NB_getval__'('$lf_status', TOpts, fail), '$lf_opt'( initialization, TOpts, Ref), nb:nb_queue_close(Ref, Answers, []), - writeln(init:Answers), '$process_init_goal'(Answers). '$exec_initialization_goals'. diff --git a/pl/imports.yap b/pl/imports.yap index 606d9981a..6ed6b00c3 100644 --- a/pl/imports.yap +++ b/pl/imports.yap @@ -1,5 +1,5 @@ /** - ** @file imports.yapi + ** @file imports.yap * * @brief Module systemm code to import predicates * diff --git a/pl/os.yap b/pl/os.yap index c8fde94fc..6003f410c 100644 --- a/pl/os.yap +++ b/pl/os.yap @@ -9,7 +9,7 @@ *************************************************************************/ /** - * @file os.yap + * @file pl/os.yap */ :- system_module( '$os', [ cd/0, diff --git a/pl/preds.yap b/pl/preds.yap index 9cb45460b..379230edd 100644 --- a/pl/preds.yap +++ b/pl/preds.yap @@ -16,7 +16,7 @@ *************************************************************************/ /** - * @file preds.yap + * @file pl/preds.yap */ :- system_module( '$_preds', [abolish/1, abolish/2, diff --git a/swi/library/autoloader.yap b/swi/library/autoloader.yap index b37ac4102..7f8d4a9c0 100644 --- a/swi/library/autoloader.yap +++ b/swi/library/autoloader.yap @@ -1,5 +1,5 @@ /** - * @file autoloader.yap + * @file swi/library/autoloader.yap */ :- module(autoloader,[make_library_index/0]).