This commit is contained in:
Vitor Santos Costa 2018-05-31 00:15:48 +01:00
parent bbd0122fc3
commit 7325407d23
3 changed files with 15 additions and 20 deletions

View File

@ -1744,6 +1744,7 @@ X_API bool YAP_EnterGoal(YAP_PredEntryPtr ape, CELL *ptr, YAP_dogoalinfo *dgi) {
// HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot); // HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
out = Yap_exec_absmi(true, false); out = Yap_exec_absmi(true, false);
fprintf(stderr,"EnterGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n", out,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot); fprintf(stderr,"EnterGoal success=%d: H=%d ENV=%p B=%d TR=%d P=%p CP=%p Slots=%d\n", out,HR-H0,LCL0-ENV,LCL0-(CELL*)B,(CELL*)TR-LCL0, P, CP, LOCAL_CurSlot);
dgi->b = LCL0 - (CELL *)B;
if (out) { if (out) {
dgi->EndSlot = LOCAL_CurSlot; dgi->EndSlot = LOCAL_CurSlot;
Yap_StartSlots(); Yap_StartSlots();

View File

@ -72,11 +72,13 @@ python_query( Caller, String ) :-
atomic_to_term( String, Goal, VarNames ), atomic_to_term( String, Goal, VarNames ),
query_to_answer( Goal, VarNames, Status, Bindings), query_to_answer( Goal, VarNames, Status, Bindings),
atom_to_string( Status, SStatus ), atom_to_string( Status, SStatus ),
Caller.q.port := SStatus, Caller.port := SStatus,
start_low_level_trace,
write_query_answer( Bindings ), write_query_answer( Bindings ),
nl(user_error), nl(user_error),
Caller.q.answer := {}, Caller.answer := {},
maplist(in_dict(Caller.q.answer), Bindings). maplist(in_dict(Caller.answer), Bindings).
in_dict(Dict, var([V0,V|Vs])) :- !, in_dict(Dict, var([V0,V|Vs])) :- !,
Dict[V] := V0, Dict[V] := V0,
@ -84,6 +86,6 @@ in_dict(Dict, var([V0,V|Vs])) :- !,
in_dict(_Dict, var([_],_G)) :- !. in_dict(_Dict, var([_],_G)) :- !.
in_dict(Dict, nonvar([V0|Vs],G)) :- !, in_dict(Dict, nonvar([V0|Vs],G)) :- !,
Dict[V0] := G, Dict[V0] := G,
in_dict( Dict, nonvar(Vs, Gs)). in_dict( Dict, nonvar(Vs, G) ).
in_dict(_Dict, nonvar([],_G)) :- !. in_dict(_Dict, nonvar([],_G)) :- !.
in_dict(_, _). in_dict(_, _).

View File

@ -53,37 +53,29 @@ class Predicate( YAPPredicate ):
def __init__(self, t, module=None): def __init__(self, t, module=None):
super().__init__(t) super().__init__(t)
class Query: class Query (YAPQuery):
"""Goal is a predicate instantiated under a specific environment """ """Goal is a predicate instantiated under a specific environment """
def __init__(self, engine, g): def __init__(self, engine, g):
engine.reSet() super().__init__(g)
self.engine = engine self.engine = engine
self.q = engine.query(g)
if self.q:
self.port = "call" self.port = "call"
self.bindings = None self.bindings = None
self.engine = engine
self.answer = {} self.answer = {}
def __iter__(self): def __iter__(self):
return self return self
def __next__(self): def __next__(self):
if not self.q: if self.port == "exit" or self.port == "fail":
raise RuntimeError()
if self.port == "exit":
return return
else: else:
if self.q.next(): if self.next():
return self.port,self.answer return self.port,self.answer
else: else:
self.close() self.close()
def close( self ): def close( self ):
if self.q: self.engine.reSet()
self.q.close()
self.q = None
def name( name, arity): def name( name, arity):
try: try: