fix bad merge
This commit is contained in:
parent
ee12fea7cd
commit
d76fa9ca3d
@ -1574,6 +1574,7 @@ void Yap_InitCPreds(void) {
|
|||||||
Yap_InitCmpPreds();
|
Yap_InitCmpPreds();
|
||||||
Yap_InitCoroutPreds();
|
Yap_InitCoroutPreds();
|
||||||
Yap_InitDBPreds();
|
Yap_InitDBPreds();
|
||||||
|
Yap_InitErrorPreds();
|
||||||
Yap_InitExecFs();
|
Yap_InitExecFs();
|
||||||
Yap_InitGlobals();
|
Yap_InitGlobals();
|
||||||
Yap_InitInlines();
|
Yap_InitInlines();
|
||||||
|
151
C/terms.c
151
C/terms.c
@ -300,143 +300,46 @@ static Int cyclic_term(USES_REGS1) /* cyclic_term(+T) */
|
|||||||
return Yap_IsCyclicTerm(Deref(ARG1));
|
return Yap_IsCyclicTerm(Deref(ARG1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
static Term BREAK_LOOP(CELL d0,struct non_single_struct_t *to_visit ) {
|
static Term BREAK_LOOP(CELL d0,struct non_single_struct_t *to_visit ) {
|
||||||
char buf[64];
|
char buf[64];
|
||||||
snprintf(buf, 63, "@^[" Int_FORMAT "]", to_visit-(struct non_single_struct_t*)AtomOfTerm(d0));
|
snprintf(buf, 63, "@^[" Int_FORMAT "]", to_visit-(struct non_single_struct_t*)AtomOfTerm(d0));
|
||||||
return MkAtomTerm(Yap_LookupAtom(buf));
|
return MkAtomTerm(Yap_LookupAtom(buf));
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#define BREAK_CYC \
|
||||||
|
if (IS_VISIT_MARKER) { \
|
||||||
|
MaBind(pt0,AbsAppl(HR)); \
|
||||||
|
HR[0] = (CELL)FunctorDollarVar; \
|
||||||
|
HR[1] = MkIntegerTerm((struct non_single_struct_t*)AtomOfTerm(d0)-to_visit); \
|
||||||
|
HR += 2; \
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief routine to locate all variables in a term, and its applications */
|
@brief routine to locate all variables in a term, and its applications */
|
||||||
|
|
||||||
static int cycles_in_complex_term( CELL *pt0_, CELL *pt0_end_ USES_REGS) {
|
static int break_cycles_in_complex_term( CELL *pt0_, CELL *pt0_end_ USES_REGS) {
|
||||||
|
CELL *pt0, *pt0_end;
|
||||||
|
int lvl;
|
||||||
|
size_t auxsz = 1024 * sizeof(struct non_single_struct_t);
|
||||||
|
struct non_single_struct_t *to_visit0, *to_visit,* to_visit_max;
|
||||||
|
CELL *InitialH = HR;
|
||||||
|
tr_fr_ptr TR0 = TR;
|
||||||
|
|
||||||
CELL *pt0, *pt0_end;
|
WALK_COMPLEX_TERM__(BREAK_CYC, BREAK_CYC, {});
|
||||||
size_t auxsz = 1024 * sizeof(struct non_single_struct_t);
|
/* leave an empty slot to fill in later */
|
||||||
struct non_single_struct_t *to_visit0, *to_visit, *to_visit_max;
|
END_WALK();
|
||||||
int lvl;
|
|
||||||
|
|
||||||
reset:
|
return false;
|
||||||
lvl = push_text_stack();
|
|
||||||
pt0 = pt0_, pt0_end = pt0_end_;
|
|
||||||
to_visit0 = Malloc(auxsz);
|
|
||||||
to_visit= to_visit0;
|
|
||||||
to_visit_max = to_visit0 + auxsz/sizeof(struct non_single_struct_t);
|
|
||||||
CELL *InitialH = HR;
|
|
||||||
tr_fr_ptr TR0 = TR;
|
|
||||||
if (TR > (tr_fr_ptr)LOCAL_TrailTop - 256) { \
|
|
||||||
/* Trail overflow */\
|
|
||||||
goto trail_overflow;\
|
|
||||||
}\
|
|
||||||
auxsz *= 2;
|
|
||||||
int rc = 0;
|
|
||||||
CELL *ptf;
|
|
||||||
ptf = HR;
|
|
||||||
HR++;
|
|
||||||
while (to_visit >= to_visit0) {
|
|
||||||
CELL d0;
|
|
||||||
CELL *ptd0;
|
|
||||||
|
|
||||||
while (pt0 < pt0_end) {
|
|
||||||
++pt0;
|
|
||||||
ptd0 = pt0;
|
|
||||||
d0 = *ptd0;
|
|
||||||
list_loop:
|
|
||||||
deref_head(d0, var_in_term_unk);
|
|
||||||
var_in_term_nvar : {
|
|
||||||
if (IsPairTerm(d0)) {
|
|
||||||
if (to_visit + 32 >= to_visit_max) {
|
|
||||||
goto aux_overflow;
|
|
||||||
}
|
|
||||||
ptd0 = RepPair(d0);
|
|
||||||
d0 = ptd0[0];
|
|
||||||
if (IS_VISIT_MARKER) {
|
|
||||||
rc++;
|
|
||||||
*ptf++ = BREAK_LOOP(d0, to_visit);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
*ptf++ = AbsPair(HR);
|
|
||||||
to_visit->pt0 = pt0;
|
|
||||||
to_visit->pt0_end = pt0_end;
|
|
||||||
to_visit->ptd0 = ptd0;
|
|
||||||
to_visit->d0 = d0;
|
|
||||||
to_visit->ptf = ptf;
|
|
||||||
to_visit++;
|
|
||||||
ptf = HR;
|
|
||||||
if (HR + 1024 > ASP) { \
|
|
||||||
goto global_overflow;\
|
|
||||||
}\
|
|
||||||
HR += 2;
|
|
||||||
*ptd0 = VISIT_MARKER;
|
|
||||||
pt0 = ptd0;
|
|
||||||
pt0_end = pt0+1;
|
|
||||||
ptf = HR - 2;
|
|
||||||
goto list_loop;
|
|
||||||
} else if (IsApplTerm(d0)) {
|
|
||||||
register Functor f;
|
|
||||||
/* store the terms to visit */
|
|
||||||
ptd0 = RepAppl(d0);
|
|
||||||
f = (Functor)(d0 = *ptd0);
|
|
||||||
if (IsExtensionFunctor(f)) {
|
|
||||||
*ptf++ = AbsAppl(ptd0);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (IS_VISIT_MARKER) {
|
|
||||||
rc++;
|
|
||||||
*ptf++ = BREAK_LOOP(d0, to_visit);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (to_visit + 32 >= to_visit_max) {
|
|
||||||
goto aux_overflow;
|
|
||||||
}
|
|
||||||
*ptf++ = AbsAppl(HR);
|
|
||||||
to_visit->pt0 = pt0;
|
|
||||||
to_visit->pt0_end = pt0_end;
|
|
||||||
to_visit->ptd0 = ptd0;
|
|
||||||
to_visit->d0 = d0;
|
|
||||||
to_visit->ptf = ptf;
|
|
||||||
to_visit++;
|
|
||||||
|
|
||||||
*ptd0 = VISIT_MARKER;
|
|
||||||
*HR++ = (CELL)f;
|
|
||||||
ptf = HR;
|
|
||||||
Term d1 = ArityOfFunctor(f);
|
|
||||||
pt0 = ptd0;
|
|
||||||
pt0_end = ptd0 + (d1);
|
|
||||||
HR+=d1;
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
if (IS_VISIT_MARKER) {
|
|
||||||
rc++;
|
|
||||||
*ptf++ = BREAK_LOOP(d0, to_visit);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
*ptf++ = d0;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
derefa_body(d0, ptd0, var_in_term_unk, var_in_term_nvar);
|
|
||||||
*ptf++ = d0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* Do we still have compound terms to visit */
|
|
||||||
to_visit--;
|
|
||||||
if (to_visit >= to_visit0) {
|
|
||||||
pt0 = to_visit->pt0;
|
|
||||||
pt0_end = to_visit->pt0_end;
|
|
||||||
ptf = to_visit->ptf;
|
|
||||||
*to_visit->ptd0 = to_visit->d0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pop_text_stack(lvl);
|
|
||||||
|
|
||||||
return rc;
|
|
||||||
|
|
||||||
def_overflow();
|
def_overflow();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Term Yap_CyclesInTerm(Term t USES_REGS) {
|
Term Yap_BreakCyclesInTerm(Term t USES_REGS) {
|
||||||
cs[3]++;
|
cs[3]++;
|
||||||
t = Deref(t);
|
t = Deref(t);
|
||||||
if (IsVarTerm(t)) {
|
if (IsVarTerm(t)) {
|
||||||
@ -445,7 +348,7 @@ Term Yap_CyclesInTerm(Term t USES_REGS) {
|
|||||||
return t;
|
return t;
|
||||||
} else {
|
} else {
|
||||||
CELL *Hi = HR;
|
CELL *Hi = HR;
|
||||||
if ( cycles_in_complex_term(&(t)-1, &(t)PASS_REGS) >0) {
|
if ( break_cycles_in_complex_term(&(t)-1, &(t)PASS_REGS) >0) {
|
||||||
return Hi[0];
|
return Hi[0];
|
||||||
} else {
|
} else {
|
||||||
HR = Hi;
|
HR = Hi;
|
||||||
@ -463,9 +366,9 @@ Term Yap_CyclesInTerm(Term t USES_REGS) {
|
|||||||
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
static Int cycles_in_term(USES_REGS1) /* cyclic_term(+T) */
|
static Int break_cycles_in_term(USES_REGS1) /* cyclic_term(+T) */
|
||||||
{
|
{
|
||||||
return Yap_CyclesInTerm(Deref(ARG1));
|
return Yap_BreakCyclesInTerm(Deref(ARG1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1451,7 +1354,7 @@ static Int rational_term_to_tree(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Yap_InitTermCPreds(void) {
|
void Yap_InitTermCPreds(void) {
|
||||||
Yap_InitCPred("cycles_in_term", 2, cycles_in_term, 0);
|
Yap_InitCPred("break_cycles_in_term", 2, break_cycles_in_term, 0);
|
||||||
Yap_InitCPred("term_variables", 2, term_variables, 0);
|
Yap_InitCPred("term_variables", 2, term_variables, 0);
|
||||||
Yap_InitCPred("term_variables", 3, term_variables3, 0);
|
Yap_InitCPred("term_variables", 3, term_variables3, 0);
|
||||||
Yap_InitCPred("$variables_in_term", 3, variables_in_term, 0);
|
Yap_InitCPred("$variables_in_term", 3, variables_in_term, 0);
|
||||||
|
75
C/write.c
75
C/write.c
@ -410,51 +410,6 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
lastw = alphanum;
|
lastw = alphanum;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static inline bool was_visited(Term t, wglbs *wg, Term *ta ) {
|
|
||||||
Term *tp;
|
|
||||||
if (IsApplTerm(t)) {
|
|
||||||
if (IsExtensionFunctor(FunctorOfTerm(t)))
|
|
||||||
return false;
|
|
||||||
tp = RepAppl(t);
|
|
||||||
}
|
|
||||||
else if (IsPairTerm(t)) tp = RepPair(t);
|
|
||||||
else return false;
|
|
||||||
if (IsAtomTerm(*tp)) {
|
|
||||||
CELL *pt= (CELL*)AtomOfTerm(*tp);
|
|
||||||
if (pt >= wg->visited0 &&
|
|
||||||
pt < wg->visited) {
|
|
||||||
int depth = (wg->visited+1)-tp;
|
|
||||||
wrputs(" @( ", wg->stream);
|
|
||||||
wrputn(depth, wg);
|
|
||||||
wrputs( " ) ", wg->stream);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
wg->visited[0] = *tp;
|
|
||||||
*tp = MkAtomTerm( (Atom)wg->visited );
|
|
||||||
wg++;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline Term visited_indirection(Term t, wglbs *wg ) {
|
|
||||||
Term *tp = (CELL *)AtomOfTerm(t);
|
|
||||||
if (tp >= wg->visited0
|
|
||||||
&& (CELL *) *tp < wg->visited_top)
|
|
||||||
return *tp;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline void done_visiting(Term t, wglbs *wg) {
|
|
||||||
Term *tp;
|
|
||||||
if (IsApplTerm(t)) tp = RepAppl(t);
|
|
||||||
else if (IsPairTerm(t)) tp = RepPair(t);
|
|
||||||
else return;
|
|
||||||
*tp = *--wg->visited;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* writes a blob (default) */
|
/* writes a blob (default) */
|
||||||
static int wrputblob(AtomEntry *ref, int Quote_illegal,
|
static int wrputblob(AtomEntry *ref, int Quote_illegal,
|
||||||
struct write_globs *wglb) {
|
struct write_globs *wglb) {
|
||||||
@ -777,14 +732,9 @@ static void write_list(Term t, int direction, int depth,
|
|||||||
struct rewind_term nrwt;
|
struct rewind_term nrwt;
|
||||||
nrwt.parent = rwt;
|
nrwt.parent = rwt;
|
||||||
nrwt.u_sd.s.ptr = 0;
|
nrwt.u_sd.s.ptr = 0;
|
||||||
Term hot;
|
|
||||||
if (was_visited(t, wglb, &hot)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bool loop = true;
|
bool loop = true;
|
||||||
while (loop) {
|
while (loop) {
|
||||||
loop = false;
|
loop = false;
|
||||||
PROTECT(t, writeTerm(hot, 999, depth + 1, FALSE, wglb, &nrwt));
|
|
||||||
ti = TailOfTerm(t);
|
ti = TailOfTerm(t);
|
||||||
if (IsVarTerm(ti))
|
if (IsVarTerm(ti))
|
||||||
break;
|
break;
|
||||||
@ -838,25 +788,15 @@ static void writeTerm(Term t, int p, int depth, int rinfixarg,
|
|||||||
} else if (IsIntTerm(t)) {
|
} else if (IsIntTerm(t)) {
|
||||||
wrputn((Int)IntOfTerm(t), wglb);
|
wrputn((Int)IntOfTerm(t), wglb);
|
||||||
} else if (IsAtomTerm(t)) {
|
} else if (IsAtomTerm(t)) {
|
||||||
Term tn;
|
|
||||||
if ((tn = visited_indirection(t, wglb))!=0) {
|
|
||||||
writeTerm(tn,p,depth,rinfixarg,wglb,rwt);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
putAtom(AtomOfTerm(t), wglb->Quote_illegal, wglb);
|
putAtom(AtomOfTerm(t), wglb->Quote_illegal, wglb);
|
||||||
} else if (IsPairTerm(t)) {
|
} else if (IsPairTerm(t)) {
|
||||||
if (wglb->Ignore_ops) {
|
if (wglb->Ignore_ops) {
|
||||||
wrputs("'.'(", wglb->stream);
|
wrputs("'.'(", wglb->stream);
|
||||||
lastw = separator;
|
lastw = separator;
|
||||||
Term hot;
|
|
||||||
if ((was_visited(t, wglb, &hot))) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PROTECT(t, writeTerm(hot, 999, depth + 1, FALSE, wglb, &nrwt));
|
PROTECT(t, writeTerm(HeadOfTerm(t), 999, depth + 1, FALSE, wglb, &nrwt));
|
||||||
wrputs(",", wglb->stream);
|
wrputs(",", wglb->stream);
|
||||||
writeTerm(TailOfTerm(t), 999, depth + 1, FALSE, wglb, &nrwt);
|
writeTerm(TailOfTerm(t), 999, depth + 1, FALSE, wglb, &nrwt);
|
||||||
done_visiting(t, wglb);
|
|
||||||
wrclose_bracket(wglb, TRUE);
|
wrclose_bracket(wglb, TRUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -936,10 +876,6 @@ if ((was_visited(t, wglb, &hot))) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Term argf;
|
|
||||||
if (was_visited(t, wglb, &argf)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!wglb->Ignore_ops && Arity == 1 && Yap_IsPrefixOp(atom, &op, &rp)) {
|
if (!wglb->Ignore_ops && Arity == 1 && Yap_IsPrefixOp(atom, &op, &rp)) {
|
||||||
Term tright = ArgOfTerm(1, t);
|
Term tright = ArgOfTerm(1, t);
|
||||||
@ -1073,7 +1009,6 @@ if ((was_visited(t, wglb, &hot))) {
|
|||||||
if (k == -1) {
|
if (k == -1) {
|
||||||
wrputc('_', wglb->stream);
|
wrputc('_', wglb->stream);
|
||||||
lastw = alphanum;
|
lastw = alphanum;
|
||||||
done_visiting(t, wglb);
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
wrputc((k % 26) + 'A', wglb->stream);
|
wrputc((k % 26) + 'A', wglb->stream);
|
||||||
@ -1145,7 +1080,6 @@ if ((was_visited(t, wglb, &hot))) {
|
|||||||
writeTerm(ArgOfTerm(op, t), 999, depth + 1, FALSE, wglb, &nrwt);
|
writeTerm(ArgOfTerm(op, t), 999, depth + 1, FALSE, wglb, &nrwt);
|
||||||
wrclose_bracket(wglb, TRUE);
|
wrclose_bracket(wglb, TRUE);
|
||||||
}
|
}
|
||||||
done_visiting(t, wglb);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1176,11 +1110,8 @@ void Yap_plwrite(Term t, StreamDesc *mywrite, int max_depth, int flags,
|
|||||||
wglb.lw = separator;
|
wglb.lw = separator;
|
||||||
Term tp;
|
Term tp;
|
||||||
|
|
||||||
if ((flags & Handle_cyclics_f) ){
|
if ( 0&& (flags & Handle_cyclics_f) ){
|
||||||
// tp = Yap_CyclesInTerm(t PASS_REGS);
|
tp = Yap_BreakCyclesInTerm(t PASS_REGS);
|
||||||
wglb.visited = Malloc(1024*sizeof(CELL)),
|
|
||||||
wglb.visited0 = wglb.visited,
|
|
||||||
wglb.visited_top = wglb.visited+1024;
|
|
||||||
} else {
|
} else {
|
||||||
tp = t;
|
tp = t;
|
||||||
}
|
}
|
||||||
|
@ -446,7 +446,7 @@ bool Yap_isDirectory(const char *FileName);
|
|||||||
extern bool Yap_Exists(const char *f);
|
extern bool Yap_Exists(const char *f);
|
||||||
|
|
||||||
/* terms.c */
|
/* terms.c */
|
||||||
extern Term Yap_CyclesInTerm(Term t USES_REGS);
|
extern Term Yap_BreakCyclesInTerm(Term t USES_REGS);
|
||||||
extern bool Yap_IsCyclicTerm(Term inp USES_REGS);
|
extern bool Yap_IsCyclicTerm(Term inp USES_REGS);
|
||||||
extern Term Yap_BreakCycles(Term inp, UInt arity, Term *listp USES_REGS);
|
extern Term Yap_BreakCycles(Term inp, UInt arity, Term *listp USES_REGS);
|
||||||
extern void Yap_InitTermCPreds(void);
|
extern void Yap_InitTermCPreds(void);
|
||||||
|
Reference in New Issue
Block a user