fix cyclic_term mess up from yesterday.
This commit is contained in:
parent
a3757ddbd7
commit
e60b485134
@ -436,6 +436,11 @@ p_cyclic( USES_REGS1 )
|
||||
return rational_tree(t);
|
||||
}
|
||||
|
||||
int Yap_IsAcyclicTerm(Term t)
|
||||
{
|
||||
return !rational_tree(t);
|
||||
}
|
||||
|
||||
static Int
|
||||
p_acyclic( USES_REGS1 )
|
||||
{
|
||||
|
164
C/utilpreds.c
164
C/utilpreds.c
@ -2927,168 +2927,6 @@ static Int ground_complex_term(register CELL *pt0, register CELL *pt0_end USES_R
|
||||
return -1;
|
||||
}
|
||||
|
||||
static Int finite_tree_complex_term(register CELL *pt0, register CELL *pt0_end USES_REGS)
|
||||
{
|
||||
|
||||
register CELL **to_visit0, **to_visit = (CELL **)Yap_PreAllocCodeSpace();
|
||||
|
||||
to_visit0 = to_visit;
|
||||
loop:
|
||||
while (pt0 < pt0_end) {
|
||||
register CELL d0;
|
||||
register CELL *ptd0;
|
||||
|
||||
++pt0;
|
||||
ptd0 = pt0;
|
||||
d0 = *ptd0;
|
||||
deref_head(d0, vars_in_term_unk);
|
||||
vars_in_term_nvar:
|
||||
{
|
||||
if (d0 == TermFoundVar) {
|
||||
#ifdef RATIONAL_TREES
|
||||
while (to_visit > to_visit0) {
|
||||
to_visit -= 3;
|
||||
pt0 = to_visit[0];
|
||||
pt0_end = to_visit[1];
|
||||
*pt0 = (CELL)to_visit[2];
|
||||
}
|
||||
#endif
|
||||
return FALSE;
|
||||
}
|
||||
if (IsPairTerm(d0)) {
|
||||
if (to_visit + 1024 >= (CELL **)AuxSp) {
|
||||
goto aux_overflow;
|
||||
}
|
||||
#ifdef RATIONAL_TREES
|
||||
to_visit[0] = pt0;
|
||||
to_visit[1] = pt0_end;
|
||||
to_visit[2] = (CELL *)*pt0;
|
||||
to_visit += 3;
|
||||
*pt0 = TermFoundVar;
|
||||
#else
|
||||
if (pt0 < pt0_end) {
|
||||
to_visit[0] = pt0;
|
||||
to_visit[1] = pt0_end;
|
||||
to_visit += 2;
|
||||
}
|
||||
#endif
|
||||
pt0 = RepPair(d0) - 1;
|
||||
pt0_end = RepPair(d0) + 1;
|
||||
} else if (IsApplTerm(d0)) {
|
||||
register Functor f;
|
||||
register CELL *ap2;
|
||||
/* store the terms to visit */
|
||||
ap2 = RepAppl(d0);
|
||||
f = (Functor)(*ap2);
|
||||
|
||||
if (IsExtensionFunctor(f)) {
|
||||
continue;
|
||||
}
|
||||
if (to_visit + 1024 >= (CELL **)AuxSp) {
|
||||
goto aux_overflow;
|
||||
}
|
||||
#ifdef RATIONAL_TREES
|
||||
to_visit[0] = pt0;
|
||||
to_visit[1] = pt0_end;
|
||||
to_visit[2] = (CELL *)*pt0;
|
||||
to_visit += 3;
|
||||
*pt0 = TermFoundVar;
|
||||
#else
|
||||
/* store the terms to visit */
|
||||
if (pt0 < pt0_end) {
|
||||
to_visit[0] = pt0;
|
||||
to_visit[1] = pt0_end;
|
||||
to_visit += 2;
|
||||
}
|
||||
#endif
|
||||
d0 = ArityOfFunctor(f);
|
||||
pt0 = ap2;
|
||||
pt0_end = ap2 + d0;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
derefa_body(d0, ptd0, vars_in_term_unk, vars_in_term_nvar);
|
||||
continue;
|
||||
}
|
||||
/* Do we still have compound terms to visit */
|
||||
if (to_visit > to_visit0) {
|
||||
#ifdef RATIONAL_TREES
|
||||
to_visit -= 3;
|
||||
pt0 = to_visit[0];
|
||||
pt0_end = to_visit[1];
|
||||
*pt0 = (CELL)to_visit[2];
|
||||
#else
|
||||
to_visit -= 2;
|
||||
pt0 = to_visit[0];
|
||||
pt0_end = to_visit[1];
|
||||
#endif
|
||||
goto loop;
|
||||
}
|
||||
return TRUE;
|
||||
|
||||
aux_overflow:
|
||||
/* unwind stack */
|
||||
#ifdef RATIONAL_TREES
|
||||
while (to_visit > to_visit0) {
|
||||
to_visit -= 3;
|
||||
pt0 = to_visit[0];
|
||||
*pt0 = (CELL)to_visit[2];
|
||||
}
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
int Yap_IsAcyclicTerm(Term t)
|
||||
{
|
||||
CACHE_REGS
|
||||
while (TRUE) {
|
||||
Int out;
|
||||
|
||||
if (IsVarTerm(t)) {
|
||||
return TRUE;
|
||||
} else if (IsPrimitiveTerm(t)) {
|
||||
return TRUE;
|
||||
} else if (IsPairTerm(t)) {
|
||||
if ((out = finite_tree_complex_term(RepPair(t)-1,
|
||||
RepPair(t)+1 PASS_REGS)) >= 0) {
|
||||
return out;
|
||||
}
|
||||
} else {
|
||||
Functor fun = FunctorOfTerm(t);
|
||||
|
||||
if (IsExtensionFunctor(fun))
|
||||
return TRUE;
|
||||
else if ((out = finite_tree_complex_term(RepAppl(t),
|
||||
RepAppl(t)+
|
||||
ArityOfFunctor(fun) PASS_REGS)) >= 0) {
|
||||
return out;
|
||||
}
|
||||
}
|
||||
if (out < 0) {
|
||||
*H++ = t;
|
||||
if (!Yap_ExpandPreAllocCodeSpace(0, NULL, TRUE)) {
|
||||
Yap_Error(OUT_OF_AUXSPACE_ERROR, ARG1, "overflow in finite_tree");
|
||||
return FALSE;
|
||||
}
|
||||
t = *--H;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static Int
|
||||
p_acyclic_term( USES_REGS1 ) /* finite_tree(+T) */
|
||||
{
|
||||
return Yap_IsAcyclicTerm(Deref(ARG1));
|
||||
}
|
||||
|
||||
static Int
|
||||
p_cyclic_term( USES_REGS1 ) /* finite_tree(+T) */
|
||||
{
|
||||
return !Yap_IsAcyclicTerm(Deref(ARG1));
|
||||
}
|
||||
|
||||
int Yap_IsGroundTerm(Term t)
|
||||
{
|
||||
CACHE_REGS
|
||||
@ -5353,8 +5191,6 @@ void Yap_InitUtilCPreds(void)
|
||||
Yap_InitCPred("duplicate_term", 2, p_duplicate_term, 0);
|
||||
Yap_InitCPred("copy_term_nat", 2, p_copy_term_no_delays, 0);
|
||||
Yap_InitCPred("ground", 1, p_ground, SafePredFlag);
|
||||
Yap_InitCPred("acyclic_term", 1, p_acyclic_term, SafePredFlag);
|
||||
Yap_InitCPred("cyclic_term", 1, p_cyclic_term, SafePredFlag);
|
||||
Yap_InitCPred("$variables_in_term", 3, p_variables_in_term, HiddenPredFlag);
|
||||
Yap_InitCPred("$non_singletons_in_term", 3, p_non_singletons_in_term, HiddenPredFlag);
|
||||
Yap_InitCPred("term_variables", 2, p_term_variables, 0);
|
||||
|
16
docs/yap.tex
16
docs/yap.tex
@ -3343,17 +3343,11 @@ Replace every @code{'$VAR'(@var{I})} by a free variable.
|
||||
@cnindex ground/1
|
||||
Succeeds if there are no free variables in the term @var{T}.
|
||||
|
||||
@item cyclic_term(@var{T}) [ISO]
|
||||
@findex cyclic_term/1
|
||||
@snindex cyclic_term/1
|
||||
@cnindex cyclic_term/1
|
||||
Succeeds if there are loops in the term @var{T}, that is, it is an infite term.
|
||||
|
||||
@item acyclic_term(@var{T}) [ISO]
|
||||
@findex acyclic_term/1
|
||||
@snindex acyclic_term/1
|
||||
@cnindex acyclic_term/1
|
||||
Succeeds if there are no loops in the term @var{T}, that is, it is an fite term.
|
||||
Succeeds if there are loops in the term @var{T}, that is, it is an infite term.
|
||||
|
||||
@item arg(+@var{N},+@var{T},@var{A}) [ISO]
|
||||
@findex arg/3
|
||||
@ -3491,12 +3485,6 @@ Succeed if @var{Subsumer} unifies with the least general
|
||||
generalization over @var{T1} and
|
||||
@var{T2}.
|
||||
|
||||
@item acyclic_term(?@var{Term}) [ISO]
|
||||
@findex cyclic_term/1
|
||||
@syindex cyclic_term/1
|
||||
@cnindex cyclic_term/1
|
||||
Succeed if the argument @var{Term} is an acyclic term.
|
||||
|
||||
@item term_variables(?@var{Term}, -@var{Variables}) [ISO]
|
||||
@findex term_variables/2
|
||||
@syindex term_variables/2
|
||||
@ -11927,7 +11915,7 @@ efficiency. They are available through the
|
||||
@findex cyclic_term/1
|
||||
@syindex cyclic_term/1
|
||||
@cnindex cyclic_term/1
|
||||
Succeed if the argument @var{Term} is a cyclic term.
|
||||
Succeed if the argument @var{Term} is not a cyclic term.
|
||||
|
||||
@item term_hash(+@var{Term}, ?@var{Hash})
|
||||
@findex term_hash/2
|
||||
|
Reference in New Issue
Block a user