This commit is contained in:
Vitor Santos Costa 2018-07-06 16:51:19 +01:00
parent 3bf897c503
commit 260dcbe754
11 changed files with 50 additions and 37 deletions

View File

@ -112,7 +112,7 @@ static Term indexer(Term inp) {
return TermZERO; return TermZERO;
} }
Yap_Error(TYPE_ERROR_ATOM, inp, Yap_Error(TYPE_ERROR_ATOM, inp,
"set_prolog_flag in {dec10,error,fail,quiet}"); "set_prolog_flag index to an atom");
return TermZERO; return TermZERO;
} }

View File

@ -144,12 +144,12 @@ static Term synerr(Term inp) {
return inp; return inp;
if (IsAtomTerm(inp)) { if (IsAtomTerm(inp)) {
Yap_Error(DOMAIN_ERROR_OUT_OF_RANGE, inp, Yap_ThrowError(DOMAIN_ERROR_OUT_OF_RANGE, inp,
"set_prolog_flag in {dec10,error,fail,quiet}"); "set_prolog_flag in {dec10,error,fail,quiet}");
return TermZERO; return TermZERO;
} }
Yap_Error(TYPE_ERROR_ATOM, inp, Yap_ThrowError(TYPE_ERROR_ATOM, inp,
"set_prolog_flag in {dec10,error,fail,quiet}"); "syntax_error flag must be atom");
return TermZERO; return TermZERO;
} }

View File

