This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
yap-6.3/H/trim_trail.h

166 lines
4.6 KiB
C
Raw Normal View History

2017-11-08 09:29:01 +00:00
#ifdef FROZEN_STACKS
2019-05-27 15:32:39 +01:00
#define RESET_TRAIL_ENTRY(pt) { TrailTerm(pt) = (CELL)(pt); TrailVal(pt) = (CELL)(pt); }
2017-07-30 21:53:07 +01:00
{
2019-05-27 15:32:39 +01:00
tr_fr_ptr pt1, pbase;
pbase = B->cp_tr;
pt1 = TR - 1;
2017-07-30 21:53:07 +01:00
while (pt1 >= pbase) {
BEGD(d1);
d1 = TrailTerm(pt1);
if (IsVarTerm(d1)) {
2019-05-27 15:32:39 +01:00
if (d1 >= (CELL)HBREG && d1 < Unsigned(HR)) {
RESET_TRAIL_ENTRY(pt1);
2017-07-30 21:53:07 +01:00
}
pt1--;
} else if (IsPairTerm(d1)) {
CELL *pt = RepPair(d1);
#ifdef LIMIT_TABLING
2017-07-30 21:53:07 +01:00
if ((ADDR)pt == LOCAL_TrailBase) {
sg_fr_ptr sg_fr = (sg_fr_ptr)TrailVal(pt1);
SgFr_state(sg_fr)--; /* complete_in_use --> complete : compiled_in_use
--> compiled */
insert_into_global_sg_fr_list(sg_fr);
} else
#endif /* LIMIT_TABLING */
2017-07-30 21:53:07 +01:00
if (IN_BETWEEN(LOCAL_TrailBase, pt, LOCAL_TrailTop)) {
/* skip, this is a problem because we lose information,
namely active references */
pt1 = (tr_fr_ptr)pt;
2019-05-27 15:32:39 +01:00
} else if (IN_BETWEEN(H0, pt, LCL0) && IsApplTerm(HeadOfTerm(d1))) {
2017-07-30 21:53:07 +01:00
Term t = HeadOfTerm(d1);
Functor f = FunctorOfTerm(t);
if (f == FunctorBigInt) {
2017-11-08 09:29:01 +00:00
Int tag = Yap_blob_tag(t);
2017-07-30 21:53:07 +01:00
GLOBAL_OpaqueHandlers[tag].cut_handler(d1);
2019-05-27 15:32:39 +01:00
RESET_TRAIL_ENTRY(pt1);
2017-07-30 21:53:07 +01:00
}
pt1--;
continue;
} else if ((*pt & (LogUpdMask | IndexMask)) == (LogUpdMask | IndexMask)) {
LogUpdIndex *cl = ClauseFlagsToLogUpdIndex(pt);
int erase;
#if defined(THREADS) || defined(YAPOR)
2017-07-30 21:53:07 +01:00
PredEntry *ap = cl->ClPred;
#endif
2017-07-30 21:53:07 +01:00
LOCK(ap->PELock);
DEC_CLREF_COUNT(cl);
2019-05-27 15:32:39 +01:00
RESET_TRAIL_ENTRY(pt1);
2017-07-30 21:53:07 +01:00
cl->ClFlags &= ~InUseMask;
erase = (cl->ClFlags & (ErasedMask | DirtyMask)) && !(cl->ClRefCount);
if (erase) {
/* at this point, we are the only ones accessing the clause,
hence we don't need to have a lock it */
if (cl->ClFlags & ErasedMask)
Yap_ErLogUpdIndex(cl);
else
Yap_CleanUpIndex(cl);
}
UNLOCK(ap->PELock);
}
2017-07-30 21:53:07 +01:00
pt1--;
} else if (IsApplTerm(d1)) {
if (IN_BETWEEN(HBREG, RepAppl(d1), B->cp_b)) {
2019-05-27 15:32:39 +01:00
RESET_TRAIL_ENTRY(pt1);
pt1--;
RESET_TRAIL_ENTRY(pt1);
/* deterministic binding to multi-assignment variable */
pt1 --;
2017-07-30 21:53:07 +01:00
} else {
pt1 -= 2;
}
} else {
2019-05-27 15:32:39 +01:00
pt1--;
}
2017-07-30 21:53:07 +01:00
ENDD(d1);
}
}
#else
2017-07-30 21:53:07 +01:00
{
tr_fr_ptr pt1, pt0;
pt1 = pt0 = B->cp_tr;
while (pt1 != TR) {
BEGD(d1);
d1 = TrailTerm(pt1);
if (IsVarTerm(d1)) {
if (d1 < (CELL)HBREG || d1 > Unsigned(B->cp_b)) {
#ifdef FROZEN_STACKS
2017-07-30 21:53:07 +01:00
TrailVal(pt0) = TrailVal(pt1);
#endif /* FROZEN_STACKS */
2017-07-30 21:53:07 +01:00
TrailTerm(pt0) = d1;
pt0++;
}
pt1++;
} else if (IsApplTerm(d1)) {
if (IN_BETWEEN(HBREG, RepAppl(d1), B->cp_b)) {
#ifdef FROZEN_STACKS
2017-07-30 21:53:07 +01:00
pt1 += 2;
#else
2017-07-30 21:53:07 +01:00
pt1 += 3;
#endif
2017-07-30 21:53:07 +01:00
} else {
#ifdef FROZEN_STACKS
2017-07-30 21:53:07 +01:00
TrailVal(pt0) = TrailVal(pt1);
TrailTerm(pt0) = d1;
TrailVal(pt0 + 1) = TrailVal(pt1 + 1);
TrailTerm(pt0 + 1) = TrailTerm(pt1 + 1);
pt0 += 2;
pt1 += 2;
#else
2017-07-30 21:53:07 +01:00
TrailTerm(pt0 + 1) = TrailTerm(pt1 + 1);
TrailTerm(pt0) = TrailTerm(pt0 + 2) = d1;
pt0 += 3;
pt1 += 3;
#endif /* FROZEN_STACKS */
2017-07-30 21:53:07 +01:00
}
} else if (IsPairTerm(d1)) {
CELL *pt = RepPair(d1);
else if (IN_BETWEEN(H0, pt, HR) && IsApplTerm(HeadOfTerm(d1))) {
Term t = HeadOfTerm(d1);
Functor f = FunctorOfTerm(t);
if (f == FunctorBigInt) {
RESET_VARIABLE(&TrailTerm(pt1));
Int tag = Yap_blob_tag(t);
GLOBAL_OpaqueHandlers[tag].cut_handler(d1);
} else if ((*pt & (LogUpdMask | IndexMask)) ==
(LogUpdMask | IndexMask)) {
LogUpdIndex *cl = ClauseFlagsToLogUpdIndex(pt);
#if defined(YAPOR) || defined(THREADS)
2017-07-30 21:53:07 +01:00
PredEntry *ap = cl->ClPred;
#endif
2017-07-30 21:53:07 +01:00
int erase;
2017-07-30 21:53:07 +01:00
LOCK(ap->PELock);
DEC_CLREF_COUNT(cl);
cl->ClFlags &= ~InUseMask;
erase = (cl->ClFlags & (DirtyMask | ErasedMask)) && !(cl->ClRefCount);
if (erase) {
/* at this point, we are the only ones accessing the clause,
hence we don't need to have a lock it */
if (cl->ClFlags & ErasedMask)
Yap_ErLogUpdIndex(cl);
else
Yap_CleanUpIndex(cl);
}
UNLOCK(ap->PELock);
} else {
TrailTerm(pt0) = d1;
pt0++;
}
pt1++;
}
else {
TrailTerm(pt0) = d1;
pt0++;
pt1++;
}
2017-07-30 21:53:07 +01:00
ENDD(d1);
}
TR = pt0;
}
#endif /* FROZEN_STACKS */