debugging

This commit is contained in:
Vitor Santos Costa
2018-05-28 09:31:59 +01:00
parent b59af58616
commit 2415a2e58c
9 changed files with 178 additions and 45 deletions

View File

@@ -30,9 +30,9 @@
python/2,
acquire_GIL/0,
release_GIL/0,
python_threaded/0,
prolog_list_to_python_list/3,
op(100,fy,$),
python_threaded/0,
prolog_list_to_python_list/3,
op(100,fy,$),
op(950,fy,:=),
op(950,yfx,:=),
% op(950,fx,<-),

View File

@@ -10,17 +10,19 @@
yap_query/4,
python_query/2,
python_query/3,
python_import/1,
yapi_query/2
]).
:- yap_flag(verbose, silent).
:- yap_flag(verbose, silent).
:- use_module(library(python)).
:- use_module( library(lists) ).
:- use_module( library(maplist) ).
:- use_module( library(rbtrees) ).
:- use_module( library(terms) ).
:- reexport( library(python) ).
:- python_import(yap4py.yapi).
%:- python_import(gc).

View File

@@ -280,7 +280,8 @@ set (RENAMED_RESOURCES
# yap_kernel/resources/codemirror/mode/prolog/prolog.js
)
set (PL_SOURCES yap_ipython/prolog/jupyter.yap)
set (PL_SOURCES yap_ipython/prolog/jupyter.yap
)
set(FILES ${PYTHON_SOURCES} ${PL_SOURCES} ${EXTRAS} ${RESOURCES})

View File

@@ -1,30 +1,24 @@
/**
* @file jupyter.yap
*
* @brief allow interaction between Jupyter and YAP.
*
* @long The code in here:
* - establishes communication between Prolog and Python Streams
* - inputs Prolog code and queries
* - supports completion of Prolog programs.
* -
*/
* @file jupyter.yap4py
*
* @brief JUpyter support.
*/
% :- module( jupyter,
% [jupyter_query/3,
% errors/2,
% ready/2,
% completion/2,
% ]
%% ).
:- [library(hacks)].
:- reexport(library(yapi)).
:- reexport(completer).
:- use_module(library(hacks)).
:- use_module(library(lists)).
:- use_module(library(maplist)).
:- use_module(library(python)).
:- use_module(library(yapi)).
:- python_import(sys).
@@ -40,7 +34,8 @@ jupyter_cell( _Caller, _, Line ) :-
jupyter_cell( _Caller, _, [] ) :- !.
jupyter_cell( Caller, _, Line ) :-
Self := Caller.query,
python_query( Self, Line, box_input ).
start_low_level_trace,
python_query( Self, Line ).
jupyter_consult(Text) :-
blank( Text ),
@@ -62,21 +57,26 @@ blankc('\t').
streams(false) :-
nb_setval(jupyter_cell, false),
flush_output,
forall(
stream_property( S, mode(_) ),
close(S)
).
nb_setval(jupyter_cell, false),
fail,
flush_output,
retract(cell_stream(S)),
close(S),
fail.
streams(false).
streams(true) :-
nb_setval(jupyter_cell, true),
% open('/python/input', read, _Input, [alias(user_input),bom(false)]),
open('/python/sys.stdout', append, _Output, [alias(user_output)]),
open('/python/sys.stderr', append, _Error, [alias(user_error)]),
% set_prolog_flag(user_input,_Input),
set_prolog_flag(user_output,_Output),
set_prolog_flag(user_error,_Error).
nb_setval(jupyter_cell, true),
fail,
% open('/python/input', read, _Input, [alias(user_input),bom(false)]),
open('/python/sys.stdout', append, Output, [alias(user_output)]),
assert( cell_stream( Output) ),
open('/python/sys.stderr', append, Error, [alias(user_error)]),
assert( cell_stream( Error) ),
% set_prolog_flag(user_input,_Input),
set_prolog_flag(user_output, Output),
set_prolog_flag(user_error, Error).
streams(true).
ready(_Self, Line ) :-
blank( Line ),

View File

@@ -496,8 +496,10 @@ class YAPCompleter(Completer):
self.matches = []
prolog_res = self.shell.yapeng.mgoal(completions(text, self), "user",True)
if self.matches:
print( text, magic_res )
return text, self.matches
magic_res = self.magic_matches(text)
print( text, magic_res )
return text, magic_res
@@ -535,6 +537,7 @@ class YAPRun:
# construct a self.queryuery from a one-line string
# self.query is opaque to Python
try:
print(query,s, file=sys.stderr)
program,query,stop,howmany = self.prolog_cell(s)
found = False
if s != self.os:
@@ -545,10 +548,12 @@ class YAPRun:
self.query = self.yapeng.query( pg)
self.query.port = "call"
self.query.answer = {}
print("new", file=sys.stderr)
else:
self.query.port = "retry"
self.os = s
howmany += self.iterations
print('old', file=sys.stderr)
while self.query.next():
answer = self.query.answer
found = True
@@ -696,7 +701,7 @@ class YAPRun:
if linec:
self.shell.run_line_magic(magic, line)
else:
print("txt0: ",txt0,"\n")
print("txt0: ",txt0,"\n", file=sys.stderr)
if len(txt0) == 1:
cell = ""
else:
@@ -730,7 +735,7 @@ class YAPRun:
self.yapeng.mgoal(streams(False),"user", True)
except Exception as e:
has_raised = True
self.yapeng.mgoal(streams("off"),"user")
self.yapeng.mgoal(streams(False),"user")
if state:
self.shell.last_execution_succeeded = True
self.result.result = (True, dicts)