This commit is contained in:
Vitor Santos Costa 2017-06-16 11:53:46 +01:00
parent 8ac3d980c2
commit 31f1c25ee7
8 changed files with 23 additions and 190 deletions

View File

@ -517,7 +517,6 @@ bool YAPEngine::mgoal(Term t, Term tmod)
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exec ");
result = (bool)YAP_EnterGoal(ap, nullptr, &q);
// fprintf(stderr,"in");Yap_DebugPlWrite(t);
{
YAP_LeaveGoal(false, &q);
RECOVER_MACHINE_REGS();
@ -625,6 +624,7 @@ Term YAPEngine::fun(Term t)
YAPQuery::YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm ts[])
: YAPPredicate(f, mod)
{
/* ignore flags for now */
BACKUP_MACHINE_REGS();
Term *nts;
@ -1110,7 +1110,7 @@ YAPEngine::YAPEngine(int argc, char *argv[],
s += "\n";
}
}
printf("%s\n", s.c_str());
// printf("%s\n", s.c_str());
return s.c_str();
}

View File

@ -1,167 +0,0 @@
% % % -*-Mode : Prolog; -*-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Author: Vitor Santos Costa
% E-mail: vsc@dcc.fc.up.pt
% Copyright (C): Universidade do Porto
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% This file is part of the YAP Python Interface
% distributed according to Perl Artistic License
% check LICENSE file for distribution license
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
:- module(python,
[
init_python/0,
end_python/0,
python_command/1,
python_run_file/1,
python_run_command/1,
python_run_script/2,
python_assign/3,
python_import/1,
array_to_python_list/4,
array_to_python_tuple/4,
array_to_python_view/5,
python/2,
acquire_GIL/0,
release_GIL/0,
python_threaded/0,
(:=)/2,
(:=)/1,
% (<-)/2,
% (<-)/1,
op(100,fy,$),
op(950,fy,:=),
op(950,yfx,:=),
op(950,fx,<-),
op(950,yfx,<-),
op(50, yf, []),
op(50, yf, '()'),
op(100, xfy, '.'),
op(100, fy, '.')
]).
/** <module> python
A C-based Prolog interface to python.
@author Vitor Santos Costa
@version 0:0:5, 2012/10/8
@license Perl Artistic License
This is an interface to allow calling Python from Prolog. Please look
at the SWIG package if you want to embedd Prolog with Python.
The interface should be activated by consulting the python lybrary. It
immediately boots a Python image.
To best define the interface, one has to address two opposite goals:
- make it as similar to python as possible
- make all embedded language interfaces (python, R, Java) as
similar as possible.
YAP supports the following translation between Prolog and Python:
| *Prolog* | *Pyhon* | *Prolog Examples* |
|:-------------:|:-------------:|---------------------------------------:|
| Numbers | Numbers | 2.3
| | | 1545
| | |
| Atom | Symbols | var
| $Atom | | $var [ = var]
| `string` | 'string' | \`hello\`
| "string" | ' | "hello"
| | |
| Atom(...) | Symb(...) | f( a, b, named=v)
| E.F(...) | E.F (...) | mod.f( a) [ = [mod\|f(a)] ]
| Atom() | | f() [ = '()'(f) ]
| Lists | Lists | [1,2,3]
| t(....) | Tuples | t(1,2,3) to (1,2,3)
| (..., ...) | | (1,2,3)[ = (1,(2,3))]
| {.=., .=.} | Dict | {\`one\`: 1, \`two\`: 2, \`three\`: 3}
*/
/************************************************************************************************************
Python interface
Data types are
Python Prolog
string atoms
numbers numbers
lists lists
tuples t(...)
generic objs __pointer__(Address)
$var refers to the attribute __main__.var
*************************************************************************************************************/
:- use_module(library(shlib)).
:- use_module(library(lists)).
:- use_module(library(apply_macros)).
:- use_module(library(charsio)).
:- dynamic python_mref_cache/2, python_obj_cache/2.
:= (P1,P2) :- !,
:= P1,
:= P2.
:= import( F ) :- !, python_import(F).
:= F :- python_is(F,_).
V <- F :-
V := F.
( V := F ) :-
python_assign(V, F).
((<- F)) :-
:= F.
python_import(Module) :-
python_import(Module, _).
python(Exp, Out) :-
Out := Exp.
python_assign(V, New) :- var(V), !,
python_is( New, V).
python_assign(T, F) :- atom(T), !,
python_assign_symbol(T, F).
python_assign(T.I, F) :- !,
python_assign_field(T, I, F).
python_assign(T[I], F) :- !,
python_assign_item(T, I, F).
python_assign(F, Tuple) :-
python_assign_tuple(F, Tuple).
python_command(Cmd) :-
python_run_command(Cmd).
start_python :-
python_import('inspect', _),
at_halt(end_python).
add_cwd_to_python :-
unix(getcwd(Dir)),
atom_concat(['sys.path.append(\"',Dir,'\")'], Command),
python_command(Command),
python_command("sys.argv = [\"yap\"]").
% done
:- initialization( load_foreign_files([libYAPPython], [], init_python), now ).
:- initialization( load_foreign_library(foreign(libYAPPython), init_python), now ).

