write infinite terms
This commit is contained in:
parent
d5c1ca716e
commit
ecab37f72c
2
C/exec.c
2
C/exec.c
@ -1615,6 +1615,8 @@ void Yap_fail_all(choiceptr bb USES_REGS) {
|
||||
saved_p = P;
|
||||
saved_cp = CP;
|
||||
/* prune away choicepoints */
|
||||
if (B == bb)
|
||||
return;
|
||||
while (B->cp_b && B->cp_b != bb && B->cp_ap != NOCODE) {
|
||||
B = B->cp_b;
|
||||
#ifdef YAPOR
|
||||
|
42
C/write.c
42
C/write.c
@ -687,9 +687,10 @@ static void putUnquotedString(Term string, struct write_globs *wglb)
|
||||
static Term from_pointer(CELL *ptr0, struct rewind_term *rwt,
|
||||
struct write_globs *wglb) {
|
||||
CACHE_REGS
|
||||
Term t;
|
||||
Term t, ti;
|
||||
CELL *ptr = ptr0;
|
||||
|
||||
int i = 0;
|
||||
|
||||
while (IsVarTerm(*ptr) && !IsUnboundVar(ptr))
|
||||
ptr = (CELL *)*ptr;
|
||||
t = *ptr;
|
||||
@ -701,9 +702,13 @@ static Term from_pointer(CELL *ptr0, struct rewind_term *rwt,
|
||||
|
||||
if (!IsAtomicTerm(t) && !IsVarTerm(t)) {
|
||||
while (x) {
|
||||
if (Yap_GetDerefedFromSlot(x->u_sd.s.old) == t)
|
||||
return TermFoundVar;
|
||||
if (Yap_GetDerefedFromSlot(x->u_sd.s.old) == t) {
|
||||
ti = MkIntegerTerm(i);
|
||||
return Yap_MkApplTerm(FunctorDoubleHat, 1, &ti);
|
||||
}
|
||||
x = x->parent;
|
||||
i++;
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -713,9 +718,12 @@ static Term from_pointer(CELL *ptr0, struct rewind_term *rwt,
|
||||
struct rewind_term *x = rwt->parent;
|
||||
|
||||
while (x) {
|
||||
if (x->u_sd.d.old == t)
|
||||
return TermFoundVar;
|
||||
if (x->u_sd.d.old == t) {
|
||||
ti = MkIntegerTerm(i);
|
||||
return Yap_MkApplTerm(FunctorDoubleHat, 1, &ti);
|
||||
}
|
||||
x = x->parent;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -790,20 +798,23 @@ static void write_var(CELL *t, struct write_globs *wglb,
|
||||
}
|
||||
}
|
||||
|
||||
static Term check_infinite_loop(Term t, struct rewind_term *x,
|
||||
static int check_infinite_loop(Term t, struct rewind_term *x,
|
||||
struct write_globs *wglb) {
|
||||
CACHE_REGS
|
||||
if (wglb->Keep_terms) {
|
||||
int i =0;
|
||||
if (wglb->Keep_terms) {
|
||||
while (x) {
|
||||
if (Yap_GetFromSlot(x->u_sd.s.old) == t)
|
||||
return TermFoundVar;
|
||||
return i;
|
||||
x = x->parent;
|
||||
i++;
|
||||
}
|
||||
} else {
|
||||
while (x) {
|
||||
if (x->u_sd.d.old == t)
|
||||
return TermFoundVar;
|
||||
return i;
|
||||
x = x->parent;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return t;
|
||||
@ -826,9 +837,16 @@ static void write_list(Term t, int direction, int depth,
|
||||
ti = TailOfTerm(t);
|
||||
if (IsVarTerm(ti))
|
||||
break;
|
||||
if (!IsPairTerm(ti) ||
|
||||
!IsPairTerm((ti = check_infinite_loop(ti, rwt, wglb))))
|
||||
if (!IsPairTerm(ti))
|
||||
break;
|
||||
int i;
|
||||
if ((i = check_infinite_loop(ti, rwt, wglb))>0) {
|
||||
char s[1024];
|
||||
snprintf(s, 1023, "%d", i);
|
||||
wrputs(" ^^(", wglb->stream);
|
||||
wrputs(s, wglb->stream);
|
||||
wrputs(") ", wglb->stream);
|
||||
}
|
||||
ndirection = RepPair(ti) - RepPair(t);
|
||||
/* make sure we're not trapped in loops */
|
||||
if (ndirection > 0) {
|
||||
|
2
H/ATOMS
2
H/ATOMS
@ -187,6 +187,7 @@ A GlobalSp N "global_sp"
|
||||
A GlobalTrie N "global_trie"
|
||||
A GoalExpansion N "goal_expansion"
|
||||
A Hat N "^"
|
||||
A DoubleHat N "^^"
|
||||
A HERE N "\n <====HERE====> \n"
|
||||
A HandleThrow F "$handle_throw"
|
||||
A Heap N "heap"
|
||||
@ -535,6 +536,7 @@ F GoalExpansion2 GoalExpansion 2
|
||||
F GoalExpansion GoalExpansion 3
|
||||
F HandleThrow HandleThrow 3
|
||||
F Hat Hat 2
|
||||
F DoubleHat DoubleHat 1
|
||||
F I I 2
|
||||
F Id Id 1
|
||||
F Info1 Info 1
|
||||
|
@ -182,6 +182,7 @@
|
||||
AtomGlobalTrie = Yap_LookupAtom("global_trie"); TermGlobalTrie = MkAtomTerm(AtomGlobalTrie);
|
||||
AtomGoalExpansion = Yap_LookupAtom("goal_expansion"); TermGoalExpansion = MkAtomTerm(AtomGoalExpansion);
|
||||
AtomHat = Yap_LookupAtom("^"); TermHat = MkAtomTerm(AtomHat);
|
||||
AtomDoubleHat = Yap_LookupAtom("^^"); TermDoubleHat = MkAtomTerm(AtomDoubleHat);
|
||||
AtomHERE = Yap_LookupAtom("\n <====HERE====> \n"); TermHERE = MkAtomTerm(AtomHERE);
|
||||
AtomHandleThrow = Yap_FullLookupAtom("$handle_throw"); TermHandleThrow = MkAtomTerm(AtomHandleThrow);
|
||||
AtomHeap = Yap_LookupAtom("heap"); TermHeap = MkAtomTerm(AtomHeap);
|
||||
@ -530,6 +531,7 @@
|
||||
FunctorGoalExpansion = Yap_MkFunctor(AtomGoalExpansion,3);
|
||||
FunctorHandleThrow = Yap_MkFunctor(AtomHandleThrow,3);
|
||||
FunctorHat = Yap_MkFunctor(AtomHat,2);
|
||||
FunctorDoubleHat = Yap_MkFunctor(AtomDoubleHat,1);
|
||||
FunctorI = Yap_MkFunctor(AtomI,2);
|
||||
FunctorId = Yap_MkFunctor(AtomId,1);
|
||||
FunctorInfo1 = Yap_MkFunctor(AtomInfo,1);
|
||||
|
@ -182,6 +182,7 @@
|
||||
AtomGlobalTrie = AtomAdjust(AtomGlobalTrie); TermGlobalTrie = MkAtomTerm(AtomGlobalTrie);
|
||||
AtomGoalExpansion = AtomAdjust(AtomGoalExpansion); TermGoalExpansion = MkAtomTerm(AtomGoalExpansion);
|
||||
AtomHat = AtomAdjust(AtomHat); TermHat = MkAtomTerm(AtomHat);
|
||||
AtomDoubleHat = AtomAdjust(AtomDoubleHat); TermDoubleHat = MkAtomTerm(AtomDoubleHat);
|
||||
AtomHERE = AtomAdjust(AtomHERE); TermHERE = MkAtomTerm(AtomHERE);
|
||||
AtomHandleThrow = AtomAdjust(AtomHandleThrow); TermHandleThrow = MkAtomTerm(AtomHandleThrow);
|
||||
AtomHeap = AtomAdjust(AtomHeap); TermHeap = MkAtomTerm(AtomHeap);
|
||||
@ -530,6 +531,7 @@
|
||||
FunctorGoalExpansion = FuncAdjust(FunctorGoalExpansion);
|
||||
FunctorHandleThrow = FuncAdjust(FunctorHandleThrow);
|
||||
FunctorHat = FuncAdjust(FunctorHat);
|
||||
FunctorDoubleHat = FuncAdjust(FunctorDoubleHat);
|
||||
FunctorI = FuncAdjust(FunctorI);
|
||||
FunctorId = FuncAdjust(FunctorId);
|
||||
FunctorInfo1 = FuncAdjust(FunctorInfo1);
|
||||
|
@ -182,6 +182,7 @@ X_API EXTERNAL Atom AtomGlobalSp; X_API EXTERNAL Term TermGlobalSp;
|
||||
X_API EXTERNAL Atom AtomGlobalTrie; X_API EXTERNAL Term TermGlobalTrie;
|
||||
X_API EXTERNAL Atom AtomGoalExpansion; X_API EXTERNAL Term TermGoalExpansion;
|
||||
X_API EXTERNAL Atom AtomHat; X_API EXTERNAL Term TermHat;
|
||||
X_API EXTERNAL Atom AtomDoubleHat; X_API EXTERNAL Term TermDoubleHat;
|
||||
X_API EXTERNAL Atom AtomHERE; X_API EXTERNAL Term TermHERE;
|
||||
X_API EXTERNAL Atom AtomHandleThrow; X_API EXTERNAL Term TermHandleThrow;
|
||||
X_API EXTERNAL Atom AtomHeap; X_API EXTERNAL Term TermHeap;
|
||||
@ -614,6 +615,8 @@ X_API EXTERNAL Functor FunctorHandleThrow;
|
||||
|
||||
X_API EXTERNAL Functor FunctorHat;
|
||||
|
||||
X_API EXTERNAL Functor FunctorDoubleHat;
|
||||
|
||||
X_API EXTERNAL Functor FunctorI;
|
||||
|
||||
X_API EXTERNAL Functor FunctorId;
|
||||
|
@ -207,8 +207,6 @@
|
||||
|
||||
:- module(learning,[do_learning/1,
|
||||
do_learning/2,
|
||||
set_problog_flag/2,
|
||||
problog_flag/2,
|
||||
reset_learning/0
|
||||
]).
|
||||
|
||||
@ -630,7 +628,7 @@ init_one_query(QueryID,Query,Type) :-
|
||||
rb_new(H0),
|
||||
maplist_to_hash(MapList, H0, Hash),
|
||||
Tree \= [],
|
||||
% writeln(Dir:Tree:MapList),
|
||||
writeln(QueryID),
|
||||
tree_to_grad(Tree, Hash, [], Grad),
|
||||
recordz(QueryID,bdd(Dir, Grad, MapList),_)
|
||||
)
|
||||
|
@ -181,7 +181,7 @@ display(Stream, T) :-
|
||||
/* interface to user portray */
|
||||
'$portray'(T) :-
|
||||
\+ '$undefined'(portray(_),user),
|
||||
'$system_catch'(call(portray(T)),user,Error,user:'$Error'(Error)), !,
|
||||
catch(user:portray(T),user,Error,user:'$Error'(Error)), !,
|
||||
set_value('$portray',true), fail.
|
||||
'$portray'(_) :- set_value('$portray',false), fail.
|
||||
|
||||
|
Reference in New Issue
Block a user