jupyter_dbug
This commit is contained in:
parent
bdc9e7005d
commit
82df9ce5b5
@ -40,7 +40,9 @@ bool Yap_Warning(const char *s, ...) {
|
|||||||
Term ts[2];
|
Term ts[2];
|
||||||
const char *fmt;
|
const char *fmt;
|
||||||
char tmpbuf[MAXPATHLEN];
|
char tmpbuf[MAXPATHLEN];
|
||||||
|
yap_error_descriptor_t olde;
|
||||||
|
|
||||||
|
Yap_pushErrorContext(&olde);
|
||||||
LOCAL_DoingUndefp = true;
|
LOCAL_DoingUndefp = true;
|
||||||
LOCAL_within_print_message = true;
|
LOCAL_within_print_message = true;
|
||||||
pred = RepPredProp(PredPropByFunc(FunctorPrintMessage,
|
pred = RepPredProp(PredPropByFunc(FunctorPrintMessage,
|
||||||
@ -53,19 +55,23 @@ bool Yap_Warning(const char *s, ...) {
|
|||||||
#else
|
#else
|
||||||
(void)vsprintf(tmpbuf, fmt, ap);
|
(void)vsprintf(tmpbuf, fmt, ap);
|
||||||
#endif
|
#endif
|
||||||
} else
|
} else {
|
||||||
|
Yap_popErrorContext(false);
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
if (pred->OpcodeOfPred == UNDEF_OPCODE || pred->OpcodeOfPred == FAIL_OPCODE) {
|
if (pred->OpcodeOfPred == UNDEF_OPCODE || pred->OpcodeOfPred == FAIL_OPCODE) {
|
||||||
fprintf(stderr, "warning message: %s\n", tmpbuf);
|
fprintf(stderr, "warning message: %s\n", tmpbuf);
|
||||||
LOCAL_DoingUndefp = false;
|
LOCAL_DoingUndefp = false;
|
||||||
LOCAL_within_print_message = false;
|
LOCAL_within_print_message = false;
|
||||||
|
Yap_popErrorContext(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
ts[1] = MkAtomTerm(AtomWarning);
|
ts[1] = MkAtomTerm(AtomWarning);
|
||||||
ts[0] = MkAtomTerm(Yap_LookupAtom(tmpbuf));
|
ts[0] = MkAtomTerm(Yap_LookupAtom(tmpbuf));
|
||||||
rc = Yap_execute_pred(pred, ts, true PASS_REGS);
|
rc = Yap_execute_pred(pred, ts, true PASS_REGS);
|
||||||
|
Yap_popErrorContext(false);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,8 @@ PyObject *py_ModDict;
|
|||||||
|
|
||||||
VFS_t pystream;
|
VFS_t pystream;
|
||||||
|
|
||||||
static void *py_open(VFS_t *me, int sno, const char *name,
|
static void *
|
||||||
|
py_open(VFS_t *me, int sno, const char *name,
|
||||||
const char *io_mode) {
|
const char *io_mode) {
|
||||||
#if HAVE_STRCASESTR
|
#if HAVE_STRCASESTR
|
||||||
if (strcasestr(name, "//python/") == name)
|
if (strcasestr(name, "//python/") == name)
|
||||||
@ -37,6 +38,7 @@ static void *py_open(VFS_t *me, int sno, const char *name,
|
|||||||
name += strlen("//python/");
|
name += strlen("//python/");
|
||||||
#endif
|
#endif
|
||||||
StreamDesc *st = YAP_RepStreamFromId(sno);
|
StreamDesc *st = YAP_RepStreamFromId(sno);
|
||||||
|
fprintf(stderr,"opened %p\n");
|
||||||
// we assume object is already open, so there is no need to open it.
|
// we assume object is already open, so there is no need to open it.
|
||||||
PyObject *stream = string_to_python(name, true, NULL);
|
PyObject *stream = string_to_python(name, true, NULL);
|
||||||
if (stream == Py_None)
|
if (stream == Py_None)
|
||||||
@ -44,12 +46,16 @@ static void *py_open(VFS_t *me, int sno, const char *name,
|
|||||||
Py_INCREF(stream);
|
Py_INCREF(stream);
|
||||||
st->u.private_data = stream;
|
st->u.private_data = stream;
|
||||||
st->vfs = me;
|
st->vfs = me;
|
||||||
|
if (strchr(io_mode,'r'))
|
||||||
|
st->status = Input_Stream_f;
|
||||||
|
else
|
||||||
st->status = Append_Stream_f | Output_Stream_f;
|
st->status = Append_Stream_f | Output_Stream_f;
|
||||||
Yap_DefaultStreamOps(st);
|
Yap_DefaultStreamOps(st);
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool py_close(int sno) {
|
static bool
|
||||||
|
py_close(int sno) {
|
||||||
return true;
|
return true;
|
||||||
StreamDesc *s = YAP_GetStreamFromId(sno);
|
StreamDesc *s = YAP_GetStreamFromId(sno);
|
||||||
PyObject *fclose = PyObject_GetAttrString(s->u.private_data, "close");
|
PyObject *fclose = PyObject_GetAttrString(s->u.private_data, "close");
|
||||||
@ -58,7 +64,8 @@ static bool py_close(int sno) {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int py_put(int sno, int ch) {
|
static int
|
||||||
|
py_put(int sno, int ch) {
|
||||||
// PyObject *pyw; // buffer
|
// PyObject *pyw; // buffer
|
||||||
// int pyw_kind;
|
// int pyw_kind;
|
||||||
// PyObject *pyw_data;
|
// PyObject *pyw_data;
|
||||||
|
@ -182,7 +182,6 @@ class YAPShell:
|
|||||||
self.port = "call"
|
self.port = "call"
|
||||||
# launch the query
|
# launch the query
|
||||||
while self.answer(q):
|
while self.answer(q):
|
||||||
print( self.port )
|
|
||||||
if self.port == "exit":
|
if self.port == "exit":
|
||||||
# done
|
# done
|
||||||
q.close()
|
q.close()
|
||||||
|
@ -61,12 +61,12 @@ blankc('\n').
|
|||||||
blankc('\t').
|
blankc('\t').
|
||||||
|
|
||||||
enter_cell(_Self) :-
|
enter_cell(_Self) :-
|
||||||
%open('//python/input', read, _Input, []),
|
open('//python/input', read, Input, []),
|
||||||
open('//python/sys.stdout', append, _Output, []),
|
open('//python/sys.stdout', append, Output, []),
|
||||||
open('//python/sys.stdout', append, _Error, []),
|
open('//python/sys.stdout', append, Error, []),
|
||||||
%set_prolog_flag(user_input, _Input),
|
set_prolog_flag(user_input, Input),
|
||||||
set_prolog_flag(user_output, _Output),
|
set_prolog_flag(user_output, Output),
|
||||||
set_prolog_flag(user_error, _Error).
|
set_prolog_flag(user_error, Error).
|
||||||
|
|
||||||
exit_cell(_Self) :-
|
exit_cell(_Self) :-
|
||||||
%close( user_input),
|
%close( user_input),
|
||||||
@ -239,14 +239,21 @@ optype(yf,pos).
|
|||||||
|
|
||||||
:- dynamic syntax_error/4, undo/1.
|
:- dynamic syntax_error/4, undo/1.
|
||||||
|
|
||||||
|
user:portray_message(_Severity, error(syntax_error(Cause),info(between(_,LN,_), _FileName, CharPos, Details))) :-
|
||||||
|
nb_getval(jupyter_cell, on),
|
||||||
|
assert( syntax_error(Cause,LN,CharPos,Details) ).
|
||||||
|
user:portray_message(_Severity, error(style_check(_),_) ) :-
|
||||||
|
nb_getval(jupyter_cell, on).
|
||||||
|
|
||||||
open_events(Self, Text, Stream) :-
|
open_events(Self, Text, Stream) :-
|
||||||
Self.errors := [],
|
Self.errors := [],
|
||||||
open_mem_read_stream( Text, Stream ),
|
nb_setval( jupyter, on),
|
||||||
assert((user:portray_message(_Severity, error(syntax_error(Cause),info(between(_,LN,_), _FileName, CharPos, Details))) :-
|
open_mem_read_stream( Text, Stream ).
|
||||||
assert( syntax_error(Cause,LN,CharPos,Details) )
|
|
||||||
)).
|
:- initialization( nb_setval( jupyter, off ) ).
|
||||||
|
|
||||||
close_events( _Self ) :-
|
close_events( _Self ) :-
|
||||||
|
nb_setval( jupyter, off ),
|
||||||
retract( undo(G) ),
|
retract( undo(G) ),
|
||||||
call(G),
|
call(G),
|
||||||
fail.
|
fail.
|
||||||
@ -255,3 +262,5 @@ close_events( Self ) :-
|
|||||||
Self.errors := [t(C,L,N,A)] + Self.errors,
|
Self.errors := [t(C,L,N,A)] + Self.errors,
|
||||||
fail.
|
fail.
|
||||||
close_events( _ ).
|
close_events( _ ).
|
||||||
|
|
||||||
|
:- ( start_low_level_trace ).
|
||||||
|
Reference in New Issue
Block a user