This commit is contained in:
Vitor Santos Costa 2018-12-12 00:39:17 +00:00
parent 7e84455117
commit 473132c3ec
4 changed files with 26 additions and 37 deletions

View File

@ -11,7 +11,7 @@ YAP_Term TermErrStream, TermOutStream;
static void pyflush(StreamDesc *st) {
#if 0
st->u.w_irl.ptr[0] = '\0';
fprintf(stderr,"%s\n", st->u.w_irl.buf);
// fprintf(stderr,"%s\n", st->u.w_irl.buf);
term_t tg = python_acquire_GIL();
if (st->user_name == TermOutStream){
PySys_WriteStdout("%s", st->u.w_irl.buf);
@ -103,7 +103,7 @@ static void *py_open(VFS_t *me, const char *name, const char *io_mode,
if (pystream == NULL || pystream == Py_None) {
python_release_GIL(ctk);
return NULL;
}
}
StreamDesc *st = YAP_RepStreamFromId(sno);
st->name = YAP_LookupAtom(name);
if (strcmp(name, "sys.stdout") == 0 || strcmp(name, "sys.stderr") == 0 ||

View File

@ -73,8 +73,7 @@ python_query( Caller, String ) :-
query_to_answer( Goal, VarNames, Status, Bindings),
Caller.port := Status,
write_query_answer( Bindings ),
nl(user_error),
Caller.answer := {},
nl(user_error),
maplist(in_dict(Caller.answer, Bindings), Bindings).
/**

View File

@ -522,7 +522,7 @@ class YAPRun(InteractiveShell):
self.query = None
self.os = None
self.it = None
self.port = None
self.port = "None"
self.answers = None
self.bindings = dicts = []
self.shell.yapeng = self.yapeng
@ -566,42 +566,37 @@ class YAPRun(InteractiveShell):
self.query.close()
self.query = None
self.port = None
self.answers = None
self.answers = []
self.os = program+squery
self.iterations = 0
pg = jupyter_query( self, program, squery)
self.query = self.yapeng.query(pg)
self.answers = []
self.port = "call"
self.port = "call"
found = False
self.answer = {}
while self.query.next():
#sys.stderr.write('B '+str( self.answer) +'\n')
#sys.stderr.write('C '+ str(self.port) +'\n'+'\n')
found = True
print( "uek",self.answer )
self.answers += [self.answer]
print( "ek",self.answers )
self.iterations += 1
if self.port == "exit":
if self.port == "exit" or stop or howmany == self.iterations:
self.os = None
#sys.stderr.write('Done, with'+str(self.answers)+'\n')
result.result = True,self.bindings
self.query.close()
self.query = None
if found:
sys.stderr.write('Completed, with '+str(self.answers)+'\n')
result.result = self.answers
return result
if stop or howmany == self.iterations:
result.result = True, self.answers
return result
if found:
sys.stderr.write('Done, with '+str(self.answers)+'\n')
else:
self.os = None
self.query.close()
self.query = None
sys.stderr.write('Fail\n')
result.result = True,self.bindings
return result
except Exception as e:
sys.stderr.write('Exception '+str(e)+'in query '+ str(self.query)+
':'+pg+'\n '+str( self.bindings)+ '\n')
has_raised = True
result.result = False
result.result = []
return result
@ -698,8 +693,7 @@ class YAPRun(InteractiveShell):
except:
line = ""
self.shell.last_execution_succeeded = True
self.shell.run_cell_magic(magic, line, body)
result.result = True
result.result = self.shell.run_cell_magic(magic, line, body)
return
else:
linec = True
@ -720,7 +714,7 @@ class YAPRun(InteractiveShell):
# can fill in the output value.
self.shell.displayhook.exec_result = result
if self.syntaxErrors(cell):
result.result = False
result.result = []
return
has_raised = False
try:
@ -745,11 +739,10 @@ class YAPRun(InteractiveShell):
self.jupyter_query( cell )
# state = tracer.runfunc(jupyter_query( self, cell ) )
self.shell.last_execution_succeeded = True
result.info += [self.answer]
result.result = True
result.result = []
except Exception as e:
has_raised = True
result.result = False
result.result = []
try:
(etype, value, tb) = e
traceback.print_exception(etype, value, tb)
@ -774,7 +767,7 @@ class YAPRun(InteractiveShell):
self.shell.execution_count += 1
self.yapeng.mgoal(streams(False),"user", True)
return result.result
return
def clean_end(self,s):
"""
@ -809,7 +802,7 @@ class YAPRun(InteractiveShell):
def prolog_cell(self,s):
def prolog_cell(self,s):
"""
Trasform a text into program+query. A query is the
last line if the last line is non-empty and does not terminate

View File

@ -494,9 +494,6 @@ write_query_answer( Bindings ) :-
'$write_goal_output'(G1, First, NG, Next, IG),
'$write_vars_and_goals'(LG, Next, IG).
'$goal_to_string'(Format, G, String) :-
format(codes(String),Format,G).
'$write_goal_output'(var([V|VL]), First, [var([V|VL])|L], next, L) :- !,
( First = first -> true ; format(user_error,',~n',[]) ),
format(user_error,'~a',[V]),
@ -516,14 +513,14 @@ write_query_answer( Bindings ) :-
G = [_|_], !,
% dump on string first so that we can check whether we actually
% had any output from the solver.
'$goal_to_string'(Format, G, String),
( String == [] ->
term_to_string( G, String),
( String == `` ->
% we didn't
IG = NG, First = Next
;
% we did
( First = first -> true ; format(user_error,',~n',[]) ),
format(user_error, '~s', [String]),
format(user_error, '~N~s', [String]),
NG = [G|IG]
).
'$write_goal_output'(_-G, First, [G|NG], next, NG) :- !,