fix copy_term between constraints

change visiited stack in unify to AuxSp because H can be changed
by woken goals


git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@221 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
vsc 2001-12-11 03:34:03 +00:00
parent 373a5439fa
commit 6a34f51a25
6 changed files with 59 additions and 36 deletions

View File

@ -90,7 +90,7 @@ AddFailToQueue(void)
}
static int
CopyAttVar(Term orig, CELL ***to_visit_ptr)
CopyAttVar(CELL *orig, CELL ***to_visit_ptr, CELL *res)
{
register attvar_record *attv = (attvar_record *)orig;
register attvar_record *newv;
@ -107,13 +107,32 @@ CopyAttVar(Term orig, CELL ***to_visit_ptr)
RESET_VARIABLE(&(newv->Value));
newv->NS = UpdateTimedVar(AttsMutableList, (CELL)&(newv->Done));
for (j = 0; j < NUM_OF_ATTS; j++) {
Term t = Deref(attv->Atts[2*j+1]);
newv->Atts[2*j] = time;
to_visit[0] = attv->Atts+2*j;
to_visit[1] = attv->Atts+2*j+1;
to_visit[2] = newv->Atts+2*j+1;
to_visit += 3;
if (IsVarTerm(t)) {
RESET_VARIABLE(newv->Atts+(2*j+1));
} else if (IsAtomicTerm(t)) {
newv->Atts[2*j+1] = t;
} else {
#ifdef RATIONAL_TREES
to_visit[0] = attv->Atts+2*j;
to_visit[1] = attv->Atts+2*j+1;
to_visit[2] = newv->Atts+2*j+1;
to_visit[3] = (CELL *)(attv->Atts[2*j]);
/* fool the system into thinking we had a variable there */
attv->Atts[2*j] = AbsAppl(H);
to_visit += 4;
#else
to_visit[0] = attv->Atts+2*j;
to_visit[1] = attv->Atts+2*j+1;
to_visit[2] = newv->Atts+2*j+1;
to_visit += 3;
#endif
}
}
*to_visit_ptr = to_visit;
*res = (CELL)&(newv->Done);
UpdateTimedVar(DelayedVars, (CELL)(newv->Atts+2*j));
return(TRUE);
}

View File

@ -326,7 +326,7 @@ copy_suspended_goals(sus_record *pt, CELL ***to_visit_ptr)
}
static int
CopySuspendedVar(Term orig, CELL ***to_visit_ptr)
CopySuspendedVar(CELL *orig, CELL ***to_visit_ptr, CELL *res)
{
register sus_tag *sreg = (sus_tag *)orig, *vs;
@ -337,6 +337,7 @@ CopySuspendedVar(Term orig, CELL ***to_visit_ptr)
RESET_VARIABLE(&(vs->ActiveSus));
vs->sus_id = susp_ext;
vs->SG = copy_suspended_goals(sreg->SG, to_visit_ptr);
*res = (CELL)&(vs->ActiveSus);
UpdateTimedVar(DelayedVars, (CELL)(vs+1));
return(TRUE);
}

View File

