jupyter
This commit is contained in:
@@ -11,13 +11,13 @@ set (PYTHON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/yap4py/yapi.py ${CMAKE_CURRENT_S
|
||||
|
||||
SET_SOURCE_FILES_PROPERTIES(../../swig/yap.i PROPERTIES CPLUSPLUS ON)
|
||||
SET_SOURCE_FILES_PROPERTIES(../../swig/yap.i PROPERTIES SWIG_FLAGS "-O;-py3")
|
||||
SET_SOURCE_FILES_PROPERTIES(../../swiyap.i PROPERTIES SWIG_MODULE_NAME yap4py.yap)
|
||||
SET_SOURCE_FILES_PROPERTIES(../../swig/yap.i PROPERTIES SWIG_MODULE_NAME yap4py.yap)
|
||||
#SET_SOURCE_FILES_PROPERTIES(../../swi/yap.i PROPERTIES OUTPUT_NAME yap)
|
||||
|
||||
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/yap4py)
|
||||
|
||||
set(YAP4PY_PL prolog/yapi.yap)
|
||||
set(YAP4PY_PY yap4py/__init__.py yap4py/__main__.py yap4py/yapi.py)
|
||||
set(YAP4PY_PY yap4py/__main__.py yap4py/yapi.py)
|
||||
|
||||
configure_file("setup.py.in" setup.py)
|
||||
configure_file("MANIFEST.in" ${CMAKE_CURRENT_BINARY_DIR}/MANIFEST.in)
|
||||
@@ -51,7 +51,7 @@ else()
|
||||
endif()
|
||||
|
||||
add_custom_target( YAP4PY ALL
|
||||
COMMAND ${SWIG_EXECUTABLE} -c++ -python -O -py3 -module "yap" -addextern -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/H/generated -I${CMAKE_SOURCE_DIR}/include
|
||||
COMMAND ${SWIG_EXECUTABLE} -c++ -python -O -py3 -module "yap" -addextern -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/H/generated -I${CMAKE_SOURCE_DIR}/include
|
||||
-I${CMAKE_SOURCE_DIR}/OPTYap -I${CMAKE_SOURCE_DIR}/os -I${CMAKE_SOURCE_DIR}/utf8proc -I.././.. -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/packages/python
|
||||
-outdir ${CMAKE_CURRENT_BINARY_DIR}/yap4py -I${GMP_INCLUDE_DIRS} -DX_API="" -o ${CMAKE_CURRENT_BINARY_DIR}/yap4py/yap_wrap.cxx -oh ${CMAKE_CURRENT_BINARY_DIR}/yap4py/yap_wrap.hh ${SWIG_SOURCES}
|
||||
COMMAND ${PYTHON_EXECUTABLE} setup.py sdist ${bdist}
|
||||
|
@@ -10,9 +10,8 @@
|
||||
python_query/2,
|
||||
yapi_query/2
|
||||
]).
|
||||
:- stop_low_level_trace.
|
||||
|
||||
:- yap_flag(verbose, verbose).
|
||||
:- yap_flag(verbose, silent).
|
||||
|
||||
|
||||
:- use_module( library(lists) ).
|
||||
@@ -22,6 +21,7 @@
|
||||
:- reexport( library(python) ).
|
||||
|
||||
:- python_import(yap4py.yapi).
|
||||
:- python_import(gc).
|
||||
|
||||
%:- start_low_level_trace.
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
%:- initialization set_preds.
|
||||
|
||||
set_preds :-
|
||||
fail,
|
||||
current_predicate(P, Q),
|
||||
functor(Q,P,A),
|
||||
atom_string(P,S),
|
||||
@@ -47,6 +48,7 @@ set_preds :-
|
||||
fail),
|
||||
fail.
|
||||
set_preds :-
|
||||
fail,
|
||||
system_predicate(P/A),
|
||||
atom_string(P,S),
|
||||
catch(
|
||||
@@ -61,14 +63,15 @@ argi(N,I,I1) :-
|
||||
I1 is I+1.
|
||||
|
||||
python_query( Caller, String ) :-
|
||||
Self := Caller.it,
|
||||
atomic_to_term( String, Goal, VarNames ),
|
||||
query_to_answer( Goal, VarNames, Status, Bindings),
|
||||
Self.port := Status,
|
||||
Caller.port := Status,
|
||||
% := print( gc.get_referrers(Caller.port)),
|
||||
write_query_answer( Bindings ),
|
||||
nl(user_error),
|
||||
Self.bindings := {},
|
||||
maplist(in_dict(Self.bindings), Bindings).
|
||||
Caller.answer := {},
|
||||
maplist(in_dict(Caller.answer), Bindings).
|
||||
% := print( "b", gc.get_referrers(Caller.answer)).
|
||||
|
||||
in_dict(Dict, var([V0,V|Vs])) :- !,
|
||||
Dict[V] := V0,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#!/usr/bin/env python
|
||||
#!/usr/bin/env python
|
||||
# coding: utf-8
|
||||
|
||||
# Copyright (c) IPython Development Team.
|
||||
@@ -51,24 +51,25 @@ from distutils.core import setup
|
||||
|
||||
here = abspath(dirname(__file__))
|
||||
libpydir = abspath(sysconfig.get_path('platlib'))
|
||||
libpyauxdir = abspath(os.path.dirname('stdlib'))
|
||||
#libpyauxdir = abspath(os.path.dirname('stdlib'))
|
||||
#pkg_root = join(here, name)
|
||||
|
||||
here = path.abspath(path.dirname(__file__))
|
||||
|
||||
sys.path.insert(0, "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
|
||||
python_libdir = path.abspath(path.dirname("${PYTHON_LIBRARIES}"))
|
||||
|
||||
if platform.system() == 'Windows':
|
||||
local_libs = []
|
||||
win_libs = ['wsock32','ws2_32']
|
||||
my_extra_link_args = ['-Wl,-export-all-symbols']
|
||||
elif platform.system() == 'Darwin':
|
||||
my_extra_link_args = ['-L','..','-Wl,-rpath','-Wl,${CMAKE_INSTALL_FULL_LIBDIR}']
|
||||
my_extra_link_args = ['-L','..','-Wl,-rpath,'+abspath(join(sysconfig.get_path('platlib'),'yap4py')),'-Wl,-rpath,${CMAKE_INSTALL_FULL_LIBDIR}','-Wl,-rpath,../yap4py']
|
||||
win_libs = []
|
||||
local_libs = ['Py4YAP']
|
||||
elif platform.system() == 'Linux':
|
||||
my_extra_link_args = ['-L','..','-Wl,-rpath','-Wl,${CMAKE_INSTALL_FULL_LIBDIR}']
|
||||
my_extra_link_args = ['-L','..','-Wl,-rpath,'+abspath(join(sysconfig.get_path('platlib'),'yap4py')),'-Wl,-rpath,${CMAKE_INSTALL_FULL_LIBDIR}','-Wl,-rpath,../yap4py']
|
||||
win_libs = []
|
||||
local_libs = ['Py4YAP']
|
||||
|
||||
@@ -78,22 +79,21 @@ elif platform.system() == 'Linux':
|
||||
native_sources = ["yap4py/yap_wrap.cxx","yap4py/yapi.cpp"]
|
||||
|
||||
#gmp_dir = path.abspath(path.dirname("${GMP_LIBRARIES}"))
|
||||
#python_libdir = path.abspath(path.dirname("${PYTHON_LIBRARIES}")
|
||||
# Get the long description from the README file
|
||||
|
||||
|
||||
|
||||
extensions = [Extension('yap4py._yap', native_sources,
|
||||
extensions = [Extension('_yap', native_sources,
|
||||
define_macros=[('MAJOR_VERSION', '1'),
|
||||
('MINOR_VERSION', '0'),
|
||||
('_YAP_NOT_INSTALLED_', '1'),
|
||||
('YAP_PYTHON', '1'),
|
||||
('_GNU_SOURCE', '1')],
|
||||
runtime_library_dirs=[abspath(sysconfig.get_path('platlib')),
|
||||
abspath(sysconfig.get_path('platlib'))],
|
||||
runtime_library_dirs=[
|
||||
abspath(join(sysconfig.get_path('platlib'),'yap4py')), abspath(sysconfig.get_path('platlib')),'${CMAKE_INSTALL_FULL_LIBDIR}'],
|
||||
swig_opts=['-modern', '-c++', '-py3',
|
||||
'-DX_API', '-Iyap4py/include' ],
|
||||
library_dirs=[".",'../../..'],
|
||||
library_dirs=[".",'../../..','${CMAKE_INSTALL_FULL_LIBDIR}'],
|
||||
extra_link_args=my_extra_link_args,
|
||||
libraries=['Yap','gmp']+win_libs+local_libs,
|
||||
include_dirs=['${CMAKE_SOURCE_DIR}/H',
|
||||
@@ -122,7 +122,7 @@ setup_args = dict(
|
||||
scripts=glob(join('scripts', '*')),
|
||||
packages=['yap4py'],
|
||||
ext_modules=extensions,
|
||||
py_modules=[],
|
||||
sources=['yap4py/yapi.py','yap4py/yap.py','yap4py/__main__.py','yap4py/__init_.py'],
|
||||
# package_data=package_data,
|
||||
include_package_data=True,
|
||||
data_files = data_files,
|
||||
|
@@ -16,15 +16,18 @@ if platform.system() == 'Windows':
|
||||
ctypes.WinDLL(dll)
|
||||
elif platform.system() == 'Darwin':
|
||||
def load( dll ):
|
||||
dll = glob.glob(os.path.join(os.path.realpath(__file__),dll))[0]
|
||||
dll = glob.glob(os.path.join(os.path.dirname(__file__),dll))[0]
|
||||
dll = os.path.abspath(dll)
|
||||
ctypes.CDLL(dll)
|
||||
# load('libYap.dylib')
|
||||
# load('libPy4YAP.dylib')
|
||||
#load( '_yap*.dylib' )
|
||||
print('loaded ',dll)
|
||||
|
||||
# try:
|
||||
# load( '_yap*.so' )
|
||||
# except:
|
||||
# load( '_yap*.dylib' )
|
||||
else:
|
||||
def load( dll ):
|
||||
dll = glob.glob(os.path.join(os.path.realpath(__file__),dll))[0]
|
||||
dll = glob.glob(os.path.join(os.path.dirname(__file__),dll))[0]
|
||||
dll = os.path.abspath(dll)
|
||||
ctypes.CDLL(dll)
|
||||
# \`load('_yap*.so')
|
||||
load('_yap*.so')
|
||||
|
@@ -47,24 +47,21 @@ class Predicate( YAPPredicate ):
|
||||
def __init__(self, t, module=None):
|
||||
super().__init__(t)
|
||||
|
||||
class Goal(object):
|
||||
class IQuery(YAPQuery):
|
||||
"""Goal is a predicate instantiated under a specific environment """
|
||||
def __init__(self, engine, g):
|
||||
self.q = engine.query(g)
|
||||
self.e = engine
|
||||
self = engine.query(g)
|
||||
self.port = "call"
|
||||
self.bindings = None
|
||||
|
||||
def __iter__(self):
|
||||
return PrologTableIter( self.e, self )
|
||||
return PrologTableIter( self )
|
||||
|
||||
class PrologTableIter:
|
||||
|
||||
def __init__(self, e, g):
|
||||
def __init__(self, q):
|
||||
try:
|
||||
self.e = e
|
||||
self.g = g
|
||||
self.q = g.q
|
||||
self.q = q
|
||||
except:
|
||||
print('Error')
|
||||
|
||||
@@ -77,9 +74,9 @@ class PrologTableIter:
|
||||
if not self.q:
|
||||
raise StopIteration()
|
||||
if self.q.next():
|
||||
rc = self.g.bindings
|
||||
if self.g.port == "exit":
|
||||
self.close()
|
||||
rc = self.q.bindings
|
||||
if self.q.port == "exit":
|
||||
self.q.close()
|
||||
return rc
|
||||
else:
|
||||
if self.q:
|
||||
@@ -179,7 +176,7 @@ class YAPShell:
|
||||
bindings = []
|
||||
g = python_query(self, query)
|
||||
if not self.q:
|
||||
self.it = Goal( engine, g )
|
||||
self.it = IQuery( engine, g )
|
||||
for bind in self.it:
|
||||
bindings += [bind]
|
||||
if do_ask:
|
||||
|
Reference in New Issue
Block a user