dynamic loading
This commit is contained in:
@@ -6,8 +6,8 @@ import os.path
|
||||
import platform
|
||||
import sys
|
||||
|
||||
global yap_lib_path
|
||||
yap_lib_path = os.path.dirname(__file__)
|
||||
# global yap_lib_path
|
||||
#yap_lib_path = os.path.dirname(__file__)
|
||||
|
||||
if platform.system() == 'Windows':
|
||||
def load( dll ):
|
||||
@@ -15,10 +15,10 @@ if platform.system() == 'Windows':
|
||||
dll = os.path.abspath(dll)
|
||||
ctypes.WinDLL(dll)
|
||||
load('libYap*')
|
||||
else:
|
||||
def load( dll ):
|
||||
dll = glob.glob(os.path.join(yap_lib_path,dll))[0]
|
||||
dll = os.path.abspath(dll)
|
||||
ctypes.CDLL(dll, mode=ctypes.RTLD_GLOBAL)
|
||||
# else:
|
||||
# def load( dll ):
|
||||
# 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('libPy4YAP*')
|
||||
|
@@ -6,18 +6,20 @@ import keyword
|
||||
# import pdb
|
||||
from collections import namedtuple
|
||||
|
||||
from yap import *
|
||||
from .yap import *
|
||||
|
||||
|
||||
class Engine( YAPEngine ):
|
||||
def __init__(self, args=None,**kwargs):
|
||||
# type: (object) -> object
|
||||
self.contained = False
|
||||
if not args:
|
||||
args = EngineArgs(**kwargs)
|
||||
yap_lib_path = os.path.dirname(__file__)
|
||||
args.setYapShareDir(os.path.join(yap_lib_path,"prolog"))
|
||||
args.setYapLibDir(yap_lib_path)
|
||||
args.setSavedState(os.path.join(yap_lib_path,"startup.yss"))
|
||||
if self.contained:
|
||||
yap_lib_path = os.path.dirname(__file__)
|
||||
args.setYapShareDir(os.path.join(yap_lib_path,"prolog"))
|
||||
args.setYapLibDir(yap_lib_path)
|
||||
args.setSavedState(os.path.join(yap_lib_path,"startup.yss"))
|
||||
YAPEngine.__init__(self,args)
|
||||
self.goal( set_prolog_flag('verbose', 'silent' ) )
|
||||
self.goal( use_module(library('yapi') ) )
|
||||
@@ -84,19 +86,10 @@ class PrologTableIter:
|
||||
self.q = None
|
||||
raise StopIteration()
|
||||
|
||||
f2p = []
|
||||
f2p = {"fails":{}}
|
||||
for i in range(16):
|
||||
f2p += [{}]
|
||||
f2p[i] ={}
|
||||
|
||||
def named( name, arity):
|
||||
if arity > 0 and name.isidentifier() and not keyword.iskeyword(name):
|
||||
s = []
|
||||
for i in range(arity):
|
||||
s += ["A" + str(i)]
|
||||
f2p[arity][name] = namedtuple(name, s)
|
||||
|
||||
class PrologPredicate( YAPPrologPredicate ):
|
||||
""" Interface to Prolog Predicate"""
|
||||
|
||||
|
||||
|
||||
@@ -115,6 +108,20 @@ yapi_query = namedtuple( 'yapi_query', 'vars dict')
|
||||
show_answer = namedtuple( 'show_answer', 'vars dict')
|
||||
set_prolog_flag = namedtuple('set_prolog_flag', 'flag new_value')
|
||||
|
||||
|
||||
def named( name, arity):
|
||||
try:
|
||||
if arity > 0 and name.isidentifier() and not keyword.iskeyword(name):
|
||||
s = []
|
||||
for i in range(arity):
|
||||
s += ["A" + str(i)]
|
||||
f2p[arity][name] = namedtuple(name, s)
|
||||
except:
|
||||
f2p[fails][name] = True
|
||||
|
||||
class PrologPredicate( YAPPrologPredicate ):
|
||||
""" Interface to Prolog Predicate"""
|
||||
|
||||
class v(YAPVarTerm):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
Reference in New Issue
Block a user