From 4db2a1fe7f48cfee8560e9d40d1f267b4eb959b7 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Mon, 9 Jan 2017 14:58:57 +0000 Subject: [PATCH] python --- CXX/CMakeLists.txt | 8 ++++++++ CXX/CXXSources.cmake | 9 --------- CXX/yapi.cpp | 18 ++++++++++++------ CXX/yapq.hh | 7 ++++++- CXX/yapt.hh | 19 ++++--------------- packages/cplint/cplint.h | 10 ++++++---- packages/python/CMakeLists.txt | 2 +- packages/python/pybips.c | 16 ++++++++++------ packages/swig/python/CMakeLists.txt | 11 ++++++----- 9 files changed, 53 insertions(+), 47 deletions(-) diff --git a/CXX/CMakeLists.txt b/CXX/CMakeLists.txt index 105fbb8e6..2a3ea9a8c 100644 --- a/CXX/CMakeLists.txt +++ b/CXX/CMakeLists.txt @@ -8,6 +8,14 @@ set (CXX_SOURCES yapi.cpp ) +set (CXX_HEADERS + yapa.hh + yapdb.hh + yapi.h + yapie.hh + yapq.hh +- yapt.hh +-) list(APPEND LIBYAP_SOURCES ${CXX_SOURCES} PARENT_SCOPE) diff --git a/CXX/CXXSources.cmake b/CXX/CXXSources.cmake index 52dec53fa..e69de29bb 100644 --- a/CXX/CXXSources.cmake +++ b/CXX/CXXSources.cmake @@ -1,9 +0,0 @@ -set (CXX_SOURCES - yapa.hh - yapdb.hh - yapi.cpp - yapi.hh - yapie.hh - yapq.hh - yapt.hh -) diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp index 69c70bc8b..4e2d189e4 100644 --- a/CXX/yapi.cpp +++ b/CXX/yapi.cpp @@ -194,16 +194,18 @@ Term &YAPTerm::operator[](arity_t i) { // Functor f = FunctorOfTerm(t0); // if (IsExtensionFunctor(f)) // return 0; - RECOVER_MACHINE_REGS(); - return RepAppl(t0)[(i + 1)]; + tf = RepAppl(t0)[(i + 1)]; } else if (IsPairTerm(t0)) { if (i == 0) tf = HeadOfTerm(t0); else if (i == 1) tf = TailOfTerm(t0); RECOVER_MACHINE_REGS(); - return RepPair(tf)[i]; + tf = RepPair(tf)[i]; } + RECOVER_MACHINE_REGS(); + Yap_Error(TYPE_ERROR_COMPOUND, tf, ""); + throw YAPError(); } Term &YAPListTerm::operator[](arity_t i) { @@ -397,6 +399,8 @@ void YAPQuery::openQuery() { bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) { CACHE_REGS + if (ap.ap == NULL) + return false; BACKUP_MACHINE_REGS(); arity_t arity = ap.getArity(); bool result; @@ -426,11 +430,13 @@ bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) { bool YAPEngine::goalt(YAPTerm Yt) { return Yt.term(); } -bool YAPEngine::goal(Term t) { +bool YAPEngine::mgoal(Term t, Term tmod) { CACHE_REGS BACKUP_MACHINE_REGS(); - Term terr, tmod = CurrentModule, *ts = nullptr; + Term terr, *ts = nullptr; PredEntry *ap = Yap_get_pred(t, tmod, "C++"); + if (ap == nullptr) + return false; arity_t arity = ap->ArityOfPE; bool result; jmp_buf q_env; @@ -755,7 +761,7 @@ void YAPEngine::doInit(YAP_file_type_t BootMode) { Yap_AndroidSz = 0; #endif yerror = YAPError(); - + YAPQuery initq = YAPQuery(YAPAtom("$init_system")); if (initq.next()) { initq.cut(); diff --git a/CXX/yapq.hh b/CXX/yapq.hh index d06392c80..db79ce565 100644 --- a/CXX/yapq.hh +++ b/CXX/yapq.hh @@ -180,7 +180,12 @@ public: /// current directory for the engine bool goalt(YAPTerm t); /// current directory for the engine - bool goal(Term t); + bool mgoal(Term t, Term tmod); + /// current directory for the engine + +bool goal(Term t) { + return mgoal(t, CurrentModule); +} /// reset Prolog state void reSet(); /// release: assune that there are no stack pointers, just release memory diff --git a/CXX/yapt.hh b/CXX/yapt.hh index 5a46dce13..458edf0d7 100644 --- a/CXX/yapt.hh +++ b/CXX/yapt.hh @@ -6,16 +6,7 @@ extern "C" { Term YAP_ReadBuffer(const char *s, Term *tp); -#if defined(SWIGPYTHON) && 0 -#include -extern Term pythonToYAP(PyObject *inp); -#define YAPTerm _YAPTERM -#elifndef HAVE_PYTHON_H -typdef struct { int no_python; } PyObject; -#else -#include -#endif -}; +} class YAPError; @@ -55,14 +46,12 @@ public: }; YAPTerm(Term tn) { mk(tn); }; - YAPTerm(PyObject *inp) { #ifdef SWIGPYTHON + YAPTerm(PyObject *inp) { Term tinp = pythonToYAP(inp); t = Yap_InitSlot(tinp); -#else - t = 0; -#endif } +#endif /// private method to convert from Term (internal YAP representation) to /// YAPTerm // do nothing constructor @@ -96,7 +85,7 @@ public: inline void bind(YAPTerm *b) { LOCAL_HandleBase[t] = b->term(); } /// from YAPTerm to Term (internal YAP representation) /// fetch a sub-term - Term &operator[](size_t n); + Term &operator[](arity_t n); // const YAPTerm *vars(); /// this term is == to t1 virtual bool exactlyEqual(YAPTerm t1) { diff --git a/packages/cplint/cplint.h b/packages/cplint/cplint.h index 313bc17a6..97f3ce4eb 100644 --- a/packages/cplint/cplint.h +++ b/packages/cplint/cplint.h @@ -10,10 +10,12 @@ for the relative license. #include #include "config.h" #include "cudd_config.h" -#if HAVE_CUDD_CUDDINT_H -#include "cudd/cuddInt.h" -#elif HAVE_CUDDINT_H -#include "cuddInt.h" +#if HAVE_CUDD_CUDD_H +#include "cudd/cudd.h" +#include "cudd/mtr.h" +#elif HAVE_CUDD_H +#include "cudd.h" +#include "mtr.h" #endif #include "YapInterface.h" diff --git a/packages/python/CMakeLists.txt b/packages/python/CMakeLists.txt index 961946973..f4b63b352 100644 --- a/packages/python/CMakeLists.txt +++ b/packages/python/CMakeLists.txt @@ -3,7 +3,7 @@ if (PYTHONLIBS_FOUND) -include(FindPythonModule) +include(FindPythonModule) include("${CMAKE_SOURCE_DIR}/packages/python/Sources.cmake") diff --git a/packages/python/pybips.c b/packages/python/pybips.c index 5437a215b..5945a921e 100644 --- a/packages/python/pybips.c +++ b/packages/python/pybips.c @@ -641,9 +641,9 @@ static PyObject *structseq_repr(PyObject *iobj) { #endif PyObject *term_to_nametuple(const char *s, int arity, term_t t) { + PyObject *o; #if PY_MAJOR_VERSION >= 3 PyTypeObject *typp; - PyObject *o; PyObject *key = PyUnicode_FromString(s); if (py_F2P && PyDict_Contains(py_F2P, key)) { typp = (PyTypeObject *)PyDict_GetItem(py_F2P, key); @@ -667,7 +667,10 @@ PyObject *term_to_nametuple(const char *s, int arity, term_t t) { if (py_F2P) PyDict_SetItem(py_F2P, key, (PyObject *)typp); } - o = PyStructSequence_New(typp); + o = PyTuple_New(typp); +#else + o = PyTuple_New(arity); +#endif term_t tleft = PL_new_term_ref(); int i; @@ -678,15 +681,17 @@ PyObject *term_to_nametuple(const char *s, int arity, term_t t) { pArg = term_to_python(tleft, false); if (pArg == NULL) return NULL; +#if PY_MAJOR_VERSION >= 3 /* pArg reference stolen here: */ PyStructSequence_SET_ITEM(o, i, pArg); } ((PyStructSequence *)o)->ob_base.ob_size = arity; - return o; #else - if (PyObject_HasAttrString(py_Yapex, "T")) - c = PyObject_GetAttrString(py_Yapex, "T"); + /* pArg reference stolen here: */ + PyTuple_SET_ITEM(o, i, pArg); + } + PyObject *o1; o1 = PyTuple_New(2); PyTuple_SET_ITEM(o1, 0, PyUnicode_FromString(s)); PyTuple_SET_ITEM(o1, 1, o); @@ -959,7 +964,6 @@ PyObject *compound_to_pytree(term_t t, functor_t fun) { return NULL; term_t tleft; int i; - PyObject *o1; o = PyTuple_New(arity); tleft = PL_new_term_ref(); for (i = 0; i < arity; i++) { diff --git a/packages/swig/python/CMakeLists.txt b/packages/swig/python/CMakeLists.txt index b1823e213..56be27561 100644 --- a/packages/swig/python/CMakeLists.txt +++ b/packages/swig/python/CMakeLists.txt @@ -13,7 +13,7 @@ GET_PROPERTY(OBJECTS TARGET libOPTYap PROPERTY SOURCES) # list( APPEND OBJECTS GET_PROPERTY(sourcefiles TARGET utf8proc PROPERTY SOURCES)) # list( APPEND OBJECTS GET_PROPERTY(sourcefiles TARGET Yap++ PROPERTY SOURCES)) -if (PYTHONLIBS_FOUND) +ipf (PYTHONLIBS_FOUND) include(FindPythonModule) @@ -36,10 +36,11 @@ if (PYTHONLIBS_FOUND) SET( CMAKE_SWIG_OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/yap" ) - SWIG_ADD_MODULE(Py2YAP python ../yap.i ) - SWIG_LINK_LIBRARIES(Py2YAP ${PYTHON_LIBRARIES} Yap++ YAPPython libYap) + SWIG_ADD_MODULE(Py2YAP python ../yap.i ${YAP_SOURCES} ${PYTHo_SOURCES}) + SWIG_LINK_LIBRARIES(Py2YAP ${PYTHON_LIBRARIES} ) set_target_properties ( ${SWIG_MODULE_Py2YAP_REAL_NAME} PROPERTIES -NO_SONAME ON OUTPUT_NAME _yap LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/yap" ) +NO_SONAME ON OUTPUT_NAME _yap LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/yap" ENABLE_EXPORTS ON + ) execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c "import sysconfig; print( sysconfig.get_path( 'platlib' ) )" @@ -64,7 +65,7 @@ NO_SONAME ON OUTPUT_NAME _yap LIBRARY_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_D INSTALL ( FILES ${CMAKE_CURRENT_BINARY_DIR}/yap/_yap.so DESTINATION ${PYTHON_MODULE_PATH} ) INSTALL ( FILES ${CMAKE_CURRENT_BINARY_DIR}/yap/yap.py DESTINATION ${PYTHON_MODULE_PATH} ) - + if ( DOCUMENTATION AND DOXYGEN_FOUND )