Python support
This commit is contained in:
parent
e6c2503563
commit
c0c002134b
@ -1,4 +1,3 @@
|
||||
|
||||
/************************************************************************* *
|
||||
* YAP Prolog *
|
||||
* Yap Prolog was developed at NCCUP - Universidade do Porto *
|
||||
@ -2012,8 +2011,7 @@ X_API int YAP_InitConsult(int mode, const char *filename, int *osnop) {
|
||||
CACHE_REGS
|
||||
FILE *f;
|
||||
int sno;
|
||||
char full[FILENAME_MAX]
|
||||
BACKUP_MACHINE_REGS();
|
||||
char full[FILENAME_MAX] BACKUP_MACHINE_REGS();
|
||||
|
||||
if (mode == YAP_BOOT_MODE) {
|
||||
mode = YAP_CONSULT_MODE;
|
||||
@ -2026,10 +2024,9 @@ X_API int YAP_InitConsult(int mode, const char *filename, int *osnop) {
|
||||
f = fopen(fl, "r");
|
||||
if (!f)
|
||||
return -1;
|
||||
else if (fl != filename && fl != full &&
|
||||
fl != LOCAL_FileNameBuf &&
|
||||
fl != LOCAL_FileNameBuf2)
|
||||
free(fl);
|
||||
else if (fl != filename && fl != full && fl != LOCAL_FileNameBuf &&
|
||||
fl != LOCAL_FileNameBuf2)
|
||||
free((void *)fl);
|
||||
sno = Yap_OpenStream(f, NULL, TermNil, Input_Stream_f);
|
||||
*osnop = Yap_CheckAlias(AtomLoopStream);
|
||||
if (!Yap_AddAlias(AtomLoopStream, sno)) {
|
||||
@ -2455,8 +2452,10 @@ Int YAP_Init(YAP_init_args *yap_init) {
|
||||
}
|
||||
if (Atts && Atts * 1024 > 2048 * sizeof(CELL))
|
||||
Yap_AttsSize = Atts * 1024;
|
||||
else
|
||||
else {
|
||||
Yap_AttsSize = 2048 * sizeof(CELL);
|
||||
}
|
||||
LOCAL_PrologMode &= ~BootMode;
|
||||
if (restore_result == DO_ONLY_CODE) {
|
||||
/* first, initialize the saved state */
|
||||
Term t_goal = MkAtomTerm(AtomInitProlog);
|
||||
|
7
C/exec.c
7
C/exec.c
@ -1781,7 +1781,6 @@ restart_runtopgoal:
|
||||
|
||||
#if !USE_SYSTEM_MALLOC
|
||||
if (LOCAL_TrailTop - HeapTop < 2048) {
|
||||
LOCAL_PrologMode = BootMode;
|
||||
Yap_Error(RESOURCE_ERROR_TRAIL, TermNil,
|
||||
"unable to boot because of too little Trail space");
|
||||
}
|
||||
@ -1994,7 +1993,8 @@ static Int JumpToEnv() {
|
||||
/* we are already doing a catch */
|
||||
/* make sure we prune C-choicepoints */
|
||||
if (handler->cp_ap == NOCODE &&
|
||||
handler >= (choiceptr)(LCL0 - LOCAL_CBorder)) {
|
||||
(handler >= (choiceptr)(LCL0 - LOCAL_CBorder) ||
|
||||
handler->cp_b == NULL)) {
|
||||
break;
|
||||
}
|
||||
oh = handler;
|
||||
@ -2047,7 +2047,8 @@ static Int jump_env(USES_REGS1) {
|
||||
Term t = Deref(ARG1);
|
||||
Yap_PutException(t);
|
||||
bool out = JumpToEnv(PASS_REGS1);
|
||||
if (P == FAILCODE && B->cp_ap == NOCODE && LCL0 - (CELL *)B > LOCAL_CBorder) {
|
||||
if (B != NULL && P == FAILCODE && B->cp_ap == NOCODE &&
|
||||
LCL0 - (CELL *)B > LOCAL_CBorder) {
|
||||
// we're failing up to the top layer
|
||||
LOCAL_Error_TYPE = THROW_EVENT;
|
||||
}
|
||||
|
@ -2,7 +2,7 @@
|
||||
find_host_package (SWIG)
|
||||
macro_log_feature (SWIG_FOUND "Swig"
|
||||
"Use SWIG Documentation System "
|
||||
"http://www.swig.org" FALSE)
|
||||
"http://www.swig.org" ON)
|
||||
|
||||
if (SWIG_FOUND)
|
||||
#
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
INCLUDE(${SWIG_USE_FILE})
|
||||
|
||||
FIND_PACKAGE(PythonLibs)
|
||||
if (PYTHONLIBS_FOUND)
|
||||
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
|
||||
|
||||
INCLUDE_DIRECTORIES( ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/CXX)
|
||||
@ -12,9 +12,51 @@ SET(CMAKE_SWIG_FLAGS "")
|
||||
|
||||
SET_SOURCE_FILES_PROPERTIES(../yap.i PROPERTIES CPLUSPLUS ON)
|
||||
SET_SOURCE_FILES_PROPERTIES(../yap.i PROPERTIES SWIG_FLAGS "-includeall")
|
||||
SWIG_ADD_MODULE(yapy python ../yap.i)
|
||||
SWIG_LINK_LIBRARIES(yapy ${PYTHON_LIBRARIES} Yap++ libYap)
|
||||
SWIG_ADD_MODULE(yap python ../yap.i)
|
||||
SWIG_LINK_LIBRARIES(yap ${PYTHON_LIBRARIES} Yap++ libYap)
|
||||
set_target_properties ( ${SWIG_MODULE_yap_REAL_NAME} PROPERTIES NO_SONAME ON )
|
||||
|
||||
INSTALL(FILES yapy.py
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${outdir}/yap.py
|
||||
DESTINATION ${libpl}/python)
|
||||
execute_process ( COMMAND ${PYTHON_EXECUTABLE} -c "from distutils import sysconfig; print( sysconfig.get_python_lib( plat_specific=True, prefix='${CMAKE_INSTALL_PREFIX}' ) )"
|
||||
OUTPUT_VARIABLE _ABS_PYTHON_MODULE_PATH
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE )
|
||||
|
||||
get_filename_component ( _ABS_PYTHON_MODULE_PATH ${_ABS_PYTHON_MODULE_PATH} ABSOLUTE )
|
||||
file ( RELATIVE_PATH _REL_PYTHON_MODULE_PATH ${CMAKE_INSTALL_PREFIX} ${_ABS_PYTHON_MODULE_PATH} )
|
||||
|
||||
set ( PYTHON_MODULE_PATH
|
||||
${_REL_PYTHON_MODULE_PATH}
|
||||
)
|
||||
|
||||
INSTALL ( FILES ${CMAKE_CURRENT_BINARY_DIR}/_yap.so DESTINATION ${PYTHON_MODULE_PATH} )
|
||||
INSTALL ( FILES ${CMAKE_CURRENT_BINARY_DIR}/yap.py DESTINATION ${PYTHON_MODULE_PATH} )
|
||||
INSTALL ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/yapex.py DESTINATION ${PYTHON_MODULE_PATH} )
|
||||
|
||||
if ( DOCUMENTATION AND DOXYGEN_FOUND )
|
||||
|
||||
set(CMAKE_SWIG_FLAGS -DDOXYGEN=${DOXYGEN_FOUND})
|
||||
|
||||
# Run doxygen to only generate the xml
|
||||
add_custom_command ( OUTPUT ${CMAKE_BINARY_DIR}/doc/xml/ftdi_8c.xml
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_BINARY_DIR}/doc
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_BINARY_DIR}/Doxyfile.xml
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
DEPENDS ${c_headers};${c_sources};${cpp_sources};${cpp_headers}
|
||||
)
|
||||
|
||||
# generate .i from doxygen .xml
|
||||
add_custom_command ( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i
|
||||
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/doxy2swig.py -n
|
||||
${CMAKE_BINARY_DIR}/doc/xml/ftdi_8c.xml
|
||||
${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i
|
||||
DEPENDS ${CMAKE_BINARY_DIR}/doc/xml/ftdi_8c.xml
|
||||
)
|
||||
add_custom_target ( doc_i DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ftdi1_doc.i )
|
||||
add_dependencies( ${SWIG_MODULE_ftdi1_REAL_NAME} doc_i )
|
||||
|
||||
endif ()
|
||||
|
||||
|
||||
# add_subdirectory ( examples )
|
||||
else ()
|
||||
message(STATUS "Not building python bindings")
|
||||
endif(PYTHONLIBS_FOUND)
|
||||
|
@ -1,33 +0,0 @@
|
||||
# python commands
|
||||
|
||||
import sys
|
||||
import yap
|
||||
|
||||
#
|
||||
# initialize engine
|
||||
engine = yap.YAPEngine();
|
||||
# engine = yap.YAPEngine(yap.YAPParams());
|
||||
|
||||
def query( s ):
|
||||
q = engine.query(s)
|
||||
while q.next():
|
||||
vs = q.namedVars()
|
||||
if vs.length() == 0:
|
||||
print( "yes" )
|
||||
return
|
||||
else:
|
||||
while vs.length() > 0:
|
||||
eq = vs.car()
|
||||
print( eq.getArg(1).text() + " = " + eq.getArg(2).text() )
|
||||
vs = vs.cdr()
|
||||
s = raw_input("next: ?")
|
||||
if s.find(';') != 0 :
|
||||
return
|
||||
print( "no more answers" )
|
||||
return
|
||||
|
||||
def live():
|
||||
loop = True
|
||||
while loop:
|
||||
s = raw_input("?- ")
|
||||
query( s )
|
Reference in New Issue
Block a user