This commit is contained in:
Vitor Santos Costa 2017-11-21 15:44:43 +00:00
parent 484213efb6
commit 06485f071a
31 changed files with 357 additions and 632 deletions

View File

@ -2304,21 +2304,23 @@ X_API char *YAP_CompileClause(Term t) {
static int yap_lineno = 0; static int yap_lineno = 0;
/* do initial boot by consulting the file boot.yap */ /* do initial boot by consulting the file boot.yap */
static void do_bootfile(const char *bootfilename USES_REGS) { static void do_bootfile(const char *b_file USES_REGS) {
Term t; Term t;
int bootfile, osno; int bootfile, osno;
Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1); Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1);
Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1); Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1);
char full[YAP_FILENAME_MAX + 1];
/* consult boot.pl */ /* consult boot.pl */
char *full = malloc(YAP_FILENAME_MAX + 1);
full[0] = '\0';
/* the consult mode does not matter here, really */ /* the consult mode does not matter here, really */
bootfile = YAP_InitConsult(YAP_BOOT_MODE, bootfilename, full, &osno); bootfile = YAP_InitConsult(YAP_BOOT_MODE, b_file, full, &osno);
if (bootfile < 0) { if (bootfile < 0) {
fprintf(stderr, "[ FATAL ERROR: could not open bootfile %s ]\n", fprintf(stderr, "[ FATAL ERROR: could not open bootfile %s ]\n",
bootfilename); b_file);
exit(1); exit(1);
} }
free(full);
do { do {
CACHE_REGS CACHE_REGS
YAP_Reset(YAP_FULL_RESET); YAP_Reset(YAP_FULL_RESET);
@ -2329,7 +2331,7 @@ static void do_bootfile(const char *bootfilename USES_REGS) {
if (t == 0) { if (t == 0) {
fprintf(stderr, fprintf(stderr,
"[ SYNTAX ERROR: while parsing bootfile %s at line %d ]\n", "[ SYNTAX ERROR: while parsing bootfile %s at line %d ]\n",
bootfilename, yap_lineno); b_file, yap_lineno);
} else if (YAP_IsVarTerm(t) || t == TermNil) { } else if (YAP_IsVarTerm(t) || t == TermNil) {
fprintf(stderr, "[ line %d: term cannot be compiled ]", yap_lineno); fprintf(stderr, "[ line %d: term cannot be compiled ]", yap_lineno);
} else if (YAP_IsPairTerm(t)) { } else if (YAP_IsPairTerm(t)) {
@ -2420,10 +2422,11 @@ static void do_bootfile(const char *bootfilename USES_REGS) {
YAP_file_type_t restore_result = yap_init->boot_file_type; YAP_file_type_t restore_result = yap_init->boot_file_type;
bool do_bootstrap = (restore_result & YAP_CONSULT_MODE); bool do_bootstrap = (restore_result & YAP_CONSULT_MODE);
CELL Trail = 0, Stack = 0, Heap = 0, Atts = 0; CELL Trail = 0, Stack = 0, Heap = 0, Atts = 0;
char boot_file[YAP_FILENAME_MAX + 1]; char *boot_file;
Int rc; Int rc;
const char *yroot; const char *yroot;
boot_file = calloc(YAP_FILENAME_MAX + 1, 1);
/* ignore repeated calls to YAP_Init */ /* ignore repeated calls to YAP_Init */
if (YAP_initialized) if (YAP_initialized)
return YAP_FOUND_BOOT_ERROR; return YAP_FOUND_BOOT_ERROR;
@ -2467,9 +2470,10 @@ static void do_bootfile(const char *bootfilename USES_REGS) {
if (yap_init->YapPrologBootFile == NULL) if (yap_init->YapPrologBootFile == NULL)
yap_init->YapPrologBootFile = BootFile; yap_init->YapPrologBootFile = BootFile;
#else #else
yap_init->YapPrologBootFile =
Yap_findFile(yap_init->YapPrologBootFile, BootFile, yroot, boot_file, const char *s = Yap_findFile(yap_init->YapPrologBootFile, BootFile, yroot, boot_file,
true, YAP_BOOT_PL, true, true); true, YAP_BOOT_PL, true, true);
if (s && s[0] != '\0') strcpy(boot_file, s);
#endif #endif
} }
@ -2619,18 +2623,17 @@ static void do_bootfile(const char *bootfilename USES_REGS) {
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, true); setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, true);
rc = YAP_QLY; rc = YAP_QLY;
} else { } else {
if (!yap_init->YapPrologBootFile) if (boot_file[0] == '\0')
yap_init->YapPrologBootFile = BootFile; strcpy(boot_file, BootFile);
rc = YAP_BOOT_PL; do_bootfile(boot_file PASS_REGS);
do_bootfile(yap_init->YapPrologBootFile);
setAtomicGlobalPrologFlag( setAtomicGlobalPrologFlag(
RESOURCE_DATABASE_FLAG, RESOURCE_DATABASE_FLAG,
MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologBootFile))); MkAtomTerm(Yap_LookupAtom(boot_file)));
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false); setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false);
} }
start_modules(); start_modules();
YAP_initialized = true; YAP_initialized = true;
return rc; return YAP_BOOT_PL;
} }
#if (DefTrailSpace < MinTrailSpace) #if (DefTrailSpace < MinTrailSpace)

View File

