virtual streams

This commit is contained in:
Vítor Santos Costa
2018-05-24 21:45:38 +01:00
parent 8607aee725
commit 7c934d3f40
9 changed files with 28 additions and 51 deletions

View File

@@ -7,21 +7,21 @@
YAP_Term TermErrStream, TermOutStream;
static int py_put(int sno, int ch) {
static int py_putc(int sno, int ch) {
// PyObject *pyw; // buffer
// int pyw_kind;
// PyObject *pyw_data;
StreamDesc *st = YAP_GetStreamFromId(sno);
if (st->user_name == TermOutStream) {
term_t tg = python_acquire_GIL();
// term_t tg = python_acquire_GIL();
PySys_WriteStdout("%C", ch);
python_release_GIL(tg);
//python_release_GIL(tg);
return ch;
}
if (st->user_name == TermErrStream) {
term_t tg = python_acquire_GIL();
//term_t tg = python_acquire_GIL();
PySys_WriteStderr("%C", ch);
python_release_GIL(tg);
//python_release_GIL(tg);
return ch;
}
char s[2];
@@ -73,6 +73,7 @@ static void *py_open(VFS_t *me, const char *name, const char *io_mode,
return st;
}
static bool py_close(int sno) {
StreamDesc *st = YAP_RepStreamFromId(sno);
if (strcmp(st->name, "sys.stdout") && strcmp(st->name, "sys.stderr")) {
@@ -200,7 +201,7 @@ bool init_python_vfs(void) {
pystream.close = py_close;
pystream.get_char = py_getc;
pystream.peek_char = py_peek;
pystream.put_char = py_put;
pystream.put_char = py_putc;
pystream.flush = py_flush;
pystream.seek = py_seek;
pystream.next = GLOBAL_VFS;

View File

@@ -145,6 +145,7 @@ class YAPShell:
# return
try:
engine = self.engine
engine.ReSet()
bindings = []
loop = False
g = python_query(self, query)
@@ -176,7 +177,6 @@ class YAPShell:
return False, None
except Exception as e:
print("Exception")
print(dir(e))
return False, None
def live(self, engine, **kwargs):
@@ -208,6 +208,7 @@ class YAPShell:
#
def __init__(self, engine, **kwargs):
self.engine = engine
self.live(engine)

View File

@@ -1,18 +0,0 @@
:- use_module(library(python)).
:- if( current_prolog_flag(apple, true) ).
:- putenv( 'LC_CTYPE', 'en_us:UTF-8').
plot_inline :-
X := self.inline_plotting,
nb_setval(inline, X ),
X = true,
!,
:= (
import( matplotlib ),
matplotlib.use( `nbagg` )
).
:- endif.

View File

@@ -72,7 +72,7 @@ streams(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_input,_Input),
set_prolog_flag(user_output,_Output),
set_prolog_flag(user_error,_Error).