This commit is contained in:
Vitor Santos Costa 2019-02-04 15:10:06 +00:00
parent d874dc5857
commit cb4d17cb4f
3 changed files with 26 additions and 58 deletions

View File

@ -169,9 +169,8 @@ typedef struct non_single_struct_t {
to_visit++; \ to_visit++; \
d0 = ptd0[0]; \ d0 = ptd0[0]; \
pt0 = ptd0; \ pt0 = ptd0; \
*ptd0 = TermFreeTerm; \ *pt0 = TermFreeTerm; \
pt0_end = pt0 + 1; \ pt0_end = pt0 + 1; \
if (pt0 <= pt0_end) \
goto list_loop; \ goto list_loop; \
} else if (IsApplTerm(d0)) { \ } else if (IsApplTerm(d0)) { \
register Functor f; \ register Functor f; \
@ -651,7 +650,7 @@ static Term attvars_in_complex_term(register CELL *pt0, register CELL *pt0_end,
Term inp USES_REGS) { Term inp USES_REGS) {
register tr_fr_ptr TR0 = TR; register tr_fr_ptr TR0 = TR;
CELL *InitialH = HR; CELL *InitialH = HR;
CELL output = AbsPair(HR); CELL output = inp;
WALK_COMPLEX_TERM(); WALK_COMPLEX_TERM();
@ -664,9 +663,7 @@ static Term attvars_in_complex_term(register CELL *pt0, register CELL *pt0_end,
if (HR + 1024 > ASP) { if (HR + 1024 > ASP) {
goto global_overflow; goto global_overflow;
} }
HR[1] = AbsPair(HR + 2); output = MkPairTerm( (CELL) & (a0->Done), output);
HR += 2;
HR[-2] = (CELL) & (a0->Done);
/* store the terms to visit */ /* store the terms to visit */
if (to_visit + 32 >= to_visit_max) { if (to_visit + 32 >= to_visit_max) {
goto aux_overflow; goto aux_overflow;
@ -704,10 +701,9 @@ static Term attvars_in_complex_term(register CELL *pt0, register CELL *pt0_end,
} else { } else {
HR[-1] = t2; /* don't need to trail */ HR[-1] = t2; /* don't need to trail */
} }
return (output);
} else {
return (inp);
} }
return (output);
def_aux_overflow(); def_aux_overflow();
def_global_overflow(); def_global_overflow();
@ -1179,7 +1175,7 @@ static Int numbervars_in_complex_term(CELL *pt0, CELL *pt0_end, Int numbv,
WALK_COMPLEX_TERM__({}, RENUMBER_SINGLES, {}); WALK_COMPLEX_TERM__({}, RENUMBER_SINGLES, {});
/* do or pt2 are unbound */ /* do or pt2 are unbound */
if (singles) if (singles||false)
*ptd0 = numbervar_singleton(PASS_REGS1); *ptd0 = numbervar_singleton(PASS_REGS1);
else else
*ptd0 = numbervar(numbv++ PASS_REGS); *ptd0 = numbervar(numbv++ PASS_REGS);
@ -1336,15 +1332,13 @@ static Term BREAK_LOOP(int ddep) {
return Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("@^"), 1), 1, &t0); return Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("@^"), 1), 1, &t0);
} }
static Term UNFOLD_LOOP(Term t, Term *b, Term l) { static Term UNFOLD_LOOP(Term t, Term *b) {
Term ti = Yap_MkNewApplTerm(FunctorEq, 2); Term os[2], o;
RepAppl(ti)[2] = t; os[0] = o = MkVarTerm();
Term o = RepAppl(ti)[1]; os[1] = t;
HR[0] = ti; Term ti = Yap_MkApplTerm(FunctorEq, 2, os);
HR[1] = l; *b = MkPairTerm(ti, *b);
*b = AbsPair(HR);
b = HR + 1;
HR += 2;
return o; return o;
} }
@ -1358,13 +1352,13 @@ static int loops_in_complex_term(CELL *pt0, CELL *pt0_end,
*to_visit0 = to_visit, *to_visit0 = to_visit,
*to_visit_max = to_visit + 1024; *to_visit_max = to_visit + 1024;
to_visit0 = to_visit; CELL *ptf = HR;
to_visit_max = to_visit0 + 1024; CELL *ptd0;
CELL *ptf = HR-1; if (listp)
*listp = tail;
restart: restart:
while (pt0 < pt0_end) { while (pt0 < pt0_end) {
CELL d0; CELL d0;
CELL *ptd0;
++pt0; ++pt0;
ptd0 = pt0; ptd0 = pt0;
d0 = *ptd0; d0 = *ptd0;
@ -1383,7 +1377,7 @@ restart:
struct non_single_struct_t *v0 = struct non_single_struct_t *v0 =
(struct non_single_struct_t *)AtomOfTerm(d0); (struct non_single_struct_t *)AtomOfTerm(d0);
if (listp) { if (listp) {
*ptf = UNFOLD_LOOP(AbsPair(v0->ptf-1), listp, tail); *ptf = UNFOLD_LOOP(AbsPair(v0->ptf-1), listp);
ptf++; ptf++;
} else { } else {
*ptf++ = BREAK_LOOP(to_visit - v0); *ptf++ = BREAK_LOOP(to_visit - v0);
@ -1417,7 +1411,7 @@ restart:
if (IsAtomTerm((CELL)f)) { if (IsAtomTerm((CELL)f)) {
struct non_single_struct_t *v0 = (struct non_single_struct_t *)AtomOfTerm(*ap2); struct non_single_struct_t *v0 = (struct non_single_struct_t *)AtomOfTerm(*ap2);
if (listp) { if (listp) {
*ptf = UNFOLD_LOOP(AbsAppl(v0->ptf-1), listp, tail); *ptf = UNFOLD_LOOP(AbsAppl(v0->ptf-1), listp);
ptf++; ptf++;
} else { } else {
*ptf++ = BREAK_LOOP(to_visit - v0); *ptf++ = BREAK_LOOP(to_visit - v0);
@ -1429,7 +1423,6 @@ restart:
goto aux_overflow; goto aux_overflow;
} }
*ptf++ = AbsAppl(HR); *ptf++ = AbsAppl(HR);
HR[0] = (CELL)f;
to_visit->pt0 = pt0; to_visit->pt0 = pt0;
to_visit->pt0_end = pt0_end; to_visit->pt0_end = pt0_end;
to_visit->ptd0 = ap2; to_visit->ptd0 = ap2;
@ -1439,6 +1432,7 @@ restart:
to_visit++; to_visit++;
pt0 = ap2; pt0 = ap2;
pt0_end = ap2 + (ArityOfFunctor(f)); pt0_end = ap2 + (ArityOfFunctor(f));
HR[0] = (CELL)f;
ptf = HR+1; ptf = HR+1;
HR = ptf +ArityOfFunctor(f); HR = ptf +ArityOfFunctor(f);
} else { } else {
@ -1457,7 +1451,7 @@ restart:
pt0 = to_visit->pt0; pt0 = to_visit->pt0;
ptf = to_visit->ptf; ptf = to_visit->ptf;
pt0_end = to_visit->pt0_end; pt0_end = to_visit->pt0_end;
CELL *ptd0 = to_visit->ptd0; ptd0 = to_visit->ptd0;
*ptd0 = to_visit->d0; *ptd0 = to_visit->d0;
goto restart; goto restart;
} }
@ -1475,7 +1469,6 @@ Term Yap_BreakCycles(Term inp, UInt arity, Term *listp, Term tail USES_REGS) {
} else { } else {
Int res; Int res;
CELL *op = HR; CELL *op = HR;
HR++;
res = loops_in_complex_term((&t) - 1, &t, listp, tail PASS_REGS); res = loops_in_complex_term((&t) - 1, &t, listp, tail PASS_REGS);
if (res < 0) if (res < 0)
return -1; return -1;

View File

@ -33,35 +33,7 @@
/* /*
% grounds all free variables % grounds all free variables
% as terms of the form '$VAR'(N) % as terms of the form '$VAR'(N)
*/
numbervars('$VAR'(M), M, N) :- !,
succ(M, N).
numbervars(Atomic, M, M) :-
atomic(Atomic), !.
numbervars(Term, M, N) :-
functor(Term, _, Arity),
'$numbervars'(0,Arity, Term, M, N).
'$numbervars'(A, A, _, N, N) :- !.
'$numbervars'(A,Arity, Term, M, N) :-
'$succ'(A,An),
arg(An, Term, Arg),
numbervars(Arg, M, K), !,
'$numbervars'(An, Arity, Term, K, N).
ground(Term) :-
nonvar(Term), % This term is not a variable,
functor(Term, _, Arity),
'$ground'(Arity, Term). % and none of its arguments are.
'$ground'(0, _) :- !.
'$ground'(N, Term) :-
'$predc'(N,M),
arg(N, Term, ArgN),
ground(ArgN),
'$ground'(M, Term).
numbervars(Term, M, N) :- numbervars(Term, M, N) :-
'$variables_in_term'(Term, [], L), '$variables_in_term'(Term, [], L),
'$numbermarked_vars'(L, M, N). '$numbermarked_vars'(L, M, N).

View File

@ -18,7 +18,8 @@ main :-
writeln('-----------------------'), writeln('-----------------------'),
fail. fail.
main :- main :-
main((rational_term_to_tree(X,A,B,[]),writeln(A:B)), X). main((rational_term_to_tree(X,A,B,[]), numbervars(A+B,1,_),
writeln((A->B))), X).
main. main.
main(G, X) :- main(G, X) :-
@ -51,6 +52,8 @@ d(X) :- X= f(X,[X,X]).
d(X) :- X= f(X,[X,g(X)]). d(X) :- X= f(X,[X,g(X)]).
d(X) :- X= f(_,X/[X]). d(X) :- X= f(_,X/[X]).
d(X) :- X= f(_,A/[A]), A= f(X,[X,g(X)]). d(X) :- X= f(_,A/[A]), A= f(X,[X,g(X)]).
d(X) :- X= f(_,A/[A]), A= f(X,[A,g(X)]).
d(X) :- X= f(_,A/[A]), A= f(B,[X,g(A)]), B=[C|B], C=[X].
end :- writeln('....'), fail. end :- writeln('....'), fail.