Merge /home/vsc/yap
This commit is contained in:
commit
2905688c0f
@ -112,7 +112,7 @@ static Term indexer(Term inp) {
|
||||
return TermZERO;
|
||||
}
|
||||
Yap_Error(TYPE_ERROR_ATOM, inp,
|
||||
"set_prolog_flag in {dec10,error,fail,quiet}");
|
||||
"set_prolog_flag index to an atom");
|
||||
return TermZERO;
|
||||
}
|
||||
|
||||
|
@ -144,12 +144,12 @@ static Term synerr(Term inp) {
|
||||
return 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}");
|
||||
return TermZERO;
|
||||
}
|
||||
Yap_Error(TYPE_ERROR_ATOM, inp,
|
||||
"set_prolog_flag in {dec10,error,fail,quiet}");
|
||||
Yap_ThrowError(TYPE_ERROR_ATOM, inp,
|
||||
"syntax_error flag must be atom");
|
||||
return TermZERO;
|
||||
}
|
||||
|
||||
|
29
os/alias.c
29
os/alias.c
@ -221,16 +221,16 @@ Yap_SetAlias (Atom arg, int sno)
|
||||
CACHE_REGS
|
||||
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)
|
||||
LOCAL_c_input_stream = sno;
|
||||
if (arg == AtomUserOut)
|
||||
LOCAL_c_output_stream = sno;
|
||||
if (arg == AtomUserErr)
|
||||
LOCAL_c_error_stream = sno;
|
||||
while (aliasp < aliasp_max) {
|
||||
// replace alias
|
||||
if (aliasp->name == arg) {
|
||||
aliasp->alias_stream = sno;
|
||||
return;
|
||||
}
|
||||
aliasp++;
|
||||
@ -317,16 +317,16 @@ ExistsAliasForStream (int sno, Atom al)
|
||||
while (aliasp < aliasp_max) {
|
||||
if (aliasp->alias_stream == sno && aliasp->name == al) {
|
||||
if (al == AtomUserIn) {
|
||||
LOCAL_c_input_stream = StdInStream;
|
||||
aliasp->alias_stream = StdInStream;
|
||||
}
|
||||
LOCAL_c_input_stream = sno;
|
||||
aliasp->alias_stream = sno;
|
||||
} else
|
||||
if (al == AtomUserOut) {
|
||||
LOCAL_c_output_stream = StdOutStream;
|
||||
aliasp->alias_stream = StdOutStream;
|
||||
LOCAL_c_output_stream = sno;
|
||||
aliasp->alias_stream = sno;
|
||||
}
|
||||
if (al == AtomUserErr) {
|
||||
LOCAL_c_error_stream = StdErrStream;
|
||||
aliasp->alias_stream = StdErrStream;
|
||||
LOCAL_c_error_stream = sno;
|
||||
aliasp->alias_stream = sno;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -387,6 +387,12 @@ Yap_AddAlias (Atom arg, int sno)
|
||||
|
||||
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) {
|
||||
if (aliasp->name == arg) {
|
||||
aliasp->alias_stream = sno;
|
||||
@ -394,6 +400,7 @@ Yap_AddAlias (Atom arg, int sno)
|
||||
}
|
||||
aliasp++;
|
||||
}
|
||||
|
||||
/* we have not found an alias neither a hole */
|
||||
if (aliasp == GLOBAL_FileAliases+GLOBAL_SzOfFileAliases)
|
||||
ExtendAliasArray();
|
||||
|
@ -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,
|
||||
Term file_name, encoding_t encoding, stream_flags_t flags,
|
||||
void *vfs) {
|
||||
fprintf(stderr,"+ %s --> %d\n", name, sno);
|
||||
StreamDesc *st = &GLOBAL_Stream[sno];
|
||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "init %s %s:%s stream <%d>",
|
||||
io_mode, CurrentModule == 0? "prolog": RepAtom(AtomOfTerm(CurrentModule))->StrOfAE,
|
||||
|
@ -998,7 +998,8 @@ static void CloseStream(int sno) {
|
||||
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "close stream <%d>",
|
||||
// sno);
|
||||
VFS_t *me;
|
||||
if ((me = GLOBAL_Stream[sno].vfs) != NULL &&
|
||||
fprintf( stderr, "- %d\n",sno);
|
||||
if ((me = GLOBAL_Stream[sno].vfs) != NULL &&
|
||||
GLOBAL_Stream[sno].file == NULL) {
|
||||
if (me->close) {
|
||||
me->close(sno);
|
||||
|
@ -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 (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 )
|
||||
|
||||
#talk to python.pl
|
||||
|
@ -112,7 +112,7 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
||||
// Yap_DebugPlWriteln(yt);
|
||||
switch (PL_term_type(t)) {
|
||||
case PL_VARIABLE: {
|
||||
if (t == 0) {
|
||||
if (yt == 0) {
|
||||
Yap_ThrowError(SYSTEM_ERROR_INTERNAL, yt, "in term_to_python");
|
||||
}
|
||||
PyObject *out = PyTuple_New(1);
|
||||
@ -150,19 +150,18 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
||||
} else {
|
||||
return CHECKNULL(t, NULL);
|
||||
}
|
||||
PyObject *pobj = PyUnicode_FromString(s);
|
||||
|
||||
#if PY_MAJOR_VERSION < 3
|
||||
if (proper_ascii_string(s)) {
|
||||
PyObject *o = PyString_FromStringAndSize(s, strlen(s));
|
||||
return CHECKNULL(t, o);
|
||||
} else
|
||||
}
|
||||
#endif
|
||||
{
|
||||
// char *p = malloc(strlen(s)+1);
|
||||
// strcpy(p, s);
|
||||
PyObject *pobj = PyUnicode_FromString(s);
|
||||
Py_IncRef(pobj);
|
||||
return CHECKNULL(t, pobj);
|
||||
}
|
||||
} break;
|
||||
case PL_INTEGER: {
|
||||
int64_t j;
|
||||
@ -406,8 +405,8 @@ PyObject *deref_term_to_python(term_t t) {
|
||||
// am\n");
|
||||
YAP_Term yt = YAP_GetFromSlot(t);
|
||||
if (YAP_IsVarTerm(yt)) {
|
||||
char s[32];
|
||||
char *o = YAP_WriteBuffer(yt, s, 31, 0);
|
||||
char b[1024];
|
||||
char *o = YAP_WriteBuffer(yt, b, 1023, 0);
|
||||
PyObject *p = PyUnicode_FromString(o);
|
||||
return p;
|
||||
}
|
||||
|
@ -953,9 +953,11 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
|
||||
|
||||
if (!PL_get_arg(1, t, targ))
|
||||
return NULL;
|
||||
// Yap_DebugPlWriteln(YAP_GetFromSlot(t));
|
||||
lhs = term_to_python(targ, true, NULL, true);
|
||||
AOK(PL_get_arg(2, t, targ), NULL);
|
||||
rhs = term_to_python(targ, true, NULL, true);
|
||||
Yap_DebugPlWriteln(YAP_GetFromSlot(targ));
|
||||
if (PySequence_Check(lhs) && PySequence_Check(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);
|
||||
}
|
||||
}
|
||||
DebugPrintf("Tuple %p\n", pyDict);
|
||||
fprintf(stderr,"Tuple %p: %s\n", pyDict, PyUnicode_AsUTF8(PyObject_Str(pyDict)));
|
||||
if (!indict) {
|
||||
if (PL_is_variable(tleft)) {
|
||||
pArg = Py_None;
|
||||
|
@ -5,9 +5,12 @@ PyObject *py_Main;
|
||||
|
||||
void pyErrorHandler__(int line, const char *file, const char *code) {
|
||||
// this code is called if a Python error is found.
|
||||
fprintf(stderr, " Python error detcted at %s %s:%d\n\n", code, file, line);
|
||||
PyErr_Print();
|
||||
}
|
||||
//int lvl = push_text_stack();
|
||||
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) {
|
||||
Py_ssize_t len;
|
||||
|
@ -709,6 +709,7 @@ class YAPRun:
|
||||
self.shell.displayhook.exec_result = self.result
|
||||
has_raised = False
|
||||
try:
|
||||
self.yapeng.mgoal(streams(True),"user", True)
|
||||
self.bindings = dicts = []
|
||||
if cell.strip('\n \t'):
|
||||
#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
|
||||
#
|
||||
# tracer.runfunc(f,self,cell,state)
|
||||
self.yapeng.mgoal(streams(True),"user", True)
|
||||
self.jupyter_query( cell )
|
||||
self.yapeng.mgoal(streams(False),"user", True)
|
||||
# state = tracer.runfunc(jupyter_query( self, cell ) )
|
||||
self.shell.last_execution_succeeded = True
|
||||
self.result.result = (True, dicts)
|
||||
self.yapeng.mgoal(streams(False),"user", True)
|
||||
|
||||
except Exception as e:
|
||||
has_raised = True
|
||||
self.result.result = False
|
||||
self.yapeng.mgoal(streams(False),"user", True)
|
||||
|
||||
self.shell.last_execution_succeeded = not has_raised
|
||||
|
||||
@ -771,7 +772,7 @@ class YAPRun:
|
||||
else:
|
||||
taken = l0-(i-1)
|
||||
n = s[i+1:].strip()
|
||||
s = s[:i-1]
|
||||
s = s[:i]
|
||||
if n:
|
||||
its = 0
|
||||
for ch in n:
|
||||
|
@ -236,7 +236,6 @@ qend_program :-
|
||||
prolog_flag_property(X, [access(read_write)]),
|
||||
atom(X),
|
||||
yap_flag(X, V),
|
||||
writeln(X:V),
|
||||
X \= gc_margin, % different machines will have different needs,
|
||||
X \= argv,
|
||||
X \= os_argv,
|
||||
|
Reference in New Issue
Block a user