@ -221,16 +221,16 @@ Yap_SetAlias (Atom arg, int sno)
CACHE_REGS CACHE_REGS
AliasDesc aliasp = GLOBAL_FileAliases, aliasp_max = GLOBAL_FileAliases+GLOBAL_NOfFileAliases; AliasDesc aliasp = GLOBAL_FileAliases, aliasp_max = GLOBAL_FileAliases+GLOBAL_NOfFileAliases;
while (aliasp < aliasp_max) {
// replace alias
if (aliasp->name == arg) {
aliasp->alias_stream = sno;
if (arg == AtomUserIn) if (arg == AtomUserIn)
LOCAL_c_input_stream = sno; LOCAL_c_input_stream = sno;
if (arg == AtomUserOut) if (arg == AtomUserOut)
LOCAL_c_output_stream = sno; LOCAL_c_output_stream = sno;
if (arg == AtomUserErr) if (arg == AtomUserErr)
LOCAL_c_error_stream = sno; LOCAL_c_error_stream = sno;
while (aliasp < aliasp_max) {
// replace alias
if (aliasp->name == arg) {
aliasp->alias_stream = sno;
return; return;
} }
aliasp++; aliasp++;
@ -317,16 +317,16 @@ ExistsAliasForStream (int sno, Atom al)
while (aliasp < aliasp_max) { while (aliasp < aliasp_max) {
if (aliasp->alias_stream == sno && aliasp->name == al) { if (aliasp->alias_stream == sno && aliasp->name == al) {
if (al == AtomUserIn) { if (al == AtomUserIn) {
LOCAL_c_input_stream = StdInStream; LOCAL_c_input_stream = sno;
aliasp->alias_stream = StdInStream; aliasp->alias_stream = sno;
} } else
if (al == AtomUserOut) { if (al == AtomUserOut) {
LOCAL_c_output_stream = StdOutStream; LOCAL_c_output_stream = sno;
aliasp->alias_stream = StdOutStream; aliasp->alias_stream = sno;
} }
if (al == AtomUserErr) { if (al == AtomUserErr) {
LOCAL_c_error_stream = StdErrStream; LOCAL_c_error_stream = sno;
aliasp->alias_stream = StdErrStream; aliasp->alias_stream = sno;
} }
return true; return true;
} }
@ -387,6 +387,12 @@ Yap_AddAlias (Atom arg, int sno)
AliasDesc aliasp = GLOBAL_FileAliases, aliasp_max = GLOBAL_FileAliases+GLOBAL_NOfFileAliases; AliasDesc aliasp = GLOBAL_FileAliases, aliasp_max = GLOBAL_FileAliases+GLOBAL_NOfFileAliases;
if (arg == AtomUserIn)
LOCAL_c_input_stream = sno;
else if (arg == AtomUserOut)
LOCAL_c_output_stream = sno;
else if (arg == AtomUserErr)
LOCAL_c_error_stream = sno;
while (aliasp < aliasp_max) { while (aliasp < aliasp_max) {
if (aliasp->name == arg) { if (aliasp->name == arg) {
aliasp->alias_stream = sno; aliasp->alias_stream = sno;
@ -394,6 +400,7 @@ Yap_AddAlias (Atom arg, int sno)
} }
aliasp++; aliasp++;
} }
/* we have not found an alias neither a hole */ /* we have not found an alias neither a hole */
if (aliasp == GLOBAL_FileAliases+GLOBAL_SzOfFileAliases) if (aliasp == GLOBAL_FileAliases+GLOBAL_SzOfFileAliases)
ExtendAliasArray(); ExtendAliasArray();

View File

@ -1129,6 +1129,7 @@ static void check_bom(int sno, StreamDesc *st) {
bool Yap_initStream(int sno, FILE *fd, const char *name, const char *io_mode, bool Yap_initStream(int sno, FILE *fd, const char *name, const char *io_mode,
Term file_name, encoding_t encoding, stream_flags_t flags, Term file_name, encoding_t encoding, stream_flags_t flags,
void *vfs) { void *vfs) {
fprintf(stderr,"+ %s --> %d\n", name, sno);
StreamDesc *st = &GLOBAL_Stream[sno]; StreamDesc *st = &GLOBAL_Stream[sno];
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "init %s %s:%s stream <%d>", __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "init %s %s:%s stream <%d>",
io_mode, CurrentModule == 0? "prolog": RepAtom(AtomOfTerm(CurrentModule))->StrOfAE, io_mode, CurrentModule == 0? "prolog": RepAtom(AtomOfTerm(CurrentModule))->StrOfAE,

View File

@ -998,6 +998,7 @@ static void CloseStream(int sno) {
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "close stream <%d>", // __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "close stream <%d>",
// sno); // sno);
VFS_t *me; VFS_t *me;
fprintf( stderr, "- %d\n",sno);
if ((me = GLOBAL_Stream[sno].vfs) != NULL && if ((me = GLOBAL_Stream[sno].vfs) != NULL &&
GLOBAL_Stream[sno].file == NULL) { GLOBAL_Stream[sno].file == NULL) {
if (me->close) { if (me->close) {

View File

@ -5,7 +5,7 @@ set (PYTHON_SOURCES python.c pl2py.c pybips.c py2pl.c pl2pl.c pypreds.c pyio.c)
set (PYTHON_HEADERS py4yap.h) set (PYTHON_HEADERS py4yap.h)
set (CMAKE_POSITION_INDEPENDENT_CODE TRUE) set (CMAKE_POSITION_INDEPENDENT_CODE TRUE)
include_directories( ${CMAKE_BINARY_DIR} ${PYTHON_INCLUDE_DIRS} include_directories( BEFORE ${PYTHON_INCLUDE_DIRS} ${CMAKE_BINARY_DIR}
${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/os ) ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/os )
#talk to python.pl #talk to python.pl

View File

@ -112,7 +112,7 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
// Yap_DebugPlWriteln(yt); // Yap_DebugPlWriteln(yt);
switch (PL_term_type(t)) { switch (PL_term_type(t)) {
case PL_VARIABLE: { case PL_VARIABLE: {
if (t == 0) { if (yt == 0) {
Yap_ThrowError(SYSTEM_ERROR_INTERNAL, yt, "in term_to_python"); Yap_ThrowError(SYSTEM_ERROR_INTERNAL, yt, "in term_to_python");
} }
PyObject *out = PyTuple_New(1); PyObject *out = PyTuple_New(1);
@ -150,19 +150,18 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
} else { } else {
return CHECKNULL(t, NULL); return CHECKNULL(t, NULL);
} }
PyObject *pobj = PyUnicode_FromString(s);
#if PY_MAJOR_VERSION < 3 #if PY_MAJOR_VERSION < 3
if (proper_ascii_string(s)) { if (proper_ascii_string(s)) {
PyObject *o = PyString_FromStringAndSize(s, strlen(s)); PyObject *o = PyString_FromStringAndSize(s, strlen(s));
return CHECKNULL(t, o); return CHECKNULL(t, o);
} else }
#endif #endif
{
// char *p = malloc(strlen(s)+1); // char *p = malloc(strlen(s)+1);
// strcpy(p, s); // strcpy(p, s);
PyObject *pobj = PyUnicode_FromString(s);
Py_IncRef(pobj); Py_IncRef(pobj);
return CHECKNULL(t, pobj); return CHECKNULL(t, pobj);
}
} break; } break;
case PL_INTEGER: { case PL_INTEGER: {
int64_t j; int64_t j;
@ -406,8 +405,8 @@ PyObject *deref_term_to_python(term_t t) {
// am\n"); // am\n");
YAP_Term yt = YAP_GetFromSlot(t); YAP_Term yt = YAP_GetFromSlot(t);
if (YAP_IsVarTerm(yt)) { if (YAP_IsVarTerm(yt)) {
char s[32]; char b[1024];
char *o = YAP_WriteBuffer(yt, s, 31, 0); char *o = YAP_WriteBuffer(yt, b, 1023, 0);
PyObject *p = PyUnicode_FromString(o); PyObject *p = PyUnicode_FromString(o);
return p; return p;
} }

View File

@ -953,9 +953,11 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
if (!PL_get_arg(1, t, targ)) if (!PL_get_arg(1, t, targ))
return NULL; return NULL;
// Yap_DebugPlWriteln(YAP_GetFromSlot(t));
lhs = term_to_python(targ, true, NULL, true); lhs = term_to_python(targ, true, NULL, true);
AOK(PL_get_arg(2, t, targ), NULL); AOK(PL_get_arg(2, t, targ), NULL);
rhs = term_to_python(targ, true, NULL, true); rhs = term_to_python(targ, true, NULL, true);
Yap_DebugPlWriteln(YAP_GetFromSlot(targ));
if (PySequence_Check(lhs) && PySequence_Check(rhs)) { if (PySequence_Check(lhs) && PySequence_Check(rhs)) {
return PySequence_Concat(lhs, rhs); return PySequence_Concat(lhs, rhs);
} }
@ -1037,7 +1039,7 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
pArgs = PyTuple_New(i); pArgs = PyTuple_New(i);
} }
} }
DebugPrintf("Tuple %p\n", pyDict); fprintf(stderr,"Tuple %p: %s\n", pyDict, PyUnicode_AsUTF8(PyObject_Str(pyDict)));
if (!indict) { if (!indict) {
if (PL_is_variable(tleft)) { if (PL_is_variable(tleft)) {
pArg = Py_None; pArg = Py_None;

View File

@ -5,9 +5,12 @@ PyObject *py_Main;
void pyErrorHandler__(int line, const char *file, const char *code) { void pyErrorHandler__(int line, const char *file, const char *code) {
// this code is called if a Python error is found. // this code is called if a Python error is found.
fprintf(stderr, " Python error detcted at %s %s:%d\n\n", code, file, line); //int lvl = push_text_stack();
PyErr_Print(); PyObject *type, *val;
} // PyErr_Fetch(&type, &val, NULL);
// PyErr_Print();
// Yap_ThrowError__(file,code,line,0, SYSTEM_ERROR_RUNTIME_PYTHON ,"Python Error %s: %s",PyUnicode_AsUTF8(PyObject_Str(type)), PyUnicode_AsUTF8(PyObject_Str(val)));
};
static foreign_t python_len(term_t tobj, term_t tf) { static foreign_t python_len(term_t tobj, term_t tf) {
Py_ssize_t len; Py_ssize_t len;

View File

@ -709,6 +709,7 @@ class YAPRun:
self.shell.displayhook.exec_result = self.result self.shell.displayhook.exec_result = self.result
has_raised = False has_raised = False
try: try:
self.yapeng.mgoal(streams(True),"user", True)
self.bindings = dicts = [] self.bindings = dicts = []
if cell.strip('\n \t'): if cell.strip('\n \t'):
#create a Trace object, telling it what to ignore, and whether to #create a Trace object, telling it what to ignore, and whether to
@ -725,16 +726,16 @@ class YAPRun:
# run the new command using the given tracer # run the new command using the given tracer
# #
# tracer.runfunc(f,self,cell,state) # tracer.runfunc(f,self,cell,state)
self.yapeng.mgoal(streams(True),"user", True)
self.jupyter_query( cell ) self.jupyter_query( cell )
self.yapeng.mgoal(streams(False),"user", True)
# state = tracer.runfunc(jupyter_query( self, cell ) ) # state = tracer.runfunc(jupyter_query( self, cell ) )
self.shell.last_execution_succeeded = True self.shell.last_execution_succeeded = True
self.result.result = (True, dicts) self.result.result = (True, dicts)
self.yapeng.mgoal(streams(False),"user", True)
except Exception as e: except Exception as e:
has_raised = True has_raised = True
self.result.result = False self.result.result = False
self.yapeng.mgoal(streams(False),"user", True)
self.shell.last_execution_succeeded = not has_raised self.shell.last_execution_succeeded = not has_raised
@ -771,7 +772,7 @@ class YAPRun:
else: else:
taken = l0-(i-1) taken = l0-(i-1)
n = s[i+1:].strip() n = s[i+1:].strip()
s = s[:i-1] s = s[:i]
if n: if n:
its = 0 its = 0
for ch in n: for ch in n:

View File

@ -236,7 +236,6 @@ qend_program :-
prolog_flag_property(X, [access(read_write)]), prolog_flag_property(X, [access(read_write)]),
atom(X), atom(X),
yap_flag(X, V), yap_flag(X, V),
writeln(X:V),
X \= gc_margin, % different machines will have different needs, X \= gc_margin, % different machines will have different needs,
X \= argv, X \= argv,
X \= os_argv, X \= os_argv,