fixes to C interface

This commit is contained in:
Vítor Santos Costa
2018-05-30 08:12:51 +01:00
parent e9274ef5d3
commit 8cfeb53e77
5 changed files with 52 additions and 73 deletions

View File

@@ -69,13 +69,14 @@ argi(N,I,I1) :-
I1 is I+1.
python_query( Caller, String ) :-
atomic_to_term( String, Goal, VarNames ),
writeln(String),
atomic_to_term( String, Goal, VarNames ),
query_to_answer( Goal, VarNames, Status, Bindings),
Caller.port := Status,
Caller.q.port := Status,
% := print( gc.get_referrers(Caller.port)),
write_query_answer( Bindings ),
nl(user_error),
Caller.answer := {},
Caller.q.answer := {},
maplist(in_dict(Caller.answer), Bindings).
% := print( "b", gc.get_referrers(Caller.answer)).

View File

@@ -73,8 +73,8 @@ class Query:
raise StopIteration()
if self.q.next():
rc = self.q.answer
if self.q.port == "exit":
return rc
# if self.q.port == "exit":
return rc
else:
if self:
self.close()
@@ -138,7 +138,7 @@ class YAPShell:
# # vs is the list of variables
# you can print it out, the left-side is the variable name,
# the right side wraps a handle to a variable
import pdb; pdb.set_trace()
#import pdb; pdb.set_trace()
# #pdb.set_trace()
# atom match either symbols, or if no symbol exists, sttrings, In this case
# variable names should match strings
@@ -154,7 +154,9 @@ class YAPShell:
g.release()
g = python_query(self, query)
self.q = Query( engine, g )
print(self.q.port)
for bind in self.q:
print(bind,self.q.port)
bindings += [bind]
if loop:
continue
@@ -175,6 +177,7 @@ class YAPShell:
break
if self.q:
self.q.close()
self.q = None
if bindings:
return True,bindings
print("No (more) answers")
@@ -183,7 +186,9 @@ class YAPShell:
if not self.q:
return False, None
self.q.close()
print("Exception")
self.q = None
print("Exception",e)
e.errorNo = 0
return False, None
def live(self, engine, **kwargs):
@@ -193,8 +198,9 @@ class YAPShell:
try:
s = input("?- ")
if not s:
loop = False
continue
else:
print(s)
self.query_prolog(s)
except SyntaxError as err:
print("Syntax Error error: {0}".format(err))