This commit is contained in:
Vitor Santos Costa 2018-08-19 14:39:12 +01:00
parent 208ed54b45
commit 244ee465c4
8 changed files with 37 additions and 23 deletions

View File

@ -1137,7 +1137,7 @@ void Yap_plwrite(Term t, StreamDesc *mywrite, int max_depth, int flags,
rwt.parent = NULL;
wglb.Ignore_ops = flags & Ignore_ops_f;
wglb.Write_strings = flags & BackQuote_String_f;
if (!(flags & Ignore_cyclics_f) && Yap_do_low_level_trace) {
if (!(flags & Ignore_cyclics_f) && false) {
Term ts[2];
Yap_do_low_level_trace=false;
Yap_DebugPlWriteln(t);

View File

@ -1,4 +1,5 @@
#include "Yap.h"
#include "py4yap.h"
@ -259,8 +260,6 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
return out;
} else {
PyObject *no = find_term_obj(o, &t0, false);
if (no == o)
return NULL;
return yap_to_python(t0, eval, no, cvt);
}
} else {
@ -418,7 +417,7 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
PL_reset_term_refs(arg);
YAPPy_ThrowError(SYSTEM_ERROR_INTERNAL, t, "t(...)->python");
}
PyObject *a = term_to_python(arg, eval, o, cvt);
PyObject *a = term_to_python(arg, eval, NULL, cvt);
if (a) {
if (PyTuple_SetItem(rc, i, a) < 0) {
PL_reset_term_refs(arg);

View File

@ -226,7 +226,7 @@ bool python_assign(term_t t, PyObject *exp, PyObject *context) {
return python_to_term(exp, t);
}
case PL_STRING: {
case PL_STRING: {
char *s = NULL;
size_t l;
PL_get_string_chars(t, &s,&l);

View File

@ -12,21 +12,29 @@
#include "py4yap.h"
static PyObject *finalLookup(PyObject *i, const char *s) {
PyObject *rc;
PyObject *os = PyUnicode_FromString(s), *rc = NULL;
if (i == NULL)
return NULL;
if (strcmp(s, "none") == 0)
return Py_None;
if (PyDict_Check(i)) {
if ((rc = PyDict_GetItemString(i, s)))
return rc;
}
if (PyModule_Check(i)) {
if ((rc = PyDict_GetItemString(i, s)))
return rc;
i = PyModule_GetDict(i);
}
if (PyDict_Check(i))
{
if (PyDict_Contains(i, os) == 1) {
rc = PyDict_GetItem(i, os);
}
if (PyObject_HasAttrString(i, s)) {
return PyObject_GetAttrString(i, s);
}
if (!rc && PyObject_HasAttr(i, os)) {
rc = PyObject_GetAttr(i, os);
}
if (rc)
{
Py_IncRef(rc);
return rc;
}
return NULL;
}
@ -69,6 +77,10 @@ PyObject *lookupPySymbol(const char *sp, PyObject *pContext, PyObject **duc) {
if ((out = finalLookup(py_Builtin, sp))) {
return out;
}
if ((out = finalLookup(py_Atoms, sp)))
{
return out;
}
PyObject *py_Local = PyEval_GetLocals();
if ((out = finalLookup(py_Local, sp)) && out != Py_None) {
return out;
@ -479,7 +491,7 @@ static PyObject *bip_sum(term_t t) {
}
#if PY_MAJOR_VERSION < 3
if (PyInt_CheckExact(item)) {
764PyFPE_START_PROTECT("add", Py_DECREF(item); Py_DECREF(iter);
PyFPE_START_PROTECT("add", Py_DECREF(item); Py_DECREF(iter);
return 0)f_result += (double)PyInt_AS_LONG(item);
PyFPE_END_PROTECT(f_result) Py_DECREF(item);
continue;
@ -1079,6 +1091,8 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
PyObject *key = PyUnicode_FromString(sk);
AOK(PL_get_arg(2, tleft, tleft), NULL);
PyObject *val = term_to_python(tleft, true, o, cvt);
if (val == NULL)
return NULL;
PyDict_SetItem(pyDict, key, val);
} else {
indict = false;
@ -1110,9 +1124,9 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
PyObject *rc;
if (ys && PyCallable_Check(ys)) {
PyObject_Print(ys, stderr, 0);
PyObject_Print(pArgs, stderr, 0);
PyObject_Print(pyDict, stderr, 0);
//PyObject_Print(ys, stderr, 0);
// PyObject_Print(pArgs, stderr, 0);
// PyObject_Print(pyDict, stderr, 0);
// PyObject_Print(pArgs, stderr, 0);
// PyObject_Print(o, stderr, 0);

View File

@ -131,7 +131,7 @@ static bool py_close(int sno) {
static bool pygetLine(StreamDesc *rl_iostream, int sno) {
// term_t ctk = python_acquire_GIL();
const char *myrl_line;
PyObject *user_line;
PyObject *user_line, *prompt;
StreamDesc *s = YAP_GetStreamFromId(sno);
//term_t tg = python_acquire_GIL();
if (!strcmp(RepAtom(s->name)->StrOfAE,"input") ) {
@ -144,10 +144,10 @@ static bool pygetLine(StreamDesc *rl_iostream, int sno) {
Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), err);
}
}
user_line = PyObject_CallFunctionObjArgs(pystream, NULL);
user_line = PyObject_CallFunctionObjArgs(pystream, PyUnicode_FromString("?- ") , NULL);
} else {
PyObject *readl = PyObject_GetAttrString(s->u.private_data, "readline");
user_line = PyObject_CallFunction(readl, NULL);
user_line = PyObject_CallFunction(readl, PyUnicode_FromString("?- ") , NULL);
}
myrl_line = PyUnicode_AsUTF8(user_line);
if (myrl_line == NULL)

View File

@ -648,7 +648,7 @@ static int python_import(term_t mname, term_t mod) {
foreign_t rc = address_to_term(pModule, mod);
if (do_as) {
PyObject_SetAttrString(py_Main, as, pModule);
PyModule_AddObject(py_Main, as, pModule);
}
python_release_GIL(t0);
pyErrorAndReturn(rc);

View File

@ -648,6 +648,7 @@ class YAPRun:
raw_cell, store_history, silent, shell_futures)
self.result = interactiveshell.ExecutionResult(info)
self.result.error_before_exec = None
if (raw_cell == "") or raw_cell.isspace():
self.shell.last_execution_succeeded = True

View File

@ -35,7 +35,7 @@ class YAPEngine;
#if defined(SWIGPYTHON)
%pythoncode %{
YAPError = _yap.YAPError
# YAPError = _yap.YAPError
%}
%typemap(typecheck) Term* {