fixes to support copy_term and nb_
This commit is contained in:
parent
3d10482cc7
commit
30a4f3cfe7
12
C/attvar.c
12
C/attvar.c
@ -96,7 +96,7 @@ CopyAttVar(CELL *orig, struct cp_frame **to_visit_ptr, CELL *res)
|
|||||||
to_visit->start_cp = vt-1;
|
to_visit->start_cp = vt-1;
|
||||||
to_visit->end_cp = vt;
|
to_visit->end_cp = vt;
|
||||||
if (IsVarTerm(attv->Atts)) {
|
if (IsVarTerm(attv->Atts)) {
|
||||||
newv->Atts = (CELL)H;
|
Bind(&newv->Atts, (CELL)H);
|
||||||
to_visit->to = H;
|
to_visit->to = H;
|
||||||
H++;
|
H++;
|
||||||
} else {
|
} else {
|
||||||
@ -123,7 +123,7 @@ TermToAttVar(Term attvar, Term to)
|
|||||||
attvar_record *attv = BuildNewAttVar();
|
attvar_record *attv = BuildNewAttVar();
|
||||||
if (!attv)
|
if (!attv)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
attv->Atts = attvar;
|
Bind(&attv->Atts, attvar);
|
||||||
*VarOfTerm(to) = AbsAttVar(attv);
|
*VarOfTerm(to) = AbsAttVar(attv);
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
@ -254,11 +254,7 @@ AddNewModule(attvar_record *attv, Term t, int new, int do_it)
|
|||||||
if (!do_it)
|
if (!do_it)
|
||||||
return;
|
return;
|
||||||
if (IsVarTerm(attv->Atts)) {
|
if (IsVarTerm(attv->Atts)) {
|
||||||
if (new) {
|
Bind(&(attv->Atts),t);
|
||||||
attv->Atts = t;
|
|
||||||
} else {
|
|
||||||
Bind(&(attv->Atts),t);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Term *wherep = &attv->Atts;
|
Term *wherep = &attv->Atts;
|
||||||
|
|
||||||
@ -480,7 +476,7 @@ p_put_att_term(void) {
|
|||||||
}
|
}
|
||||||
if (new) {
|
if (new) {
|
||||||
Bind(VarOfTerm(inp), AbsAttVar(attv));
|
Bind(VarOfTerm(inp), AbsAttVar(attv));
|
||||||
attv->Atts = Deref(ARG2);
|
Bind(&attv->Atts, Deref(ARG2));
|
||||||
} else {
|
} else {
|
||||||
MaBind(&(attv->Atts), Deref(ARG2));
|
MaBind(&(attv->Atts), Deref(ARG2));
|
||||||
}
|
}
|
||||||
|
102
C/globals.c
102
C/globals.c
@ -224,6 +224,11 @@ Yap_GetFromArena(Term *arenap, UInt cells, UInt arity)
|
|||||||
CELL *newH;
|
CELL *newH;
|
||||||
UInt old_sz = ArenaSz(arena), new_size;
|
UInt old_sz = ArenaSz(arena), new_size;
|
||||||
|
|
||||||
|
if (IN_BETWEEN(base, H, max)) {
|
||||||
|
base = H;
|
||||||
|
H += cells;
|
||||||
|
return base;
|
||||||
|
}
|
||||||
if (base+cells > ASP-1024) {
|
if (base+cells > ASP-1024) {
|
||||||
if (!GrowArena(arena, max, old_sz, old_sz+sizeof(CELL)*1024, arity))
|
if (!GrowArena(arena, max, old_sz, old_sz+sizeof(CELL)*1024, arity))
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -280,6 +285,9 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, int share, int cop
|
|||||||
CELL *HB0 = HB;
|
CELL *HB0 = HB;
|
||||||
tr_fr_ptr TR0 = TR;
|
tr_fr_ptr TR0 = TR;
|
||||||
int ground = TRUE;
|
int ground = TRUE;
|
||||||
|
#ifdef COROUTINING
|
||||||
|
CELL *dvarsmin = NULL, *dvarsmax=NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
HB = HLow;
|
HB = HLow;
|
||||||
to_visit0 = to_visit;
|
to_visit0 = to_visit;
|
||||||
@ -455,52 +463,50 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, int share, int cop
|
|||||||
*ptf++ = (CELL) ptd0;
|
*ptf++ = (CELL) ptd0;
|
||||||
} else {
|
} else {
|
||||||
#if COROUTINING
|
#if COROUTINING
|
||||||
if (IsAttVar(ptd0) && copy_att_vars) {
|
if (copy_att_vars && IsAttachedTerm((CELL)ptd0)) {
|
||||||
attvar_record *newv = (attvar_record *)H;
|
/* if unbound, call the standard copy term routine */
|
||||||
newv->AttFunc = FunctorAttVar;
|
struct cp_frame *bp;
|
||||||
RESET_VARIABLE(&newv->Done);
|
|
||||||
*ptf = AbsAttVar(newv);
|
if (IN_BETWEEN(dvarsmin, ptd0, dvarsmax)) {
|
||||||
ptf++;
|
*ptf++ = (CELL) ptd0;
|
||||||
/* store the terms to visit */
|
} else {
|
||||||
#ifdef RATIONAL_TREES
|
CELL new;
|
||||||
if (to_visit+1 >= (struct cp_frame *)AuxSp) {
|
|
||||||
goto heap_overflow;
|
bp = to_visit;
|
||||||
}
|
if (!attas[ExtFromCell(ptd0)].copy_term_op(ptd0, &bp, ptf)) {
|
||||||
to_visit->start_cp = pt0;
|
goto overflow;
|
||||||
to_visit->end_cp = pt0_end;
|
|
||||||
to_visit->to = ptf;
|
|
||||||
to_visit->oldv = *pt0;
|
|
||||||
to_visit->ground = ground;
|
|
||||||
/* fool the system into thinking we had a variable there */
|
|
||||||
*pt0 = AbsAppl(H);
|
|
||||||
to_visit ++;
|
|
||||||
#else
|
|
||||||
if (pt0 < pt0_end) {
|
|
||||||
if (to_visit ++ >= (CELL **)AuxSp) {
|
|
||||||
goto heap_overflow;
|
|
||||||
}
|
}
|
||||||
to_visit->start_cp = pt0;
|
to_visit = bp;
|
||||||
to_visit->end_cp = pt0_end;
|
new = *ptf;
|
||||||
to_visit->to = ptf;
|
if (TR > (tr_fr_ptr)Yap_TrailTop - 256) {
|
||||||
to_visit->ground = ground;
|
/* Trail overflow */
|
||||||
to_visit ++;
|
if (!Yap_growtrail((TR-TR0)*sizeof(tr_fr_ptr *), TRUE)) {
|
||||||
}
|
goto trail_overflow;
|
||||||
#endif
|
}
|
||||||
pt0 = ptd0+(1-1);
|
}
|
||||||
pt0_end = ptd0 + (ATT_RECORD_ARITY-1);
|
Bind_and_Trail(ptd0, new);
|
||||||
/* store the functor for the new term */
|
if (dvarsmin == NULL) {
|
||||||
ptf = H+2;
|
dvarsmin = CellPtr(new);
|
||||||
H = CellPtr(newv+1);
|
} else {
|
||||||
if (H > ASP - MIN_ARENA_SIZE) {
|
*dvarsmax = (CELL)(CellPtr(new)+1);
|
||||||
goto overflow;
|
}
|
||||||
|
dvarsmax = CellPtr(new)+1;
|
||||||
|
ptf++;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
*ptf++ = d0;
|
#endif
|
||||||
|
/* first time we met this term */
|
||||||
|
RESET_VARIABLE(ptf);
|
||||||
|
if ((ADDR)TR > Yap_TrailTop-MIN_ARENA_SIZE)
|
||||||
|
goto trail_overflow;
|
||||||
|
Bind_and_Trail(ptd0, (CELL)ptf);
|
||||||
|
ptf++;
|
||||||
|
#ifdef COROUTINING
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do we still have compound terms to visit */
|
/* Do we still have compound terms to visit */
|
||||||
if (to_visit > to_visit0) {
|
if (to_visit > to_visit0) {
|
||||||
to_visit --;
|
to_visit --;
|
||||||
@ -554,6 +560,24 @@ copy_complex_term(register CELL *pt0, register CELL *pt0_end, int share, int cop
|
|||||||
#endif
|
#endif
|
||||||
reset_trail(TR0);
|
reset_trail(TR0);
|
||||||
return -2;
|
return -2;
|
||||||
|
|
||||||
|
trail_overflow:
|
||||||
|
/* oops, we're in trouble */
|
||||||
|
H = HLow;
|
||||||
|
/* we've done it */
|
||||||
|
/* restore our nice, friendly, term to its original state */
|
||||||
|
HB = HB0;
|
||||||
|
#ifdef RATIONAL_TREES
|
||||||
|
while (to_visit > to_visit0) {
|
||||||
|
to_visit--;
|
||||||
|
pt0 = to_visit->start_cp;
|
||||||
|
pt0_end = to_visit->end_cp;
|
||||||
|
ptf = to_visit->to;
|
||||||
|
*pt0 = to_visit->oldv;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
reset_trail(TR0);
|
||||||
|
return -4;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Term
|
static Term
|
||||||
|
@ -65,18 +65,7 @@ clean_dirty_tr(tr_fr_ptr TR0) {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
Term p = TrailTerm(pt++);
|
Term p = TrailTerm(pt++);
|
||||||
if (IsVarTerm(p)) {
|
RESET_VARIABLE(p);
|
||||||
RESET_VARIABLE(p);
|
|
||||||
} else {
|
|
||||||
/* copy downwards */
|
|
||||||
#ifdef FROZEN_STACKS
|
|
||||||
#else
|
|
||||||
TrailTerm(TR0+1) = TrailTerm(pt);
|
|
||||||
TrailTerm(TR0) = TrailTerm(TR0+2) = p;
|
|
||||||
#endif
|
|
||||||
pt+=2;
|
|
||||||
TR0 += 3;
|
|
||||||
}
|
|
||||||
} while (pt != TR);
|
} while (pt != TR);
|
||||||
TR = TR0;
|
TR = TR0;
|
||||||
}
|
}
|
||||||
@ -270,6 +259,8 @@ copy_complex_term(CELL *pt0, CELL *pt0_end, int share, int newattvs, CELL *ptf,
|
|||||||
Bind(ptd0, new);
|
Bind(ptd0, new);
|
||||||
if (dvarsmin == NULL) {
|
if (dvarsmin == NULL) {
|
||||||
dvarsmin = CellPtr(new);
|
dvarsmin = CellPtr(new);
|
||||||
|
} else {
|
||||||
|
*dvarsmax = (CELL)(CellPtr(new)+1);
|
||||||
}
|
}
|
||||||
dvarsmax = CellPtr(new)+1;
|
dvarsmax = CellPtr(new)+1;
|
||||||
ptf++;
|
ptf++;
|
||||||
@ -316,7 +307,23 @@ copy_complex_term(CELL *pt0, CELL *pt0_end, int share, int newattvs, CELL *ptf,
|
|||||||
|
|
||||||
/* restore our nice, friendly, term to its original state */
|
/* restore our nice, friendly, term to its original state */
|
||||||
clean_dirty_tr(TR0);
|
clean_dirty_tr(TR0);
|
||||||
HB = HB0;
|
/* follow chain of multi-assigned variables */
|
||||||
|
if (dvarsmin) {
|
||||||
|
fprintf(stderr,"%ld--%ld\n", dvarsmin-H0,dvarsmax-H0);
|
||||||
|
dvarsmin += 1;
|
||||||
|
do {
|
||||||
|
CELL *newv;
|
||||||
|
fprintf(stderr,"mabind %ld %p %p\n", dvarsmin-H0, TR, dvarsmin+1);
|
||||||
|
Bind(dvarsmin+1, dvarsmin[1]);
|
||||||
|
fprintf(stderr,"redone %p\n", TR);
|
||||||
|
if (IsUnboundVar(dvarsmin))
|
||||||
|
break;
|
||||||
|
newv = CellPtr(*dvarsmin);
|
||||||
|
RESET_VARIABLE(dvarsmin);
|
||||||
|
dvarsmin = newv;
|
||||||
|
} while (TRUE);
|
||||||
|
HB = HB0;
|
||||||
|
}
|
||||||
return ground;
|
return ground;
|
||||||
|
|
||||||
overflow:
|
overflow:
|
||||||
@ -516,7 +523,7 @@ Yap_CopyTermNoShare(Term inp) {
|
|||||||
static Int
|
static Int
|
||||||
p_copy_term(void) /* copy term t to a new instance */
|
p_copy_term(void) /* copy term t to a new instance */
|
||||||
{
|
{
|
||||||
v Term t = CopyTerm(ARG1, 2, TRUE, TRUE);
|
Term t = CopyTerm(ARG1, 2, TRUE, TRUE);
|
||||||
if (t == 0L)
|
if (t == 0L)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
/* be careful, there may be a stack shift here */
|
/* be careful, there may be a stack shift here */
|
||||||
|
Reference in New Issue
Block a user