virtual streams
This commit is contained in:
parent
8607aee725
commit
7c934d3f40
@ -1774,7 +1774,7 @@ X_API bool YAP_RetryGoal(YAP_dogoalinfo *dgi) {
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
X_API bool YAP_LeaveGoal(bool backtrack, YAP_dogoalinfo *dgi) {
|
X_API bool YAP_LeaveGoal(bool exit, YAP_dogoalinfo *dgi) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
choiceptr myB;
|
choiceptr myB;
|
||||||
|
|
||||||
@ -1792,7 +1792,7 @@ X_API bool YAP_LeaveGoal(bool backtrack, YAP_dogoalinfo *dgi) {
|
|||||||
B = myB;
|
B = myB;
|
||||||
}
|
}
|
||||||
/* if backtracking asked for, recover space and bindings */
|
/* if backtracking asked for, recover space and bindings */
|
||||||
if (backtrack) {
|
if (!exit) {
|
||||||
P = FAILCODE;
|
P = FAILCODE;
|
||||||
Yap_exec_absmi(true, YAP_EXEC_ABSMI);
|
Yap_exec_absmi(true, YAP_EXEC_ABSMI);
|
||||||
/* recover stack space */
|
/* recover stack space */
|
||||||
|
11
CXX/yapi.cpp
11
CXX/yapi.cpp
@ -53,7 +53,6 @@ static void YAPCatchError()
|
|||||||
YAPPredicate::YAPPredicate(Term &t, Term &tmod, CELL *&ts, const char *pname) {
|
YAPPredicate::YAPPredicate(Term &t, Term &tmod, CELL *&ts, const char *pname) {
|
||||||
Term t0 = t;
|
Term t0 = t;
|
||||||
ap = nullptr;
|
ap = nullptr;
|
||||||
Yap_DebugPlWriteln(t);
|
|
||||||
restart:
|
restart:
|
||||||
if (IsVarTerm(t)) {
|
if (IsVarTerm(t)) {
|
||||||
throw YAPError(SOURCE(), INSTANTIATION_ERROR, t0, pname);
|
throw YAPError(SOURCE(), INSTANTIATION_ERROR, t0, pname);
|
||||||
@ -503,7 +502,7 @@ bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) {
|
|||||||
q.cp = CP;
|
q.cp = CP;
|
||||||
// allow Prolog style exceotion handling
|
// allow Prolog style exceotion handling
|
||||||
// don't forget, on success these bindings will still be there);
|
// don't forget, on success these bindings will still be there);
|
||||||
result = YAP_LeaveGoal(false, &q);
|
result = YAP_LeaveGoal(true, &q);
|
||||||
|
|
||||||
YAPCatchError();
|
YAPCatchError();
|
||||||
|
|
||||||
@ -737,14 +736,10 @@ bool YAPQuery::next() {
|
|||||||
q_state = 1;
|
q_state = 1;
|
||||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", result);
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", result);
|
||||||
|
|
||||||
if (!result) {
|
YAP_LeaveGoal(result, &q_h);
|
||||||
YAP_LeaveGoal(false, &q_h);
|
|
||||||
Yap_CloseHandles(q_handles);
|
Yap_CloseHandles(q_handles);
|
||||||
q_open = false;
|
q_open = false;
|
||||||
YAPCatchError();
|
YAPCatchError();
|
||||||
} else {
|
|
||||||
q_handles = Yap_StartSlots();
|
|
||||||
}
|
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
LOCAL_RestartEnv = oldp;
|
LOCAL_RestartEnv = oldp;
|
||||||
return result;
|
return result;
|
||||||
@ -1004,7 +999,7 @@ void *YAPPrologPredicate::retractClause(YAPTerm skeleton, bool all) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::string YAPError::text() {
|
std::string YAPError::text() {
|
||||||
char buf[256];
|
|
||||||
return "Error";
|
return "Error";
|
||||||
#if 0
|
#if 0
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
|
18
CXX/yapq.hh
18
CXX/yapq.hh
@ -45,7 +45,6 @@ class X_API YAPQuery : public YAPPredicate {
|
|||||||
YAPPairTerm names;
|
YAPPairTerm names;
|
||||||
YAPTerm goal;
|
YAPTerm goal;
|
||||||
// temporaries
|
// temporaries
|
||||||
Term tnames, tgoal;
|
|
||||||
YAPError *e;
|
YAPError *e;
|
||||||
|
|
||||||
inline void setNext() { // oq = LOCAL_execution;
|
inline void setNext() { // oq = LOCAL_execution;
|
||||||
@ -92,31 +91,30 @@ public:
|
|||||||
/// It is given a string, calls the parser and obtains a Prolog term that
|
/// It is given a string, calls the parser and obtains a Prolog term that
|
||||||
/// should be a callable
|
/// should be a callable
|
||||||
/// goal.
|
/// goal.
|
||||||
inline YAPQuery(const char *s) : YAPPredicate(s, tgoal, tnames) {
|
inline YAPQuery(const char *s) : YAPPredicate(s, goal.term(), names.term()) {
|
||||||
CELL *qt = nullptr;
|
CELL *qt = nullptr;
|
||||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %d",
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %d",
|
||||||
LOCAL_CurSlot);
|
LOCAL_CurSlot);
|
||||||
if (!ap)
|
if (!ap)
|
||||||
return;
|
return;
|
||||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", names.text());
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", names.text());
|
||||||
if (IsPairTerm(tgoal)) {
|
if (IsPairTerm(goal.term())) {
|
||||||
qt = RepPair(tgoal);
|
qt = RepPair(goal.term());
|
||||||
tgoal = Yap_MkApplTerm(FunctorCsult, 1, qt);
|
goal.put(Yap_MkApplTerm(FunctorCsult, 1, qt));
|
||||||
ap = RepPredProp(PredPropByFunc(FunctorCsult, TermProlog));
|
ap = RepPredProp(PredPropByFunc(FunctorCsult, TermProlog));
|
||||||
}
|
}
|
||||||
goal = YAPTerm(tgoal);
|
if (IsApplTerm(goal.term())) {
|
||||||
if (IsApplTerm(tgoal)) {
|
Functor f = FunctorOfTerm(goal.term());
|
||||||
Functor f = FunctorOfTerm(tgoal);
|
|
||||||
if (!IsExtensionFunctor(f)) {
|
if (!IsExtensionFunctor(f)) {
|
||||||
arity_t arity = ap->ArityOfPE;
|
arity_t arity = ap->ArityOfPE;
|
||||||
if (arity) {
|
if (arity) {
|
||||||
qt = RepAppl(tgoal) + 1;
|
qt = RepAppl(goal.term()) + 1;
|
||||||
for (arity_t i = 0; i < arity; i++)
|
for (arity_t i = 0; i < arity; i++)
|
||||||
XREGS[i + 1] = qt[i];
|
XREGS[i + 1] = qt[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
names = YAPPairTerm(tnames);
|
names = YAPPairTerm(names.term());
|
||||||
openQuery();
|
openQuery();
|
||||||
};
|
};
|
||||||
// inline YAPQuery() : YAPPredicate(s, tgoal, tnames)
|
// inline YAPQuery() : YAPPredicate(s, tgoal, tnames)
|
||||||
|
@ -571,13 +571,13 @@ int Yap_DebugGetc() {
|
|||||||
int Yap_DebugPutc(FILE *s, wchar_t ch) {
|
int Yap_DebugPutc(FILE *s, wchar_t ch) {
|
||||||
if (Yap_Option['l' - 96])
|
if (Yap_Option['l' - 96])
|
||||||
(void)putc(ch, Yap_logfile);
|
(void)putc(ch, Yap_logfile);
|
||||||
return (putc(ch, s));
|
return (putc(ch, stderr));
|
||||||
}
|
}
|
||||||
|
|
||||||
int Yap_DebugPuts(FILE *s, const char *sch) {
|
int Yap_DebugPuts(FILE *s, const char *sch) {
|
||||||
if (Yap_Option['l' - 96])
|
if (Yap_Option['l' - 96])
|
||||||
(void)fputs(sch, Yap_logfile);
|
(void)fputs(sch, Yap_logfile);
|
||||||
return fputs(sch, s);
|
return fputs(sch, stderr);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Yap_DebugErrorPuts(const char *s) { Yap_DebugPuts(stderr, s); }
|
void Yap_DebugErrorPuts(const char *s) { Yap_DebugPuts(stderr, s); }
|
||||||
@ -1584,7 +1584,7 @@ int Yap_OpenStream(Term tin, const char *io_mode, Term user_name,
|
|||||||
} else {
|
} else {
|
||||||
st->file = fopen(fname, io_mode);
|
st->file = fopen(fname, io_mode);
|
||||||
}
|
}
|
||||||
if (!st->file && !st->vfs) {
|
if (!st->file) {
|
||||||
fprintf(stderr, "trying %s\n", fname);
|
fprintf(stderr, "trying %s\n", fname);
|
||||||
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s", fname);
|
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s", fname);
|
||||||
/* extract BACK info passed through the stream descriptor */
|
/* extract BACK info passed through the stream descriptor */
|
||||||
@ -1629,7 +1629,7 @@ int Yap_OpenStream(Term tin, const char *io_mode, Term user_name,
|
|||||||
pop_text_stack(i);
|
pop_text_stack(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (st->file == NULL && st->vfs == NULL) {
|
if (st->file == NULL) {
|
||||||
if (!strchr(io_mode, 'b') && binary_file(fname)) {
|
if (!strchr(io_mode, 'b') && binary_file(fname)) {
|
||||||
UNLOCK(st->streamlock);
|
UNLOCK(st->streamlock);
|
||||||
if (errno == ENOENT && !strchr(io_mode, 'r')) {
|
if (errno == ENOENT && !strchr(io_mode, 'r')) {
|
||||||
|
@ -7,21 +7,21 @@
|
|||||||
|
|
||||||
YAP_Term TermErrStream, TermOutStream;
|
YAP_Term TermErrStream, TermOutStream;
|
||||||
|
|
||||||
static int py_put(int sno, int ch) {
|
static int py_putc(int sno, int ch) {
|
||||||
// PyObject *pyw; // buffer
|
// PyObject *pyw; // buffer
|
||||||
// int pyw_kind;
|
// int pyw_kind;
|
||||||
// PyObject *pyw_data;
|
// PyObject *pyw_data;
|
||||||
StreamDesc *st = YAP_GetStreamFromId(sno);
|
StreamDesc *st = YAP_GetStreamFromId(sno);
|
||||||
if (st->user_name == TermOutStream) {
|
if (st->user_name == TermOutStream) {
|
||||||
term_t tg = python_acquire_GIL();
|
// term_t tg = python_acquire_GIL();
|
||||||
PySys_WriteStdout("%C", ch);
|
PySys_WriteStdout("%C", ch);
|
||||||
python_release_GIL(tg);
|
//python_release_GIL(tg);
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
if (st->user_name == TermErrStream) {
|
if (st->user_name == TermErrStream) {
|
||||||
term_t tg = python_acquire_GIL();
|
//term_t tg = python_acquire_GIL();
|
||||||
PySys_WriteStderr("%C", ch);
|
PySys_WriteStderr("%C", ch);
|
||||||
python_release_GIL(tg);
|
//python_release_GIL(tg);
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
char s[2];
|
char s[2];
|
||||||
@ -73,6 +73,7 @@ static void *py_open(VFS_t *me, const char *name, const char *io_mode,
|
|||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool py_close(int sno) {
|
static bool py_close(int sno) {
|
||||||
StreamDesc *st = YAP_RepStreamFromId(sno);
|
StreamDesc *st = YAP_RepStreamFromId(sno);
|
||||||
if (strcmp(st->name, "sys.stdout") && strcmp(st->name, "sys.stderr")) {
|
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.close = py_close;
|
||||||
pystream.get_char = py_getc;
|
pystream.get_char = py_getc;
|
||||||
pystream.peek_char = py_peek;
|
pystream.peek_char = py_peek;
|
||||||
pystream.put_char = py_put;
|
pystream.put_char = py_putc;
|
||||||
pystream.flush = py_flush;
|
pystream.flush = py_flush;
|
||||||
pystream.seek = py_seek;
|
pystream.seek = py_seek;
|
||||||
pystream.next = GLOBAL_VFS;
|
pystream.next = GLOBAL_VFS;
|
||||||
|
@ -145,6 +145,7 @@ class YAPShell:
|
|||||||
# return
|
# return
|
||||||
try:
|
try:
|
||||||
engine = self.engine
|
engine = self.engine
|
||||||
|
engine.ReSet()
|
||||||
bindings = []
|
bindings = []
|
||||||
loop = False
|
loop = False
|
||||||
g = python_query(self, query)
|
g = python_query(self, query)
|
||||||
@ -176,7 +177,6 @@ class YAPShell:
|
|||||||
return False, None
|
return False, None
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print("Exception")
|
print("Exception")
|
||||||
print(dir(e))
|
|
||||||
return False, None
|
return False, None
|
||||||
|
|
||||||
def live(self, engine, **kwargs):
|
def live(self, engine, **kwargs):
|
||||||
@ -208,6 +208,7 @@ class YAPShell:
|
|||||||
#
|
#
|
||||||
def __init__(self, engine, **kwargs):
|
def __init__(self, engine, **kwargs):
|
||||||
self.engine = engine
|
self.engine = engine
|
||||||
|
|
||||||
self.live(engine)
|
self.live(engine)
|
||||||
|
|
||||||
|
|
||||||
|
@ -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.
|
|
@ -72,7 +72,7 @@ streams(true) :-
|
|||||||
% open('/python/input', read, _Input, [alias(user_input),bom(false)]),
|
% open('/python/input', read, _Input, [alias(user_input),bom(false)]),
|
||||||
open('/python/sys.stdout', append, _Output, [alias(user_output)]),
|
open('/python/sys.stdout', append, _Output, [alias(user_output)]),
|
||||||
open('/python/sys.stderr', append, _Error, [alias(user_error)]),
|
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_output,_Output),
|
||||||
set_prolog_flag(user_error,_Error).
|
set_prolog_flag(user_error,_Error).
|
||||||
|
|
||||||
|
@ -111,4 +111,4 @@ exports(In, Exports) :-
|
|||||||
read(In, Term),
|
read(In, Term),
|
||||||
Term = (:- module(_Name, Exports)).
|
Term = (:- module(_Name, Exports)).
|
||||||
|
|
||||||
@}
|
%% @}
|
||||||
|
Reference in New Issue
Block a user