This commit is contained in:
Vitor Santos Costa 2017-01-09 14:58:57 +00:00
parent 6778ea2975
commit 4db2a1fe7f
9 changed files with 53 additions and 47 deletions

View File

@ -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)

View File

@ -1,9 +0,0 @@
set (CXX_SOURCES
yapa.hh
yapdb.hh
yapi.cpp
yapi.hh
yapie.hh
yapq.hh
yapt.hh
)

View File

@ -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();

View File

@ -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

View File

@ -6,16 +6,7 @@
extern "C" {
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;
@ -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) {

View File

@ -10,10 +10,12 @@ for the relative license.
#include <stdio.h>
#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"

View File

@ -3,7 +3,7 @@
if (PYTHONLIBS_FOUND)
include(FindPythonModule)
include(FindPythonModule)
include("${CMAKE_SOURCE_DIR}/packages/python/Sources.cmake")

View File

@ -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++) {

View File

@ -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 )