deb
This commit is contained in:
parent
e5945b8e8b
commit
4092003cd6
72
C/terms.c
72
C/terms.c
@ -28,6 +28,8 @@
|
||||
|
||||
#include "YapHeap.h"
|
||||
|
||||
#define debug_pop_text_stack(l) [ if (to_visit != to_visit0) printf("%d\n",__LINE__); pop_text_stack(l) }
|
||||
|
||||
#include "attvar.h"
|
||||
#include "yapio.h"
|
||||
#ifdef HAVE_STRING_H
|
||||
@ -155,8 +157,9 @@ typedef struct non_single_struct_t {
|
||||
++pt0; \
|
||||
ptd0 = pt0; \
|
||||
d0 = *ptd0; \
|
||||
list_loop: \
|
||||
deref_head(d0, var_in_term_unk); \
|
||||
list_loop: \
|
||||
fprintf(stderr,"%ld at %s\n", to_visit-to_visit0, __FUNCTION__);\
|
||||
deref_head(d0, var_in_term_unk); \
|
||||
var_in_term_nvar : { \
|
||||
if (IsPairTerm(d0)) { \
|
||||
if (to_visit + 32 >= to_visit_max) { \
|
||||
@ -256,19 +259,19 @@ typedef struct non_single_struct_t {
|
||||
CELL *ptd0 = to_visit->ptd0; \
|
||||
*ptd0 = to_visit->d0; \
|
||||
} \
|
||||
pop_text_stack(lvl); \
|
||||
pop_text_stack(lvl); fprintf(stderr,"<%ld at %s\n", to_visit-to_visit0, __FUNCTION__);\
|
||||
return true; \
|
||||
}
|
||||
|
||||
#define CYC_APPL \
|
||||
if (IsAtomTerm((CELL)f)) { \
|
||||
if (IsAtomTerm((CELL)f)) { \
|
||||
while (to_visit > to_visit0) { \
|
||||
to_visit--; \
|
||||
CELL *ptd0 = to_visit->ptd0; \
|
||||
*ptd0 = to_visit->d0; \
|
||||
} \
|
||||
pop_text_stack(lvl); \
|
||||
return true; \
|
||||
pop_text_stack(lvl); fprintf(stderr,"<%d at %s\n", to_visit-to_visit0, __FUNCTION__);\
|
||||
return true; \
|
||||
}
|
||||
|
||||
/**
|
||||
@ -697,6 +700,7 @@ static Term attvars_in_complex_term(register CELL *pt0, register CELL *pt0_end,
|
||||
|
||||
clean_tr(TR0 PASS_REGS);
|
||||
pop_text_stack(lvl);
|
||||
fprintf(stderr,"<%ld at %s\n", to_visit-to_visit0, __FUNCTION__);
|
||||
if (HR != InitialH) {
|
||||
/* close the list */
|
||||
Term t2 = Deref(inp);
|
||||
@ -1000,7 +1004,7 @@ static Term bind_vars_in_complex_term(CELL *pt0, CELL *pt0_end,
|
||||
if (to_visit > to_visit0) {
|
||||
to_visit--;
|
||||
pt0 = to_visit->ptd0;
|
||||
*pt0 = to_visit0->d0;
|
||||
*pt0 = to_visit->d0;
|
||||
goto list_loop;
|
||||
}
|
||||
|
||||
@ -1311,7 +1315,7 @@ static Int largest_numbervar(USES_REGS1) {
|
||||
return Yap_unify(MaxNumberedVar(Deref(ARG1), 2 PASS_REGS), ARG2);
|
||||
}
|
||||
|
||||
static Term BREAK_LOOP(int ddep) {
|
||||
static Term BREAK_LOOP(Int ddep) {
|
||||
Term t0 = MkIntegerTerm(ddep);
|
||||
return Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("@^"), 1), 1, &t0);
|
||||
}
|
||||
@ -1326,28 +1330,26 @@ static Term UNFOLD_LOOP(Term t, Term *b) {
|
||||
return o;
|
||||
}
|
||||
|
||||
static int loops_in_complex_term(CELL *pt0, CELL *pt0_end,
|
||||
Term *listp,
|
||||
Term tail USES_REGS) {
|
||||
static Term *loops_in_complex_term(CELL *pt0, CELL *pt0_end,
|
||||
Term *listp USES_REGS) {
|
||||
int lvl = push_text_stack();
|
||||
|
||||
struct non_single_struct_t *to_visit = Malloc(
|
||||
1024 * sizeof(struct non_single_struct_t)),
|
||||
*to_visit0 = to_visit,
|
||||
*to_visit_max = to_visit + 1024;
|
||||
|
||||
CELL *ptf = HR;
|
||||
CELL *ptd0;
|
||||
if (listp)
|
||||
*listp = tail;
|
||||
restart:
|
||||
CELL *ptd0;
|
||||
CELL *ptf0 = HR,
|
||||
*ptf = HR;
|
||||
restart:
|
||||
while (pt0 < pt0_end) {
|
||||
CELL d0;
|
||||
++pt0;
|
||||
ptd0 = pt0;
|
||||
d0 = *ptd0;
|
||||
list_loop:
|
||||
deref_head(d0, vars_in_term_unk);
|
||||
fprintf(stderr,"%d at %s\n", to_visit-to_visit0, __FUNCTION__);
|
||||
deref_head(d0, vars_in_term_unk);
|
||||
vars_in_term_nvar:
|
||||
if (IsPairTerm(d0)) {
|
||||
if (to_visit + 32 >= to_visit_max) {
|
||||
@ -1361,8 +1363,7 @@ restart:
|
||||
struct non_single_struct_t *v0 =
|
||||
(struct non_single_struct_t *)AtomOfTerm(d0);
|
||||
if (listp) {
|
||||
*ptf = UNFOLD_LOOP(AbsPair(v0->ptf-1), listp);
|
||||
ptf++;
|
||||
*ptf++ = UNFOLD_LOOP(AbsPair(v0->ptf-1), listp);
|
||||
} else {
|
||||
*ptf++ = BREAK_LOOP(to_visit - v0);
|
||||
}
|
||||
@ -1395,8 +1396,7 @@ restart:
|
||||
if (IsAtomTerm((CELL)f)) {
|
||||
struct non_single_struct_t *v0 = (struct non_single_struct_t *)AtomOfTerm(*ptd0);
|
||||
if (listp) {
|
||||
*ptf = UNFOLD_LOOP(AbsAppl(v0->ptf-1), listp);
|
||||
ptf++;
|
||||
*ptf++ = UNFOLD_LOOP(AbsAppl(v0->ptf-1), listp);
|
||||
} else {
|
||||
*ptf++ = BREAK_LOOP(to_visit - v0);
|
||||
}
|
||||
@ -1425,7 +1425,7 @@ restart:
|
||||
goto restart;
|
||||
|
||||
derefa_body(d0, ptd0, vars_in_term_unk, vars_in_term_nvar);
|
||||
*ptf++ = (CELL)ptd0;
|
||||
*ptf++ = *ptd0;
|
||||
goto restart;
|
||||
}
|
||||
/* Do we still have compound terms to visit */
|
||||
@ -1439,28 +1439,24 @@ restart:
|
||||
*ptd0 = to_visit->d0;
|
||||
goto restart;
|
||||
}
|
||||
fprintf(stderr,"exit %d at %s\n", to_visit-to_visit0, __FUNCTION__);
|
||||
|
||||
pop_text_stack(lvl);
|
||||
return 0;
|
||||
return ptf0;
|
||||
|
||||
def_aux_overflow();
|
||||
}
|
||||
|
||||
Term Yap_BreakCycles(Term inp, UInt arity, Term *listp, Term tail USES_REGS) {
|
||||
Term Yap_BreakCycles(Term inp, UInt arity, Term *listp USES_REGS) {
|
||||
Term t = Deref(inp);
|
||||
|
||||
if (IsVarTerm(t) || IsPrimitiveTerm(t)) {
|
||||
return t;
|
||||
} else {
|
||||
Int res;
|
||||
CELL *op = HR;
|
||||
res = loops_in_complex_term((&t) - 1, &t, listp, tail PASS_REGS);
|
||||
if (res < 0)
|
||||
return -1;
|
||||
if (IsPairTerm(t))
|
||||
return AbsPair(op);
|
||||
else
|
||||
return AbsAppl(op);
|
||||
} else if (IsPairTerm(t)) {
|
||||
return AbsPair(loops_in_complex_term((&t) - 1, &t, listp PASS_REGS));
|
||||
}
|
||||
return AbsAppl(loops_in_complex_term((&t) - 1, &t, listp PASS_REGS));
|
||||
|
||||
}
|
||||
|
||||
/** @pred rational_term_to_tree(? _TI_,- _TF_, ?SubTerms, ?MoreSubterms)
|
||||
@ -1476,11 +1472,11 @@ Term Yap_BreakCycles(Term inp, UInt arity, Term *listp, Term tail USES_REGS) {
|
||||
*/
|
||||
static Int p_break_rational(USES_REGS1) {
|
||||
Term t = (ARG1);
|
||||
Term l = Deref(ARG4), k;
|
||||
Term l = Deref(ARG4);
|
||||
if (IsVarTerm(l))
|
||||
Yap_unify(l, MkVarTerm());
|
||||
return Yap_unify(Yap_BreakCycles(t, 4, &k, l PASS_REGS), ARG2) &&
|
||||
Yap_unify(k, ARG3);
|
||||
return Yap_unify(Yap_BreakCycles(t, 4, &l PASS_REGS), ARG2) &&
|
||||
Yap_unify(l, ARG3) ;
|
||||
}
|
||||
|
||||
void Yap_InitTermCPreds(void) {
|
||||
|
25
C/write.c
25
C/write.c
@ -70,11 +70,11 @@ typedef struct rewind_term {
|
||||
|
||||
typedef struct write_globs {
|
||||
StreamDesc *stream;
|
||||
int Quote_illegal, Ignore_ops, Handle_vars, Use_portray, Portray_delays;
|
||||
int Keep_terms;
|
||||
int Write_Loops;
|
||||
int Write_strings;
|
||||
int last_atom_minus;
|
||||
bool Quote_illegal, Ignore_ops, Handle_vars, Use_portray, Portray_delays;
|
||||
bool Keep_terms;
|
||||
bool Write_Loops;
|
||||
bool Write_strings;
|
||||
UInt last_atom_minus;
|
||||
UInt MaxDepth, MaxArgs;
|
||||
wtype lw;
|
||||
} wglbs;
|
||||
@ -1089,8 +1089,21 @@ void Yap_plwrite(Term t, StreamDesc *mywrite, int max_depth, int flags,
|
||||
wglb.stream = mywrite;
|
||||
wglb.Ignore_ops = flags & Ignore_ops_f;
|
||||
wglb.Write_strings = flags & BackQuote_String_f;
|
||||
wglb.Use_portray = false;
|
||||
wglb.Handle_vars = true;
|
||||
wglb.Use_portray = false;
|
||||
wglb.Portray_delays = false;
|
||||
wglb.Keep_terms = false;
|
||||
wglb.Write_Loops = false;
|
||||
wglb.Write_strings = false;
|
||||
wglb.Quote_illegal = false;
|
||||
wglb.Ignore_ops = false;
|
||||
wglb.MaxDepth = false;
|
||||
wglb.MaxArgs = false;
|
||||
wglb.lw = separator;
|
||||
|
||||
if ((flags & Handle_cyclics_f) && Yap_IsCyclicTerm(t) ){
|
||||
t = Yap_BreakCycles(t, 3, NULL, TermNil PASS_REGS);
|
||||
t = Yap_BreakCycles(t, 3, NULL PASS_REGS);
|
||||
}
|
||||
/* protect slots for portray */
|
||||
writeTerm(t, priority, 1, false, &wglb, &rwt);
|
||||
|
@ -446,7 +446,7 @@ extern bool Yap_Exists(const char *f);
|
||||
|
||||
/* terms.c */
|
||||
extern bool Yap_IsCyclicTerm(Term inp USES_REGS);
|
||||
extern Term Yap_BreakCycles(Term inp, UInt arity, Term *listp, Term tail USES_REGS);
|
||||
extern Term Yap_BreakCycles(Term inp, UInt arity, Term *listp USES_REGS);
|
||||
extern void Yap_InitTermCPreds(void);
|
||||
|
||||
/* threads.c */
|
||||
|
@ -2,21 +2,24 @@
|
||||
|
||||
:- linitialization(main).
|
||||
|
||||
:- op(700, xfx, :=: ).
|
||||
|
||||
main :-
|
||||
main( cyclic_term(X), X).
|
||||
main :-
|
||||
writeln('-----------------------'),
|
||||
writeln('--- cyclic_term/1 --------------------'),
|
||||
fail.
|
||||
main :-
|
||||
main( ground(X), X).
|
||||
main :-
|
||||
writeln('-----------------------'),
|
||||
writeln('--- ground/1 ------------------'),
|
||||
fail.
|
||||
main :-
|
||||
main2( (terms:variables_in_term(X, O), writeln(X=O) ), X, L, O).
|
||||
main2( (terms:variables_in_term(X, O), writeln(X=O) ), X, L, O).
|
||||
main :-
|
||||
writeln('-----------------------'),
|
||||
writeln('--------variables_in_term/2, writeln/1 ---------------'),
|
||||
fail.
|
||||
|
||||
main :-
|
||||
main2( (terms:new_variables_in_term(L,X, O), writeln(X+L=O) ), X, L, O).
|
||||
main :-
|
||||
@ -30,7 +33,22 @@ main :-
|
||||
main :-
|
||||
main( writeln(X), X).
|
||||
main :-
|
||||
writeln('-----------------------'),
|
||||
writeln('------rational_term_to_tree(X,A,B,[]),\
|
||||
writeln((A->B) -----------------'),
|
||||
fail.
|
||||
main :-
|
||||
main((rational_term_to_tree(X,A,B,[]),
|
||||
writeln((A->B))), X).
|
||||
main :-
|
||||
writeln('------ numbervars(A+B,1,_),\
|
||||
writeln((A->B) -----------------'),
|
||||
fail.
|
||||
main :-
|
||||
main(( numbervars(A+B,1,_),
|
||||
writeln((A->B))), X).
|
||||
main :-
|
||||
writeln('------rational_term_to_tree(X,A,B,[]), numbervars(A+B,1,_),\
|
||||
writeln((A->B) -----------------'),
|
||||
fail.
|
||||
main :-
|
||||
main((rational_term_to_tree(X,A,B,[]), numbervars(A+B,1,_),
|
||||
@ -55,35 +73,36 @@ m( G ) :-
|
||||
writeln(no),
|
||||
end.
|
||||
|
||||
d(X) :- X = [_A].
|
||||
d(X) :- X = [a,_A].
|
||||
d(X) :- X = [X].
|
||||
d(X) :- X = [_|X].
|
||||
d(X) :- X = [_,X].
|
||||
d(X) :- X = [_,x].
|
||||
d(X) :- X = [_,x(X)].
|
||||
d(X) :- X= f(X).
|
||||
d(X) :- X= f(X,X).
|
||||
d(X) :- X= f(_,X).
|
||||
d(X) :- X= f(A,A,X).
|
||||
d(X) :- X= f(A,A,g(A)).
|
||||
d(X) :- X= f(A,g(X,[A|A]),X).
|
||||
d(X) :- X= f(X,[X,X]).
|
||||
d(X) :- X= f(X,[X,g(X)]).
|
||||
d(X) :- X= f(_,X/[X]).
|
||||
d(X) :- X= f(_,A/[A]), A= f(X,[X,g(X)]).
|
||||
d(X) :- X= f(_,A/[A]), A= f(X,[A,g(X)]).
|
||||
d(X) :- X= f(_,A/[A]), A= f(B,[X,g(A)]), B=[C|B], C=[X].
|
||||
d(X) :- X :=: [_A].
|
||||
d(X) :- X :=: [a,_A].
|
||||
d(X) :- X :=: [X].
|
||||
d(X) :- X :=: [_|X].
|
||||
d(X) :- X :=: [_,X].
|
||||
d(X) :- X :=: [_,x].
|
||||
d(X) :- X :=: [_,x(X)].
|
||||
d(X) :- X:=: f(X).
|
||||
d(X) :- X:=: f(X,X).
|
||||
d(X) :- X:=: f(_,X).
|
||||
d(X) :- X:=: f(A,A,X).
|
||||
d(X) :- X:=: f(A,A,g(A)).
|
||||
d(X) :- X:=: f(A,g(X,[A|A]),X).
|
||||
d(X) :- X:=: f(X,[X,X]).
|
||||
d(X) :- X:=: f(X,[X,g(X)]).
|
||||
d(X) :- X:=: f(_,X/[X]).
|
||||
d(X) :- X:=: f(_,A/[A]), A:=: f(X,[X,g(X)]).
|
||||
d(X) :- X:=: f(_,A/[A]), A:=: f(X,[A,g(X)]).
|
||||
d(X) :- X:=: f(_,A/[A]), A:=: f(B,[X,g(A)]), B:=:[C|B], C:=:[X].
|
||||
|
||||
end :- writeln('....'), fail.
|
||||
|
||||
e(X,Y) :- X = t(_A,B,_C,D), Y = [B,E].
|
||||
e(X,Y) :- X = t(_A,_B,_C,_D), Y = [_,_E].
|
||||
e(X,Y) :- X = t(A,_B,C,_D), Y = [ A,C].
|
||||
e(X,Y) :- X = t(A,[X,_D]), Y = [A,_C,_E].
|
||||
e(X,Y) :- X = t(A,[X,C]), Y = [A,C,_E].
|
||||
e(X,Y) :- X = t(A,X,_B,[X,C,_D]), Y = [A,C,E].
|
||||
|
||||
/*
|
||||
e(X,Y) :- X :=: t(_A,B,_C,D), Y :=: [B,E].
|
||||
e(X,Y) :- X :=: t(_A,_B,_C,_D), Y :=: [_,_E].
|
||||
e(X,Y) :- X :=: t(A,_B,C,_D), Y :=: [ A,C].
|
||||
e(X,Y) :- X :=: t(A,[X,_D]), Y :=: [A,_C,_E].
|
||||
e(X,Y) :- X :=: t(A,[X,C]), Y :=: [A,C,_E].
|
||||
*/
|
||||
e(X,Y) :- X :=: t(A,X,_B,[X,C,_D]), Y :=: [A,C,_E].
|
||||
|
||||
a(no, no).
|
||||
a(no, no).
|
||||
@ -102,3 +121,7 @@ a(yes, yes).
|
||||
a(yes, yes).
|
||||
a(yes, no).
|
||||
a(yes, no).
|
||||
|
||||
X :-: Y :- writeln(X), fail.
|
||||
X :=: X.
|
||||
|
||||
|
Reference in New Issue
Block a user