View File

@ -9,12 +9,13 @@ set (CMAKE_POSITION_INDEPENDENT_CODE TRUE)
include_directories( ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/include )
add_library (YAPPython SHARED pyload.c ${PYTHON_HEADERS} )
if (WIN32)
add_library (Py4YAP OBJECT ${PYTHON_SOURCES} ${PYTHON_HEADERS})
add_library (YAPPython SHARED pyload.c ${PYTHON_HEADERS} )
else()
add_library (Py4YAP SHARED ${PYTHON_SOURCES} ${PYTHON_HEADERS})
add_library (YAPPython SHARED pyload.c ${PYTHON_SOURCES} ${PYTHON_HEADERS})
# arithmetic hassle.
set_property(TARGET Py4YAP PROPERTY CXX_STANDARD 11)
@ -36,7 +37,7 @@ set_property(TARGET YAPPython PROPERTY CXX_STANDARD_REQUIRED ON)
target_link_libraries(YAPPython libYap ${PYTHON_LIBRARIES})
set_property( SOURCE ${PYTHON_SOURCES} APPEND PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 _GNU-SOURCE=1)
set_property( SOURCE ${PYTHON_SOURCES} APPEND PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 _GNU_SOURCE=1)
set (PYTHON_PL python.pl)
@ -44,11 +45,7 @@ install(FILES python.pl DESTINATION ${libpl} )
add_to_group( pl_library PYTHON_PL )
# configure_file ("setup.py.cmake" "setup.py" )
# set(SETUP_PY "${CMAKE_CURRENT_BINARY_DIR}/setup.py")
#set_target_properties (YAPPython PROPERTIES PREFIX "")
set_target_properties (YAPPython PROPERTIES PREFIX "")
install(TARGETS YAPPython
LIBRARY DESTINATION ${dlls}

View File

@ -99,7 +99,7 @@ PyObject *find_obj(PyObject *ob, term_t l, bool eval) {
yt = YAP_GetFromSlot(l);
while (YAP_IsPairTerm(yt)) {
hd = YAP_HeadOfTerm(yt);
ob = yap_to_python(hd, eval, ob);
ob = yap_to_python(hd, true, ob);
ob = CHECKNULL(yt, ob);
if (!ob){
return Py_None;

View File

@ -151,4 +151,4 @@ add_cwd_to_python :-
python_command("sys.argv = [\"yap\"]").
% done
:- initialization( load_foreign_files([libYAPPython], [], init_python_dll), now ).
:- initialization( load_foreign_files(['YAPPython'], [], init_python_dll), now ).

View File

@ -48,13 +48,15 @@ endif()
$<TARGET_FILE:itries>
$<TARGET_FILE:sys>
$<TARGET_FILE:yap_random>
$<TARGET_FILE:YAP++>
$<TARGET_FILE:YAPPython>
)
if (TARGET real)
list(APPEND python_dlls $<TARGET_FILE:real>
)
endif()
if (NOT WIN32)
list(APPEND python_dlls $<TARGET_FILE:YAP++> $<TARGET_FILE:Py4YAP>
)
endif()
set (PL ${pl_library} ${PROLOG_SOURCES} )
@ -76,7 +78,7 @@ add_custom_target( YAP4PY_SETUP_DIRS
)
add_custom_target( YAP4PY ALL
COMMAND ${PYTHON_EXECUTABLE} setup.py sdist bdist_wheel
COMMAND ${SWIG_EXECUTABLE} -python -modern -c++ -py3 -DX_API -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/include -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/H/generated -I${CMAKE_SOURCE_DIR}/OPTYap -I../../.. -o yap_wrap.cpp yap.i
COMMAND ${PYTHON_EXECUTABLE} setup.py sdist bdist_wheel
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS YAP4PY_SETUP)

View File

@ -20,6 +20,6 @@ else:
dll = glob.glob(os.path.join(yap_lib_path,dll))[0]
dll = os.path.abspath(dll)
ctypes.CDLL(dll, mode=ctypes.RTLD_GLOBAL)
load('libYap*')
load('libYAP+*')
load('libPy4YAP*')
load('libYap*')

View File

@ -52,20 +52,21 @@ here = os.path.abspath(os.path.dirname(__file__))
pkg_root = pjoin(here, name)
my_extra_link_args = []
if platform.system() == 'Darwin':
if platform.system() == 'Windows':
local_libs = []
win_libs = ['wsock32','ws2_32']
my_extra_link_args = ['-Wl,-export-all-symbols']
else:
# if platform.system() == 'Darwin':
my_extra_link_args = ['-Wl,-rpath', '-Wl,${_ABS_PYTHON_MODULE_PATH}']
win_libs = []
local_libs = ['YAP++','Py4YAP']
# or dll in glob('yap/dlls/*'):
# move( dll ,'lib' )
elif platform.system() == 'Windows':
local_libs = []
win_libs = ['wsock32','ws2_32']
my_extra_link_args = ['-Wl,-export-all-symbols']
cplus = ['']
bpy2yap = []
native_sources = ['yap.i']
native_sources = ['yap_wrap.cpp']
here = path.abspath(path.dirname(__file__))
# Get the long description from the README file