This commit is contained in:
Vítor Santos Costa 2019-02-04 22:10:30 +00:00
parent cb4d17cb4f
commit 3b8475f882
3 changed files with 60 additions and 50 deletions

View File

@ -164,20 +164,20 @@ typedef struct non_single_struct_t {
goto restart; \ goto restart; \
to_visit->pt0 = pt0; \ to_visit->pt0 = pt0; \
to_visit->pt0_end = pt0_end; \ to_visit->pt0_end = pt0_end; \
to_visit->ptd0 = ptd0; \ to_visit->ptd0 = ptd0; \
to_visit->d0 = *ptd0; \ to_visit->d0 = *ptd0; \
to_visit++; \ to_visit++; \
d0 = ptd0[0]; \ d0 = ptd0[0]; \
*ptd0 = TermFreeTerm; \
pt0 = ptd0; \ pt0 = ptd0; \
*pt0 = TermFreeTerm; \
pt0_end = pt0 + 1; \ pt0_end = pt0 + 1; \
goto list_loop; \ goto list_loop; \
} else if (IsApplTerm(d0)) { \ } else if (IsApplTerm(d0)) { \
register Functor f; \ register Functor f; \
register CELL *ap2; \ register CELL *ap2; \
/* store the terms to visit */ \ /* store the terms to visit */ \
ap2 = RepAppl(d0); \ ptd0 = RepAppl(d0); \
f = (Functor)(*ap2); \ f = (Functor)(d0 = *ptd0); \
\ \
if (to_visit + 32 >= to_visit_max) { \ if (to_visit + 32 >= to_visit_max) { \
goto aux_overflow; \ goto aux_overflow; \
@ -189,14 +189,14 @@ typedef struct non_single_struct_t {
} \ } \
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 = ptd0; \
to_visit->d0 = (CELL)f; \ to_visit->d0 = d0; \
to_visit++; \ to_visit++; \
\ \
*ap2 = TermNil; \ *ptd0 = TermNil; \
d0 = ArityOfFunctor(f); \ Term d1 = ArityOfFunctor(f); \
pt0 = ap2; \ pt0 = ptd0; \
pt0_end = ap2 + d0; \ pt0_end = ptd0 + d1; \
goto restart; \ goto restart; \
} else { \ } else { \
PRIMI0; \ PRIMI0; \
@ -468,9 +468,9 @@ static Term vars_in_complex_term(register CELL *pt0, register CELL *pt0_end,
END_WALK(); END_WALK();
/* 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--;
pt0 = to_visit->pt0; to_visit--;
pt0 = to_visit->pt0;
pt0_end = to_visit->pt0_end; pt0_end = to_visit->pt0_end;
CELL *ptd0 = to_visit->ptd0; CELL *ptd0 = to_visit->ptd0;
*ptd0 = to_visit->d0; *ptd0 = to_visit->d0;
@ -1089,13 +1089,12 @@ p_free_variables_in_term(USES_REGS1) /* variables within term t */
static Term non_singletons_in_complex_term(CELL *pt0, CELL *pt0_end USES_REGS) { static Term non_singletons_in_complex_term(CELL *pt0, CELL *pt0_end USES_REGS) {
tr_fr_ptr TR0 = TR; tr_fr_ptr TR0 = TR;
CELL *InitialH = HR; CELL *InitialH = HR;
HB = (CELL *)ASP;
CELL output = AbsPair(HR); CELL output = AbsPair(HR);
WALK_COMPLEX_TERM__({}, {}, FOUND_VAR_AGAIN()); WALK_COMPLEX_TERM__({}, {}, FOUND_VAR_AGAIN());
/* do or pt2 are unbound */ /* do or pt2 are unbound */
*ptd0 = TermFoundVar; YapBind(ptd0,TermFoundVar);
/* next make sure we can recover the variable again */
TrailTerm(TR++) = (CELL)ptd0;
END_WALK(); END_WALK();
/* 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) {
@ -1111,6 +1110,7 @@ static Term non_singletons_in_complex_term(CELL *pt0, CELL *pt0_end USES_REGS) {
clean_tr(TR0 PASS_REGS); clean_tr(TR0 PASS_REGS);
pop_text_stack(lvl); pop_text_stack(lvl);
HB = (CELL*)B->cp_b;
if (HR != InitialH) { if (HR != InitialH) {
/* close the list */ /* close the list */
HR[-1] = Deref(ARG2); HR[-1] = Deref(ARG2);
@ -1161,7 +1161,7 @@ static void renumbervar(Term t, Int id USES_REGS) {
} }
#define RENUMBER_SINGLES \ #define RENUMBER_SINGLES \
if (singles && ap2 >= InitialH && ap2 < HR) { \ if (singles ) { \
renumbervar(d0, numbv++ PASS_REGS); \ renumbervar(d0, numbv++ PASS_REGS); \
goto restart; \ goto restart; \
} }
@ -1174,42 +1174,37 @@ static Int numbervars_in_complex_term(CELL *pt0, CELL *pt0_end, Int numbv,
WALK_COMPLEX_TERM__({}, RENUMBER_SINGLES, {}); WALK_COMPLEX_TERM__({}, RENUMBER_SINGLES, {});
if (IsAttVar(pt0))
continue;
/* do or pt2 are unbound */ /* do or pt2 are unbound */
if (singles||false) if (singles)
*ptd0 = numbervar_singleton(PASS_REGS1); d0 = numbervar_singleton(PASS_REGS1);
else else
*ptd0 = numbervar(numbv++ PASS_REGS); d0 = numbervar(numbv++ PASS_REGS);
/* leave an empty slot to fill in later */ /* leave an empty slot to fill in later */
if (HR + 1024 > ASP) { if (HR + 1024 > ASP) {
goto global_overflow; goto global_overflow;
} }
/* next make sure noone will see this as a variable again */ /* next make sure noone will see this as a variable again */
if (TR > (tr_fr_ptr)LOCAL_TrailTop - 256) { YapBind(ptd0, d0);
/* Trail overflow */
if (!Yap_growtrail((TR - TR0) * sizeof(tr_fr_ptr *), true)) {
goto trail_overflow;
}
}
#if defined(TABLING) || defined(YAPOR_SBA)
TrailVal(TR) = (CELL)ptd0;
#endif
TrailTerm(TR++) = (CELL)ptd0;
continue;
END_WALK(); END_WALK();
/* Do we still have compound terms to visit */ /* Do we still have compound terms to visit */
if (to_visit > to_visit0) { while (to_visit > to_visit0) {
to_visit--; to_visit--;
pt0 = to_visit->pt0; pt0 = to_visit->pt0;
pt0_end = to_visit->pt0_end; pt0_end = to_visit->pt0_end;
CELL *ptd0 = to_visit->ptd0; CELL *ptd0 = to_visit->ptd0;
*ptd0 = to_visit->d0; *ptd0 = to_visit->d0;
if (pt0 >= pt0_end)
continue;
goto restart; goto restart;
} }
prune(B PASS_REGS);
pop_text_stack(lvl); pop_text_stack(lvl);
return numbv; return numbv;
@ -1369,14 +1364,14 @@ restart:
if (to_visit + 32 >= to_visit_max) { if (to_visit + 32 >= to_visit_max) {
goto aux_overflow; goto aux_overflow;
} }
CELL *headp = RepPair(d0); CELL *ptd0 = RepPair(d0);
d0 = headp[0]; d0 = ptd0[0];
if (IsAtomTerm(d0) && (CELL *)AtomOfTerm(d0) >= (CELL *)to_visit0 && if (IsAtomTerm(d0) && (CELL *)AtomOfTerm(d0) >= (CELL *)to_visit0 &&
(CELL *)AtomOfTerm(d0) < (CELL *)to_visit_max) { (CELL *)AtomOfTerm(d0) < (CELL *)to_visit) {
// LIST0; // LIST0;
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); *ptf = UNFOLD_LOOP(AbsPair(v0->ptf-1), listp);
ptf++; ptf++;
} else { } else {
@ -1387,12 +1382,12 @@ restart:
*ptf++ = AbsPair(HR); *ptf++ = AbsPair(HR);
to_visit->pt0 = pt0; to_visit->pt0 = pt0;
to_visit->pt0_end = pt0_end; to_visit->pt0_end = pt0_end;
to_visit->ptd0 = headp; to_visit->ptd0 = ptd0;
to_visit->ptf = ptf; to_visit->ptf = ptf;
to_visit->d0 = d0; to_visit->d0 = d0 = *ptd0;
*headp = MkAtomTerm((AtomEntry *)to_visit); *ptd0 = MkAtomTerm((AtomEntry *)to_visit);
to_visit++; to_visit++;
pt0 = headp; pt0 = ptd0;
pt0_end = pt0 + 1; pt0_end = pt0 + 1;
ptd0 = pt0; ptd0 = pt0;
ptf = HR; ptf = HR;
@ -1400,16 +1395,16 @@ restart:
goto list_loop; goto list_loop;
} else if (IsApplTerm(d0)) { } else if (IsApplTerm(d0)) {
register Functor f; register Functor f;
register CELL *ap2;
/* store the terms to visit */ /* store the terms to visit */
ap2 = RepAppl(d0); ptd0 = RepAppl(d0);
f = (Functor)(*ap2); f = (Functor)(*ptd0);
if (IsExtensionFunctor(f)) { if (IsExtensionFunctor(f)) {
*ptf++ = d0; *ptf++ = d0;
continue; continue;
} }
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(*ptd0);
if (listp) { if (listp) {
*ptf = UNFOLD_LOOP(AbsAppl(v0->ptf-1), listp); *ptf = UNFOLD_LOOP(AbsAppl(v0->ptf-1), listp);
ptf++; ptf++;
@ -1425,13 +1420,13 @@ restart:
*ptf++ = AbsAppl(HR); *ptf++ = AbsAppl(HR);
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 = ptd0;
to_visit->d0 = *ap2; to_visit->d0 = *ptd0;
to_visit->ptf = ptf; to_visit->ptf = ptf;
*ap2 = MkAtomTerm((AtomEntry *)to_visit); *ptd0 = MkAtomTerm((AtomEntry *)to_visit);
to_visit++; to_visit++;
pt0 = ap2; pt0 = ptd0;
pt0_end = ap2 + (ArityOfFunctor(f)); pt0_end = ptd0 + (ArityOfFunctor(f));
HR[0] = (CELL)f; HR[0] = (CELL)f;
ptf = HR+1; ptf = HR+1;
HR = ptf +ArityOfFunctor(f); HR = ptf +ArityOfFunctor(f);

View File

@ -88,7 +88,7 @@ static char *send_tracer_message(char *start, char *name, arity_t arity,
} }
} }
const char *sn = Yap_TermToBuffer(args[i], const char *sn = Yap_TermToBuffer(args[i],
Quote_illegal_f | Handle_vars_f); Handle_cyclics_f|Quote_illegal_f | Handle_vars_f);
size_t sz; size_t sz;
if (sn == NULL) { if (sn == NULL) {
sn = malloc(strlen("<* error *>")+1); sn = malloc(strlen("<* error *>")+1);

View File

@ -54,6 +54,21 @@ restart:
goto restart; goto restart;
} }
} }
INLINE_ONLY Term *pDerefa(CELL *b);
INLINE_ONLY Term *pDerefa(CELL *b) {
Term a = *b;
restart:
if (!IsVarTerm(a)) {
return b;
} else if (a == (CELL)b) {
return b;
} else {
b = (CELL *)a;
a = *b;
goto restart;
}
}
INLINE_ONLY Term ArgOfTerm(int i, Term t); INLINE_ONLY Term ArgOfTerm(int i, Term t);