Merge 192.168.1.103:github/yap-6.3

This commit is contained in:
Vitor Santos Costa 2017-12-01 10:49:46 +00:00
commit 55f4767621
35 changed files with 500 additions and 696 deletions

View File

@ -134,11 +134,12 @@ inline static Atom SearchInInvisible(const unsigned char *atom) {
static inline Atom SearchAtom(const unsigned char *p, Atom a) {
AtomEntry *ae;
const char *ps = (const char *)p;
/* search atom in chain */
while (a != NIL) {
ae = RepAtom(a);
if (strcmp(ae->UStrOfAE, p) == 0) {
if (strcmp(ae->StrOfAE, ps) == 0) {
return (a);
}
a = ae->NextOfAE;

View File

@ -77,10 +77,11 @@ void *my_malloc(size_t sz) {
p = malloc(sz);
// Yap_DebugPuts(stderr,"gof\n");
if (Yap_do_low_level_trace)
#if __ANDROID__
__android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "+ %d %p", write_malloc,p);
#else
fprintf(stderr, "+s %p\n @%p %ld\n", p, TR, LCL0 - (CELL *)LCL0);
if (sz > 500 && write_malloc++ > 0)
__android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "+ %d %p", write_malloc,
p);
#endif
return p;
}
@ -100,7 +101,7 @@ void *my_realloc(void *ptr, size_t sz) {
void my_free(void *p) {
// printf("f %p\n",p);
if (Yap_do_low_level_trace)
fprintf(stderr, "- %p\n @%p %ld\n", p, TR, LCL0 - (CELL *)LCL0);
fprintf(stderr, "- %p\n @%p %ld\n", p, TR, (long int)(LCL0 - (CELL *)B) );
if (write_malloc && write_malloc++ > 0)
__android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "- %d %p", write_malloc,
p);

View File

@ -2112,38 +2112,39 @@ X_API void YAP_ClearExceptions(void) {
Yap_ResetException(worker_id);
}
X_API int YAP_InitConsult(int mode, const char *filename, char *full,
X_API int YAP_InitConsult(int mode, const char *fname, char *full,
int *osnop) {
CACHE_REGS
FILE *f = NULL;
int sno;
BACKUP_MACHINE_REGS();
int lvl = push_text_stack();
if (mode == YAP_BOOT_MODE) {
mode = YAP_CONSULT_MODE;
}
char *bfp = Malloc(YAP_FILENAME_MAX+1);
bfp[0] = '\0';
if(fname != NULL && fname[0] != 0 )
strcpy( bfp, fname );
bool consulted = (mode == YAP_CONSULT_MODE);
Yap_init_consult(consulted, filename);
const char *fl = Yap_findFile(filename, NULL, BootFilePath, full, true,
const char *fl = Yap_findFile(bfp, NULL, NULL, full, true,
YAP_BOOT_PL, true, true);
if (!fl)
return -1;
f = fopen(fl, "r");
if (!f)
return -1;
if (!f) {
if (!fl || !fl[0]) {
pop_text_stack(lvl);
return -1;
}
sno = Yap_OpenStream(f, NULL, TermNil, Input_Stream_f);
Yap_init_consult(consulted,bfp);
sno = Yap_OpenStream(fl, "r" );
*osnop = Yap_CheckAlias(AtomLoopStream);
if (!Yap_AddAlias(AtomLoopStream, sno)) {
Yap_CloseStream(sno);
sno = -1;
pop_text_stack(lvl);
sno = -1;
}
GLOBAL_Stream[sno].name = Yap_LookupAtom(fl);
GLOBAL_Stream[sno].user_name = MkAtomTerm(Yap_LookupAtom(filename));
GLOBAL_Stream[sno].encoding = ENC_ISO_UTF8;
RECOVER_MACHINE_REGS();
GLOBAL_Stream[sno].user_name = MkAtomTerm(Yap_LookupAtom(fname));
GLOBAL_Stream[sno].encoding = LOCAL_encoding;
pop_text_stack(lvl);
RECOVER_MACHINE_REGS();
UNLOCK(GLOBAL_Stream[sno].streamlock);
return sno;
}
@ -2181,7 +2182,7 @@ X_API void YAP_EndConsult(int sno, int *osnop) {
X_API Term YAP_Read(FILE *f) {
Term o;
int sno = Yap_OpenStream(f, NULL, TermNil, Input_Stream_f);
int sno = Yap_FileStream(f, NULL, TermNil, Input_Stream_f);
BACKUP_MACHINE_REGS();
o = Yap_read_term(sno, TermNil, 1);
@ -2210,7 +2211,7 @@ X_API Term YAP_ReadClauseFromStream(int sno) {
X_API void YAP_Write(Term t, FILE *f, int flags) {
BACKUP_MACHINE_REGS();
int sno = Yap_OpenStream(f, NULL, TermNil, Output_Stream_f);
int sno = Yap_FileStream(f, NULL, TermNil, Output_Stream_f);
Yap_plwrite(t, GLOBAL_Stream + sno, 0, flags, GLOBAL_MaxPriority);
Yap_ReleaseStream(sno);
@ -2304,21 +2305,23 @@ X_API char *YAP_CompileClause(Term t) {
static int yap_lineno = 0;
/* 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;
int bootfile, osno;
Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1);
Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1);
char full[YAP_FILENAME_MAX + 1];
/* consult boot.pl */
char *full = malloc(YAP_FILENAME_MAX + 1);
full[0] = '\0';
/* 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) {
fprintf(stderr, "[ FATAL ERROR: could not open bootfile %s ]\n",
bootfilename);
b_file);
exit(1);
}
free(full);
do {
CACHE_REGS
YAP_Reset(YAP_FULL_RESET);
@ -2329,7 +2332,7 @@ static void do_bootfile(const char *bootfilename USES_REGS) {
if (t == 0) {
fprintf(stderr,
"[ SYNTAX ERROR: while parsing bootfile %s at line %d ]\n",
bootfilename, yap_lineno);
b_file, yap_lineno);
} else if (YAP_IsVarTerm(t) || t == TermNil) {
fprintf(stderr, "[ line %d: term cannot be compiled ]", yap_lineno);
} else if (YAP_IsPairTerm(t)) {
@ -2420,10 +2423,11 @@ static void do_bootfile(const char *bootfilename USES_REGS) {
YAP_file_type_t restore_result = yap_init->boot_file_type;
bool do_bootstrap = (restore_result & YAP_CONSULT_MODE);
CELL Trail = 0, Stack = 0, Heap = 0, Atts = 0;
char boot_file[YAP_FILENAME_MAX + 1];
char *boot_file;
Int rc;
const char *yroot;
boot_file = calloc(YAP_FILENAME_MAX + 1, 1);
/* ignore repeated calls to YAP_Init */
if (YAP_initialized)
return YAP_FOUND_BOOT_ERROR;
@ -2450,7 +2454,12 @@ static void do_bootfile(const char *bootfilename USES_REGS) {
if (yap_init->SavedState == NULL) {
yap_init->SavedState = YAP_STARTUP;
}
if (!LOCAL_TextBuffer)
LOCAL_TextBuffer = Yap_InitTextAllocator();
#if __ANDROID__
//if (yap_init->assetManager)
Yap_InitAssetManager( );
#endif
#if USE_DL_MALLOC
if (yap_init->SavedState == NULL)
yap_init->SavedState = YAP_STARTUP;
@ -2467,9 +2476,10 @@ static void do_bootfile(const char *bootfilename USES_REGS) {
if (yap_init->YapPrologBootFile == NULL)
yap_init->YapPrologBootFile = BootFile;
#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);
if (s && s[0] != '\0') strcpy(boot_file, s);
#endif
}
@ -2619,18 +2629,17 @@ static void do_bootfile(const char *bootfilename USES_REGS) {
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, true);
rc = YAP_QLY;
} else {
if (!yap_init->YapPrologBootFile)
yap_init->YapPrologBootFile = BootFile;
rc = YAP_BOOT_PL;
do_bootfile(yap_init->YapPrologBootFile);
if (boot_file[0] == '\0')
strcpy(boot_file, BootFile);
do_bootfile(boot_file PASS_REGS);
setAtomicGlobalPrologFlag(
RESOURCE_DATABASE_FLAG,
MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologBootFile)));
MkAtomTerm(Yap_LookupAtom(boot_file)));
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false);
}
start_modules();
YAP_initialized = true;
return rc;
return YAP_BOOT_PL;
}
#if (DefTrailSpace < MinTrailSpace)
@ -2652,7 +2661,7 @@ static void do_bootfile(const char *bootfilename USES_REGS) {
#define DEFAULT_SCHEDULERLOOP 10
#define DEFAULT_DELAYEDRELEASELOAD 3
X_API YAP_file_type_t YAP_FastInit(char saved_state[], int argc, char *argv[]) {
X_API YAP_file_type_t YAP_FastInit(char *saved_state, int argc, char *argv[]) {
YAP_init_args init_args;
YAP_file_type_t out;

View File

@ -1873,8 +1873,6 @@ bool Yap_addclause(Term t, yamop *cp, Term tmode, Term mod, Term *t4ref)
} else {
tf = Yap_MkStaticRefTerm(ClauseCodeToStaticClause(cp), p);
}
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "add %s/%ld %p",
RepAtom(at)->StrOfAE, Arity);
if (mod == PROLOG_MODULE)
mod = TermProlog;
if (pflags & MultiFileFlag) {
@ -2059,36 +2057,33 @@ Atom Yap_ConsultingFile(USES_REGS1) {
if (LOCAL_consult_level == 0) {
return (AtomUser);
} else {
return (Yap_ULookupAtom(LOCAL_ConsultBase[2].filename));
return (Yap_ULookupAtom(LOCAL_ConsultBase[2].f_name));
}
}
/* consult file *file*, *mode* may be one of either consult or reconsult */
static void init_consult(int mode, const unsigned char *file) {
CACHE_REGS
if (!LOCAL_ConsultSp) {
InitConsultStack();
}
if (LOCAL_ConsultSp >= LOCAL_ConsultLow + 6) {
expand_consult();
}
LOCAL_ConsultSp--;
LOCAL_ConsultSp->filename = file;
LOCAL_ConsultSp--;
LOCAL_ConsultSp->mode = mode;
LOCAL_ConsultSp--;
LOCAL_ConsultSp->c = (LOCAL_ConsultBase - LOCAL_ConsultSp);
LOCAL_ConsultBase = LOCAL_ConsultSp;
void Yap_init_consult(int mode, const char *filenam) {
CACHE_REGS
if (!LOCAL_ConsultSp) {
InitConsultStack();
}
if (LOCAL_ConsultSp >= LOCAL_ConsultLow + 6) {
expand_consult();
}
LOCAL_ConsultSp--;
LOCAL_ConsultSp->f_name = (const unsigned char *)filenam;
LOCAL_ConsultSp--;
LOCAL_ConsultSp->mode = mode;
LOCAL_ConsultSp--;
LOCAL_ConsultSp->c = (LOCAL_ConsultBase - LOCAL_ConsultSp);
LOCAL_ConsultBase = LOCAL_ConsultSp;
#if !defined(YAPOR) && !defined(YAPOR_SBA)
/* if (LOCAL_consult_level == 0)
do_toggle_static_predicates_in_use(TRUE); */
#endif
LOCAL_consult_level++;
LOCAL_LastAssertedPred = NULL;
}
LOCAL_consult_level++;
LOCAL_LastAssertedPred = NULL;
void Yap_init_consult(int mode, const char *file) {
init_consult(mode, (const unsigned char *)file);
}
static Int p_startconsult(USES_REGS1) { /* '$start_consult'(+Mode) */
@ -2097,7 +2092,7 @@ static Int p_startconsult(USES_REGS1) { /* '$start_consult'(+Mode) */
int mode;
mode = strcmp("consult", (char *)smode);
init_consult(mode, RepAtom(AtomOfTerm(Deref(ARG2)))->UStrOfAE);
Yap_init_consult(mode, RepAtom(AtomOfTerm(Deref(ARG2)))->StrOfAE);
t = MkIntTerm(LOCAL_consult_level);
return (Yap_unify_constant(ARG3, t));
}

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))
#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
#define NAN (0.0 / 0.0)
#endif
@ -77,7 +82,7 @@ int pop_text_stack__(int i) {
return lvl;
}
void *pop_output_text_stack__(int i, void *export) {
void *pop_output_text_stack__(int i, const void *export) {
int lvl = LOCAL_TextBuffer->lvl;
while (lvl >= i) {
struct mblock *p = LOCAL_TextBuffer->first[lvl];
@ -993,7 +998,7 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
return false;
}
b_l0 = strlen((const char *)buf0);
if (bcmp(buf, buf0, b_l0) != 0) {
if (memcmp(buf, buf0, b_l0) != 0) {
return false;
}
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);
b_l0 = b_l - b_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) {
return false;
}
@ -1043,35 +1048,6 @@ bool Yap_Splice_Text(int n, size_t cuts[], seq_tv_t *inp,
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

View File

@ -147,12 +147,14 @@ static int dump_runtime_variables(void) {
return 1;
}
YAP_file_type_t Yap_InitDefaults(YAP_init_args *iap, char saved_state[],
YAP_file_type_t Yap_InitDefaults(YAP_init_args *iap, char *saved_state,
int argc, char *argv[]) {
memset(iap, 0, sizeof(YAP_init_args));
#if __ANDROID__
iap->boot_file_type = YAP_BOOT_PL;
iap->SavedState = NULL;
iap->SavedState = malloc(strlen(saved_state)+1);
strcpy(iap->SavedState, saved_state);
iap->assetManager = true;
#else
iap->boot_file_type = YAP_QLY;
iap->SavedState = saved_state;
@ -496,11 +498,7 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
} else if (!strncmp("-home=", p, strlen("-home="))) {
GLOBAL_Home = p + strlen("-home=");
} else if (!strncmp("-cwd=", p, strlen("-cwd="))) {
#if __WINDOWS__
if (_chdir(p + strlen("-cwd=")) < 0) {
#else
if (chdir(p + strlen("-cwd=")) < 0) {
#endif
if (!ChDir(p + strlen("-cwd=")) ) {
fprintf(stderr, " [ YAP unrecoverable error in setting cwd: %s ]\n",
strerror(errno));
}

View File

@ -249,9 +249,6 @@ if (APPLE)
endif ()
endif ()
if (ANDROID)
set(datarootdir /assets)
endif ()
set(prefix ${CMAKE_INSTALL_PREFIX}) #BINDIR})
set(bindir ${CMAKE_INSTALL_PREFIX}/bin) #BINDIR})
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(datarootdir ${CMAKE_INSTALL_PREFIX}/share) #DATAROOTDIR})
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(docdir ${CMAKE_INSTALL_PREFIX}/share/docs) #MANDIR})
@ -458,12 +459,12 @@ endif ()
OPTION(WITH_SWIG " Enable SWIG interfaces to foreign languages" ON)
IF (WITH_SWIG OR ANDROID)
IF (WITH_SWIG)
find_host_package(SWIG)
# macro_log_feature (SWIG_FOUND "Swig"
# "Use SWIG Interface Generator "
# "http://www.swig.org" ON)
ENDIF (WITH_SWIG OR ANDROID)
ENDIF (WITH_SWIG)
option(WITH_PYTHON
@ -614,11 +615,6 @@ ADD_SUBDIRECTORY(library)
ADD_SUBDIRECTORY(swi/library "swiLibrary")
if (ANDROID)
target_link_libraries(libYap android log)
endif ()
set_target_properties(libYap
PROPERTIES OUTPUT_NAME Yap
)
@ -638,8 +634,9 @@ if (PYTHONLIBS_FOUND AND SWIG_FOUND)
endif ()
IF (SWIG_FOUND OR ANDROID)
add_subDIRECTORY(packages/swig NO_POLICY_SCOPE)
IF ( ANDROID)
add_subDIRECTORY(packages/swig )
target_link_libraries(libYap android log)
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
"NOT WITH_YAPOR_THOR; NOT WITH_SYSTEM_MMAP" OFF)
if (NOT ANDROID)
add_subDIRECTORY(library/lammpi)
if (MPI_C_FOUND)
if (MPI_C_FOUND\D)
CMAKE_DEPENDENT_OPTION(WITH_MPI ON "Interface to OpenMPI/MPICH"
"MPI_C_FOUND" OFF)
@ -822,6 +821,8 @@ if (MPI_C_FOUND)
endif ()
endif (MPI_C_FOUND)
endif(NOT ANDROID)
## add_subDIRECTORY(utils)
#

View File

@ -625,7 +625,7 @@ Term YAPEngine::fun(Term t)
return 0;
}
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_CloseHandles(q.CurSlot);
Term rc = Yap_PopTermFromDB(pt);
@ -751,8 +751,8 @@ bool YAPQuery::next()
}
if (result)
{
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %d %s %ld",
q_state, vnames.text(), LOCAL_CurSlot);
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %d %s %d",
q_state, names.text(), LOCAL_CurSlot);
}
else
{
@ -892,6 +892,8 @@ static size_t Yap_AndroidMax, Yap_AndroidSz;
extern void (*Yap_DisplayWithJava)(int c);
static YAPCallback *cb = new YAPCallback();
void Yap_displayWithJava(int c)
{
char *ptr = Yap_AndroidBufp;
@ -914,17 +916,18 @@ void Yap_displayWithJava(int c)
if (c == '\n')
{
Yap_AndroidBufp[Yap_AndroidSz] = '\0';
curren->run(Yap_AndroidBufp);
cb->run(Yap_AndroidBufp);
Yap_AndroidSz = 0;
}
}
#endif
void YAPEngine::doInit(YAP_file_type_t BootMode)
{
if ((BootMode = YAP_Init(&engine_args->init_args)) == YAP_FOUND_BOOT_ERROR)
if ((BootMode = YAP_Init(engine_args)) == YAP_FOUND_BOOT_ERROR)
{
return;
throw YAPError();
@ -945,26 +948,29 @@ void YAPEngine::doInit(YAP_file_type_t BootMode)
YAPQuery initq = YAPQuery(YAPPredicate(p), nullptr);
if (initq.next())
{
initq.cut();
initq.cut();
}
CurrentModule = TermUser;
}
YAPEngine::YAPEngine(int argc, char *argv[],
YAPCallback *cb)
YAPCallback *cb)
: _callback(0) { // a single engine can be active
YAP_file_type_t BootMode;
engine_args = new YAPEngineArgs();
BootMode = YAP_parse_yap_arguments(argc, argv, &engine_args->init_args);
BootMode = YAP_parse_yap_arguments(argc, argv, engine_args);
// delYAPCallback()b
// if (cb)
// setYAPCallback(cb);
doInit(BootMode);
doInit(BootMode);
}
YAPPredicate::YAPPredicate(YAPAtom at)
{
CACHE_REGS

View File

@ -25,6 +25,10 @@ class X_API YAPPredicate;
Queries and engines
*/
#if __ANDROID__
#endif
/**
* @brief Queries
*
@ -94,11 +98,11 @@ YAPQuery() {
inline YAPQuery(const char *s) : YAPPredicate(s, tgoal, tnames)
{
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);
if (!ap)
return;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", vnames.text());
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "%s", names.text());
goal = YAPTerm(tgoal);
if (IsPairTerm(tgoal)) {
qt = RepPair(tgoal);
@ -151,6 +155,7 @@ void close();
/// query variables.
void cut();
Term namedVars() {return names.term(); };
YAPPairTerm namedVarTerms() {return names; };
/// query variables, but copied out
std::vector<Term> namedVarsVector() {
return names.listToArray(); };
@ -180,170 +185,179 @@ public:
virtual void run(char *s) {}
};
void YAP_init_args::YAP_init_args()
{
Yap_InitDefaults(this, NULL, 0, NULL);
} ;
/// @brief Setup all arguments to a new engine
class X_API YAPEngineArgs {
struct X_API YAPEngineArgs: YAP_init_args {
public:
YAP_init_args init_args;
YAPEngineArgs(): yap_boot_params() {
#if YAP_PYTHON
Embedded = true;
python_in_python = Py_IsInitialized();
#endif
};
inline void setEmbedded( bool fl )
{
init_args.Embedded = fl;
Embedded = fl;
};
inline bool getEmbedded( )
{
return init_args.Embedded;
return Embedded;
};
inline void setStackSize( bool fl )
{
init_args.StackSize = fl;
StackSize = fl;
};
inline bool getStackSize( )
{
return init_args.StackSize;
return StackSize;
};
inline void setTrailSize( bool fl )
{
init_args.TrailSize = fl;
TrailSize = fl;
};
inline bool getTrailSize( )
{
return init_args.TrailSize;
return TrailSize;
};
inline bool getMStackSize( )
{
return init_args.StackSize;
return StackSize;
};
inline void setMaxTrailSize( bool fl )
{
init_args.MaxTrailSize = fl;
MaxTrailSize = fl;
};
inline bool getMaxTrailSize( )
{
return init_args.MaxTrailSize;
return MaxTrailSize;
};
inline void setYapLibDir( const char * fl )
{
init_args.YapLibDir = (const char *)malloc(strlen(fl)+1);
strcpy((char *)init_args.YapLibDir, fl);
YapLibDir = (const char *)malloc(strlen(fl)+1);
strcpy((char *)YapLibDir, fl);
};
inline const char * getYapLibDir( )
{
return init_args.YapLibDir;
return YapLibDir;
};
inline void setYapShareDir( const char * fl )
{
init_args.YapShareDir = (const char *)malloc(strlen(fl)+1);
strcpy((char *)init_args.YapShareDir, fl);
YapShareDir = (const char *)malloc(strlen(fl)+1);
strcpy((char *)YapShareDir, fl);
};
inline const char * getYapShareDir( )
{
return init_args.YapShareDir;
return YapShareDir;
};
inline void setSavedState( const char * fl )
{
init_args.SavedState = (const char *)malloc(strlen(fl)+1);
strcpy((char *)init_args.SavedState, fl);
SavedState = (const char *)malloc(strlen(fl)+1);
strcpy((char *)SavedState, fl);
};
inline const char * getSavedState( )
{
return init_args.SavedState;
return SavedState;
};
inline void setYapPrologBootFile( const char * fl )
{
init_args.YapPrologBootFile = (const char *)malloc(strlen(fl)+1);
strcpy((char *)init_args.YapPrologBootFile, fl);
YapPrologBootFile = (const char *)malloc(strlen(fl)+1);
strcpy((char *)YapPrologBootFile, fl);
};
inline const char * getYapPrologBootFile( )
{
return init_args.YapPrologBootFile;
return YapPrologBootFile;
};
inline void setYapPrologGoal( const char * fl )
{
init_args.YapPrologGoal = fl;
YapPrologGoal = fl;
};
inline const char * getYapPrologGoal( )
{
return init_args.YapPrologGoal;
return YapPrologGoal;
};
inline void setYapPrologTopLevelGoal( const char * fl )
{
init_args.YapPrologTopLevelGoal = fl;
YapPrologTopLevelGoal = fl;
};
inline const char * getYapPrologTopLevelGoal( )
{
return init_args.YapPrologTopLevelGoal;
return YapPrologTopLevelGoal;
};
inline void setHaltAfterConsult( bool fl )
{
init_args.HaltAfterConsult = fl;
HaltAfterConsult = fl;
};
inline bool getHaltAfterConsult( )
{
return init_args.HaltAfterConsult;
return HaltAfterConsult;
};
inline void setFastBoot( bool fl )
{
init_args.FastBoot = fl;
FastBoot = fl;
};
inline bool getFastBoot( )
{
return init_args.FastBoot;
};
inline bool getFastBoot( )
{
return FastBoot;
};
#if __ANDROID__
//> export ResoourceManager
inline void setAssetManager( AAssetManager *mgr )
{
assetManager = mgr;
};
#endif
inline void setArgc( int fl )
{
init_args.Argc = fl;
Argc = fl;
};
inline int getArgc( )
{
return init_args.Argc;
return Argc;
};
inline void setArgv( char ** fl )
{
init_args.Argv = fl;
Argv = fl;
};
inline char ** getArgv( )
{
return init_args.Argv;
return Argv;
};
YAPEngineArgs() {
Yap_InitDefaults(&init_args, NULL, 0, NULL);
#if YAP_PYTHON
init_args.Embedded = true;
python_in_python = Py_IsInitialized();
#endif
};
};
@ -368,7 +382,7 @@ private:
YAPEngine(YAPEngineArgs *cargs)
{
engine_args = cargs;
//doInit(cargs->init_args.boot_file_type);
//doInit(cargs->boot_file_type);
doInit(YAP_QLY);
}; /// construct a new engine, including aaccess to callbacks
/// construct a new engine using argc/argv list of arguments

View File

@ -112,7 +112,18 @@ public:
inline Term term() {
return gt();
} /// from YAPTerm to Term (internal YAP representation)
inline void bind(Term b) { LOCAL_HandleBase[t] = b; }
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(YAPTerm *b) { LOCAL_HandleBase[t] = b->term(); }
/// from YAPTerm to Term (internal YAP representation)
/// fetch a sub-term
@ -324,7 +335,7 @@ public:
RECOVER_MACHINE_REGS();
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 isInteger() { return false; } /// type check for integer
virtual bool isFloat() { return false; } /// type check for floating-point
@ -354,6 +365,9 @@ public:
YAPPairTerm();
Term getHead() { return (HeadOfTerm(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() {
Term *tailp;
Term t1 = gt();

View File

@ -67,7 +67,7 @@ extern int pop_text_stack__(int lvl USES_REGS);
(/*fprintf(stderr, "v %*c %s:%s:%d\n", AllocLevel(), ' ', __FILE__, \
__FUNCTION__, __LINE__),*/ \
pop_output_text_stack__(lvl,p))
extern void *pop_output_text_stack__(int lvl, void *ox USES_REGS);
extern void *pop_output_text_stack__(int lvl, const void *ox USES_REGS);
/****************** character definition table **************************/
@ -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) {
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;
if (!Yap_CVT_Text(&inp, &out PASS_REGS))
return 0L;
return NULL;
return out.val.uc0;
}
@ -1642,5 +1674,4 @@ static inline Term Yap_SubtractTailString(Term t1, Term th USES_REGS) {
#endif // ≈YAP_TEXT_H
extern const char *Yap_TextTermToText(Term t 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 void Yap_InitItDeepenPreds(void);
extern struct AliasDescS *Yap_InitStandardAliases(void);
extern struct vfs *Yap_InitAssetManager(void);
/* load_foreign.c */
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,
const char *root, char *result, bool access,
YAP_file_type_t ftype, bool expand_root, bool in_lib);
extern bool ChDir(const char *path);
/* threads.c */
extern void Yap_InitThreadPreds(void);
extern void Yap_InitFirstWorkerThreadHandle(void);

View File

@ -24,7 +24,7 @@
/* consulting files */
typedef union CONSULT_OBJ {
const unsigned char *filename;
const unsigned char *f_name;
int mode;
Prop p;
UInt c;

View File

@ -10,12 +10,27 @@
if (ANDROID)
set( GMP_ROOT ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI} )
set (GMP_INCLUDE_DIRS ${GMP_ROOT})
set (GMP_LIBRARIES ${GMP_ROOT}/libgmp.so)
set (GMP_FOUND ON)
set (GMP_LIBRARIES_DIR ${GMP_ROOT})
elif(MSVC)
set( GMP_LOC ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI} )
if (EXISTS ${GMP_LOC} )
message("Looking good for ${GMP_LOC}")
set(GMP_INCLUDE_DIRS ${GMP_LOC} CACHE PATH "include search path")
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
PATHS
$ENV{GMP_ROOT}
@ -84,6 +99,7 @@ else()
${GMP_LIBRARIES_DIR}/../include
${GMP_LIBRARIES_DIR}
)
endif()
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)
endif()

View File

@ -33,6 +33,7 @@
#include <encoding.h>
typedef struct {
dev_t st_dev; /* ID of device containing file */
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
const char *prefix;
const char *suffix;
bool (*id)(struct vfs *me, const char *s);
bool (*chDir)(struct vfs *me, const char *s);
/** operations */
void *(*open)(const char *s,
const char *io_mode); /// open an object
void *(*open)(int sno, const char *fname, const char *io_mode); /// open an object
/// in this space, usual w,r,a,b flags plus B (store in a buffer)
bool (*close)(int sno); /// close the object
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
int64_t (*seek)(int sno, int64_t offset,
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
void (*closedir)(void *d);
bool (*closedir)(void *d);
; /// close access a directory object
bool (*stat)(const char *s,
vfs_stat *); /// obtain size, age, permissions of a file.
bool (*isdir)(const char *s); /// verify whether is directory.
bool (*exists)(const char *s); /// verify whether a file exists.
bool (*chdir)(const char *s); /// set working directory (may be virtual).
bool (*isdir)(struct vfs *,const char *s); /// verify whether is directory.
bool (*exists)(struct vfs *, const char *s); /// verify whether a file exists.
bool (*chdir)(struct vfs *,const char *s); /// set working directory (may be virtual).
encoding_t enc; /// default file encoded.
YAP_Term (*parsers)(int sno); // a set of parsers that can read the
// 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;
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;
}
if (me->vflags & VFS_HAS_SUFFIX && (sz = strlen(me->suffix)) && (d = (sz0 - sz)) >= 0 &&
strcmp(fname + d, me->suffix) == 0)
return me;
if (me->vflags & VFS_HAS_FUNCTION && (me->id(me, fname))) {
strcmp(fname + d, me->suffix) == 0) {
return me;
}
me = me->next;

View File

@ -189,6 +189,11 @@ typedef encoding_t YAP_encoding_t;
#endif
#if __ANDROID__
#include <android/asset_manager.h>
#include <android/native_activity.h>
#endif
typedef struct YAP_thread_attr_struct {
size_t ssize;
size_t tsize;
@ -322,6 +327,10 @@ typedef struct yap_boot_params {
int QuietMode;
//> 0, maintain default, > 0 use fd-1, < 0 close
int inp, out, err;
#if __ANDROID__
//> android asset support
AAssetManager *assetManager;
#endif
/* support nf's ypp preprocessor code */
#define YAP_MAX_YPP_DEFS 100
char *def_var[YAP_MAX_YPP_DEFS];
@ -342,11 +351,14 @@ typedef struct yap_boot_params {
int ErrorNo;
//> errorstring
char *ErrorCause;
#ifdef __cplusplus
void YAP_init_args();
#endif
} YAP_init_args;
#ifdef YAP_H
YAP_file_type_t Yap_InitDefaults(YAP_init_args *init_args, char saved_state[],
int Argc, char *Argv[]);
int Argc, char **Argv);
#endif
/* this should be opaque to the user */

View File

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

View File

@ -33,107 +33,93 @@ static char SccsId[] = "%W% %G%";
// for native asset manager
#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_YAPDroid_setAssetManager(JNIEnv* env, jclass clazz, jobject assetManager)
{
return me->priv[0].mgr;
Yap_assetManager = AAssetManager_fromJava(env, assetManager);
return true;
}
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
open_asset(struct vfs *me, struct stream_desc *st, const char *fname, const char
*io_mode)
static void *
open_asset__( int sno, const char *fname, const char *io_mode)
{
AAssetManager *mgr;
int mode;
const void *buf;
VFS_t *me = GLOBAL_Stream[sno].vfs;
if (strstr(fname,"/assets") == fname) {
// we're in
mgr = getMgr(me);
if (mgr == NULL) {
return PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil,
"asset manager",
fname);
}
if (strchr(io_mode, 'w') || strchr(io_mode, 'a')) {
return PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil,
"%s: no writing but flags are %s",
fname, io_mode);
}
if (strchr(io_mode, 'B'))
mode = AASSET_MODE_BUFFER;
else
{
mode = AASSET_MODE_UNKNOWN;
// we're in
if ( Yap_assetManager == NULL) {
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil,
"asset manager",
fname);
return NULL;
}
AAsset *a = AAssetManager_open(mgr , fname, mode);
// try not to use it as an asset
off64_t sz = AAsset_getLength64(a), sz0 = 0;
int fd;
if ((fd = AAsset_openFileDescriptor64(a, &sz0, &sz)) >= 0) {
// can use it as red-only file
st->file = fdopen( fd, "r");
if (strchr(io_mode, 'w') || strchr(io_mode, 'a')) {
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, TermNil,
"%s: no writing but flags are %s",
fname, io_mode);
return NULL;
}
if (strchr(io_mode, 'B'))
mode = AASSET_MODE_BUFFER;
else {
mode = AASSET_MODE_UNKNOWN;
}
AAsset *a = AAssetManager_open( Yap_assetManager, fname, mode);
// try not to use it as an asset
off64_t sz = AAsset_getLength64(a), sz0 = 0;
int fd;
StreamDesc *st = GLOBAL_Stream+sno;
if ((fd = AAsset_openFileDescriptor64(a, &sz0, &sz)) >= 0) {
// can use it as red-only file
st->file = fdopen(fd, "r");
st->vfs = me;
st->vfs_handle = a;
return a;
} else if ((buf = AAsset_getBuffer(a))) {
// copy to memory
bool rc = Yap_set_stream_to_buf(st, buf, sz);
if (rc) AAsset_close(a);
return st;
}
// should be done, but if not
GLOBAL_Stream[sno].vfs_handle= a;
st->vfs = me;
st->vfs_handle = a;
return true;
} else if ((buf = AAsset_getBuffer(a)) ) {
// copy to memory
bool rc = Yap_set_stream_to_buf(st, buf, sz);
AAsset_close(a);
return rc;
}
// should be done, but if not
st->vfs_handle = a;
st->vfs = me;
return true;
}
if (me->next) {
return me->next->open(me->next, st, fname, io_mode);
return a;
}
return NULL;
}
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;
}
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;
if ( AAsset_read (st->vfs_handle, &ch, 1) )
if ( AAsset_read (GLOBAL_Stream[sno].vfs_handle, &ch, 1) )
return ch;
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)
@ -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;
if (stat64( "/assets", &bf)) {
struct stat bf;
if (stat( "/assets", &bf)) {
out->st_dev = bf.st_dev;
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_birthtimespec, (const void *)&out->st_birthtimespec, sizeof(struct timespec));
}
AAssetManager *mgr = getMgr(me);
AAsset *a = AAssetManager_open(mgr , fname, AASSET_MODE_UNKNOWN);
AAsset *a = AAssetManager_open( Yap_assetManager , fname, AASSET_MODE_UNKNOWN);
// try not to use it as an asset
out->st_size = AAsset_getLength64(a);
AAsset_close(a);
@ -171,11 +156,11 @@ static bool stat_a(struct vfs *me, const char *fname, vfs_stat *out)
}
static
bool is_dir_a(struct vfs *me, const char *dirName)
bool is_dir_a( VFS_t *me,const char *dirName)
{
bool rc;
// 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)
return false;
rc = (AAssetDir_getNextFileName(d) != NULL);
@ -184,22 +169,22 @@ bool is_dir_a(struct vfs *me, const char *dirName)
}
static
bool exists_a(struct vfs *me, const char *dirName)
VFS_t *exists_a(VFS_t *me, const char *dirName)
{
// 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)
return false;
return NULL;
AAsset_close(d);
return true;
return me;
}
static bool set_cwd (struct vfs *me, const char *dirName) {
static bool set_cwd (VFS_t *me, const char *dirName) {
chdir("/assets");
if (me->virtual_cwd)
free(me->virtual_cwd);
free((void*)(me->virtual_cwd));
me->virtual_cwd = malloc( sizeof(dirName) + 1 );
return me!= NULL;
}
@ -207,23 +192,23 @@ static bool set_cwd (struct vfs *me, const char *dirName) {
#endif
/* create a new alias arg for stream sno */
VFS_t *
Yap_InitAssetManager(void)
Yap_InitAssetManager( void )
{
#if __ANDROID__O
#if __ANDROID__
VFS_t *me;
/* init standard VFS */
me = (VFS_t *)Yap_AllocCodeSpace(sizeof(struct vfs));
me->name = "/assets";
me->vflags = VFS_CAN_EXEC|VFS_CAN_SEEK|VFS_HAS_PREFIX; /// the main flags describing the operation of the Fs.
me->prefix = "/assets";
/** 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->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->opendir = opendir_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) */
Int n;
Term t1;
int sno;
int sno = LOCAL_c_output_stream;
int ch;
if (IsVarTerm(t1 = Deref(ARG1))) {

View File

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

View File

@ -246,20 +246,18 @@ static void unix_upd_stream_info(StreamDesc *s) {
void Yap_DefaultStreamOps(StreamDesc *st) {
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;
if (st->encoding == ENC_ISO_UTF8)
st->stream_wgetc = get_wchar_UTF8;
else
st->stream_wgetc = get_wchar;
st->stream_putc = FilePutc;
st->stream_getc = PlGetc;
if (st->vfs) {
st->stream_putc = st->vfs->put_char;
st->stream_wgetc = st->vfs->get_char;
} else {
st->stream_putc = FilePutc;
st->stream_getc = PlGetc;
}
if (st->status & (Promptable_Stream_f)) {
Yap_ConsoleOps(st);
}
@ -300,7 +298,7 @@ static void InitStdStream(int sno, SMALLUNSGN flags, FILE *file, VFS_t *vfsp) {
INIT_LOCK(s->streamlock);
if (vfsp != NULL) {
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) {
(PlIOError(EXISTENCE_ERROR_SOURCE_SINK, MkIntTerm(sno), "%s",
vfsp->name));
@ -1312,7 +1310,7 @@ do_open(Term file_name, Term t2,
}
struct vfs *vfsp = 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;
if (st->u.private_data == NULL)
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name, "%s", fname));
@ -1522,7 +1520,56 @@ static Int p_open_null_stream(USES_REGS1) {
return (Yap_unify(ARG1, t));
}
int Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags) {
int Yap_OpenStream(const char *fname, const char * io_mode) {
CACHE_REGS
int sno;
StreamDesc *st;
Atom at;
struct vfs *vfsp;
FILE *fd;
int flags;
sno = GetFreeStreamD();
if (sno < 0)
return (PlIOError(RESOURCE_ERROR_MAX_STREAMS, MkAtomTerm(Yap_LookupAtom(fname)),
"new stream not available for opening"));
st = GLOBAL_Stream+sno;
vfsp = NULL;
if ((vfsp = vfs_owner(fname)) != NULL) {
st->u.private_data = vfsp->open(sno, fname, io_mode);
UNLOCK(st->streamlock);
fd = NULL;
if (st->u.private_data == NULL)
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, MkAtomTerm(Yap_LookupAtom(fname)), "%s", fname));
st->vfs = vfsp;
} else if ((fd = fopen(fname, io_mode)) == NULL ||
(!strchr(io_mode, 'b') && binary_file(fname))) {
UNLOCK(st->streamlock);
if (errno == ENOENT && !strchr(io_mode, 'r')) {
return PlIOError(EXISTENCE_ERROR_SOURCE_SINK, MkAtomTerm(Yap_LookupAtom(fname)), "%s: %s", fname,
strerror(errno));
} else {
return PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, MkAtomTerm(Yap_LookupAtom(fname)), "%s: %s",
fname, strerror(errno));
}
}
if (strchr(io_mode, 'r')) {
if (strchr(io_mode, 'a')) {
at = AtomAppend;
flags = Append_Stream_f | Output_Stream_f;
} else {
at = AtomWrite;
flags = Output_Stream_f;
}
} else {
at = AtomRead;
flags = Input_Stream_f;
}
Yap_initStream(sno, fd, fname, fname, LOCAL_encoding, flags, at, NULL);
return sno;
}
int Yap_FileStream(FILE *fd, char *name, Term file_name, int flags) {
CACHE_REGS
int sno;
Atom at;
@ -1542,6 +1589,26 @@ int Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags) {
return sno;
}
int FileStream(FILE* fd, char *name, Term file_name, int flags )
{
int sno;
Atom at;
sno = GetFreeStreamD();
if (sno < 0)
return (PlIOError(RESOURCE_ERROR_MAX_STREAMS, name,
"new stream not available for opening"));
if (flags & Output_Stream_f) {
if (flags & Append_Stream_f)
at = AtomAppend;
else
at = AtomWrite;
} else
at = AtomRead;
Yap_initStream(sno, fd, name, file_name, LOCAL_encoding, flags, at, NULL);
return sno;
}
#define CheckStream(arg, kind, msg) \
CheckStream__(__FILE__, __FUNCTION__, __LINE__, arg, kind, msg)
@ -1869,8 +1936,7 @@ static Int get_abs_file_parameter(USES_REGS1) {
void Yap_InitPlIO(struct yap_boot_params *argi) {
Int i;
if (argi->inp > 0)
if (argi->inp > 0)
Yap_stdin = fdopen(argi->inp - 1, "r");
else if (argi->inp)
Yap_stdin = NULL;

View File

@ -283,8 +283,4 @@ static inline void freeBuffer(const void *ptr) {
free((void *)ptr);
}
/** VFS handling */
VFS_t *Yap_InitAssetManager(void);
#endif

View File

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

View File

@ -79,7 +79,7 @@ static bool is_directory(const char *FileName) {
VFS_t *vfs;
if ((vfs = vfs_owner(FileName))) {
return vfs->isdir(FileName);
return vfs->isdir(vfs,FileName);
}
#ifdef _WIN32
DWORD dwAtts = GetFileAttributes(FileName);
@ -102,10 +102,9 @@ static bool is_directory(const char *FileName) {
}
bool Yap_Exists(const char *f) {
VFS_t *vfs;
if ((vfs = vfs_owner(f))) {
return vfs->exists(f);
VFS_t *vfs;
if ((vfs = vfs_owner(f))) {
return vfs->exists(vfs,f) != NULL;
}
#if _WIN32
if (_access(f, 0) == 0)
@ -169,9 +168,10 @@ bool Yap_IsAbsolutePath(const char *p0) {
static const char *PlExpandVars(const char *source, const char *root,
char *result) {
CACHE_REGS
int lvl = push_text_stack();
const char *src = source;
if (!result)
result = BaseMalloc(YAP_FILENAME_MAX + 1);
result = Malloc(YAP_FILENAME_MAX + 1);
if (strlen(source) >= YAP_FILENAME_MAX) {
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil,
@ -194,6 +194,7 @@ static const char *PlExpandVars(const char *source, const char *root,
if (s != NULL)
strncpy(result, s, YAP_FILENAME_MAX);
strcat(result, src);
result = pop_output_text_stack(lvl, result);
return result;
} else {
#if HAVE_GETPWNAM
@ -208,6 +209,7 @@ static const char *PlExpandVars(const char *source, const char *root,
FileError(SYSTEM_ERROR_OPERATING_SYSTEM,
MkAtomTerm(Yap_LookupAtom(source)),
"User %s does not exist in %s", result, source);
pop_text_stack(lvl);
return NULL;
}
strncpy(result, user_passwd->pw_dir, YAP_FILENAME_MAX);
@ -219,6 +221,7 @@ static const char *PlExpandVars(const char *source, const char *root,
return NULL;
#endif
}
result = pop_output_text_stack(lvl, result);
return result;
}
// do VARIABLE expansion
@ -260,6 +263,7 @@ static const char *PlExpandVars(const char *source, const char *root,
if (tocp > YAP_FILENAME_MAX) {
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, MkStringTerm(src),
"path too long");
pop_text_stack(lvl);
return NULL;
}
if (root && !Yap_IsAbsolutePath(source)) {
@ -271,6 +275,7 @@ static const char *PlExpandVars(const char *source, const char *root,
strncpy(result, source, strlen(src) + 1);
}
}
result = pop_output_text_stack(lvl, result);
return result;
}
@ -341,14 +346,14 @@ static char *PrologPath(const char *Y, char *X) { return (char *)Y; }
#define HAVE_REALPATH 1
#endif
static bool ChDir(const char *path) {
bool ChDir(const char *path) {
bool rc = false;
char qp[FILENAME_MAX + 1];
const char *qpath = Yap_AbsoluteFile(path, qp, true);
VFS_t *v;
if ((v = vfs_owner(path))) {
return v->chdir(path);
return v->chdir(v, path);
}
#if _WIN32
rc = true;
@ -1242,7 +1247,8 @@ const char *Yap_findFile(const char *isource, const char *idef,
if (ftype == YAP_PL) {
root = YAP_SHAREDIR;
} else if (ftype == YAP_BOOT_PL) {
root = YAP_SHAREDIR;
root = malloc(YAP_FILENAME_MAX+1);
strcpy(root, YAP_SHAREDIR);
strcat(root,"/pl");
} else {
root = YAP_LIBDIR;

View File

@ -22,11 +22,14 @@
#undef HAVE_LIBREADLINE
#endif
#include "YapStreams.h"
#include <stdio.h>
#include <wchar.h>
#include "YapIOConfig.h"
#include <Yatom.h>
#include <VFS.h>
#ifndef _PL_WRITE_
@ -45,6 +48,13 @@ typedef struct AliasDescS {
/* parser stack, used to be AuxSp, now is ASP */
#define ParserAuxSp LOCAL_ScannerStack
/**
*
* @return a new VFS that will support /assets
*/
extern VFS_t *Yap_InitAssetManager( void );
/* routines in parser.c */
extern VarEntry *Yap_LookupVar(const char *);
extern Term Yap_VarNames(VarEntry *, Term);
@ -76,7 +86,8 @@ extern int Yap_PlGetWchar(void);
extern int Yap_PlFGetchar(void);
extern int Yap_GetCharForSIGINT(void);
extern Int Yap_StreamToFileNo(Term);
extern int Yap_OpenStream(FILE *, char *, Term, int);
extern int Yap_OpenStream(const char*, const char *);
extern int Yap_FileStream(FILE*, char *, Term, int);
extern char *Yap_TermToString(Term t, encoding_t encoding, int flags);
extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length,
encoding_t *encoding, int flags);
@ -108,8 +119,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_open_buf_read_stream(const char *buf, size_t nchars,
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 Term Yap_BufferToTerm(const unsigned char *s, Term opts);
extern X_API Term Yap_BufferToTermWithPrioBindings(const unsigned char *s,
@ -151,4 +160,8 @@ INLINE_ONLY inline EXTERN Term MkCharTerm(Int c) {
extern uint64_t Yap_StartOfWTimes;
extern bool Yap_HandleSIGINT(void);
extern bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, size_t nchars USES_REGS);
#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.

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_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)

View File

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

View File

@ -52,7 +52,7 @@ The following predicates construct a BDD:
tell_warning :-
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_)

View File

@ -19,7 +19,7 @@ for the relative license.
FILE *open_file (char *filename, const char *mode);
FILE *open_file (char *file_name, const char *mode);
static YAP_Bool compute_prob(void);
variables createVars(YAP_Term t,DdManager * mgr, int create_dot, char inames[1000][20])
@ -214,14 +214,14 @@ void init_my_predicates()
YAP_UserCPredicate("compute_prob",compute_prob,4);
}
FILE * open_file(char *filename, const char *mode)
FILE * open_file(char *file_name, const char *mode)
/* opens a file */
{
FILE *fp;
if ((fp = fopen(filename, mode)) == NULL)
if ((fp = fopen(file_name, mode)) == NULL)
{
perror(filename);
perror(file_name);
exit(1);
}
return fp;

View File

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

View File

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

View File

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

View File

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

View File

@ -58,7 +58,12 @@ set(PL_BOOT_SOURCES
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
DEPENDS ${PL_BOOT_SOURCES}
)
@ -67,7 +72,6 @@ else ()
DEPENDS ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP}
)
add_custom_command(OUTPUT ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP}
COMMAND ldd yap
COMMAND ./yap -B
VERBATIM
WORKING_DIRECTORY ${CMAKE_TOP_BINARY_DIR}
@ -79,7 +83,7 @@ install(FILES ${CMAKE_TOP_BINARY_DIR}/${YAP_STARTUP}
)
endif()
install(FILES ${PL_SOURCES}
DESTINATION ${libpl}/pl
)