This commit is contained in:
commit
a115024aee
3
.gitignore
vendored
3
.gitignore
vendored
@ -213,3 +213,6 @@ cmake/compile_commands.json
|
|||||||
cmake/cudd_config.h
|
cmake/cudd_config.h
|
||||||
|
|
||||||
cmake/docs/Doxyfile
|
cmake/docs/Doxyfile
|
||||||
|
|
||||||
|
*.stackdump
|
||||||
|
*.gz
|
1
C/save.c
1
C/save.c
@ -1430,6 +1430,7 @@ OpenRestore(const char *inpf, const char *YapLibDir, CELL *Astate, CELL *ATrail,
|
|||||||
return FAIL_RESTORE;
|
return FAIL_RESTORE;
|
||||||
if (fname[0] &&
|
if (fname[0] &&
|
||||||
(mode = try_open(fname,Astate,ATrail,AStack,AHeap,streamp)) != FAIL_RESTORE) {
|
(mode = try_open(fname,Astate,ATrail,AStack,AHeap,streamp)) != FAIL_RESTORE) {
|
||||||
|
setAtomicGlobalPrologFlag( RESOURCE_DATABASE_FLAG, MkAtomTerm(Yap_LookupAtom(fname)) );
|
||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
/* try to open from current directory */
|
/* try to open from current directory */
|
||||||
|
@ -871,7 +871,7 @@ static int num_send_error_message(char s[]) {
|
|||||||
|
|
||||||
#define number_overflow() \
|
#define number_overflow() \
|
||||||
{ \
|
{ \
|
||||||
size_t nsz = min(max_size * 2, max_size); \
|
size_t nsz = Yap_Min(max_size * 2, max_size); \
|
||||||
char *nbuf; \
|
char *nbuf; \
|
||||||
\
|
\
|
||||||
if (buf == buf0) { \
|
if (buf == buf0) { \
|
||||||
@ -1408,7 +1408,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
for (; chtype(ch) <= NU; ch = getchr(inp_stream)) {
|
for (; chtype(ch) <= NU; ch = getchr(inp_stream)) {
|
||||||
if (charp == TokImage + (sz - 1)) {
|
if (charp == TokImage + (sz - 1)) {
|
||||||
unsigned char *p0 = TokImage;
|
unsigned char *p0 = TokImage;
|
||||||
sz = min(sz * 2, sz + MBYTE);
|
sz = Yap_Min(sz * 2, sz + MBYTE);
|
||||||
TokImage = Realloc(p0, sz);
|
TokImage = Realloc(p0, sz);
|
||||||
if (TokImage == NULL) {
|
if (TokImage == NULL) {
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
@ -1562,7 +1562,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
if (charp > TokImage + (sz - 1)) {
|
if (charp > TokImage + (sz - 1)) {
|
||||||
TokImage = Realloc(TokImage, min(sz * 2, sz + MBYTE));
|
TokImage = Realloc(TokImage, Yap_Min(sz * 2, sz + MBYTE));
|
||||||
if (TokImage == NULL) {
|
if (TokImage == NULL) {
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
}
|
}
|
||||||
@ -1737,7 +1737,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
add_ch_to_buff(och);
|
add_ch_to_buff(och);
|
||||||
for (; chtype(ch) == SY; ch = getchr(inp_stream)) {
|
for (; chtype(ch) == SY; ch = getchr(inp_stream)) {
|
||||||
if (charp >= TokImage + (sz - 10)) {
|
if (charp >= TokImage + (sz - 10)) {
|
||||||
sz = min(sz * 2, sz + MBYTE);
|
sz = Yap_Min(sz * 2, sz + MBYTE);
|
||||||
TokImage = Realloc(TokImage, sz);
|
TokImage = Realloc(TokImage, sz);
|
||||||
if (!TokImage)
|
if (!TokImage)
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
|
@ -92,9 +92,12 @@ endif()
|
|||||||
|
|
||||||
OPTION (WITH_SWIG " Enable SWIG interfaces to foreign languages" ON)
|
OPTION (WITH_SWIG " Enable SWIG interfaces to foreign languages" ON)
|
||||||
|
|
||||||
IF (WITH_SWIG)
|
IF (WITH_SWIG OR ANDROID)
|
||||||
find_host_package (SWIG)
|
find_host_package (SWIG)
|
||||||
ENDIF (WITH_SWIG)
|
macro_log_feature (SWIG_FOUND "Swig"
|
||||||
|
"Use SWIG Interface Generator "
|
||||||
|
"http://www.swig.org" ON)
|
||||||
|
ENDIF (WITH_SWIG OR ANDROID)
|
||||||
|
|
||||||
option (WITH_PYTHON
|
option (WITH_PYTHON
|
||||||
"Allow Python->YAP and YAP->Python" ON)
|
"Allow Python->YAP and YAP->Python" ON)
|
||||||
@ -104,37 +107,20 @@ IF (WITH_PYTHON)
|
|||||||
ENDIF (WITH_PYTHON)
|
ENDIF (WITH_PYTHON)
|
||||||
|
|
||||||
|
|
||||||
IF (SWIG_FOUND)
|
|
||||||
add_subDIRECTORY (packages/swig NO_POLICY_SCOPE)
|
|
||||||
ENDIF(SWIG_FOUND)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (ANDROID)
|
|
||||||
|
|
||||||
ADD_SUBDIRECTORY(os)
|
|
||||||
ADD_SUBDIRECTORY(OPTYap)
|
|
||||||
ADD_SUBDIRECTORY(packages/myddas)
|
|
||||||
ADD_SUBDIRECTORY(utf8proc)
|
|
||||||
ADD_SUBDIRECTORY(CXX)
|
|
||||||
|
|
||||||
|
|
||||||
else()
|
|
||||||
|
|
||||||
List (APPEND YLIBS $<TARGET_OBJECTS:libOPTYap> )
|
List (APPEND YLIBS $<TARGET_OBJECTS:libOPTYap> )
|
||||||
List (APPEND YLIBS $<TARGET_OBJECTS:libYAPOs> )
|
List (APPEND YLIBS $<TARGET_OBJECTS:libYAPOs> )
|
||||||
List (APPEND YLIBS $<TARGET_OBJECTS:utf8proc> )
|
List (APPEND YLIBS $<TARGET_OBJECTS:utf8proc> )
|
||||||
List (APPEND YLIBS $<TARGET_OBJECTS:myddas> )
|
List (APPEND YLIBS $<TARGET_OBJECTS:myddas> )
|
||||||
List (APPEND YLIBS $<TARGET_OBJECTS:Yapsqlite3> )
|
|
||||||
List (APPEND YLIBS $<TARGET_OBJECTS:libswi> )
|
List (APPEND YLIBS $<TARGET_OBJECTS:libswi> )
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
List (APPEND YLIBS $<TARGET_OBJECTS:Yapsqlite3> )
|
||||||
List (APPEND YLIBS $<TARGET_OBJECTS:YAP++> )
|
List (APPEND YLIBS $<TARGET_OBJECTS:YAP++> )
|
||||||
if (WITH_PYTHON )
|
if (WITH_PYTHON )
|
||||||
List (APPEND YLIBS $<TARGET_OBJECTS:Py4YAP> )
|
List (APPEND YLIBS $<TARGET_OBJECTS:Py4YAP> )
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -165,8 +151,6 @@ if (USE_READLINE)
|
|||||||
endif (USE_READLINE)
|
endif (USE_READLINE)
|
||||||
|
|
||||||
if (ANDROID)
|
if (ANDROID)
|
||||||
add_dependencies(libYap plmyddas )
|
|
||||||
|
|
||||||
target_link_libraries(libYap android log)
|
target_link_libraries(libYap android log)
|
||||||
|
|
||||||
endif ()
|
endif ()
|
||||||
@ -190,6 +174,11 @@ if (PYTHONLIBS_FOUND AND SWIG_FOUND)
|
|||||||
ENDIF()
|
ENDIF()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
IF (SWIG_FOUND OR ANDROID)
|
||||||
|
add_subDIRECTORY (packages/swig NO_POLICY_SCOPE)
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
include(Config NO_POLICY_SCOPE)
|
include(Config NO_POLICY_SCOPE)
|
||||||
|
|
||||||
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES
|
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES
|
||||||
|
106
CXX/yapi.cpp
106
CXX/yapi.cpp
@ -27,6 +27,8 @@ X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static YAPEngine *curren;
|
||||||
|
|
||||||
YAPAtomTerm::YAPAtomTerm(char *s)
|
YAPAtomTerm::YAPAtomTerm(char *s)
|
||||||
{ // build string
|
{ // build string
|
||||||
BACKUP_H();
|
BACKUP_H();
|
||||||
@ -187,6 +189,7 @@ YAPApplTerm::YAPApplTerm(std::string f, std::vector<YAPTerm> ts)
|
|||||||
mk(o);
|
mk(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
YAPApplTerm::YAPApplTerm(YAPFunctor f) : YAPTerm()
|
YAPApplTerm::YAPApplTerm(YAPFunctor f) : YAPTerm()
|
||||||
{
|
{
|
||||||
BACKUP_H();
|
BACKUP_H();
|
||||||
@ -649,19 +652,19 @@ YAPQuery::YAPQuery(YAPFunctor f, YAPTerm mod, YAPTerm ts[])
|
|||||||
/* ignore flags for now */
|
/* ignore flags for now */
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
Term *nts;
|
Term *nts;
|
||||||
Term goal;
|
Term tgoal;
|
||||||
|
|
||||||
if ( ts) {
|
if ( ts) {
|
||||||
|
|
||||||
goal = YAPApplTerm(f, ts).term();
|
goal = new YAPApplTerm(f, ts);
|
||||||
nts = RepAppl(goal)+1;
|
nts = RepAppl(goal->term())+1;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
goal = MkVarTerm();
|
goal = new YAPVarTerm();
|
||||||
nts = nullptr;
|
nts = nullptr;
|
||||||
}
|
}
|
||||||
openQuery( nts);
|
openQuery(goal->term(), nts);
|
||||||
names = YAPPairTerm( TermNil );
|
names = new YAPPairTerm();
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -671,13 +674,14 @@ YAPQuery::YAPQuery(YAPFunctor f, YAPTerm ts[]) : YAPPredicate(f) {
|
|||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
CELL *nts;
|
CELL *nts;
|
||||||
if (ts) {
|
if (ts) {
|
||||||
goal = YAPApplTerm(f, nts);
|
tgoal = YAPApplTerm(f, nts);
|
||||||
} else {
|
} else {
|
||||||
goal = YAPVarTerm();
|
tgoal = YAPVarTerm();
|
||||||
nts = nullptr;
|
nts = nullptr;
|
||||||
}
|
}
|
||||||
names = YAPPairTerm( TermNil );
|
*names = new YAPPairTerm();
|
||||||
openQuery(term(), nts);
|
*goal = new YAPTerm(tgoal);
|
||||||
|
openQuery(goal.term(), nts);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -692,14 +696,14 @@ YAPQuery::YAPQuery(YAPTerm t) : YAPPredicate(t)
|
|||||||
Functor f = FunctorOfTerm(tt);
|
Functor f = FunctorOfTerm(tt);
|
||||||
if (IsExtensionFunctor(f))
|
if (IsExtensionFunctor(f))
|
||||||
nts = nullptr;
|
nts = nullptr;
|
||||||
nts = RepAppl(goal.term())+1;
|
nts = RepAppl(tt)+1;
|
||||||
} else if (IsPairTerm(tt)) {
|
} else if (IsPairTerm(tt)) {
|
||||||
nts = RepPair(tt);
|
nts = RepPair(tt);
|
||||||
} else {
|
} else {
|
||||||
nts = nullptr;
|
nts = nullptr;
|
||||||
}
|
}
|
||||||
openQuery( nts);
|
names = new YAPPairTerm();
|
||||||
names = YAPPairTerm( TermNil );
|
goal = new YAPTerm(t);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -708,15 +712,14 @@ YAPQuery::YAPQuery(YAPPredicate p, YAPTerm ts[]) : YAPPredicate(p.ap) {
|
|||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
arity_t arity = p.ap->ArityOfPE;
|
arity_t arity = p.ap->ArityOfPE;
|
||||||
if (arity) {
|
if (arity) {
|
||||||
goal = YAPApplTerm(YAPFunctor(p.ap->FunctorOfPred), ts).term();
|
goal = new YAPApplTerm(YAPFunctor(p.ap->FunctorOfPred), ts);
|
||||||
for (arity_t i =0; i < arity; i++)
|
for (arity_t i =0; i < arity; i++) {
|
||||||
XREGS[i+1]=ts[i].term();
|
XREGS[i + 1] = ts[i].term();
|
||||||
openQuery( nullptr);
|
|
||||||
} else {
|
|
||||||
goal = YAPAtomTerm((Atom)(p.ap->FunctorOfPred));
|
|
||||||
openQuery(nullptr);
|
|
||||||
}
|
}
|
||||||
names = TermNil;
|
} else {
|
||||||
|
goal = new YAPAtomTerm((Atom)(p.ap->FunctorOfPred)); }
|
||||||
|
openQuery(goal->term(), nullptr);
|
||||||
|
names = new YAPPairTerm();
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -726,13 +729,21 @@ bool YAPQuery::next()
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
sigjmp_buf buf, *oldp = LOCAL_RestartEnv;
|
sigjmp_buf buf, *oldp = LOCAL_RestartEnv;
|
||||||
Term terr;
|
Term terr;
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "next %d %ld",
|
||||||
|
q_state, LOCAL_CurSlot);
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "next %d %s %ld",
|
||||||
|
q_state, names->text(), LOCAL_CurSlot);
|
||||||
|
|
||||||
|
if (ap == NULL || ap->OpcodeOfPred == UNDEF_OPCODE) {
|
||||||
|
ap = rewriteUndefQuery();
|
||||||
|
}
|
||||||
|
LOCAL_RestartEnv = &q_env;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
if (!q_open)
|
if (!q_open)
|
||||||
return false;
|
return false;
|
||||||
LOCAL_RestartEnv = &buf;
|
if (false && sigsetjmp(q_env, false))
|
||||||
if (sigsetjmp(*LOCAL_RestartEnv, false))
|
|
||||||
{
|
{
|
||||||
//throw YAPError();
|
//throw YAPError();
|
||||||
return false;
|
return false;
|
||||||
@ -751,8 +762,8 @@ bool YAPQuery::next()
|
|||||||
}
|
}
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %d %s %ld",
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "names %d %s %ld",
|
||||||
q_state, vnames.text(), LOCAL_CurSlot);
|
q_state, names->text(), LOCAL_CurSlot);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -763,7 +774,6 @@ bool YAPQuery::next()
|
|||||||
{
|
{
|
||||||
if ((terr = Yap_GetException()))
|
if ((terr = Yap_GetException()))
|
||||||
{
|
{
|
||||||
LOCAL_RestartEnv = &buf;
|
|
||||||
throw YAPError();
|
throw YAPError();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -792,7 +802,6 @@ bool YAPQuery::next()
|
|||||||
Yap_CloseHandles(q_handles);
|
Yap_CloseHandles(q_handles);
|
||||||
q_open = false;
|
q_open = false;
|
||||||
std::cerr << "Exception received by " << __func__ << "( " << YAPTerm(terr).text() << ").\n Forwarded...\n\n";
|
std::cerr << "Exception received by " << __func__ << "( " << YAPTerm(terr).text() << ").\n Forwarded...\n\n";
|
||||||
LOCAL_RestartEnv = oldp;
|
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -801,10 +810,10 @@ PredEntry *
|
|||||||
YAPQuery::rewriteUndefQuery()
|
YAPQuery::rewriteUndefQuery()
|
||||||
{
|
{
|
||||||
Term ts[3];
|
Term ts[3];
|
||||||
ARG1 = ts[0] = goal.term();
|
ARG1 = ts[0] = goal->term();
|
||||||
ARG2 = ts[1] = ap->ModuleOfPred;
|
ARG2 = ts[1] = ap->ModuleOfPred;
|
||||||
ARG3 = ts[2] = Yap_cp_as_integer(B PASS_REGS);
|
ARG3 = ts[2] = Yap_cp_as_integer(B PASS_REGS);
|
||||||
goal = YAPApplTerm(FunctorUndefinedQuery, ts);
|
goal = new YAPApplTerm(FunctorUndefinedQuery, ts);
|
||||||
return ap = PredUndefinedQuery;
|
return ap = PredUndefinedQuery;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -886,39 +895,6 @@ JNIEXPORT jint JNICALL JNI_MySQLOnLoad(JavaVM *vm, void *reserved)
|
|||||||
return JNI_VERSION_1_6;
|
return JNI_VERSION_1_6;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *Yap_AndroidBufp;
|
|
||||||
|
|
||||||
static size_t Yap_AndroidMax, Yap_AndroidSz;
|
|
||||||
|
|
||||||
extern void (*Yap_DisplayWithJava)(int c);
|
|
||||||
|
|
||||||
void Yap_displayWithJava(int c)
|
|
||||||
{
|
|
||||||
char *ptr = Yap_AndroidBufp;
|
|
||||||
if (!ptr)
|
|
||||||
ptr = Yap_AndroidBufp = (char *)malloc(Yap_AndroidSz);
|
|
||||||
ptr[Yap_AndroidSz++] = c;
|
|
||||||
if (Yap_AndroidMax - 1 == Yap_AndroidSz)
|
|
||||||
{
|
|
||||||
if (Yap_AndroidMax < 32 * 1024)
|
|
||||||
{
|
|
||||||
Yap_AndroidMax *= 2;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Yap_AndroidMax += 32 * 1024;
|
|
||||||
}
|
|
||||||
Yap_AndroidBufp = (char *)realloc(ptr, Yap_AndroidMax);
|
|
||||||
}
|
|
||||||
Yap_AndroidBufp[Yap_AndroidSz] = '\0';
|
|
||||||
if (c == '\n')
|
|
||||||
{
|
|
||||||
Yap_AndroidBufp[Yap_AndroidSz] = '\0';
|
|
||||||
curren->run(Yap_AndroidBufp);
|
|
||||||
Yap_AndroidSz = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
@ -932,11 +908,7 @@ void YAPEngine::doInit(YAP_file_type_t BootMode)
|
|||||||
/* Begin preprocessor code */
|
/* Begin preprocessor code */
|
||||||
/* live */
|
/* live */
|
||||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "initialize_prolog");
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "initialize_prolog");
|
||||||
#if __ANDROID__
|
curren = this;
|
||||||
Yap_AndroidBufp = (char *)malloc(Yap_AndroidMax = 4096);
|
|
||||||
Yap_AndroidBufp[0] = '\0';
|
|
||||||
Yap_AndroidSz = 0;
|
|
||||||
#endif
|
|
||||||
//yerror = YAPError();
|
//yerror = YAPError();
|
||||||
#if YAP_PYTHON
|
#if YAP_PYTHON
|
||||||
do_init_python();
|
do_init_python();
|
||||||
|
293
CXX/yapq.hh
293
CXX/yapq.hh
@ -9,8 +9,8 @@
|
|||||||
*
|
*
|
||||||
* @{
|
* @{
|
||||||
*
|
*
|
||||||
* These classes wrap engine and query. An engine is an environment where we can rum
|
* These classes wrap engine and query. An engine is an environment where we
|
||||||
* Prolog, that is, where we can run queries.
|
* can rum Prolog, that is, where we can run queries.
|
||||||
*
|
*
|
||||||
* Also, supports callbacks and engine configuration.
|
* Also, supports callbacks and engine configuration.
|
||||||
*
|
*
|
||||||
@ -31,8 +31,7 @@ class X_API YAPPredicate;
|
|||||||
* interface to a YAP Query;
|
* interface to a YAP Query;
|
||||||
* uses an SWI-like status info internally.
|
* uses an SWI-like status info internally.
|
||||||
*/
|
*/
|
||||||
class X_API YAPQuery : public YAPPredicate
|
class X_API YAPQuery : public YAPPredicate {
|
||||||
{
|
|
||||||
bool q_open;
|
bool q_open;
|
||||||
int q_state;
|
int q_state;
|
||||||
yhandle_t q_g, q_handles;
|
yhandle_t q_g, q_handles;
|
||||||
@ -41,10 +40,10 @@ class X_API YAPQuery : public YAPPredicate
|
|||||||
int q_flags;
|
int q_flags;
|
||||||
YAP_dogoalinfo q_h;
|
YAP_dogoalinfo q_h;
|
||||||
YAPQuery *oq;
|
YAPQuery *oq;
|
||||||
YAPPairTerm names;
|
YAPPairTerm *names;
|
||||||
YAPTerm goal;
|
YAPTerm *goal;
|
||||||
// temporaries
|
// temporaries
|
||||||
Term tnames, tgoal ;
|
Term tnames, tgoal;
|
||||||
|
|
||||||
inline void setNext() { // oq = LOCAL_execution;
|
inline void setNext() { // oq = LOCAL_execution;
|
||||||
// LOCAL_execution = this;
|
// LOCAL_execution = this;
|
||||||
@ -55,19 +54,20 @@ class X_API YAPQuery : public YAPPredicate
|
|||||||
q_p = P;
|
q_p = P;
|
||||||
q_cp = CP;
|
q_cp = CP;
|
||||||
// make sure this is safe
|
// make sure this is safe
|
||||||
|
names = new YAPPairTerm();
|
||||||
|
goal = new YAPTerm();
|
||||||
q_handles = LOCAL_CurSlot;
|
q_handles = LOCAL_CurSlot;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void openQuery(Term *ts);
|
||||||
|
|
||||||
void openQuery( Term *ts);
|
PredEntry *rewriteUndefQuery();
|
||||||
|
|
||||||
PredEntry *rewriteUndefQuery();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
YAPQuery() {
|
YAPQuery() {
|
||||||
goal = TermTrue;
|
goal = TermTrue;
|
||||||
openQuery( nullptr);
|
openQuery(nullptr);
|
||||||
};
|
};
|
||||||
/// main constructor, uses a predicate and an array of terms
|
/// main constructor, uses a predicate and an array of terms
|
||||||
///
|
///
|
||||||
/// It is given a YAPPredicate _p_ , and an array of terms that must have at
|
/// It is given a YAPPredicate _p_ , and an array of terms that must have at
|
||||||
@ -85,32 +85,29 @@ YAPQuery() {
|
|||||||
///
|
///
|
||||||
/// It is given a functor, and an array of terms that must have at least
|
/// It is given a functor, and an array of terms that must have at least
|
||||||
/// the same arity as the functor. Works within the current module.
|
/// the same arity as the functor. Works within the current module.
|
||||||
//YAPQuery(YAPFunctor f, YAPTerm t[]);
|
// YAPQuery(YAPFunctor f, YAPTerm t[]);
|
||||||
/// string constructor without varnames
|
/// string constructor without varnames
|
||||||
///
|
///
|
||||||
/// It is given a string, calls the parser and obtains a Prolog term that
|
/// It is given a string, calls the parser and obtains a Prolog term that
|
||||||
/// should be a callable
|
/// should be a callable
|
||||||
/// goal.
|
/// goal.
|
||||||
inline YAPQuery(const char *s) : YAPPredicate(s, tgoal, tnames)
|
inline YAPQuery(const char *s) : YAPPredicate(s, tgoal, tnames) {
|
||||||
{
|
|
||||||
CELL *qt = nullptr;
|
CELL *qt = nullptr;
|
||||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %ld",
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "got game %ld",
|
||||||
LOCAL_CurSlot);
|
LOCAL_CurSlot);
|
||||||
if (!ap)
|
if (!ap)
|
||||||
return;
|
return;
|
||||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", vnames.text());
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "ŸAPQuery");
|
||||||
goal = YAPTerm(tgoal);
|
|
||||||
if (IsPairTerm(tgoal)) {
|
if (IsPairTerm(tgoal)) {
|
||||||
qt = RepPair(tgoal);
|
qt = RepPair(tgoal);
|
||||||
tgoal = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("consult"), 1),1,qt);
|
tgoal =
|
||||||
|
Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("consult"), 1), 1, qt);
|
||||||
} else if (IsApplTerm(tgoal)) {
|
} else if (IsApplTerm(tgoal)) {
|
||||||
Functor f = FunctorOfTerm(tgoal);
|
Functor f = FunctorOfTerm(tgoal);
|
||||||
if (!IsExtensionFunctor(f)) {
|
if (!IsExtensionFunctor(f)) {
|
||||||
qt = RepAppl(tgoal)+1;
|
qt = RepAppl(tgoal) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
names = YAPPairTerm(tnames);
|
|
||||||
openQuery(qt);
|
|
||||||
};
|
};
|
||||||
// inline YAPQuery() : YAPPredicate(s, tgoal, tnames)
|
// inline YAPQuery() : YAPPredicate(s, tgoal, tnames)
|
||||||
// {
|
// {
|
||||||
@ -118,7 +115,7 @@ YAPQuery() {
|
|||||||
// LOCAL_CurSlot);
|
// LOCAL_CurSlot);
|
||||||
// if (!ap)
|
// if (!ap)
|
||||||
// return;
|
// return;
|
||||||
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", vnames.text());
|
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", names->text());
|
||||||
// goal = YAPTerm(tgoal);
|
// goal = YAPTerm(tgoal);
|
||||||
// names = YAPPairTerm(tnames);
|
// names = YAPPairTerm(tnames);
|
||||||
// openQuery(tgoal);
|
// openQuery(tgoal);
|
||||||
@ -131,40 +128,37 @@ YAPQuery() {
|
|||||||
/// set flags for query execution, currently only for exception handling
|
/// set flags for query execution, currently only for exception handling
|
||||||
void setFlag(int flag) { q_flags |= flag; }
|
void setFlag(int flag) { q_flags |= flag; }
|
||||||
/// reset flags for query execution, currently only for exception handling
|
/// reset flags for query execution, currently only for exception handling
|
||||||
void resetFlag(int flag) { q_flags &= ~flag; }
|
void resetFlag(int flag) { q_flags &= ~flag; }
|
||||||
/// first query
|
/// first query
|
||||||
///
|
///
|
||||||
/// actually implemented by calling the next();
|
/// actually implemented by calling the next();
|
||||||
inline bool first() { return next(); }
|
inline bool first() { return next(); }
|
||||||
/// ask for the next solution of the current query
|
/// ask for the next solution of the current query
|
||||||
/// same call for every solution
|
/// same call for every solution
|
||||||
bool next();
|
bool next();
|
||||||
/// does this query have open choice-points?
|
/// does this query have open choice-points?
|
||||||
/// or is it deterministic?
|
/// or is it deterministic?
|
||||||
bool deterministic();
|
bool deterministic();
|
||||||
/// represent the top-goal
|
/// represent the top-goal
|
||||||
const char *text();
|
const char *text();
|
||||||
/// remove alternatives in the current search space, and finish the current
|
/// remove alternatives in the current search space, and finish tnamedyaphe
|
||||||
/// query
|
/// current query finish the current query: undo all bindings.
|
||||||
/// finish the current query: undo all bindings.
|
void close();
|
||||||
void close();
|
/// query variables.
|
||||||
/// query variables.
|
void cut();
|
||||||
void cut();
|
|
||||||
Term namedVars() {return names.term(); };
|
Term namedVars() { return names->term(); };
|
||||||
/// query variables, but copied out
|
YAPPairTerm *namedYAPVars() { return names; };
|
||||||
std::vector<Term> namedVarsVector() {
|
/// query variables, but copied out
|
||||||
return names.listToArray(); };
|
YAPTerm getTerm(yhandle_t t);
|
||||||
/// convert a ref to a binding.
|
/// simple YAP Query;
|
||||||
YAPTerm getTerm(yhandle_t t);
|
/// just calls YAP and reports success or failure, Useful when we just
|
||||||
/// simple YAP Query;
|
/// want things done, eg YAPCommand("load_files(library(lists), )")
|
||||||
/// just calls YAP and reports success or failure, Useful when we just
|
inline bool command() {
|
||||||
/// want things done, eg YAPCommand("load_files(library(lists), )")
|
|
||||||
inline bool command()
|
|
||||||
{
|
|
||||||
bool rc = next();
|
bool rc = next();
|
||||||
close();
|
close();
|
||||||
return rc;
|
return rc;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
// Java support
|
// Java support
|
||||||
@ -172,170 +166,96 @@ inline bool command()
|
|||||||
/// This class implements a callback Prolog-side. It will be inherited by the
|
/// This class implements a callback Prolog-side. It will be inherited by the
|
||||||
/// Java or Python
|
/// Java or Python
|
||||||
/// class that actually implements the callback.
|
/// class that actually implements the callback.
|
||||||
class X_API YAPCallback
|
class X_API YAPCallback {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
virtual ~YAPCallback() {}
|
virtual ~YAPCallback() {}
|
||||||
virtual void run() { LOG("callback"); }
|
virtual void run() { LOG("callback"); }
|
||||||
virtual void run(char *s) {}
|
virtual void run(char *s) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// @brief Setup all arguments to a new engine
|
/// @brief Setup all arguments to a new engine
|
||||||
class X_API YAPEngineArgs {
|
class X_API YAPEngineArgs {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
YAP_init_args init_args;
|
YAP_init_args init_args;
|
||||||
|
|
||||||
inline void setEmbedded( bool fl )
|
inline void setEmbedded(bool fl) { init_args.Embedded = fl; };
|
||||||
{
|
|
||||||
init_args.Embedded = fl;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool getEmbedded( )
|
inline bool getEmbedded() { return init_args.Embedded; };
|
||||||
{
|
|
||||||
return init_args.Embedded;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline void setStackSize( bool fl )
|
inline void setStackSize(bool fl) { init_args.StackSize = fl; };
|
||||||
{
|
|
||||||
init_args.StackSize = fl;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool getStackSize( )
|
inline bool getStackSize() { return init_args.StackSize; };
|
||||||
{
|
|
||||||
return init_args.StackSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline void setTrailSize( bool fl )
|
inline void setTrailSize(bool fl) { init_args.TrailSize = fl; };
|
||||||
{
|
|
||||||
init_args.TrailSize = fl;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool getTrailSize( )
|
inline bool getTrailSize() { return init_args.TrailSize; };
|
||||||
{
|
|
||||||
return init_args.TrailSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool getMStackSize( )
|
inline bool getMStackSize() { return init_args.StackSize; };
|
||||||
{
|
|
||||||
return init_args.StackSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline void setMaxTrailSize( bool fl )
|
inline void setMaxTrailSize(bool fl) { init_args.MaxTrailSize = fl; };
|
||||||
{
|
|
||||||
init_args.MaxTrailSize = fl;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool getMaxTrailSize( )
|
inline bool getMaxTrailSize() { return init_args.MaxTrailSize; };
|
||||||
{
|
|
||||||
return init_args.MaxTrailSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline void setYapLibDir( const char * fl )
|
inline void setYapLibDir(const char *fl) {
|
||||||
{
|
init_args.YapLibDir = (const char *)malloc(strlen(fl) + 1);
|
||||||
init_args.YapLibDir = (const char *)malloc(strlen(fl)+1);
|
|
||||||
strcpy((char *)init_args.YapLibDir, fl);
|
strcpy((char *)init_args.YapLibDir, fl);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const char * getYapLibDir( )
|
inline const char *getYapLibDir() { return init_args.YapLibDir; };
|
||||||
{
|
|
||||||
return init_args.YapLibDir;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline void setYapShareDir( const char * fl )
|
inline void setYapShareDir(const char *fl) {
|
||||||
{
|
init_args.YapShareDir = (const char *)malloc(strlen(fl) + 1);
|
||||||
init_args.YapShareDir = (const char *)malloc(strlen(fl)+1);
|
|
||||||
strcpy((char *)init_args.YapShareDir, fl);
|
strcpy((char *)init_args.YapShareDir, fl);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const char * getYapShareDir( )
|
inline const char *getYapShareDir() { return init_args.YapShareDir; };
|
||||||
{
|
|
||||||
return init_args.YapShareDir;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline void setSavedState( const char * fl )
|
inline void setSavedState(const char *fl) {
|
||||||
{
|
init_args.SavedState = (const char *)malloc(strlen(fl) + 1);
|
||||||
init_args.SavedState = (const char *)malloc(strlen(fl)+1);
|
|
||||||
strcpy((char *)init_args.SavedState, fl);
|
strcpy((char *)init_args.SavedState, fl);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const char * getSavedState( )
|
inline const char *getSavedState() { return init_args.SavedState; };
|
||||||
{
|
|
||||||
return init_args.SavedState;
|
inline void setYapPrologBootFile(const char *fl) {
|
||||||
|
init_args.YapPrologBootFile = (const char *)malloc(strlen(fl) + 1);
|
||||||
|
strcpy((char *)init_args.YapPrologBootFile, fl);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void setYapPrologBootFile( const char * fl )
|
inline const char *getYapPrologBootFile() {
|
||||||
{
|
|
||||||
init_args.YapPrologBootFile = (const char *)malloc(strlen(fl)+1);
|
|
||||||
strcpy((char *)init_args.YapPrologBootFile, fl);
|
|
||||||
};
|
|
||||||
|
|
||||||
inline const char * getYapPrologBootFile( )
|
|
||||||
{
|
|
||||||
return init_args.YapPrologBootFile;
|
return init_args.YapPrologBootFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void setYapPrologGoal( const char * fl )
|
inline void setYapPrologGoal(const char *fl) {
|
||||||
{
|
|
||||||
init_args.YapPrologGoal = fl;
|
init_args.YapPrologGoal = fl;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const char * getYapPrologGoal( )
|
inline const char *getYapPrologGoal() { return init_args.YapPrologGoal; };
|
||||||
{
|
|
||||||
return init_args.YapPrologGoal;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline void setYapPrologTopLevelGoal( const char * fl )
|
inline void setYapPrologTopLevelGoal(const char *fl) {
|
||||||
{
|
|
||||||
init_args.YapPrologTopLevelGoal = fl;
|
init_args.YapPrologTopLevelGoal = fl;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const char * getYapPrologTopLevelGoal( )
|
inline const char *getYapPrologTopLevelGoal() {
|
||||||
{
|
|
||||||
return init_args.YapPrologTopLevelGoal;
|
return init_args.YapPrologTopLevelGoal;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void setHaltAfterConsult( bool fl )
|
inline void setHaltAfterConsult(bool fl) { init_args.HaltAfterConsult = fl; };
|
||||||
{
|
|
||||||
init_args.HaltAfterConsult = fl;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool getHaltAfterConsult( )
|
inline bool getHaltAfterConsult() { return init_args.HaltAfterConsult; };
|
||||||
{
|
|
||||||
return init_args.HaltAfterConsult;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline void setFastBoot( bool fl )
|
inline void setFastBoot(bool fl) { init_args.FastBoot = fl; };
|
||||||
{
|
|
||||||
init_args.FastBoot = fl;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool getFastBoot( )
|
inline bool getFastBoot() { return init_args.FastBoot; };
|
||||||
{
|
|
||||||
return init_args.FastBoot;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline void setArgc( int fl )
|
inline void setArgc(int fl) { init_args.Argc = fl; };
|
||||||
{
|
|
||||||
init_args.Argc = fl;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline int getArgc( )
|
inline int getArgc() { return init_args.Argc; };
|
||||||
{
|
|
||||||
return init_args.Argc;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline void setArgv( char ** fl )
|
inline void setArgv(char **fl) { init_args.Argv = fl; };
|
||||||
{
|
|
||||||
init_args.Argv = fl;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline char ** getArgv( )
|
inline char **getArgv() { return init_args.Argv; };
|
||||||
{
|
|
||||||
return init_args.Argv;
|
|
||||||
};
|
|
||||||
|
|
||||||
YAPEngineArgs() {
|
YAPEngineArgs() {
|
||||||
Yap_InitDefaults(&init_args, NULL, 0, NULL);
|
Yap_InitDefaults(&init_args, NULL, 0, NULL);
|
||||||
@ -346,15 +266,13 @@ public:
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief YAP Engine: takes care of the execution environment
|
* @brief YAP Engine: takes care of the execution environment
|
||||||
where we can go executing goals.
|
where we can go executing goals.
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class YAPEngine
|
class YAPEngine {
|
||||||
{
|
|
||||||
private:
|
private:
|
||||||
YAPEngineArgs *engine_args;
|
YAPEngineArgs *engine_args;
|
||||||
YAPCallback *_callback;
|
YAPCallback *_callback;
|
||||||
@ -363,12 +281,11 @@ private:
|
|||||||
YAP_dogoalinfo q;
|
YAP_dogoalinfo q;
|
||||||
PredEntry *rewriteUndefEngineQuery(PredEntry *ap, Term t, Term tmod);
|
PredEntry *rewriteUndefEngineQuery(PredEntry *ap, Term t, Term tmod);
|
||||||
|
|
||||||
public :
|
public:
|
||||||
/// construct a new engine; may use a variable number of arguments
|
/// construct a new engine; may use a variable number of arguments
|
||||||
YAPEngine(YAPEngineArgs *cargs)
|
YAPEngine(YAPEngineArgs *cargs) {
|
||||||
{
|
|
||||||
engine_args = cargs;
|
engine_args = cargs;
|
||||||
//doInit(cargs->init_args.boot_file_type);
|
// doInit(cargs->init_args.boot_file_type);
|
||||||
doInit(YAP_QLY);
|
doInit(YAP_QLY);
|
||||||
}; /// construct a new engine, including aaccess to callbacks
|
}; /// construct a new engine, including aaccess to callbacks
|
||||||
/// construct a new engine using argc/argv list of arguments
|
/// construct a new engine using argc/argv list of arguments
|
||||||
@ -379,16 +296,14 @@ private:
|
|||||||
/// remove current callback
|
/// remove current callback
|
||||||
void delYAPCallback() { _callback = 0; };
|
void delYAPCallback() { _callback = 0; };
|
||||||
/// set a new callback
|
/// set a new callback
|
||||||
void setYAPCallback(YAPCallback *cb)
|
void setYAPCallback(YAPCallback *cb) {
|
||||||
{
|
|
||||||
delYAPCallback();
|
delYAPCallback();
|
||||||
_callback = cb;
|
_callback = cb;
|
||||||
};
|
};
|
||||||
/// execute the callback.
|
/// execute the callback.
|
||||||
////void run() { if (_callback) _callback.run(); }
|
////void run() { if (_callback) _callback.run(); }
|
||||||
/// execute the callback with a text argument.
|
/// execute the callback with a text argument.
|
||||||
void run(char *s)
|
void run(char *s) {
|
||||||
{
|
|
||||||
if (_callback)
|
if (_callback)
|
||||||
_callback->run(s);
|
_callback->run(s);
|
||||||
}
|
}
|
||||||
@ -415,25 +330,20 @@ private:
|
|||||||
bool mgoal(Term t, Term tmod);
|
bool mgoal(Term t, Term tmod);
|
||||||
/// current directory for the engine
|
/// current directory for the engine
|
||||||
|
|
||||||
bool goal(Term t)
|
bool goal(Term t) { return mgoal(t, CurrentModule); }
|
||||||
{
|
|
||||||
return mgoal(t, CurrentModule);
|
|
||||||
}
|
|
||||||
/// reset Prolog state
|
/// reset Prolog state
|
||||||
void reSet();
|
void reSet();
|
||||||
/// assune that there are no stack pointers, just release memory
|
/// assune that there are no stack pointers, just release memory
|
||||||
// for last execution
|
// for last execution
|
||||||
void release();
|
void release();
|
||||||
|
|
||||||
const char *currentDir()
|
const char *currentDir() {
|
||||||
{
|
|
||||||
char dir[1024];
|
char dir[1024];
|
||||||
std::string s = Yap_getcwd(dir, 1024 - 1);
|
std::string s = Yap_getcwd(dir, 1024 - 1);
|
||||||
return s.c_str();
|
return s.c_str();
|
||||||
};
|
};
|
||||||
/// report YAP version as a string
|
/// report YAP version as a string
|
||||||
const char *version()
|
const char *version() {
|
||||||
{
|
|
||||||
std::string s = Yap_version();
|
std::string s = Yap_version();
|
||||||
return s.c_str();
|
return s.c_str();
|
||||||
};
|
};
|
||||||
@ -445,16 +355,15 @@ private:
|
|||||||
Term fun(YAPTerm t) { return fun(t.term()); };
|
Term fun(YAPTerm t) { return fun(t.term()); };
|
||||||
//> set a StringFlag, usually a path
|
//> set a StringFlag, usually a path
|
||||||
//>
|
//>
|
||||||
bool setStringFlag(std::string arg, std::string path)
|
bool setStringFlag(std::string arg, std::string path) {
|
||||||
{
|
return setYapFlag(MkAtomTerm(Yap_LookupAtom(arg.data())),
|
||||||
return setYapFlag(MkAtomTerm(Yap_LookupAtom(arg.data())), MkAtomTerm(Yap_LookupAtom(path.data())));
|
MkAtomTerm(Yap_LookupAtom(path.data())));
|
||||||
};
|
};
|
||||||
|
|
||||||
Term top_level( std::string s);
|
Term top_level(std::string s);
|
||||||
Term next_answer(YAPQuery * &Q);
|
Term next_answer(YAPQuery *&Q);
|
||||||
|
};
|
||||||
};
|
|
||||||
|
|
||||||
#endif /* YAPQ_HH */
|
#endif /* YAPQ_HH */
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
|
155
CXX/yapt.hh
155
CXX/yapt.hh
@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
|
||||||
X_API Term YAP_ReadBuffer(const char *s, Term *tp);
|
X_API Term YAP_ReadBuffer(const char *s, Term *tp);
|
||||||
}
|
}
|
||||||
|
|
||||||
class YAPError;
|
class YAPError;
|
||||||
@ -38,11 +38,17 @@ class YAPError;
|
|||||||
*/
|
*/
|
||||||
class X_API YAPTerm {
|
class X_API YAPTerm {
|
||||||
friend class YAPPredicate;
|
friend class YAPPredicate;
|
||||||
|
|
||||||
friend class YAPPrologPredicate;
|
friend class YAPPrologPredicate;
|
||||||
|
|
||||||
friend class YAPQuery;
|
friend class YAPQuery;
|
||||||
|
|
||||||
friend class YAPModule;
|
friend class YAPModule;
|
||||||
|
|
||||||
friend class YAPModuleProp;
|
friend class YAPModuleProp;
|
||||||
|
|
||||||
friend class YAPApplTerm;
|
friend class YAPApplTerm;
|
||||||
|
|
||||||
friend class YAPListTerm;
|
friend class YAPListTerm;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -73,13 +79,16 @@ public:
|
|||||||
// t = Yap_InitSlot(tinp);
|
// t = Yap_InitSlot(tinp);
|
||||||
//}
|
//}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/// private method to convert from Term (internal YAP representation) to
|
/// private method to convert from Term (internal YAP representation) to
|
||||||
/// YAPTerm
|
/// YAPTerm
|
||||||
// do nothing constructor
|
// do nothing constructor
|
||||||
YAPTerm() { t=0; };
|
YAPTerm() { t = 0; };
|
||||||
|
|
||||||
// YAPTerm(yhandle_t i) { t = i; };
|
// YAPTerm(yhandle_t i) { t = i; };
|
||||||
/// pointer to term
|
/// pointer to term
|
||||||
YAPTerm(void *ptr);
|
YAPTerm(void *ptr);
|
||||||
|
|
||||||
/// parse string s and construct a term.
|
/// parse string s and construct a term.
|
||||||
YAPTerm(char *s) {
|
YAPTerm(char *s) {
|
||||||
Term tp;
|
Term tp;
|
||||||
@ -87,6 +96,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if 1
|
#if 1
|
||||||
|
|
||||||
/// Term destructor, tries to recover slot
|
/// Term destructor, tries to recover slot
|
||||||
virtual ~YAPTerm() {
|
virtual ~YAPTerm() {
|
||||||
// fprintf(stderr,"-%d,%lx,%p ",t,LOCAL_HandleBase[t] ,HR);
|
// fprintf(stderr,"-%d,%lx,%p ",t,LOCAL_HandleBase[t] ,HR);
|
||||||
@ -111,18 +121,24 @@ public:
|
|||||||
/// YAPTerm(YAPFunctor f, YAPTerm ts[]);
|
/// YAPTerm(YAPFunctor f, YAPTerm ts[]);
|
||||||
/// extract the tag of a term, after dereferencing.
|
/// extract the tag of a term, after dereferencing.
|
||||||
YAP_tag_t tag();
|
YAP_tag_t tag();
|
||||||
|
|
||||||
/// copy the term ( term copy )
|
/// copy the term ( term copy )
|
||||||
Term deepCopy();
|
Term deepCopy();
|
||||||
|
|
||||||
/// numbervars ( int start, bool process=false )
|
/// numbervars ( int start, bool process=false )
|
||||||
intptr_t numberVars(intptr_t start, bool skip_singletons = false);
|
intptr_t numberVars(intptr_t start, bool skip_singletons = false);
|
||||||
|
|
||||||
inline Term term() {
|
inline Term term() {
|
||||||
return gt();
|
return gt();
|
||||||
} /// from YAPTerm to Term (internal YAP representation)
|
} /// from YAPTerm to Term (internal YAP representation)
|
||||||
inline void bind(Term b) { LOCAL_HandleBase[t] = b; }
|
inline void bind(Term b) { LOCAL_HandleBase[t] = b; }
|
||||||
|
|
||||||
inline void bind(YAPTerm *b) { LOCAL_HandleBase[t] = b->term(); }
|
inline void bind(YAPTerm *b) { LOCAL_HandleBase[t] = b->term(); }
|
||||||
|
|
||||||
/// from YAPTerm to Term (internal YAP representation)
|
/// from YAPTerm to Term (internal YAP representation)
|
||||||
/// fetch a sub-term
|
/// fetch a sub-term
|
||||||
Term &operator[](arity_t n);
|
Term &operator[](arity_t n);
|
||||||
|
|
||||||
// const YAPTerm *vars();
|
// const YAPTerm *vars();
|
||||||
/// this term is == to t1
|
/// this term is == to t1
|
||||||
virtual bool exactlyEqual(YAPTerm t1) {
|
virtual bool exactlyEqual(YAPTerm t1) {
|
||||||
@ -169,6 +185,7 @@ public:
|
|||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return out;
|
return out;
|
||||||
};
|
};
|
||||||
|
|
||||||
/// term hash,
|
/// term hash,
|
||||||
virtual bool isVar() { return IsVarTerm(gt()); } /// type check for unound
|
virtual bool isVar() { return IsVarTerm(gt()); } /// type check for unound
|
||||||
virtual bool isAtom() { return IsAtomTerm(gt()); } /// type check for atom
|
virtual bool isAtom() { return IsAtomTerm(gt()); } /// type check for atom
|
||||||
@ -189,6 +206,52 @@ public:
|
|||||||
virtual bool isGround() { return Yap_IsGroundTerm(gt()); } /// term is ground
|
virtual bool isGround() { return Yap_IsGroundTerm(gt()); } /// term is ground
|
||||||
virtual bool isList() { return Yap_IsListTerm(gt()); } /// term is a list
|
virtual bool isList() { return Yap_IsListTerm(gt()); } /// term is a list
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<YAPTerm> YAPTermToJavaArray()
|
||||||
|
{
|
||||||
|
BACKUP_H();
|
||||||
|
Term pt = gt();
|
||||||
|
if (IsApplTerm(t)) {
|
||||||
|
arity_t arity = ArityOfFunctor(FunctorOfTerm(pt));
|
||||||
|
std::vector<YAPTerm> o = std::vector<YAPTerm>(arity);
|
||||||
|
for (arity_t i=0; i < arity; i++) {
|
||||||
|
o[i] = YAPTerm( ArgOfTerm(i+1, pt) );
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (IsPairTerm(t)) {
|
||||||
|
std::vector<YAPTerm> o = std::vector<YAPTerm>(2);
|
||||||
|
o[0] = YAPTerm( HeadOfTerm(pt) );
|
||||||
|
o[1] = YAPTerm( TailOfTerm(pt) );
|
||||||
|
return o;
|
||||||
|
|
||||||
|
}
|
||||||
|
return std::vector<YAPTerm>(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Term> YAPTermToVector()
|
||||||
|
{
|
||||||
|
BACKUP_H();
|
||||||
|
Term pt = gt();
|
||||||
|
if (IsApplTerm(t)) {
|
||||||
|
arity_t arity = ArityOfFunctor(FunctorOfTerm(pt));
|
||||||
|
std::vector<Term> o = std::vector<Term>(arity);
|
||||||
|
for (arity_t i=0; i < arity; i++) {
|
||||||
|
o[i] = ( ArgOfTerm(i+1, pt) );
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
|
||||||
|
}
|
||||||
|
if (IsPairTerm(t)) {
|
||||||
|
std::vector<Term> o = std::vector<Term>(2);
|
||||||
|
o[0] = ( HeadOfTerm(pt) );
|
||||||
|
o[1] = ( TailOfTerm(pt) );
|
||||||
|
return o;
|
||||||
|
|
||||||
|
}
|
||||||
|
return std::vector<Term>(0);
|
||||||
|
}
|
||||||
/// extract the argument i of the term, where i in 1...arity
|
/// extract the argument i of the term, where i in 1...arity
|
||||||
virtual Term getArg(arity_t i) {
|
virtual Term getArg(arity_t i) {
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
@ -207,12 +270,14 @@ public:
|
|||||||
else
|
else
|
||||||
YAPError(DOMAIN_ERROR_OUT_OF_RANGE, t0, "t0.getArg()");
|
YAPError(DOMAIN_ERROR_OUT_OF_RANGE, t0, "t0.getArg()");
|
||||||
} else {
|
} else {
|
||||||
YAPError(TYPE_ERROR_COMPOUND , t0, "t0.getArg()");
|
YAPError(TYPE_ERROR_COMPOUND, t0, "t0.getArg()");
|
||||||
}
|
}
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return tf;
|
return tf;
|
||||||
}
|
}
|
||||||
|
virtual YAPTerm getYAPArg(int i) {
|
||||||
|
return YAPTerm(getArg((arity_t)i));
|
||||||
|
}
|
||||||
/// extract the arity of the term
|
/// extract the arity of the term
|
||||||
/// variables have arity 0
|
/// variables have arity 0
|
||||||
virtual inline arity_t arity() {
|
virtual inline arity_t arity() {
|
||||||
@ -244,7 +309,7 @@ public:
|
|||||||
}
|
}
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
length = strlen(os) + 1;
|
length = strlen(os) + 1;
|
||||||
char *sm = (char *)malloc(length + 1);
|
char *sm = (char *) malloc(length + 1);
|
||||||
strcpy(sm, os);
|
strcpy(sm, os);
|
||||||
return sm;
|
return sm;
|
||||||
};
|
};
|
||||||
@ -261,10 +326,15 @@ public:
|
|||||||
*/
|
*/
|
||||||
class X_API YAPFunctor : public YAPProp {
|
class X_API YAPFunctor : public YAPProp {
|
||||||
friend class YAPApplTerm;
|
friend class YAPApplTerm;
|
||||||
|
|
||||||
friend class YAPTerm;
|
friend class YAPTerm;
|
||||||
|
|
||||||
friend class YAPPredicate;
|
friend class YAPPredicate;
|
||||||
|
|
||||||
friend class YAPQuery;
|
friend class YAPQuery;
|
||||||
|
|
||||||
Functor f;
|
Functor f;
|
||||||
|
|
||||||
/// Constructor: receives Prolog functor and casts it to YAPFunctor
|
/// Constructor: receives Prolog functor and casts it to YAPFunctor
|
||||||
///
|
///
|
||||||
/// Notice that this is designed for internal use only.
|
/// Notice that this is designed for internal use only.
|
||||||
@ -284,6 +354,7 @@ public:
|
|||||||
inline YAPFunctor(const char *s, uintptr_t arity, bool isutf8 = true) {
|
inline YAPFunctor(const char *s, uintptr_t arity, bool isutf8 = true) {
|
||||||
f = Yap_MkFunctor(Yap_LookupAtom(s), arity);
|
f = Yap_MkFunctor(Yap_LookupAtom(s), arity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructor: receives name as a wide string plus arity
|
/// Constructor: receives name as a wide string plus arity
|
||||||
///
|
///
|
||||||
/// Notice that this is designed for UNICODE right now
|
/// Notice that this is designed for UNICODE right now
|
||||||
@ -293,6 +364,7 @@ public:
|
|||||||
inline YAPFunctor(const wchar_t *s, uintptr_t arity) {
|
inline YAPFunctor(const wchar_t *s, uintptr_t arity) {
|
||||||
CACHE_REGS f = Yap_MkFunctor(UTF32ToAtom(s PASS_REGS), arity);
|
CACHE_REGS f = Yap_MkFunctor(UTF32ToAtom(s PASS_REGS), arity);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Getter: extract name of functor as an atom
|
/// Getter: extract name of functor as an atom
|
||||||
///
|
///
|
||||||
/// this is for external usage.
|
/// this is for external usage.
|
||||||
@ -312,16 +384,22 @@ class X_API YAPApplTerm : public YAPTerm {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
YAPApplTerm(Term t0) { mk(t0); }
|
YAPApplTerm(Term t0) { mk(t0); }
|
||||||
|
|
||||||
YAPApplTerm(Functor f, Term ts[]) {
|
YAPApplTerm(Functor f, Term ts[]) {
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
Term t0 = Yap_MkApplTerm(f, f->ArityOfFE, ts);
|
Term t0 = Yap_MkApplTerm(f, f->ArityOfFE, ts);
|
||||||
mk(t0);
|
mk(t0);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
};
|
};
|
||||||
|
|
||||||
YAPApplTerm(YAPFunctor f, YAPTerm ts[]);
|
YAPApplTerm(YAPFunctor f, YAPTerm ts[]);
|
||||||
|
|
||||||
YAPApplTerm(const std::string s, std::vector<YAPTerm> ts);
|
YAPApplTerm(const std::string s, std::vector<YAPTerm> ts);
|
||||||
|
|
||||||
YAPApplTerm(YAPFunctor f);
|
YAPApplTerm(YAPFunctor f);
|
||||||
|
|
||||||
inline Functor functor() { return FunctorOfTerm(gt()); }
|
inline Functor functor() { return FunctorOfTerm(gt()); }
|
||||||
|
|
||||||
inline YAPFunctor getFunctor() { return YAPFunctor(FunctorOfTerm(gt())); }
|
inline YAPFunctor getFunctor() { return YAPFunctor(FunctorOfTerm(gt())); }
|
||||||
|
|
||||||
Term getArg(arity_t i) {
|
Term getArg(arity_t i) {
|
||||||
@ -332,6 +410,7 @@ public:
|
|||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return tf;
|
return tf;
|
||||||
};
|
};
|
||||||
|
|
||||||
virtual bool isVar() { return false; } /// type check for unbound
|
virtual bool isVar() { return false; } /// type check for unbound
|
||||||
virtual bool isAtom() { return false; } /// type check for atom
|
virtual bool isAtom() { return false; } /// type check for atom
|
||||||
virtual bool isInteger() { return false; } /// type check for integer
|
virtual bool isInteger() { return false; } /// type check for integer
|
||||||
@ -359,10 +438,23 @@ public:
|
|||||||
else
|
else
|
||||||
Yap_ThrowError(TYPE_ERROR_LIST, t0, "YAPPairTerms");
|
Yap_ThrowError(TYPE_ERROR_LIST, t0, "YAPPairTerms");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// cons
|
||||||
YAPPairTerm(YAPTerm hd, YAPTerm tl);
|
YAPPairTerm(YAPTerm hd, YAPTerm tl);
|
||||||
|
|
||||||
|
/// null constructor, or empty list
|
||||||
YAPPairTerm();
|
YAPPairTerm();
|
||||||
|
|
||||||
|
bool empty() { return gt() == TermNil; }
|
||||||
|
|
||||||
Term getHead() { return (HeadOfTerm(gt())); }
|
Term getHead() { return (HeadOfTerm(gt())); }
|
||||||
|
|
||||||
Term getTail() { return (TailOfTerm(gt())); }
|
Term getTail() { return (TailOfTerm(gt())); }
|
||||||
|
|
||||||
|
YAPTerm car() { return YAPTerm(HeadOfTerm(gt())); }
|
||||||
|
|
||||||
|
YAPPairTerm cdr() { return YAPPairTerm(TailOfTerm(gt())); }
|
||||||
|
|
||||||
std::vector<Term> listToArray() {
|
std::vector<Term> listToArray() {
|
||||||
Term *tailp;
|
Term *tailp;
|
||||||
Term t1 = gt();
|
Term t1 = gt();
|
||||||
@ -379,6 +471,23 @@ public:
|
|||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<YAPTerm> listToYAPArray() {
|
||||||
|
Term *tailp;
|
||||||
|
Term t1 = gt();
|
||||||
|
Int l = Yap_SkipList(&t1, &tailp);
|
||||||
|
if (l < 0) {
|
||||||
|
throw YAPError(TYPE_ERROR_LIST, YAPTerm(t), "");
|
||||||
|
}
|
||||||
|
std::vector<YAPTerm> o = std::vector<YAPTerm>(l);
|
||||||
|
int i = 0;
|
||||||
|
Term t = gt();
|
||||||
|
while (t != TermNil) {
|
||||||
|
o[i++] = YAPTerm(HeadOfTerm(t));
|
||||||
|
t = TailOfTerm(t);
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -387,7 +496,8 @@ public:
|
|||||||
|
|
||||||
class X_API YAPNumberTerm : public YAPTerm {
|
class X_API YAPNumberTerm : public YAPTerm {
|
||||||
public:
|
public:
|
||||||
YAPNumberTerm(){};
|
YAPNumberTerm() {};
|
||||||
|
|
||||||
bool isTagged() { return IsIntTerm(gt()); }
|
bool isTagged() { return IsIntTerm(gt()); }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -398,6 +508,7 @@ public:
|
|||||||
class X_API YAPIntegerTerm : public YAPNumberTerm {
|
class X_API YAPIntegerTerm : public YAPNumberTerm {
|
||||||
public:
|
public:
|
||||||
YAPIntegerTerm(intptr_t i);
|
YAPIntegerTerm(intptr_t i);
|
||||||
|
|
||||||
intptr_t getInteger() { return IntegerOfTerm(gt()); };
|
intptr_t getInteger() { return IntegerOfTerm(gt()); };
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -418,15 +529,18 @@ public:
|
|||||||
///
|
///
|
||||||
/// @param[in] the term
|
/// @param[in] the term
|
||||||
YAPListTerm() { mk(TermNil); /* else type_error */ }
|
YAPListTerm() { mk(TermNil); /* else type_error */ }
|
||||||
|
|
||||||
/// Create an empty list term.
|
/// Create an empty list term.
|
||||||
///
|
///
|
||||||
/// @param[in] the term
|
/// @param[in] the term
|
||||||
YAPListTerm(Term t0) { mk(t0); /* else type_error */ }
|
YAPListTerm(Term t0) { mk(t0); /* else type_error */ }
|
||||||
|
|
||||||
/// Create a list term out of an array of terms.
|
/// Create a list term out of an array of terms.
|
||||||
///
|
///
|
||||||
/// @param[in] the array of terms
|
/// @param[in] the array of terms
|
||||||
/// @param[in] the length of the array
|
/// @param[in] the length of the array
|
||||||
YAPListTerm(YAPTerm ts[], size_t n);
|
YAPListTerm(YAPTerm ts[], size_t n);
|
||||||
|
|
||||||
// YAPListTerm( vector<YAPTerm> v );
|
// YAPListTerm( vector<YAPTerm> v );
|
||||||
/// Return the number of elements in a list term.
|
/// Return the number of elements in a list term.
|
||||||
size_t length() {
|
size_t length() {
|
||||||
@ -434,12 +548,15 @@ public:
|
|||||||
Term t1 = gt();
|
Term t1 = gt();
|
||||||
return Yap_SkipList(&t1, &tailp);
|
return Yap_SkipList(&t1, &tailp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Extract the nth element.
|
/// Extract the nth element.
|
||||||
Term &operator[](size_t n);
|
Term &operator[](size_t n);
|
||||||
|
|
||||||
/// Extract the first element of a list.
|
/// Extract the first element of a list.
|
||||||
///
|
///
|
||||||
/// @param[in] the list
|
/// @param[in] the list
|
||||||
Term car();
|
Term car();
|
||||||
|
|
||||||
/// Extract the tail elements of a list.
|
/// Extract the tail elements of a list.
|
||||||
///
|
///
|
||||||
/// @param[in] the list
|
/// @param[in] the list
|
||||||
@ -452,6 +569,7 @@ public:
|
|||||||
/* error */
|
/* error */
|
||||||
throw YAPError(TYPE_ERROR_LIST, YAPTerm(to), "");
|
throw YAPError(TYPE_ERROR_LIST, YAPTerm(to), "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// copy a list.
|
/// copy a list.
|
||||||
///
|
///
|
||||||
/// @param[in] the list
|
/// @param[in] the list
|
||||||
@ -462,9 +580,7 @@ public:
|
|||||||
/// @param[in] the list
|
/// @param[in] the list
|
||||||
inline bool nil() {
|
inline bool nil() {
|
||||||
return gt() == TermNil;
|
return gt() == TermNil;
|
||||||
}
|
};
|
||||||
|
|
||||||
;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -474,12 +590,16 @@ class X_API YAPStringTerm : public YAPTerm {
|
|||||||
public:
|
public:
|
||||||
/// your standard constructor
|
/// your standard constructor
|
||||||
YAPStringTerm(char *s);
|
YAPStringTerm(char *s);
|
||||||
|
|
||||||
/// use this one to construct length limited strings
|
/// use this one to construct length limited strings
|
||||||
YAPStringTerm(char *s, size_t len);
|
YAPStringTerm(char *s, size_t len);
|
||||||
|
|
||||||
/// construct using wide chars
|
/// construct using wide chars
|
||||||
YAPStringTerm(wchar_t *s);
|
YAPStringTerm(wchar_t *s);
|
||||||
|
|
||||||
/// construct using length-limited wide chars
|
/// construct using length-limited wide chars
|
||||||
YAPStringTerm(wchar_t *s, size_t len);
|
YAPStringTerm(wchar_t *s, size_t len);
|
||||||
|
|
||||||
const char *getString() { return StringOfTerm(gt()); }
|
const char *getString() { return StringOfTerm(gt()); }
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -489,21 +609,28 @@ public:
|
|||||||
*/
|
*/
|
||||||
class X_API YAPAtomTerm : public YAPTerm {
|
class X_API YAPAtomTerm : public YAPTerm {
|
||||||
friend class YAPModule;
|
friend class YAPModule;
|
||||||
|
|
||||||
// Constructor: receives a C-atom;
|
// Constructor: receives a C-atom;
|
||||||
YAPAtomTerm(Term t) : YAPTerm(t) { IsAtomTerm(t); }
|
YAPAtomTerm(Term t) : YAPTerm(t) { IsAtomTerm(t); }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
YAPAtomTerm(Atom a) { mk(MkAtomTerm(a)); }
|
YAPAtomTerm(Atom a) { mk(MkAtomTerm(a)); }
|
||||||
|
|
||||||
// Constructor: receives an atom;
|
// Constructor: receives an atom;
|
||||||
YAPAtomTerm(YAPAtom a) : YAPTerm() { mk(MkAtomTerm(a.a)); }
|
YAPAtomTerm(YAPAtom a) : YAPTerm() { mk(MkAtomTerm(a.a)); }
|
||||||
|
|
||||||
// Constructor: receives a sequence of ISO-LATIN1 codes;
|
// Constructor: receives a sequence of ISO-LATIN1 codes;
|
||||||
YAPAtomTerm(char s[]);
|
YAPAtomTerm(char s[]);
|
||||||
|
|
||||||
// Constructor: receives a sequence of up to n ISO-LATIN1 codes;
|
// Constructor: receives a sequence of up to n ISO-LATIN1 codes;
|
||||||
YAPAtomTerm(char *s, size_t len);
|
YAPAtomTerm(char *s, size_t len);
|
||||||
|
|
||||||
// Constructor: receives a sequence of wchar_ts, whatever they may be;
|
// Constructor: receives a sequence of wchar_ts, whatever they may be;
|
||||||
YAPAtomTerm(wchar_t *s);
|
YAPAtomTerm(wchar_t *s);
|
||||||
|
|
||||||
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
|
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
|
||||||
YAPAtomTerm(wchar_t *s, size_t len);
|
YAPAtomTerm(wchar_t *s, size_t len);
|
||||||
|
|
||||||
bool isVar() { return false; } /// type check for unbound
|
bool isVar() { return false; } /// type check for unbound
|
||||||
bool isAtom() { return true; } /// type check for atom
|
bool isAtom() { return true; } /// type check for atom
|
||||||
bool isInteger() { return false; } /// type check for integer
|
bool isInteger() { return false; } /// type check for integer
|
||||||
@ -516,9 +643,11 @@ public:
|
|||||||
virtual bool isList() { return gt() == TermNil; } /// [] is a list
|
virtual bool isList() { return gt() == TermNil; } /// [] is a list
|
||||||
// Getter: outputs the atom;
|
// Getter: outputs the atom;
|
||||||
YAPAtom getAtom() { return YAPAtom(AtomOfTerm(gt())); }
|
YAPAtom getAtom() { return YAPAtom(AtomOfTerm(gt())); }
|
||||||
|
|
||||||
// Getter: outputs the name as a sequence of ISO-LATIN1 codes;
|
// Getter: outputs the name as a sequence of ISO-LATIN1 codes;
|
||||||
const char *text() { return (const char *)AtomOfTerm(gt())->StrOfAE; }
|
const char *text() { return (const char *) AtomOfTerm(gt())->StrOfAE; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* YAPT_HH */
|
#endif /* YAPT_HH */
|
||||||
|
|
||||||
|
|
||||||
@ -530,16 +659,20 @@ class X_API YAPVarTerm : public YAPTerm {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
/// constructor
|
/// constructor
|
||||||
YAPVarTerm() {mk(MkVarTerm()); };
|
YAPVarTerm() { mk(MkVarTerm()); };
|
||||||
|
|
||||||
/// get the internal representation
|
/// get the internal representation
|
||||||
CELL *getVar() { return VarOfTerm(gt()); }
|
CELL *getVar() { return VarOfTerm(gt()); }
|
||||||
|
|
||||||
/// is the variable bound to another one
|
/// is the variable bound to another one
|
||||||
YAPVarTerm(Term t) {
|
YAPVarTerm(Term t) {
|
||||||
if (IsVarTerm(t)) {
|
if (IsVarTerm(t)) {
|
||||||
mk(t);
|
mk(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool unbound() { return IsUnboundVar(VarOfTerm(gt())); }
|
bool unbound() { return IsUnboundVar(VarOfTerm(gt())); }
|
||||||
|
|
||||||
inline bool isVar() { return true; } /// type check for unbound
|
inline bool isVar() { return true; } /// type check for unbound
|
||||||
inline bool isAtom() { return false; } /// type check for atom
|
inline bool isAtom() { return false; } /// type check for atom
|
||||||
inline bool isInteger() { return false; } /// type check for integer
|
inline bool isInteger() { return false; } /// type check for integer
|
||||||
|
@ -300,7 +300,7 @@ static inline bool trueLocalPrologFlag(int id) {
|
|||||||
return LOCAL_Flags[id].at == TermTrue;
|
return LOCAL_Flags[id].at == TermTrue;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool falsePrologFlag(int id) {
|
static inline bool falseLocalPrologFlag(int id) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
return LOCAL_Flags[id].at == TermFalse;
|
return LOCAL_Flags[id].at == TermFalse;
|
||||||
}
|
}
|
||||||
@ -317,6 +317,10 @@ static inline bool silentMode(void) {
|
|||||||
return GLOBAL_Flags[VERBOSE_FLAG].at == TermSilent;
|
return GLOBAL_Flags[VERBOSE_FLAG].at == TermSilent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool verboseMode(void) {
|
||||||
|
return GLOBAL_Flags[VERBOSE_FLAG].at != TermSilent;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void setVerbosity(Term val) {
|
static inline void setVerbosity(Term val) {
|
||||||
GLOBAL_Flags[VERBOSE_FLAG].at = val;
|
GLOBAL_Flags[VERBOSE_FLAG].at = val;
|
||||||
}
|
}
|
||||||
|
@ -358,7 +358,7 @@ call_count_data/3 built-in.
|
|||||||
YAP_FLAG(REPORT_ERROR_FLAG, "report_error", true, booleanFlag, "true",
|
YAP_FLAG(REPORT_ERROR_FLAG, "report_error", true, booleanFlag, "true",
|
||||||
NULL),
|
NULL),
|
||||||
YAP_FLAG(RESOURCE_DATABASE_FLAG, "resource_database", false, isatom,
|
YAP_FLAG(RESOURCE_DATABASE_FLAG, "resource_database", false, isatom,
|
||||||
"boot.yap", NULL),
|
"pl/boot.yap", NULL),
|
||||||
/**<`resource_database`
|
/**<`resource_database`
|
||||||
Name of the resource file (saved-state or Prolog file) used to construct
|
Name of the resource file (saved-state or Prolog file) used to construct
|
||||||
the YAP
|
the YAP
|
||||||
|
@ -179,15 +179,15 @@ INLINE_ONLY inline EXTERN void Yap_PutInHandle__(yhandle_t slot,
|
|||||||
LOCAL_HandleBase[slot] = t;
|
LOCAL_HandleBase[slot] = t;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef max
|
#ifndef Yap_Max
|
||||||
#define max(X, Y) (X > Y ? X : Y)
|
#define Yap_Max(X, Y) (X > Y ? X : Y)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define ensure_handles ensure_slots
|
#define ensure_handles ensure_slots
|
||||||
INLINE_ONLY inline EXTERN void ensure_slots(int N USES_REGS) {
|
INLINE_ONLY inline EXTERN void ensure_slots(int N USES_REGS) {
|
||||||
if (LOCAL_CurHandle + N >= LOCAL_NHandles) {
|
if (LOCAL_CurHandle + N >= LOCAL_NHandles) {
|
||||||
size_t inc = max(16 * 1024, LOCAL_NHandles / 2); // measured in cells
|
size_t inc = Yap_Max(16 * 1024, LOCAL_NHandles / 2); // measured in cells
|
||||||
inc = max(inc, (size_t)N + 16); // measured in cells
|
inc = Yap_Max(inc, (size_t)N + 16); // measured in cells
|
||||||
LOCAL_HandleBase = (CELL *)realloc(LOCAL_HandleBase,
|
LOCAL_HandleBase = (CELL *)realloc(LOCAL_HandleBase,
|
||||||
(inc + LOCAL_NHandles) * sizeof(CELL));
|
(inc + LOCAL_NHandles) * sizeof(CELL));
|
||||||
LOCAL_NHandles += inc;
|
LOCAL_NHandles += inc;
|
||||||
|
@ -59,8 +59,9 @@ extern int pop_text_stack(int lvl USES_REGS);
|
|||||||
extern void *protected_pop_text_stack(int lvl, void *safe, bool tmp,
|
extern void *protected_pop_text_stack(int lvl, void *safe, bool tmp,
|
||||||
size_t sz USES_REGS);
|
size_t sz USES_REGS);
|
||||||
|
|
||||||
#ifndef min
|
#ifndef Yap_Min
|
||||||
#define min(x, y) (x < y ? x : y)
|
#define Yap_Min(x, y) (x < y ? x : y)
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define MBYTE (1024 * 1024)
|
#define MBYTE (1024 * 1024)
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
# GMP_LIBRARY_DLL - library DLL to install. Only available on WIN32.
|
# GMP_LIBRARY_DLL - library DLL to install. Only available on WIN32.
|
||||||
# GMP_LIBRARIES_DIR - the directory the library we link with is found in.
|
# GMP_LIBRARIES_DIR - the directory the library we link with is found in.
|
||||||
|
|
||||||
|
message( "xxxxx ${ANDROID_ABI} yyyyy ${CMAKE_CURRENT_DIR} zzzzzzzzzz" )
|
||||||
|
|
||||||
if (ANDROID)
|
if (ANDROID)
|
||||||
set( GMP_ROOT ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI} )
|
set( GMP_ROOT ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI} )
|
||||||
set (GMP_FOUND ON)
|
set (GMP_FOUND ON)
|
||||||
@ -26,6 +28,7 @@ if(MSVC)
|
|||||||
${CMAKE_SOURCE_DIR}/../tools/mpird/lib
|
${CMAKE_SOURCE_DIR}/../tools/mpird/lib
|
||||||
${CMAKE_SOURCE_DIR}/../mpir/lib
|
${CMAKE_SOURCE_DIR}/../mpir/lib
|
||||||
${CMAKE_SOURCE_DIR}/../mpird/lib
|
${CMAKE_SOURCE_DIR}/../mpird/lib
|
||||||
|
|
||||||
$ENV{PROGRAMFILES}/mpir/lib
|
$ENV{PROGRAMFILES}/mpir/lib
|
||||||
$ENV{PROGRAMFILES}/mpird/lib
|
$ENV{PROGRAMFILES}/mpird/lib
|
||||||
$ENV{HOME}/mpir/lib
|
$ENV{HOME}/mpir/lib
|
||||||
|
@ -7,7 +7,7 @@ if (POLICY CMP0042)
|
|||||||
cmake_policy( SET CMP0042 NEW)
|
cmake_policy( SET CMP0042 NEW)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ANDROID)
|
if (ANDROID_OLD)
|
||||||
macro ( MY_add_custom_target)
|
macro ( MY_add_custom_target)
|
||||||
endmacro()
|
endmacro()
|
||||||
else()
|
else()
|
||||||
@ -17,7 +17,7 @@ else()
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
if (ANDROID)
|
if (ANDROID_OLD)
|
||||||
macro ( add_component arg1)
|
macro ( add_component arg1)
|
||||||
foreach(item ${ARGN})
|
foreach(item ${ARGN})
|
||||||
get_filename_component(i ${item} ABSOLUTE)
|
get_filename_component(i ${item} ABSOLUTE)
|
||||||
@ -41,7 +41,7 @@ else()
|
|||||||
endmacro()
|
endmacro()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ANDROID)
|
if (ANDROID_OLD)
|
||||||
macro ( MY_add_dependencies)
|
macro ( MY_add_dependencies)
|
||||||
endmacro()
|
endmacro()
|
||||||
else()
|
else()
|
||||||
@ -50,7 +50,7 @@ else()
|
|||||||
endmacro()
|
endmacro()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ANDROID)
|
if (ANDROID_OLD)
|
||||||
macro ( MY_add_library)
|
macro ( MY_add_library)
|
||||||
endmacro()
|
endmacro()
|
||||||
else()
|
else()
|
||||||
@ -68,7 +68,7 @@ else()
|
|||||||
endmacro()
|
endmacro()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ANDROID)
|
if (ANDROID_OLD)
|
||||||
macro ( MY_include)
|
macro ( MY_include)
|
||||||
endmacro()
|
endmacro()
|
||||||
else()
|
else()
|
||||||
@ -86,7 +86,7 @@ else()
|
|||||||
endmacro()
|
endmacro()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ANDROID)
|
if (ANDROID_OLD)
|
||||||
macro ( MY_set_target_properties)
|
macro ( MY_set_target_properties)
|
||||||
endmacro()
|
endmacro()
|
||||||
else()
|
else()
|
||||||
@ -95,7 +95,7 @@ else()
|
|||||||
endmacro()
|
endmacro()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ANDROID)
|
if (ANDROID_OLD)
|
||||||
macro ( MY_target_link_libraries)
|
macro ( MY_target_link_libraries)
|
||||||
endmacro()
|
endmacro()
|
||||||
else()
|
else()
|
||||||
|
@ -31,6 +31,8 @@
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <encoding.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
dev_t st_dev; /* ID of device containing file */
|
dev_t st_dev; /* ID of device containing file */
|
||||||
mode_t st_mode; /* Mode of file (see below) */
|
mode_t st_mode; /* Mode of file (see below) */
|
||||||
@ -47,6 +49,7 @@ typedef struct {
|
|||||||
#endif
|
#endif
|
||||||
} vfs_stat;
|
} vfs_stat;
|
||||||
|
|
||||||
|
|
||||||
typedef enum vfs_flags {
|
typedef enum vfs_flags {
|
||||||
VFS_CAN_WRITE = 0x1, /// we can write to files in this space
|
VFS_CAN_WRITE = 0x1, /// we can write to files in this space
|
||||||
VFS_CAN_EXEC = 0x2, /// we can execute files in this space
|
VFS_CAN_EXEC = 0x2, /// we can execute files in this space
|
||||||
@ -62,7 +65,7 @@ typedef union {
|
|||||||
size_t sz;
|
size_t sz;
|
||||||
void *pt;
|
void *pt;
|
||||||
uintptr_t scalar;
|
uintptr_t scalar;
|
||||||
#if __ANDROID__
|
#if __ANDROID__0
|
||||||
AAssetManager *mgr;
|
AAssetManager *mgr;
|
||||||
AAsset *asset;
|
AAsset *asset;
|
||||||
#endif
|
#endif
|
||||||
@ -108,6 +111,10 @@ typedef struct vfs {
|
|||||||
|
|
||||||
extern VFS_t *GLOBAL_VFS;
|
extern VFS_t *GLOBAL_VFS;
|
||||||
|
|
||||||
|
extern void init_android_stream(void);
|
||||||
|
|
||||||
|
extern void Yap_InitStdStream(int sno, SMALLUNSGN flags, FILE *file, VFS_t *vfsp);
|
||||||
|
|
||||||
static inline VFS_t *vfs_owner(const char *fname) {
|
static inline VFS_t *vfs_owner(const char *fname) {
|
||||||
VFS_t *me = GLOBAL_VFS;
|
VFS_t *me = GLOBAL_VFS;
|
||||||
int d;
|
int d;
|
||||||
|
12
libYap.cmake
12
libYap.cmake
@ -89,12 +89,12 @@ list(APPEND YAP_SYSTEM_OPTIONS "thread support")
|
|||||||
# we use the nice UTF-8 package
|
# we use the nice UTF-8 package
|
||||||
#available at the Julia project
|
#available at the Julia project
|
||||||
|
|
||||||
MY_ADD_SUBDIRECTORY ( os )
|
ADD_SUBDIRECTORY ( os )
|
||||||
MY_ADD_SUBDIRECTORY ( OPTYap )
|
ADD_SUBDIRECTORY ( OPTYap )
|
||||||
MY_ADD_SUBDIRECTORY ( packages/myddas )
|
ADD_SUBDIRECTORY ( packages/myddas )
|
||||||
MY_ADD_SUBDIRECTORY ( utf8proc )
|
ADD_SUBDIRECTORY ( utf8proc )
|
||||||
MY_ADD_SUBDIRECTORY ( library/dialect/swi/fli )
|
ADD_SUBDIRECTORY ( library/dialect/swi/fli )
|
||||||
MY_ADD_SUBDIRECTORY ( CXX )
|
ADD_SUBDIRECTORY ( CXX )
|
||||||
|
|
||||||
if (READLINE_LIBS)
|
if (READLINE_LIBS)
|
||||||
target_link_libraries(libYap ${READLINE_LIBS} )
|
target_link_libraries(libYap ${READLINE_LIBS} )
|
||||||
|
@ -33,7 +33,7 @@ static char SccsId[] = "%W% %G%";
|
|||||||
// for native asset manager
|
// for native asset manager
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#if __ANDROID__
|
#if __ANDROID__0
|
||||||
|
|
||||||
|
|
||||||
static AAssetManager * getMgr(struct vfs *me)
|
static AAssetManager * getMgr(struct vfs *me)
|
||||||
@ -212,7 +212,7 @@ VFS_t *
|
|||||||
Yap_InitAssetManager(void)
|
Yap_InitAssetManager(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
#if __ANDROID__
|
#if __ANDROID__O
|
||||||
VFS_t *me;
|
VFS_t *me;
|
||||||
/* init standard VFS */
|
/* init standard VFS */
|
||||||
me = (VFS_t *)Yap_AllocCodeSpace(sizeof(struct vfs));
|
me = (VFS_t *)Yap_AllocCodeSpace(sizeof(struct vfs));
|
||||||
|
16
os/iopreds.c
16
os/iopreds.c
@ -288,7 +288,7 @@ static void InitFileIO(StreamDesc *s) {
|
|||||||
Yap_DefaultStreamOps(s);
|
Yap_DefaultStreamOps(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file, void *vfsp) {
|
static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file, VFS_t *vfsp) {
|
||||||
StreamDesc *s = &GLOBAL_Stream[sno];
|
StreamDesc *s = &GLOBAL_Stream[sno];
|
||||||
s->file = file;
|
s->file = file;
|
||||||
s->status = flags;
|
s->status = flags;
|
||||||
@ -298,7 +298,15 @@ static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file, void *vfsp) {
|
|||||||
s->vfs = vfsp;
|
s->vfs = vfsp;
|
||||||
s->encoding = ENC_ISO_UTF8;
|
s->encoding = ENC_ISO_UTF8;
|
||||||
INIT_LOCK(s->streamlock);
|
INIT_LOCK(s->streamlock);
|
||||||
|
if (vfsp != NULL) {
|
||||||
|
s->u.private_data = vfsp->open(vfsp->name, (sno == StdInStream ? "read" : "write" ));
|
||||||
|
if (s->u.private_data == NULL) {
|
||||||
|
(PlIOError(EXISTENCE_ERROR_SOURCE_SINK, MkIntTerm(sno), "%s", vfsp->name));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
unix_upd_stream_info(s);
|
unix_upd_stream_info(s);
|
||||||
|
}
|
||||||
/* Getting streams to prompt is a mess because we need for cooperation
|
/* Getting streams to prompt is a mess because we need for cooperation
|
||||||
between readers and writers to the stream :-(
|
between readers and writers to the stream :-(
|
||||||
*/
|
*/
|
||||||
@ -329,6 +337,11 @@ static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file, void *vfsp) {
|
|||||||
#endif /* HAVE_SETBUF */
|
#endif /* HAVE_SETBUF */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Yap_InitStdStream(int sno, SMALLUNSGN flags, FILE *file, VFS_t *vfsp) {
|
||||||
|
InitStdStream(sno, flags, file, vfsp);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Term Yap_StreamUserName(int sno) {
|
Term Yap_StreamUserName(int sno) {
|
||||||
Term atname;
|
Term atname;
|
||||||
StreamDesc *s = &GLOBAL_Stream[sno];
|
StreamDesc *s = &GLOBAL_Stream[sno];
|
||||||
@ -1073,6 +1086,7 @@ bool Yap_initStream(int sno, FILE *fd, const char *name, Term file_name,
|
|||||||
st->encoding = encoding;
|
st->encoding = encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (name == NULL) {
|
if (name == NULL) {
|
||||||
char buf[YAP_FILENAME_MAX + 1];
|
char buf[YAP_FILENAME_MAX + 1];
|
||||||
name = Yap_guessFileName(fd, sno, buf, YAP_FILENAME_MAX);
|
name = Yap_guessFileName(fd, sno, buf, YAP_FILENAME_MAX);
|
||||||
|
@ -300,7 +300,7 @@ has_reposition(int sno,
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *Yap_guessFileName(FILE *file, int sno, char *nameb, size_t max) {
|
char *Yap_guessFileName(FILE *file, int sno, char *nameb, size_t max) {
|
||||||
size_t maxs = max(255, max);
|
size_t maxs = Yap_Max(255, max);
|
||||||
if (!nameb) {
|
if (!nameb) {
|
||||||
nameb = malloc(maxs + 1);
|
nameb = malloc(maxs + 1);
|
||||||
}
|
}
|
||||||
|
12
os/sysbits.c
12
os/sysbits.c
@ -954,16 +954,16 @@ static bool initSysPath(Term tlib, Term tcommons, bool dir_done,
|
|||||||
if ((dir = Yap_RegistryGetString("library")) && is_directory(dir)) {
|
if ((dir = Yap_RegistryGetString("library")) && is_directory(dir)) {
|
||||||
dir_done = true;
|
dir_done = true;
|
||||||
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(dir))))
|
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(dir))))
|
||||||
return FALSE;
|
return false;
|
||||||
}
|
}
|
||||||
if ((dir = Yap_RegistryGetString("prolog_commons")) && is_directory(dir)) {
|
if ((dir = Yap_RegistryGetString("prolog_commons")) && is_directory(dir)) {
|
||||||
if (!Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(dir))))
|
if (!Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(dir))))
|
||||||
return FALSE;
|
return false;
|
||||||
commons_done = true;
|
commons_done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (dir_done && commons_done)
|
if (dir_done && commons_done)
|
||||||
return TRUE;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
strncpy(LOCAL_FileNameBuf, YAP_SHAREDIR, YAP_FILENAME_MAX);
|
strncpy(LOCAL_FileNameBuf, YAP_SHAREDIR, YAP_FILENAME_MAX);
|
||||||
strncat(LOCAL_FileNameBuf, "/", YAP_FILENAME_MAX);
|
strncat(LOCAL_FileNameBuf, "/", YAP_FILENAME_MAX);
|
||||||
@ -972,7 +972,7 @@ static bool initSysPath(Term tlib, Term tcommons, bool dir_done,
|
|||||||
strncat(LOCAL_FileNameBuf, "Yap", YAP_FILENAME_MAX);
|
strncat(LOCAL_FileNameBuf, "Yap", YAP_FILENAME_MAX);
|
||||||
if (is_directory(LOCAL_FileNameBuf)) {
|
if (is_directory(LOCAL_FileNameBuf)) {
|
||||||
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
|
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
|
||||||
return FALSE;
|
return false;
|
||||||
dir_done = true;
|
dir_done = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1035,15 +1035,15 @@ static bool initSysPath(Term tlib, Term tcommons, bool dir_done,
|
|||||||
if (!dir_done && is_directory(LOCAL_FileNameBuf)) {
|
if (!dir_done && is_directory(LOCAL_FileNameBuf)) {
|
||||||
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
|
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
dir_done = true;
|
dir_done = true;
|
||||||
|
}
|
||||||
LOCAL_FileNameBuf[len] = '\0';
|
LOCAL_FileNameBuf[len] = '\0';
|
||||||
strncat(LOCAL_FileNameBuf, "PrologCommons", YAP_FILENAME_MAX);
|
strncat(LOCAL_FileNameBuf, "PrologCommons", YAP_FILENAME_MAX);
|
||||||
if (!commons_done && is_directory(LOCAL_FileNameBuf)) {
|
if (!commons_done && is_directory(LOCAL_FileNameBuf)) {
|
||||||
if (!Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
|
if (!Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
|
||||||
commons_done = true;
|
commons_done = true;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
return dir_done && commons_done;
|
return dir_done && commons_done;
|
||||||
}
|
}
|
||||||
|
@ -685,7 +685,7 @@ void init_myddas(void) {
|
|||||||
#if defined MYDDAS_ODBC
|
#if defined MYDDAS_ODBC
|
||||||
Yap_InitBackMYDDAS_ODBCPreds();
|
Yap_InitBackMYDDAS_ODBCPreds();
|
||||||
#endif
|
#endif
|
||||||
#if defined MYDDAS_SQLITE3
|
#if WIN32
|
||||||
Yap_InitBackMYDDAS_SQLITE3Preds();
|
Yap_InitBackMYDDAS_SQLITE3Preds();
|
||||||
#endif
|
#endif
|
||||||
#if defined USE_MYDDAS
|
#if defined USE_MYDDAS
|
||||||
@ -697,7 +697,7 @@ void init_myddas(void) {
|
|||||||
#if defined MYDDAS_ODBC
|
#if defined MYDDAS_ODBC
|
||||||
Yap_InitMYDDAS_ODBCPreds();
|
Yap_InitMYDDAS_ODBCPreds();
|
||||||
#endif
|
#endif
|
||||||
#if defined MYDDAS_SQLITE3
|
#if WIN32
|
||||||
Yap_InitMYDDAS_SQLITE3Preds();
|
Yap_InitMYDDAS_SQLITE3Preds();
|
||||||
#endif
|
#endif
|
||||||
#if defined USE_MYDDAS
|
#if defined USE_MYDDAS
|
||||||
|
@ -39,11 +39,17 @@ function(cpp_compile output filename)
|
|||||||
set_source_files_properties(${outfile} PROPERTIES GENERATED TRUE)
|
set_source_files_properties(${outfile} PROPERTIES GENERATED TRUE)
|
||||||
endfunction()
|
endfunction()
|
||||||
|
|
||||||
|
if (ANDROID)
|
||||||
|
set (MYDDAS_PL_OUTDIR ${YAP_APP_DIR}/src/generated/assets/Yap} )
|
||||||
|
else()
|
||||||
|
set (MYDDAS_PL_OUTDIR ${CMAKE_CURRENT_BINARY_DIR} )
|
||||||
|
endif()
|
||||||
|
|
||||||
function(cpp_driver output dbms filename)
|
function(cpp_driver output dbms filename)
|
||||||
if (0)
|
if (0)
|
||||||
set(outfile ${libpl}/myddas_${dbms}.yap)
|
set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap)
|
||||||
else()
|
else()
|
||||||
set(outfile ${CMAKE_CURRENT_BINARY_DIR}/myddas_${dbms}.yap)
|
set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap)
|
||||||
endif()
|
endif()
|
||||||
set(${output} ${${output}} ${outfile} PARENT_SCOPE)
|
set(${output} ${${output}} ${outfile} PARENT_SCOPE)
|
||||||
IF (MSVC)
|
IF (MSVC)
|
||||||
@ -74,3 +80,4 @@ add_custom_target(plmyddas ALL DEPENDS ${MYDDAS_YAP} )
|
|||||||
install(FILES ${MYDDAS_YAP}
|
install(FILES ${MYDDAS_YAP}
|
||||||
DESTINATION ${libpl}
|
DESTINATION ${libpl}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -40,14 +40,14 @@ src/Android/jni/sqlite/android_database_SQLiteConnection.cpp
|
|||||||
src/Android/jni/sqlite/android_database_SQLiteDebug.cpp
|
src/Android/jni/sqlite/android_database_SQLiteDebug.cpp
|
||||||
src/Android/jni/sqlite/android_database_SQLiteGlobal.cpp
|
src/Android/jni/sqlite/android_database_SQLiteGlobal.cpp
|
||||||
src/Android/jni/sqlite/nativehelper/jni.h
|
src/Android/jni/sqlite/nativehelper/jni.h
|
||||||
src/Android/jni/sqlite/nativehelper/jniConstants.h
|
src/Android/jni/sqlite/nativehelper/JniConstants.h
|
||||||
src/Android/jni/sqlite/nativehelper/JNIHelp.h
|
src/Android/jni/sqlite/nativehelper/JNIHelp.h
|
||||||
src/Android/jni/sqlite/nativehelper/ScopedLocalRef.h
|
src/Android/jni/sqlite/nativehelper/ScopedLocalRef.h
|
||||||
)
|
)
|
||||||
|
|
||||||
endif (ANDROID)
|
endif (ANDROID)
|
||||||
|
|
||||||
add_component( Yapsqlite3
|
add_library( Yapsqlite3 SHARED
|
||||||
${YAPSQLITE3_SOURCES} )
|
${YAPSQLITE3_SOURCES} )
|
||||||
|
|
||||||
MY_set_target_properties(Yapsqlite3
|
MY_set_target_properties(Yapsqlite3
|
||||||
@ -56,3 +56,9 @@ add_component( Yapsqlite3
|
|||||||
# SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION}
|
# SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION}
|
||||||
POSITION_INDEPENDENT_CODE TRUE
|
POSITION_INDEPENDENT_CODE TRUE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if (ANDROID)
|
||||||
|
target_link_libraries(Yapsqlite3 android log)
|
||||||
|
|
||||||
|
endif ()
|
@ -676,6 +676,17 @@ void init_sqlite3( void )
|
|||||||
Yap_InitBackMYDDAS_SQLITE3Preds();
|
Yap_InitBackMYDDAS_SQLITE3Preds();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if _ANDROID_
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
lib_yap_up_pt_init_sqlite(JNIEnv *env);
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL
|
||||||
|
lib_yap_up_pt_init_sqlite(JNIEnv *env)
|
||||||
|
{
|
||||||
|
init_sqlite3();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
@ -360,23 +360,22 @@ static jlong nativePrepareStatement(JNIEnv *env, jclass clazz,
|
|||||||
int err = sqlite3_prepare16_v2(connection->db, sql, sqlLength * sizeof(jchar),
|
int err = sqlite3_prepare16_v2(connection->db, sql, sqlLength * sizeof(jchar),
|
||||||
&statement, NULL);
|
&statement, NULL);
|
||||||
env->ReleaseStringCritical(sqlString, sql);
|
env->ReleaseStringCritical(sqlString, sql);
|
||||||
|
#if 0
|
||||||
if (err != SQLITE_OK) {
|
if (err != SQLITE_OK) {
|
||||||
// Error messages like 'near ")": syntax error' are not
|
// Error messages like 'near ")": syntax error' are not
|
||||||
// always helpful enough, so construct an error string that
|
// always helpful enough, so construct an error string that
|
||||||
// includes the query itself.
|
// includes the query itself.
|
||||||
const char *query = env->GetStringUTFChars(sqlString, NULL);
|
const char *query = env->GetStringUTFChars(sqlString, NULL);
|
||||||
char *message = (char *)malloc(strlen(query) + 50);
|
char *message[512];
|
||||||
if (message) {
|
if (message) {
|
||||||
strcpy(message, ", while compiling: "); // less than 50 chars
|
strcpy(message, ", while compiling: "); // less than 50 chars
|
||||||
strcat(message, query);
|
strcat(message, query);
|
||||||
}
|
}
|
||||||
env->ReleaseStringUTFChars(sqlString, query);
|
env->ReleaseStringUTFChars(sqlString, query);
|
||||||
throw_sqlite3_exception(env, connection->db, message);
|
throw_sqlite3_exception(env, connection->db, message);
|
||||||
free(message);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
ALOGV("Prepared statement %p on connection %p", statement, connection->db);
|
ALOGV("Prepared statement %p on connection %p", statement, connection->db);
|
||||||
return reinterpret_cast<jlong>(statement);
|
return reinterpret_cast<jlong>(statement);
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,8 @@ add_library (YAPPython SHARED pyload.c ${PYTHON_HEADERS} )
|
|||||||
if (WIN32)
|
if (WIN32)
|
||||||
add_library (Py4YAP OBJECT ${PYTHON_SOURCES} ${PYTHON_HEADERS})
|
add_library (Py4YAP OBJECT ${PYTHON_SOURCES} ${PYTHON_HEADERS})
|
||||||
|
|
||||||
|
target_link_libraries(YAPPython libYap ${PYTHON_LIBRARIES})
|
||||||
|
|
||||||
else()
|
else()
|
||||||
add_library (Py4YAP SHARED ${PYTHON_SOURCES} ${PYTHON_HEADERS})
|
add_library (Py4YAP SHARED ${PYTHON_SOURCES} ${PYTHON_HEADERS})
|
||||||
|
|
||||||
@ -21,7 +23,6 @@ add_library (Py4YAP SHARED ${PYTHON_SOURCES} ${PYTHON_HEADERS})
|
|||||||
set_property(TARGET Py4YAP PROPERTY CXX_STANDARD_REQUIRED ON)
|
set_property(TARGET Py4YAP PROPERTY CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
target_link_libraries(Py4YAP libYap ${PYTHON_LIBRARIES})
|
target_link_libraries(Py4YAP libYap ${PYTHON_LIBRARIES})
|
||||||
target_link_libraries(YAPPython Py4YAP)
|
|
||||||
|
|
||||||
MY_install(TARGETS Py4YAP
|
MY_install(TARGETS Py4YAP
|
||||||
LIBRARY DESTINATION ${libdir}
|
LIBRARY DESTINATION ${libdir}
|
||||||
@ -33,7 +34,6 @@ endif()
|
|||||||
# arithmetic hassle.
|
# arithmetic hassle.
|
||||||
set_property(TARGET YAPPython PROPERTY CXX_STANDARD_REQUIRED ON)
|
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)
|
||||||
|
|
||||||
|
@ -114,3 +114,142 @@ install(FILES ${PROLOG_SOURCES} DESTINATION ${libpl})
|
|||||||
add_dependencies(${SWIG_MODULE_ftdi1_REAL_NAME} doc_i)
|
add_dependencies(${SWIG_MODULE_ftdi1_REAL_NAME} doc_i)
|
||||||
|
|
||||||
ENDIF ()
|
ENDIF ()
|
||||||
|
|
||||||
|
# This is a CMake example for Python
|
||||||
|
|
||||||
|
#INCLUDE(NewUseSWIG)
|
||||||
|
|
||||||
|
include(FindPythonModule)
|
||||||
|
|
||||||
|
set (PROLOG_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/yapi.yap
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/jupyter.yap)
|
||||||
|
set (PYTHON_SOURCES
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/yap4py/yapi.py
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/yap4py/__init__.py
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/yap4py/__main__.py
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
set (PL ${pl_library} ${PROLOG_SOURCES} )
|
||||||
|
|
||||||
|
|
||||||
|
set (python_dlls
|
||||||
|
$<TARGET_FILE:libYap>
|
||||||
|
$<TARGET_FILE:YAPPython>
|
||||||
|
$<TARGET_FILE:matrix>
|
||||||
|
$<TARGET_FILE:regexp>
|
||||||
|
$<TARGET_FILE:yap_rl>
|
||||||
|
$<TARGET_FILE:tries>
|
||||||
|
$<TARGET_FILE:itries>
|
||||||
|
$<TARGET_FILE:sys>
|
||||||
|
$<TARGET_FILE:yap_random>
|
||||||
|
)
|
||||||
|
if (TARGET real)
|
||||||
|
list(APPEND python_dlls $<TARGET_FILE:real>
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
if (NOT WIN32)
|
||||||
|
list(APPEND python_dlls $<TARGET_FILE:YAP++>
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
file(RELATIVE_PATH RELATIVE_SOURCE ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
|
configure_file("setup.py.in" ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
|
||||||
|
configure_file("MANIFEST.in" ${CMAKE_CURRENT_BINARY_DIR}/MANIFEST.in)
|
||||||
|
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/YAP4PY.md" ${CMAKE_CURRENT_BINARY_DIR}/README)
|
||||||
|
|
||||||
|
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH})
|
||||||
|
|
||||||
|
INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/CXX")
|
||||||
|
|
||||||
|
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(../../swig/yap.i PROPERTIES SWIG_MODULE_NAME yap)
|
||||||
|
|
||||||
|
if (WIN32)
|
||||||
|
|
||||||
|
#set (SYS_DLLS ${GMP_LIBRARIES} c:/msys64/mingw64/bin/libgmp-10.dll)
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# inform we are compiling YAP
|
||||||
|
# s used in MSYS
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# INSTALL ( TARGETS ${SWIG_MODULE_Py2YAP_REAL_NAME}
|
||||||
|
# RUNTIME DESTINATION ${PYTHON_MODULE_PATH}
|
||||||
|
# ARCHIVE DESTINATION ${PYTHON_MODULE_PATH}
|
||||||
|
# LIBRARY DESTINATION ${PYTHON_MODULE_PATH}
|
||||||
|
# )
|
||||||
|
|
||||||
|
|
||||||
|
add_custom_target( YAP4PY_SETUP_DIRS
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/yap4py
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog/pl
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/yap4py/prolog/os
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
add_custom_COMMAND( OUTPUT yap4py/prolog/lists,yap
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy ${PL} yap4py/prolog
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
DEPENDS YAP4PY_SETUP_DIRS ${PL} )
|
||||||
|
|
||||||
|
add_custom_COMMAND( OUTPUT yap4py/prolog/pl/boot.yap
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy ${pl_boot_library} yap4py/prolog/pl
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
DEPENDS YAP4PY_SETUP_DIRS ${pl_boot_library} )
|
||||||
|
|
||||||
|
add_custom_COMMAND( OUTPUT yap4py/prolog/os/yio.yap
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy ${pl_os_library} yap4py/prolog/os
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
DEPENDS YAP4PY_SETUP_DIRS ${pl_os_library} )
|
||||||
|
|
||||||
|
add_custom_COMMAND( OUTPUT yap4py/startup.yss
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy ${PYTHON_SOURCES} ${python_dlls} ${CMAKE_BINARY_DIR}/startup.yss yap4py
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
DEPENDS YAP4PY_SETUP_DIRS STARTUP )
|
||||||
|
|
||||||
|
add_custom_target( YAP4PY ALL
|
||||||
|
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_conda
|
||||||
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
|
||||||
|
DEPENDS yap4py/yapi.py yap4py/prolog/lists,yap yap4py/prolog/pl/boot.yap yap4py/startup.yss yap4py/prolog/os/yio.yap )
|
||||||
|
|
||||||
|
|
||||||
|
install(CODE "execute_process"
|
||||||
|
COMMAND ${PYTHON_EXECUTABLE} -m pip install --force --no-index -f packages/python/swig/dist YAP4PY
|
||||||
|
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||||
|
DEPENDS YAP4PY ${CMAKE_BINARY_DIR}/${YAP_STARTUP} ${dlls} )
|
||||||
|
|
||||||
|
install(FILES ${PROLOG_SOURCES} DESTINATION ${libpl})
|
||||||
|
|
||||||
|
|
||||||
|
if (WITH_DOCS 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/xm11l/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 ()
|
||||||
|
>>>>>>> 11e81b457dcc145e07b457482698a90e0ec350a2
|
||||||
|
@ -1,8 +1,9 @@
|
|||||||
# include COPYING.md
|
|
||||||
# include CONTRIBUTING.md
|
# include CONTRIBUTING.md
|
||||||
include README.md
|
include README.md
|
||||||
|
|
||||||
recursive-include * *.*
|
recursive-include yap4py/prolog *.*
|
||||||
|
recursive-include html *.*
|
||||||
|
recursive-include docs *.*
|
||||||
|
|
||||||
# Documentation
|
# Documentation
|
||||||
graft docs
|
graft docs
|
||||||
|
@ -20,6 +20,7 @@ else:
|
|||||||
dll = glob.glob(os.path.join(yap_lib_path,dll))[0]
|
dll = glob.glob(os.path.join(yap_lib_path,dll))[0]
|
||||||
dll = os.path.abspath(dll)
|
dll = os.path.abspath(dll)
|
||||||
ctypes.CDLL(dll, mode=ctypes.RTLD_GLOBAL)
|
ctypes.CDLL(dll, mode=ctypes.RTLD_GLOBAL)
|
||||||
|
if platform.system() == 'Apple'::
|
||||||
load('libYap*')
|
load('libYap*')
|
||||||
load('libYAP+*')
|
load('libYAP+*')
|
||||||
load('libPy4YAP*')
|
load('libPy4YAP*')
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
"""The main routine of the yap python project."""
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import yapi
|
|
||||||
|
|
||||||
|
|
||||||
"""The main routine."""
|
|
||||||
if args is None:
|
|
||||||
args = sys.argv[1:]
|
|
||||||
yap4pi.yapi.live(args)
|
|
6
packages/python/swig/distutils.cfg
Normal file
6
packages/python/swig/distutils.cfg
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
[build]
|
||||||
|
compiler=mingw32
|
||||||
|
|
||||||
|
[build_ext]
|
||||||
|
compiler=mingw32
|
||||||
|
|
@ -68,6 +68,8 @@ cplus = ['']
|
|||||||
bpy2yap = []
|
bpy2yap = []
|
||||||
native_sources = ['yap_wrap.cpp']
|
native_sources = ['yap_wrap.cpp']
|
||||||
here = path.abspath(path.dirname(__file__))
|
here = path.abspath(path.dirname(__file__))
|
||||||
|
gmp_dir = path.abspath(path.dirname("${GMP_LIBRARIES}"))
|
||||||
|
python_libdir = path.abspath(path.dirname("${PYTHON_LIBRARIES}"))
|
||||||
|
|
||||||
# Get the long description from the README file
|
# Get the long description from the README file
|
||||||
|
|
||||||
@ -79,14 +81,14 @@ extensions = [Extension('_yap', native_sources,
|
|||||||
('_YAP_NOT_INSTALLED_', '1'),
|
('_YAP_NOT_INSTALLED_', '1'),
|
||||||
('YAP_PYTHON', '1'),
|
('YAP_PYTHON', '1'),
|
||||||
('_GNU_SOURCE', '1')],
|
('_GNU_SOURCE', '1')],
|
||||||
runtime_library_dirs=['yap4py', '${libdir}', '${bindir}'],
|
runtime_library_dirs=['yap4py', '${libdir}', '${bindir}', '${gmp_dir}', '${python_libdir}'],
|
||||||
swig_opts=['-modern', '-c++', '-py3',
|
swig_opts=['-modern', '-c++', '-py3',
|
||||||
'-DX_API', '-I${CMAKE_SOURCE_DIR}/CXX', '-I${CMAKE_SOURCE_DIR}/include',
|
'-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}/H', '-I${CMAKE_SOURCE_DIR}/H/generated',
|
||||||
'-I${CMAKE_SOURCE_DIR}/os', '-I${CMAKE_SOURCE_DIR}/OPTYap', '-I../../..'],
|
'-I${CMAKE_SOURCE_DIR}/os', '-I${CMAKE_SOURCE_DIR}/OPTYap', '-I../../..'],
|
||||||
library_dirs=['../../..', '../../../CXX', '..', "${dlls}", "${bindir}", '.'],
|
library_dirs=['../../..', '../../../CXX', '..', "${dlls}", "${bindir}", 'c:/Anaconda3'],
|
||||||
extra_link_args=my_extra_link_args,
|
extra_link_args=my_extra_link_args,
|
||||||
libraries=['Yap','${PYTHON_LIBRARIES}','${GMP_LIBRARIES}']+win_libs+local_libs,
|
libraries=['Yap','gmp']+win_libs+local_libs,
|
||||||
include_dirs=['../../..',
|
include_dirs=['../../..',
|
||||||
'${GMP_INCLUDE_DIRS}',
|
'${GMP_INCLUDE_DIRS}',
|
||||||
'${CMAKE_SOURCE_DIR}/H',
|
'${CMAKE_SOURCE_DIR}/H',
|
||||||
@ -112,7 +114,7 @@ def visit(d0, pls):
|
|||||||
|
|
||||||
|
|
||||||
package_data = {
|
package_data = {
|
||||||
'': visit('.', [])
|
'yap4py.prolog': """${PL}""".split(sep=";")
|
||||||
}
|
}
|
||||||
|
|
||||||
version_ns = {'__version__': '6.3.5', 'minor-version': '6', 'minor-version': '3', 'patch': '5'}
|
version_ns = {'__version__': '6.3.5', 'minor-version': '6', 'minor-version': '3', 'patch': '5'}
|
||||||
@ -125,6 +127,12 @@ setup_args = dict(
|
|||||||
py_modules=['yap'],
|
py_modules=['yap'],
|
||||||
package_data=package_data,
|
package_data=package_data,
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
|
requirements=[
|
||||||
|
'm2w64-gmp',
|
||||||
|
'm2-msys2-keyring',
|
||||||
|
'm2-msys2-launcher-git',
|
||||||
|
'm2-msys2-runtime',
|
||||||
|
],
|
||||||
description="YAP in Python",
|
description="YAP in Python",
|
||||||
author='YAP Development Team',
|
author='YAP Development Team',
|
||||||
author_email='ipython-dev@scipy.org',
|
author_email='ipython-dev@scipy.org',
|
||||||
|
@ -1 +1,14 @@
|
|||||||
|
"""The main routine of the yap python project."""
|
||||||
|
|
||||||
|
import sys
|
||||||
import yap4py.yapi
|
import yap4py.yapi
|
||||||
|
|
||||||
|
|
||||||
|
def main(**args):
|
||||||
|
"""The main routine."""
|
||||||
|
if args is None:
|
||||||
|
args = sys.argv[1:]
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
yap4py.yapi.live()
|
||||||
|
@ -8,12 +8,14 @@
|
|||||||
|
|
||||||
# This is a CMake example for Python and Java
|
# This is a CMake example for Python and Java
|
||||||
|
|
||||||
|
set (SOURCES yap.i)
|
||||||
|
|
||||||
INCLUDE(${SWIG_USE_FILE})
|
INCLUDE(${SWIG_USE_FILE})
|
||||||
|
|
||||||
if (ANDROID)
|
if (ANDROID)
|
||||||
add_subdirectory(android)
|
add_subdirectory(android)
|
||||||
else(ANDROID)
|
else(ANDROID)
|
||||||
# add_subdirectory(java)
|
add_subdirectory(java)
|
||||||
endif(ANDROID)
|
endif(ANDROID)
|
||||||
|
|
||||||
set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS SWIGYAP=1)
|
set_property( DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS SWIGYAP=1)
|
||||||
|
@ -1,21 +1,72 @@
|
|||||||
|
|
||||||
# This is a CMake example for Python and Java
|
# This is a CMake file for SWIG and Android
|
||||||
|
|
||||||
|
FILE( MAKE_DIRECTORY ${YAP_APP_DIR}/src/generated/java/pt/up/yap/lib )
|
||||||
|
FILE( MAKE_DIRECTORY ${YAP_APP_DIR}/src/generated/assets)
|
||||||
|
set(CMAKE_SWIG_OUTDIR ${YAP_APP_DIR}/src/generated/java/pt/up/yap/lib )
|
||||||
|
set( SWIG_MODULE_NAME pt.up.yap.lib )
|
||||||
|
set ( pllib ${YAP_APP_DIR}/src/generated/assets/Yap )
|
||||||
|
|
||||||
set(CMAKE_SWIG_OUTDIR ${YAP_APP_DIR}/app/src/main/java/pt/up/yap/lib )
|
set ( SWIG_SOURCES ${CMAKE_SOURCE_DIR}/packages/swig/yap.i )
|
||||||
|
|
||||||
set ( SWIG_SOURCES ../yap.i )
|
|
||||||
SET_SOURCE_FILES_PROPERTIES(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON)
|
SET_SOURCE_FILES_PROPERTIES(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON)
|
||||||
|
|
||||||
include_directories (
|
include_directories (
|
||||||
${CMAKE_SOURCE_DIR}/CXX
|
${CMAKE_SOURCE_DIR}/CXX
|
||||||
)
|
)
|
||||||
|
set( GMP_ROOT ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI} )
|
||||||
|
set (GMP_INCLUDE_DIRS ${GMP_ROOT})
|
||||||
|
set (GMP_LIBRARIES ${GMP_ROOT}/libgmp.so)
|
||||||
|
|
||||||
|
|
||||||
add_custom_command (OUTPUT yap_swig.cpp
|
add_custom_command (OUTPUT yap_swig.cpp
|
||||||
COMMAND ${SWIG} -java -outdir ${CMAKE_SWIG_OUTDIR} -outcurrentdir -addextern -I${CMAKE_SOURCE_DIR}/CXX ${SWIG_SOURCES} -o yap_swig.cpp
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${pllib}
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${pllib}/pl
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E make_directory ${pllib}/os
|
||||||
|
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy ${pl_library} ${pllib}
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy ${pl_boot_library} ${pllib}/pl
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy ${pl_os_library} ${pllib}/os
|
||||||
|
COMMAND ${SWIG_EXECUTABLE} -c++ -java -package ${SWIG_MODULE_NAME} -outdir ${CMAKE_SWIG_OUTDIR} -outcurrentdir -addextern -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/include -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/os -I${CMAKE_SOURCE_DIR}/OPTYap -I${CMAKE_BINARY_DIR} -I${GMP_INCLUDE_DIRS} -DX_API="" -o yap_swig.cpp ${SWIG_SOURCES}
|
||||||
|
DEPENDS ${SWIG_SOURCES} YAP++
|
||||||
)
|
)
|
||||||
|
|
||||||
add_custom_target ( swig ALL
|
add_custom_command (OUTPUT swig_streamer.cpp
|
||||||
DEPENDS yap_swig.cpp
|
COMMAND ${SWIG_EXECUTABLE} -c++ -java -package ${SWIG_MODULE_NAME} -outdir ${CMAKE_SWIG_OUTDIR} -outcurrentdir -addextern -I${CMAKE_CURRENT_SOURCE_DIR} -o swig_streamer.cpp streamer.i
|
||||||
|
DEPENDS streamer.i
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
# GMP_FOUND - true if GMP/MPIR was found
|
||||||
|
# GMP_INCLUDE_DIRS - include search path
|
||||||
|
# GMP_LIBRARIES - libraries to link with
|
||||||
|
#config.h needs this (TODO: change in code latter)
|
||||||
|
include_directories( .;${GMP_INCLUDE_DIRS};${CMAKE_SOURCE_DIR}/include;${CMAKE_SOURCE_DIR}/H;${CMAKE_SOURCE_DIR}/H/generated;${CMAKE_SOURCE_DIR}/os;${CMAKE_SOURCE_DIR}/OPTYap;${CMAKE_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR} )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
add_library (YAPJava SHARED
|
||||||
|
yap_swig.cpp swig_streamer.cpp streamer.cpp streamer.h
|
||||||
|
)
|
||||||
|
target_link_libraries(YAPJava ${GMP_LIBRARIES} )
|
||||||
|
|
||||||
|
|
||||||
|
target_link_libraries( YAPJava YAP++ libYap android log)
|
||||||
|
|
||||||
|
if (FALSE)
|
||||||
|
|
||||||
|
set (SWIG_ADD_MODULE YAPJava SHARED CPLUPLUS ${SWIG_SOURCES} )
|
||||||
|
# Define swig module with given name and specified language
|
||||||
|
|
||||||
|
|
||||||
|
set (SWIG_LINK_LIBRARIES YAPJava YAP++ libYAP )
|
||||||
|
#- Link libraries to swig module
|
||||||
|
|
||||||
|
|
||||||
|
add_library (YAPJavaTop SHARED
|
||||||
|
main.cpp main.h
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries( YAPJavaTop ${SWIG_MODULE_${YAPJava}_REAL_NAME} YAP++ libYap android)
|
||||||
|
|
||||||
|
endif()
|
||||||
|
@ -92,7 +92,10 @@ class JavaYAP {
|
|||||||
|
|
||||||
public static void main(String args[])
|
public static void main(String args[])
|
||||||
{
|
{
|
||||||
System.loadLibrary("Native");
|
System.loadLibrary("gmp");
|
||||||
|
System.loadLibrary("Yap");
|
||||||
|
System.loadLibrary("YAP++");
|
||||||
|
System.loadLibrary("JAVAYap");
|
||||||
|
|
||||||
JavaYAP y = new JavaYAP();
|
JavaYAP y = new JavaYAP();
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
|
// supports Java and Python
|
||||||
|
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <gmpxx.h>
|
#include <gmpxx.h>
|
||||||
|
|
||||||
extern "C"{
|
extern "C"{
|
||||||
#ifdef SWIGPYTHON
|
#ifdef SWIGPYTHON
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
@ -22,11 +23,11 @@
|
|||||||
%include std_string.i
|
%include std_string.i
|
||||||
%include std_vector.i
|
%include std_vector.i
|
||||||
|
|
||||||
namespace std {
|
|
||||||
%template(vectort) vector<Term>;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
<<<<<<< HEAD
|
||||||
%feature("novaluewrapper") std::vector<Term>;
|
%feature("novaluewrapper") std::vector<Term>;
|
||||||
|
=======
|
||||||
|
>>>>>>> 11e81b457dcc145e07b457482698a90e0ec350a2
|
||||||
|
|
||||||
%ignore *::operator[];
|
%ignore *::operator[];
|
||||||
|
|
||||||
@ -255,120 +256,44 @@ case DOMAIN_ERROR_NOT_LESS_THAN_ZERO:
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
// Language independent exception handler
|
%typemap(in) arity_t { (jlong)($input); }
|
||||||
%include exception.i
|
|
||||||
|
|
||||||
%exception {
|
%typecheck(2) Int { $1 = PyLong_Check($input); }
|
||||||
|
%typecheck(3) double { $1 = PyFloat_Check($input); }
|
||||||
|
%typecheck(2) const char * { $1 = PyUnicode_Check($input); }
|
||||||
|
|
||||||
|
%typecheck(1) Term { $1 = !PyUnicode_Check($input); }
|
||||||
|
%typecheck(1) YAP_Term { $1 = PyUnicode_Check($input); }
|
||||||
|
|
||||||
|
%typecheck(0) YAPTerm { $1 = !PyUnicode_Check($input); }
|
||||||
|
|
||||||
|
|
||||||
|
%typemap(in) jlong %{
|
||||||
|
$1 = (jlong)$input;
|
||||||
|
%}
|
||||||
|
|
||||||
|
%typemap(out) arity_t { *(jlong *)&$result = $1; }
|
||||||
|
|
||||||
|
// Language independent exception handler
|
||||||
|
// simplified version
|
||||||
|
%include <exception.i>
|
||||||
|
|
||||||
|
%exception {
|
||||||
try {
|
try {
|
||||||
$action
|
$action
|
||||||
} catch (YAPError e) {
|
} catch (const std::out_of_range& e) {
|
||||||
yap_error_number en = e.getID();
|
SWIG_exception(SWIG_IndexError, e.what());
|
||||||
LOCAL_Error_TYPE = YAP_NO_ERROR;
|
} catch (const std::exception& e) {
|
||||||
switch (e.getErrorClass()) {
|
SWIG_exception(SWIG_RuntimeError, e.what());
|
||||||
case YAPC_NO_ERROR:
|
} catch (...) {
|
||||||
break;
|
SWIG_exception(SWIG_RuntimeError, "unknown exception");
|
||||||
/// bad domain, "first argument often is the predicate.
|
|
||||||
case DOMAIN_ERROR: {
|
|
||||||
switch (en) {
|
|
||||||
case DOMAIN_ERROR_OUT_OF_RANGE:
|
|
||||||
case DOMAIN_ERROR_NOT_LESS_THAN_ZERO:
|
|
||||||
SWIG_exception(SWIG_IndexError, e.text());
|
|
||||||
break;
|
|
||||||
case DOMAIN_ERROR_CLOSE_OPTION:
|
|
||||||
case DOMAIN_ERROR_ENCODING:
|
|
||||||
case DOMAIN_ERROR_PROLOG_FLAG:
|
|
||||||
case DOMAIN_ERROR_ABSOLUTE_FILE_NAME_OPTION:
|
|
||||||
case DOMAIN_ERROR_READ_OPTION:
|
|
||||||
case DOMAIN_ERROR_SET_STREAM_OPTION:
|
|
||||||
SWIG_exception(SWIG_AttributeError, e.text());
|
|
||||||
break;
|
|
||||||
case DOMAIN_ERROR_FILE_ERRORS:
|
|
||||||
case DOMAIN_ERROR_FILE_TYPE:
|
|
||||||
case DOMAIN_ERROR_IO_MODE:
|
|
||||||
case DOMAIN_ERROR_SOURCE_SINK:
|
|
||||||
case DOMAIN_ERROR_STREAM_POSITION:
|
|
||||||
SWIG_exception(SWIG_IOError, e.text());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
SWIG_exception(SWIG_ValueError, e.text());
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
/// bad arithmetic
|
|
||||||
case EVALUATION_ERROR: {
|
|
||||||
switch (en) {
|
|
||||||
case EVALUATION_ERROR_FLOAT_OVERFLOW:
|
|
||||||
case EVALUATION_ERROR_FLOAT_UNDERFLOW:
|
|
||||||
case EVALUATION_ERROR_INT_OVERFLOW:
|
|
||||||
case EVALUATION_ERROR_UNDERFLOW:
|
|
||||||
SWIG_exception(SWIG_OverflowError, e.text());
|
|
||||||
break;
|
|
||||||
case EVALUATION_ERROR_ZERO_DIVISOR:
|
|
||||||
SWIG_exception(SWIG_DivisionByZero, e.text());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
/// missing object (I/O mostly)
|
|
||||||
case EXISTENCE_ERROR:
|
|
||||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
|
||||||
break;
|
|
||||||
/// should be bound
|
|
||||||
case INSTANTIATION_ERROR_CLASS:
|
|
||||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
|
||||||
break;
|
|
||||||
/// bad access, I/O
|
|
||||||
case PERMISSION_ERROR: {
|
|
||||||
switch (en) {
|
|
||||||
case PERMISSION_ERROR_INPUT_BINARY_STREAM:
|
|
||||||
case PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM:
|
|
||||||
case PERMISSION_ERROR_INPUT_STREAM:
|
|
||||||
case PERMISSION_ERROR_INPUT_TEXT_STREAM:
|
|
||||||
case PERMISSION_ERROR_OPEN_SOURCE_SINK:
|
|
||||||
case PERMISSION_ERROR_OUTPUT_BINARY_STREAM:
|
|
||||||
case PERMISSION_ERROR_REPOSITION_STREAM:
|
|
||||||
case PERMISSION_ERROR_OUTPUT_STREAM:
|
|
||||||
case PERMISSION_ERROR_OUTPUT_TEXT_STREAM:
|
|
||||||
SWIG_exception(SWIG_OverflowError, e.text());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
|
||||||
}
|
|
||||||
} break;
|
|
||||||
/// something that could not be represented into a type
|
|
||||||
case REPRESENTATION_ERROR:
|
|
||||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
|
||||||
break;
|
|
||||||
/// not enough ....
|
|
||||||
case RESOURCE_ERROR:
|
|
||||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
|
||||||
break;
|
|
||||||
/// bad text
|
|
||||||
case SYNTAX_ERROR_CLASS:
|
|
||||||
SWIG_exception(SWIG_SyntaxError, e.text());
|
|
||||||
break;
|
|
||||||
/// OS or internal
|
|
||||||
case SYSTEM_ERROR_CLASS:
|
|
||||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
|
||||||
break;
|
|
||||||
/// bad typing
|
|
||||||
case TYPE_ERROR:
|
|
||||||
SWIG_exception(SWIG_TypeError, e.text());
|
|
||||||
break;
|
|
||||||
/// should be unbound
|
|
||||||
case UNINSTANTIATION_ERROR_CLASS:
|
|
||||||
SWIG_exception(SWIG_RuntimeError, e.text());
|
|
||||||
break;
|
|
||||||
/// escape hatch
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
%{
|
%{
|
||||||
/* Put header files here or function declarations like below */
|
/* Put header files here or function declarations like below */
|
||||||
|
|
||||||
|
|
||||||
@ -383,20 +308,35 @@ case DOMAIN_ERROR_NOT_LESS_THAN_ZERO:
|
|||||||
// it shouldn't
|
// it shouldn't
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern void init_sqlite();
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
/* turn on director wrapping Callback */
|
|
||||||
%feature("director") YAPCallback;
|
|
||||||
|
|
||||||
%include "yapa.hh"
|
/* turn on director wrapping Callback */
|
||||||
|
//%feature("director") YAPCallback;
|
||||||
|
|
||||||
%include "yapie.hh"
|
%include "yapa.hh"
|
||||||
|
|
||||||
%include "yapt.hh"
|
%include "yapie.hh"
|
||||||
|
|
||||||
%include "yapdb.hh"
|
%include "yapt.hh"
|
||||||
|
|
||||||
|
%include "yapdb.hh"
|
||||||
|
|
||||||
|
%include "yapq.hh"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
namespace std {
|
||||||
|
|
||||||
|
%template(TermVector) vector<Term>;
|
||||||
|
%feature("novaluewrapper") vector<Term>;
|
||||||
|
|
||||||
|
//%template(YAPTermVector) vector<YAPTerm>;
|
||||||
|
//%feature("novaluewrapper") vector<YAPTerm>;
|
||||||
|
};
|
||||||
|
|
||||||
%include "yapq.hh"
|
|
||||||
|
|
||||||
%init %{
|
%init %{
|
||||||
%}
|
%}
|
||||||
|
@ -546,7 +546,10 @@ initialize_prolog :-
|
|||||||
current_prolog_flag(compiled_at,AT),
|
current_prolog_flag(compiled_at,AT),
|
||||||
current_prolog_flag(version_data, yap(Mj, Mi, Patch, _) ),
|
current_prolog_flag(version_data, yap(Mj, Mi, Patch, _) ),
|
||||||
sub_atom( VersionGit, 0, 8, _, VERSIONGIT ),
|
sub_atom( VersionGit, 0, 8, _, VERSIONGIT ),
|
||||||
|
current_prolog_flag(version_data, yap(Mj, Mi, Patch, _) ),
|
||||||
|
current_prolog_flag(resource_database, Saved ),
|
||||||
format(user_error, '% YAP ~d.~d.~d-~a (compiled ~a)~n', [Mj,Mi, Patch, VERSIONGIT, AT]),
|
format(user_error, '% YAP ~d.~d.~d-~a (compiled ~a)~n', [Mj,Mi, Patch, VERSIONGIT, AT]),
|
||||||
|
format(user_error, '% database loaded from ~a~n', [Saved]),
|
||||||
fail.
|
fail.
|
||||||
'$version'.
|
'$version'.
|
||||||
|
|
||||||
|
@ -24,8 +24,6 @@
|
|||||||
|
|
||||||
:- use_system_module( '$_modules', ['$do_import'/3]).
|
:- use_system_module( '$_modules', ['$do_import'/3]).
|
||||||
|
|
||||||
:- multifile user:system_foreign/1.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -37,6 +35,11 @@
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
maplist_(_, [], []).
|
||||||
|
maplist_(Pred, [A1|L1], [A2|L2]) :-
|
||||||
|
call(Pred, A1, A2),
|
||||||
|
maplist_(Pred, L1, L2).
|
||||||
|
|
||||||
/** @pred load_foreign_files( _Files_, _Libs_, _InitRoutine_)
|
/** @pred load_foreign_files( _Files_, _Libs_, _InitRoutine_)
|
||||||
|
|
||||||
should be used, from inside YAP, to load object files produced by the C
|
should be used, from inside YAP, to load object files produced by the C
|
||||||
@ -58,96 +61,44 @@ if defined, or in the default library.
|
|||||||
YAP supports the SWI-Prolog interface to loading foreign code, the shlib package.
|
YAP supports the SWI-Prolog interface to loading foreign code, the shlib package.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
load_foreign_files(Objs,Libs,Entry) :-
|
load_foreign_files(Objs,Libs,Entry) :-
|
||||||
source_module(M),
|
source_module(M),
|
||||||
'$check_objs_for_load_foreign_files'(Objs,NewObjs,load_foreign_files(Objs,Libs,Entry)),
|
%G = load_foreign_files(Objs,Libs,Entry),
|
||||||
'$check_libs_for_load_foreign_files'(Libs,NewLibs,load_foreign_files(Objs,Libs,Entry)),
|
'$absfs'( Objs, [file_type(executable),
|
||||||
'$check_entry_for_load_foreign_files'(Entry,load_foreign_files(Objs,Libs,Entry)),
|
access(read),
|
||||||
(
|
expand(true),
|
||||||
recordzifnot( '$foreign', M:'$foreign'(Objs,Libs,Entry), _)
|
file_errors(fail)], NewObjs),
|
||||||
->
|
maplist_( '$load_lib', Libs, NewLibs),
|
||||||
|
'$load_foreign_files'(NewObjs,NewLibs,Entry),
|
||||||
|
!,
|
||||||
|
prolog_load_context(file, F),
|
||||||
|
ignore( recordzifnot( '$load_foreign_done', [F, M], _) ).
|
||||||
|
|
||||||
'$load_foreign_files'(NewObjs,NewLibs,Entry),
|
'$absfs'([],_P,[]).
|
||||||
(
|
'$absfs'([F|Fs],P,[NF|NFs]) :-
|
||||||
prolog_load_context(file, F)
|
'$name_object'(F, P, NF),
|
||||||
->
|
!,
|
||||||
ignore( recordzifnot( '$load_foreign_done', [F, M], _) )
|
'$absfs'(Fs,P,NFs).
|
||||||
;
|
'$absfs'([F|Fs],P,[F|NFs]) :-
|
||||||
true
|
'$absfs'(Fs,P,NFs).
|
||||||
)
|
|
||||||
;
|
|
||||||
true
|
|
||||||
),
|
|
||||||
!.
|
|
||||||
|
|
||||||
/** @pred load_absolute_foreign_files( _Files_, _Libs_, _InitRoutine_)
|
'$name_object'(I, P, O) :-
|
||||||
|
atom(I),
|
||||||
|
!,
|
||||||
|
absolute_file_name(foreign(I), O, P).
|
||||||
|
'$name_object'(I, P, O) :-
|
||||||
|
absolute_file_name(I, O, P).
|
||||||
|
|
||||||
|
'$load_lib'(_,L,L).
|
||||||
|
|
||||||
|
/** @pred load_absolute_foreign_files( Files, Libs, InitRoutine)
|
||||||
|
|
||||||
Loads object files produced by the C compiler. It is useful when no search should be performed and instead one has the full paths to the _Files_ and _Libs_.
|
Loads object files produced by the C compiler. It is useful when no search should be performed and instead one has the full paths to the _Files_ and _Libs_.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
load_absolute_foreign_files(Objs,Libs,Entry) :-
|
load_absolute_foreign_files(_Objs,_Libs,_Entry).
|
||||||
source_module(M),
|
|
||||||
(
|
|
||||||
recordzifnot( '$foreign', M:'$foreign'(Objs,Libs,Entry), _)
|
|
||||||
->
|
|
||||||
'$load_foreign_files'(Objs,Libs,Entry),
|
|
||||||
(
|
|
||||||
prolog_load_context(file, F)
|
|
||||||
->
|
|
||||||
ignore( recordzifnot( '$load_foreign_done', [F, M], _) )
|
|
||||||
;
|
|
||||||
true
|
|
||||||
)
|
|
||||||
;
|
|
||||||
true
|
|
||||||
),
|
|
||||||
!.
|
|
||||||
|
|
||||||
'$check_objs_for_load_foreign_files'(V,_,G) :- var(V), !,
|
|
||||||
'$do_error'(instantiation_error,G).
|
|
||||||
'$check_objs_for_load_foreign_files'([],[],_) :- !.
|
|
||||||
'$check_objs_for_load_foreign_files'([Obj|Objs],[NObj|NewObjs],G) :- !,
|
|
||||||
'$check_obj_for_load_foreign_files'(Obj,NObj,G),
|
|
||||||
'$check_objs_for_load_foreign_files'(Objs,NewObjs,G).
|
|
||||||
'$check_objs_for_load_foreign_files'(Objs,_,G) :-
|
|
||||||
'$do_error'(type_error(list,Objs),G).
|
|
||||||
|
|
||||||
'$check_obj_for_load_foreign_files'(V,_,G) :- var(V), !,
|
|
||||||
'$do_error'(instantiation_error,G).
|
|
||||||
'$check_obj_for_load_foreign_files'(Obj,NewObj,_) :- atom(Obj), !,
|
|
||||||
( atom(Obj), Obj1 = foreign(Obj) ; Obj1 = Obj ),
|
|
||||||
absolute_file_name(foreign(Obj),[file_type(executable),
|
|
||||||
access(read),
|
|
||||||
expand(true),
|
|
||||||
file_errors(fail)
|
|
||||||
], NewObj).
|
|
||||||
'$check_obj_for_load_foreign_files'(Obj,_,G) :-
|
|
||||||
'$do_error'(type_error(atom,Obj),G).
|
|
||||||
|
|
||||||
'$check_libs_for_load_foreign_files'(V,_,G) :- var(V), !,
|
|
||||||
'$do_error'(instantiation_error,G).
|
|
||||||
'$check_libs_for_load_foreign_files'([],[],_) :- !.
|
|
||||||
'$check_libs_for_load_foreign_files'([Lib|Libs],[NLib|NLibs],G) :- !,
|
|
||||||
'$check_lib_for_load_foreign_files'(Lib,NLib,G),
|
|
||||||
'$check_libs_for_load_foreign_files'(Libs,NLibs,G).
|
|
||||||
'$check_libs_for_load_foreign_files'(Libs,_,G) :-
|
|
||||||
'$do_error'(type_error(list,Libs),G).
|
|
||||||
|
|
||||||
'$check_lib_for_load_foreign_files'(V,_,G) :- var(V), !,
|
|
||||||
'$do_error'(instantiation_error,G).
|
|
||||||
'$check_lib_for_load_foreign_files'(Lib,NLib,_) :- atom(Lib), !,
|
|
||||||
'$process_obj_suffix'(Lib,NewLib),
|
|
||||||
'$checklib_prefix'(NewLib,NLib).
|
|
||||||
'$check_lib_for_load_foreign_files'(Lib,_,G) :-
|
|
||||||
'$do_error'(type_error(atom,Lib),G).
|
|
||||||
|
|
||||||
'$process_obj_suffix'(Obj,Obj) :-
|
|
||||||
current_prolog_flag(shared_object_extension, ObjSuffix),
|
|
||||||
sub_atom(Obj, _, _, 0, ObjSuffix), !.
|
|
||||||
'$process_obj_suffix'(Obj,NewObj) :-
|
|
||||||
current_prolog_flag(shared_object_extension, ObjSuffix),
|
|
||||||
atom_concat([Obj,'.',ObjSuffix],NewObj).
|
|
||||||
|
|
||||||
'$checklib_prefix'(F,F) :- is_absolute_file_name(F), !.
|
'$checklib_prefix'(F,F) :- is_absolute_file_name(F), !.
|
||||||
'$checklib_prefix'(F, F) :-
|
'$checklib_prefix'(F, F) :-
|
||||||
sub_atom(F, 0, _, _, lib), !.
|
sub_atom(F, 0, _, _, lib), !.
|
||||||
@ -163,12 +114,6 @@ load_absolute_foreign_files(Objs,Libs,Entry) :-
|
|||||||
fail.
|
fail.
|
||||||
'$import_foreign'(_F, _M0, _M).
|
'$import_foreign'(_F, _M0, _M).
|
||||||
|
|
||||||
'$check_entry_for_load_foreign_files'(V,G) :- var(V), !,
|
|
||||||
'$do_error'(instantiation_error,G).
|
|
||||||
'$check_entry_for_load_foreign_files'(Entry,_) :- atom(Entry), !.
|
|
||||||
'$check_entry_for_load_foreign_files'(Entry,G) :-
|
|
||||||
'$do_error'(type_error(atom,Entry),G).
|
|
||||||
|
|
||||||
/** @pred open_shared_object(+ _File_, - _Handle_)
|
/** @pred open_shared_object(+ _File_, - _Handle_)
|
||||||
|
|
||||||
File is the name of a shared object file (called dynamic load
|
File is the name of a shared object file (called dynamic load
|
||||||
|
@ -74,10 +74,13 @@ commons_directory( Path ):-
|
|||||||
foreign_directory(Home) :-
|
foreign_directory(Home) :-
|
||||||
current_prolog_flag(prolog_foreign_directory, Home),
|
current_prolog_flag(prolog_foreign_directory, Home),
|
||||||
Home \= ''.
|
Home \= ''.
|
||||||
|
foreign_directory(C) :-
|
||||||
|
current_prolog_flag(windows, true),
|
||||||
|
file_search_path(path, C).
|
||||||
foreign_directory( '.').
|
foreign_directory( '.').
|
||||||
foreign_directory(yap('lib/Yap')).
|
foreign_directory(yap('lib/Yap')).
|
||||||
foreign_directory( Path ):-
|
%foreign_directory( Path ):-
|
||||||
system_foreign( Path ).
|
% system_foreign( Path ).
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@pred prolog_file_type(?Suffix:atom, ?Handler:atom) is nondet, dynamic
|
@pred prolog_file_type(?Suffix:atom, ?Handler:atom) is nondet, dynamic
|
||||||
|
@ -36,13 +36,12 @@ set (LIBRARY_PL
|
|||||||
dcg/basics.pl
|
dcg/basics.pl
|
||||||
)
|
)
|
||||||
|
|
||||||
|
add_to_group( pl_library LIBRARY_PL )
|
||||||
|
|
||||||
if (ANDROID)
|
if (ANDROID)
|
||||||
file(INSTALL ${LIBRARY_PL} DESTINATION ${libpl})
|
file(INSTALL ${LIBRARY_PL} DESTINATION ${libpl})
|
||||||
else()
|
else()
|
||||||
|
|
||||||
install(FILES ${LIBRARY_PL}
|
|
||||||
DESTINATION ${libpl}
|
DESTINATION ${libpl}
|
||||||
)
|
)
|
||||||
|
|
||||||
endif()
|
|
||||||
|
Reference in New Issue
Block a user