@ -31,6 +31,11 @@ inline static size_t min_size(size_t i, size_t j) { return (i < j ? i : j); }
#define wcsnlen(S, N) min_size(N, wcslen(S)) #define wcsnlen(S, N) min_size(N, wcslen(S))
#endif #endif
#ifndef HAVE_STPCPY
inline static void* __stpcpy(void * i, const void * j) { return strcpy(i,j)+strlen(j);}
#define stpcpy __stpcpy
#endif
#ifndef NAN #ifndef NAN
#define NAN (0.0 / 0.0) #define NAN (0.0 / 0.0)
#endif #endif
@ -993,7 +998,7 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
return false; return false;
} }
b_l0 = strlen((const char *)buf0); b_l0 = strlen((const char *)buf0);
if (bcmp(buf, buf0, b_l0) != 0) { if (memcmp(buf, buf0, b_l0) != 0) {
return false; return false;
} }
u_l0 = strlen_utf8(buf0); u_l0 = strlen_utf8(buf0);
@ -1016,7 +1021,7 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
u_l1 = strlen_utf8(buf1); u_l1 = strlen_utf8(buf1);
b_l0 = b_l - b_l1; b_l0 = b_l - b_l1;
u_l0 = u_l - u_l1; u_l0 = u_l - u_l1;
if (bcmp(skip_utf8((const unsigned char *)buf, b_l0), buf1, b_l1) != if (memcmp(skip_utf8((const unsigned char *)buf, b_l0), buf1, b_l1) !=
0) { 0) {
return false; return false;
} }
@ -1043,35 +1048,6 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
return true; return true;
} }
/**
* Function to convert a generic text term (string, atom, list of codes, list
of<
atoms) into a buff
er.
*
* @param t the term
* @param buf the buffer, if NULL a buffer is malloced, and the user should
reclai it
* @param len buffer size
* @param enc encoding (UTF-8 is strongly recommended)
*
* @return the buffer, or NULL in case of failure. If so, Yap_Error may be
called.
*/
const char *Yap_TextTermToText(Term t USES_REGS) {
seq_tv_t inp, out;
inp.val.t = t;
inp.type = Yap_TextType(t);
inp.type = YAP_STRING_ATOM | YAP_STRING_STRING | YAP_STRING_ATOMS_CODES |
YAP_STRING_TERM;
inp.enc = ENC_ISO_UTF8;
out.enc = ENC_ISO_UTF8;
out.type = YAP_STRING_CHARS;
out.val.c = NULL;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return NULL;
return out.val.c;
}
/** /**
* Convert from a predicate structure to an UTF-8 string of the form * Convert from a predicate structure to an UTF-8 string of the form

View File

@ -496,11 +496,7 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
} else if (!strncmp("-home=", p, strlen("-home="))) { } else if (!strncmp("-home=", p, strlen("-home="))) {
GLOBAL_Home = p + strlen("-home="); GLOBAL_Home = p + strlen("-home=");
} else if (!strncmp("-cwd=", p, strlen("-cwd="))) { } else if (!strncmp("-cwd=", p, strlen("-cwd="))) {
#if __WINDOWS__ if (!ChDir(p + strlen("-cwd=")) ) {
if (_chdir(p + strlen("-cwd=")) < 0) {
#else
if (chdir(p + strlen("-cwd=")) < 0) {
#endif
fprintf(stderr, " [ YAP unrecoverable error in setting cwd: %s ]\n", fprintf(stderr, " [ YAP unrecoverable error in setting cwd: %s ]\n",
strerror(errno)); strerror(errno));
} }

View File

@ -249,9 +249,6 @@ if (APPLE)
endif () endif ()
endif () endif ()
if (ANDROID)
set(datarootdir /assets)
endif ()
set(prefix ${CMAKE_INSTALL_PREFIX}) #BINDIR}) set(prefix ${CMAKE_INSTALL_PREFIX}) #BINDIR})
set(bindir ${CMAKE_INSTALL_PREFIX}/bin) #BINDIR}) set(bindir ${CMAKE_INSTALL_PREFIX}/bin) #BINDIR})
set(includedir ${CMAKE_INSTALL_PREFIX}/include) #INCLUDEDIR}) set(includedir ${CMAKE_INSTALL_PREFIX}/include) #INCLUDEDIR})
@ -259,6 +256,10 @@ set(libdir ${CMAKE_INSTALL_PREFIX}/lib) #LIBDIR})
set(exec_prefix ${CMAKE_INSTALL_PREFIX}/libexec) #LIBEXECDIR}) set(exec_prefix ${CMAKE_INSTALL_PREFIX}/libexec) #LIBEXECDIR})
set(datarootdir ${CMAKE_INSTALL_PREFIX}/share) #DATAROOTDIR}) set(datarootdir ${CMAKE_INSTALL_PREFIX}/share) #DATAROOTDIR})
set(datadir ${CMAKE_INSTALL_PREFIX}/share) #DATADIR}) set(datadir ${CMAKE_INSTALL_PREFIX}/share) #DATADIR})
if (ANDROID)
set(datarootdir ${YAP_APP_DIR}/src/generated/assets)
set(datadir ${YAP_APP_DIR}/src/generated/assets)
endif ()
set(mandir ${CMAKE_INSTALL_PREFIX}/share/man) #MANDIR}) set(mandir ${CMAKE_INSTALL_PREFIX}/share/man) #MANDIR})
set(docdir ${CMAKE_INSTALL_PREFIX}/share/docs) #MANDIR}) set(docdir ${CMAKE_INSTALL_PREFIX}/share/docs) #MANDIR})
@ -458,7 +459,7 @@ endif ()
OPTION(WITH_SWIG " Enable SWIG interfaces to foreign languages" ON) OPTION(WITH_SWIG " Enable SWIG interfaces to foreign languages" ON)
IF (WITH_SWIG OR ANDROID) IF (WITH_SWIG)
find_host_package(SWIG) find_host_package(SWIG)
# macro_log_feature (SWIG_FOUND "Swig" # macro_log_feature (SWIG_FOUND "Swig"
# "Use SWIG Interface Generator " # "Use SWIG Interface Generator "
@ -614,11 +615,6 @@ ADD_SUBDIRECTORY(library)
ADD_SUBDIRECTORY(swi/library "swiLibrary") ADD_SUBDIRECTORY(swi/library "swiLibrary")
if (ANDROID)
target_link_libraries(libYap android log)
endif ()
set_target_properties(libYap set_target_properties(libYap
PROPERTIES OUTPUT_NAME Yap PROPERTIES OUTPUT_NAME Yap
) )
@ -638,8 +634,9 @@ if (PYTHONLIBS_FOUND AND SWIG_FOUND)
endif () endif ()
IF (SWIG_FOUND OR ANDROID) IF ( ANDROID)
add_subDIRECTORY(packages/swig NO_POLICY_SCOPE) add_subDIRECTORY(packages/swig )
target_link_libraries(libYap android log)
ENDIF () ENDIF ()
@ -801,9 +798,11 @@ CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_MMAP "Use MMAP for shared memory allocation"
CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_SHM "Use SHM for shared memory allocation" ON CMAKE_DEPENDENT_OPTION(WITH_SYSTEM_SHM "Use SHM for shared memory allocation" ON
"NOT WITH_YAPOR_THOR; NOT WITH_SYSTEM_MMAP" OFF) "NOT WITH_YAPOR_THOR; NOT WITH_SYSTEM_MMAP" OFF)
if (NOT ANDROID)
add_subDIRECTORY(library/lammpi) add_subDIRECTORY(library/lammpi)
if (MPI_C_FOUND) if (MPI_C_FOUND\D)
CMAKE_DEPENDENT_OPTION(WITH_MPI ON "Interface to OpenMPI/MPICH" CMAKE_DEPENDENT_OPTION(WITH_MPI ON "Interface to OpenMPI/MPICH"
"MPI_C_FOUND" OFF) "MPI_C_FOUND" OFF)
@ -822,6 +821,8 @@ if (MPI_C_FOUND)
endif () endif ()
endif (MPI_C_FOUND) endif (MPI_C_FOUND)
endif(NOT ANDROID)
## add_subDIRECTORY(utils) ## add_subDIRECTORY(utils)
# #

View File

@ -625,7 +625,7 @@ Term YAPEngine::fun(Term t)
return 0; return 0;
} }
DBTerm *pt = Yap_StoreTermInDB(Yap_GetFromSlot(o), arity); DBTerm *pt = Yap_StoreTermInDB(Yap_GetFromSlot(o), arity);
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %ld", o); __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", o);
YAP_LeaveGoal(false, &q); YAP_LeaveGoal(false, &q);
Yap_CloseHandles(q.CurSlot); Yap_CloseHandles(q.CurSlot);
Term rc = Yap_PopTermFromDB(pt); Term rc = Yap_PopTermFromDB(pt);
@ -751,8 +751,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", "vnames %d %s %d",
q_state, vnames.text(), LOCAL_CurSlot); q_state, names.text(), LOCAL_CurSlot);
} }
else else
{ {
@ -892,6 +892,8 @@ static size_t Yap_AndroidMax, Yap_AndroidSz;
extern void (*Yap_DisplayWithJava)(int c); extern void (*Yap_DisplayWithJava)(int c);
static YAPCallback *cb = new YAPCallback();
void Yap_displayWithJava(int c) void Yap_displayWithJava(int c)
{ {
char *ptr = Yap_AndroidBufp; char *ptr = Yap_AndroidBufp;
@ -914,11 +916,12 @@ void Yap_displayWithJava(int c)
if (c == '\n') if (c == '\n')
{ {
Yap_AndroidBufp[Yap_AndroidSz] = '\0'; Yap_AndroidBufp[Yap_AndroidSz] = '\0';
curren->run(Yap_AndroidBufp); cb->run(Yap_AndroidBufp);
Yap_AndroidSz = 0; Yap_AndroidSz = 0;
} }
} }
#endif #endif
@ -961,10 +964,13 @@ YAPEngine::YAPEngine(int argc, char *argv[],
// delYAPCallback()b // delYAPCallback()b
// if (cb) // if (cb)
// setYAPCallback(cb); // setYAPCallback(cb);
doInit(BootMode); doInit(BootMode);
} }
YAPPredicate::YAPPredicate(YAPAtom at) YAPPredicate::YAPPredicate(YAPAtom at)
{ {
CACHE_REGS CACHE_REGS

View File

@ -25,6 +25,10 @@ class X_API YAPPredicate;
Queries and engines Queries and engines
*/ */
#if __ANDROID__
#endif
/** /**
* @brief Queries * @brief Queries
* *
@ -94,11 +98,11 @@ YAPQuery() {
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 %d",
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);
if (IsPairTerm(tgoal)) { if (IsPairTerm(tgoal)) {
qt = RepPair(tgoal); qt = RepPair(tgoal);
@ -151,6 +155,7 @@ void close();
/// query variables. /// query variables.
void cut(); void cut();
Term namedVars() {return names.term(); }; Term namedVars() {return names.term(); };
YAPPairTerm namedVarTerms() {return names; };
/// query variables, but copied out /// query variables, but copied out
std::vector<Term> namedVarsVector() { std::vector<Term> namedVarsVector() {
return names.listToArray(); }; return names.listToArray(); };
@ -317,6 +322,14 @@ public:
return init_args.FastBoot; return init_args.FastBoot;
}; };
#if __ANDROID__
//> export ResoourceManager
inline void setAssetManager( AAssetManager *mgr )
{
init_args.assetManager = mgr;
};
#endif
inline void setArgc( int fl ) inline void setArgc( int fl )
{ {
init_args.Argc = fl; init_args.Argc = fl;

View File

@ -112,6 +112,17 @@ public:
inline Term term() { inline Term term() {
return gt(); return gt();
} /// from YAPTerm to Term (internal YAP representation) } /// from YAPTerm to Term (internal YAP representation)
YAPTerm arg(int i) {
BACKUP_MACHINE_REGS();
Term t0 = gt();
YAPTerm tf;
if (!IsApplTerm(t0) && !IsPairTerm(t))
return (Term)0;
tf = YAPTerm(ArgOfTerm(i, t0) );
RECOVER_MACHINE_REGS();
return tf;
};
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)
@ -354,6 +365,9 @@ public:
YAPPairTerm(); YAPPairTerm();
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())); }
bool nil() { return gt() == TermNil; }
YAPPairTerm cdr() { return YAPPairTerm(TailOfTerm(gt())); }
std::vector<Term> listToArray() { std::vector<Term> listToArray() {
Term *tailp; Term *tailp;
Term t1 = gt(); Term t1 = gt();

View File

@ -1433,6 +1433,38 @@ static inline void Yap_OverwriteUTF8BufferToLowCase(void *buf USES_REGS) {
} }
} }
/**
* Function to convert a generic text term (string, atom, list of codes, list
of<
atoms) into a buff
er.
*
* @param t the term
* @param buf the buffer, if NULL a buffer is malloced, and the user should
reclai it
* @param len buffer size
* @param enc encoding (UTF-8 is strongly recommended)
*
* @return the buffer, or NULL in case of failure. If so, Yap_Error may be
called.
*
* notice that it must be called from a push memory.
*/
static inline const char *Yap_TextTermToText(Term t0 USES_REGS) {
seq_tv_t inp, out;
inp.val.t = t0;
inp.type = YAP_STRING_ATOM | YAP_STRING_STRING | YAP_STRING_CODES |
YAP_STRING_ATOMS_CODES | YAP_STRING_MALLOC;
out.val.uc = NULL;
out.type = YAP_STRING_CHARS;
out.enc = ENC_ISO_UTF8;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return NULL;
return out.val.c0;
}
static inline const unsigned char *Yap_TextToUTF8Buffer(Term t0 USES_REGS) { static inline const unsigned char *Yap_TextToUTF8Buffer(Term t0 USES_REGS) {
seq_tv_t inp, out; seq_tv_t inp, out;
@ -1444,7 +1476,7 @@ static inline const unsigned char *Yap_TextToUTF8Buffer(Term t0 USES_REGS) {
out.enc = ENC_ISO_UTF8; out.enc = ENC_ISO_UTF8;
if (!Yap_CVT_Text(&inp, &out PASS_REGS)) if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return 0L; return NULL;
return out.val.uc0; return out.val.uc0;
} }
@ -1642,5 +1674,4 @@ static inline Term Yap_SubtractTailString(Term t1, Term th USES_REGS) {
#endif // ≈YAP_TEXT_H #endif // ≈YAP_TEXT_H
extern const char *Yap_TextTermToText(Term t USES_REGS);
extern Term Yap_MkTextTerm(const char *s, int guide USES_REGS); extern Term Yap_MkTextTerm(const char *s, int guide USES_REGS);

View File

@ -306,7 +306,6 @@ extern void Yap_CloseReadline(void);
extern bool Yap_InitReadline(Term t); extern bool Yap_InitReadline(Term t);
extern void Yap_InitItDeepenPreds(void); extern void Yap_InitItDeepenPreds(void);
extern struct AliasDescS *Yap_InitStandardAliases(void); extern struct AliasDescS *Yap_InitStandardAliases(void);
extern struct vfs *Yap_InitAssetManager(void);
/* load_foreign.c */ /* load_foreign.c */
extern void Yap_InitLoadForeign(void); extern void Yap_InitLoadForeign(void);
@ -436,6 +435,8 @@ extern const char *Yap_AbsoluteFileInBuffer(const char *spec, char *outp, size_t
extern const char *Yap_findFile(const char *isource, const char *idef, extern const char *Yap_findFile(const char *isource, const char *idef,
const char *root, char *result, bool access, const char *root, char *result, bool access,
YAP_file_type_t ftype, bool expand_root, bool in_lib); YAP_file_type_t ftype, bool expand_root, bool in_lib);
extern bool ChDir(const char *path);
/* threads.c */ /* threads.c */
extern void Yap_InitThreadPreds(void); extern void Yap_InitThreadPreds(void);
extern void Yap_InitFirstWorkerThreadHandle(void); extern void Yap_InitFirstWorkerThreadHandle(void);

View File

@ -10,12 +10,27 @@
if (ANDROID) if (ANDROID)
set( GMP_ROOT ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI} )
set (GMP_INCLUDE_DIRS ${GMP_ROOT}) set( GMP_LOC ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI} )
set (GMP_LIBRARIES ${GMP_ROOT}/libgmp.so) if (EXISTS ${GMP_LOC} )
set (GMP_FOUND ON) message("Looking good for ${GMP_LOC}")
set (GMP_LIBRARIES_DIR ${GMP_ROOT}) set(GMP_INCLUDE_DIRS ${GMP_LOC} CACHE PATH "include search path")
elif(MSVC) set(GMP_LIBRARIES ${GMP_LOC}/libgmp.so CACHE FILEPATH "include search path")
set(GMP_LIBRARIES_DIR ${GMP_LOC} CACHE PATH "include search path")
else()
message("Bad call: ${GMP_LOC} does not exist")
endif()
find_path(GMP_INCLUDE_DIRS
NAMES gmp.h
HINTS ${GMP_LOC}
NO_SYSTEM_ENVIRONMENT_PATH)
find_library(GMP_LIBRARIES NAMES gmp
PATHS
${GMP_ROOT}
NO_SYSTEM_ENVIRONMENT_PATH)
elseif(MSVC)
find_library(GMP_LIBRARIES NAMES mpir mpird find_library(GMP_LIBRARIES NAMES mpir mpird
PATHS PATHS
$ENV{GMP_ROOT} $ENV{GMP_ROOT}
@ -84,6 +99,7 @@ else()
${GMP_LIBRARIES_DIR}/../include ${GMP_LIBRARIES_DIR}/../include
${GMP_LIBRARIES_DIR} ${GMP_LIBRARIES_DIR}
) )
endif()
get_filename_component(GMP_LIBRARIES_DIR "${GMP_LIBRARIES}" PATH CACHE) get_filename_component(GMP_LIBRARIES_DIR "${GMP_LIBRARIES}" PATH CACHE)
@ -101,5 +117,4 @@ endif()
mark_as_advanced(GMP_LIBRARIES GMP_LIBRARIES_DIR GMP_INCLUDE_DIRS) mark_as_advanced(GMP_LIBRARIES GMP_LIBRARIES_DIR GMP_INCLUDE_DIRS)
endif()

View File

@ -33,6 +33,7 @@
#include <encoding.h> #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) */
@ -77,10 +78,9 @@ typedef struct vfs {
/// a way to identify a file in this VFS: two special cases, prefix and suffix /// a way to identify a file in this VFS: two special cases, prefix and suffix
const char *prefix; const char *prefix;
const char *suffix; const char *suffix;
bool (*id)(struct vfs *me, const char *s); bool (*chDir)(struct vfs *me, const char *s);
/** operations */ /** operations */
void *(*open)(const char *s, void *(*open)(int sno, const char *fname, const char *io_mode); /// open an object
const char *io_mode); /// open an object
/// in this space, usual w,r,a,b flags plus B (store in a buffer) /// in this space, usual w,r,a,b flags plus B (store in a buffer)
bool (*close)(int sno); /// close the object bool (*close)(int sno); /// close the object
int (*get_char)(int sno); /// get an octet to the stream int (*get_char)(int sno); /// get an octet to the stream
@ -88,15 +88,15 @@ typedef struct vfs {
void (*flush)(int sno); /// flush a stream void (*flush)(int sno); /// flush a stream
int64_t (*seek)(int sno, int64_t offset, int64_t (*seek)(int sno, int64_t offset,
int whence); /// jump around the stream int whence); /// jump around the stream
void *(*opendir)(const char *s); /// open a directory object, if one exists void *(*opendir)(struct vfs *,const char *s); /// open a directory object, if one exists
const char *(*nextdir)(void *d); /// walk to the next entry in a directory object const char *(*nextdir)(void *d); /// walk to the next entry in a directory object
void (*closedir)(void *d); bool (*closedir)(void *d);
; /// close access a directory object ; /// close access a directory object
bool (*stat)(const char *s, bool (*stat)(const char *s,
vfs_stat *); /// obtain size, age, permissions of a file. vfs_stat *); /// obtain size, age, permissions of a file.
bool (*isdir)(const char *s); /// verify whether is directory. bool (*isdir)(struct vfs *,const char *s); /// verify whether is directory.
bool (*exists)(const char *s); /// verify whether a file exists. bool (*exists)(struct vfs *, const char *s); /// verify whether a file exists.
bool (*chdir)(const char *s); /// set working directory (may be virtual). bool (*chdir)(struct vfs *,const char *s); /// set working directory (may be virtual).
encoding_t enc; /// default file encoded. encoding_t enc; /// default file encoded.
YAP_Term (*parsers)(int sno); // a set of parsers that can read the YAP_Term (*parsers)(int sno); // a set of parsers that can read the
// stream and generate a YAP_Term // stream and generate a YAP_Term
@ -121,12 +121,15 @@ static inline VFS_t *vfs_owner(const char *fname) {
size_t sz0 = strlen(fname), sz; size_t sz0 = strlen(fname), sz;
while (me) { while (me) {
if ((me->vflags & VFS_HAS_PREFIX) && strstr(fname, me->prefix) == fname) bool p = true;
if ((me->vflags & VFS_HAS_PREFIX) && p) {
const char *r = fname, *s = me->prefix;
while (*s && p) p = *s++ == *r++;
if (p && r > fname+1)
return me; return me;
}
if (me->vflags & VFS_HAS_SUFFIX && (sz = strlen(me->suffix)) && (d = (sz0 - sz)) >= 0 && if (me->vflags & VFS_HAS_SUFFIX && (sz = strlen(me->suffix)) && (d = (sz0 - sz)) >= 0 &&
strcmp(fname + d, me->suffix) == 0) strcmp(fname + d, me->suffix) == 0) {
return me;
if (me->vflags & VFS_HAS_FUNCTION && (me->id(me, fname))) {
return me; return me;
} }
me = me->next; me = me->next;

View File

@ -189,6 +189,11 @@ typedef encoding_t YAP_encoding_t;
#endif #endif
#if __ANDROID__
#include <android/asset_manager.h>
#include <android/native_activity.h>
#endif
typedef struct YAP_thread_attr_struct { typedef struct YAP_thread_attr_struct {
size_t ssize; size_t ssize;
size_t tsize; size_t tsize;
@ -322,6 +327,10 @@ typedef struct yap_boot_params {
int QuietMode; int QuietMode;
//> 0, maintain default, > 0 use fd-1, < 0 close //> 0, maintain default, > 0 use fd-1, < 0 close
int inp, out, err; int inp, out, err;
#if __ANDROID__
//> android asset support
AAssetManager *assetManager;
#endif
/* support nf's ypp preprocessor code */ /* support nf's ypp preprocessor code */
#define YAP_MAX_YPP_DEFS 100 #define YAP_MAX_YPP_DEFS 100
char *def_var[YAP_MAX_YPP_DEFS]; char *def_var[YAP_MAX_YPP_DEFS];

View File

@ -76,8 +76,8 @@ MY_add_subdirectory(ytest)
add_to_group( LIBRARY_PL pl_library) add_to_group( LIBRARY_PL pl_library)
if (0) install(FILES ${LIBRARY_PL} DESTINATION ${libpl})
file(COPY ${LIBRARY_PL} DESTINATION ${libpl})
else() if (ANDROID)
install(FILES ${LIBRARY_PL} DESTINATION ${libpl}) file( INSTALL ${LIBRARY_PL} DESTINATION ${libpl} )
endif() endif()

View File

@ -33,41 +33,30 @@ static char SccsId[] = "%W% %G%";
// for native asset manager // for native asset manager
#include <sys/types.h> #include <sys/types.h>
#if __ANDROID__0
#if __ANDROID__
#include <android/asset_manager.h>
#include <android/native_activity.h>
static AAssetManager * getMgr(struct vfs *me) AAssetManager * Yap_assetManager;
jboolean Java_pt_up_yap_app_assetAssetManager(JNIEnv* env, jclass clazz, jobject assetManager)
{ {
return me->priv[0].mgr; Yap_assetManager = AAssetManager_fromJava(env, assetManager);
}
void
Java_pt_up_yap_app_YAPDroid_load(JNIEnv *env,
jobject assetManager) {
AAssetManager *mgr = AAssetManager_fromJava(env, assetManager);
if (mgr == NULL) {
return;
}
VFS_t *me = GLOBAL_VFS;
while ( strcmp(me->name, "/assets") == 0)
me = me->next;
me->priv[0].mgr = mgr;
} }
static bool static void *
open_asset(struct vfs *me, struct stream_desc *st, const char *fname, const char open_asset__
( int sno, const char *fname, const char
*io_mode) *io_mode)
{ {
AAssetManager *mgr;
int mode; int mode;
const void *buf; const void *buf;
VFS_t *me = GLOBAL_Stream[sno].vfs;
if (strstr(fname,"/assets") == fname) { if (strstr(fname,"/assets") == fname) {
// we're in // we're in
mgr = getMgr(me); if ( Yap_assetManager == NULL) {
if (mgr == NULL) {
return PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil, return PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil,
"asset manager", "asset manager",
fname); fname);
@ -79,61 +68,58 @@ open_asset(struct vfs *me, struct stream_desc *st, const char *fname, const char
} }
if (strchr(io_mode, 'B')) if (strchr(io_mode, 'B'))
mode = AASSET_MODE_BUFFER; mode = AASSET_MODE_BUFFER;
else else {
{
mode = AASSET_MODE_UNKNOWN; mode = AASSET_MODE_UNKNOWN;
} }
AAsset *a = AAssetManager_open(mgr , fname, mode); AAsset *a = AAssetManager_open( Yap_assetManager, fname, mode);
// try not to use it as an asset // try not to use it as an asset
off64_t sz = AAsset_getLength64(a), sz0 = 0; off64_t sz = AAsset_getLength64(a), sz0 = 0;
int fd; int fd;
StreamDesc *st = GLOBAL_Stream+sno;
if ((fd = AAsset_openFileDescriptor64(a, &sz0, &sz)) >= 0) { if ((fd = AAsset_openFileDescriptor64(a, &sz0, &sz)) >= 0) {
// can use it as red-only file // can use it as red-only file
st->file = fdopen( fd, "r"); st->file = fdopen(fd, "r");
st->vfs = me; st->vfs = me;
st->vfs_handle = a; st->vfs_handle = a;
return true; return a;
} else if ((buf = AAsset_getBuffer(a)) ) { } else if ((buf = AAsset_getBuffer(a))) {
// copy to memory // copy to memory
bool rc = Yap_set_stream_to_buf(st, buf, sz); bool rc = Yap_set_stream_to_buf(st, buf, sz);
AAsset_close(a); AAsset_close(a);
return rc; return rc;
} }
// should be done, but if not // should be done, but if not
st->vfs_handle = a; GLOBAL_Stream[sno].vfs_handle= a;
st->vfs = me; st->vfs = me;
return true; return true;
} }
if (me->next) {
return me->next->open(me->next, st, fname, io_mode);
}
return NULL; return NULL;
} }
static bool static bool
close_asset(struct stream_desc *st) close_asset(int sno)
{ {
AAsset_close(st->vfs_handle); AAsset_close(GLOBAL_Stream[sno].vfs_handle);
return true; return true;
} }
static int64_t seek64(struct stream_desc *st, int64_t offset, int whence) static int64_t seek64(int sno, int64_t offset, int whence)
{ {
return AAsset_seek64(st->vfs_handle, offset, whence); return AAsset_seek64(GLOBAL_Stream[sno].vfs_handle, offset, whence);
} }
static int getc_asset(struct stream_desc *st) static int getc_asset(int sno)
{ {
int ch; int ch;
if ( AAsset_read (st->vfs_handle, &ch, 1) ) if ( AAsset_read (GLOBAL_Stream[sno].vfs_handle, &ch, 1) )
return ch; return ch;
return -1; return -1;
} }
static void *opendir_a(struct vfs *me, const char *dirName) static void *opendir_a( VFS_t *me, const char *dirName)
{ {
return (void *)AAssetManager_openDir (getMgr(me), dirName); return (void *)AAssetManager_openDir (Yap_assetManager, dirName);
} }
static const char *readdir_a(void *dirHandle) static const char *readdir_a(void *dirHandle)
@ -148,10 +134,10 @@ static bool closedir_a(void *dirHandle)
} }
static bool stat_a(struct vfs *me, const char *fname, vfs_stat *out) static bool stat_a(VFS_t *me, const char *fname, vfs_stat *out)
{ {
struct stat64 bf; struct stat bf;
if (stat64( "/assets", &bf)) { if (stat( "/assets", &bf)) {
out->st_dev = bf.st_dev; out->st_dev = bf.st_dev;
out->st_uid = bf.st_uid; out->st_uid = bf.st_uid;
@ -161,8 +147,7 @@ static bool stat_a(struct vfs *me, const char *fname, vfs_stat *out)
memcpy(&out->st_ctimespec, (const void *)&out->st_ctimespec, sizeof(struct timespec)); memcpy(&out->st_ctimespec, (const void *)&out->st_ctimespec, sizeof(struct timespec));
memcpy(&out->st_birthtimespec, (const void *)&out->st_birthtimespec, sizeof(struct timespec)); memcpy(&out->st_birthtimespec, (const void *)&out->st_birthtimespec, sizeof(struct timespec));
} }
AAssetManager *mgr = getMgr(me); AAsset *a = AAssetManager_open( Yap_assetManager , fname, AASSET_MODE_UNKNOWN);
AAsset *a = AAssetManager_open(mgr , fname, AASSET_MODE_UNKNOWN);
// try not to use it as an asset // try not to use it as an asset
out->st_size = AAsset_getLength64(a); out->st_size = AAsset_getLength64(a);
AAsset_close(a); AAsset_close(a);
@ -171,11 +156,11 @@ static bool stat_a(struct vfs *me, const char *fname, vfs_stat *out)
} }
static static
bool is_dir_a(struct vfs *me, const char *dirName) bool is_dir_a( VFS_t *me,const char *dirName)
{ {
bool rc; bool rc;
// try not to use it as an asset // try not to use it as an asset
AAssetDir *d = AAssetManager_openDir (getMgr(me), dirName); AAssetDir *d = AAssetManager_openDir ( Yap_assetManager, dirName);
if (d == NULL) if (d == NULL)
return false; return false;
rc = (AAssetDir_getNextFileName(d) != NULL); rc = (AAssetDir_getNextFileName(d) != NULL);
@ -184,10 +169,10 @@ bool is_dir_a(struct vfs *me, const char *dirName)
} }
static static
bool exists_a(struct vfs *me, const char *dirName) bool exists_a(VFS_t *me, const char *dirName)
{ {
// try not to use it as an asset // try not to use it as an asset
AAsset *d = AAssetManager_open (getMgr(me), dirName, AASSET_MODE_UNKNOWN); AAsset *d = AAssetManager_open ( Yap_assetManager, dirName, AASSET_MODE_UNKNOWN);
if (d == NULL) if (d == NULL)
return false; return false;
AAsset_close(d); AAsset_close(d);
@ -195,11 +180,11 @@ bool exists_a(struct vfs *me, const char *dirName)
} }
static bool set_cwd (struct vfs *me, const char *dirName) { static bool set_cwd (VFS_t *me, const char *dirName) {
chdir("/assets"); chdir("/assets");
if (me->virtual_cwd) if (me->virtual_cwd)
free(me->virtual_cwd); free((void*)(me->virtual_cwd));
me->virtual_cwd = malloc( sizeof(dirName) + 1 ); me->virtual_cwd = malloc( sizeof(dirName) + 1 );
return me!= NULL; return me!= NULL;
} }
@ -209,21 +194,22 @@ static bool set_cwd (struct vfs *me, const char *dirName) {
/* create a new alias arg for stream sno */ /* create a new alias arg for stream sno */
VFS_t * VFS_t *
Yap_InitAssetManager(void) Yap_InitAssetManager( AAssetManager* mgr )
{ {
#if __ANDROID__O #if __ANDROID__
VFS_t *me; VFS_t *me;
Yap_assetManager = mgr;
/* init standard VFS */ /* init standard VFS */
me = (VFS_t *)Yap_AllocCodeSpace(sizeof(struct vfs)); me = (VFS_t *)Yap_AllocCodeSpace(sizeof(struct vfs));
me->name = "/assets"; me->name = "/assets";
me->vflags = VFS_CAN_EXEC|VFS_CAN_SEEK|VFS_HAS_PREFIX; /// the main flags describing the operation of the Fs. me->vflags = VFS_CAN_EXEC|VFS_CAN_SEEK|VFS_HAS_PREFIX; /// the main flags describing the operation of the Fs.
me->prefix = "/assets"; me->prefix = "/assets";
/** operations */ /** operations */
me->open = open_asset; /// open an object in this space me->open = open_asset__; /// open an object in this space
me->close= close_asset; /// close the object me->close= close_asset; /// close the object
me->get_char = getc_asset; /// get an octet to the stream me->get_char = getc_asset; /// get an octet to the stream
me->putc = NULL; /// output an octet to the stream me->put_char = NULL; /// output an octet to the stream
me->seek = seek64; /// jump around the stream me->seek = seek64; /// jump around the stream
me->opendir = opendir_a; /// open a directory object, if one exists me->opendir = opendir_a; /// open a directory object, if one exists
me->nextdir = readdir_a; /// open a directory object, if one exists me->nextdir = readdir_a; /// open a directory object, if one exists

View File

@ -865,7 +865,7 @@ as those for `put` (see 6.11).
static Int skip_1(USES_REGS1) { /* 'skip'(N) */ static Int skip_1(USES_REGS1) { /* 'skip'(N) */
Int n; Int n;
Term t1; Term t1;
int sno; int sno = LOCAL_c_output_stream;
int ch; int ch;
if (IsVarTerm(t1 = Deref(ARG1))) { if (IsVarTerm(t1 = Deref(ARG1))) {

View File

@ -25,6 +25,7 @@ static char SccsId[] = "%W% %G%";
*/ */
#include "sysbits.h" #include "sysbits.h"
#include "yapio.h"
#if _MSC_VER || defined(__MINGW32__) #if _MSC_VER || defined(__MINGW32__)
#define SYSTEM_STAT _stat #define SYSTEM_STAT _stat

View File

@ -246,20 +246,18 @@ static void unix_upd_stream_info(StreamDesc *s) {
void Yap_DefaultStreamOps(StreamDesc *st) { void Yap_DefaultStreamOps(StreamDesc *st) {
CACHE_REGS CACHE_REGS
if (st->vfs) {
st->stream_wputc = st->vfs->put_char;
st->stream_wgetc = st->vfs->get_char;
st->stream_putc = st->vfs->put_char;
st->stream_wgetc = st->vfs->get_char;
return;
}
st->stream_wputc = put_wchar; st->stream_wputc = put_wchar;
if (st->encoding == ENC_ISO_UTF8) if (st->encoding == ENC_ISO_UTF8)
st->stream_wgetc = get_wchar_UTF8; st->stream_wgetc = get_wchar_UTF8;
else else
st->stream_wgetc = get_wchar; st->stream_wgetc = get_wchar;
if (st->vfs) {
st->stream_putc = st->vfs->put_char;
st->stream_wgetc = st->vfs->get_char;
} else {
st->stream_putc = FilePutc; st->stream_putc = FilePutc;
st->stream_getc = PlGetc; st->stream_getc = PlGetc;
}
if (st->status & (Promptable_Stream_f)) { if (st->status & (Promptable_Stream_f)) {
Yap_ConsoleOps(st); Yap_ConsoleOps(st);
} }
@ -300,7 +298,7 @@ static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file, VFS_t *vfsp) {
INIT_LOCK(s->streamlock); INIT_LOCK(s->streamlock);
if (vfsp != NULL) { if (vfsp != NULL) {
s->u.private_data = s->u.private_data =
vfsp->open(vfsp->name, (sno == StdInStream ? "read" : "write")); vfsp->open(sno, vfsp->name, (sno == StdInStream ? "read" : "write"));
if (s->u.private_data == NULL) { if (s->u.private_data == NULL) {
(PlIOError(EXISTENCE_ERROR_SOURCE_SINK, MkIntTerm(sno), "%s", (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, MkIntTerm(sno), "%s",
vfsp->name)); vfsp->name));
@ -1312,7 +1310,7 @@ do_open(Term file_name, Term t2,
} }
struct vfs *vfsp = NULL; struct vfs *vfsp = NULL;
if ((vfsp = vfs_owner(fname)) != NULL) { if ((vfsp = vfs_owner(fname)) != NULL) {
st->u.private_data = vfsp->open(fname, io_mode); st->u.private_data = vfsp->open(sno, fname, io_mode);
fd = NULL; fd = NULL;
if (st->u.private_data == NULL) if (st->u.private_data == NULL)
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name, "%s", fname)); return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name, "%s", fname));
@ -1869,7 +1867,10 @@ static Int get_abs_file_parameter(USES_REGS1) {
void Yap_InitPlIO(struct yap_boot_params *argi) { void Yap_InitPlIO(struct yap_boot_params *argi) {
Int i; Int i;
#if __ANDROID__
if (argi->assetManager)
Yap_InitAssetManager( argi->assetManager );
#endif
if (argi->inp > 0) if (argi->inp > 0)
Yap_stdin = fdopen(argi->inp - 1, "r"); Yap_stdin = fdopen(argi->inp - 1, "r");
else if (argi->inp) else if (argi->inp)

View File

@ -285,6 +285,6 @@ static inline void freeBuffer(const void *ptr) {
/** VFS handling */ /** VFS handling */
VFS_t *Yap_InitAssetManager(void); VFS_t *Yap_InitAssetManager(AAssetManager *mgr);
#endif #endif

View File

@ -24,7 +24,7 @@ static char SccsId[] = "%W% %G%";
*/ */
#include "sysbits.h" #include "sysbits.h"
#include "YapStreams.h"
#if !HAVE_FMEMOPEN || !defined(HAVE_FMEMOPEN) #if !HAVE_FMEMOPEN || !defined(HAVE_FMEMOPEN)
@ -180,7 +180,7 @@ static int MemPutc(int sno, int ch) {
return ((int)ch); return ((int)ch);
} }
bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, size_t nchars) { bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, size_t nchars USES_REGS) {
FILE *f; FILE *f;
stream_flags_t flags; stream_flags_t flags;
@ -241,14 +241,15 @@ open_mem_read_stream(USES_REGS1) /* $open_mem_read_stream(+List,-Stream) */
{ {
Term t, ti; Term t, ti;
int sno; int sno;
char buf0[YAP_FILENAME_MAX + 1]; int i = push_text_stack();
const char *buf; const char *buf;
ti = Deref(ARG1); ti = Deref(ARG1);
buf = Yap_TextTermToText(ti, buf0, 0, LOCAL_encoding); buf = Yap_TextTermToText(ti PASS_REGS);
if (!buf) { if (!buf) {
return false; return false;
} }
buf = pop_output_text_stack(i, buf);
sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding, sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding,
MEM_BUF_MALLOC); MEM_BUF_MALLOC);
t = Yap_MkStream(sno); t = Yap_MkStream(sno);

View File

@ -79,7 +79,7 @@ static bool is_directory(const char *FileName) {
VFS_t *vfs; VFS_t *vfs;
if ((vfs = vfs_owner(FileName))) { if ((vfs = vfs_owner(FileName))) {
return vfs->isdir(FileName); return vfs->isdir(vfs,FileName);
} }
#ifdef _WIN32 #ifdef _WIN32
DWORD dwAtts = GetFileAttributes(FileName); DWORD dwAtts = GetFileAttributes(FileName);
@ -102,10 +102,13 @@ static bool is_directory(const char *FileName) {
} }
bool Yap_Exists(const char *f) { bool Yap_Exists(const char *f) {
VFS_t *vfs; VFS_t *vfs = GLOBAL_VFS;
if ((vfs = vfs_owner(f))) { while(vfs) {
return vfs->exists(f); VFS_t *n=vfs->exists(vfs,f);
if (n==vfs) return true;
if (!n) return false;
vfs = n;
} }
#if _WIN32 #if _WIN32
if (_access(f, 0) == 0) if (_access(f, 0) == 0)
@ -341,14 +344,14 @@ static char *PrologPath(const char *Y, char *X) { return (char *)Y; }
#define HAVE_REALPATH 1 #define HAVE_REALPATH 1
#endif #endif
static bool ChDir(const char *path) { bool ChDir(const char *path) {
bool rc = false; bool rc = false;
char qp[FILENAME_MAX + 1]; char qp[FILENAME_MAX + 1];
const char *qpath = Yap_AbsoluteFile(path, qp, true); const char *qpath = Yap_AbsoluteFile(path, qp, true);
VFS_t *v; VFS_t *v;
if ((v = vfs_owner(path))) { if ((v = vfs_owner(path))) {
return v->chdir(path); return v->chdir(v, path);
} }
#if _WIN32 #if _WIN32
rc = true; rc = true;
@ -1242,7 +1245,8 @@ const char *Yap_findFile(const char *isource, const char *idef,
if (ftype == YAP_PL) { if (ftype == YAP_PL) {
root = YAP_SHAREDIR; root = YAP_SHAREDIR;
} else if (ftype == YAP_BOOT_PL) { } else if (ftype == YAP_BOOT_PL) {
root = YAP_SHAREDIR; root = malloc(YAP_FILENAME_MAX+1);
strcpy(root, YAP_SHAREDIR);
strcat(root,"/pl"); strcat(root,"/pl");
} else { } else {
root = YAP_LIBDIR; root = YAP_LIBDIR;

View File

@ -22,6 +22,8 @@
#undef HAVE_LIBREADLINE #undef HAVE_LIBREADLINE
#endif #endif
#include "YapStreams.h"
#include <stdio.h> #include <stdio.h>
#include <wchar.h> #include <wchar.h>
@ -108,8 +110,6 @@ extern Term Yap_StringToNumberTerm(const char *s, encoding_t *encp,
extern int Yap_FormatFloat(Float f, char **s, size_t sz); extern int Yap_FormatFloat(Float f, char **s, size_t sz);
extern int Yap_open_buf_read_stream(const char *buf, size_t nchars, extern int Yap_open_buf_read_stream(const char *buf, size_t nchars,
encoding_t *encp, memBufSource src); encoding_t *encp, memBufSource src);
extern bool Yap_set_stream_to_buf(struct stream_desc *st, const char *buf,
encoding_t enc, size_t nchars);
extern int Yap_open_buf_write_stream(encoding_t enc, memBufSource src); extern int Yap_open_buf_write_stream(encoding_t enc, memBufSource src);
extern Term Yap_BufferToTerm(const unsigned char *s, Term opts); extern Term Yap_BufferToTerm(const unsigned char *s, Term opts);
extern X_API Term Yap_BufferToTermWithPrioBindings(const unsigned char *s, extern X_API Term Yap_BufferToTermWithPrioBindings(const unsigned char *s,
@ -151,4 +151,8 @@ INLINE_ONLY inline EXTERN Term MkCharTerm(Int c) {
extern uint64_t Yap_StartOfWTimes; extern uint64_t Yap_StartOfWTimes;
extern bool Yap_HandleSIGINT(void); extern bool Yap_HandleSIGINT(void);
extern bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, size_t nchars USES_REGS);
#endif #endif

View File

@ -19,7 +19,7 @@
]). ]).
:- catch(load_foreign_files([horus], [], init_predicates), _, patch_things_up) :- catch(load_foreign_files([libhorus], [], init_predicates), _, patch_things_up)
-> true ; warning. -> true ; warning.

View File

@ -58,7 +58,7 @@ if (CMAKE_MAJOR_VERSION GREATER 2)
#set_property(TARGET horus PROPERTY CXX_STANDARD 11) #set_property(TARGET horus PROPERTY CXX_STANDARD 11)
#set_property(TARGET horus PROPERTY CXX_STANDARD_REQUIRED ON) #set_property(TARGET horus PROPERTY CXX_STANDARD_REQUIRED ON)
set_target_properties (horus PROPERTIES PREFIX "" CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON) set_target_properties (horus PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
add_executable (HorusCli HorusCli.cpp) add_executable (HorusCli HorusCli.cpp)

View File

@ -46,8 +46,6 @@ IF (CUDD_FOUND)
) )
endif() endif()
set_target_properties (cudd PROPERTIES PREFIX "")
add_subdirectory(simplecudd) add_subdirectory(simplecudd)
add_subdirectory(simplecudd_lfi) add_subdirectory(simplecudd_lfi)
set(YAP_SYSTEM_OPTIONS "cudd " ${YAP_SYSTEM_OPTIONS} PARENT_SCOPE) set(YAP_SYSTEM_OPTIONS "cudd " ${YAP_SYSTEM_OPTIONS} PARENT_SCOPE)

View File

@ -52,7 +52,7 @@ The following predicates construct a BDD:
tell_warning :- tell_warning :-
print_message(warning,functionality(cudd)). print_message(warning,functionality(cudd)).
:- catch(load_foreign_files([cudd], [], init_cudd),_,fail) -> true ; tell_warning. :- catch(load_foreign_files([libcudd], [], init_cudd),_,fail) -> true ; tell_warning.
/** /**
@pred bdd_new(? _Exp_, - _BddHandle_) @pred bdd_new(? _Exp_, - _BddHandle_)

View File

@ -11,18 +11,19 @@ set(MYDDAS_YPP
set(MYDDAS_DRIVERS set(MYDDAS_DRIVERS
"myddas_driver.ypp" "myddas_driver.ypp"
) )
message("libpl ${libpl}")
if (0)
set (PREFIX ${libpl} ) if (ANDROID)
set (MYDDAS_PREFIX ${libpl} )
else() else()
set (PREFIX ${CMAKE_CURRENT_BINARY_DIR} ) set (MYDDAS_PREFIX ${CMAKE_CURRENT_BINARY_DIR} )
endif() endif()
get_property(MYDDAS_FLAGS GLOBAL PROPERTY COMPILE_DEFINITIONS) get_property(MYDDAS_FLAGS GLOBAL PROPERTY COMPILE_DEFINITIONS)
function(cpp_compile output filename) function(cpp_compile output filename)
get_filename_component(base ${filename} NAME_WE) get_filename_component(base ${filename} NAME_WE)
set(base_abs ${PREFIX}/${base}) set(base_abs ${MYDDAS_PREFIX}/${base})
set(outfile ${base_abs}.yap) set(outfile ${base_abs}.yap)
set(${output} ${${output}} ${outfile} PARENT_SCOPE) set(${output} ${${output}} ${outfile} PARENT_SCOPE)
IF (MSVC) IF (MSVC)
@ -40,17 +41,13 @@ function(cpp_compile output filename)
endfunction() endfunction()
if (ANDROID) if (ANDROID)
set (MYDDAS_PL_OUTDIR ${YAP_APP_DIR}/src/generated/assets/Yap} ) set (MYDDAS_PL_OUTDIR ${YAP_APP_DIR}/src/generated/assets/Yap )
else() else()
set (MYDDAS_PL_OUTDIR ${CMAKE_CURRENT_BINARY_DIR} ) set (MYDDAS_PL_OUTDIR ${CMAKE_CURRENT_BINARY_DIR} )
endif() endif()
function(cpp_driver output dbms filename) function(cpp_driver output dbms filename)
if (0)
set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap) set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap)
else()
set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap)
endif()
set(${output} ${${output}} ${outfile} PARENT_SCOPE) set(${output} ${${output}} ${outfile} PARENT_SCOPE)
IF (MSVC) IF (MSVC)
add_custom_command( add_custom_command(

View File

@ -18,21 +18,21 @@
#undef sqlite3 #undef sqlite3
#define DBMS(x) sqlite3_##x #define DBMS(x) sqlite3_##x
#define c_DBMS(x) c_sqlite3_##x #define c_DBMS(x) c_sqlite3_##x
#define NAME() 'Yapsqlite3' #define NAME() 'libYapsqlite3'
#define MODULE() myddas_sqlite3 #define MODULE() myddas_sqlite3
#define INIT() init_sqlite3 #define INIT() init_sqlite3
#elif defined( odbc ) #elif defined( odbc )
#undef odbc #undef odbc
#define DBMS(x) odbc_##x #define DBMS(x) odbc_##x
#define c_DBMS(x) c_odbc_##x #define c_DBMS(x) c_odbc_##x
#define NAME() 'Yapodbc' #define NAME() 'libYapodbc'
#define MODULE() myddas_odbc #define MODULE() myddas_odbc
#define INIT() init_odbc #define INIT() init_odbc
#elif defined( postgres ) #elif defined( postgres )
#undef postgres #undef postgres
#define DBMS(x) postgres_##x #define DBMS(x) postgres_##x
#define c_DBMS(x) c_postgres_##x #define c_DBMS(x) c_postgres_##x
#define NAME() 'Yappostgres' #define NAME() 'libYappostgres'
#define MODULE() myddas_postgres #define MODULE() myddas_postgres
#define INIT() init_odbc #define INIT() init_odbc
#endif #endif

View File

@ -60,7 +60,6 @@ set_target_properties(Yapsqlite3
# RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION} # RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION}
# SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION} # SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION}
POSITION_INDEPENDENT_CODE TRUE POSITION_INDEPENDENT_CODE TRUE
PREFIX ""
) )
target_link_libraries(Yapsqlite3 libYap) target_link_libraries(Yapsqlite3 libYap)

View File

@ -1,72 +1,73 @@
include (UseSWIG)
INCLUDE_DIRECTORIES(
../../../H
../../../H/generated
../../../OPTYap
../../../include
../../../CXX
.
..
${CMAKE_CURRENT_BINARY_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
set_property(GLOBAL
APPEND PROPERTY
COMPILE_DEFINITIONS
-Dmmap=mmap64)
# This is a CMake file for SWIG and Android # 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(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 ( SWIG_SOURCES ${CMAKE_SOURCE_DIR}/packages/swig/yap.i ) FILE( MAKE_DIRECTORY ${YAP_APP_DIR}/src/generated/assets)
SET_SOURCE_FILES_PROPERTIES(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON) FILE( MAKE_DIRECTORY ${CMAKE_SWIG_OUTDIR})
set(SWIG_OUTFILE_DIR ${CMAKE_CURRENT_BINARY_DIR} )
set_property(SOURCE ../yap.i PROPERTY CPLUSPLUS ON)
SET_SOURCE_FILES_PROPERTIES(../yap.i PROPERTIES SWIG_FLAGS "-O;-package;pt.up.yap.lib;-D__ANDROID__=1")
include_directories ( set( SWIG_PACKAGE_NAME pt.up.yap.lib )
${CMAKE_SOURCE_DIR}/CXX
) set (SWIG_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../yap.i )
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 ${SWIG_OUTFILE_DIR}/yapJAVA.cxx
COMMAND ${CMAKE_COMMAND} -E make_directory ${pllib} COMMAND ${SWIG_EXECUTABLE} -c++ -java -O -package "pt.up.yap.lib" -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/H/generated -I${CMAKE_SOURCE_DIR}/include
COMMAND ${CMAKE_COMMAND} -E make_directory ${pllib}/pl -I${CMAKE_SOURCE_DIR}/OPTYap -I${CMAKE_SOURCE_DIR}/os -I${CMAKE_SOURCE_DIR}/utf8proc -I.././.. -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/packages/python
COMMAND ${CMAKE_COMMAND} -E make_directory ${pllib}/os -outdir ${CMAKE_SWIG_OUTDIR} -I${GMP_INCLUDE_DIRS} -D__ANDROID__=1 -DX_API="" -o ${SWIG_OUTFILE_DIR}/yapJAVA.cxx -oh ${SWIG_OUTFILE_DIR}/yapJAVA.hh ${CMAKE_CURRENT_SOURCE_DIR}/../yap.i
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMAND ${CMAKE_COMMAND} -E copy ${pl_library} ${pllib} DEPENDS ${SWIG_SOURCES}
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_command (OUTPUT swig_streamer.cpp ADD_LIBRARY(YAPJava
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 SHARED
DEPENDS streamer.i ${SWIG_OUTFILE_DIR}/yapJAVA.cxx
) )
target_link_libraries(YAPJava YAP++ libYap android log)
# GMP_FOUND - true if GMP/MPIR was found set_property(SOURCE streamer.i PROPERTY CPLUSPLUS ON)
# GMP_INCLUDE_DIRS - include search path SET_SOURCE_FILES_PROPERTIES(streamer.i PROPERTIES SWIG_FLAGS "-O;-package;pt.up.yap.lib;-D__ANDROID__=1")
# 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} ) set (SWIG_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/streamer.i)
add_custom_command( OUTPUT ${SWIG_OUTFILE_DIR}/streamerJAVA.cxx
add_lib(YAPJava COMMAND ${SWIG_EXECUTABLE} -c++ -java -O -package "pt.up.yap.lib" -O -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/H/generated -I${CMAKE_SOURCE_DIR}/include
yap_swig.cpp swig_streamer.cpp streamer.cpp streamer.h -I${CMAKE_SOURCE_DIR}/OPTYap -I${CMAKE_SOURCE_DIR}/os -I${CMAKE_SOURCE_DIR}/utf8proc -I.././.. -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/packages/python
) -outdir ${CMAKE_SWIG_OUTDIR} -I${GMP_INCLUDE_DIRS} -D__ANDROID__=1 -DX_API="" -o ${SWIG_OUTFILE_DIR}/streamerJAVA.cxx -oh ${SWIG_OUTFILE_DIR}/streamerJAVA.hh ${CMAKE_CURRENT_SOURCE_DIR}/streamer.i
target_link_libraries(YAPJava ${GMP_LIBRARIES} ) WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
DEPENDS ${SWIG_SOURCES}
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) ADD_LIBRARY(YAPStreamer
SHARED # [TYPE <SHARED|MODULE|STATIC|USE_BUILD_SHARED_LIBS>]
${CMAKE_CURRENT_SOURCE_DIR}/streamer.cpp ${SWIG_OUTFILE_DIR}/streamerJAVA.cxx
)
target_link_libraries(YAPStreamer YAP++ libYap android log)
endif()

View File

@ -285,346 +285,6 @@ class YAPEngine;
#if THREADS #if THREADS
#define Yap_regp regcache #define Yap_regp regcache
#endif #endif
// we cannot consult YapInterface.h, that conflicts with what we // we cannot consult YapInterface.h, that conflicts with what we
@ -661,6 +321,7 @@ class YAPEngine;
//%feature("novaluewrapper") vector<YAPTerm>; //%feature("novaluewrapper") vector<YAPTerm>;
}; };
%init %{ %init %{

View File

@ -58,7 +58,12 @@ set(PL_BOOT_SOURCES
add_to_group(PL_BOOT_SOURCES pl_boot_library) add_to_group(PL_BOOT_SOURCES pl_boot_library)
if (CMAKE_CROSSCOMPILING) if (ANDROID)
add_custom_target(STARTUP
DEPENDS ${PL_BOOT_SOURCES}
)
file (INSTALL ${PL_BOOT_SOURCES} DESTINATION ${libpl}/pl)
elseif(CMAKE_CROSSCOMPILING)
add_custom_target(STARTUP ALL SOURCES add_custom_target(STARTUP ALL SOURCES
DEPENDS ${PL_BOOT_SOURCES} DEPENDS ${PL_BOOT_SOURCES}
) )
@ -67,7 +72,6 @@ else ()
DEPENDS ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP} DEPENDS ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP}
) )
add_custom_command(OUTPUT ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP} add_custom_command(OUTPUT ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP}
COMMAND ldd yap
COMMAND ./yap -B COMMAND ./yap -B
VERBATIM VERBATIM
WORKING_DIRECTORY ${CMAKE_TOP_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_TOP_BINARY_DIR}
@ -79,7 +83,7 @@ install(FILES ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP}
) )
endif() endif()
install(FILES ${PL_SOURCES} install(FILES ${PL_SOURCES}
DESTINATION ${libpl}/pl DESTINATION ${libpl}/pl
) )