@ -462,7 +462,7 @@ IUnify_complex(CELL *pt0, CELL *pt0_end, CELL *pt1)
register CELL *HBREG = HB;
#endif /* SHADOW_HB */
CELL **to_visit = (CELL **)H;
CELL **to_visit = (CELL **)AuxSp;
loop:
while (pt0 < pt0_end) {
@ -489,19 +489,19 @@ loop:
#ifdef RATIONAL_TREES
/* now link the two structures so that no one else will */
/* come here */
to_visit -= 4;
to_visit[0] = pt0;
to_visit[1] = pt0_end;
to_visit[2] = pt1;
to_visit[3] = (CELL *)d0;
to_visit += 4;
*pt0 = d1;
#else
/* store the terms to visit */
if (pt0 < pt0_end) {
to_visit -= 3;
to_visit[0] = pt0;
to_visit[1] = pt0_end;
to_visit[2] = pt1;
to_visit += 3;
}
#endif
@ -531,19 +531,19 @@ loop:
#ifdef RATIONAL_TREES
/* now link the two structures so that no one else will */
/* come here */
to_visit -= 4;
to_visit[0] = pt0;
to_visit[1] = pt0_end;
to_visit[2] = pt1;
to_visit[3] = (CELL *)d0;
to_visit += 4;
*pt0 = d1;
#else
/* store the terms to visit */
if (pt0 < pt0_end) {
to_visit -= 3;
to_visit[0] = pt0;
to_visit[1] = pt0_end;
to_visit[2] = pt1;
to_visit += 3;
}
#endif
d0 = ArityOfFunctor(f);
@ -579,18 +579,18 @@ loop:
}
}
/* Do we still have compound terms to visit */
if (to_visit > (CELL **) H) {
if (to_visit < (CELL **) AuxSp) {
#ifdef RATIONAL_TREES
to_visit -= 4;
pt0 = to_visit[0];
pt0_end = to_visit[1];
pt1 = to_visit[2];
*pt0 = (CELL)to_visit[3];
to_visit += 4;
#else
to_visit -= 3;
pt0 = to_visit[0];
pt0_end = to_visit[1];
pt1 = to_visit[2];
to_visit += 3;
#endif
goto loop;
}
@ -599,11 +599,11 @@ loop:
cufail:
#ifdef RATIONAL_TREES
/* failure */
while (to_visit > (CELL **) H) {
while (to_visit < (CELL **) AuxSp) {
CELL *pt0;
to_visit -= 4;
pt0 = to_visit[0];
*pt0 = (CELL)to_visit[3];
to_visit += 4;
}
#endif
return (FALSE);

View File

@ -171,16 +171,15 @@ static void copy_complex_term(register CELL *pt0, register CELL *pt0_end, CELL *
tr_fr_ptr CurTR;
bp[0] = to_visit;
*ptf = (CELL)(H+2);
Bind_Global(ptd0,(CELL)ptf);
ptf++;
CurTR = TR;
HB = HB0;
if (!attas[ExtFromCell(ptd0)].copy_term_op((Term)(ptd0-2), bp)) {
if (!attas[ExtFromCell(ptd0)].copy_term_op(ptd0, bp, ptf)) {
goto overflow;
}
to_visit = bp[0];
HB = HLow;
ptf++;
if (CurTR != TR) {
/* Problem here is that the attached routine might
* have changed the list of suspended goals and stored
@ -258,18 +257,20 @@ CopyTerm(Term inp) {
if (IsVarTerm(t)) {
#if COROUTINING
restart_attached:
if (IsAttachedTerm(t)) {
CELL *ap = VarOfTerm(t), *HB0;
H++;
HB0 = H;
copy_complex_term(ap-1, ap, HB0-1, HB0-1);
if (H == HB0-1) { /* handle overflow */
gc(3, ENV, P);
CELL *Hi;
restart_attached:
*H = t;
Hi = H+1;
H += 2;
copy_complex_term(Hi-2, Hi-1, Hi, Hi);
if (H == Hi) { /* handle overflow */
gc(2, ENV, P);
t = Deref(ARG1);
goto restart_attached;
}
return((CELL)(HB0+2)); /* advance two cells */
return(Hi[0]);
}
#endif
return(MkVarTerm());
@ -287,7 +288,7 @@ CopyTerm(Term inp) {
H += 2;
copy_complex_term(ap-1, ap+1, Hi, Hi);
if (H == Hi) { /* handle overflow */
gc(3, ENV, P);
gc(2, ENV, P);
t = Deref(ARG1);
goto restart_list;
}
@ -307,7 +308,7 @@ CopyTerm(Term inp) {
H += 1+ArityOfFunctor(f);
copy_complex_term(ap, ap+ArityOfFunctor(f), HB0+1, HB0);
if (H == HB0) {
gc(3, ENV, P);
gc(2, ENV, P);
t = Deref(ARG1);
goto restart_appl;
}

View File

@ -8475,11 +8475,12 @@ User-defined procedure, called to convert the attributes in @var{Var} to
a @var{Goal}. Should fail when no interpretation is available.
@item @var{Module}:project_attributes(@var{-QueryVars}, @var{+AttrVars})
@findex attribute_goal/2
@syindex attribute_goal/2
@cnindex attribute_goal/2
User-defined procedure, called to convert the attributes in @var{Var} to
a @var{Goal}. Should fail when no interpretation is available.
@findex project_attributes/2
@syindex project_attributes/2
@cnindex project_attributes/2
User-defined procedure, called to project the attributes in the query,
@var{AttrVars}, given that the set of variables in the query is
@var{QueryVars}.
@end table

View File

@ -10,7 +10,7 @@
* File: TermExt.h *
* mods: *
* comments: Extensions to standard terms for YAP *
* version: $Id: TermExt.h.m4,v 1.3 2001-09-18 15:14:11 vsc Exp $ *
* version: $Id: TermExt.h.m4,v 1.4 2001-12-11 03:34:03 vsc Exp $ *
*************************************************************************/
#if USE_OFFSETS
@ -70,7 +70,7 @@ typedef struct {
in some predefined context */
void (*bind_op)(Term *, Term);
/* what to do if someone wants to copy our constraint */
int (*copy_term_op)(Term, CELL ***);
int (*copy_term_op)(CELL *, CELL ***, CELL *);
/* op called to do marking in GC */
void (*mark_op)(CELL *);
} ext_op;
@ -202,6 +202,7 @@ Inline(IsAttachFunc, Int, Functor, f, FALSE)
Inline(IsAttachedTerm, Int, Term, t, FALSE)
#endif
EXTERN int STD_PROTO(unify_extension,(Functor, CELL, CELL *, CELL));