python
This commit is contained in:
parent
6778ea2975
commit
4db2a1fe7f
@ -8,6 +8,14 @@ set (CXX_SOURCES
|
|||||||
yapi.cpp
|
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)
|
list(APPEND LIBYAP_SOURCES ${CXX_SOURCES} PARENT_SCOPE)
|
||||||
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
set (CXX_SOURCES
|
|
||||||
yapa.hh
|
|
||||||
yapdb.hh
|
|
||||||
yapi.cpp
|
|
||||||
yapi.hh
|
|
||||||
yapie.hh
|
|
||||||
yapq.hh
|
|
||||||
yapt.hh
|
|
||||||
)
|
|
18
CXX/yapi.cpp
18
CXX/yapi.cpp
@ -194,16 +194,18 @@ Term &YAPTerm::operator[](arity_t i) {
|
|||||||
// Functor f = FunctorOfTerm(t0);
|
// Functor f = FunctorOfTerm(t0);
|
||||||
// if (IsExtensionFunctor(f))
|
// if (IsExtensionFunctor(f))
|
||||||
// return 0;
|
// return 0;
|
||||||
RECOVER_MACHINE_REGS();
|
tf = RepAppl(t0)[(i + 1)];
|
||||||
return RepAppl(t0)[(i + 1)];
|
|
||||||
} else if (IsPairTerm(t0)) {
|
} else if (IsPairTerm(t0)) {
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
tf = HeadOfTerm(t0);
|
tf = HeadOfTerm(t0);
|
||||||
else if (i == 1)
|
else if (i == 1)
|
||||||
tf = TailOfTerm(t0);
|
tf = TailOfTerm(t0);
|
||||||
RECOVER_MACHINE_REGS();
|
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) {
|
Term &YAPListTerm::operator[](arity_t i) {
|
||||||
@ -397,6 +399,8 @@ void YAPQuery::openQuery() {
|
|||||||
|
|
||||||
bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) {
|
bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
if (ap.ap == NULL)
|
||||||
|
return false;
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
arity_t arity = ap.getArity();
|
arity_t arity = ap.getArity();
|
||||||
bool result;
|
bool result;
|
||||||
@ -426,11 +430,13 @@ bool YAPEngine::call(YAPPredicate ap, YAPTerm ts[]) {
|
|||||||
|
|
||||||
bool YAPEngine::goalt(YAPTerm Yt) { return Yt.term(); }
|
bool YAPEngine::goalt(YAPTerm Yt) { return Yt.term(); }
|
||||||
|
|
||||||
bool YAPEngine::goal(Term t) {
|
bool YAPEngine::mgoal(Term t, Term tmod) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
Term terr, tmod = CurrentModule, *ts = nullptr;
|
Term terr, *ts = nullptr;
|
||||||
PredEntry *ap = Yap_get_pred(t, tmod, "C++");
|
PredEntry *ap = Yap_get_pred(t, tmod, "C++");
|
||||||
|
if (ap == nullptr)
|
||||||
|
return false;
|
||||||
arity_t arity = ap->ArityOfPE;
|
arity_t arity = ap->ArityOfPE;
|
||||||
bool result;
|
bool result;
|
||||||
jmp_buf q_env;
|
jmp_buf q_env;
|
||||||
@ -755,7 +761,7 @@ void YAPEngine::doInit(YAP_file_type_t BootMode) {
|
|||||||
Yap_AndroidSz = 0;
|
Yap_AndroidSz = 0;
|
||||||
#endif
|
#endif
|
||||||
yerror = YAPError();
|
yerror = YAPError();
|
||||||
|
|
||||||
YAPQuery initq = YAPQuery(YAPAtom("$init_system"));
|
YAPQuery initq = YAPQuery(YAPAtom("$init_system"));
|
||||||
if (initq.next()) {
|
if (initq.next()) {
|
||||||
initq.cut();
|
initq.cut();
|
||||||
|
@ -180,7 +180,12 @@ public:
|
|||||||
/// current directory for the engine
|
/// current directory for the engine
|
||||||
bool goalt(YAPTerm t);
|
bool goalt(YAPTerm t);
|
||||||
/// current directory for the engine
|
/// 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
|
/// reset Prolog state
|
||||||
void reSet();
|
void reSet();
|
||||||
/// release: assune that there are no stack pointers, just release memory
|
/// release: assune that there are no stack pointers, just release memory
|
||||||
|
19
CXX/yapt.hh
19
CXX/yapt.hh
@ -6,16 +6,7 @@
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
Term YAP_ReadBuffer(const char *s, Term *tp);
|
Term YAP_ReadBuffer(const char *s, Term *tp);
|
||||||
#if defined(SWIGPYTHON) && 0
|
}
|
||||||
#include <Python.h>
|
|
||||||
extern Term pythonToYAP(PyObject *inp);
|
|
||||||
#define YAPTerm _YAPTERM
|
|
||||||
#elifndef HAVE_PYTHON_H
|
|
||||||
typdef struct { int no_python; } PyObject;
|
|
||||||
#else
|
|
||||||
#include <Python.h>
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
|
|
||||||
class YAPError;
|
class YAPError;
|
||||||
|
|
||||||
@ -55,14 +46,12 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
YAPTerm(Term tn) { mk(tn); };
|
YAPTerm(Term tn) { mk(tn); };
|
||||||
YAPTerm(PyObject *inp) {
|
|
||||||
#ifdef SWIGPYTHON
|
#ifdef SWIGPYTHON
|
||||||
|
YAPTerm(PyObject *inp) {
|
||||||
Term tinp = pythonToYAP(inp);
|
Term tinp = pythonToYAP(inp);
|
||||||
t = Yap_InitSlot(tinp);
|
t = Yap_InitSlot(tinp);
|
||||||
#else
|
|
||||||
t = 0;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
/// private method to convert from Term (internal YAP representation) to
|
/// private method to convert from Term (internal YAP representation) to
|
||||||
/// YAPTerm
|
/// YAPTerm
|
||||||
// do nothing constructor
|
// do nothing constructor
|
||||||
@ -96,7 +85,7 @@ public:
|
|||||||
inline void bind(YAPTerm *b) { LOCAL_HandleBase[t] = b->term(); }
|
inline void bind(YAPTerm *b) { LOCAL_HandleBase[t] = b->term(); }
|
||||||
/// from YAPTerm to Term (internal YAP representation)
|
/// from YAPTerm to Term (internal YAP representation)
|
||||||
/// fetch a sub-term
|
/// fetch a sub-term
|
||||||
Term &operator[](size_t n);
|
Term &operator[](arity_t n);
|
||||||
// const YAPTerm *vars();
|
// const YAPTerm *vars();
|
||||||
/// this term is == to t1
|
/// this term is == to t1
|
||||||
virtual bool exactlyEqual(YAPTerm t1) {
|
virtual bool exactlyEqual(YAPTerm t1) {
|
||||||
|
@ -10,10 +10,12 @@ for the relative license.
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "cudd_config.h"
|
#include "cudd_config.h"
|
||||||
#if HAVE_CUDD_CUDDINT_H
|
#if HAVE_CUDD_CUDD_H
|
||||||
#include "cudd/cuddInt.h"
|
#include "cudd/cudd.h"
|
||||||
#elif HAVE_CUDDINT_H
|
#include "cudd/mtr.h"
|
||||||
#include "cuddInt.h"
|
#elif HAVE_CUDD_H
|
||||||
|
#include "cudd.h"
|
||||||
|
#include "mtr.h"
|
||||||
#endif
|
#endif
|
||||||
#include "YapInterface.h"
|
#include "YapInterface.h"
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
if (PYTHONLIBS_FOUND)
|
if (PYTHONLIBS_FOUND)
|
||||||
|
|
||||||
include(FindPythonModule)
|
include(FindPythonModule)
|
||||||
|
|
||||||
|
|
||||||
include("${CMAKE_SOURCE_DIR}/packages/python/Sources.cmake")
|
include("${CMAKE_SOURCE_DIR}/packages/python/Sources.cmake")
|
||||||
|
@ -641,9 +641,9 @@ static PyObject *structseq_repr(PyObject *iobj) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
PyObject *term_to_nametuple(const char *s, int arity, term_t t) {
|
PyObject *term_to_nametuple(const char *s, int arity, term_t t) {
|
||||||
|
PyObject *o;
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#if PY_MAJOR_VERSION >= 3
|
||||||
PyTypeObject *typp;
|
PyTypeObject *typp;
|
||||||
PyObject *o;
|
|
||||||
PyObject *key = PyUnicode_FromString(s);
|
PyObject *key = PyUnicode_FromString(s);
|
||||||
if (py_F2P && PyDict_Contains(py_F2P, key)) {
|
if (py_F2P && PyDict_Contains(py_F2P, key)) {
|
||||||
typp = (PyTypeObject *)PyDict_GetItem(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)
|
if (py_F2P)
|
||||||
PyDict_SetItem(py_F2P, key, (PyObject *)typp);
|
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();
|
term_t tleft = PL_new_term_ref();
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -678,15 +681,17 @@ PyObject *term_to_nametuple(const char *s, int arity, term_t t) {
|
|||||||
pArg = term_to_python(tleft, false);
|
pArg = term_to_python(tleft, false);
|
||||||
if (pArg == NULL)
|
if (pArg == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
#if PY_MAJOR_VERSION >= 3
|
||||||
/* pArg reference stolen here: */
|
/* pArg reference stolen here: */
|
||||||
PyStructSequence_SET_ITEM(o, i, pArg);
|
PyStructSequence_SET_ITEM(o, i, pArg);
|
||||||
}
|
}
|
||||||
((PyStructSequence *)o)->ob_base.ob_size = arity;
|
((PyStructSequence *)o)->ob_base.ob_size = arity;
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
#else
|
#else
|
||||||
if (PyObject_HasAttrString(py_Yapex, "T"))
|
/* pArg reference stolen here: */
|
||||||
c = PyObject_GetAttrString(py_Yapex, "T");
|
PyTuple_SET_ITEM(o, i, pArg);
|
||||||
|
}
|
||||||
|
PyObject *o1;
|
||||||
o1 = PyTuple_New(2);
|
o1 = PyTuple_New(2);
|
||||||
PyTuple_SET_ITEM(o1, 0, PyUnicode_FromString(s));
|
PyTuple_SET_ITEM(o1, 0, PyUnicode_FromString(s));
|
||||||
PyTuple_SET_ITEM(o1, 1, o);
|
PyTuple_SET_ITEM(o1, 1, o);
|
||||||
@ -959,7 +964,6 @@ PyObject *compound_to_pytree(term_t t, functor_t fun) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
term_t tleft;
|
term_t tleft;
|
||||||
int i;
|
int i;
|
||||||
PyObject *o1;
|
|
||||||
o = PyTuple_New(arity);
|
o = PyTuple_New(arity);
|
||||||
tleft = PL_new_term_ref();
|
tleft = PL_new_term_ref();
|
||||||
for (i = 0; i < arity; i++) {
|
for (i = 0; i < arity; i++) {
|
||||||
|
@ -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 utf8proc PROPERTY SOURCES))
|
||||||
# list( APPEND OBJECTS GET_PROPERTY(sourcefiles TARGET Yap++ PROPERTY SOURCES))
|
# list( APPEND OBJECTS GET_PROPERTY(sourcefiles TARGET Yap++ PROPERTY SOURCES))
|
||||||
|
|
||||||
if (PYTHONLIBS_FOUND)
|
ipf (PYTHONLIBS_FOUND)
|
||||||
|
|
||||||
include(FindPythonModule)
|
include(FindPythonModule)
|
||||||
|
|
||||||
@ -36,10 +36,11 @@ if (PYTHONLIBS_FOUND)
|
|||||||
SET( CMAKE_SWIG_OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/yap" )
|
SET( CMAKE_SWIG_OUTDIR "${CMAKE_CURRENT_BINARY_DIR}/yap" )
|
||||||
|
|
||||||
|
|
||||||
SWIG_ADD_MODULE(Py2YAP python ../yap.i )
|
SWIG_ADD_MODULE(Py2YAP python ../yap.i ${YAP_SOURCES} ${PYTHo_SOURCES})
|
||||||
SWIG_LINK_LIBRARIES(Py2YAP ${PYTHON_LIBRARIES} Yap++ YAPPython libYap)
|
SWIG_LINK_LIBRARIES(Py2YAP ${PYTHON_LIBRARIES} )
|
||||||
set_target_properties ( ${SWIG_MODULE_Py2YAP_REAL_NAME} PROPERTIES
|
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' ) )"
|
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.so DESTINATION ${PYTHON_MODULE_PATH} )
|
||||||
INSTALL ( FILES ${CMAKE_CURRENT_BINARY_DIR}/yap/yap.py DESTINATION ${PYTHON_MODULE_PATH} )
|
INSTALL ( FILES ${CMAKE_CURRENT_BINARY_DIR}/yap/yap.py DESTINATION ${PYTHON_MODULE_PATH} )
|
||||||
|
|
||||||
|
|
||||||
if ( DOCUMENTATION AND DOXYGEN_FOUND )
|
if ( DOCUMENTATION AND DOXYGEN_FOUND )
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user