Merge /Users/vsc/github/yap-6.3
This commit is contained in:
commit
237430afb4
@ -134,11 +134,12 @@ inline static Atom SearchInInvisible(const unsigned char *atom) {
|
|||||||
|
|
||||||
static inline Atom SearchAtom(const unsigned char *p, Atom a) {
|
static inline Atom SearchAtom(const unsigned char *p, Atom a) {
|
||||||
AtomEntry *ae;
|
AtomEntry *ae;
|
||||||
|
const char *ps = (const char *)p;
|
||||||
|
|
||||||
/* search atom in chain */
|
/* search atom in chain */
|
||||||
while (a != NIL) {
|
while (a != NIL) {
|
||||||
ae = RepAtom(a);
|
ae = RepAtom(a);
|
||||||
if (strcmp(ae->UStrOfAE, p) == 0) {
|
if (strcmp(ae->StrOfAE, ps) == 0) {
|
||||||
return (a);
|
return (a);
|
||||||
}
|
}
|
||||||
a = ae->NextOfAE;
|
a = ae->NextOfAE;
|
||||||
|
@ -77,10 +77,11 @@ void *my_malloc(size_t sz) {
|
|||||||
p = malloc(sz);
|
p = malloc(sz);
|
||||||
// Yap_DebugPuts(stderr,"gof\n");
|
// Yap_DebugPuts(stderr,"gof\n");
|
||||||
if (Yap_do_low_level_trace)
|
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);
|
fprintf(stderr, "+s %p\n @%p %ld\n", p, TR, LCL0 - (CELL *)LCL0);
|
||||||
if (sz > 500 && write_malloc++ > 0)
|
#endif
|
||||||
__android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "+ %d %p", write_malloc,
|
|
||||||
p);
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +101,7 @@ void *my_realloc(void *ptr, size_t sz) {
|
|||||||
void my_free(void *p) {
|
void my_free(void *p) {
|
||||||
// printf("f %p\n",p);
|
// printf("f %p\n",p);
|
||||||
if (Yap_do_low_level_trace)
|
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)
|
if (write_malloc && write_malloc++ > 0)
|
||||||
__android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "- %d %p", write_malloc,
|
__android_log_print(ANDROID_LOG_ERROR, "YAPDroid ", "- %d %p", write_malloc,
|
||||||
p);
|
p);
|
||||||
|
@ -17,6 +17,10 @@
|
|||||||
/* for freeBSD9.1 */
|
/* for freeBSD9.1 */
|
||||||
#define _WITH_DPRINTF
|
#define _WITH_DPRINTF
|
||||||
|
|
||||||
|
#ifdef CONDA_BUILD
|
||||||
|
#undef HAVE_FMEMOPEN
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __APPLE__
|
#ifdef __APPLE__
|
||||||
#include "fmemopen.h"
|
#include "fmemopen.h"
|
||||||
#endif
|
#endif
|
||||||
@ -209,8 +213,8 @@ bool YAP_get_blob(Term t, void **blob, size_t *len, blob_type_t **type) {
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void *YAP_blob_data(Atom x, size_t *len, blob_type_t **type) {
|
void *YAP_blob_data(YAP_Atom at, size_t *len, blob_type_t **type) {
|
||||||
|
Atom x = at;
|
||||||
if (!IsBlob(x)) {
|
if (!IsBlob(x)) {
|
||||||
|
|
||||||
if (len)
|
if (len)
|
||||||
|
1090
C/c_interface.c
1090
C/c_interface.c
File diff suppressed because it is too large
Load Diff
13
C/cdmgr.c
13
C/cdmgr.c
@ -1873,8 +1873,6 @@ bool Yap_addclause(Term t, yamop *cp, Term tmode, Term mod, Term *t4ref)
|
|||||||
} else {
|
} else {
|
||||||
tf = Yap_MkStaticRefTerm(ClauseCodeToStaticClause(cp), p);
|
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)
|
if (mod == PROLOG_MODULE)
|
||||||
mod = TermProlog;
|
mod = TermProlog;
|
||||||
if (pflags & MultiFileFlag) {
|
if (pflags & MultiFileFlag) {
|
||||||
@ -2059,12 +2057,12 @@ Atom Yap_ConsultingFile(USES_REGS1) {
|
|||||||
if (LOCAL_consult_level == 0) {
|
if (LOCAL_consult_level == 0) {
|
||||||
return (AtomUser);
|
return (AtomUser);
|
||||||
} else {
|
} 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 */
|
/* consult file *file*, *mode* may be one of either consult or reconsult */
|
||||||
static void init_consult(int mode, const unsigned char *file) {
|
void Yap_init_consult(int mode, const char *filenam) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
if (!LOCAL_ConsultSp) {
|
if (!LOCAL_ConsultSp) {
|
||||||
InitConsultStack();
|
InitConsultStack();
|
||||||
@ -2073,7 +2071,7 @@ static void init_consult(int mode, const unsigned char *file) {
|
|||||||
expand_consult();
|
expand_consult();
|
||||||
}
|
}
|
||||||
LOCAL_ConsultSp--;
|
LOCAL_ConsultSp--;
|
||||||
LOCAL_ConsultSp->filename = file;
|
LOCAL_ConsultSp->f_name = (const unsigned char *)filenam;
|
||||||
LOCAL_ConsultSp--;
|
LOCAL_ConsultSp--;
|
||||||
LOCAL_ConsultSp->mode = mode;
|
LOCAL_ConsultSp->mode = mode;
|
||||||
LOCAL_ConsultSp--;
|
LOCAL_ConsultSp--;
|
||||||
@ -2085,10 +2083,7 @@ static void init_consult(int mode, const unsigned char *file) {
|
|||||||
#endif
|
#endif
|
||||||
LOCAL_consult_level++;
|
LOCAL_consult_level++;
|
||||||
LOCAL_LastAssertedPred = NULL;
|
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) */
|
static Int p_startconsult(USES_REGS1) { /* '$start_consult'(+Mode) */
|
||||||
@ -2097,7 +2092,7 @@ static Int p_startconsult(USES_REGS1) { /* '$start_consult'(+Mode) */
|
|||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
mode = strcmp("consult", (char *)smode);
|
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);
|
t = MkIntTerm(LOCAL_consult_level);
|
||||||
return (Yap_unify_constant(ARG3, t));
|
return (Yap_unify_constant(ARG3, t));
|
||||||
}
|
}
|
||||||
|
@ -4911,17 +4911,17 @@ static Int cont_current_key_integer(USES_REGS1) {
|
|||||||
return Yap_unify(term, ARG1) && Yap_unify(term, ARG2);
|
return Yap_unify(term, ARG1) && Yap_unify(term, ARG2);
|
||||||
}
|
}
|
||||||
|
|
||||||
Term Yap_FetchTermFromDB(DBTerm *ref) {
|
Term Yap_FetchTermFromDB(void *ref) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
return GetDBTerm(ref, FALSE PASS_REGS);
|
return GetDBTerm(ref, FALSE PASS_REGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
Term Yap_FetchClauseTermFromDB(DBTerm *ref) {
|
Term Yap_FetchClauseTermFromDB(void *ref) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
return GetDBTerm(ref, TRUE PASS_REGS);
|
return GetDBTerm(ref, TRUE PASS_REGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
Term Yap_PopTermFromDB(DBTerm *ref) {
|
Term Yap_PopTermFromDB(void *ref) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
Term t = GetDBTerm(ref, FALSE PASS_REGS);
|
Term t = GetDBTerm(ref, FALSE PASS_REGS);
|
||||||
@ -5304,7 +5304,7 @@ static void ReleaseTermFromDB(DBTerm *ref USES_REGS) {
|
|||||||
FreeDBSpace((char *)ref);
|
FreeDBSpace((char *)ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Yap_ReleaseTermFromDB(DBTerm *ref) {
|
void Yap_ReleaseTermFromDB(void *ref) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
ReleaseTermFromDB(ref PASS_REGS);
|
ReleaseTermFromDB(ref PASS_REGS);
|
||||||
}
|
}
|
||||||
|
@ -303,7 +303,7 @@ static char tmpbuf[YAP_BUF_SIZE];
|
|||||||
}
|
}
|
||||||
|
|
||||||
#include "YapErrors.h"
|
#include "YapErrors.h"
|
||||||
|
//
|
||||||
void Yap_pushErrorContext(yap_error_descriptor_t *new_error) {
|
void Yap_pushErrorContext(yap_error_descriptor_t *new_error) {
|
||||||
new_error->top_error = LOCAL_ActiveError;
|
new_error->top_error = LOCAL_ActiveError;
|
||||||
LOCAL_ActiveError = new_error;
|
LOCAL_ActiveError = new_error;
|
||||||
@ -386,10 +386,10 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
|
|||||||
Yap_RestartYap(1);
|
Yap_RestartYap(1);
|
||||||
}
|
}
|
||||||
LOCAL_ActiveError->errorNo = type;
|
LOCAL_ActiveError->errorNo = type;
|
||||||
LOCAL_ActiveError->errorAsText = Yap_LookupAtom(Yap_errorName(type));
|
LOCAL_ActiveError->errorAsText = Yap_errorName(type);
|
||||||
LOCAL_ActiveError->errorClass = Yap_errorClass(type);
|
LOCAL_ActiveError->errorClass = Yap_errorClass(type);
|
||||||
LOCAL_ActiveError->classAsText =
|
LOCAL_ActiveError->classAsText =
|
||||||
Yap_LookupAtom(Yap_errorClassName(LOCAL_ActiveError->errorClass));
|
Yap_errorClassName(LOCAL_ActiveError->errorClass);
|
||||||
LOCAL_ActiveError->errorLine = lineno;
|
LOCAL_ActiveError->errorLine = lineno;
|
||||||
LOCAL_ActiveError->errorFunction = function;
|
LOCAL_ActiveError->errorFunction = function;
|
||||||
LOCAL_ActiveError->errorFile = file;
|
LOCAL_ActiveError->errorFile = file;
|
||||||
|
6
C/exec.c
6
C/exec.c
@ -2039,10 +2039,10 @@ static Int jump_env(USES_REGS1) {
|
|||||||
// LOCAL_Error_TYPE = ERROR_EVENT;
|
// LOCAL_Error_TYPE = ERROR_EVENT;
|
||||||
Term t1 = ArgOfTerm(1, t);
|
Term t1 = ArgOfTerm(1, t);
|
||||||
if (IsApplTerm(t1) && IsAtomTerm((t2 = ArgOfTerm(1, t1)))) {
|
if (IsApplTerm(t1) && IsAtomTerm((t2 = ArgOfTerm(1, t1)))) {
|
||||||
LOCAL_ActiveError->errorAsText = AtomOfTerm(t2);
|
LOCAL_ActiveError->errorAsText = RepAtom(AtomOfTerm(t2))->StrOfAE;
|
||||||
LOCAL_ActiveError->classAsText = NameOfFunctor(FunctorOfTerm(t1));
|
LOCAL_ActiveError->classAsText = RepAtom(NameOfFunctor(FunctorOfTerm(t1)))->StrOfAE;
|
||||||
} else if (IsAtomTerm(t)) {
|
} else if (IsAtomTerm(t)) {
|
||||||
LOCAL_ActiveError->errorAsText = AtomOfTerm(t1);
|
LOCAL_ActiveError->errorAsText = RepAtom(AtomOfTerm(t1))->StrOfAE;
|
||||||
LOCAL_ActiveError->classAsText = NULL;
|
LOCAL_ActiveError->classAsText = NULL;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
28
C/load_dl.c
28
C/load_dl.c
@ -159,25 +159,18 @@ int Yap_CloseForeignFile(void *handle) {
|
|||||||
* LoadForeign(ofiles,libs,proc_name,init_proc) dynamically loads foreign
|
* LoadForeign(ofiles,libs,proc_name,init_proc) dynamically loads foreign
|
||||||
* code files and libraries and locates an initialization routine
|
* code files and libraries and locates an initialization routine
|
||||||
*/
|
*/
|
||||||
static Int LoadForeign(StringList ofiles, StringList libs, char *proc_name,
|
static Int LoadForeign(StringList
|
||||||
|
ofiles, StringList libs, char *proc_name,
|
||||||
YapInitProc *init_proc) {
|
YapInitProc *init_proc) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
LOCAL_ErrorMessage = NULL;
|
LOCAL_ErrorMessage = NULL;
|
||||||
|
|
||||||
while (libs) {
|
while (libs) {
|
||||||
const char *file = AtomName(libs->name);
|
const char *file = AtomName(libs->name);
|
||||||
if (!Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true,
|
|
||||||
true)) {
|
|
||||||
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);
|
|
||||||
/* use LD_LIBRARY_PATH */
|
|
||||||
strncpy(LOCAL_ErrorMessage, (char *)AtomName(libs->name),
|
|
||||||
YAP_FILENAME_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __osf__
|
#ifdef __osf__
|
||||||
if ((libs->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY)) == NULL)
|
if ((libs->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY)) == NULL)
|
||||||
#else
|
#else
|
||||||
if ((libs->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY | RTLD_GLOBAL)) ==
|
if ((libs->handle = dlopen(file, RTLD_LAZY | RTLD_GLOBAL)) ==
|
||||||
NULL)
|
NULL)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
@ -194,20 +187,9 @@ static Int LoadForeign(StringList ofiles, StringList libs, char *proc_name,
|
|||||||
/* load libraries first so that their symbols are available to
|
/* load libraries first so that their symbols are available to
|
||||||
other routines */
|
other routines */
|
||||||
const char *file = AtomName(ofiles->name);
|
const char *file = AtomName(ofiles->name);
|
||||||
if (!Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true,
|
|
||||||
true)) {
|
if ((ofiles->handle = dlopen(file, RTLD_LAZY | RTLD_GLOBAL)) ==
|
||||||
if (LOCAL_ErrorMessage == NULL) {
|
|
||||||
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);
|
|
||||||
strcpy(LOCAL_ErrorMessage,
|
|
||||||
"%% Trying to open non-existing file in LoadForeign");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#ifdef __osf__
|
|
||||||
if ((ofiles->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY)) == NULL)
|
|
||||||
#else
|
|
||||||
if ((ofiles->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY | RTLD_GLOBAL)) ==
|
|
||||||
NULL)
|
NULL)
|
||||||
#endif
|
|
||||||
{
|
{
|
||||||
if (LOCAL_ErrorMessage == NULL) {
|
if (LOCAL_ErrorMessage == NULL) {
|
||||||
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);
|
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);
|
||||||
|
81
C/qlyr.c
81
C/qlyr.c
@ -597,8 +597,32 @@ static void RestoreHashPreds(USES_REGS1) {}
|
|||||||
|
|
||||||
static void RestoreAtomList(Atom atm USES_REGS) {}
|
static void RestoreAtomList(Atom atm USES_REGS) {}
|
||||||
|
|
||||||
|
static bool maybe_read_bytes(FILE *stream, void *ptr, size_t sz) {
|
||||||
|
do {
|
||||||
|
size_t count;
|
||||||
|
if ((count = fread(ptr, 1, sz, stream)) == sz)
|
||||||
|
return true;
|
||||||
|
if (feof(stream) || ferror(stream))
|
||||||
|
return false;
|
||||||
|
sz -= count;
|
||||||
|
ptr += count;
|
||||||
|
} while (true);
|
||||||
|
}
|
||||||
|
|
||||||
static size_t read_bytes(FILE *stream, void *ptr, size_t sz) {
|
static size_t read_bytes(FILE *stream, void *ptr, size_t sz) {
|
||||||
return fread(ptr, sz, 1, stream);
|
do {
|
||||||
|
size_t count = fread(ptr, 1, sz, stream);
|
||||||
|
if (count == sz)
|
||||||
|
return sz;
|
||||||
|
if (feof(stream)) {
|
||||||
|
PlIOError(PERMISSION_ERROR_INPUT_PAST_END_OF_STREAM, TermNil, "read_qly/3: expected %ld bytes got %ld", sz, count);
|
||||||
|
return 0;
|
||||||
|
} else if (ferror(stream)) {
|
||||||
|
PlIOError(PERMISSION_ERROR_INPUT_STREAM, TermNil, "read_qly/3: expected %ld bytes got error %s", sz, strerror(errno));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
sz -= count;
|
||||||
|
} while(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char read_byte(FILE *stream) { return getc(stream); }
|
static unsigned char read_byte(FILE *stream) { return getc(stream); }
|
||||||
@ -632,34 +656,26 @@ static pred_flags_t read_predFlags(FILE *stream) {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool checkChars(FILE *stream, char s[]) {
|
|
||||||
int ch, c;
|
|
||||||
char *p = s;
|
|
||||||
|
|
||||||
while ((ch = *p++)) {
|
|
||||||
if ((c = read_byte(stream)) != ch) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static Atom do_header(FILE *stream) {
|
static Atom do_header(FILE *stream) {
|
||||||
char s[2048], *p = s, ch;
|
char s[2049], *p = s, *q;
|
||||||
|
char h0[] = "#!/bin/sh\nexec_dir=${YAPBINDIR:-";
|
||||||
|
char h1[] = "exec $exec_dir/yap $0 \"$@\"\nsaved ";
|
||||||
Atom at;
|
Atom at;
|
||||||
|
|
||||||
if (!checkChars(stream, "#!/bin/sh\nexec_dir=${YAPBINDIR:-"))
|
if (!maybe_read_bytes( stream, s, 2048) )
|
||||||
return NIL;
|
return NIL;
|
||||||
while ((ch = read_byte(stream)) != '\n')
|
if (strstr(s, h0)!= s)
|
||||||
;
|
|
||||||
if (!checkChars(stream, "exec $exec_dir/yap $0 \"$@\"\nsaved "))
|
|
||||||
return NIL;
|
return NIL;
|
||||||
while ((ch = read_byte(stream)) != ',')
|
if ((p=strstr(s, h1)) == NULL) {
|
||||||
*p++ = ch;
|
return NIL;
|
||||||
*p++ = '\0';
|
}
|
||||||
at = Yap_LookupAtom(s);
|
p += strlen(h1);
|
||||||
while ((ch = read_byte(stream)))
|
q = strchr(p,',');
|
||||||
;
|
if (!q)
|
||||||
|
return NIL;
|
||||||
|
q[0] = '\0';
|
||||||
|
at = Yap_LookupAtom(p);
|
||||||
return at;
|
return at;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -674,12 +690,21 @@ static Int get_header(USES_REGS1) {
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
if (!(stream = Yap_GetInputStream(t1, "header scanning in qload"))) {
|
if (!(stream = Yap_GetInputStream(t1, "header scanning in qload"))) {
|
||||||
return FALSE;
|
return false;
|
||||||
|
}
|
||||||
|
sigjmp_buf signew, *sighold = LOCAL_RestartEnv;
|
||||||
|
LOCAL_RestartEnv = &signew;
|
||||||
|
|
||||||
|
if (sigsetjmp(signew, 1) != 0) {
|
||||||
|
LOCAL_RestartEnv = sighold;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
if ((at = do_header(stream)) == NIL)
|
if ((at = do_header(stream)) == NIL)
|
||||||
rc = FALSE;
|
rc = false;
|
||||||
else
|
else {
|
||||||
rc = Yap_unify(ARG2, MkAtomTerm(at));
|
rc = Yap_unify(ARG2, MkAtomTerm(at));
|
||||||
|
}
|
||||||
|
LOCAL_RestartEnv = sighold;
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1072,10 +1097,10 @@ static Int qload_program(USES_REGS1) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
YAP_file_type_t Yap_Restore(const char *s, const char *lib_dir) {
|
YAP_file_type_t Yap_Restore(const char *s) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
FILE *stream = Yap_OpenRestore(s, lib_dir);
|
FILE *stream = Yap_OpenRestore(s);
|
||||||
if (!stream)
|
if (!stream)
|
||||||
return -1;
|
return -1;
|
||||||
GLOBAL_RestoreFile = s;
|
GLOBAL_RestoreFile = s;
|
||||||
|
48
C/save.c
48
C/save.c
@ -87,7 +87,7 @@ void initIO(void);
|
|||||||
|
|
||||||
static int myread(FILE *, char *, Int);
|
static int myread(FILE *, char *, Int);
|
||||||
static Int mywrite(FILE *, char *, Int);
|
static Int mywrite(FILE *, char *, Int);
|
||||||
static FILE *open_file(char *, int);
|
static FILE *open_file(const char *, int);
|
||||||
static int close_file(void);
|
static int close_file(void);
|
||||||
static Int putout(CELL);
|
static Int putout(CELL);
|
||||||
static Int putcellptr(CELL *);
|
static Int putcellptr(CELL *);
|
||||||
@ -123,7 +123,7 @@ static void restore_heap(void);
|
|||||||
static void ShowAtoms(void);
|
static void ShowAtoms(void);
|
||||||
static void ShowEntries(PropEntry *);
|
static void ShowEntries(PropEntry *);
|
||||||
#endif
|
#endif
|
||||||
static int OpenRestore(const char *, const char *, CELL *, CELL *, CELL *,
|
static int OpenRestore(const char *, CELL *, CELL *, CELL *,
|
||||||
CELL *, FILE **);
|
CELL *, FILE **);
|
||||||
static void CloseRestore(void);
|
static void CloseRestore(void);
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
@ -233,7 +233,7 @@ static Int OldHeapUsed;
|
|||||||
static CELL which_save;
|
static CELL which_save;
|
||||||
|
|
||||||
/* Open a file to read or to write */
|
/* Open a file to read or to write */
|
||||||
static FILE *open_file(char *my_file, int flag) {
|
static FILE *open_file(const char *my_file, int flag) {
|
||||||
FILE *splfild;
|
FILE *splfild;
|
||||||
char flags[6];
|
char flags[6];
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@ -1307,10 +1307,11 @@ static void ShowAtoms() {
|
|||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
static int commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail,
|
static int commit_to_saved_state(const char *s, CELL *Astate, CELL *ATrail,
|
||||||
CELL *AStack, CELL *AHeap) {
|
CELL *AStack, CELL *AHeap) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int mode;
|
int mode;
|
||||||
|
char tmp[YAP_FILENAME_MAX+1];
|
||||||
|
|
||||||
if ((mode = check_header(Astate, ATrail, AStack, AHeap PASS_REGS)) ==
|
if ((mode = check_header(Astate, ATrail, AStack, AHeap PASS_REGS)) ==
|
||||||
FAIL_RESTORE)
|
FAIL_RESTORE)
|
||||||
@ -1318,9 +1319,8 @@ static int commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail,
|
|||||||
LOCAL_PrologMode = BootMode;
|
LOCAL_PrologMode = BootMode;
|
||||||
if (Yap_HeapBase) {
|
if (Yap_HeapBase) {
|
||||||
if (falseGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG) && !silentMode()) {
|
if (falseGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG) && !silentMode()) {
|
||||||
Yap_findFile(s, NULL, NULL, LOCAL_FileNameBuf2, true, YAP_QLY, true,
|
Yap_AbsoluteFile(s, tmp, true);
|
||||||
true);
|
fprintf(stderr, "%% Restoring file %s\n", tmp);
|
||||||
fprintf(stderr, "%% Restoring file %s\n", LOCAL_FileNameBuf2);
|
|
||||||
}
|
}
|
||||||
Yap_CloseStreams(TRUE);
|
Yap_CloseStreams(TRUE);
|
||||||
}
|
}
|
||||||
@ -1333,7 +1333,7 @@ static int commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail,
|
|||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack,
|
static int try_open(const char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack,
|
||||||
CELL *AHeap, FILE **streamp) {
|
CELL *AHeap, FILE **streamp) {
|
||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
@ -1355,18 +1355,13 @@ static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack,
|
|||||||
return mode;
|
return mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int OpenRestore(const char *inpf, const char *YapLibDir, CELL *Astate,
|
static int OpenRestore(const char *fname, CELL *Astate,
|
||||||
CELL *ATrail, CELL *AStack, CELL *AHeap,
|
CELL *ATrail, CELL *AStack, CELL *AHeap,
|
||||||
FILE **streamp) {
|
FILE **streamp) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
int mode;
|
int mode;
|
||||||
char fname[YAP_FILENAME_MAX + 1];
|
if (fname && fname[0] && (mode = try_open(fname, Astate, ATrail, AStack, AHeap,
|
||||||
|
|
||||||
if (!Yap_findFile(inpf, YAP_STARTUP, YapLibDir, fname, true, YAP_SAVED_STATE,
|
|
||||||
true, true))
|
|
||||||
return FAIL_RESTORE;
|
|
||||||
if (fname[0] && (mode = try_open(fname, Astate, ATrail, AStack, AHeap,
|
|
||||||
streamp)) != FAIL_RESTORE) {
|
streamp)) != FAIL_RESTORE) {
|
||||||
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
|
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
|
||||||
MkAtomTerm(Yap_LookupAtom(fname)));
|
MkAtomTerm(Yap_LookupAtom(fname)));
|
||||||
@ -1378,22 +1373,19 @@ static int OpenRestore(const char *inpf, const char *YapLibDir, CELL *Astate,
|
|||||||
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,
|
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,
|
||||||
"incorrect saved state ");
|
"incorrect saved state ");
|
||||||
} else {
|
} else {
|
||||||
strncpy(LOCAL_FileNameBuf, inpf, YAP_FILENAME_MAX - 1);
|
strncpy(LOCAL_FileNameBuf, fname, YAP_FILENAME_MAX - 1);
|
||||||
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,
|
do_SYSTEM_ERROR_INTERNAL(PERMISSION_ERROR_OPEN_SOURCE_SINK,
|
||||||
"could not open saved state");
|
"could not open saved state");
|
||||||
}
|
}
|
||||||
return FAIL_RESTORE;
|
return FAIL_RESTORE;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *Yap_OpenRestore(const char *inpf, const char *YapLibDir) {
|
FILE *Yap_OpenRestore(const char *inpf) {
|
||||||
FILE *stream = NULL;
|
FILE *stream = NULL;
|
||||||
|
|
||||||
if (!inpf)
|
if (!inpf)
|
||||||
inpf = "startup.yss";
|
inpf = "startup.yss";
|
||||||
if (!YapLibDir) {
|
OpenRestore(inpf, NULL, NULL, NULL, NULL, &stream);
|
||||||
YapLibDir = YAP_LIBDIR;
|
|
||||||
}
|
|
||||||
OpenRestore(inpf, YapLibDir, NULL, NULL, NULL, NULL, &stream);
|
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1467,14 +1459,14 @@ static void RestoreHeap(OPCODE old_ops[] USES_REGS) {
|
|||||||
* This function is called to know about the parameters of the last saved
|
* This function is called to know about the parameters of the last saved
|
||||||
* state
|
* state
|
||||||
*/
|
*/
|
||||||
int Yap_SavedInfo(const char *FileName, const char *YapLibDir, CELL *ATrail,
|
int Yap_SavedInfo(const char *FileName, CELL *ATrail,
|
||||||
CELL *AStack, CELL *AHeap) {
|
CELL *AStack, CELL *AHeap) {
|
||||||
return DO_ONLY_CODE;
|
return DO_ONLY_CODE;
|
||||||
|
|
||||||
CELL MyTrail, MyStack, MyHeap, MyState;
|
CELL MyTrail, MyStack, MyHeap, MyState;
|
||||||
int mode;
|
int mode;
|
||||||
|
|
||||||
mode = OpenRestore(FileName, YapLibDir, &MyState, &MyTrail, &MyStack, &MyHeap,
|
mode = OpenRestore(FileName, &MyState, &MyTrail, &MyStack, &MyHeap,
|
||||||
NULL);
|
NULL);
|
||||||
if (mode == FAIL_RESTORE) {
|
if (mode == FAIL_RESTORE) {
|
||||||
return -1;
|
return -1;
|
||||||
@ -1554,13 +1546,13 @@ static void FreeRecords(void) {
|
|||||||
* This function is called when wanting only to restore the heap and
|
* This function is called when wanting only to restore the heap and
|
||||||
* associated registers
|
* associated registers
|
||||||
*/
|
*/
|
||||||
static int Restore(char *s, char *lib_dir USES_REGS) {
|
static int Restore(char *s_dir USES_REGS) {
|
||||||
int restore_mode;
|
int restore_mode;
|
||||||
|
|
||||||
OPCODE old_ops[_std_top + 1];
|
OPCODE old_ops[_std_top + 1];
|
||||||
CELL MyTrail, MyStack, MyHeap, MyState;
|
CELL MyTrail, MyStack, MyHeap, MyState;
|
||||||
|
|
||||||
if ((restore_mode = OpenRestore(s, lib_dir, &MyState, &MyTrail, &MyStack,
|
if ((restore_mode = OpenRestore(s_dir, &MyState, &MyTrail, &MyStack,
|
||||||
&MyHeap, NULL)) == FAIL_RESTORE)
|
&MyHeap, NULL)) == FAIL_RESTORE)
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
Yap_ShutdownLoadForeign();
|
Yap_ShutdownLoadForeign();
|
||||||
@ -1612,9 +1604,9 @@ static int Restore(char *s, char *lib_dir USES_REGS) {
|
|||||||
return restore_mode;
|
return restore_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Yap_SavedStateRestore(char *s, char *lib_dir) {
|
int Yap_SavedStateRestore(char *s) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
return Restore(s, lib_dir PASS_REGS);
|
return Restore(s PASS_REGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int p_restore(USES_REGS1) {
|
static Int p_restore(USES_REGS1) {
|
||||||
@ -1640,7 +1632,7 @@ static Int p_restore(USES_REGS1) {
|
|||||||
Yap_Error(TYPE_ERROR_LIST, t1, "restore/1");
|
Yap_Error(TYPE_ERROR_LIST, t1, "restore/1");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
if ((mode = Restore(s, NULL PASS_REGS)) == DO_ONLY_CODE) {
|
if ((mode = Restore(s PASS_REGS)) == DO_ONLY_CODE) {
|
||||||
Yap_RestartYap(3);
|
Yap_RestartYap(3);
|
||||||
}
|
}
|
||||||
return (mode != FAIL_RESTORE);
|
return (mode != FAIL_RESTORE);
|
||||||
|
229
C/scanner.c
229
C/scanner.c
@ -689,12 +689,12 @@ static int send_error_message(char s[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static wchar_t read_quoted_char(int *scan_nextp,
|
static wchar_t read_quoted_char(int *scan_nextp,
|
||||||
struct stream_desc *inp_stream) {
|
struct stream_desc *st) {
|
||||||
int ch;
|
int ch;
|
||||||
|
|
||||||
/* escape sequence */
|
/* escape sequence */
|
||||||
do_switch:
|
do_switch:
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 10:
|
case 10:
|
||||||
return 0;
|
return 0;
|
||||||
@ -705,7 +705,7 @@ do_switch:
|
|||||||
case 'b':
|
case 'b':
|
||||||
return '\b';
|
return '\b';
|
||||||
case 'c':
|
case 'c':
|
||||||
while (chtype((ch = getchrq(inp_stream))) == BS)
|
while (chtype((ch = getchrq(st))) == BS)
|
||||||
;
|
;
|
||||||
{
|
{
|
||||||
if (ch == '\\') {
|
if (ch == '\\') {
|
||||||
@ -732,7 +732,7 @@ do_switch:
|
|||||||
wchar_t wc = '\0';
|
wchar_t wc = '\0';
|
||||||
|
|
||||||
for (i = 0; i < 4; i++) {
|
for (i = 0; i < 4; i++) {
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
wc += (ch - '0') << ((3 - i) * 4);
|
wc += (ch - '0') << ((3 - i) * 4);
|
||||||
} else if (ch >= 'a' && ch <= 'f') {
|
} else if (ch >= 'a' && ch <= 'f') {
|
||||||
@ -750,7 +750,7 @@ do_switch:
|
|||||||
wchar_t wc = '\0';
|
wchar_t wc = '\0';
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch >= '0' && ch <= '9') {
|
if (ch >= '0' && ch <= '9') {
|
||||||
wc += (ch - '0') << ((7 - i) * 4);
|
wc += (ch - '0') << ((7 - i) * 4);
|
||||||
} else if (ch >= 'a' && ch <= 'f') {
|
} else if (ch >= 'a' && ch <= 'f') {
|
||||||
@ -777,7 +777,7 @@ do_switch:
|
|||||||
if (trueGlobalPrologFlag(ISO_FLAG)) {
|
if (trueGlobalPrologFlag(ISO_FLAG)) {
|
||||||
return send_error_message("invalid escape sequence");
|
return send_error_message("invalid escape sequence");
|
||||||
} else {
|
} else {
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch == '?') { /* delete character */
|
if (ch == '?') { /* delete character */
|
||||||
return 127;
|
return 127;
|
||||||
} else if (ch >= 'a' && ch < 'z') { /* hexa */
|
} else if (ch >= 'a' && ch < 'z') { /* hexa */
|
||||||
@ -800,13 +800,13 @@ do_switch:
|
|||||||
/* follow ISO */
|
/* follow ISO */
|
||||||
{
|
{
|
||||||
unsigned char so_far = ch - '0';
|
unsigned char so_far = ch - '0';
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch >= '0' && ch < '8') { /* octal */
|
if (ch >= '0' && ch < '8') { /* octal */
|
||||||
so_far = so_far * 8 + (ch - '0');
|
so_far = so_far * 8 + (ch - '0');
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch >= '0' && ch < '8') { /* octal */
|
if (ch >= '0' && ch < '8') { /* octal */
|
||||||
so_far = so_far * 8 + (ch - '0');
|
so_far = so_far * 8 + (ch - '0');
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch != '\\') {
|
if (ch != '\\') {
|
||||||
return send_error_message("invalid octal escape sequence");
|
return send_error_message("invalid octal escape sequence");
|
||||||
}
|
}
|
||||||
@ -826,19 +826,19 @@ do_switch:
|
|||||||
/* hexadecimal character (YAP allows empty hexadecimal */
|
/* hexadecimal character (YAP allows empty hexadecimal */
|
||||||
{
|
{
|
||||||
unsigned char so_far = 0;
|
unsigned char so_far = 0;
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (my_isxdigit(ch, 'f', 'F')) { /* hexa */
|
if (my_isxdigit(ch, 'f', 'F')) { /* hexa */
|
||||||
so_far =
|
so_far =
|
||||||
so_far * 16 + (chtype(ch) == NU
|
so_far * 16 + (chtype(ch) == NU
|
||||||
? ch - '0'
|
? ch - '0'
|
||||||
: (my_isupper(ch) ? ch - 'A' : ch - 'a') + 10);
|
: (my_isupper(ch) ? ch - 'A' : ch - 'a') + 10);
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (my_isxdigit(ch, 'f', 'F')) { /* hexa */
|
if (my_isxdigit(ch, 'f', 'F')) { /* hexa */
|
||||||
so_far =
|
so_far =
|
||||||
so_far * 16 + (chtype(ch) == NU
|
so_far * 16 + (chtype(ch) == NU
|
||||||
? ch - '0'
|
? ch - '0'
|
||||||
: (my_isupper(ch) ? ch - 'A' : ch - 'a') + 10);
|
: (my_isupper(ch) ? ch - 'A' : ch - 'a') + 10);
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch == '\\') {
|
if (ch == '\\') {
|
||||||
return so_far;
|
return so_far;
|
||||||
} else {
|
} else {
|
||||||
@ -890,7 +890,7 @@ static int num_send_error_message(char s[]) {
|
|||||||
|
|
||||||
/* reads a number, either integer or float */
|
/* reads a number, either integer or float */
|
||||||
|
|
||||||
static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
static Term get_num(int *chp, int *chbuffp, StreamDesc *st, int sign) {
|
||||||
int ch = *chp;
|
int ch = *chp;
|
||||||
Int val = 0L, base = ch - '0';
|
Int val = 0L, base = ch - '0';
|
||||||
int might_be_float = TRUE, has_overflow = FALSE;
|
int might_be_float = TRUE, has_overflow = FALSE;
|
||||||
@ -899,7 +899,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
int max_size = 254, left = 254;
|
int max_size = 254, left = 254;
|
||||||
|
|
||||||
*sp++ = ch;
|
*sp++ = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
/*
|
/*
|
||||||
* because of things like 00'2, 03'2 and even better 12'2, I need to
|
* because of things like 00'2, 03'2 and even better 12'2, I need to
|
||||||
* do this (have mercy)
|
* do this (have mercy)
|
||||||
@ -909,7 +909,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
if (--left == 0)
|
if (--left == 0)
|
||||||
number_overflow();
|
number_overflow();
|
||||||
base = 10 * base + ch - '0';
|
base = 10 * base + ch - '0';
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
if (ch == '\'') {
|
if (ch == '\'') {
|
||||||
if (base > 36) {
|
if (base > 36) {
|
||||||
@ -919,7 +919,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
if (--left == 0)
|
if (--left == 0)
|
||||||
number_overflow();
|
number_overflow();
|
||||||
*sp++ = ch;
|
*sp++ = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
if (base == 0) {
|
if (base == 0) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
wchar_t ascii = ch;
|
wchar_t ascii = ch;
|
||||||
@ -927,11 +927,11 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
|
|
||||||
if (ch == '\\' &&
|
if (ch == '\\' &&
|
||||||
Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE) {
|
Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE) {
|
||||||
ascii = read_quoted_char(&scan_extra, inp_stream);
|
ascii = read_quoted_char(&scan_extra, st);
|
||||||
}
|
}
|
||||||
/* a quick way to represent ASCII */
|
/* a quick way to represent ASCII */
|
||||||
if (scan_extra)
|
if (scan_extra)
|
||||||
*chp = getchr(inp_stream);
|
*chp = getchr(st);
|
||||||
if (sign == -1) {
|
if (sign == -1) {
|
||||||
return MkIntegerTerm(-ascii);
|
return MkIntegerTerm(-ascii);
|
||||||
}
|
}
|
||||||
@ -951,7 +951,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
val = oval * base + chval;
|
val = oval * base + chval;
|
||||||
if (oval != (val - chval) / base) /* overflow */
|
if (oval != (val - chval) / base) /* overflow */
|
||||||
has_overflow = (has_overflow || TRUE);
|
has_overflow = (has_overflow || TRUE);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (ch == 'x' && base == 0) {
|
} else if (ch == 'x' && base == 0) {
|
||||||
@ -959,7 +959,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
if (--left == 0)
|
if (--left == 0)
|
||||||
number_overflow();
|
number_overflow();
|
||||||
*sp++ = ch;
|
*sp++ = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
while (my_isxdigit(ch, 'F', 'f')) {
|
while (my_isxdigit(ch, 'F', 'f')) {
|
||||||
Int oval = val;
|
Int oval = val;
|
||||||
int chval =
|
int chval =
|
||||||
@ -971,17 +971,17 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
val = val * 16 + chval;
|
val = val * 16 + chval;
|
||||||
if (oval != (val - chval) / 16) /* overflow */
|
if (oval != (val - chval) / 16) /* overflow */
|
||||||
has_overflow = TRUE;
|
has_overflow = TRUE;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
*chp = ch;
|
*chp = ch;
|
||||||
} else if (ch == 'o' && base == 0) {
|
} else if (ch == 'o' && base == 0) {
|
||||||
might_be_float = FALSE;
|
might_be_float = FALSE;
|
||||||
base = 8;
|
base = 8;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
} else if (ch == 'b' && base == 0) {
|
} else if (ch == 'b' && base == 0) {
|
||||||
might_be_float = FALSE;
|
might_be_float = FALSE;
|
||||||
base = 2;
|
base = 2;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
} else {
|
} else {
|
||||||
val = base;
|
val = base;
|
||||||
base = 10;
|
base = 10;
|
||||||
@ -1002,7 +1002,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
val = val * base + ch - '0';
|
val = val * base + ch - '0';
|
||||||
if (val / base != oval || val - oval * base != ch - '0') /* overflow */
|
if (val / base != oval || val - oval * base != ch - '0') /* overflow */
|
||||||
has_overflow = TRUE;
|
has_overflow = TRUE;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
if (might_be_float && (ch == '.' || ch == 'e' || ch == 'E')) {
|
if (might_be_float && (ch == '.' || ch == 'e' || ch == 'E')) {
|
||||||
int has_dot = (ch == '.');
|
int has_dot = (ch == '.');
|
||||||
@ -1010,7 +1010,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
unsigned char *dp;
|
unsigned char *dp;
|
||||||
int dc;
|
int dc;
|
||||||
|
|
||||||
if (chtype(ch = getchr(inp_stream)) != NU) {
|
if (chtype(ch = getchr(st)) != NU) {
|
||||||
if (ch == 'e' || ch == 'E') {
|
if (ch == 'e' || ch == 'E') {
|
||||||
if (trueGlobalPrologFlag(ISO_FLAG))
|
if (trueGlobalPrologFlag(ISO_FLAG))
|
||||||
return num_send_error_message(
|
return num_send_error_message(
|
||||||
@ -1045,21 +1045,21 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
if (--left == 0)
|
if (--left == 0)
|
||||||
number_overflow();
|
number_overflow();
|
||||||
*sp++ = ch;
|
*sp++ = ch;
|
||||||
} while (chtype(ch = getchr(inp_stream)) == NU);
|
} while (chtype(ch = getchr(st)) == NU);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ch == 'e' || ch == 'E') {
|
if (ch == 'e' || ch == 'E') {
|
||||||
if (--left == 0)
|
if (--left == 0)
|
||||||
number_overflow();
|
number_overflow();
|
||||||
*sp++ = ch;
|
*sp++ = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
if (ch == '-') {
|
if (ch == '-') {
|
||||||
if (--left == 0)
|
if (--left == 0)
|
||||||
number_overflow();
|
number_overflow();
|
||||||
*sp++ = '-';
|
*sp++ = '-';
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
} else if (ch == '+') {
|
} else if (ch == '+') {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
if (chtype(ch) != NU) {
|
if (chtype(ch) != NU) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -1071,7 +1071,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
|
|||||||
if (--left == 0)
|
if (--left == 0)
|
||||||
number_overflow();
|
number_overflow();
|
||||||
*sp++ = ch;
|
*sp++ = ch;
|
||||||
} while (chtype(ch = getchr(inp_stream)) == NU);
|
} while (chtype(ch = getchr(st)) == NU);
|
||||||
}
|
}
|
||||||
*sp = '\0';
|
*sp = '\0';
|
||||||
*chp = ch;
|
*chp = ch;
|
||||||
@ -1257,7 +1257,7 @@ const char *Yap_tokText(void *tokptre) {
|
|||||||
return ".";
|
return ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
static void open_comment(int ch, StreamDesc *inp_stream USES_REGS) {
|
static void open_comment(int ch, StreamDesc *st USES_REGS) {
|
||||||
CELL *h0 = HR;
|
CELL *h0 = HR;
|
||||||
HR += 5;
|
HR += 5;
|
||||||
h0[0] = AbsAppl(h0 + 2);
|
h0[0] = AbsAppl(h0 + 2);
|
||||||
@ -1272,7 +1272,7 @@ static void open_comment(int ch, StreamDesc *inp_stream USES_REGS) {
|
|||||||
LOCAL_CommentsTail = h0 + 1;
|
LOCAL_CommentsTail = h0 + 1;
|
||||||
h0 += 2;
|
h0 += 2;
|
||||||
h0[0] = (CELL)FunctorMinus;
|
h0[0] = (CELL)FunctorMinus;
|
||||||
h0[1] = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
|
h0[1] = Yap_StreamPosition(st - GLOBAL_Stream);
|
||||||
h0[2] = TermNil;
|
h0[2] = TermNil;
|
||||||
LOCAL_CommentsNextChar = h0 + 2;
|
LOCAL_CommentsNextChar = h0 + 2;
|
||||||
LOCAL_CommentsBuff = (wchar_t *)malloc(1024 * sizeof(wchar_t));
|
LOCAL_CommentsBuff = (wchar_t *)malloc(1024 * sizeof(wchar_t));
|
||||||
@ -1301,14 +1301,14 @@ static void close_comment(USES_REGS1) {
|
|||||||
|
|
||||||
// mark that we reached EOF,
|
// mark that we reached EOF,
|
||||||
// next token will be end_of_file)
|
// next token will be end_of_file)
|
||||||
static void mark_eof(struct stream_desc *inp_stream) {
|
static void mark_eof(struct stream_desc *st) {
|
||||||
inp_stream->status |= Push_Eof_Stream_f;
|
st->status |= Push_Eof_Stream_f;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define add_ch_to_buff(ch) \
|
#define add_ch_to_buff(ch) \
|
||||||
{ charp += put_utf8(charp, ch); }
|
{ charp += put_utf8(charp, ch); }
|
||||||
|
|
||||||
TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
TokEntry *Yap_tokenizer(struct stream_desc *st, bool store_comments,
|
||||||
Term *tposp) {
|
Term *tposp) {
|
||||||
|
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -1324,14 +1324,15 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
LOCAL_AnonVarTable = NULL;
|
LOCAL_AnonVarTable = NULL;
|
||||||
l = NULL;
|
l = NULL;
|
||||||
p = NULL; /* Just to make lint happy */
|
p = NULL; /* Just to make lint happy */
|
||||||
ch = getchr(inp_stream);
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "i %d", st-GLOBAL_Stream);
|
||||||
|
ch = getchr(st);
|
||||||
while (chtype(ch) == BS) {
|
while (chtype(ch) == BS) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
*tposp = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
|
*tposp = Yap_StreamPosition(st - GLOBAL_Stream);
|
||||||
Yap_setCurrentSourceLocation(inp_stream);
|
Yap_setCurrentSourceLocation(st);
|
||||||
LOCAL_StartLineCount = inp_stream->linecount;
|
LOCAL_StartLineCount = st->linecount;
|
||||||
LOCAL_StartLinePos = inp_stream->linepos;
|
LOCAL_StartLinePos = st->linepos;
|
||||||
do {
|
do {
|
||||||
int quote, isvar;
|
int quote, isvar;
|
||||||
unsigned char *charp, *mp;
|
unsigned char *charp, *mp;
|
||||||
@ -1350,22 +1351,22 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
p = t;
|
p = t;
|
||||||
restart:
|
restart:
|
||||||
while (chtype(ch) == BS) {
|
while (chtype(ch) == BS) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
t->TokPos = GetCurInpPos(inp_stream);
|
t->TokPos = GetCurInpPos(st);
|
||||||
|
|
||||||
switch (chtype(ch)) {
|
switch (chtype(ch)) {
|
||||||
|
|
||||||
case CC:
|
case CC:
|
||||||
if (store_comments) {
|
if (store_comments) {
|
||||||
open_comment(ch, inp_stream PASS_REGS);
|
open_comment(ch, st PASS_REGS);
|
||||||
continue_comment:
|
continue_comment:
|
||||||
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF) {
|
while ((ch = getchr(st)) != 10 && chtype(ch) != EF) {
|
||||||
extend_comment(ch PASS_REGS);
|
extend_comment(ch PASS_REGS);
|
||||||
}
|
}
|
||||||
extend_comment(ch PASS_REGS);
|
extend_comment(ch PASS_REGS);
|
||||||
if (chtype(ch) != EF) {
|
if (chtype(ch) != EF) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
if (chtype(ch) == CC) {
|
if (chtype(ch) == CC) {
|
||||||
extend_comment(ch PASS_REGS);
|
extend_comment(ch PASS_REGS);
|
||||||
goto continue_comment;
|
goto continue_comment;
|
||||||
@ -1373,7 +1374,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
}
|
}
|
||||||
close_comment(PASS_REGS1);
|
close_comment(PASS_REGS1);
|
||||||
} else {
|
} else {
|
||||||
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF)
|
while ((ch = getchr(st)) != 10 && chtype(ch) != EF)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
if (chtype(ch) != EF) {
|
if (chtype(ch) != EF) {
|
||||||
@ -1381,15 +1382,15 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
if (t == l) {
|
if (t == l) {
|
||||||
/* we found a comment before reading characters */
|
/* we found a comment before reading characters */
|
||||||
while (chtype(ch) == BS) {
|
while (chtype(ch) == BS) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
*tposp = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
|
*tposp = Yap_StreamPosition(st - GLOBAL_Stream);
|
||||||
Yap_setCurrentSourceLocation(inp_stream);
|
Yap_setCurrentSourceLocation(st);
|
||||||
}
|
}
|
||||||
goto restart;
|
goto restart;
|
||||||
} else {
|
} else {
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
mark_eof(inp_stream);
|
mark_eof(st);
|
||||||
t->TokInfo = TermEof;
|
t->TokInfo = TermEof;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -1398,14 +1399,14 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
case UL:
|
case UL:
|
||||||
case LC: {
|
case LC: {
|
||||||
int32_t och = ch;
|
int32_t och = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
size_t sz = 512;
|
size_t sz = 512;
|
||||||
TokImage = Malloc(sz PASS_REGS);
|
TokImage = Malloc(sz PASS_REGS);
|
||||||
scan_name:
|
scan_name:
|
||||||
charp = (unsigned char *)TokImage;
|
charp = (unsigned char *)TokImage;
|
||||||
isvar = (chtype(och) != LC);
|
isvar = (chtype(och) != LC);
|
||||||
add_ch_to_buff(och);
|
add_ch_to_buff(och);
|
||||||
for (; chtype(ch) <= NU; ch = getchr(inp_stream)) {
|
for (; chtype(ch) <= NU; ch = getchr(st)) {
|
||||||
if (charp == TokImage + (sz - 1)) {
|
if (charp == TokImage + (sz - 1)) {
|
||||||
unsigned char *p0 = TokImage;
|
unsigned char *p0 = TokImage;
|
||||||
sz = Yap_Min(sz * 2, sz + MBYTE);
|
sz = Yap_Min(sz * 2, sz + MBYTE);
|
||||||
@ -1423,7 +1424,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
}
|
}
|
||||||
add_ch_to_buff(ch);
|
add_ch_to_buff(ch);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
add_ch_to_buff('\0');
|
add_ch_to_buff('\0');
|
||||||
if (!isvar) {
|
if (!isvar) {
|
||||||
@ -1459,7 +1460,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
cha = ch;
|
cha = ch;
|
||||||
cherr = 0;
|
cherr = 0;
|
||||||
CHECK_SPACE();
|
CHECK_SPACE();
|
||||||
if ((t->TokInfo = get_num(&cha, &cherr, inp_stream, sign)) == 0L) {
|
if ((t->TokInfo = get_num(&cha, &cherr, st, sign)) == 0L) {
|
||||||
if (p) {
|
if (p) {
|
||||||
p->Tok = eot_tok;
|
p->Tok = eot_tok;
|
||||||
t->TokInfo = TermError;
|
t->TokInfo = TermError;
|
||||||
@ -1471,7 +1472,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
if (cherr) {
|
if (cherr) {
|
||||||
TokEntry *e;
|
TokEntry *e;
|
||||||
t->Tok = Number_tok;
|
t->Tok = Number_tok;
|
||||||
t->TokPos = GetCurInpPos(inp_stream);
|
t->TokPos = GetCurInpPos(st);
|
||||||
e = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
e = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
||||||
if (e == NULL) {
|
if (e == NULL) {
|
||||||
return TrailSpaceError(p, l);
|
return TrailSpaceError(p, l);
|
||||||
@ -1497,7 +1498,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
|
|
||||||
t->Tok = Ord(Var_tok);
|
t->Tok = Ord(Var_tok);
|
||||||
t->TokInfo = (Term)Yap_LookupVar("E");
|
t->TokInfo = (Term)Yap_LookupVar("E");
|
||||||
t->TokPos = GetCurInpPos(inp_stream);
|
t->TokPos = GetCurInpPos(st);
|
||||||
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
||||||
if (e2 == NULL) {
|
if (e2 == NULL) {
|
||||||
return TrailSpaceError(p, l);
|
return TrailSpaceError(p, l);
|
||||||
@ -1530,7 +1531,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
if (ch == '(')
|
if (ch == '(')
|
||||||
solo_flag = FALSE;
|
solo_flag = FALSE;
|
||||||
t->TokInfo = MkAtomTerm(AtomE);
|
t->TokInfo = MkAtomTerm(AtomE);
|
||||||
t->TokPos = GetCurInpPos(inp_stream);
|
t->TokPos = GetCurInpPos(st);
|
||||||
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
|
||||||
if (e2 == NULL) {
|
if (e2 == NULL) {
|
||||||
return TrailSpaceError(p, l);
|
return TrailSpaceError(p, l);
|
||||||
@ -1557,7 +1558,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
charp = TokImage;
|
charp = TokImage;
|
||||||
quote = ch;
|
quote = ch;
|
||||||
len = 0;
|
len = 0;
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
size_t sz = 1024;
|
size_t sz = 1024;
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
@ -1577,23 +1578,23 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (ch == quote) {
|
if (ch == quote) {
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch != quote)
|
if (ch != quote)
|
||||||
break;
|
break;
|
||||||
add_ch_to_buff(ch);
|
add_ch_to_buff(ch);
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
} else if (ch == '\\' &&
|
} else if (ch == '\\' &&
|
||||||
Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE) {
|
Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE) {
|
||||||
int scan_next = TRUE;
|
int scan_next = TRUE;
|
||||||
if ((ch = read_quoted_char(&scan_next, inp_stream))) {
|
if ((ch = read_quoted_char(&scan_next, st))) {
|
||||||
add_ch_to_buff(ch);
|
add_ch_to_buff(ch);
|
||||||
}
|
}
|
||||||
if (scan_next) {
|
if (scan_next) {
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
add_ch_to_buff(ch);
|
add_ch_to_buff(ch);
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
}
|
}
|
||||||
++len;
|
++len;
|
||||||
}
|
}
|
||||||
@ -1628,9 +1629,9 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
if (ch == '\0') {
|
if (ch == '\0') {
|
||||||
int pch;
|
int pch;
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
pch = Yap_peek(inp_stream - GLOBAL_Stream);
|
pch = Yap_peek(st - GLOBAL_Stream);
|
||||||
if (chtype(pch) == EF) {
|
if (chtype(pch) == EF) {
|
||||||
mark_eof(inp_stream);
|
mark_eof(st);
|
||||||
t->TokInfo = TermEof;
|
t->TokInfo = TermEof;
|
||||||
} else {
|
} else {
|
||||||
t->TokInfo = TermNewLine;
|
t->TokInfo = TermNewLine;
|
||||||
@ -1638,11 +1639,11 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
t->TokInfo = TermEof;
|
t->TokInfo = TermEof;
|
||||||
return l;
|
return l;
|
||||||
} else
|
} else
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
break;
|
break;
|
||||||
case SY: {
|
case SY: {
|
||||||
int pch;
|
int pch;
|
||||||
if (ch == '.' && (pch = Yap_peek(inp_stream - GLOBAL_Stream)) &&
|
if (ch == '.' && (pch = Yap_peek(st - GLOBAL_Stream)) &&
|
||||||
(chtype(pch) == BS || chtype(pch) == EF || pch == '%')) {
|
(chtype(pch) == BS || chtype(pch) == EF || pch == '%')) {
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
// consume...
|
// consume...
|
||||||
@ -1655,7 +1656,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
if (ch == '`')
|
if (ch == '`')
|
||||||
goto quoted_string;
|
goto quoted_string;
|
||||||
och = ch;
|
och = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
if (och == '.') {
|
if (och == '.') {
|
||||||
if (chtype(ch) == BS || chtype(ch) == EF || ch == '%') {
|
if (chtype(ch) == BS || chtype(ch) == EF || ch == '%') {
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
@ -1664,7 +1665,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
if (chtype(ch) == EF) {
|
if (chtype(ch) == EF) {
|
||||||
mark_eof(inp_stream);
|
mark_eof(st);
|
||||||
t->TokInfo = TermEof;
|
t->TokInfo = TermEof;
|
||||||
} else {
|
} else {
|
||||||
t->TokInfo = TermNewLine;
|
t->TokInfo = TermNewLine;
|
||||||
@ -1675,12 +1676,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
if (och == '/' && ch == '*') {
|
if (och == '/' && ch == '*') {
|
||||||
if (store_comments) {
|
if (store_comments) {
|
||||||
CHECK_SPACE();
|
CHECK_SPACE();
|
||||||
open_comment('/', inp_stream PASS_REGS);
|
open_comment('/', st PASS_REGS);
|
||||||
while ((och != '*' || ch != '/') && chtype(ch) != EF) {
|
while ((och != '*' || ch != '/') && chtype(ch) != EF) {
|
||||||
och = ch;
|
och = ch;
|
||||||
CHECK_SPACE();
|
CHECK_SPACE();
|
||||||
extend_comment(ch PASS_REGS);
|
extend_comment(ch PASS_REGS);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
if (chtype(ch) != EF) {
|
if (chtype(ch) != EF) {
|
||||||
CHECK_SPACE();
|
CHECK_SPACE();
|
||||||
@ -1690,7 +1691,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
} else {
|
} else {
|
||||||
while ((och != '*' || ch != '/') && chtype(ch) != EF) {
|
while ((och != '*' || ch != '/') && chtype(ch) != EF) {
|
||||||
och = ch;
|
och = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (chtype(ch) == EF) {
|
if (chtype(ch) == EF) {
|
||||||
@ -1699,15 +1700,15 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
/* leave comments */
|
/* leave comments */
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
if (t == l) {
|
if (t == l) {
|
||||||
/* we found a comment before reading characters */
|
/* we found a comment before reading characters */
|
||||||
while (chtype(ch) == BS) {
|
while (chtype(ch) == BS) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
CHECK_SPACE();
|
CHECK_SPACE();
|
||||||
*tposp = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
|
*tposp = Yap_StreamPosition(st - GLOBAL_Stream);
|
||||||
Yap_setCurrentSourceLocation(inp_stream);
|
Yap_setCurrentSourceLocation(st);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
goto restart;
|
goto restart;
|
||||||
@ -1721,7 +1722,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
return l;
|
return l;
|
||||||
}
|
}
|
||||||
if (chtype(ch) == EF) {
|
if (chtype(ch) == EF) {
|
||||||
mark_eof(inp_stream);
|
mark_eof(st);
|
||||||
t->TokInfo = TermEof;
|
t->TokInfo = TermEof;
|
||||||
} else {
|
} else {
|
||||||
t->TokInfo = TermNl;
|
t->TokInfo = TermNl;
|
||||||
@ -1733,7 +1734,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
TokImage = Malloc(sz);
|
TokImage = Malloc(sz);
|
||||||
charp = TokImage;
|
charp = TokImage;
|
||||||
add_ch_to_buff(och);
|
add_ch_to_buff(och);
|
||||||
for (; chtype(ch) == SY; ch = getchr(inp_stream)) {
|
for (; chtype(ch) == SY; ch = getchr(st)) {
|
||||||
if (charp >= TokImage + (sz - 10)) {
|
if (charp >= TokImage + (sz - 10)) {
|
||||||
sz = Yap_Min(sz * 2, sz + MBYTE);
|
sz = Yap_Min(sz * 2, sz + MBYTE);
|
||||||
TokImage = Realloc(TokImage, sz);
|
TokImage = Realloc(TokImage, sz);
|
||||||
@ -1764,7 +1765,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
unsigned char chs[2];
|
unsigned char chs[2];
|
||||||
chs[0] = ch;
|
chs[0] = ch;
|
||||||
chs[1] = '\0';
|
chs[1] = '\0';
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
t->TokInfo = MkAtomTerm(Yap_ULookupAtom(chs));
|
t->TokInfo = MkAtomTerm(Yap_ULookupAtom(chs));
|
||||||
t->Tok = Ord(kind = Name_tok);
|
t->Tok = Ord(kind = Name_tok);
|
||||||
if (ch == '(')
|
if (ch == '(')
|
||||||
@ -1773,7 +1774,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
|
|
||||||
case BK:
|
case BK:
|
||||||
och = ch;
|
och = ch;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
{
|
{
|
||||||
unsigned char chs[10];
|
unsigned char chs[10];
|
||||||
TokImage = charp = chs;
|
TokImage = charp = chs;
|
||||||
@ -1783,12 +1784,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
}
|
}
|
||||||
if (och == '(') {
|
if (och == '(') {
|
||||||
while (chtype(ch) == BS) {
|
while (chtype(ch) == BS) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
}
|
}
|
||||||
if (ch == ')') {
|
if (ch == ')') {
|
||||||
t->TokInfo = TermEmptyBrackets;
|
t->TokInfo = TermEmptyBrackets;
|
||||||
t->Tok = Ord(kind = Name_tok);
|
t->Tok = Ord(kind = Name_tok);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
solo_flag = FALSE;
|
solo_flag = FALSE;
|
||||||
break;
|
break;
|
||||||
} else if (!solo_flag) {
|
} else if (!solo_flag) {
|
||||||
@ -1797,12 +1798,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
}
|
}
|
||||||
} else if (och == '[') {
|
} else if (och == '[') {
|
||||||
while (chtype(ch) == BS) {
|
while (chtype(ch) == BS) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
};
|
};
|
||||||
if (ch == ']') {
|
if (ch == ']') {
|
||||||
t->TokInfo = TermNil;
|
t->TokInfo = TermNil;
|
||||||
t->Tok = Ord(kind = Name_tok);
|
t->Tok = Ord(kind = Name_tok);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
solo_flag = FALSE;
|
solo_flag = FALSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1827,26 +1828,26 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
cur_qq = qq;
|
cur_qq = qq;
|
||||||
}
|
}
|
||||||
t->TokInfo = (CELL)qq;
|
t->TokInfo = (CELL)qq;
|
||||||
if (inp_stream->status & Seekable_Stream_f) {
|
if (st->status & Seekable_Stream_f) {
|
||||||
qq->start.byteno = fseek(inp_stream->file, 0, 0);
|
qq->start.byteno = fseek(st->file, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
qq->start.byteno = inp_stream->charcount - 1;
|
qq->start.byteno = st->charcount - 1;
|
||||||
}
|
}
|
||||||
qq->start.lineno = inp_stream->linecount;
|
qq->start.lineno = st->linecount;
|
||||||
qq->start.linepos = inp_stream->linepos - 1;
|
qq->start.linepos = st->linepos - 1;
|
||||||
qq->start.charno = inp_stream->charcount - 1;
|
qq->start.charno = st->charcount - 1;
|
||||||
t->Tok = Ord(kind = QuasiQuotes_tok);
|
t->Tok = Ord(kind = QuasiQuotes_tok);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
solo_flag = FALSE;
|
solo_flag = FALSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
while (chtype(ch) == BS) {
|
while (chtype(ch) == BS) {
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
};
|
};
|
||||||
if (ch == '}') {
|
if (ch == '}') {
|
||||||
t->TokInfo = TermBraces;
|
t->TokInfo = TermBraces;
|
||||||
t->Tok = Ord(kind = Name_tok);
|
t->Tok = Ord(kind = Name_tok);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
solo_flag = FALSE;
|
solo_flag = FALSE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -1863,16 +1864,16 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
}
|
}
|
||||||
cur_qq = NULL;
|
cur_qq = NULL;
|
||||||
t->TokInfo = (CELL)qq;
|
t->TokInfo = (CELL)qq;
|
||||||
if (inp_stream->status & Seekable_Stream_f) {
|
if (st->status & Seekable_Stream_f) {
|
||||||
qq->mid.byteno = fseek(inp_stream->file, 0, 0);
|
qq->mid.byteno = fseek(st->file, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
qq->mid.byteno = inp_stream->charcount - 1;
|
qq->mid.byteno = st->charcount - 1;
|
||||||
}
|
}
|
||||||
qq->mid.lineno = inp_stream->linecount;
|
qq->mid.lineno = st->linecount;
|
||||||
qq->mid.linepos = inp_stream->linepos - 1;
|
qq->mid.linepos = st->linepos - 1;
|
||||||
qq->mid.charno = inp_stream->charcount - 1;
|
qq->mid.charno = st->charcount - 1;
|
||||||
t->Tok = Ord(kind = QuasiQuotes_tok);
|
t->Tok = Ord(kind = QuasiQuotes_tok);
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
sz = 1024;
|
sz = 1024;
|
||||||
TokImage = Malloc(sz);
|
TokImage = Malloc(sz);
|
||||||
if (!TokImage) {
|
if (!TokImage) {
|
||||||
@ -1885,11 +1886,11 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
charp = TokImage;
|
charp = TokImage;
|
||||||
quote = ch;
|
quote = ch;
|
||||||
len = 0;
|
len = 0;
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
|
|
||||||
while (TRUE) {
|
while (TRUE) {
|
||||||
if (ch == '|') {
|
if (ch == '|') {
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
if (ch != '}') {
|
if (ch != '}') {
|
||||||
} else {
|
} else {
|
||||||
charp += put_utf8((unsigned char *)charp, och);
|
charp += put_utf8((unsigned char *)charp, och);
|
||||||
@ -1899,13 +1900,13 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
}
|
}
|
||||||
} else if (chtype(ch) == EF) {
|
} else if (chtype(ch) == EF) {
|
||||||
Free(TokImage);
|
Free(TokImage);
|
||||||
mark_eof(inp_stream);
|
mark_eof(st);
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
t->TokInfo = TermOutOfHeapError;
|
t->TokInfo = TermOutOfHeapError;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
charp += put_utf8(charp, ch);
|
charp += put_utf8(charp, ch);
|
||||||
ch = getchrq(inp_stream);
|
ch = getchrq(st);
|
||||||
}
|
}
|
||||||
if (charp > (unsigned char *)AuxSp - 1024) {
|
if (charp > (unsigned char *)AuxSp - 1024) {
|
||||||
/* Not enough space to read in the string. */
|
/* Not enough space to read in the string. */
|
||||||
@ -1925,26 +1926,26 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
strncpy((char *)mp, (const char *)TokImage, len + 1);
|
strncpy((char *)mp, (const char *)TokImage, len + 1);
|
||||||
qq->text = (unsigned char *)mp;
|
qq->text = (unsigned char *)mp;
|
||||||
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
||||||
if (inp_stream->status & Seekable_Stream_f) {
|
if (st->status & Seekable_Stream_f) {
|
||||||
qq->end.byteno = fseek(inp_stream->file, 0, 0);
|
qq->end.byteno = fseek(st->file, 0, 0);
|
||||||
} else {
|
} else {
|
||||||
qq->end.byteno = inp_stream->charcount - 1;
|
qq->end.byteno = st->charcount - 1;
|
||||||
}
|
}
|
||||||
qq->end.lineno = inp_stream->linecount;
|
qq->end.lineno = st->linecount;
|
||||||
qq->end.linepos = inp_stream->linepos - 1;
|
qq->end.linepos = st->linepos - 1;
|
||||||
qq->end.charno = inp_stream->charcount - 1;
|
qq->end.charno = st->charcount - 1;
|
||||||
if (!(t->TokInfo)) {
|
if (!(t->TokInfo)) {
|
||||||
return CodeSpaceError(t, p, l);
|
return CodeSpaceError(t, p, l);
|
||||||
}
|
}
|
||||||
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
|
||||||
solo_flag = FALSE;
|
solo_flag = FALSE;
|
||||||
ch = getchr(inp_stream);
|
ch = getchr(st);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
t->Tok = Ord(kind = Ponctuation_tok);
|
t->Tok = Ord(kind = Ponctuation_tok);
|
||||||
break;
|
break;
|
||||||
case EF:
|
case EF:
|
||||||
mark_eof(inp_stream);
|
mark_eof(st);
|
||||||
t->Tok = Ord(kind = eot_tok);
|
t->Tok = Ord(kind = eot_tok);
|
||||||
t->TokInfo = TermEof;
|
t->TokInfo = TermEof;
|
||||||
return l;
|
return l;
|
||||||
@ -1966,7 +1967,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
|
|||||||
p->TokNext = e;
|
p->TokNext = e;
|
||||||
e->Tok = Error_tok;
|
e->Tok = Error_tok;
|
||||||
e->TokInfo = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
|
e->TokInfo = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
|
||||||
e->TokPos = GetCurInpPos(inp_stream);
|
e->TokPos = GetCurInpPos(st);
|
||||||
e->TokNext = NULL;
|
e->TokNext = NULL;
|
||||||
LOCAL_ErrorMessage = NULL;
|
LOCAL_ErrorMessage = NULL;
|
||||||
p = e;
|
p = e;
|
||||||
|
@ -1091,15 +1091,15 @@ bool set_clause_info(yamop *codeptr, PredEntry *pp) {
|
|||||||
Term ts[2];
|
Term ts[2];
|
||||||
void *begin;
|
void *begin;
|
||||||
if (pp->ArityOfPE == 0) {
|
if (pp->ArityOfPE == 0) {
|
||||||
LOCAL_ActiveError->prologPredName = (Atom) pp->FunctorOfPred;
|
LOCAL_ActiveError->prologPredName = RepAtom((Atom) pp->FunctorOfPred)->StrOfAE;
|
||||||
LOCAL_ActiveError->prologPredArity = 0;
|
LOCAL_ActiveError->prologPredArity = 0;
|
||||||
} else {
|
} else {
|
||||||
LOCAL_ActiveError->prologPredName = NameOfFunctor(pp->FunctorOfPred);
|
LOCAL_ActiveError->prologPredName = RepAtom(NameOfFunctor(pp->FunctorOfPred))->StrOfAE;
|
||||||
LOCAL_ActiveError->prologPredArity = pp->ArityOfPE;
|
LOCAL_ActiveError->prologPredArity = pp->ArityOfPE;
|
||||||
}
|
}
|
||||||
LOCAL_ActiveError->prologPredModule =
|
LOCAL_ActiveError->prologPredModule =
|
||||||
(pp->ModuleOfPred ? pp->ModuleOfPred : TermProlog);
|
(pp->ModuleOfPred ? RepAtom(AtomOfTerm(pp->ModuleOfPred))->StrOfAE : "prolog");
|
||||||
LOCAL_ActiveError->prologPredFile = pp->src.OwnerFile;
|
LOCAL_ActiveError->prologPredFile = RepAtom(pp->src.OwnerFile)->StrOfAE;
|
||||||
if (codeptr->opc == UNDEF_OPCODE) {
|
if (codeptr->opc == UNDEF_OPCODE) {
|
||||||
LOCAL_ActiveError->prologPredFirstLine = 0;
|
LOCAL_ActiveError->prologPredFirstLine = 0;
|
||||||
LOCAL_ActiveError->prologPredLine = 0;
|
LOCAL_ActiveError->prologPredLine = 0;
|
||||||
|
@ -1349,13 +1349,13 @@ static Int p_statistics_lu_db_size(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Int p_executable(USES_REGS1) {
|
static Int p_executable(USES_REGS1) {
|
||||||
|
char tmp[YAP_FILENAME_MAX+1];
|
||||||
if (GLOBAL_argv && GLOBAL_argv[0])
|
if (GLOBAL_argv && GLOBAL_argv[0])
|
||||||
Yap_findFile(GLOBAL_argv[0], NULL, NULL, LOCAL_FileNameBuf, true, YAP_EXE,
|
Yap_AbsoluteFile(GLOBAL_argv[0], tmp, true);
|
||||||
true, true);
|
|
||||||
else
|
else
|
||||||
strncpy(LOCAL_FileNameBuf, Yap_FindExecutable(), YAP_FILENAME_MAX - 1);
|
strncpy(tmp, Yap_FindExecutable(), YAP_FILENAME_MAX);
|
||||||
|
|
||||||
return Yap_unify(MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)), ARG1);
|
return Yap_unify(MkAtomTerm(Yap_LookupAtom(tmp)), ARG1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int p_system_mode(USES_REGS1) {
|
static Int p_system_mode(USES_REGS1) {
|
||||||
|
44
C/text.c
44
C/text.c
@ -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
|
||||||
|
|
||||||
|
#if !defined(HAVE_STPCPY) && !defined(__APPLE__)
|
||||||
|
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
|
||||||
@ -77,7 +82,7 @@ int pop_text_stack__(int i) {
|
|||||||
return lvl;
|
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;
|
int lvl = LOCAL_TextBuffer->lvl;
|
||||||
while (lvl >= i) {
|
while (lvl >= i) {
|
||||||
struct mblock *p = LOCAL_TextBuffer->first[lvl];
|
struct mblock *p = LOCAL_TextBuffer->first[lvl];
|
||||||
@ -97,7 +102,7 @@ void *pop_output_text_stack__(int i, void *export) {
|
|||||||
lvl--;
|
lvl--;
|
||||||
}
|
}
|
||||||
LOCAL_TextBuffer->lvl = lvl;
|
LOCAL_TextBuffer->lvl = lvl;
|
||||||
return export;
|
return (void *)export;
|
||||||
}
|
}
|
||||||
|
|
||||||
// void pop_text_stack(int i) { LOCAL_TextBuffer->lvl = i; }
|
// void pop_text_stack(int i) { LOCAL_TextBuffer->lvl = i; }
|
||||||
@ -482,7 +487,7 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
|
|||||||
#endif
|
#endif
|
||||||
if (inp->type & YAP_STRING_TERM) {
|
if (inp->type & YAP_STRING_TERM) {
|
||||||
// Yap_DebugPlWriteln(inp->val.t);
|
// Yap_DebugPlWriteln(inp->val.t);
|
||||||
char *s = (char *)Yap_TermToString(inp->val.t, ENC_ISO_UTF8, 0);
|
char *s = (char *) Yap_TermToBuffer(inp->val.t, ENC_ISO_UTF8, 0);
|
||||||
return inp->val.uc = (unsigned char *)s;
|
return inp->val.uc = (unsigned char *)s;
|
||||||
}
|
}
|
||||||
if (inp->type & YAP_STRING_CHARS) {
|
if (inp->type & YAP_STRING_CHARS) {
|
||||||
@ -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
|
||||||
|
@ -501,7 +501,7 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
|
|||||||
#endif
|
#endif
|
||||||
if (inp->type & YAP_STRING_TERM) {
|
if (inp->type & YAP_STRING_TERM) {
|
||||||
// Yap_DebugPlWriteln(inp->val.t);
|
// Yap_DebugPlWriteln(inp->val.t);
|
||||||
char *s = (char *)Yap_TermToString(inp->val.t, lengp, ENC_ISO_UTF8, 0);
|
char *s = (char *) Yap_TermToBuffer(inp->val.t, lengp, ENC_ISO_UTF8, 0);
|
||||||
return inp->val.uc = (unsigned char *)s;
|
return inp->val.uc = (unsigned char *)s;
|
||||||
}
|
}
|
||||||
if (inp->type & YAP_STRING_CHARS) {
|
if (inp->type & YAP_STRING_CHARS) {
|
||||||
|
@ -87,7 +87,7 @@ static char *send_tracer_message(char *start, char *name, arity_t arity,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const char *sn = Yap_TermToString(args[i], LOCAL_encoding,
|
const char *sn = Yap_TermToBuffer(args[i], LOCAL_encoding,
|
||||||
Quote_illegal_f | Handle_vars_f);
|
Quote_illegal_f | Handle_vars_f);
|
||||||
size_t sz;
|
size_t sz;
|
||||||
if (sn == NULL) {
|
if (sn == NULL) {
|
||||||
|
@ -1255,7 +1255,7 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
|
|||||||
Yap_CloseSlots(sls);
|
Yap_CloseSlots(sls);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *Yap_TermToString(Term t, encoding_t enc, int flags) {
|
char *Yap_TermToBuffer(Term t, encoding_t enc, int flags) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int sno = Yap_open_buf_write_stream(enc, flags);
|
int sno = Yap_open_buf_write_stream(enc, flags);
|
||||||
const char *sf;
|
const char *sf;
|
||||||
|
713
C/yap-args.c
713
C/yap-args.c
@ -1,33 +1,41 @@
|
|||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* *
|
* *
|
||||||
* Yap Prolog *
|
* Yap Prolog *
|
||||||
* *
|
* *
|
||||||
* Yap Prolog Was Developed At Nccup - Universidade Do Porto *
|
* Yap Prolog Was Developed At Nccup - Universidade Do Porto *
|
||||||
* *
|
* *
|
||||||
* Copyright L.Damas, V.S.Costa And Universidade Do Porto 1985-1997 *
|
* Copyright L.Damas, V.S.Costa And Universidade Do Porto 1985-1997 *
|
||||||
* *
|
* *
|
||||||
**************************************************************************
|
**************************************************************************
|
||||||
* *
|
* *
|
||||||
* File: Yap.C *
|
* File: Yap.C * Last
|
||||||
* Last Rev: *
|
*Rev:
|
||||||
* Mods: *
|
* Mods:
|
||||||
* Comments: Yap's Main File: parse arguments *
|
** Comments: Yap's Main File: parse arguments *
|
||||||
* *
|
* *
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
/* static char SccsId[] = "X 4.3.3"; */
|
/* static char SccsId[] = "X 4.3.3"; */
|
||||||
|
|
||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
#include "YapHeap.h"
|
#include "YapHeap.h"
|
||||||
#include "YapInterface.h"
|
#include "YapInterface.h"
|
||||||
|
#include "YapStreams.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#if HAVE_UNISTD_H
|
#if HAVE_UNISTD_H
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_STDINT_H
|
#if HAVE_STDINT_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */
|
#ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */
|
||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
#undef HAVE_UNISTD_H
|
#undef HAVE_UNISTD_H
|
||||||
@ -35,28 +43,352 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#if HAVE_STRING_H
|
#if HAVE_STRING_H
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_ERRNO_H
|
#if HAVE_ERRNO_H
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_DIRECT_H
|
#if HAVE_DIRECT_H
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if HAVE_LIBGEN_H
|
||||||
#ifndef YAP_ROOTDIR
|
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
|
||||||
char
|
|
||||||
*YAP_BINDIR,
|
|
||||||
*YAP_ROOTDIR,
|
|
||||||
*YAP_SHAREDIR,
|
|
||||||
*YAP_LIBDIR,
|
|
||||||
*YAP_YAPLIB;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR,
|
||||||
|
*Yap_PLDIR, *Yap_BOOTPLDIR, *Yap_BOOTSTRAPPLDIR, *Yap_COMMONSDIR,
|
||||||
|
*Yap_STARTUP, *Yap_BOOTFILE;
|
||||||
|
|
||||||
|
static int yap_lineno = 0;
|
||||||
|
|
||||||
|
/* do initial boot by consulting the file boot.yap */
|
||||||
|
static void do_bootfile(const char *b_file USES_REGS) {
|
||||||
|
Term t;
|
||||||
|
int boot_stream, osno;
|
||||||
|
Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1);
|
||||||
|
Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1);
|
||||||
|
|
||||||
|
/* consult boot.pl */
|
||||||
|
char *full = malloc(YAP_FILENAME_MAX + 1);
|
||||||
|
full[0] = '\0';
|
||||||
|
/* the consult mode does not matter here, really */
|
||||||
|
boot_stream = YAP_InitConsult(YAP_BOOT_MODE, b_file, full, &osno);
|
||||||
|
if (boot_stream < 0) {
|
||||||
|
fprintf(stderr, "[ FATAL ERROR: could not open boot_stream %s ]\n", b_file);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
free(full);
|
||||||
|
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
|
||||||
|
MkAtomTerm(GLOBAL_Stream[boot_stream].name));
|
||||||
|
do {
|
||||||
|
CACHE_REGS
|
||||||
|
YAP_Reset(YAP_FULL_RESET);
|
||||||
|
Yap_StartSlots();
|
||||||
|
t = YAP_ReadClauseFromStream(boot_stream);
|
||||||
|
|
||||||
|
// Yap_DebugPlWriteln(t);
|
||||||
|
if (t == 0) {
|
||||||
|
fprintf(stderr,
|
||||||
|
"[ SYNTAX ERROR: while parsing boot_stream %s at line %d ]\n",
|
||||||
|
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)) {
|
||||||
|
fprintf(stderr, "[ SYSTEM ERROR: consult not allowed in boot file ]\n");
|
||||||
|
fprintf(stderr, "error found at line %d and pos %d", yap_lineno,
|
||||||
|
fseek(GLOBAL_Stream[boot_stream].file, 0L, SEEK_CUR));
|
||||||
|
} else if (IsApplTerm(t) && (FunctorOfTerm(t) == functor_query ||
|
||||||
|
FunctorOfTerm(t) == functor_command1)) {
|
||||||
|
YAP_RunGoalOnce(ArgOfTerm(1, t));
|
||||||
|
} else {
|
||||||
|
Term ts[2];
|
||||||
|
char *ErrorMessage;
|
||||||
|
Functor fun = Yap_MkFunctor(Yap_LookupAtom("$prepare_clause"), 2);
|
||||||
|
PredEntry *pe = RepPredProp(PredPropByFunc(fun, PROLOG_MODULE));
|
||||||
|
|
||||||
|
if (pe->OpcodeOfPred != UNDEF_OPCODE && pe->OpcodeOfPred != FAIL_OPCODE) {
|
||||||
|
ts[0] = t;
|
||||||
|
RESET_VARIABLE(ts + 1);
|
||||||
|
if (YAP_RunGoal(Yap_MkApplTerm(fun, 2, ts)))
|
||||||
|
t = ts[1];
|
||||||
|
}
|
||||||
|
ErrorMessage = YAP_CompileClause(t);
|
||||||
|
if (ErrorMessage) {
|
||||||
|
fprintf(stderr, "%s", ErrorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (t != TermEof);
|
||||||
|
BACKUP_MACHINE_REGS();
|
||||||
|
|
||||||
|
YAP_EndConsult(boot_stream, &osno);
|
||||||
|
#if DEBUG
|
||||||
|
if (Yap_output_msg)
|
||||||
|
fprintf(stderr, "Boot loaded\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @brief A simple language for detecting where YAP stuff cn be found
|
||||||
|
*
|
||||||
|
* @long The options are
|
||||||
|
* `[V]` use a configuration variable YAP_XXXDIR, prefixed by "DESTDIR"
|
||||||
|
* `(V)PATH` compute V and add /PATH,
|
||||||
|
* `$V` search the envurinment
|
||||||
|
* `?V` search the WINDOWS registry
|
||||||
|
* ~` search HOME
|
||||||
|
* `@` query user option.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
const char *rootdirs[] = {"[root]", "(execdir)..", "/usr/local", "~", NULL};
|
||||||
|
|
||||||
|
const char *bindirs[] = {"[bin]", "(root)bin", NULL};
|
||||||
|
|
||||||
|
const char *libdirs[] = {
|
||||||
|
#if __ANDROID__
|
||||||
|
"/assets/lib",
|
||||||
|
#endif
|
||||||
|
"[lib]", "(root)lib", NULL};
|
||||||
|
|
||||||
|
const char *sharedirs[] = {
|
||||||
|
#if __ANDROID__
|
||||||
|
"/assets/share",
|
||||||
|
#endif
|
||||||
|
"[share]", "(root)share", NULL};
|
||||||
|
|
||||||
|
const char *dlldirs[] = {"$YAPLIBDIR", "(lib)Yap", ".", NULL};
|
||||||
|
|
||||||
|
const char *ssdirs[] = {".", "$YAPLIBDIR", "(lib)Yap", NULL};
|
||||||
|
|
||||||
|
const char *pldirs[] = {"$YAPSHAREDIR", "?library", "(share)Yap", ".", NULL};
|
||||||
|
|
||||||
|
const char *bootpldirs[] = {"(pl)pl", ".", NULL};
|
||||||
|
|
||||||
|
const char *bootstrappldirs[] = {YAP_PL_SRCDIR, NULL};
|
||||||
|
|
||||||
|
const char *commonsdirs[] = {"(share)PrologCommons", ".", NULL};
|
||||||
|
|
||||||
|
const char *ssnames[] = {"@SavedState", YAP_STARTUP, "startup.yss", NULL};
|
||||||
|
|
||||||
|
const char *plnames[] = {"@YapPrologBootFile", YAP_BOOTFILE, "boot.yap", NULL};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search
|
||||||
|
*/
|
||||||
|
char *location(YAP_init_args *iap, const char *inp, char *out) {
|
||||||
|
if (inp == NULL || inp[0] == '\0') {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
out[0] = '\0';
|
||||||
|
if (inp[0] == '(') {
|
||||||
|
if (strstr(inp + 1, "root") == inp + 1 && Yap_ROOTDIR &&
|
||||||
|
Yap_ROOTDIR[0] != '\0') {
|
||||||
|
strcpy(out, Yap_ROOTDIR);
|
||||||
|
strcat(out, "/");
|
||||||
|
strcat(out, inp + strlen("(root)"));
|
||||||
|
} else if (strstr(inp + 1, "bin") == inp + 1 && Yap_BINDIR &&
|
||||||
|
Yap_BINDIR[0] != '\0') {
|
||||||
|
strcpy(out, Yap_BINDIR);
|
||||||
|
strcat(out, "/");
|
||||||
|
strcat(out, inp + strlen("(bin)"));
|
||||||
|
} else if (strstr(inp + 1, "lib") == inp + 1 && Yap_LIBDIR &&
|
||||||
|
Yap_LIBDIR[0] != '\0') {
|
||||||
|
strcpy(out, Yap_LIBDIR);
|
||||||
|
strcat(out, "/");
|
||||||
|
strcat(out, inp + strlen("(lib)"));
|
||||||
|
} else if (strstr(inp + 1, "share") == inp + 1 && Yap_SHAREDIR &&
|
||||||
|
Yap_SHAREDIR[0] != '\0') {
|
||||||
|
strcpy(out, Yap_SHAREDIR);
|
||||||
|
strcat(out, "/");
|
||||||
|
strcat(out, inp + strlen("(share)"));
|
||||||
|
} else if (strstr(inp + 1, "pl") == inp + 1 && Yap_PLDIR &&
|
||||||
|
Yap_PLDIR[0] != '\0') {
|
||||||
|
strcpy(out, Yap_PLDIR);
|
||||||
|
strcat(out, "/");
|
||||||
|
strcat(out, inp + strlen("(pl)"));
|
||||||
|
} else if (strstr(inp + 1, "execdir") == inp + 1) {
|
||||||
|
char *buf = Malloc(YAP_FILENAME_MAX+1);
|
||||||
|
const char *ex = Yap_AbsoluteFile(Yap_FindExecutable(), buf, false);
|
||||||
|
if (ex != NULL) {
|
||||||
|
strcpy(out, dirname((char *)ex));
|
||||||
|
strcat(out, "/");
|
||||||
|
strcat(out, inp + strlen("(execdir)"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (inp[0] == '@') {
|
||||||
|
|
||||||
|
if (strstr(inp + 1, "YapPrologBootFile") == inp + 1) {
|
||||||
|
const char *tmp;
|
||||||
|
tmp = iap->YapPrologBootFile;
|
||||||
|
if (tmp && tmp[0])
|
||||||
|
strcpy(out, tmp);
|
||||||
|
} else if (strstr(inp + 1, "SavedState") == inp + 1) {
|
||||||
|
const char *tmp = iap->SavedState;
|
||||||
|
if (tmp && tmp[0])
|
||||||
|
strcpy(out, tmp);
|
||||||
|
}
|
||||||
|
} else if (inp[0] == '$') {
|
||||||
|
char *e;
|
||||||
|
if ((e = getenv(inp + 1)) != NULL) {
|
||||||
|
strcpy(out, e);
|
||||||
|
}
|
||||||
|
} else if (inp[0] == '?') {
|
||||||
|
#if _WINDOWS_
|
||||||
|
char *e;
|
||||||
|
if ((e = Yap_RegistryGetString(inp + 1)) != NULL) {
|
||||||
|
strcpy(out, e);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
} else if (inp[0] == '~') {
|
||||||
|
char *e;
|
||||||
|
if ((e = getenv("HOME")) != NULL) {
|
||||||
|
if (inp[1] == '\0') {
|
||||||
|
strcpy(out, e);
|
||||||
|
} else if (inp[1] == '/') {
|
||||||
|
strcpy(out, e);
|
||||||
|
strcat(out, inp + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (inp[0] == '[') {
|
||||||
|
char *o = out;
|
||||||
|
const char *e;
|
||||||
|
if ((e = getenv("DESTDIR"))) {
|
||||||
|
strcpy(out, e);
|
||||||
|
o += strlen(e);
|
||||||
|
}
|
||||||
|
if (strstr(inp + 1, "root") == inp + 1) {
|
||||||
|
#ifdef YAP_ROOTDIR
|
||||||
|
strcpy(o, YAP_ROOTDIR);
|
||||||
|
#endif
|
||||||
|
} else if (strstr(inp + 1, "lib") == inp + 1) {
|
||||||
|
#ifdef YAP_LIBDIR
|
||||||
|
strcpy(o, YAP_LIBDIR);
|
||||||
|
#endif
|
||||||
|
} else if (strstr(inp + 1, "share") == inp + 1) {
|
||||||
|
#ifdef YAP_SHAREDIR
|
||||||
|
strcpy(o, YAP_SHAREDIR);
|
||||||
|
#endif
|
||||||
|
} else if (strstr(inp + 1, "dll") == inp + 1) {
|
||||||
|
#ifdef YAP_DLLDIR
|
||||||
|
strcpy(o, YAP_DLLDIR);
|
||||||
|
#endif
|
||||||
|
} else if (strstr(inp + 1, "pl") == inp + 1) {
|
||||||
|
#ifdef YAP_PLDIR
|
||||||
|
strcpy(o, YAP_PLDIR);
|
||||||
|
#endif
|
||||||
|
} else if (strstr(inp + 1, "commons") == inp + 1) {
|
||||||
|
#ifdef YAP_COMMONSDIR
|
||||||
|
strcpy(o, YAP_COMMONSDIR);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
strcpy(out, inp);
|
||||||
|
}
|
||||||
|
if (out[0]) {
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief find default paths for main YAP variables
|
||||||
|
*
|
||||||
|
* This function is called once at boot time to set the main paths; it
|
||||||
|
* searches a list of paths to instantiate a number of variables. Paths must
|
||||||
|
* be directories.
|
||||||
|
*
|
||||||
|
* It treats the following variables as :
|
||||||
|
* ROOTDIR, SHAREDIR, LIBDIR, EXECUTABLE
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
static const char *find_directory(YAP_init_args *iap, const char *paths[],
|
||||||
|
const char *names[]) {
|
||||||
|
int lvl = push_text_stack();
|
||||||
|
char *out = Malloc(YAP_FILENAME_MAX + 1);
|
||||||
|
const char *inp;
|
||||||
|
char *full;
|
||||||
|
if (names) {
|
||||||
|
full = Malloc(YAP_FILENAME_MAX + 1);
|
||||||
|
}
|
||||||
|
int i = 0;
|
||||||
|
while ((inp = paths[i++]) != NULL) {
|
||||||
|
out[0] = '\0';
|
||||||
|
char *o = location(iap, inp, out), *no;
|
||||||
|
if (o && o[0] && Yap_isDirectory(o)) {
|
||||||
|
if (names) {
|
||||||
|
size_t s = strlen(o);
|
||||||
|
o[s++] = '/';
|
||||||
|
const char *p;
|
||||||
|
int j = 0;
|
||||||
|
while ((p = names[j++])) {
|
||||||
|
char *io = o + s;
|
||||||
|
if ((no = location(iap, p, io)) && io[0] != '\0' && Yap_Exists(o))
|
||||||
|
return pop_output_text_stack(lvl, realpath(o, full));
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
return pop_output_text_stack(lvl, o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pop_text_stack(lvl);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void Yap_set_locations(YAP_init_args *iap) {
|
||||||
|
#if CONDA_BUILD
|
||||||
|
if (!getenv("DESTDIR")) {
|
||||||
|
char *buf = Malloc( YAP_FILENAME_MAX + 1);
|
||||||
|
const char *o = Yap_FindExecutable();
|
||||||
|
if (!o)
|
||||||
|
return;
|
||||||
|
o = Yap_AbsoluteFile(o, buf, false);
|
||||||
|
Int i = strlen(o);
|
||||||
|
while (--i) {
|
||||||
|
if (Yap_dir_separator((int)o[i]))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i == 0) { setenv("DESTDIR", "/", 1); }
|
||||||
|
else {
|
||||||
|
while (--i) {
|
||||||
|
if (Yap_dir_separator((int)o[i]))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i == 0) { setenv("DESTDIR", "/", 1); }
|
||||||
|
else { setenv("DESTDIR", o, 1); }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
setenv("DESTDIR", buf, 1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
Yap_ROOTDIR = find_directory(iap, rootdirs, NULL);
|
||||||
|
Yap_LIBDIR = find_directory(iap, libdirs, NULL);
|
||||||
|
Yap_BINDIR = find_directory(iap, bindirs, NULL);
|
||||||
|
Yap_SHAREDIR = find_directory(iap, sharedirs, NULL);
|
||||||
|
Yap_DLLDIR = find_directory(iap, dlldirs, NULL);
|
||||||
|
Yap_PLDIR = find_directory(iap, pldirs, NULL);
|
||||||
|
Yap_COMMONSDIR = find_directory(iap, commonsdirs, NULL);
|
||||||
|
Yap_STARTUP = find_directory(iap, ssdirs, ssnames);
|
||||||
|
if (iap->bootstrapping)
|
||||||
|
Yap_BOOTFILE = find_directory(iap, bootstrappldirs, plnames);
|
||||||
|
else
|
||||||
|
Yap_BOOTFILE = find_directory(iap, bootpldirs, plnames);
|
||||||
|
if (Yap_ROOTDIR)
|
||||||
|
setAtomicGlobalPrologFlag(HOME_FLAG, MkAtomTerm(Yap_LookupAtom(Yap_ROOTDIR)));
|
||||||
|
if (Yap_PLDIR)
|
||||||
|
setAtomicGlobalPrologFlag(PROLOG_LIBRARY_DIRECTORY_FLAG,
|
||||||
|
MkAtomTerm(Yap_LookupAtom(Yap_PLDIR)));
|
||||||
|
if (Yap_DLLDIR)
|
||||||
|
setAtomicGlobalPrologFlag(PROLOG_FOREIGN_DIRECTORY_FLAG,
|
||||||
|
MkAtomTerm(Yap_LookupAtom(Yap_DLLDIR)));
|
||||||
|
}
|
||||||
|
|
||||||
static void print_usage(void) {
|
static void print_usage(void) {
|
||||||
fprintf(stderr, "\n[ Valid switches for command line arguments: ]\n");
|
fprintf(stderr, "\n[ Valid switches for command line arguments: ]\n");
|
||||||
fprintf(stderr, " -? Shows this screen\n");
|
fprintf(stderr, " -? Shows this screen\n");
|
||||||
@ -97,7 +429,8 @@ static void print_usage(void) {
|
|||||||
defined(YAPOR_THREADS)
|
defined(YAPOR_THREADS)
|
||||||
fprintf(stderr, " -w Number of workers (default: %d)\n",
|
fprintf(stderr, " -w Number of workers (default: %d)\n",
|
||||||
DEFAULT_NUMBERWORKERS);
|
DEFAULT_NUMBERWORKERS);
|
||||||
fprintf(stderr, " -sl Loop scheduler executions before look for hiden "
|
fprintf(stderr,
|
||||||
|
" -sl Loop scheduler executions before look for hiden "
|
||||||
"shared work (default: %d)\n",
|
"shared work (default: %d)\n",
|
||||||
DEFAULT_SCHEDULERLOOP);
|
DEFAULT_SCHEDULERLOOP);
|
||||||
fprintf(stderr, " -d Value of delayed release of load (default: %d)\n",
|
fprintf(stderr, " -d Value of delayed release of load (default: %d)\n",
|
||||||
@ -147,54 +480,38 @@ static int dump_runtime_variables(void) {
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
YAP_file_type_t Yap_InitDefaults(YAP_init_args *iap, char saved_state[],
|
X_API YAP_file_type_t Yap_InitDefaults(void *x, char *saved_state, int argc,
|
||||||
int argc, char *argv[]) {
|
char *argv[]) {
|
||||||
|
|
||||||
|
if (!LOCAL_TextBuffer)
|
||||||
|
LOCAL_TextBuffer = Yap_InitTextAllocator();
|
||||||
|
YAP_init_args *iap = x;
|
||||||
memset(iap, 0, sizeof(YAP_init_args));
|
memset(iap, 0, sizeof(YAP_init_args));
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
iap->boot_file_type = YAP_BOOT_PL;
|
iap->boot_file_type = YAP_BOOT_PL;
|
||||||
iap->SavedState = NULL;
|
iap->SavedState = NULL;
|
||||||
|
iap->assetManager = NULL;
|
||||||
#else
|
#else
|
||||||
iap->boot_file_type = YAP_QLY;
|
iap->boot_file_type = YAP_QLY;
|
||||||
iap->SavedState = saved_state;
|
iap->SavedState = saved_state;
|
||||||
#endif
|
#endif
|
||||||
iap->Argc = argc;
|
iap->Argc = argc;
|
||||||
iap->Argv = argv;
|
iap->Argv = argv;
|
||||||
iap->YapLibDir = YAP_YAPLIB;
|
return YAP_QLY;
|
||||||
return iap->boot_file_type;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @short Paese command line
|
||||||
|
* @param argc number of arguments
|
||||||
|
* @param argv arguments
|
||||||
|
* @param iap options, see YAP_init_args
|
||||||
|
* @return boot from saved state or restore; error
|
||||||
|
*/
|
||||||
X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
|
X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
|
||||||
YAP_init_args *iap) {
|
YAP_init_args *iap) {
|
||||||
char *p;
|
char *p;
|
||||||
size_t *ssize;
|
size_t *ssize;
|
||||||
|
|
||||||
#ifndef YAP_ROOTDIR
|
|
||||||
{
|
|
||||||
char *b0=Yap_FindExecutable(), *b1, *b2;
|
|
||||||
char b[YAP_FILENAME_MAX + 1];
|
|
||||||
|
|
||||||
strncpy(b, b0, YAP_FILENAME_MAX);
|
|
||||||
b1 = dirname(b);
|
|
||||||
YAP_BINDIR = malloc(strlen(b1)+1);
|
|
||||||
strcpy(YAP_BINDIR, b1);
|
|
||||||
b2 = dirname(b1);
|
|
||||||
YAP_ROOTDIR = malloc(strlen(b2)+1);
|
|
||||||
strcpy(YAP_ROOTDIR, b2);
|
|
||||||
strncpy(b, YAP_ROOTDIR, YAP_FILENAME_MAX);
|
|
||||||
strncat( b, "/share", YAP_FILENAME_MAX);
|
|
||||||
YAP_SHAREDIR= malloc(strlen(b)+1);
|
|
||||||
strcpy(YAP_SHAREDIR, b);
|
|
||||||
strncpy(b, YAP_ROOTDIR, YAP_FILENAME_MAX);
|
|
||||||
strncat( b, "/lib", YAP_FILENAME_MAX);
|
|
||||||
YAP_LIBDIR= malloc(strlen(b)+1);
|
|
||||||
strcpy(YAP_LIBDIR, b);
|
|
||||||
strncpy(b, YAP_ROOTDIR, YAP_FILENAME_MAX);
|
|
||||||
strncat( b, "/lib/Yap", YAP_FILENAME_MAX);
|
|
||||||
YAP_YAPLIB= malloc(strlen(b)+1);
|
|
||||||
strcpy(YAP_YAPLIB, b);
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Yap_InitDefaults(iap, NULL, argc, argv);
|
Yap_InitDefaults(iap, NULL, argc, argv);
|
||||||
while (--argc > 0) {
|
while (--argc > 0) {
|
||||||
p = *++argv;
|
p = *++argv;
|
||||||
@ -219,8 +536,9 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
|
|||||||
iap->YapPrologBootFile = *++argv;
|
iap->YapPrologBootFile = *++argv;
|
||||||
argc--;
|
argc--;
|
||||||
} else {
|
} else {
|
||||||
iap->YapPrologBootFile = "boot.yap";
|
iap->YapPrologBootFile = NULL;
|
||||||
}
|
}
|
||||||
|
iap->bootstrapping = true;
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
print_usage();
|
print_usage();
|
||||||
@ -474,9 +792,8 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
|
|||||||
else {
|
else {
|
||||||
argc--;
|
argc--;
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
fprintf(
|
fprintf(stderr, " [ YAP unrecoverable error: missing goal for "
|
||||||
stderr,
|
"option 'z' ]\n");
|
||||||
" [ YAP unrecoverable error: missing goal for option 'z' ]\n");
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
argv++;
|
argv++;
|
||||||
@ -496,11 +813,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 (!Yap_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));
|
||||||
}
|
}
|
||||||
@ -537,9 +850,8 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
|
|||||||
else {
|
else {
|
||||||
argc--;
|
argc--;
|
||||||
if (argc == 0) {
|
if (argc == 0) {
|
||||||
fprintf(
|
fprintf(stderr, " [ YAP unrecoverable error: missing paths for "
|
||||||
stderr,
|
"option 'p' ]\n");
|
||||||
" [ YAP unrecoverable error: missing paths for option 'p' ]\n");
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
argv++;
|
argv++;
|
||||||
@ -583,3 +895,270 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
|
|||||||
}
|
}
|
||||||
return iap->boot_file_type;
|
return iap->boot_file_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
YAP_DelayInit()
|
||||||
|
|
||||||
|
ensures initialization is done after engine creation.
|
||||||
|
It receives a pointer to function and a string describing
|
||||||
|
the module.
|
||||||
|
*/
|
||||||
|
|
||||||
|
X_API bool YAP_initialized = false;
|
||||||
|
static int n_mdelays = 0;
|
||||||
|
static YAP_delaymodule_t *m_delays;
|
||||||
|
|
||||||
|
X_API bool YAP_DelayInit(YAP_ModInit_t f, const char s[]) {
|
||||||
|
if (m_delays) {
|
||||||
|
m_delays = realloc(m_delays, (n_mdelays + 1) * sizeof(YAP_delaymodule_t));
|
||||||
|
} else {
|
||||||
|
m_delays = malloc(sizeof(YAP_delaymodule_t));
|
||||||
|
}
|
||||||
|
m_delays[n_mdelays].f = f;
|
||||||
|
m_delays[n_mdelays].s = s;
|
||||||
|
n_mdelays++;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Yap_LateInit(const char s[]) {
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < n_mdelays; i++) {
|
||||||
|
if (!strcmp(m_delays[i].s, s)) {
|
||||||
|
m_delays[i].f();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void start_modules(void) {
|
||||||
|
Term cm = CurrentModule;
|
||||||
|
size_t i;
|
||||||
|
for (i = 0; i < n_mdelays; i++) {
|
||||||
|
CurrentModule = MkAtomTerm(YAP_LookupAtom(m_delays[i].s));
|
||||||
|
m_delays[i].f();
|
||||||
|
}
|
||||||
|
CurrentModule = cm;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// whether Yap is under control of some other system
|
||||||
|
bool Yap_embedded = true;
|
||||||
|
|
||||||
|
struct ssz_t {
|
||||||
|
size_t Heap, Stack, Trail;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void init_hw(YAP_init_args *yap_init, struct ssz_t *spt) {
|
||||||
|
Yap_page_size = Yap_InitPageSize(); /* init memory page size, required by
|
||||||
|
later functions */
|
||||||
|
#if defined(YAPOR_COPY) || defined(YAPOR_COW) || defined(YAPOR_SBA)
|
||||||
|
Yap_init_yapor_global_local_memory();
|
||||||
|
#endif /* YAPOR_COPY || YAPOR_COW || YAPOR_SBA */
|
||||||
|
if (!yap_init->Embedded) {
|
||||||
|
GLOBAL_PrologShouldHandleInterrupts =
|
||||||
|
!yap_init->PrologCannotHandleInterrupts;
|
||||||
|
Yap_InitSysbits(0); /* init signal handling and time, required by later
|
||||||
|
functions */
|
||||||
|
GLOBAL_argv = yap_init->Argv;
|
||||||
|
GLOBAL_argc = yap_init->Argc;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if __ANDROID__
|
||||||
|
|
||||||
|
// if (yap_init->assetManager)
|
||||||
|
Yap_InitAssetManager();
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
if (yap_init->TrailSize == 0) {
|
||||||
|
if (spt->Trail == 0)
|
||||||
|
spt->Trail = DefTrailSpace;
|
||||||
|
} else {
|
||||||
|
spt->Trail = yap_init->TrailSize;
|
||||||
|
}
|
||||||
|
// Atts = yap_init->AttsSize;
|
||||||
|
if (yap_init->StackSize == 0) {
|
||||||
|
spt->Stack = DefStackSpace;
|
||||||
|
} else {
|
||||||
|
spt->Stack = yap_init->StackSize;
|
||||||
|
}
|
||||||
|
#ifndef USE_SYSTEM_MALLOC
|
||||||
|
if (yap_init->HeapSize == 0) {
|
||||||
|
if (spt->Heap == 0)
|
||||||
|
spt->Heap = DefHeapSpace;
|
||||||
|
} else {
|
||||||
|
spt->Heap = yap_init->HeapSize;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void init_globals(YAP_init_args *yap_init) {
|
||||||
|
GLOBAL_FAST_BOOT_FLAG = yap_init->FastBoot;
|
||||||
|
#if defined(YAPOR) || defined(TABLING)
|
||||||
|
|
||||||
|
Yap_init_root_frames();
|
||||||
|
|
||||||
|
#endif /* YAPOR || TABLING */
|
||||||
|
#ifdef YAPOR
|
||||||
|
Yap_init_yapor_workers();
|
||||||
|
#if YAPOR_THREADS
|
||||||
|
if (Yap_thread_self() != 0) {
|
||||||
|
#else
|
||||||
|
if (worker_id != 0) {
|
||||||
|
#endif
|
||||||
|
#if defined(YAPOR_COPY) || defined(YAPOR_SBA)
|
||||||
|
/*
|
||||||
|
In the SBA we cannot just happily inherit registers
|
||||||
|
from the other workers
|
||||||
|
*/
|
||||||
|
Yap_InitYaamRegs(worker_id);
|
||||||
|
#endif /* YAPOR_COPY || YAPOR_SBA */
|
||||||
|
#ifndef YAPOR_THREADS
|
||||||
|
Yap_InitPreAllocCodeSpace(0);
|
||||||
|
#endif /* YAPOR_THREADS */
|
||||||
|
/* slaves, waiting for work */
|
||||||
|
CurrentModule = USER_MODULE;
|
||||||
|
P = GETWORK_FIRST_TIME;
|
||||||
|
Yap_exec_absmi(FALSE, YAP_EXEC_ABSMI);
|
||||||
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
|
||||||
|
"abstract machine unexpected exit (YAP_Init)");
|
||||||
|
}
|
||||||
|
#endif /* YAPOR */
|
||||||
|
RECOVER_MACHINE_REGS();
|
||||||
|
/* make sure we do this after restore */
|
||||||
|
if (yap_init->MaxStackSize) {
|
||||||
|
GLOBAL_AllowLocalExpansion = FALSE;
|
||||||
|
} else {
|
||||||
|
GLOBAL_AllowLocalExpansion = TRUE;
|
||||||
|
}
|
||||||
|
if (yap_init->MaxGlobalSize) {
|
||||||
|
GLOBAL_AllowGlobalExpansion = FALSE;
|
||||||
|
} else {
|
||||||
|
GLOBAL_AllowGlobalExpansion = TRUE;
|
||||||
|
}
|
||||||
|
if (yap_init->MaxTrailSize) {
|
||||||
|
GLOBAL_AllowTrailExpansion = FALSE;
|
||||||
|
} else {
|
||||||
|
GLOBAL_AllowTrailExpansion = TRUE;
|
||||||
|
}
|
||||||
|
if (yap_init->YapPrologRCFile) {
|
||||||
|
Yap_PutValue(AtomConsultOnBoot,
|
||||||
|
MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologRCFile)));
|
||||||
|
/*
|
||||||
|
This must be done again after restore, as yap_flags
|
||||||
|
has been overwritten ....
|
||||||
|
*/
|
||||||
|
setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG,
|
||||||
|
yap_init->HaltAfterConsult);
|
||||||
|
}
|
||||||
|
if (yap_init->YapPrologTopLevelGoal) {
|
||||||
|
Yap_PutValue(AtomTopLevelGoal,
|
||||||
|
MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologTopLevelGoal)));
|
||||||
|
}
|
||||||
|
if (yap_init->YapPrologGoal) {
|
||||||
|
Yap_PutValue(AtomInitGoal,
|
||||||
|
MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologGoal)));
|
||||||
|
}
|
||||||
|
if (yap_init->YapPrologAddPath) {
|
||||||
|
Yap_PutValue(AtomExtendFileSearchPath,
|
||||||
|
MkAtomTerm(Yap_LookupAtom(yap_init->YapPrologAddPath)));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (yap_init->QuietMode) {
|
||||||
|
setVerbosity(TermSilent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static YAP_file_type_t end_init(YAP_init_args *yap_init, YAP_file_type_t rc) {
|
||||||
|
init_globals(yap_init);
|
||||||
|
LOCAL_PrologMode &= ~BootMode;
|
||||||
|
|
||||||
|
start_modules();
|
||||||
|
|
||||||
|
YAP_initialized = true;
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* this routine is supposed to be called from an external program
|
||||||
|
that wants to control Yap */
|
||||||
|
|
||||||
|
X_API YAP_file_type_t YAP_Init(YAP_init_args *yap_init) {
|
||||||
|
YAP_file_type_t restore_result = yap_init->boot_file_type;
|
||||||
|
bool do_bootstrap = (restore_result & YAP_CONSULT_MODE);
|
||||||
|
struct ssz_t minfo;
|
||||||
|
|
||||||
|
if (YAP_initialized)
|
||||||
|
return YAP_FOUND_BOOT_ERROR;
|
||||||
|
if (!LOCAL_TextBuffer)
|
||||||
|
LOCAL_TextBuffer = Yap_InitTextAllocator();
|
||||||
|
|
||||||
|
/* ignore repeated calls to YAP_Init */
|
||||||
|
Yap_embedded = yap_init->Embedded;
|
||||||
|
|
||||||
|
minfo.Trail = 0, minfo.Stack = 0, minfo.Trail = 0;
|
||||||
|
init_hw(yap_init, &minfo);
|
||||||
|
Yap_InitWorkspace(yap_init, minfo.Heap, minfo.Stack, minfo.Trail, 0,
|
||||||
|
yap_init->MaxTableSpaceSize, yap_init->NumberWorkers,
|
||||||
|
yap_init->SchedulerLoop, yap_init->DelayedReleaseLoad);
|
||||||
|
//
|
||||||
|
|
||||||
|
CACHE_REGS
|
||||||
|
if (Yap_embedded)
|
||||||
|
if (yap_init->QuietMode) {
|
||||||
|
setVerbosity(TermSilent);
|
||||||
|
}
|
||||||
|
if (yap_init->YapPrologRCFile != NULL) {
|
||||||
|
/*
|
||||||
|
This must be done before restore, otherwise
|
||||||
|
restore will print out messages ....
|
||||||
|
*/
|
||||||
|
setBooleanGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG,
|
||||||
|
yap_init->HaltAfterConsult);
|
||||||
|
}
|
||||||
|
/* tell the system who should cope with interrupts */
|
||||||
|
Yap_ExecutionMode = yap_init->ExecutionMode;
|
||||||
|
Yap_set_locations(yap_init);
|
||||||
|
if (!do_bootstrap && Yap_STARTUP && yap_init->boot_file_type != YAP_BOOT_PL &&
|
||||||
|
Yap_SavedInfo(Yap_STARTUP, &minfo.Trail, &minfo.Stack, &minfo.Heap) &&
|
||||||
|
Yap_Restore(Yap_STARTUP)) {
|
||||||
|
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, true);
|
||||||
|
CurrentModule = LOCAL_SourceModule = USER_MODULE;
|
||||||
|
return end_init(yap_init, YAP_QLY);
|
||||||
|
} else {
|
||||||
|
do_bootfile(Yap_BOOTFILE PASS_REGS);
|
||||||
|
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false);
|
||||||
|
return end_init(yap_init, YAP_BOOT_PL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if (DefTrailSpace < MinTrailSpace)
|
||||||
|
#undef DefTrailSpace
|
||||||
|
#define DefTrailSpace MinTrailSpace
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (DefStackSpace < MinStackSpace)
|
||||||
|
#undef DefStackSpace
|
||||||
|
#define DefStackSpace MinStackSpace
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if (DefHeapSpace < MinHeapSpace)
|
||||||
|
#undef DefHeapSpace
|
||||||
|
#define DefHeapSpace MinHeapSpace
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define DEFAULT_NUMBERWORKERS 1
|
||||||
|
#define DEFAULT_SCHEDULERLOOP 10
|
||||||
|
#define DEFAULT_DELAYEDRELEASELOAD 3
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
if ((out = Yap_InitDefaults(&init_args, saved_state, argc, argv)) !=
|
||||||
|
YAP_FOUND_BOOT_ERROR)
|
||||||
|
out = YAP_Init(&init_args);
|
||||||
|
if (out == YAP_FOUND_BOOT_ERROR) {
|
||||||
|
Yap_Error(init_args.ErrorNo, TermNil, init_args.ErrorCause);
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
121
CMakeLists.txt
121
CMakeLists.txt
@ -7,18 +7,18 @@ cmake_minimum_required(VERSION 3.4)
|
|||||||
# value of 3.4.0 or lower.
|
# value of 3.4.0 or lower.
|
||||||
include(CMakeToolsHelpers OPTIONAL)
|
include(CMakeToolsHelpers OPTIONAL)
|
||||||
|
|
||||||
project(YAP)
|
|
||||||
|
|
||||||
include(FeatureSummary)
|
include(FeatureSummary)
|
||||||
include(GNUInstallDirs)
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
|
project(YAP)
|
||||||
|
|
||||||
set(YAP_APP_DIR "${CMAKE_SOURCE_DIR}/../..")
|
set(YAP_APP_DIR "${CMAKE_SOURCE_DIR}/../..")
|
||||||
cmake_policy(VERSION 3.4)
|
cmake_policy(VERSION 3.4)
|
||||||
|
|
||||||
set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/cmake")
|
set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
set(ANACONDA $ENV{CONDA_BUILD} CACHE BOOL "Anaconda Environment")
|
set(ANACONDA $ENV{CONDA_BUILD} CACHE BOOL "Anaconda Environment")
|
||||||
message(STATUS "ANACONDA found: ${ANACONDA}")
|
message(STATUS "ANACONDA found: ${ANACONDA}")
|
||||||
|
|
||||||
include(CheckIncludeFiles)
|
include(CheckIncludeFiles)
|
||||||
include(CheckLibraryExists)
|
include(CheckLibraryExists)
|
||||||
@ -219,9 +219,10 @@ if (ANACONDA)
|
|||||||
#set(CMAKE_LIBRARY_PATH $ENV{SYS_PREFIX}/lib $ENV{SYS_PREFIX}/lib ${CMAKE_LIBRARY_PATH})
|
#set(CMAKE_LIBRARY_PATH $ENV{SYS_PREFIX}/lib $ENV{SYS_PREFIX}/lib ${CMAKE_LIBRARY_PATH})
|
||||||
# set(ENV{PATH} PATH $ENV{PREFIX}/bin $ENV{SYS_PREFIX}/bin $ENV{PATH})
|
# set(ENV{PATH} PATH $ENV{PREFIX}/bin $ENV{SYS_PREFIX}/bin $ENV{PATH})
|
||||||
# set(PATH $ENV{PATH} ${PATH})
|
# set(PATH $ENV{PATH} ${PATH})
|
||||||
#set( CMAKE_INSTALL_PREFIX $ENV{PREFIX} )
|
#set( CMAKE_INSTALL_FULL_PREFIX $ENV{PREFIX} )
|
||||||
set( PYTHON_LIBRARY $ENV{PREFIX}/lib/libpython$ENV{PY_VER}m$ENV{SHLIB_EXT})
|
set( PYTHON_LIBRARY $ENV{PREFIX}/lib/libpython$ENV{PY_VER}m$ENV{SHLIB_EXT})
|
||||||
set( PYTHON_INCLUDE_DIR $ENV{PREFIX}/include/python$ENV{PY_VER}m)
|
set( PYTHON_INCLUDE_DIR $ENV{PREFIX}/include/python$ENV{PY_VER}m)
|
||||||
|
set_property(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS CONDA_BUILD=1)
|
||||||
set(YAP_IS_MOVABLE 1)
|
set(YAP_IS_MOVABLE 1)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
@ -249,6 +250,7 @@ if (APPLE)
|
|||||||
endif ()
|
endif ()
|
||||||
endif ()
|
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})
|
||||||
@ -268,22 +270,26 @@ set(dlls ${libdir}/Yap)
|
|||||||
|
|
||||||
set(YAP_ROOTDIR ${prefix})
|
set(YAP_ROOTDIR ${prefix})
|
||||||
# erootdir -> rootdir
|
# erootdir -> rootdir
|
||||||
# bindir defined above
|
|
||||||
# libdir defined above
|
# libdir defined above
|
||||||
set(YAP_SHAREDIR ${datarootdir})
|
set(YAP_DATADIR ${CMAKE_INSTALL_FULL_DATADIR})
|
||||||
set(YAP_BINDIR ${bindir})
|
set(YAP_INCLUDEDIR ${CMAKE_INSTALL_FULL_INCLUDEDIR}/Yap)
|
||||||
set(YAP_INCLUDEDIR ${includedir})
|
set(YAP_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR})
|
||||||
set(YAP_ROOTDIR ${prefix})
|
set(YAP_DLLDIR ${CMAKE_INSTALL_FULL_LIBDIR}/Yap)
|
||||||
set(YAP_LIBDIR ${dlls})
|
set(YAP_PLDIR ${CMAKE_INSTALL_FULL_DATADIR}/Yap)
|
||||||
|
|
||||||
|
set(YAP_INSTALL_DLLDIR ${CMAKE_INSTALL_LIBDIR}/Yap)
|
||||||
|
set(YAP_INSTALL_PLDIR ${CMAKE_INSTALL_DATADIR}/Yap)
|
||||||
|
|
||||||
|
set(libpl ${YAP_INSTALL_PLDIR})
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# include( Sources NO_POLICY_SCOPE )
|
# include( Sources )
|
||||||
#
|
#
|
||||||
# include( Model NO_POLICY_SCOPE )
|
# include( Model )
|
||||||
|
|
||||||
include(cudd NO-POLICY-SCOPE)
|
include(cudd )
|
||||||
include(java NO-POLICY-SCOPE)
|
include(java )
|
||||||
|
|
||||||
set(pl_library "" CACHE INTERNAL "prolog library files")
|
set(pl_library "" CACHE INTERNAL "prolog library files")
|
||||||
set(pl_os_library "" CACHE INTERNAL "prolog os files")
|
set(pl_os_library "" CACHE INTERNAL "prolog os files")
|
||||||
@ -396,6 +402,36 @@ if (${C_COMPILER} MATCHES "Intel")
|
|||||||
set(HAVE_GCC 1)
|
set(HAVE_GCC 1)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
|
# rpath stuff, hopefully it works
|
||||||
|
# use, i.e. don't skip the full RPATH for the build tree
|
||||||
|
#SET(CMAKE_SKIP_BUILD_RPATH FALSE)
|
||||||
|
|
||||||
|
|
||||||
|
# when building, don't use the install RPATH already
|
||||||
|
# (but later on when installing)
|
||||||
|
#SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
||||||
|
|
||||||
|
# SET(CMAKE_INSTALL_FULL_RPATH ${CMAKE_TOP_BINARY_DIR})
|
||||||
|
|
||||||
|
# add the automatically determined parts of the RPATH
|
||||||
|
# which point to directories outside the build tree to the install RPATH
|
||||||
|
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
||||||
|
|
||||||
|
|
||||||
|
# the RPATH to be used when installing, but only if it's not a system directory
|
||||||
|
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${libdir}" isSystemDir)
|
||||||
|
IF("${isSystemDir}" STREQUAL "-1")
|
||||||
|
SET(CMAKE_INSTALL_RPATH ${libdir})
|
||||||
|
ENDIF("${isSystemDir}" STREQUAL "-1")
|
||||||
|
|
||||||
|
IF(NOT WIN32 AND NOT APPLE)
|
||||||
|
LIST(APPEND CMAKE_INSTALL_RPATH \\$ORIGIN/../lib/Yap)
|
||||||
|
LIST(APPEND CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR})
|
||||||
|
LIST(APPEND CMAKE_INSTALL_RPATH \\$ORIGIN/../lib)
|
||||||
|
LIST(APPEND CMAKE_INSTALL_RPATH \\$ORIGIN/../../../lib)
|
||||||
|
|
||||||
|
ENDIF()
|
||||||
|
|
||||||
# Model Specific
|
# Model Specific
|
||||||
if (HAVE_GCC)
|
if (HAVE_GCC)
|
||||||
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS -Wall)
|
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS -Wall)
|
||||||
@ -458,19 +494,19 @@ 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 "
|
||||||
# "http://www.swig.org" ON)
|
# "http://www.swig.org" ON)
|
||||||
ENDIF (WITH_SWIG OR ANDROID)
|
ENDIF (WITH_SWIG)
|
||||||
|
|
||||||
|
|
||||||
option(WITH_PYTHON
|
option(WITH_PYTHON
|
||||||
"Allow Python->YAP and YAP->Python" ON)
|
"Allow Python->YAP and YAP->Python" ON)
|
||||||
|
|
||||||
IF (WITH_PYTHON)
|
IF (WITH_PYTHON)
|
||||||
include(python NO_POLICY_SCOPE)
|
include(python )
|
||||||
ENDIF (WITH_PYTHON)
|
ENDIF (WITH_PYTHON)
|
||||||
|
|
||||||
|
|
||||||
@ -528,6 +564,7 @@ endif ()
|
|||||||
|
|
||||||
|
|
||||||
set(YAP_STARTUP startup.yss)
|
set(YAP_STARTUP startup.yss)
|
||||||
|
set(YAP_BOOTFILE boot.yap )
|
||||||
## define system
|
## define system
|
||||||
|
|
||||||
# Optional libraries that affect compilation
|
# Optional libraries that affect compilation
|
||||||
@ -545,27 +582,6 @@ string(SUBSTRING ${CMAKE_SHARED_LIBRARY_SUFFIX} 1 -1 SO_EXT)
|
|||||||
|
|
||||||
set_property(DIRECTORY PROPERTY CXX_STANDARD 11)
|
set_property(DIRECTORY PROPERTY CXX_STANDARD 11)
|
||||||
|
|
||||||
# rpath stuff, hopefully it works
|
|
||||||
# use, i.e. don't skip the full RPATH for the build tree
|
|
||||||
#SET(CMAKE_SKIP_BUILD_RPATH FALSE)
|
|
||||||
|
|
||||||
|
|
||||||
# when building, don't use the install RPATH already
|
|
||||||
# (but later on when installing)
|
|
||||||
#SET(CMAKE_BUILD_WITH_INSTALL_RPATH TRUE)
|
|
||||||
|
|
||||||
# SET(CMAKE_INSTALL_RPATH ${CMAKE_TOP_BINARY_DIR})
|
|
||||||
|
|
||||||
# add the automatically determined parts of the RPATH
|
|
||||||
# which point to directories outside the build tree to the install RPATH
|
|
||||||
# SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
|
|
||||||
|
|
||||||
|
|
||||||
# the RPATH to be used when installing, but only if it's not a system directory
|
|
||||||
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${libdir}" isSystemDir)
|
|
||||||
IF("${isSystemDir}" STREQUAL "-1")
|
|
||||||
SET(CMAKE_INSTALL_RPATH ${libdir})
|
|
||||||
ENDIF("${isSystemDir}" STREQUAL "-1")
|
|
||||||
|
|
||||||
include_directories(H
|
include_directories(H
|
||||||
H/generated
|
H/generated
|
||||||
@ -614,11 +630,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 +649,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 ()
|
||||||
|
|
||||||
|
|
||||||
@ -789,9 +801,9 @@ set_target_properties(yap-bin PROPERTIES OUTPUT_NAME yap)
|
|||||||
target_link_libraries(yap-bin libYap)
|
target_link_libraries(yap-bin libYap)
|
||||||
|
|
||||||
install(TARGETS libYap yap-bin
|
install(TARGETS libYap yap-bin
|
||||||
RUNTIME DESTINATION ${bindir}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
LIBRARY DESTINATION ${libdir}
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
ARCHIVE DESTINATION ${libdir}
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -801,6 +813,8 @@ 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)
|
||||||
@ -822,19 +836,26 @@ if (MPI_C_FOUND)
|
|||||||
endif ()
|
endif ()
|
||||||
endif (MPI_C_FOUND)
|
endif (MPI_C_FOUND)
|
||||||
|
|
||||||
|
endif(NOT ANDROID)
|
||||||
|
|
||||||
## add_subDIRECTORY(utils)
|
## add_subDIRECTORY(utils)
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
||||||
|
install(FILES ${INCLUDE_HEADERS} ${CONFIGURATION_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Yap )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
macro_display_feature_log()
|
macro_display_feature_log()
|
||||||
if (POLICY CMP0058)
|
if (POLICY CMP0058)
|
||||||
cmake_policy(SET CMP0058 NEW)
|
cmake_policy(SET CMP0058 NEW)
|
||||||
endif (POLICY CMP0058)
|
endif (POLICY CMP0058)
|
||||||
|
|
||||||
include(Config NO_POLICY_SCOPE)
|
include(Config )
|
||||||
|
|
||||||
|
|
||||||
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES
|
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES
|
||||||
INCLUDE_QUIET_PACKAGES
|
INCLUDE_QUIET_PACKAGES
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ else()
|
|||||||
MY_target_link_libraries(YAP++ ${CMAKE_DL_LIBS} libYap)
|
MY_target_link_libraries(YAP++ ${CMAKE_DL_LIBS} libYap)
|
||||||
|
|
||||||
MY_install(TARGETS YAP++
|
MY_install(TARGETS YAP++
|
||||||
LIBRARY DESTINATION ${libdir}
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${libdir}
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
18
CXX/yapdb.hh
18
CXX/yapdb.hh
@ -88,7 +88,9 @@ protected:
|
|||||||
PredEntry *ap;
|
PredEntry *ap;
|
||||||
|
|
||||||
/// auxiliary routine to find a predicate in the current module.
|
/// auxiliary routine to find a predicate in the current module.
|
||||||
PredEntry *getPred(YAPTerm &t, Term *&outp);
|
|
||||||
|
/// auxiliary routine to find a predicate in the current module.
|
||||||
|
PredEntry *getPred(YAPTerm &t, CELL *& outp);
|
||||||
|
|
||||||
PredEntry *asPred() { return ap; };
|
PredEntry *asPred() { return ap; };
|
||||||
|
|
||||||
@ -122,7 +124,7 @@ protected:
|
|||||||
///
|
///
|
||||||
/// It is just a call to getPred
|
/// It is just a call to getPred
|
||||||
inline YAPPredicate(Term t) {
|
inline YAPPredicate(Term t) {
|
||||||
CELL *v = NULL;
|
CELL *v = nullptr;
|
||||||
YAPTerm tt = YAPTerm(t);
|
YAPTerm tt = YAPTerm(t);
|
||||||
ap = getPred(tt, v);
|
ap = getPred(tt, v);
|
||||||
}
|
}
|
||||||
@ -131,7 +133,7 @@ protected:
|
|||||||
///
|
///
|
||||||
/// It is just a call to getPred
|
/// It is just a call to getPred
|
||||||
inline YAPPredicate(YAPTerm t) {
|
inline YAPPredicate(YAPTerm t) {
|
||||||
Term *v = nullptr;
|
CELL *v = nullptr;
|
||||||
ap = getPred(t, v);
|
ap = getPred(t, v);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -275,13 +277,13 @@ public:
|
|||||||
*/
|
*/
|
||||||
class X_API YAPFLIP : public YAPPredicate {
|
class X_API YAPFLIP : public YAPPredicate {
|
||||||
public:
|
public:
|
||||||
YAPFLIP(CPredicate call, YAPAtom name, uintptr_t arity,
|
YAPFLIP(YAP_UserCPred call, YAPAtom name, YAP_Arity arity,
|
||||||
YAPModule module = YAPModule(), CPredicate retry = 0,
|
YAPModule module = YAPModule(), YAP_UserCPred retry = 0,
|
||||||
CPredicate cut = 0, size_t extra = 0, bool test = false)
|
YAP_UserCPred cut = 0, YAP_Arity extra = 0, bool test = false)
|
||||||
: YAPPredicate(name, arity, module) {
|
: YAPPredicate(name, arity, module) {
|
||||||
if (retry) {
|
if (retry) {
|
||||||
Yap_InitCPredBackCut(name.getName(), arity, extra, call, retry, cut,
|
YAP_UserBackCutCPredicate(name.getName(), call, retry, cut, arity, extra
|
||||||
UserCPredFlag);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (test) {
|
if (test) {
|
||||||
YAP_UserCPredicate(name.getName(), call, arity);
|
YAP_UserCPredicate(name.getName(), call, arity);
|
||||||
|
51
CXX/yapi.cpp
51
CXX/yapi.cpp
@ -12,14 +12,14 @@ extern "C" {
|
|||||||
#include "YapInterface.h"
|
#include "YapInterface.h"
|
||||||
#include "blobs.h"
|
#include "blobs.h"
|
||||||
|
|
||||||
X_API char *Yap_TermToString(Term t, encoding_t encodingp,
|
X_API char *Yap_TermToBuffer(Term t, encoding_t encodingp,
|
||||||
int flags);
|
int flags);
|
||||||
|
|
||||||
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, arity_t arity);
|
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, arity_t arity);
|
||||||
X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, arity_t,
|
X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, arity_t,
|
||||||
YAP_Term);
|
YAP_Term);
|
||||||
X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred,
|
X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred,
|
||||||
arity_t, arity_t);
|
YAP_Arity, YAP_Arity);
|
||||||
|
|
||||||
#if YAP_PYTHON
|
#if YAP_PYTHON
|
||||||
X_API bool do_init_python(void);
|
X_API bool do_init_python(void);
|
||||||
@ -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,34 +916,30 @@ 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
|
||||||
|
|
||||||
|
|
||||||
void YAPEngine::doInit(YAP_file_type_t BootMode)
|
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;
|
return;
|
||||||
throw YAPError();
|
throw YAPError();
|
||||||
}
|
}
|
||||||
/* Begin preprocessor code */
|
/* Begin preprocessor code */
|
||||||
/* live */
|
/* live */
|
||||||
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "initialize_prolog");
|
|
||||||
#if __ANDROID__
|
|
||||||
Yap_AndroidBufp = (char *)malloc(Yap_AndroidMax = 4096);
|
|
||||||
Yap_AndroidBufp[0] = '\0';
|
|
||||||
Yap_AndroidSz = 0;
|
|
||||||
#endif
|
|
||||||
//yerror = YAPError();
|
//yerror = YAPError();
|
||||||
#if YAP_PYTHON
|
#if YAP_PYTHON
|
||||||
do_init_python();
|
do_init_python();
|
||||||
#endif
|
#endif
|
||||||
YAP_PredEntryPtr p = YAP_AtomToPred( YAP_LookupAtom("initialize_prolog") );
|
std::string s = "initialize_prolog";
|
||||||
|
YAPPredicate p = YAPPredicate( YAPAtomTerm(s) );
|
||||||
YAPQuery initq = YAPQuery(YAPPredicate(p), nullptr);
|
YAPQuery initq = YAPQuery(YAPPredicate(p), nullptr);
|
||||||
if (initq.next())
|
if (initq.next())
|
||||||
{
|
{
|
||||||
@ -957,14 +955,17 @@ YAPEngine::YAPEngine(int argc, char *argv[],
|
|||||||
|
|
||||||
YAP_file_type_t BootMode;
|
YAP_file_type_t BootMode;
|
||||||
engine_args = new YAPEngineArgs();
|
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
|
// 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
|
||||||
@ -986,7 +987,7 @@ YAPEngine::YAPEngine(int argc, char *argv[],
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// auxiliary routine to find a predicate in the current module.
|
/// auxiliary routine to find a predicate in the current module.
|
||||||
PredEntry *YAPPredicate::getPred(YAPTerm &tt, Term *&outp)
|
PredEntry *YAPPredicate::getPred(YAPTerm &tt, CELL * &outp)
|
||||||
{
|
{
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Term m = Yap_CurrentModule(), t = tt.term();
|
Term m = Yap_CurrentModule(), t = tt.term();
|
||||||
@ -1009,9 +1010,11 @@ YAPEngine::YAPEngine(int argc, char *argv[],
|
|||||||
else if (IsPairTerm(t))
|
else if (IsPairTerm(t))
|
||||||
{
|
{
|
||||||
Term ts[2];
|
Term ts[2];
|
||||||
ts[0] = t;
|
Functor FunctorConsult = Yap_MkFunctor(Yap_LookupAtom("consult"), 1);
|
||||||
ts[1] = m;
|
ts[1] = t;
|
||||||
t = Yap_MkApplTerm(FunctorCsult, 2, ts);
|
ts[0] = m;
|
||||||
|
t = Yap_MkApplTerm(FunctorModule, 2, ts);
|
||||||
|
t = Yap_MkApplTerm(FunctorConsult, 1, &t);
|
||||||
tt.put(t);
|
tt.put(t);
|
||||||
outp = RepAppl(t) + 1;
|
outp = RepAppl(t) + 1;
|
||||||
}
|
}
|
||||||
@ -1104,7 +1107,7 @@ YAPEngine::YAPEngine(int argc, char *argv[],
|
|||||||
if (LOCAL_ActiveError->prologPredLine)
|
if (LOCAL_ActiveError->prologPredLine)
|
||||||
{
|
{
|
||||||
s += "\n";
|
s += "\n";
|
||||||
s += LOCAL_ActiveError->prologPredFile->StrOfAE;
|
s += LOCAL_ActiveError->prologPredFile;
|
||||||
s += ":";
|
s += ":";
|
||||||
sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredLine);
|
sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredLine);
|
||||||
s += buf; // std::to_string(LOCAL_ActiveError->prologPredLine) ;
|
s += buf; // std::to_string(LOCAL_ActiveError->prologPredLine) ;
|
||||||
@ -1112,7 +1115,7 @@ YAPEngine::YAPEngine(int argc, char *argv[],
|
|||||||
s += ":0 ";
|
s += ":0 ";
|
||||||
s += LOCAL_ActiveError->prologPredModule;
|
s += LOCAL_ActiveError->prologPredModule;
|
||||||
s += ":";
|
s += ":";
|
||||||
s += (LOCAL_ActiveError->prologPredName)->StrOfAE;
|
s += (LOCAL_ActiveError->prologPredName);
|
||||||
s += "/";
|
s += "/";
|
||||||
sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredArity);
|
sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredArity);
|
||||||
s += // std::to_string(LOCAL_ActiveError->prologPredArity);
|
s += // std::to_string(LOCAL_ActiveError->prologPredArity);
|
||||||
@ -1120,13 +1123,13 @@ YAPEngine::YAPEngine(int argc, char *argv[],
|
|||||||
}
|
}
|
||||||
s += " error ";
|
s += " error ";
|
||||||
if (LOCAL_ActiveError->classAsText != nullptr)
|
if (LOCAL_ActiveError->classAsText != nullptr)
|
||||||
s += LOCAL_ActiveError->classAsText->StrOfAE;
|
s += LOCAL_ActiveError->classAsText;
|
||||||
s += ".";
|
s += ".";
|
||||||
s += LOCAL_ActiveError->errorAsText->StrOfAE;
|
s += LOCAL_ActiveError->errorAsText;
|
||||||
s += ".\n";
|
s += ".\n";
|
||||||
if (LOCAL_ActiveError->errorTerm)
|
if (LOCAL_ActiveError->errorTerm)
|
||||||
{
|
{
|
||||||
Term t = LOCAL_ActiveError->errorTerm->Entry;
|
Term t = Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);
|
||||||
if (t)
|
if (t)
|
||||||
{
|
{
|
||||||
s += "error term is: ";
|
s += "error term is: ";
|
||||||
|
12
CXX/yapi.hh
12
CXX/yapi.hh
@ -85,8 +85,16 @@ X_API extern void YAP_UserCPredicate(const char *, YAP_UserCPred,
|
|||||||
X_API extern void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred,
|
X_API extern void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred,
|
||||||
YAP_Arity, YAP_Term);
|
YAP_Arity, YAP_Term);
|
||||||
|
|
||||||
X_API extern void UserBackCPredicate(const char *name, int *init(), int *cont(),
|
X_API extern void YAP_UserBackCPredicate(const char *name,
|
||||||
int arity, int extra);
|
YAP_UserCPred init,
|
||||||
|
YAP_UserCPred cont,
|
||||||
|
YAP_Arity arity, YAP_Arity extra);
|
||||||
|
|
||||||
|
X_API extern void YAP_UserBackCutCPredicate(const char *name,
|
||||||
|
YAP_UserCPred init,
|
||||||
|
YAP_UserCPred cont,
|
||||||
|
YAP_UserCPred cut,
|
||||||
|
YAP_Arity arity, YAP_Arity extra);
|
||||||
|
|
||||||
X_API extern YAP_Term YAP_ReadBuffer(const char *s, YAP_Term *tp);
|
X_API extern YAP_Term YAP_ReadBuffer(const char *s, YAP_Term *tp);
|
||||||
|
|
||||||
|
106
CXX/yapq.hh
106
CXX/yapq.hh
@ -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(); };
|
||||||
@ -180,170 +185,177 @@ public:
|
|||||||
virtual void run(char *s) {}
|
virtual void run(char *s) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/// @brief Setup all arguments to a new engine
|
/// @brief Setup all arguments to a new engine
|
||||||
class X_API YAPEngineArgs {
|
struct X_API YAPEngineArgs: YAP_init_args {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
YAP_init_args init_args;
|
YAPEngineArgs():yap_boot_params() {
|
||||||
|
char s[32];
|
||||||
|
strcpy(s, "startup.yss" );
|
||||||
|
Yap_InitDefaults(this,s,0,nullptr);
|
||||||
|
#if YAP_PYTHON
|
||||||
|
Embedded = true;
|
||||||
|
python_in_python = Py_IsInitialized();
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
inline void setEmbedded( bool fl )
|
inline void setEmbedded( bool fl )
|
||||||
{
|
{
|
||||||
init_args.Embedded = fl;
|
Embedded = fl;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool getEmbedded( )
|
inline bool getEmbedded( )
|
||||||
{
|
{
|
||||||
return init_args.Embedded;
|
return Embedded;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void setStackSize( bool fl )
|
inline void setStackSize( bool fl )
|
||||||
{
|
{
|
||||||
init_args.StackSize = fl;
|
StackSize = fl;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool getStackSize( )
|
inline bool getStackSize( )
|
||||||
{
|
{
|
||||||
return init_args.StackSize;
|
return StackSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void setTrailSize( bool fl )
|
inline void setTrailSize( bool fl )
|
||||||
{
|
{
|
||||||
init_args.TrailSize = fl;
|
TrailSize = fl;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool getTrailSize( )
|
inline bool getTrailSize( )
|
||||||
{
|
{
|
||||||
return init_args.TrailSize;
|
return TrailSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool getMStackSize( )
|
inline bool getMStackSize( )
|
||||||
{
|
{
|
||||||
return init_args.StackSize;
|
return StackSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void setMaxTrailSize( bool fl )
|
inline void setMaxTrailSize( bool fl )
|
||||||
{
|
{
|
||||||
init_args.MaxTrailSize = fl;
|
MaxTrailSize = fl;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool getMaxTrailSize( )
|
inline bool getMaxTrailSize( )
|
||||||
{
|
{
|
||||||
return init_args.MaxTrailSize;
|
return MaxTrailSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void setYapLibDir( const char * fl )
|
inline void setYapLibDir( const char * fl )
|
||||||
{
|
{
|
||||||
init_args.YapLibDir = (const char *)malloc(strlen(fl)+1);
|
YapLibDir = (const char *)malloc(strlen(fl)+1);
|
||||||
strcpy((char *)init_args.YapLibDir, fl);
|
strcpy((char *)YapLibDir, fl);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const char * getYapLibDir( )
|
inline const char * getYapLibDir( )
|
||||||
{
|
{
|
||||||
return init_args.YapLibDir;
|
return YapLibDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void setYapShareDir( const char * fl )
|
inline void setYapShareDir( const char * fl )
|
||||||
{
|
{
|
||||||
init_args.YapShareDir = (const char *)malloc(strlen(fl)+1);
|
YapShareDir = (const char *)malloc(strlen(fl)+1);
|
||||||
strcpy((char *)init_args.YapShareDir, fl);
|
strcpy((char *)YapShareDir, fl);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const char * getYapShareDir( )
|
inline const char * getYapShareDir( )
|
||||||
{
|
{
|
||||||
return init_args.YapShareDir;
|
return YapShareDir;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void setSavedState( const char * fl )
|
inline void setSavedState( const char * fl )
|
||||||
{
|
{
|
||||||
init_args.SavedState = (const char *)malloc(strlen(fl)+1);
|
SavedState = (const char *)malloc(strlen(fl)+1);
|
||||||
strcpy((char *)init_args.SavedState, fl);
|
strcpy((char *)SavedState, fl);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const char * getSavedState( )
|
inline const char * getSavedState( )
|
||||||
{
|
{
|
||||||
return init_args.SavedState;
|
return SavedState;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void setYapPrologBootFile( const char * fl )
|
inline void setYapPrologBootFile( const char * fl )
|
||||||
{
|
{
|
||||||
init_args.YapPrologBootFile = (const char *)malloc(strlen(fl)+1);
|
YapPrologBootFile = (const char *)malloc(strlen(fl)+1);
|
||||||
strcpy((char *)init_args.YapPrologBootFile, fl);
|
strcpy((char *)YapPrologBootFile, fl);
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const char * getYapPrologBootFile( )
|
inline const char * getYapPrologBootFile( )
|
||||||
{
|
{
|
||||||
return init_args.YapPrologBootFile;
|
return YapPrologBootFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void setYapPrologGoal( const char * fl )
|
inline void setYapPrologGoal( const char * fl )
|
||||||
{
|
{
|
||||||
init_args.YapPrologGoal = fl;
|
YapPrologGoal = fl;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const char * getYapPrologGoal( )
|
inline const char * getYapPrologGoal( )
|
||||||
{
|
{
|
||||||
return init_args.YapPrologGoal;
|
return YapPrologGoal;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void setYapPrologTopLevelGoal( const char * fl )
|
inline void setYapPrologTopLevelGoal( const char * fl )
|
||||||
{
|
{
|
||||||
init_args.YapPrologTopLevelGoal = fl;
|
YapPrologTopLevelGoal = fl;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline const char * getYapPrologTopLevelGoal( )
|
inline const char * getYapPrologTopLevelGoal( )
|
||||||
{
|
{
|
||||||
return init_args.YapPrologTopLevelGoal;
|
return YapPrologTopLevelGoal;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void setHaltAfterConsult( bool fl )
|
inline void setHaltAfterConsult( bool fl )
|
||||||
{
|
{
|
||||||
init_args.HaltAfterConsult = fl;
|
HaltAfterConsult = fl;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool getHaltAfterConsult( )
|
inline bool getHaltAfterConsult( )
|
||||||
{
|
{
|
||||||
return init_args.HaltAfterConsult;
|
return HaltAfterConsult;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void setFastBoot( bool fl )
|
inline void setFastBoot( bool fl )
|
||||||
{
|
{
|
||||||
init_args.FastBoot = fl;
|
FastBoot = fl;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool getFastBoot( )
|
inline bool getFastBoot( )
|
||||||
{
|
{
|
||||||
return init_args.FastBoot;
|
return FastBoot;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#if __ANDROID__
|
||||||
|
//> export ResoourceManager
|
||||||
|
inline void setAssetManager( AAssetManager *mgr )
|
||||||
|
{
|
||||||
|
assetManager = mgr;
|
||||||
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
inline void setArgc( int fl )
|
inline void setArgc( int fl )
|
||||||
{
|
{
|
||||||
init_args.Argc = fl;
|
Argc = fl;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline int getArgc( )
|
inline int getArgc( )
|
||||||
{
|
{
|
||||||
return init_args.Argc;
|
return Argc;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void setArgv( char ** fl )
|
inline void setArgv( char ** fl )
|
||||||
{
|
{
|
||||||
init_args.Argv = fl;
|
Argv = fl;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline char ** getArgv( )
|
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 +380,7 @@ private:
|
|||||||
YAPEngine(YAPEngineArgs *cargs)
|
YAPEngine(YAPEngineArgs *cargs)
|
||||||
{
|
{
|
||||||
engine_args = cargs;
|
engine_args = cargs;
|
||||||
//doInit(cargs->init_args.boot_file_type);
|
//doInit(cargs->boot_file_type);
|
||||||
doInit(YAP_QLY);
|
doInit(YAP_QLY);
|
||||||
}; /// construct a new engine, including aaccess to callbacks
|
}; /// construct a new engine, including aaccess to callbacks
|
||||||
/// construct a new engine using argc/argv list of arguments
|
/// construct a new engine using argc/argv list of arguments
|
||||||
|
24
CXX/yapt.hh
24
CXX/yapt.hh
@ -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)
|
||||||
@ -183,7 +194,7 @@ public:
|
|||||||
virtual bool isGround() { return Yap_IsGroundTerm(gt()); } /// term is ground
|
virtual bool isGround() { return Yap_IsGroundTerm(gt()); } /// term is ground
|
||||||
virtual bool isList() { return Yap_IsListTerm(gt()); } /// term is a list
|
virtual bool isList() { return Yap_IsListTerm(gt()); } /// term is a list
|
||||||
|
|
||||||
/// extract the argument i of the term, where i in 1...arity
|
/// extract the argument i of the term, where i in 1...arityvoid *Yap_RepStreamFromId(int sno)
|
||||||
virtual Term getArg(arity_t i) {
|
virtual Term getArg(arity_t i) {
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
Term tf = 0;
|
Term tf = 0;
|
||||||
@ -230,7 +241,7 @@ public:
|
|||||||
char *os;
|
char *os;
|
||||||
|
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
if (!(os = Yap_TermToString(Yap_GetFromSlot(t), enc, Handle_vars_f))) {
|
if (!(os = Yap_TermToBuffer(Yap_GetFromSlot(t), enc, Handle_vars_f))) {
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -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();
|
||||||
@ -487,14 +501,16 @@ public:
|
|||||||
YAPAtomTerm(Atom a) { mk(MkAtomTerm(a)); }
|
YAPAtomTerm(Atom a) { mk(MkAtomTerm(a)); }
|
||||||
// Constructor: receives an atom;
|
// Constructor: receives an atom;
|
||||||
YAPAtomTerm(YAPAtom a) : YAPTerm() { mk(MkAtomTerm(a.a)); }
|
YAPAtomTerm(YAPAtom a) : YAPTerm() { mk(MkAtomTerm(a.a)); }
|
||||||
// Constructor: receives a sequence of ISO-LATIN1 codes;
|
// Constructor: receives a sequence of UTF-8 codes;
|
||||||
YAPAtomTerm(char s[]);
|
YAPAtomTerm(char s[]);
|
||||||
// Constructor: receives a sequence of up to n ISO-LATIN1 codes;
|
// Constructor: receives a sequence of up to n UTF-8 codes;
|
||||||
YAPAtomTerm(char *s, size_t len);
|
YAPAtomTerm(char *s, size_t len);
|
||||||
// Constructor: receives a sequence of wchar_ts, whatever they may be;
|
// Constructor: receives a sequence of wchar_ts, whatever they may be;
|
||||||
YAPAtomTerm(wchar_t *s);
|
YAPAtomTerm(wchar_t *s);
|
||||||
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
|
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
|
||||||
YAPAtomTerm(wchar_t *s, size_t len);
|
YAPAtomTerm(wchar_t *s, size_t len);
|
||||||
|
// Constructor: receives a std::string;
|
||||||
|
YAPAtomTerm(std::string s) { mk(MkAtomTerm(Yap_LookupAtom(s.c_str()))); };
|
||||||
bool isVar() { return false; } /// type check for unbound
|
bool isVar() { return false; } /// type check for unbound
|
||||||
bool isAtom() { return true; } /// type check for atom
|
bool isAtom() { return true; } /// type check for atom
|
||||||
bool isInteger() { return false; } /// type check for integer
|
bool isInteger() { return false; } /// type check for integer
|
||||||
|
@ -96,7 +96,7 @@ typedef struct ExtraAtomEntryStruct {
|
|||||||
#define USE_OFFSETS_IN_PROPS 0
|
#define USE_OFFSETS_IN_PROPS 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef SFLAGS PropFlags;
|
typedef CELL PropFlags;
|
||||||
|
|
||||||
/* basic property entry structure */
|
/* basic property entry structure */
|
||||||
typedef struct PropEntryStruct {
|
typedef struct PropEntryStruct {
|
||||||
|
3
H/Yap.h
3
H/Yap.h
@ -151,6 +151,9 @@ typedef void *(*fptr_t)(void);
|
|||||||
main exports in YapInterface.h
|
main exports in YapInterface.h
|
||||||
*************************************************************************************************/
|
*************************************************************************************************/
|
||||||
|
|
||||||
|
extern const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR, *Yap_PLDIR, *Yap_COMMONSDIR, *Yap_STARTUP, *Yap_BOOTFILE;
|
||||||
|
|
||||||
|
|
||||||
/* Basic exports */
|
/* Basic exports */
|
||||||
|
|
||||||
#include "YapDefs.h"
|
#include "YapDefs.h"
|
||||||
|
@ -193,8 +193,8 @@ static inline Term options(Term inp) {
|
|||||||
return Yap_IsGroundTerm(inp) ? inp : TermZERO;
|
return Yap_IsGroundTerm(inp) ? inp : TermZERO;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline Term rootdir(Term inp) {
|
static inline const char * rootdir(Term inp) {
|
||||||
return MkAtomTerm(Yap_LookupAtom(YAP_ROOTDIR));
|
return Yap_ROOTDIR;
|
||||||
}
|
}
|
||||||
|
|
||||||
// INLINE_ONLY inline EXTERN Term ok( Term inp );
|
// INLINE_ONLY inline EXTERN Term ok( Term inp );
|
||||||
|
@ -236,7 +236,7 @@ process, namely, on choice-points.
|
|||||||
YAP_FLAG(GMP_VERSION_FLAG, "gmp_version", false, isatom, "4.8.12", NULL),
|
YAP_FLAG(GMP_VERSION_FLAG, "gmp_version", false, isatom, "4.8.12", NULL),
|
||||||
YAP_FLAG(HALT_AFTER_CONSULT_FLAG, "halt_after_consult", false, booleanFlag,
|
YAP_FLAG(HALT_AFTER_CONSULT_FLAG, "halt_after_consult", false, booleanFlag,
|
||||||
"false", NULL),
|
"false", NULL),
|
||||||
/* YAP_FLAG(HOME_FLAG, "home", false, isatom, rootdir, NULL),*/ /**< home `
|
YAP_FLAG(HOME_FLAG, "home", false, isatom, YAP_ROOTDIR, NULL), /**< home `
|
||||||
|
|
||||||
the root of the YAP installation, by default `/usr/local` in Unix or
|
the root of the YAP installation, by default `/usr/local` in Unix or
|
||||||
`c:\Yap` in Windows system. Can only be set at configure time
|
`c:\Yap` in Windows system. Can only be set at configure time
|
||||||
|
37
H/YapText.h
37
H/YapText.h
@ -67,7 +67,7 @@ extern int pop_text_stack__(int lvl USES_REGS);
|
|||||||
(/*fprintf(stderr, "v %*c %s:%s:%d\n", AllocLevel(), ' ', __FILE__, \
|
(/*fprintf(stderr, "v %*c %s:%s:%d\n", AllocLevel(), ' ', __FILE__, \
|
||||||
__FUNCTION__, __LINE__),*/ \
|
__FUNCTION__, __LINE__),*/ \
|
||||||
pop_output_text_stack__(lvl,p))
|
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 **************************/
|
/****************** 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) {
|
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);
|
||||||
|
23
H/Yapproto.h
23
H/Yapproto.h
@ -292,6 +292,9 @@ extern void Yap_InitInlines(void);
|
|||||||
extern int Yap_eq(Term, Term);
|
extern int Yap_eq(Term, Term);
|
||||||
|
|
||||||
/* iopreds.c */
|
/* iopreds.c */
|
||||||
|
extern bool Yap_IsAbsolutePath(const char *p, bool);
|
||||||
|
extern Atom Yap_TemporaryFile(const char *prefix, int *fd);
|
||||||
|
extern const char *Yap_AbsoluteFile(const char *spec, char *obuf, bool expand);
|
||||||
extern void Yap_InitPlIO( struct yap_boot_params *ts );
|
extern void Yap_InitPlIO( struct yap_boot_params *ts );
|
||||||
extern void Yap_InitBackIO(void);
|
extern void Yap_InitBackIO(void);
|
||||||
extern void Yap_InitIOPreds(void);
|
extern void Yap_InitIOPreds(void);
|
||||||
@ -306,7 +309,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);
|
||||||
@ -355,16 +357,16 @@ extern void Yap_InitReadUtil(void);
|
|||||||
|
|
||||||
/* qly.c */
|
/* qly.c */
|
||||||
extern void Yap_InitQLY(void);
|
extern void Yap_InitQLY(void);
|
||||||
extern YAP_file_type_t Yap_Restore(const char *, const char *);
|
extern YAP_file_type_t Yap_Restore(const char *);
|
||||||
extern void Yap_InitQLYR(void);
|
extern void Yap_InitQLYR(void);
|
||||||
|
|
||||||
/* range.c */
|
/* range.c */
|
||||||
extern void Yap_InitRange(void);
|
extern void Yap_InitRange(void);
|
||||||
|
|
||||||
/* save.c */
|
/* save.c */
|
||||||
extern int Yap_SavedInfo(const char *, const char *, CELL *, CELL *, CELL *);
|
extern int Yap_SavedInfo(const char *, CELL *, CELL *, CELL *);
|
||||||
extern int Yap_SavedStateRestore(char *, char *);
|
extern int Yap_SavedStateRestore(char *);
|
||||||
extern FILE *Yap_OpenRestore(const char *, const char *);
|
extern FILE *Yap_OpenRestore(const char *);
|
||||||
extern void Yap_InitSavePreds(void);
|
extern void Yap_InitSavePreds(void);
|
||||||
|
|
||||||
/* scanner.c */
|
/* scanner.c */
|
||||||
@ -417,7 +419,7 @@ extern AAssetManager *Yap_assetManager;
|
|||||||
extern void *Yap_openAssetFile(const char *path);
|
extern void *Yap_openAssetFile(const char *path);
|
||||||
extern bool Yap_isAsset(const char *path);
|
extern bool Yap_isAsset(const char *path);
|
||||||
#endif
|
#endif
|
||||||
extern const char *Yap_getcwd(const char *, size_t);
|
extern const char *Yap_getcwd( char *, size_t);
|
||||||
extern void Yap_cputime_interval(Int *, Int *);
|
extern void Yap_cputime_interval(Int *, Int *);
|
||||||
extern void Yap_systime_interval(Int *, Int *);
|
extern void Yap_systime_interval(Int *, Int *);
|
||||||
extern void Yap_InitSysbits(int wid);
|
extern void Yap_InitSysbits(int wid);
|
||||||
@ -433,9 +435,11 @@ extern void Yap_WinError(char *);
|
|||||||
extern const char *Yap_AbsoluteFile(const char *spec, char *obuf, bool ok);
|
extern const char *Yap_AbsoluteFile(const char *spec, char *obuf, bool ok);
|
||||||
extern const char *Yap_AbsoluteFileInBuffer(const char *spec, char *outp, size_t sz,
|
extern const char *Yap_AbsoluteFileInBuffer(const char *spec, char *outp, size_t sz,
|
||||||
bool ok);
|
bool ok);
|
||||||
extern const char *Yap_findFile(const char *isource, const char *idef,
|
extern bool Yap_ChDir(const char *path);
|
||||||
const char *root, char *result, bool access,
|
bool Yap_isDirectory(const char *FileName);
|
||||||
YAP_file_type_t ftype, bool expand_root, bool in_lib);
|
extern bool Yap_Exists(const char *f);
|
||||||
|
|
||||||
|
|
||||||
/* threads.c */
|
/* threads.c */
|
||||||
extern void Yap_InitThreadPreds(void);
|
extern void Yap_InitThreadPreds(void);
|
||||||
extern void Yap_InitFirstWorkerThreadHandle(void);
|
extern void Yap_InitFirstWorkerThreadHandle(void);
|
||||||
@ -497,6 +501,7 @@ extern int Yap_get_stream_handle(Term, int, int, void *);
|
|||||||
extern Term Yap_get_stream_position(void *);
|
extern Term Yap_get_stream_position(void *);
|
||||||
extern struct AtomEntryStruct *Yap_lookupBlob(void *blob, size_t len, void *type,
|
extern struct AtomEntryStruct *Yap_lookupBlob(void *blob, size_t len, void *type,
|
||||||
int *newp);
|
int *newp);
|
||||||
|
extern void *Yap_RepStreamFromId(int sno);
|
||||||
|
|
||||||
/* opt.preds.c */
|
/* opt.preds.c */
|
||||||
extern void Yap_init_optyap_preds(void);
|
extern void Yap_init_optyap_preds(void);
|
||||||
|
12
H/Yatom.h
12
H/Yatom.h
@ -1306,10 +1306,10 @@ void Yap_UpdateTimestamps(PredEntry *);
|
|||||||
void Yap_ErDBE(DBRef);
|
void Yap_ErDBE(DBRef);
|
||||||
DBTerm *Yap_StoreTermInDB(Term, int);
|
DBTerm *Yap_StoreTermInDB(Term, int);
|
||||||
DBTerm *Yap_StoreTermInDBPlusExtraSpace(Term, UInt, UInt *);
|
DBTerm *Yap_StoreTermInDBPlusExtraSpace(Term, UInt, UInt *);
|
||||||
Term Yap_FetchTermFromDB(DBTerm *);
|
Term Yap_FetchTermFromDB(void *);
|
||||||
Term Yap_FetchClauseTermFromDB(DBTerm *);
|
Term Yap_FetchClauseTermFromDB(void *);
|
||||||
Term Yap_PopTermFromDB(DBTerm *);
|
Term Yap_PopTermFromDB(void *);
|
||||||
void Yap_ReleaseTermFromDB(DBTerm *);
|
void Yap_ReleaseTermFromDB(void *);
|
||||||
|
|
||||||
/* init.c */
|
/* init.c */
|
||||||
Atom Yap_GetOp(OpEntry *, int *, int);
|
Atom Yap_GetOp(OpEntry *, int *, int);
|
||||||
@ -1598,8 +1598,8 @@ bool Yap_PutException(Term t);
|
|||||||
INLINE_ONLY inline EXTERN bool Yap_HasException(void) {
|
INLINE_ONLY inline EXTERN bool Yap_HasException(void) {
|
||||||
return LOCAL_BallTerm != NULL;
|
return LOCAL_BallTerm != NULL;
|
||||||
}
|
}
|
||||||
INLINE_ONLY inline EXTERN DBTerm *Yap_RefToException(void) {
|
INLINE_ONLY inline EXTERN void *Yap_RefToException(void) {
|
||||||
DBTerm *dbt = LOCAL_BallTerm;
|
void *dbt = LOCAL_BallTerm;
|
||||||
LOCAL_BallTerm = NULL;
|
LOCAL_BallTerm = NULL;
|
||||||
return dbt;
|
return dbt;
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
/* consulting files */
|
/* consulting files */
|
||||||
|
|
||||||
typedef union CONSULT_OBJ {
|
typedef union CONSULT_OBJ {
|
||||||
const unsigned char *filename;
|
const unsigned char *f_name;
|
||||||
int mode;
|
int mode;
|
||||||
Prop p;
|
Prop p;
|
||||||
UInt c;
|
UInt c;
|
||||||
|
@ -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()
|
|
||||||
|
|
||||||
|
@ -131,7 +131,6 @@ BEAM/beam.h
|
|||||||
${CMAKE_SOURCE_DIR}/H/YapOpcodes.h
|
${CMAKE_SOURCE_DIR}/H/YapOpcodes.h
|
||||||
${CMAKE_SOURCE_DIR}/H/YapSignals.h
|
${CMAKE_SOURCE_DIR}/H/YapSignals.h
|
||||||
${CMAKE_SOURCE_DIR}/H/YapTags.h
|
${CMAKE_SOURCE_DIR}/H/YapTags.h
|
||||||
${CMAKE_SOURCE_DIR}/H/YapTerm.h
|
|
||||||
${CMAKE_SOURCE_DIR}/H/YapText.h
|
${CMAKE_SOURCE_DIR}/H/YapText.h
|
||||||
${CMAKE_SOURCE_DIR}/H/Yapproto.h
|
${CMAKE_SOURCE_DIR}/H/Yapproto.h
|
||||||
${CMAKE_SOURCE_DIR}/H/Yatom.h
|
${CMAKE_SOURCE_DIR}/H/Yatom.h
|
||||||
@ -206,6 +205,7 @@ set (INCLUDE_HEADERS
|
|||||||
${CMAKE_SOURCE_DIR}/include/YapInterface.h
|
${CMAKE_SOURCE_DIR}/include/YapInterface.h
|
||||||
${CMAKE_SOURCE_DIR}/include/YapRegs.h
|
${CMAKE_SOURCE_DIR}/include/YapRegs.h
|
||||||
${CMAKE_SOURCE_DIR}/include/YapStreams.h
|
${CMAKE_SOURCE_DIR}/include/YapStreams.h
|
||||||
|
${CMAKE_SOURCE_DIR}/include/YapTerm.h
|
||||||
${CMAKE_SOURCE_DIR}/include/blobs.h
|
${CMAKE_SOURCE_DIR}/include/blobs.h
|
||||||
${CMAKE_SOURCE_DIR}/include/c_interface.h
|
${CMAKE_SOURCE_DIR}/include/c_interface.h
|
||||||
${CMAKE_SOURCE_DIR}/include/clause_list.h
|
${CMAKE_SOURCE_DIR}/include/clause_list.h
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------
|
/*--------------------------------------------------------------------------
|
||||||
* This file is autogenerated from config.h.in
|
* This file is autogenerated from config.h.in
|
||||||
* during the cmake configuration of your project. If you need to make changes
|
* during the cmake configuration of your project. If you need to make changes
|
||||||
@ -1360,6 +1361,11 @@ signal. */
|
|||||||
#cmakedefine HAVE_STRNLEN ${HAVE_STRNLEN}
|
#cmakedefine HAVE_STRNLEN ${HAVE_STRNLEN}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Define to 1 if you have the `stpcpy' function. */
|
||||||
|
#ifndef HAVE_STPCPY
|
||||||
|
#cmakedefine HAVE_STPCPY ${HAVE_STPCPY}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Define to 1 if you have the <stropts.h> header file. */
|
/* Define to 1 if you have the <stropts.h> header file. */
|
||||||
#ifndef HAVE_STROPTS_H
|
#ifndef HAVE_STROPTS_H
|
||||||
#cmakedefine HAVE_STROPTS_H ${HAVE_STROPTS_H}
|
#cmakedefine HAVE_STROPTS_H ${HAVE_STROPTS_H}
|
||||||
@ -1943,6 +1949,11 @@ significant byte first (like Motorola and SPARC, unlike Intel). */
|
|||||||
#define YAP_STARTUP "${YAP_STARTUP}"
|
#define YAP_STARTUP "${YAP_STARTUP}"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* saved state file */
|
||||||
|
#ifndef YAP_BOOTFILE
|
||||||
|
#define YAP_BOOTFILE "${YAP_BOOTFILE}"
|
||||||
|
#endif
|
||||||
|
|
||||||
/* date of compilation */
|
/* date of compilation */
|
||||||
#ifndef YAP_TIMESTAMP
|
#ifndef YAP_TIMESTAMP
|
||||||
#define YAP_TIMESTAMP ${YAP_TIMESTAMP}
|
#define YAP_TIMESTAMP ${YAP_TIMESTAMP}
|
||||||
@ -1964,7 +1975,7 @@ significant byte first (like Motorola and SPARC, unlike Intel). */
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef YAP_IS_MOVABLE
|
|
||||||
/* name of YAP instaii */
|
/* name of YAP instaii */
|
||||||
#ifndef YAP_ROOTDIR
|
#ifndef YAP_ROOTDIR
|
||||||
#define YAP_ROOTDIR "${YAP_ROOTDIR}"
|
#define YAP_ROOTDIR "${YAP_ROOTDIR}"
|
||||||
@ -1972,17 +1983,17 @@ significant byte first (like Motorola and SPARC, unlike Intel). */
|
|||||||
|
|
||||||
/* name of YAP binaries */
|
/* name of YAP binaries */
|
||||||
#ifndef YAP_BINDIR
|
#ifndef YAP_BINDIR
|
||||||
#define YAP_BINDIR "${YAP_ROOTDIR}/bin"
|
#define YAP_BINDIR "${YAP_BINDIR}"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* name of YAP library */
|
/* name of YAP library */
|
||||||
#ifndef YAP_LIBDIR
|
#ifndef YAP_LIBDIR
|
||||||
#define YAP_LIBDIR "${YAP_ROOTDIR}/lib"
|
#define YAP_LIBDIR "${YAP_LIBDIR}"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* name of YAP DLL library */
|
/* name of YAP DLL library */
|
||||||
#ifndef YAP_YAPLIB
|
#ifndef YAP_DLLDIR
|
||||||
#define YAP_YAPLIB "${YAP_LIBDIR}/Yap"
|
#define YAP_DLLDIR "${YAP_LIBDIR}/Yap"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* name of YAP JIT library */
|
/* name of YAP JIT library */
|
||||||
@ -1994,13 +2005,14 @@ significant byte first (like Motorola and SPARC, unlike Intel). */
|
|||||||
#define YAP_SHAREDIR "${YAP_ROOTDIR}/share"
|
#define YAP_SHAREDIR "${YAP_ROOTDIR}/share"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#else
|
/* name of YAP PL library */
|
||||||
extern char
|
#ifndef YAP_PLDIR
|
||||||
*YAP_BINDIR,
|
#define YAP_PLDIR "${YAP_SHAREDIR}/Yap"
|
||||||
*YAP_ROOTDIR,
|
#endif
|
||||||
*YAP_SHAREDIR,
|
|
||||||
*YAP_LIBDIR,
|
/* name of Commons library */
|
||||||
*YAP_YAPLIB;
|
#ifndef YAP_COMMONSDIR
|
||||||
|
#define YAP COMMONSDIR "${YAP_SHAREDIR}/PrologCommmons"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ include_directories(../../CXX)
|
|||||||
|
|
||||||
|
|
||||||
install(TARGETS qtyap
|
install(TARGETS qtyap
|
||||||
RUNTIME DESTINATION ${bindir}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BIINDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
ENDIF(Qt5Widgets_FOUND)
|
ENDIF(Qt5Widgets_FOUND)
|
||||||
|
@ -107,11 +107,13 @@ static void exec_top_level(int BootMode, YAP_init_args *iap) {
|
|||||||
livegoal = YAP_FullLookupAtom("$live");
|
livegoal = YAP_FullLookupAtom("$live");
|
||||||
}
|
}
|
||||||
YAP_Exit(EXIT_SUCCESS);
|
YAP_Exit(EXIT_SUCCESS);
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
// FILE *debugf;
|
// FILE *debugf;
|
||||||
|
|
||||||
#ifdef LIGHT
|
#ifdef LIGHT
|
||||||
|
|
||||||
int _main(int argc, char **argv)
|
int _main(int argc, char **argv)
|
||||||
#else
|
#else
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
@ -121,6 +123,7 @@ int main(int argc, char **argv)
|
|||||||
int i;
|
int i;
|
||||||
YAP_init_args init_args;
|
YAP_init_args init_args;
|
||||||
BootMode = init_standard_system(argc, argv, &init_args);
|
BootMode = init_standard_system(argc, argv, &init_args);
|
||||||
|
|
||||||
if (BootMode == YAP_BOOT_ERROR) {
|
if (BootMode == YAP_BOOT_ERROR) {
|
||||||
fprintf(stderr, "[ FATAL ERROR: could not find saved state ]\n");
|
fprintf(stderr, "[ FATAL ERROR: could not find saved state ]\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
45
gtags.conf
45
gtags.conf
@ -1,45 +0,0 @@
|
|||||||
#
|
|
||||||
# Copyright (c) 1998, 1999, 2000, 2001, 2002, 2003, 2010, 2011, 2013,
|
|
||||||
# 2015, 2016
|
|
||||||
# Tama Communications Corporation
|
|
||||||
#
|
|
||||||
# This file is part of GNU GLOBAL.
|
|
||||||
#
|
|
||||||
# This file is free software; as a special exception the author gives
|
|
||||||
# unlimited permission to copy and/or distribute it, with or without
|
|
||||||
# modifications, as long as this notice is preserved.
|
|
||||||
#
|
|
||||||
# This program is distributed in the hope that it will be useful, but
|
|
||||||
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
|
|
||||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
||||||
#
|
|
||||||
# *
|
|
||||||
# Configuration file for GNU GLOBAL source code tag system.
|
|
||||||
#
|
|
||||||
# Basically, GLOBAL doesn't need this file ('gtags.conf'), because it has
|
|
||||||
# default values in itsself. If you have the file as '/etc/gtags.conf' or
|
|
||||||
# "$HOME/.globalrc" in your system then GLOBAL overwrite the default values
|
|
||||||
# with the values in the file.
|
|
||||||
#
|
|
||||||
# The format is similar to termcap(5). You can specify a target with
|
|
||||||
# GTAGSLABEL environment variable. Default target is 'default'.
|
|
||||||
#
|
|
||||||
# If you want to have a common record for yourself, it is recommended to
|
|
||||||
# use the following method:
|
|
||||||
#
|
|
||||||
default:\
|
|
||||||
:tc=yap@~/github/yap-6.3/gtags.conf:\
|
|
||||||
:tc=native:
|
|
||||||
|
|
||||||
#tc=user:tc=user:tc=new-ctags:tc=ctags:tc=pygments:
|
|
||||||
|
|
||||||
#
|
|
||||||
yap:\
|
|
||||||
:skip=Debug/,Release/,Threads/,mxe/,xcode/,codeblocks/,Qt/,xcode/,android/,compile_commands.json,xml/,YAPDroid/app/build/,YAPDroid/lib/build/: \
|
|
||||||
:tc=user-ctags-maps:
|
|
||||||
#
|
|
||||||
# A common map for both Exuberant Ctags and Universal Ctags.
|
|
||||||
# Don't include definitions of ctagscom and ctagslib in this entry.
|
|
||||||
#
|
|
||||||
user-ctags-maps:\
|
|
||||||
:langmap=Prolog\:.pl.yap.ypp.P.prolog:
|
|
@ -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)(struct vfs *,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)(struct vfs *,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;
|
||||||
|
@ -50,23 +50,10 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef YAP_H
|
|
||||||
|
|
||||||
/* The YAP main types */
|
/* The YAP main types */
|
||||||
#include "YapTerm.h"
|
#include "YapTerm.h"
|
||||||
|
|
||||||
/**
|
|
||||||
This term can never be constructed as a valid term, so it is
|
|
||||||
used as a "BAD" term
|
|
||||||
*/
|
|
||||||
#define TermZERO ((Term)0)
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
#include "YapConfig.h"
|
|
||||||
|
|
||||||
#endif /* YAP_H */
|
|
||||||
|
|
||||||
#if HAVE_STDINT_H
|
#if HAVE_STDINT_H
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#endif
|
#endif
|
||||||
@ -74,21 +61,6 @@
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* truth-values */
|
|
||||||
/* stdbool defines the booleam type, bool,
|
|
||||||
and the constants false and true */
|
|
||||||
#if HAVE_STDBOOL_H
|
|
||||||
#include <stdbool.h>
|
|
||||||
#else
|
|
||||||
#ifndef true
|
|
||||||
typedef int _Bool;
|
|
||||||
#define bool _Bool;
|
|
||||||
|
|
||||||
#define false 0
|
|
||||||
#define true 1
|
|
||||||
#endif
|
|
||||||
#endif /* HAVE_STDBOOL_H */
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
FALSE and TRUE are the pre-standard versions,
|
FALSE and TRUE are the pre-standard versions,
|
||||||
still widely used.
|
still widely used.
|
||||||
@ -103,79 +75,26 @@ typedef int _Bool;
|
|||||||
typedef bool YAP_Bool;
|
typedef bool YAP_Bool;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef YAP_H
|
|
||||||
|
|
||||||
/* if Yap.h is available, just reexport */
|
/**
|
||||||
|
This term can never be constructed as a valid term, so it is
|
||||||
|
used as a "BAD" term
|
||||||
|
*/
|
||||||
|
#define TermZERO ((Term)0)
|
||||||
|
|
||||||
#define YAP_CELL CELL
|
|
||||||
|
|
||||||
#define YAP_Term Term
|
#include "YapConfig.h"
|
||||||
|
|
||||||
#define YAP_Arity arity_t
|
|
||||||
|
|
||||||
#define YAP_Module Term
|
typedef void *YAP_PredEntryPtr;
|
||||||
|
|
||||||
#define YAP_Functor Functor
|
|
||||||
|
|
||||||
#define YAP_Atom Atom
|
|
||||||
|
|
||||||
#define YAP_Int Int
|
|
||||||
|
|
||||||
#define YAP_UInt UInt
|
|
||||||
|
|
||||||
#define YAP_Float Float
|
|
||||||
|
|
||||||
#define YAP_handle_t yhandle_t
|
|
||||||
|
|
||||||
#define YAP_PredEntryPtr struct pred_entry *
|
|
||||||
|
|
||||||
#define YAP_UserCPred CPredicate
|
|
||||||
|
|
||||||
#define YAP_agc_hook Agc_hook
|
|
||||||
|
|
||||||
#define YAP_encoding_t encoding_t
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
/* Type definitions */
|
|
||||||
#if defined(PRIdPTR)
|
|
||||||
typedef uintptr_t YAP_UInt;
|
|
||||||
typedef intptr_t YAP_Int;
|
|
||||||
#elif _WIN64
|
|
||||||
typedef int64_t YAP_Int;
|
|
||||||
typedef uint64_t YAP_UInt;
|
|
||||||
#elif _WIN32
|
|
||||||
typedef int32_t YAP_Int;
|
|
||||||
typedef uint32_t YAP_UInt;
|
|
||||||
#else
|
|
||||||
typedef long int YAP_Int;
|
|
||||||
typedef unsigned long int YAP_UInt;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef YAP_UInt YAP_CELL;
|
|
||||||
|
|
||||||
typedef YAP_CELL YAP_Term;
|
|
||||||
|
|
||||||
typedef size_t YAP_Arity;
|
typedef size_t YAP_Arity;
|
||||||
|
|
||||||
typedef YAP_Term YAP_Module;
|
typedef YAP_Term YAP_Module;
|
||||||
|
|
||||||
typedef struct FunctorEntry *YAP_Functor;
|
|
||||||
|
|
||||||
typedef struct AtomEntry *YAP_Atom;
|
|
||||||
|
|
||||||
typedef double YAP_Float;
|
|
||||||
|
|
||||||
#ifndef TRUE
|
|
||||||
#define TRUE 1
|
|
||||||
#endif
|
|
||||||
#ifndef FALSE
|
|
||||||
#define FALSE 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef YAP_Int YAP_handle_t;
|
typedef YAP_Int YAP_handle_t;
|
||||||
|
|
||||||
typedef struct YAP_pred_entry *YAP_PredEntryPtr;
|
typedef void *YAP_PredEntryPtr;
|
||||||
|
|
||||||
typedef YAP_Bool (*YAP_UserCPred)(void);
|
typedef YAP_Bool (*YAP_UserCPred)(void);
|
||||||
|
|
||||||
@ -187,6 +106,9 @@ typedef int (*YAP_agc_hook)(void *_Atom);
|
|||||||
|
|
||||||
typedef encoding_t YAP_encoding_t;
|
typedef encoding_t YAP_encoding_t;
|
||||||
|
|
||||||
|
#if __ANDROID__
|
||||||
|
#include <android/asset_manager.h>
|
||||||
|
#include <android/native_activity.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef struct YAP_thread_attr_struct {
|
typedef struct YAP_thread_attr_struct {
|
||||||
@ -210,7 +132,8 @@ typedef enum {
|
|||||||
YAP_BOOT_PL = 0x0030,
|
YAP_BOOT_PL = 0x0030,
|
||||||
YAP_QLY = 0x0040,
|
YAP_QLY = 0x0040,
|
||||||
YAP_EXE = 0x0080,
|
YAP_EXE = 0x0080,
|
||||||
YAP_FOUND_BOOT_ERROR = 0x0100
|
YAP_FOUND_BOOT_ERROR = 0x0100,
|
||||||
|
YAP_DIR = 0x0200
|
||||||
} YAP_file_type_t;
|
} YAP_file_type_t;
|
||||||
|
|
||||||
#define YAP_ANY_FILE (0x00ff)
|
#define YAP_ANY_FILE (0x00ff)
|
||||||
@ -252,9 +175,15 @@ typedef enum {
|
|||||||
#define YAP_RECONSULT_MODE 1
|
#define YAP_RECONSULT_MODE 1
|
||||||
#define YAP_BOOT_MODE 2
|
#define YAP_BOOT_MODE 2
|
||||||
|
|
||||||
|
|
||||||
|
X_API YAP_file_type_t Yap_InitDefaults(void *init_args, char saved_state[],
|
||||||
|
int Argc, char *Argv[]);
|
||||||
|
|
||||||
typedef struct yap_boot_params {
|
typedef struct yap_boot_params {
|
||||||
//> boot type as suggested by the user
|
//> boot type as suggested by the user
|
||||||
YAP_file_type_t boot_file_type;
|
YAP_file_type_t boot_file_type;
|
||||||
|
//> bootstrapping mode: YAP is not properly installed
|
||||||
|
bool bootstrapping;
|
||||||
//> if NON-NULL, path where we can find the saved state
|
//> if NON-NULL, path where we can find the saved state
|
||||||
const char *SavedState;
|
const char *SavedState;
|
||||||
//> if NON-0, minimal size for Heap or Code Area
|
//> if NON-0, minimal size for Heap or Code Area
|
||||||
@ -275,10 +204,16 @@ typedef struct yap_boot_params {
|
|||||||
size_t AttsSize;
|
size_t AttsSize;
|
||||||
//> if NON-0, maximal size for AttributeVarStack
|
//> if NON-0, maximal size for AttributeVarStack
|
||||||
size_t MaxAttsSize;
|
size_t MaxAttsSize;
|
||||||
|
//> if NON-NULL, value for YAPROOTDIR
|
||||||
|
const char *YapRootDir;
|
||||||
//> if NON-NULL, value for YAPLIBDIR
|
//> if NON-NULL, value for YAPLIBDIR
|
||||||
const char *YapLibDir;
|
const char *YapLibDir;
|
||||||
//> if NON-NULL, value for YAPSSHAREDIR, that is, default value for libraries
|
//> if NON-NULL, value for YAPSHAREDIR, that is, default value for libraries
|
||||||
const char *YapShareDir;
|
const char *YapShareDir;
|
||||||
|
//> if NON-NULL, value for YAPDLLDIR, that is, default value for libraries
|
||||||
|
const char *YapDLLDir;
|
||||||
|
//> if NON-NULL, value for YAPPLDIR, that is, default value for libraries
|
||||||
|
const char *YapPlDir;
|
||||||
//> if NON-NULL, name for a Prolog file to use when booting
|
//> if NON-NULL, name for a Prolog file to use when booting
|
||||||
const char *YapPrologBootFile;
|
const char *YapPrologBootFile;
|
||||||
//> if NON-NULL, name for a Prolog file to use when initializing
|
//> if NON-NULL, name for a Prolog file to use when initializing
|
||||||
@ -322,6 +257,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];
|
||||||
@ -344,11 +283,6 @@ typedef struct yap_boot_params {
|
|||||||
char *ErrorCause;
|
char *ErrorCause;
|
||||||
} YAP_init_args;
|
} YAP_init_args;
|
||||||
|
|
||||||
#ifdef YAP_H
|
|
||||||
YAP_file_type_t Yap_InitDefaults(YAP_init_args *init_args, char saved_state[],
|
|
||||||
int Argc, char *Argv[]);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* this should be opaque to the user */
|
/* this should be opaque to the user */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned long b; //> choice-point at entry
|
unsigned long b; //> choice-point at entry
|
||||||
|
@ -176,51 +176,51 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
|
|||||||
/// go back t
|
/// go back t
|
||||||
} yap_error_stage_t;
|
} yap_error_stage_t;
|
||||||
|
|
||||||
/// a Prolo goal that caused a bug
|
/// a Prolog goal that caused a bug
|
||||||
|
|
||||||
typedef struct error_prolog_source {
|
typedef struct yap_error_prolog_source {
|
||||||
YAP_Int prologPredCl;
|
intptr_t prologPredCl;
|
||||||
YAP_UInt prologPredLine;
|
uintptr_t prologPredLine;
|
||||||
YAP_UInt prologPredFirstLine;
|
uintptr_t prologPredFirstLine;
|
||||||
YAP_UInt prologPredLastLine;
|
uintptr_t prologPredLastLine;
|
||||||
YAP_Atom prologPredName;
|
const char * prologPredName;
|
||||||
YAP_UInt prologPredArity;
|
uintptr_t prologPredArity;
|
||||||
YAP_Term prologPredModule;
|
const char * prologPredModule;
|
||||||
YAP_Atom prologPredFile;
|
const char * prologPredFile;
|
||||||
struct DB_TERM *errorGoal;
|
void *errorGoal;
|
||||||
struct error_prolog_source *errorParent;
|
struct error_prolog_source *errorParent;
|
||||||
} error_prolog_source_t;
|
} yap_error_prolog_source_t;
|
||||||
|
|
||||||
/// all we need to know about an error/throw
|
/// all we need to know about an error/throw
|
||||||
typedef struct yap_error_descriptor {
|
typedef struct s_yap_error_descriptor {
|
||||||
enum yap_error_status status;
|
enum yap_error_status status;
|
||||||
yap_error_class_number errorClass;
|
yap_error_class_number errorClass;
|
||||||
YAP_Atom errorAsText;
|
const char * errorAsText;
|
||||||
YAP_Atom classAsText;
|
const char * classAsText;
|
||||||
yap_error_number errorNo;
|
yap_error_number errorNo;
|
||||||
YAP_Int errorLine;
|
intptr_t errorLine;
|
||||||
const char *errorFunction;
|
const char *errorFunction;
|
||||||
const char *errorFile;
|
const char *errorFile;
|
||||||
// struct error_prolog_source *errorSource;
|
// struct error_prolog_source *errorSource;
|
||||||
YAP_Int prologPredCl;
|
intptr_t prologPredCl;
|
||||||
YAP_UInt prologPredLine;
|
uintptr_t prologPredLine;
|
||||||
YAP_UInt prologPredFirstLine;
|
uintptr_t prologPredFirstLine;
|
||||||
YAP_UInt prologPredLastLine;
|
uintptr_t prologPredLastLine;
|
||||||
YAP_Atom prologPredName;
|
const char * prologPredName;
|
||||||
YAP_UInt prologPredArity;
|
uintptr_t prologPredArity;
|
||||||
YAP_Term prologPredModule;
|
const char * prologPredModule;
|
||||||
YAP_Atom prologPredFile;
|
const char * prologPredFile;
|
||||||
YAP_UInt prologParserLine;
|
uintptr_t prologParserLine;
|
||||||
YAP_UInt prologParserFirstLine;
|
uintptr_t prologParserFirstLine;
|
||||||
YAP_UInt prologParserLastLine;
|
uintptr_t prologParserLastLine;
|
||||||
YAP_Atom prologParserName;
|
const char * prologParserName;
|
||||||
YAP_Atom prologParserFile;
|
const char * prologParserFile;
|
||||||
YAP_Bool prologConsulting;
|
bool prologConsulting;
|
||||||
struct DB_TERM *errorTerm;
|
void *errorTerm;
|
||||||
YAP_Term rawErrorTerm, rawExtraErrorTerm;
|
uintptr_t rawErrorTerm, rawExtraErrorTerm;
|
||||||
char *errorMsg;
|
char *errorMsg;
|
||||||
size_t errorMsgLen;
|
size_t errorMsgLen;
|
||||||
struct yap_error_descriptor *top_error;
|
struct s_yap_error_descriptor *top_error;
|
||||||
} yap_error_descriptor_t;
|
} yap_error_descriptor_t;
|
||||||
|
|
||||||
/// compatibility with existing code..
|
/// compatibility with existing code..
|
||||||
|
@ -268,18 +268,19 @@ extern X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred,
|
|||||||
extern X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred,
|
extern X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred,
|
||||||
YAP_UserCPred, YAP_Arity, YAP_Arity);
|
YAP_UserCPred, YAP_Arity, YAP_Arity);
|
||||||
|
|
||||||
/* YAP_Int YAP_ListLength(YAP_Term t) */
|
|
||||||
extern X_API YAP_Int YAP_ListLength(YAP_Term);
|
|
||||||
|
|
||||||
extern X_API size_t YAP_UTF8_TextLength(YAP_Term t);
|
|
||||||
|
|
||||||
/* void UserBackCPredicate(char *name, int *init(), int *cont(), int *cut(),
|
/* void UserBackCPredicate(char *name, int *init(), int *cont(), int *cut(),
|
||||||
int
|
int
|
||||||
arity, int extra) */
|
arity, int extra) */
|
||||||
extern X_API void YAP_UserBackCutCPredicate(const char *, YAP_UserCPred,
|
extern X_API void YAP_UserBackCutCPredicate(const char *name, YAP_UserCPred,
|
||||||
YAP_UserCPred, YAP_UserCPred,
|
YAP_UserCPred, YAP_UserCPred,
|
||||||
YAP_Arity, YAP_Arity);
|
YAP_Arity, YAP_Arity);
|
||||||
|
|
||||||
|
/* YAP_Int YAP_ListLength(YAP_Term t) */
|
||||||
|
extern X_API YAP_Int YAP_ListLength(YAP_Term);
|
||||||
|
|
||||||
|
extern X_API size_t YAP_UTF8_TextLength(YAP_Term t);
|
||||||
|
|
||||||
/* void CallProlog(YAP_Term t) */
|
/* void CallProlog(YAP_Term t) */
|
||||||
extern X_API YAP_Int YAP_CallProlog(YAP_Term t);
|
extern X_API YAP_Int YAP_CallProlog(YAP_Term t);
|
||||||
|
|
||||||
@ -399,7 +400,7 @@ extern X_API YAP_Term YAP_ReadFromStream(int s);
|
|||||||
|
|
||||||
/// read a Prolog clause from a Prolog opened stream $s$. Similar to
|
/// read a Prolog clause from a Prolog opened stream $s$. Similar to
|
||||||
/// YAP_ReadFromStream() but takes /// default options from read_clause/3.
|
/// YAP_ReadFromStream() but takes /// default options from read_clause/3.
|
||||||
extern X_API YAP_Term YAP_ReadFromStream(int s);
|
extern X_API YAP_Term YAP_ReadClauseFromStream(int s);
|
||||||
|
|
||||||
extern X_API void YAP_Write(YAP_Term t, FILE *s, int);
|
extern X_API void YAP_Write(YAP_Term t, FILE *s, int);
|
||||||
|
|
||||||
@ -474,6 +475,16 @@ extern X_API void YAP_SetOutputMessage(void);
|
|||||||
|
|
||||||
extern X_API int YAP_StreamToFileNo(YAP_Term);
|
extern X_API int YAP_StreamToFileNo(YAP_Term);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility routine to Obtain a pointer to the YAP representation of a stream.
|
||||||
|
*
|
||||||
|
* @param sno Stream Id
|
||||||
|
* @return data structure for stream
|
||||||
|
*/
|
||||||
|
extern X_API void *YAP_RepStreamFromId(int sno);
|
||||||
|
|
||||||
|
|
||||||
extern X_API void YAP_CloseAllOpenStreams(void);
|
extern X_API void YAP_CloseAllOpenStreams(void);
|
||||||
|
|
||||||
extern X_API void YAP_FlushAllStreams(void);
|
extern X_API void YAP_FlushAllStreams(void);
|
||||||
|
@ -136,9 +136,9 @@ FILE *open_memstream(char **buf, size_t *len);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
|
//extern FILE * fmemopen(void *buf, size_t size, const char *mode);
|
||||||
#undef HAVE_FMEMOPEN
|
#define HAVE_FMEMOPEN 1
|
||||||
#undef HAVE_OPEN_MEMSTREAM
|
#define HAVE_OPEN_MEMSTREAM 1
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAVE_FMEMOPEN
|
#if HAVE_FMEMOPEN
|
||||||
|
@ -17,9 +17,6 @@
|
|||||||
#include "YapTermConfig.h"
|
#include "YapTermConfig.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
typedef void *Functor;
|
|
||||||
typedef void *Atom;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAVE_STDINT_H
|
#if HAVE_STDINT_H
|
||||||
@ -29,6 +26,22 @@ typedef void *Atom;
|
|||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* truth-values */
|
||||||
|
/* stdbool defines the booleam type, bool,
|
||||||
|
and the constants false and true */
|
||||||
|
#if HAVE_STDBOOL_H
|
||||||
|
#include <stdbool.h>
|
||||||
|
#else
|
||||||
|
#ifndef true
|
||||||
|
typedef int _Bool;
|
||||||
|
#define bool _Bool;
|
||||||
|
|
||||||
|
#define false 0
|
||||||
|
#define true 1
|
||||||
|
#endif
|
||||||
|
#endif /* HAVE_STDBOOL_H */
|
||||||
|
|
||||||
|
|
||||||
#define ALIGN_BY_TYPE(X, TYPE) \
|
#define ALIGN_BY_TYPE(X, TYPE) \
|
||||||
(((CELL)(X) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1))
|
(((CELL)(X) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1))
|
||||||
|
|
||||||
@ -45,59 +58,98 @@ typedef void *Atom;
|
|||||||
|
|
||||||
#if defined(PRIdPTR)
|
#if defined(PRIdPTR)
|
||||||
|
|
||||||
typedef intptr_t Int;
|
typedef intptr_t YAP_Int;
|
||||||
typedef uintptr_t UInt;
|
typedef uintptr_t YAP_UInt;
|
||||||
|
|
||||||
#elif defined(_WIN64)
|
#elif defined(_WIN64)
|
||||||
|
|
||||||
|
|
||||||
typedef int64_t Int;
|
typedef int64_t YAP_Int;
|
||||||
typedef uint64_t UInt;
|
typedef uint64_t YAP_UInt;
|
||||||
|
|
||||||
#elif defined(_WIN32)
|
#elif defined(_WIN32)
|
||||||
|
|
||||||
typedef int32_t Int;
|
typedef int32_t YAP_Int;
|
||||||
typedef uint32_t UInt;
|
typedef uint32_t YAP_UInt;
|
||||||
|
|
||||||
#elif SIZEOF_LONG_INT == SIZEOF_INT_P
|
#elif SIZEOF_LONG_INT == SIZEOF_INT_P
|
||||||
|
|
||||||
typedef long int Int;
|
typedef long int YAP_Int;
|
||||||
typedef unsigned long int UInt;
|
typedef unsigned long int YAP_UInt;
|
||||||
|
|
||||||
#elif SIZEOF_INT == SIZEOF_INT_P
|
#elif SIZEOF_INT == SIZEOF_INT_P
|
||||||
|
|
||||||
typedef int Int;
|
typedef int YAP_Int;
|
||||||
typedef unsigned int UInt;
|
typedef unsigned int YAP_UInt;
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#error Yap require integer types of the same size as a pointer
|
#error Yap require integer types of the same size as a pointer
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* */ typedef short int Short;
|
/* */ typedef short int YAP_Short;
|
||||||
/* */ typedef unsigned short int UShort;
|
/* */ typedef unsigned short int YAP_UShort;
|
||||||
|
|
||||||
typedef UInt CELL;
|
typedef YAP_UInt YAP_CELL;
|
||||||
|
typedef YAP_UInt YAP_Term;
|
||||||
|
|
||||||
|
/* Type definitions */
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef TRUE
|
||||||
|
#define TRUE true
|
||||||
|
#endif
|
||||||
|
#ifndef FALSE
|
||||||
|
#endif
|
||||||
|
|
||||||
|
typedef bool YAP_Bool;
|
||||||
|
#define FALSE false
|
||||||
|
|
||||||
|
typedef YAP_Int YAP_handle_t;
|
||||||
|
|
||||||
|
|
||||||
|
typedef double YAP_Float;
|
||||||
|
|
||||||
|
typedef void *YAP_Atom;
|
||||||
|
|
||||||
|
typedef void *YAP_Functor;
|
||||||
|
|
||||||
|
#ifdef YAP_H
|
||||||
|
|
||||||
|
typedef YAP_Int Int;
|
||||||
|
typedef YAP_UInt UInt;
|
||||||
|
typedef YAP_Short Short;
|
||||||
|
typedef YAP_UShort UShort;
|
||||||
|
|
||||||
typedef uint16_t BITS16;
|
typedef uint16_t BITS16;
|
||||||
typedef int16_t SBITS16;
|
typedef int16_t SBITS16;
|
||||||
typedef uint32_t BITS32;
|
typedef uint32_t BITS32;
|
||||||
|
|
||||||
|
typedef YAP_CELL CELL;
|
||||||
|
|
||||||
|
typedef YAP_Term Term;
|
||||||
|
|
||||||
#define WordSize sizeof(BITS16)
|
#define WordSize sizeof(BITS16)
|
||||||
#define CellSize sizeof(CELL)
|
#define CellSize sizeof(CELL)
|
||||||
#define SmallSize sizeof(SMALLUNSGN)
|
#define SmallSize sizeof(SMALLUNSGN)
|
||||||
|
|
||||||
|
typedef YAP_Int Int;
|
||||||
|
typedef YAP_Float Float;
|
||||||
|
typedef YAP_handle_t yhandle_t;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "YapError.h"
|
||||||
|
|
||||||
|
#include "../os/encoding.h"
|
||||||
|
|
||||||
|
typedef encoding_t YAP_encoding_t;
|
||||||
|
|
||||||
#include "YapFormat.h"
|
#include "YapFormat.h"
|
||||||
|
|
||||||
/*************************************************************************************************
|
/*************************************************************************************************
|
||||||
type casting macros
|
type casting macros
|
||||||
*************************************************************************************************/
|
*************************************************************************************************/
|
||||||
|
|
||||||
typedef UInt Term;
|
|
||||||
|
|
||||||
typedef Int yhandle_t;
|
|
||||||
|
|
||||||
typedef double Float;
|
|
||||||
|
|
||||||
#if SIZEOF_INT < SIZEOF_INT_P
|
#if SIZEOF_INT < SIZEOF_INT_P
|
||||||
#define SHORT_INTS 1
|
#define SHORT_INTS 1
|
||||||
#else
|
#else
|
@ -9,6 +9,7 @@ requirements:
|
|||||||
- cmake
|
- cmake
|
||||||
- swig
|
- swig
|
||||||
- gmp
|
- gmp
|
||||||
|
- ninja
|
||||||
- readline
|
- readline
|
||||||
- python
|
- python
|
||||||
- r
|
- r
|
||||||
@ -16,8 +17,7 @@ requirements:
|
|||||||
- pkgconfig
|
- pkgconfig
|
||||||
- make
|
- make
|
||||||
run:
|
run:
|
||||||
- python
|
- jupyterlab
|
||||||
- pythonlab
|
|
||||||
- readline
|
- readline
|
||||||
- gmp
|
- gmp
|
||||||
- r
|
- r
|
||||||
|
@ -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()
|
@ -3142,7 +3142,7 @@ term_t Yap_CvtTerm(term_t ts) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
char *PL_cwd(char *cwd, size_t cwdlen) {
|
char *PL_cwd(char *cwd, size_t cwdlen) {
|
||||||
return (char *)Yap_getcwd((const char *)cwd, cwdlen);
|
return (char *)Yap_getcwd(cwd, cwdlen);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -78,9 +78,9 @@ if (MPI_C_FOUND)
|
|||||||
add_definitions (-DHAVE_MPI_H=1)
|
add_definitions (-DHAVE_MPI_H=1)
|
||||||
|
|
||||||
install(TARGETS yap_mpi
|
install(TARGETS yap_mpi
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls}
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
endif (MPI_C_FOUND)
|
endif (MPI_C_FOUND)
|
||||||
|
@ -15,8 +15,8 @@ if (MATLAB_FOUND)
|
|||||||
target_link_libraries(matlab libYap $(MATLAB_LIBRARIES) )
|
target_link_libraries(matlab libYap $(MATLAB_LIBRARIES) )
|
||||||
|
|
||||||
install(TARGETS matlab
|
install(TARGETS matlab
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls} )
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} )
|
||||||
|
|
||||||
endif (MATLAB_FOUND)
|
endif (MATLAB_FOUND)
|
||||||
|
|
||||||
|
@ -6,8 +6,8 @@ target_link_libraries(matrix libYap)
|
|||||||
set_target_properties (matrix PROPERTIES PREFIX "")
|
set_target_properties (matrix PROPERTIES PREFIX "")
|
||||||
|
|
||||||
install(TARGETS matrix
|
install(TARGETS matrix
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls}
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -10,5 +10,5 @@ set_target_properties (yap_random PROPERTIES PREFIX "")
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
MY_install(TARGETS yap_random
|
MY_install(TARGETS yap_random
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls} )
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} )
|
||||||
|
@ -26,6 +26,6 @@ TARGET_INCLUDE_DIRECTORIES (regexp PUBLIC BEFORE
|
|||||||
${CMAKE_TOP_SOURCE_DIR}/include;${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR} )
|
${CMAKE_TOP_SOURCE_DIR}/include;${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR} )
|
||||||
|
|
||||||
install(TARGETS regexp
|
install(TARGETS regexp
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls} )
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} )
|
||||||
|
@ -11,6 +11,6 @@ target_link_libraries(yap_rl libYap)
|
|||||||
set_target_properties (yap_rl PROPERTIES PREFIX "")
|
set_target_properties (yap_rl PROPERTIES PREFIX "")
|
||||||
|
|
||||||
install(TARGETS yap_rl
|
install(TARGETS yap_rl
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls} )
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} )
|
||||||
|
|
||||||
|
@ -39,8 +39,8 @@ set_target_properties (sys PROPERTIES PREFIX "")
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
MY_install(TARGETS sys
|
MY_install(TARGETS sys
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls} )
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} )
|
||||||
|
|
||||||
configure_file ("sys_config.h.cmake" "sys_config.h" )
|
configure_file ("sys_config.h.cmake" "sys_config.h" )
|
||||||
|
@ -13,9 +13,9 @@ target_link_libraries(tries libYap)
|
|||||||
set_target_properties (tries PROPERTIES PREFIX "")
|
set_target_properties (tries PROPERTIES PREFIX "")
|
||||||
|
|
||||||
install(TARGETS tries
|
install(TARGETS tries
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls})
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR})
|
||||||
|
|
||||||
|
|
||||||
set ( ITRIES_SOURCES
|
set ( ITRIES_SOURCES
|
||||||
@ -34,7 +34,7 @@ target_link_libraries(itries libYap)
|
|||||||
set_target_properties (itries PROPERTIES PREFIX "")
|
set_target_properties (itries PROPERTIES PREFIX "")
|
||||||
|
|
||||||
install(TARGETS itries
|
install(TARGETS itries
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls} )
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} )
|
||||||
|
|
||||||
|
@ -7,7 +7,10 @@ set (YAPOS_SOURCES
|
|||||||
console.c
|
console.c
|
||||||
files.c
|
files.c
|
||||||
fmem.c
|
fmem.c
|
||||||
fmemopen.c
|
# fmemopen.c
|
||||||
|
#android/fmemopen.c
|
||||||
|
# android/fopencookie.c
|
||||||
|
# android/open_memstream.c
|
||||||
format.c
|
format.c
|
||||||
iopreds.c
|
iopreds.c
|
||||||
mem.c
|
mem.c
|
||||||
|
190
os/assets.c
190
os/assets.c
@ -33,136 +33,109 @@ 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__
|
||||||
|
|
||||||
static AAssetManager * getMgr(struct vfs *me)
|
#include <android/asset_manager.h>
|
||||||
{
|
#include <android/native_activity.h>
|
||||||
return me->priv[0].mgr;
|
|
||||||
|
AAssetManager *Yap_assetManager;
|
||||||
|
|
||||||
|
jboolean
|
||||||
|
Java_pt_up_yap_app_YAPDroid_setAssetManager(JNIEnv *env, jclass clazz, jobject assetManager) {
|
||||||
|
Yap_assetManager = AAssetManager_fromJava(env, assetManager);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void *
|
||||||
void
|
open_asset__(VFS_t *me, int sno, const char *fname, const char *io_mode) {
|
||||||
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)
|
|
||||||
{
|
|
||||||
AAssetManager *mgr;
|
|
||||||
int mode;
|
int mode;
|
||||||
const void *buf;
|
const void *buf;
|
||||||
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'))
|
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);
|
fname += strlen(me->prefix) + 1;
|
||||||
|
AAsset *a = AAssetManager_open(Yap_assetManager, fname, mode);
|
||||||
|
if (!a)
|
||||||
|
return NULL;
|
||||||
// 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;
|
||||||
if ((fd = AAsset_openFileDescriptor64(a, &sz0, &sz)) >= 0) {
|
StreamDesc *st = GLOBAL_Stream + sno;
|
||||||
// can use it as red-only file
|
if ((buf = AAsset_getBuffer(a))) {
|
||||||
st->file = fdopen( fd, "r");
|
|
||||||
st->vfs = me;
|
|
||||||
st->vfs_handle = a;
|
|
||||||
return true;
|
|
||||||
} 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);
|
if (rc) AAsset_close(a);
|
||||||
return rc;
|
st->vfs = NULL;
|
||||||
}
|
st->vfs_handle = NULL;
|
||||||
|
st->status = InMemory_Stream_f|Seekable_Stream_f|Input_Stream_f;
|
||||||
|
return st;
|
||||||
|
} else if ((fd = AAsset_openFileDescriptor64(a, &sz0, &sz)) >= 0) {
|
||||||
|
// can use it as read-only file
|
||||||
|
st->file = fdopen(fd, "r");
|
||||||
|
st->vfs = NULL;
|
||||||
|
st->vfs_handle = NULL;
|
||||||
|
st->status = Seekable_Stream_f|Input_Stream_f;
|
||||||
|
return st;
|
||||||
|
} else {
|
||||||
// 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;
|
st->status = Input_Stream_f;
|
||||||
|
return a;
|
||||||
}
|
}
|
||||||
if (me->next) {
|
|
||||||
return me->next->open(me->next, st, fname, io_mode);
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
close_asset(struct stream_desc *st)
|
close_asset(int sno) {
|
||||||
{
|
AAsset_close(GLOBAL_Stream[sno].vfs_handle);
|
||||||
AAsset_close(st->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(GLOBAL_Stream[sno].vfs_handle, offset, whence);
|
||||||
return AAsset_seek64(st->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) {
|
||||||
{
|
dirName += strlen(me->prefix) + 1;
|
||||||
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) {
|
||||||
{
|
return AAssetDir_getNextFileName((AAssetDir *) dirHandle);
|
||||||
return AAssetDir_getNextFileName ((AAssetDir *)dirHandle);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool closedir_a(void *dirHandle)
|
static bool closedir_a(void *dirHandle) {
|
||||||
{
|
AAssetDir_close((AAssetDir *) dirHandle);
|
||||||
AAssetDir_close ((AAssetDir *)dirHandle);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 stat bf;
|
||||||
struct stat64 bf;
|
fname += strlen(me->prefix) + 1;
|
||||||
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;
|
||||||
out->st_gid = bf.st_gid;
|
out->st_gid = bf.st_gid;
|
||||||
memcpy(&out->st_atimespec, (const void *)&out->st_atimespec, sizeof(struct timespec));
|
memcpy(&out->st_atimespec, (const void *) &out->st_atimespec, sizeof(struct timespec));
|
||||||
memcpy(&out->st_mtimespec,(const void *) &out->st_mtimespec, sizeof(struct timespec));
|
memcpy(&out->st_mtimespec, (const void *) &out->st_mtimespec, sizeof(struct timespec));
|
||||||
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,23 +144,25 @@ 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;
|
||||||
|
dirName += strlen(me->prefix) + 1;
|
||||||
// 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);
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "isdir %s <%p>", dirName, d);
|
||||||
AAssetDir_close(d);
|
AAssetDir_close(d);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static
|
static
|
||||||
bool exists_a(struct vfs *me, const char *dirName)
|
bool exists_a(VFS_t *me, const char *dirName) {
|
||||||
{
|
dirName += strlen(me->prefix) + 1;
|
||||||
// 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);
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "exists %s <%p>", dirName, d);
|
||||||
if (d == NULL)
|
if (d == NULL)
|
||||||
return false;
|
return false;
|
||||||
AAsset_close(d);
|
AAsset_close(d);
|
||||||
@ -195,35 +170,38 @@ bool exists_a(struct vfs *me, const char *dirName)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static bool set_cwd (struct vfs *me, const char *dirName) {
|
extern char virtual_cwd[YAP_FILENAME_MAX + 1];
|
||||||
|
|
||||||
|
static bool set_cwd(VFS_t *me, const char *dirName) {
|
||||||
|
|
||||||
chdir("/assets");
|
chdir("/assets");
|
||||||
if (me->virtual_cwd)
|
strcpy(virtual_cwd, dirName);
|
||||||
free(me->virtual_cwd);
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid",
|
||||||
me->virtual_cwd = malloc( sizeof(dirName) + 1 );
|
"chdir %s", virtual_cwd);
|
||||||
return me!= NULL;
|
Yap_do_low_level_trace=1;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* create a new alias arg for stream sno */
|
|
||||||
VFS_t *
|
VFS_t *
|
||||||
Yap_InitAssetManager(void)
|
Yap_InitAssetManager(void) {
|
||||||
{
|
|
||||||
|
|
||||||
#if __ANDROID__O
|
#if __ANDROID__
|
||||||
VFS_t *me;
|
VFS_t *me;
|
||||||
|
|
||||||
/* init standard VFS */
|
/* init standard VFS */
|
||||||
me = (VFS_t *)Yap_AllocCodeSpace(sizeof(struct vfs));
|
me = (VFS_t *) Yap_AllocCodeSpace(sizeof(struct vfs));
|
||||||
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
|
||||||
@ -236,7 +214,7 @@ Yap_InitAssetManager(void)
|
|||||||
me->parsers = NULL; /// a set of parsers that can read the stream and generate a term
|
me->parsers = NULL; /// a set of parsers that can read the stream and generate a term
|
||||||
me->writers = NULL;
|
me->writers = NULL;
|
||||||
LOCK(BGL);
|
LOCK(BGL);
|
||||||
me-> next = GLOBAL_VFS;
|
me->next = GLOBAL_VFS;
|
||||||
GLOBAL_VFS = me;
|
GLOBAL_VFS = me;
|
||||||
return me;
|
return me;
|
||||||
UNLOCK(BGL);
|
UNLOCK(BGL);
|
||||||
|
@ -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))) {
|
||||||
|
@ -20,6 +20,11 @@
|
|||||||
#define ENCODING_H 1
|
#define ENCODING_H 1
|
||||||
|
|
||||||
#include "YapError.h"
|
#include "YapError.h"
|
||||||
|
#if HAVE_STRING_H
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
ENC_OCTET = 0, /// binary files
|
ENC_OCTET = 0, /// binary files
|
||||||
|
@ -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
|
||||||
@ -459,7 +460,7 @@ static Int exists_directory(USES_REGS1) {
|
|||||||
#if HAVE_STAT
|
#if HAVE_STAT
|
||||||
struct SYSTEM_STAT ss;
|
struct SYSTEM_STAT ss;
|
||||||
|
|
||||||
file_name = RepAtom(AtomOfTerm(tname))->StrOfAE;
|
file_name = Yap_VF(RepAtom(AtomOfTerm(tname))->StrOfAE);
|
||||||
if (SYSTEM_STAT(file_name, &ss) != 0) {
|
if (SYSTEM_STAT(file_name, &ss) != 0) {
|
||||||
/* ignore errors while checking a file */
|
/* ignore errors while checking a file */
|
||||||
return false;
|
return false;
|
||||||
@ -482,7 +483,7 @@ static Int is_absolute_file_name(USES_REGS1) { /* file_base_name(Stream,N) */
|
|||||||
int l = push_text_stack();
|
int l = push_text_stack();
|
||||||
const char *buf = Yap_TextTermToText(t PASS_REGS);
|
const char *buf = Yap_TextTermToText(t PASS_REGS);
|
||||||
if (buf) {
|
if (buf) {
|
||||||
rc = Yap_IsAbsolutePath(buf);
|
rc = Yap_IsAbsolutePath(buf, true);
|
||||||
} else {
|
} else {
|
||||||
at = AtomOfTerm(t);
|
at = AtomOfTerm(t);
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
|
22
os/fmem.c
22
os/fmem.c
@ -114,16 +114,18 @@ bool fill_pads(int sno, int sno0, int total, format_info *fg USES_REGS)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, encoding_t enc,
|
bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf,
|
||||||
size_t nchars) {
|
size_t nchars USES_REGS) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
|
||||||
// like any file stream.
|
// like any file stream.
|
||||||
st->file = f = fmemopen((void *)buf, nchars, "r");
|
st->file = f = fmemopen((char *)buf, nchars, "r");
|
||||||
st->status = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f;
|
st->status = Input_Stream_f | Seekable_Stream_f | InMemory_Stream_f;
|
||||||
st->vfs = NULL;
|
st->vfs = NULL;
|
||||||
st->encoding = enc;
|
st->encoding = LOCAL_encoding;
|
||||||
Yap_DefaultStreamOps(st);
|
Yap_DefaultStreamOps(st);
|
||||||
|
st->linecount = 0;
|
||||||
|
st->linepos = st->charcount = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,9 +200,7 @@ int Yap_open_buf_write_stream(encoding_t enc, memBufSource src) {
|
|||||||
// setbuf(st->file, NULL);
|
// setbuf(st->file, NULL);
|
||||||
st->status |= Seekable_Stream_f;
|
st->status |= Seekable_Stream_f;
|
||||||
#else
|
#else
|
||||||
st->file = fmemopen((void *)buf, nchars, "w");
|
st->file = fmemopen((void *)st->nbuf, st->nsize, "w");
|
||||||
st->nsize = nchars;
|
|
||||||
st->nbuf = buf;
|
|
||||||
if (!st->nbuf) {
|
if (!st->nbuf) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -292,17 +292,15 @@ void Yap_MemOps(StreamDesc *st) {
|
|||||||
st->stream_getc = PlGetc;
|
st->stream_getc = PlGetc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sssno;
|
|
||||||
|
|
||||||
bool Yap_CloseMemoryStream(int sno) {
|
bool Yap_CloseMemoryStream(int sno) {
|
||||||
sssno++;
|
if ((GLOBAL_Stream[sno].status & Output_Stream_f) && GLOBAL_Stream[sno].file) {
|
||||||
// if (sssno > 1720) Yap_do_low_level_trace=1;
|
|
||||||
if ((GLOBAL_Stream[sno].status & Output_Stream_f)) {
|
|
||||||
fflush(GLOBAL_Stream[sno].file);
|
fflush(GLOBAL_Stream[sno].file);
|
||||||
fclose(GLOBAL_Stream[sno].file);
|
fclose(GLOBAL_Stream[sno].file);
|
||||||
if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f)
|
if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f)
|
||||||
free(GLOBAL_Stream[sno].nbuf);
|
free(GLOBAL_Stream[sno].nbuf);
|
||||||
} else {
|
} else {
|
||||||
|
if (GLOBAL_Stream[sno].file)
|
||||||
fclose(GLOBAL_Stream[sno].file);
|
fclose(GLOBAL_Stream[sno].file);
|
||||||
if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f)
|
if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f)
|
||||||
free(GLOBAL_Stream[sno].nbuf);
|
free(GLOBAL_Stream[sno].nbuf);
|
||||||
|
@ -1,10 +1,12 @@
|
|||||||
* Copyright (C) 2007 Eric Blake
|
/* Copyright (C) 2007 Eric Blake
|
||||||
* Permission to use, copy, modify, and distribute this software
|
* Permission to use, copy, modify, and distribute this software
|
||||||
* is freely granted, provided that this notice is preserved.
|
* is freely granted, provided that this notice is preserved.
|
||||||
*
|
*
|
||||||
* Modifications for Android written Jul 2009 by Alan Viverette
|
* Modifications for Android written Jul 2009 by Alan Viverette
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if __ANDROID__
|
||||||
|
|
||||||
/*
|
/*
|
||||||
FUNCTION
|
FUNCTION
|
||||||
<fmemopen>>---open a stream around a fixed-length string
|
<fmemopen>>---open a stream around a fixed-length string
|
||||||
@ -69,7 +71,7 @@ Supporting OS subroutines required: <<sbrk>>.
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <malloc.h>
|
#include <malloc.h>
|
||||||
#include "stdioext.h"
|
//#include "stdioext.h"
|
||||||
|
|
||||||
/* Describe details of an open memstream. */
|
/* Describe details of an open memstream. */
|
||||||
typedef struct fmemcookie {
|
typedef struct fmemcookie {
|
||||||
@ -172,13 +174,13 @@ fmemseek(void *cookie, fpos_t pos, int whence)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (c->writeonly && c->pos < c->eof)
|
if (c->writeonly && c->pos < c->eof)
|
||||||
{
|
{
|
||||||
c->buf[c->pos] = c->saved;
|
c->buf[c->pos] = c->saved;
|
||||||
c->saved = '\0';
|
c->saved = '\0';
|
||||||
}
|
}
|
||||||
c->pos = offset;
|
c->pos = offset;
|
||||||
if (c->writeonly && c->pos < c->eof)
|
if (c->writeonly && c->pos < c->eof)
|
||||||
{
|
{
|
||||||
c->saved = c->buf[c->pos];
|
c->saved = c->buf[c->pos];
|
||||||
c->buf[c->pos] = '\0';
|
c->buf[c->pos] = '\0';
|
||||||
@ -206,9 +208,9 @@ fmemopen(void *buf, size_t size, const char *mode)
|
|||||||
int flags;
|
int flags;
|
||||||
int dummy;
|
int dummy;
|
||||||
|
|
||||||
if ((flags = __sflags (mode, &dummy)) == 0)
|
if ((flags = __sflags (mode, &dummy)) == 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
if (!size || !(buf || flags & __SAPP))
|
if (!size || !(buf || flags & __SAPP))
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -225,7 +227,7 @@ fmemopen(void *buf, size_t size, const char *mode)
|
|||||||
c->max = size;
|
c->max = size;
|
||||||
/* 9 modes to worry about. */
|
/* 9 modes to worry about. */
|
||||||
/* w/a, buf or no buf: Guarantee a NUL after any file writes. */
|
/* w/a, buf or no buf: Guarantee a NUL after any file writes. */
|
||||||
c->writeonly = (flags & __SWR) != 0;
|
c->writeonly = (flags & __SWR) != 0;
|
||||||
c->saved = '\0';
|
c->saved = '\0';
|
||||||
if (!buf)
|
if (!buf)
|
||||||
{
|
{
|
||||||
@ -233,7 +235,7 @@ fmemopen(void *buf, size_t size, const char *mode)
|
|||||||
c->buf = (char *) (c + 1);
|
c->buf = (char *) (c + 1);
|
||||||
*(char *) buf = '\0';
|
*(char *) buf = '\0';
|
||||||
c->pos = c->eof = 0;
|
c->pos = c->eof = 0;
|
||||||
c->append = (flags & __SAPP) != 0;
|
c->append = (flags & __SAPP) != 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -244,7 +246,7 @@ fmemopen(void *buf, size_t size, const char *mode)
|
|||||||
/* a/a+ and buf: position and size at first NUL. */
|
/* a/a+ and buf: position and size at first NUL. */
|
||||||
buf = memchr (c->buf, '\0', size);
|
buf = memchr (c->buf, '\0', size);
|
||||||
c->eof = c->pos = buf ? (char *) buf - c->buf : size;
|
c->eof = c->pos = buf ? (char *) buf - c->buf : size;
|
||||||
if (!buf && c->writeonly)
|
if (!buf && c->writeonly)
|
||||||
/* a: guarantee a NUL within size even if no writes. */
|
/* a: guarantee a NUL within size even if no writes. */
|
||||||
c->buf[size - 1] = '\0';
|
c->buf[size - 1] = '\0';
|
||||||
c->append = 1;
|
c->append = 1;
|
||||||
@ -267,10 +269,12 @@ fmemopen(void *buf, size_t size, const char *mode)
|
|||||||
fp->_file = -1;
|
fp->_file = -1;
|
||||||
fp->_flags = flags;
|
fp->_flags = flags;
|
||||||
fp->_cookie = c;
|
fp->_cookie = c;
|
||||||
fp->_read = flags & (__SRD | __SRW) ? fmemread : NULL;
|
fp->_read = flags & (__SRD | __SRW) ? fmemread : NULL;
|
||||||
fp->_write = flags & (__SWR | __SRW) ? fmemwrite : NULL;
|
fp->_write = flags & (__SWR | __SRW) ? fmemwrite : NULL;
|
||||||
fp->_seek = fmemseek;
|
fp->_seek = fmemseek;
|
||||||
fp->_close = fmemclose;
|
fp->_close = fmemclose;
|
||||||
|
|
||||||
return fp;
|
return fp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
278
os/iopreds.c
278
os/iopreds.c
@ -39,42 +39,57 @@ static char SccsId[] = "%W% %G%";
|
|||||||
#include "Yatom.h"
|
#include "Yatom.h"
|
||||||
#include "yapio.h"
|
#include "yapio.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#if HAVE_UNISTD_H
|
#if HAVE_UNISTD_H
|
||||||
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_STDARG_H
|
#if HAVE_STDARG_H
|
||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_CTYPE_H
|
#if HAVE_CTYPE_H
|
||||||
#include <ctype.h>
|
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_WCTYPE_H
|
#if HAVE_WCTYPE_H
|
||||||
#include <wctype.h>
|
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_SYS_TIME_H
|
#if HAVE_SYS_TIME_H
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_SYS_TYPES_H
|
#if HAVE_SYS_TYPES_H
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_SYS_STAT_H
|
#ifdef HAVE_SYS_STAT_H
|
||||||
|
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_SYS_SELECT_H && !_MSC_VER && !defined(__MINGW32__)
|
#if HAVE_SYS_SELECT_H && !_MSC_VER && !defined(__MINGW32__)
|
||||||
|
|
||||||
#include <sys/select.h>
|
#include <sys/select.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef HAVE_UNISTD_H
|
#ifdef HAVE_UNISTD_H
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_STRING_H
|
#if HAVE_STRING_H
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_SIGNAL_H
|
#if HAVE_SIGNAL_H
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#if HAVE_FCNTL_H
|
#if HAVE_FCNTL_H
|
||||||
/* for O_BINARY and O_TEXT in WIN32 */
|
/* for O_BINARY and O_TEXT in WIN32 */
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#if HAVE_IO_H
|
#if HAVE_IO_H
|
||||||
@ -246,20 +261,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 +313,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(vfsp, 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));
|
||||||
@ -468,13 +481,13 @@ int Yap_DebugGetc() {
|
|||||||
|
|
||||||
int Yap_DebugPutc(FILE *s, wchar_t ch) {
|
int Yap_DebugPutc(FILE *s, wchar_t ch) {
|
||||||
if (Yap_Option['l' - 96])
|
if (Yap_Option['l' - 96])
|
||||||
(void)putc(ch, Yap_logfile);
|
(void) putc(ch, Yap_logfile);
|
||||||
return (putc(ch, s));
|
return (putc(ch, s));
|
||||||
}
|
}
|
||||||
|
|
||||||
int Yap_DebugPuts(FILE *s, const char *sch) {
|
int Yap_DebugPuts(FILE *s, const char *sch) {
|
||||||
if (Yap_Option['l' - 96])
|
if (Yap_Option['l' - 96])
|
||||||
(void)fputs(sch, Yap_logfile);
|
(void) fputs(sch, Yap_logfile);
|
||||||
return fputs(sch, s);
|
return fputs(sch, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -528,7 +541,7 @@ void Yap_DebugWriteIndicator(PredEntry *ap) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ap->ArityOfPE == 0) {
|
if (ap->ArityOfPE == 0) {
|
||||||
Atom At = (Atom)ap->FunctorOfPred;
|
Atom At = (Atom) ap->FunctorOfPred;
|
||||||
Yap_DebugPlWrite(MkAtomTerm(At));
|
Yap_DebugPlWrite(MkAtomTerm(At));
|
||||||
} else {
|
} else {
|
||||||
Functor f = ap->FunctorOfPred;
|
Functor f = ap->FunctorOfPred;
|
||||||
@ -557,7 +570,7 @@ int FilePutc(int sno, int ch) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
count_output_char(ch, s);
|
count_output_char(ch, s);
|
||||||
return ((int)ch);
|
return ((int) ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int NullPutc(int sno, int ch) {
|
static int NullPutc(int sno, int ch) {
|
||||||
@ -568,7 +581,7 @@ static int NullPutc(int sno, int ch) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
count_output_char(ch, s);
|
count_output_char(ch, s);
|
||||||
return ((int)ch);
|
return ((int) ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ResetEOF(StreamDesc *s) {
|
int ResetEOF(StreamDesc *s) {
|
||||||
@ -674,6 +687,8 @@ int post_process_weof(StreamDesc *s) {
|
|||||||
return EOFCHAR;
|
return EOFCHAR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void *Yap_RepStreamFromId(int sno) { return GLOBAL_Stream+(sno); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* caled after EOF found a peek, it just calls console_post_process to
|
* caled after EOF found a peek, it just calls console_post_process to
|
||||||
*conclude
|
*conclude
|
||||||
@ -735,7 +750,7 @@ static int handle_write_encoding_error(int sno, wchar_t ch) {
|
|||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
Yap_Error(REPRESENTATION_ERROR_CHARACTER, MkIntegerTerm(ch),
|
Yap_Error(REPRESENTATION_ERROR_CHARACTER, MkIntegerTerm(ch),
|
||||||
"charater %ld cannot be encoded in stream %d",
|
"charater %ld cannot be encoded in stream %d",
|
||||||
(unsigned long int)ch, sno);
|
(unsigned long int) ch, sno);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -760,7 +775,7 @@ int put_wchar(int sno, wchar_t ch) {
|
|||||||
mbstate_t mbstate;
|
mbstate_t mbstate;
|
||||||
int n;
|
int n;
|
||||||
|
|
||||||
memset((void *)&mbstate, 0, sizeof(mbstate_t));
|
memset((void *) &mbstate, 0, sizeof(mbstate_t));
|
||||||
if ((n = wcrtomb(buf, ch, &mbstate)) < 0) {
|
if ((n = wcrtomb(buf, ch, &mbstate)) < 0) {
|
||||||
/* error */
|
/* error */
|
||||||
GLOBAL_Stream[sno].stream_putc(sno, ch);
|
GLOBAL_Stream[sno].stream_putc(sno, ch);
|
||||||
@ -817,8 +832,8 @@ int put_wchar(int sno, wchar_t ch) {
|
|||||||
GLOBAL_Stream[sno].stream_putc(sno, (ch >> 8));
|
GLOBAL_Stream[sno].stream_putc(sno, (ch >> 8));
|
||||||
GLOBAL_Stream[sno].stream_putc(sno, (ch & 0xff));
|
GLOBAL_Stream[sno].stream_putc(sno, (ch & 0xff));
|
||||||
} else {
|
} else {
|
||||||
uint16_t lead = (uint16_t)LEAD_OFFSET + ((uint16_t)ch >> 10);
|
uint16_t lead = (uint16_t) LEAD_OFFSET + ((uint16_t) ch >> 10);
|
||||||
uint16_t trail = 0xDC00 + ((uint16_t)ch & 0x3FF);
|
uint16_t trail = 0xDC00 + ((uint16_t) ch & 0x3FF);
|
||||||
|
|
||||||
GLOBAL_Stream[sno].stream_putc(sno, (lead >> 8));
|
GLOBAL_Stream[sno].stream_putc(sno, (lead >> 8));
|
||||||
GLOBAL_Stream[sno].stream_putc(sno, (lead & 0xff));
|
GLOBAL_Stream[sno].stream_putc(sno, (lead & 0xff));
|
||||||
@ -915,7 +930,7 @@ static int binary_file(const char *file_name) {
|
|||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
/* ignore errors while checking a file */
|
/* ignore errors while checking a file */
|
||||||
return (FALSE);
|
return false;
|
||||||
}
|
}
|
||||||
return (S_ISDIR(ss.st_mode));
|
return (S_ISDIR(ss.st_mode));
|
||||||
#else
|
#else
|
||||||
@ -980,24 +995,26 @@ static int write_bom(int sno, StreamDesc *st) {
|
|||||||
|
|
||||||
static void check_bom(int sno, StreamDesc *st) {
|
static void check_bom(int sno, StreamDesc *st) {
|
||||||
int ch1, ch2, ch3, ch4;
|
int ch1, ch2, ch3, ch4;
|
||||||
|
if (st-> file == NULL) {
|
||||||
ch1 = fgetc(st->file);
|
PlIOError(SYSTEM_ERROR_INTERNAL, Yap_MkStream(sno), "YAP does not support BOM n %x type of files", st->status); return;
|
||||||
|
}
|
||||||
|
ch1 = st->stream_getc(sno);
|
||||||
switch (ch1) {
|
switch (ch1) {
|
||||||
case 0x00: {
|
case 0x00: {
|
||||||
ch2 = fgetc(st->file);
|
ch2 = st->stream_getc(sno);
|
||||||
if (ch2 != 0x00) {
|
if (ch2 != 0x00) {
|
||||||
ungetc(ch1, st->file);
|
ungetc(ch1, st->file);
|
||||||
ungetc(ch2, st->file);
|
ungetc(ch2, st->file);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
ch3 = fgetc(st->file);
|
ch3 = st->stream_getc(sno);
|
||||||
if (ch3 == EOFCHAR || ch3 != 0xFE) {
|
if (ch3 == EOFCHAR || ch3 != 0xFE) {
|
||||||
ungetc(ch1, st->file);
|
ungetc(ch1, st->file);
|
||||||
ungetc(ch2, st->file);
|
ungetc(ch2, st->file);
|
||||||
ungetc(ch3, st->file);
|
ungetc(ch3, st->file);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
ch4 = fgetc(st->file);
|
ch4 = st->stream_getc(sno);
|
||||||
if (ch4 == EOFCHAR || ch3 != 0xFF) {
|
if (ch4 == EOFCHAR || ch3 != 0xFF) {
|
||||||
ungetc(ch1, st->file);
|
ungetc(ch1, st->file);
|
||||||
ungetc(ch2, st->file);
|
ungetc(ch2, st->file);
|
||||||
@ -1125,8 +1142,7 @@ static bool open_header(int sno, Atom open_mode) {
|
|||||||
// skip header
|
// skip header
|
||||||
int ch;
|
int ch;
|
||||||
while ((ch = Yap_peek(sno)) == '#') {
|
while ((ch = Yap_peek(sno)) == '#') {
|
||||||
while ((ch = GLOBAL_Stream[sno].stream_wgetc(sno)) != 10 && ch != -1)
|
while ((ch = GLOBAL_Stream[sno].stream_wgetc(sno)) != 10 && ch != -1);
|
||||||
;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -1149,7 +1165,9 @@ static bool open_header(int sno, Atom open_mode) {
|
|||||||
PAR("wait", booleanFlag, OPEN_WAIT), PAR(NULL, ok, OPEN_END)
|
PAR("wait", booleanFlag, OPEN_WAIT), PAR(NULL, ok, OPEN_END)
|
||||||
|
|
||||||
#define PAR(x, y, z) z
|
#define PAR(x, y, z) z
|
||||||
typedef enum open_enum_choices { OPEN_DEFS() } open_choices_t;
|
typedef enum open_enum_choices {
|
||||||
|
OPEN_DEFS()
|
||||||
|
} open_choices_t;
|
||||||
|
|
||||||
#undef PAR
|
#undef PAR
|
||||||
|
|
||||||
@ -1164,17 +1182,15 @@ do_open(Term file_name, Term t2,
|
|||||||
Term tlist USES_REGS) { /* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
Term tlist USES_REGS) { /* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
||||||
Atom open_mode;
|
Atom open_mode;
|
||||||
int sno;
|
int sno;
|
||||||
SMALLUNSGN s;
|
|
||||||
char io_mode[8];
|
|
||||||
StreamDesc *st;
|
StreamDesc *st;
|
||||||
bool avoid_bom = false, needs_bom = false;
|
bool avoid_bom = false, needs_bom = false;
|
||||||
const char *fname;
|
const char *fname;
|
||||||
char fbuf[FILENAME_MAX];
|
char fbuf[FILENAME_MAX];
|
||||||
stream_flags_t flags;
|
stream_flags_t flags;
|
||||||
FILE *fd;
|
|
||||||
const char *s_encoding;
|
const char *s_encoding;
|
||||||
encoding_t encoding;
|
encoding_t encoding;
|
||||||
Term tenc;
|
Term tenc;
|
||||||
|
char io_mode[8];
|
||||||
// original file name
|
// original file name
|
||||||
if (IsVarTerm(file_name)) {
|
if (IsVarTerm(file_name)) {
|
||||||
Yap_Error(INSTANTIATION_ERROR, file_name, "open/3");
|
Yap_Error(INSTANTIATION_ERROR, file_name, "open/3");
|
||||||
@ -1182,7 +1198,7 @@ do_open(Term file_name, Term t2,
|
|||||||
}
|
}
|
||||||
if (!IsAtomTerm(file_name)) {
|
if (!IsAtomTerm(file_name)) {
|
||||||
if (IsStringTerm(file_name)) {
|
if (IsStringTerm(file_name)) {
|
||||||
fname = (char *)StringOfTerm(file_name);
|
fname = (char *) StringOfTerm(file_name);
|
||||||
} else {
|
} else {
|
||||||
Yap_Error(DOMAIN_ERROR_SOURCE_SINK, file_name, "open/3");
|
Yap_Error(DOMAIN_ERROR_SOURCE_SINK, file_name, "open/3");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -1205,20 +1221,6 @@ do_open(Term file_name, Term t2,
|
|||||||
} else {
|
} else {
|
||||||
open_mode = AtomOfTerm(t2);
|
open_mode = AtomOfTerm(t2);
|
||||||
}
|
}
|
||||||
// read, write, append
|
|
||||||
if (open_mode == AtomRead) {
|
|
||||||
strncpy(io_mode, "rb", 8);
|
|
||||||
s = Input_Stream_f;
|
|
||||||
} else if (open_mode == AtomWrite) {
|
|
||||||
strncpy(io_mode, "w", 8);
|
|
||||||
s = Output_Stream_f;
|
|
||||||
} else if (open_mode == AtomAppend) {
|
|
||||||
strncpy(io_mode, "a", 8);
|
|
||||||
s = Append_Stream_f | Output_Stream_f;
|
|
||||||
} else {
|
|
||||||
Yap_Error(DOMAIN_ERROR_IO_MODE, t2, "open/3");
|
|
||||||
return (FALSE);
|
|
||||||
}
|
|
||||||
/* get options */
|
/* get options */
|
||||||
xarg *args = Yap_ArgListToVector(tlist, open_defs, OPEN_END);
|
xarg *args = Yap_ArgListToVector(tlist, open_defs, OPEN_END);
|
||||||
if (args == NULL) {
|
if (args == NULL) {
|
||||||
@ -1230,22 +1232,7 @@ do_open(Term file_name, Term t2,
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
/* done */
|
/* done */
|
||||||
sno = GetFreeStreamD();
|
flags = 0;
|
||||||
if (sno < 0) {
|
|
||||||
free(args);
|
|
||||||
return PlIOError(RESOURCE_ERROR_MAX_STREAMS, TermNil, "open/3");
|
|
||||||
}
|
|
||||||
st = &GLOBAL_Stream[sno];
|
|
||||||
st->user_name = file_name;
|
|
||||||
flags = s;
|
|
||||||
// user requested encoding?
|
|
||||||
if (args[OPEN_ALIAS].used) {
|
|
||||||
Atom al = AtomOfTerm(args[OPEN_ALIAS].tvalue);
|
|
||||||
if (!Yap_AddAlias(al, sno)) {
|
|
||||||
free(args);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (args[OPEN_ENCODING].used) {
|
if (args[OPEN_ENCODING].used) {
|
||||||
tenc = args[OPEN_ENCODING].tvalue;
|
tenc = args[OPEN_ENCODING].tvalue;
|
||||||
s_encoding = RepAtom(AtomOfTerm(tenc))->StrOfAE;
|
s_encoding = RepAtom(AtomOfTerm(tenc))->StrOfAE;
|
||||||
@ -1261,9 +1248,8 @@ do_open(Term file_name, Term t2,
|
|||||||
trueGlobalPrologFlag(OPEN_EXPANDS_FILENAME_FLAG);
|
trueGlobalPrologFlag(OPEN_EXPANDS_FILENAME_FLAG);
|
||||||
// expand file name?
|
// expand file name?
|
||||||
fname = Yap_AbsoluteFile(fname, fbuf, ok);
|
fname = Yap_AbsoluteFile(fname, fbuf, ok);
|
||||||
if (fname) {
|
|
||||||
st->name = Yap_LookupAtom(fname);
|
if (!fname) {
|
||||||
} else {
|
|
||||||
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, ARG1, NULL);
|
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, ARG1, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1307,44 +1293,41 @@ do_open(Term file_name, Term t2,
|
|||||||
needs_bom = false;
|
needs_bom = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (open_mode == AtomRead) {
|
||||||
|
strncpy(io_mode, "r", 8);
|
||||||
|
} else if (open_mode == AtomWrite) {
|
||||||
|
strncpy(io_mode, "w", 8);
|
||||||
|
} else if (open_mode == AtomAppend) {
|
||||||
|
strncpy(io_mode, "a", 8);
|
||||||
|
} else {
|
||||||
|
Yap_Error(DOMAIN_ERROR_IO_MODE, MkAtomTerm(open_mode), "open/3");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ((sno = Yap_OpenStream(fname, io_mode, file_name)) < 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
st = &GLOBAL_Stream[sno];
|
||||||
|
st->user_name = file_name;
|
||||||
|
// user requested encoding?
|
||||||
|
if (args[OPEN_ALIAS].used) {
|
||||||
|
Atom al = AtomOfTerm(args[OPEN_ALIAS].tvalue);
|
||||||
|
if (!Yap_AddAlias(al, sno)) {
|
||||||
|
free(args);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
st->name = Yap_LookupAtom(fname);
|
||||||
if (st - GLOBAL_Stream < 3) {
|
if (st - GLOBAL_Stream < 3) {
|
||||||
flags |= RepError_Prolog_f;
|
flags |= RepError_Prolog_f;
|
||||||
}
|
}
|
||||||
struct vfs *vfsp = NULL;
|
|
||||||
if ((vfsp = vfs_owner(fname)) != NULL) {
|
|
||||||
st->u.private_data = vfsp->open(fname, io_mode);
|
|
||||||
fd = NULL;
|
|
||||||
if (st->u.private_data == NULL)
|
|
||||||
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name, "%s", fname));
|
|
||||||
st->vfs = vfsp;
|
|
||||||
} else if ((fd = fopen(fname, io_mode)) == NULL ||
|
|
||||||
(!(flags & Binary_Stream_f) && binary_file(fname))) {
|
|
||||||
strncpy(LOCAL_FileNameBuf, fname, MAXPATHLEN);
|
|
||||||
if (fname != fbuf)
|
|
||||||
freeBuffer((void *)fname);
|
|
||||||
fname = LOCAL_FileNameBuf;
|
|
||||||
UNLOCK(st->streamlock);
|
|
||||||
free(args);
|
|
||||||
if (errno == ENOENT && !strchr(io_mode, 'r')) {
|
|
||||||
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name, "%s: %s", fname,
|
|
||||||
strerror(errno)));
|
|
||||||
} else {
|
|
||||||
return (PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, file_name, "%s: %s",
|
|
||||||
fname, strerror(errno)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#if MAC
|
#if MAC
|
||||||
if (open_mode == AtomWrite) {
|
if (open_mode == AtomWrite) {
|
||||||
Yap_SetTextFile(RepAtom(AtomOfTerm(file_name))->StrOfAE);
|
Yap_SetTextFile(RepAtom(AtomOfTerm(file_name))->StrOfAE);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "open %s", fname);
|
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "open %s", fname);
|
||||||
flags &= ~(Free_Stream_f);
|
Yap_DefaultStreamOps(st);
|
||||||
if (!Yap_initStream(sno, fd, fname, file_name, encoding, flags, open_mode,
|
if (needs_bom && !write_bom(sno, st)) {
|
||||||
vfsp))
|
|
||||||
return false;
|
|
||||||
if (open_mode == AtomWrite) {
|
|
||||||
if (needs_bom && !write_bom(sno, st))
|
|
||||||
return false;
|
return false;
|
||||||
} else if (open_mode == AtomRead && !avoid_bom) {
|
} else if (open_mode == AtomRead && !avoid_bom) {
|
||||||
check_bom(sno, st); // can change encoding
|
check_bom(sno, st); // can change encoding
|
||||||
@ -1354,7 +1337,6 @@ do_open(Term file_name, Term t2,
|
|||||||
st->encoding = enc_id(s_encoding, st->encoding);
|
st->encoding = enc_id(s_encoding, st->encoding);
|
||||||
else
|
else
|
||||||
st->encoding = encoding;
|
st->encoding = encoding;
|
||||||
Yap_DefaultStreamOps(st);
|
|
||||||
if (script)
|
if (script)
|
||||||
open_header(sno, open_mode);
|
open_header(sno, open_mode);
|
||||||
if (fname != fbuf)
|
if (fname != fbuf)
|
||||||
@ -1388,7 +1370,8 @@ writable.
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static Int open3(USES_REGS1) { /* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
static Int open3(USES_RfEGS1) {
|
||||||
|
/* '$open'(+File,+Mode,?Stream,-ReturnCode) */
|
||||||
return do_open(Deref(ARG1), Deref(ARG2), TermNil PASS_REGS);
|
return do_open(Deref(ARG1), Deref(ARG2), TermNil PASS_REGS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1482,11 +1465,11 @@ static Int p_file_expansion(USES_REGS1) { /* '$file_expansion'(+File,-Name) */
|
|||||||
PlIOError(INSTANTIATION_ERROR, file_name, "absolute_file_name/3");
|
PlIOError(INSTANTIATION_ERROR, file_name, "absolute_file_name/3");
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
if (!Yap_findFile(RepAtom(AtomOfTerm(file_name))->StrOfAE, NULL, NULL,
|
char tmp[YAP_FILENAME_MAX+1];
|
||||||
LOCAL_FileNameBuf, true, YAP_ANY_FILE, true, false))
|
if (!Yap_AbsoluteFile(RepAtom(AtomOfTerm(file_name))->StrOfAE,tmp, false))
|
||||||
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name,
|
return (PlIOError(EXISTENCE_ERROR_SOURCE_SINK, file_name,
|
||||||
"absolute_file_name/3"));
|
"absolute_file_name/3"));
|
||||||
return (Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))));
|
return (Yap_unify(ARG2, MkAtomTerm(Yap_LookupAtom(tmp))));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int p_open_null_stream(USES_REGS1) {
|
static Int p_open_null_stream(USES_REGS1) {
|
||||||
@ -1522,7 +1505,73 @@ static Int p_open_null_stream(USES_REGS1) {
|
|||||||
return (Yap_unify(ARG1, t));
|
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, Term user_name) {
|
||||||
|
CACHE_REGS
|
||||||
|
int sno;
|
||||||
|
StreamDesc *st;
|
||||||
|
Atom at;
|
||||||
|
struct vfs *vfsp;
|
||||||
|
FILE *fd;
|
||||||
|
int flags;
|
||||||
|
|
||||||
|
sno = GetFreeStreamD();
|
||||||
|
if (sno < 0) {
|
||||||
|
PlIOError(RESOURCE_ERROR_MAX_STREAMS, MkAtomTerm(Yap_LookupAtom(fname)),
|
||||||
|
"new stream not available for opening");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
st = GLOBAL_Stream + sno;
|
||||||
|
// read, write, append
|
||||||
|
st->file = NULL;
|
||||||
|
fname = Yap_VF(fname);
|
||||||
|
if ((vfsp = vfs_owner(fname)) != NULL ) {
|
||||||
|
if (!vfsp->open(vfsp, sno, fname, io_mode)) {
|
||||||
|
UNLOCK(st->streamlock);
|
||||||
|
PlIOError(EXISTENCE_ERROR_SOURCE_SINK,
|
||||||
|
MkAtomTerm(Yap_LookupAtom(fname)), "%s", fname);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fd = st->file = fopen(fname, io_mode);
|
||||||
|
if (fd == NULL) {
|
||||||
|
if (!strchr(io_mode, 'b') && binary_file(fname)) {
|
||||||
|
UNLOCK(st->streamlock);
|
||||||
|
if (errno == ENOENT && !strchr(io_mode, 'r')) {
|
||||||
|
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, MkAtomTerm(Yap_LookupAtom(fname)), "%s: %s",
|
||||||
|
fname,
|
||||||
|
strerror(errno));
|
||||||
|
} else {
|
||||||
|
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, MkAtomTerm(Yap_LookupAtom(fname)),
|
||||||
|
"%s: %s",
|
||||||
|
fname, strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
flags = st->status;
|
||||||
|
if (strchr(io_mode, 'w')) {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
if (strchr(io_mode, 'b')) {
|
||||||
|
flags |= Binary_Stream_f;
|
||||||
|
}
|
||||||
|
Yap_initStream(sno, st->file, fname, user_name, LOCAL_encoding, flags, at, NULL);
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid",
|
||||||
|
"exists %s <%d>", fname, sno);
|
||||||
|
return sno;
|
||||||
|
}
|
||||||
|
|
||||||
|
int Yap_FileStream(FILE *fd, char *name, Term file_name, int flags) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int sno;
|
int sno;
|
||||||
Atom at;
|
Atom at;
|
||||||
@ -1542,6 +1591,25 @@ int Yap_OpenStream(FILE *fd, char *name, Term file_name, int flags) {
|
|||||||
return sno;
|
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, MkAtomTerm(Yap_LookupAtom(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) \
|
#define CheckStream(arg, kind, msg) \
|
||||||
CheckStream__(__FILE__, __FUNCTION__, __LINE__, arg, kind, msg)
|
CheckStream__(__FILE__, __FUNCTION__, __LINE__, arg, kind, msg)
|
||||||
|
|
||||||
@ -1704,7 +1772,9 @@ static Int close1 /** @pred close(+ _S_) is iso
|
|||||||
|
|
||||||
#define PAR(x, y, z) z
|
#define PAR(x, y, z) z
|
||||||
|
|
||||||
typedef enum close_enum_choices { CLOSE_DEFS() } close_choices_t;
|
typedef enum close_enum_choices {
|
||||||
|
CLOSE_DEFS()
|
||||||
|
} close_choices_t;
|
||||||
|
|
||||||
#undef PAR
|
#undef PAR
|
||||||
|
|
||||||
@ -1763,6 +1833,7 @@ Term read_line(int sno) {
|
|||||||
return (MkPairTerm(MkIntTerm(ch), tail));
|
return (MkPairTerm(MkIntTerm(ch), tail));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#define ABSOLUTE_FILE_NAME_DEFS() \
|
#define ABSOLUTE_FILE_NAME_DEFS() \
|
||||||
PAR("access", isatom, ABSOLUTE_FILE_NAME_ACCESS) \
|
PAR("access", isatom, ABSOLUTE_FILE_NAME_ACCESS) \
|
||||||
, PAR("expand", booleanFlag, ABSOLUTE_FILE_NAME_EXPAND), \
|
, PAR("expand", booleanFlag, ABSOLUTE_FILE_NAME_EXPAND), \
|
||||||
@ -1869,7 +1940,6 @@ 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 (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)
|
||||||
@ -1889,7 +1959,7 @@ void Yap_InitPlIO(struct yap_boot_params *argi) {
|
|||||||
else
|
else
|
||||||
Yap_stderr = stderr;
|
Yap_stderr = stderr;
|
||||||
GLOBAL_Stream =
|
GLOBAL_Stream =
|
||||||
(StreamDesc *)Yap_AllocCodeSpace(sizeof(StreamDesc) * MaxStreams);
|
(StreamDesc *) Yap_AllocCodeSpace(sizeof(StreamDesc) * MaxStreams);
|
||||||
for (i = 0; i < MaxStreams; ++i) {
|
for (i = 0; i < MaxStreams; ++i) {
|
||||||
INIT_LOCK(GLOBAL_Stream[i].streamlock);
|
INIT_LOCK(GLOBAL_Stream[i].streamlock);
|
||||||
GLOBAL_Stream[i].status = Free_Stream_f;
|
GLOBAL_Stream[i].status = Free_Stream_f;
|
||||||
|
@ -80,7 +80,7 @@ Int Yap_CloseSocket(int, socket_info, socket_domain);
|
|||||||
#endif /* USE_SOCKET */
|
#endif /* USE_SOCKET */
|
||||||
|
|
||||||
extern bool Yap_clearInput(int sno);
|
extern bool Yap_clearInput(int sno);
|
||||||
extern Term Yap_read_term(int inp_stream, Term opts, bool clauatse);
|
extern Term Yap_read_term(int inp_stream, Term opts, bool clause);
|
||||||
extern Term Yap_Parse(UInt prio, encoding_t enc, Term cmod);
|
extern Term Yap_Parse(UInt prio, encoding_t enc, Term cmod);
|
||||||
|
|
||||||
extern void init_read_data(ReadData _PL_rd, struct stream_desc *s);
|
extern void init_read_data(ReadData _PL_rd, struct stream_desc *s);
|
||||||
@ -216,7 +216,7 @@ INLINE_ONLY inline EXTERN void count_output_char(int ch, StreamDesc *s) {
|
|||||||
|
|
||||||
inline static Term StreamName(int i) { return (GLOBAL_Stream[i].user_name); }
|
inline static Term StreamName(int i) { return (GLOBAL_Stream[i].user_name); }
|
||||||
|
|
||||||
inline static Atom StreamFullName(int i) { return (GLOBAL_Stream[i].name); }
|
inline static Atom StreamFullName(int i) { return (Atom)(GLOBAL_Stream[i].name); }
|
||||||
|
|
||||||
inline static void console_count_output_char(int ch, StreamDesc *s) {
|
inline static void console_count_output_char(int ch, StreamDesc *s) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -273,7 +273,6 @@ extern FILE *Yap_stderr;
|
|||||||
|
|
||||||
char *Yap_MemExportStreamPtr(int sno);
|
char *Yap_MemExportStreamPtr(int sno);
|
||||||
|
|
||||||
extern bool Yap_Exists(const char *f);
|
|
||||||
|
|
||||||
static inline void freeBuffer(const void *ptr) {
|
static inline void freeBuffer(const void *ptr) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -283,8 +282,4 @@ static inline void freeBuffer(const void *ptr) {
|
|||||||
free((void *)ptr);
|
free((void *)ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** VFS handling */
|
|
||||||
|
|
||||||
VFS_t *Yap_InitAssetManager(void);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
9
os/mem.c
9
os/mem.c
@ -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);
|
||||||
|
@ -829,13 +829,13 @@ static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream,
|
|||||||
return YAP_SCANNING;
|
return YAP_SCANNING;
|
||||||
}
|
}
|
||||||
|
|
||||||
static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) {
|
static parser_state_t scan(REnv *re, FEnv *fe, int sno) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
/* preserve value of H after scanning: otherwise we may lose strings
|
/* preserve value of H after scanning: otherwise we may lose strings
|
||||||
and floats */
|
and floats */
|
||||||
LOCAL_tokptr = LOCAL_toktide =
|
LOCAL_tokptr = LOCAL_toktide =
|
||||||
|
|
||||||
Yap_tokenizer(GLOBAL_Stream + inp_stream, false, &fe->tpos);
|
Yap_tokenizer(GLOBAL_Stream + sno, false, &fe->tpos);
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if (GLOBAL_Option[2]) {
|
if (GLOBAL_Option[2]) {
|
||||||
TokEntry *t = LOCAL_tokptr;
|
TokEntry *t = LOCAL_tokptr;
|
||||||
@ -857,7 +857,7 @@ static parser_state_t scan(REnv *re, FEnv *fe, int inp_stream) {
|
|||||||
LOCAL_Error_TYPE = SYNTAX_ERROR;
|
LOCAL_Error_TYPE = SYNTAX_ERROR;
|
||||||
return YAP_PARSING_ERROR;
|
return YAP_PARSING_ERROR;
|
||||||
}
|
}
|
||||||
return scanEOF(fe, inp_stream);
|
return scanEOF(fe, sno);
|
||||||
}
|
}
|
||||||
|
|
||||||
static parser_state_t scanError(REnv *re, FEnv *fe, int inp_stream) {
|
static parser_state_t scanError(REnv *re, FEnv *fe, int inp_stream) {
|
||||||
@ -956,7 +956,7 @@ static parser_state_t parse(REnv *re, FEnv *fe, int inp_stream) {
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
Term Yap_read_term(int inp_stream, Term opts, bool clause) {
|
Term Yap_read_term(int sno, Term opts, bool clause) {
|
||||||
FEnv fe;
|
FEnv fe;
|
||||||
REnv re;
|
REnv re;
|
||||||
#if EMACS
|
#if EMACS
|
||||||
@ -968,23 +968,23 @@ Term Yap_read_term(int inp_stream, Term opts, bool clause) {
|
|||||||
while (true) {
|
while (true) {
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case YAP_START_PARSING:
|
case YAP_START_PARSING:
|
||||||
state = initParser(opts, &fe, &re, inp_stream, clause);
|
state = initParser(opts, &fe, &re, sno, clause);
|
||||||
if (state == YAP_PARSING_FINISHED) {
|
if (state == YAP_PARSING_FINISHED) {
|
||||||
pop_text_stack(lvl);
|
pop_text_stack(lvl);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case YAP_SCANNING:
|
case YAP_SCANNING:
|
||||||
state = scan(&re, &fe, inp_stream);
|
state = scan(&re, &fe, sno);
|
||||||
break;
|
break;
|
||||||
case YAP_SCANNING_ERROR:
|
case YAP_SCANNING_ERROR:
|
||||||
state = scanError(&re, &fe, inp_stream);
|
state = scanError(&re, &fe, sno);
|
||||||
break;
|
break;
|
||||||
case YAP_PARSING:
|
case YAP_PARSING:
|
||||||
state = parse(&re, &fe, inp_stream);
|
state = parse(&re, &fe, sno);
|
||||||
break;
|
break;
|
||||||
case YAP_PARSING_ERROR:
|
case YAP_PARSING_ERROR:
|
||||||
state = parseError(&re, &fe, inp_stream);
|
state = parseError(&re, &fe, sno);
|
||||||
break;
|
break;
|
||||||
case YAP_PARSING_FINISHED: {
|
case YAP_PARSING_FINISHED: {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -1021,17 +1021,17 @@ static Int
|
|||||||
|
|
||||||
static Int read_term(
|
static Int read_term(
|
||||||
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
|
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
|
||||||
int inp_stream;
|
int sno;
|
||||||
Term out;
|
Term out;
|
||||||
|
|
||||||
/* needs to change LOCAL_output_stream for write */
|
/* needs to change LOCAL_output_stream for write */
|
||||||
|
|
||||||
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
||||||
if (inp_stream == -1) {
|
if (sno == -1) {
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
out = Yap_read_term(inp_stream, add_output(ARG2, ARG3), false);
|
out = Yap_read_term(sno, add_output(ARG2, ARG3), false);
|
||||||
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return out != 0L;
|
return out != 0L;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1060,7 +1060,7 @@ static const param_t read_clause_defs[] = {READ_CLAUSE_DEFS()};
|
|||||||
#undef PAR
|
#undef PAR
|
||||||
|
|
||||||
static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
|
static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
|
||||||
int inp_stream) {
|
int sno) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
xarg *args = Yap_ArgListToVector(opts, read_clause_defs, READ_CLAUSE_END);
|
xarg *args = Yap_ArgListToVector(opts, read_clause_defs, READ_CLAUSE_END);
|
||||||
@ -1082,7 +1082,7 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
|
|||||||
fe->cmod = PROLOG_MODULE;
|
fe->cmod = PROLOG_MODULE;
|
||||||
}
|
}
|
||||||
re->bq = getBackQuotesFlag();
|
re->bq = getBackQuotesFlag();
|
||||||
fe->enc = GLOBAL_Stream[inp_stream].encoding;
|
fe->enc = GLOBAL_Stream[sno].encoding;
|
||||||
fe->sp = 0;
|
fe->sp = 0;
|
||||||
fe->qq = 0;
|
fe->qq = 0;
|
||||||
if (args[READ_CLAUSE_OUTPUT].used) {
|
if (args[READ_CLAUSE_OUTPUT].used) {
|
||||||
@ -1118,12 +1118,12 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
|
|||||||
fe->vp = 0;
|
fe->vp = 0;
|
||||||
}
|
}
|
||||||
fe->ce = Yap_CharacterEscapes(fe->cmod);
|
fe->ce = Yap_CharacterEscapes(fe->cmod);
|
||||||
re->seekable = (GLOBAL_Stream[inp_stream].status & Seekable_Stream_f) != 0;
|
re->seekable = (GLOBAL_Stream[sno].status & Seekable_Stream_f) != 0;
|
||||||
if (re->seekable) {
|
if (re->seekable) {
|
||||||
#if HAVE_FGETPOS
|
#if HAVE_FGETPOS
|
||||||
fgetpos(GLOBAL_Stream[inp_stream].file, &re->rpos);
|
fgetpos(GLOBAL_Stream[sno].file, &re->rpos);
|
||||||
#else
|
#else
|
||||||
re->cpos = GLOBAL_Stream[inp_stream].charcount;
|
re->cpos = GLOBAL_Stream[sno].charcount;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
re->prio = LOCAL_default_priority;
|
re->prio = LOCAL_default_priority;
|
||||||
@ -1166,15 +1166,15 @@ static Int read_clause2(USES_REGS1) {
|
|||||||
*/
|
*/
|
||||||
static Int read_clause(
|
static Int read_clause(
|
||||||
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
|
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
|
||||||
int inp_stream;
|
int sno;
|
||||||
Term out;
|
Term out;
|
||||||
|
|
||||||
/* needs to change LOCAL_output_stream for write */
|
/* needs to change LOCAL_output_stream for write */
|
||||||
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
||||||
if (inp_stream < 0)
|
if (sno < 0)
|
||||||
return false;
|
return false;
|
||||||
out = Yap_read_term(inp_stream, add_output(ARG2, ARG3), true);
|
out = Yap_read_term(sno, add_output(ARG2, ARG3), true);
|
||||||
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return out != 0;
|
return out != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1191,20 +1191,20 @@ static Int read_clause(
|
|||||||
*/
|
*/
|
||||||
#if 0
|
#if 0
|
||||||
static Int start_mega(USES_REGS1) {
|
static Int start_mega(USES_REGS1) {
|
||||||
int inp_stream;
|
int sno;
|
||||||
Term out;
|
Term out;
|
||||||
Term t3 = Deref(ARG3);
|
Term t3 = Deref(ARG3);
|
||||||
yhandle_t h = Yap_InitSlot(ARG2);
|
yhandle_t h = Yap_InitSlot(ARG2);
|
||||||
TokENtry *tok;
|
TokENtry *tok;
|
||||||
arity_t srity = 0;
|
arity_t srity = 0;
|
||||||
/* needs to change LOCAL_output_stream for write */
|
/* needs to change LOCAL_output_stream for write */
|
||||||
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read_exo/3");
|
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read_exo/3");
|
||||||
if (inp_stream < 0)
|
if (sno < 0)
|
||||||
return false;
|
return false;
|
||||||
/* preserve value of H after scanning: otherwise we may lose strings
|
/* preserve value of H after scanning: otherwise we may lose strings
|
||||||
and floats */
|
and floats */
|
||||||
LOCAL_tokptr = LOCAL_toktide =
|
LOCAL_tokptr = LOCAL_toktide =
|
||||||
x Yap_tokenizer(GLOBAL_Stream + inp_stream, false, &tpos);
|
x Yap_tokenizer(GLOBAL_Stream + sno, false, &tpos);
|
||||||
if (tokptr->Tok == Name_tok && (next = tokptr->TokNext) != NULL &&
|
if (tokptr->Tok == Name_tok && (next = tokptr->TokNext) != NULL &&
|
||||||
next->Tok == Ponctuation_tok && next->TokInfo == TermOpenBracket) {
|
next->Tok == Ponctuation_tok && next->TokInfo == TermOpenBracket) {
|
||||||
bool start = true;
|
bool start = true;
|
||||||
@ -1253,16 +1253,16 @@ static Int source_location(USES_REGS1) {
|
|||||||
*/
|
*/
|
||||||
static Int read2(
|
static Int read2(
|
||||||
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
|
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
|
||||||
int inp_stream;
|
int sno;
|
||||||
Int out;
|
Int out;
|
||||||
|
|
||||||
/* needs to change LOCAL_output_stream for write */
|
/* needs to change LOCAL_output_stream for write */
|
||||||
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
|
||||||
if (inp_stream == -1) {
|
if (sno == -1) {
|
||||||
return (FALSE);
|
return (FALSE);
|
||||||
}
|
}
|
||||||
out = Yap_read_term(inp_stream, add_output(ARG2, TermNil), false);
|
out = Yap_read_term(sno, add_output(ARG2, TermNil), false);
|
||||||
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,6 +144,7 @@ int GetFreeStreamD(void) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
LOCK(GLOBAL_Stream[sno].streamlock);
|
LOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
|
GLOBAL_Stream[sno].status &= ~Free_Stream_f;
|
||||||
UNLOCK(GLOBAL_StreamDescLock);
|
UNLOCK(GLOBAL_StreamDescLock);
|
||||||
GLOBAL_Stream[sno].encoding = LOCAL_encoding;
|
GLOBAL_Stream[sno].encoding = LOCAL_encoding;
|
||||||
return sno;
|
return sno;
|
||||||
@ -958,8 +959,9 @@ void Yap_CloseStreams(int loud) {
|
|||||||
static void CloseStream(int sno) {
|
static void CloseStream(int sno) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
|
||||||
fflush(NULL);
|
//fflush(NULL);
|
||||||
if (!(GLOBAL_Stream[sno].status &
|
if (GLOBAL_Stream[sno].file &&
|
||||||
|
!(GLOBAL_Stream[sno].status &
|
||||||
(Null_Stream_f | Socket_Stream_f | InMemory_Stream_f | Pipe_Stream_f)))
|
(Null_Stream_f | Socket_Stream_f | InMemory_Stream_f | Pipe_Stream_f)))
|
||||||
fclose(GLOBAL_Stream[sno].file);
|
fclose(GLOBAL_Stream[sno].file);
|
||||||
#if HAVE_SOCKET
|
#if HAVE_SOCKET
|
||||||
|
387
os/sysbits.c
387
os/sysbits.c
@ -34,14 +34,6 @@ static void FileError(yap_error_number type, Term where, const char *format,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Allocate a temporary buffer
|
|
||||||
static char *getFileNameBuffer(void) {
|
|
||||||
|
|
||||||
return Yap_AllocAtomSpace(YAP_FILENAME_MAX);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void freeFileNameBuffer(char *s) { Yap_FreeCodeSpace(s); }
|
|
||||||
|
|
||||||
static Int p_sh(USES_REGS1);
|
static Int p_sh(USES_REGS1);
|
||||||
static Int p_shell(USES_REGS1);
|
static Int p_shell(USES_REGS1);
|
||||||
static Int p_system(USES_REGS1);
|
static Int p_system(USES_REGS1);
|
||||||
@ -52,7 +44,6 @@ static Int p_putenv(USES_REGS1);
|
|||||||
static Term do_glob(const char *spec, bool ok_to);
|
static Term do_glob(const char *spec, bool ok_to);
|
||||||
#ifdef MACYAP
|
#ifdef MACYAP
|
||||||
|
|
||||||
static int chdir(char *);
|
|
||||||
/* #define signal skel_signal */
|
/* #define signal skel_signal */
|
||||||
#endif /* MACYAP */
|
#endif /* MACYAP */
|
||||||
static const char *expandVars(const char *spec, char *u);
|
static const char *expandVars(const char *spec, char *u);
|
||||||
@ -75,11 +66,11 @@ void Yap_WinError(char *yap_error) {
|
|||||||
|
|
||||||
/// is_directory: verifies whether an expanded file name
|
/// is_directory: verifies whether an expanded file name
|
||||||
/// points at a readable directory
|
/// points at a readable directory
|
||||||
static bool is_directory(const char *FileName) {
|
bool Yap_isDirectory(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);
|
||||||
@ -103,9 +94,9 @@ 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;
|
||||||
|
f = Yap_VFAlloc(f);
|
||||||
if ((vfs = vfs_owner(f))) {
|
if ((vfs = vfs_owner(f))) {
|
||||||
return vfs->exists(f);
|
return vfs->exists(vfs, f);
|
||||||
}
|
}
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
if (_access(f, 0) == 0)
|
if (_access(f, 0) == 0)
|
||||||
@ -115,8 +106,9 @@ bool Yap_Exists(const char *f) {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
#elif HAVE_ACCESS
|
#elif HAVE_ACCESS
|
||||||
if (access(f, F_OK) == 0)
|
if (access(f, F_OK) == 0) {
|
||||||
return true;
|
return true;
|
||||||
|
}
|
||||||
if (errno == EINVAL) {
|
if (errno == EINVAL) {
|
||||||
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "bad flags to access");
|
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "bad flags to access");
|
||||||
}
|
}
|
||||||
@ -148,10 +140,13 @@ int Yap_dir_separator(int ch) { return dir_separator(ch); }
|
|||||||
char *libdir = NULL;
|
char *libdir = NULL;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool Yap_IsAbsolutePath(const char *p0) {
|
bool Yap_IsAbsolutePath(const char *p0, bool expand) {
|
||||||
// verify first if expansion is needed: ~/ or $HOME/
|
// verify first if expansion is needed: ~/ or $HOME/
|
||||||
const char *p = expandVars(p0, LOCAL_FileNameBuf);
|
const char *p = p0;
|
||||||
bool nrc;
|
bool nrc;
|
||||||
|
if (expand) {
|
||||||
|
p = expandVars(p0, LOCAL_FileNameBuf);
|
||||||
|
}
|
||||||
#if _WIN32 || __MINGW32__
|
#if _WIN32 || __MINGW32__
|
||||||
nrc = !PathIsRelative(p);
|
nrc = !PathIsRelative(p);
|
||||||
#else
|
#else
|
||||||
@ -169,9 +164,10 @@ bool Yap_IsAbsolutePath(const char *p0) {
|
|||||||
static const char *PlExpandVars(const char *source, const char *root,
|
static const char *PlExpandVars(const char *source, const char *root,
|
||||||
char *result) {
|
char *result) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
|
int lvl = push_text_stack();
|
||||||
const char *src = source;
|
const char *src = source;
|
||||||
if (!result)
|
if (!result)
|
||||||
result = BaseMalloc(YAP_FILENAME_MAX + 1);
|
result = Malloc(YAP_FILENAME_MAX + 1);
|
||||||
|
|
||||||
if (strlen(source) >= YAP_FILENAME_MAX) {
|
if (strlen(source) >= YAP_FILENAME_MAX) {
|
||||||
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil,
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil,
|
||||||
@ -194,6 +190,7 @@ static const char *PlExpandVars(const char *source, const char *root,
|
|||||||
if (s != NULL)
|
if (s != NULL)
|
||||||
strncpy(result, s, YAP_FILENAME_MAX);
|
strncpy(result, s, YAP_FILENAME_MAX);
|
||||||
strcat(result, src);
|
strcat(result, src);
|
||||||
|
result = pop_output_text_stack(lvl, result);
|
||||||
return result;
|
return result;
|
||||||
} else {
|
} else {
|
||||||
#if HAVE_GETPWNAM
|
#if HAVE_GETPWNAM
|
||||||
@ -208,6 +205,7 @@ static const char *PlExpandVars(const char *source, const char *root,
|
|||||||
FileError(SYSTEM_ERROR_OPERATING_SYSTEM,
|
FileError(SYSTEM_ERROR_OPERATING_SYSTEM,
|
||||||
MkAtomTerm(Yap_LookupAtom(source)),
|
MkAtomTerm(Yap_LookupAtom(source)),
|
||||||
"User %s does not exist in %s", result, source);
|
"User %s does not exist in %s", result, source);
|
||||||
|
pop_text_stack(lvl);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
strncpy(result, user_passwd->pw_dir, YAP_FILENAME_MAX);
|
strncpy(result, user_passwd->pw_dir, YAP_FILENAME_MAX);
|
||||||
@ -219,6 +217,7 @@ static const char *PlExpandVars(const char *source, const char *root,
|
|||||||
return NULL;
|
return NULL;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
result = pop_output_text_stack(lvl, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
// do VARIABLE expansion
|
// do VARIABLE expansion
|
||||||
@ -260,9 +259,10 @@ static const char *PlExpandVars(const char *source, const char *root,
|
|||||||
if (tocp > YAP_FILENAME_MAX) {
|
if (tocp > YAP_FILENAME_MAX) {
|
||||||
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, MkStringTerm(src),
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, MkStringTerm(src),
|
||||||
"path too long");
|
"path too long");
|
||||||
|
pop_text_stack(lvl);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (root && !Yap_IsAbsolutePath(source)) {
|
if (root && !Yap_IsAbsolutePath(source, false)) {
|
||||||
strncpy(result, root, YAP_FILENAME_MAX);
|
strncpy(result, root, YAP_FILENAME_MAX);
|
||||||
if (root[strlen(root) - 1] != '/')
|
if (root[strlen(root) - 1] != '/')
|
||||||
strncat(result, "/", YAP_FILENAME_MAX);
|
strncat(result, "/", YAP_FILENAME_MAX);
|
||||||
@ -271,6 +271,7 @@ static const char *PlExpandVars(const char *source, const char *root,
|
|||||||
strncpy(result, source, strlen(src) + 1);
|
strncpy(result, source, strlen(src) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
result = pop_output_text_stack(lvl, result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,14 +342,16 @@ 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) {
|
char virtual_cwd[YAP_FILENAME_MAX + 1];
|
||||||
|
|
||||||
|
bool Yap_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;
|
||||||
@ -366,13 +369,13 @@ static bool ChDir(const char *path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static const char *myrealpath(const char *path, char *out) {
|
static const char *myrealpath(const char *path, char *out) {
|
||||||
if (!out)
|
int lvl = push_text_stack();
|
||||||
out = LOCAL_FileNameBuf;
|
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
DWORD retval = 0;
|
DWORD retval = 0;
|
||||||
|
|
||||||
// notice that the file does not need to exist
|
// notice that the file does not need to exist
|
||||||
retval = GetFullPathName(path, YAP_FILENAME_MAX, out, NULL);
|
retval = GetFullPathName(path, YAP_FILENAME_MAX, out, NULL);
|
||||||
|
pop_text_stack(lvl);
|
||||||
if (retval == 0) {
|
if (retval == 0) {
|
||||||
Yap_WinError("Generating a full path name for a file");
|
Yap_WinError("Generating a full path name for a file");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -383,12 +386,13 @@ static const char *myrealpath(const char *path, char *out) {
|
|||||||
char *rc = realpath(path, NULL);
|
char *rc = realpath(path, NULL);
|
||||||
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
|
pop_text_stack(lvl);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
// rc = NULL;
|
// rc = NULL;
|
||||||
if (errno == ENOENT || errno == EACCES) {
|
if (errno == ENOENT || errno == EACCES) {
|
||||||
char base[YAP_FILENAME_MAX + 1];
|
char *base = Malloc(YAP_FILENAME_MAX + 1);
|
||||||
strncpy(base, path, YAP_FILENAME_MAX - 1);
|
strncpy(base, path, YAP_FILENAME_MAX);
|
||||||
rc = realpath(dirname(base), out);
|
rc = realpath(dirname(base), out);
|
||||||
|
|
||||||
if (rc) {
|
if (rc) {
|
||||||
@ -412,6 +416,7 @@ static const char *myrealpath(const char *path, char *out) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
strcat(rc, b);
|
strcat(rc, b);
|
||||||
|
rc = pop_output_text_stack(lvl, rc);
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -419,6 +424,7 @@ static const char *myrealpath(const char *path, char *out) {
|
|||||||
#endif
|
#endif
|
||||||
out = malloc(strlen(path) + 1);
|
out = malloc(strlen(path) + 1);
|
||||||
strcpy(out, path);
|
strcpy(out, path);
|
||||||
|
pop_text_stack(lvl);
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -924,7 +930,7 @@ static Int make_directory(USES_REGS1) {
|
|||||||
#if defined(__MINGW32__) || _MSC_VER
|
#if defined(__MINGW32__) || _MSC_VER
|
||||||
if (_mkdir(fd) == -1) {
|
if (_mkdir(fd) == -1) {
|
||||||
#else
|
#else
|
||||||
if (mkdir(fd, 0777) == -1) {
|
if (mkdir(Yap_VFAlloc(fd), 0777) == -1) {
|
||||||
#endif
|
#endif
|
||||||
/* return an error number */
|
/* return an error number */
|
||||||
return false; // errno?
|
return false; // errno?
|
||||||
@ -933,7 +939,7 @@ static Int make_directory(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Int p_rmdir(USES_REGS1) {
|
static Int p_rmdir(USES_REGS1) {
|
||||||
const char *fd = AtomName(AtomOfTerm(ARG1));
|
const char *fd = Yap_VFAlloc(AtomName(AtomOfTerm(ARG1)));
|
||||||
#if defined(__MINGW32__) || _MSC_VER
|
#if defined(__MINGW32__) || _MSC_VER
|
||||||
if (_rmdir(fd) == -1) {
|
if (_rmdir(fd) == -1) {
|
||||||
#else
|
#else
|
||||||
@ -948,106 +954,11 @@ static Int p_rmdir(USES_REGS1) {
|
|||||||
static bool initSysPath(Term tlib, Term tcommons, bool dir_done,
|
static bool initSysPath(Term tlib, Term tcommons, bool dir_done,
|
||||||
bool commons_done) {
|
bool commons_done) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int len;
|
|
||||||
|
|
||||||
#if __WINDOWS__
|
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(Yap_PLDIR))))
|
||||||
{
|
|
||||||
char *dir;
|
|
||||||
if ((dir = Yap_RegistryGetString("library")) && is_directory(dir)) {
|
|
||||||
dir_done = true;
|
|
||||||
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(dir))))
|
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
if ((dir = Yap_RegistryGetString("prolog_commons")) && is_directory(dir)) {
|
|
||||||
if (!Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(dir))))
|
|
||||||
return false;
|
|
||||||
commons_done = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (dir_done && commons_done)
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
strncpy(LOCAL_FileNameBuf, YAP_SHAREDIR, YAP_FILENAME_MAX);
|
|
||||||
strncat(LOCAL_FileNameBuf, "/", YAP_FILENAME_MAX);
|
|
||||||
len = strlen(LOCAL_FileNameBuf);
|
|
||||||
if (!dir_done) {
|
|
||||||
strncat(LOCAL_FileNameBuf, "Yap", YAP_FILENAME_MAX);
|
|
||||||
if (is_directory(LOCAL_FileNameBuf)) {
|
|
||||||
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
|
|
||||||
return false;
|
|
||||||
dir_done = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!commons_done) {
|
|
||||||
LOCAL_FileNameBuf[len] = '\0';
|
|
||||||
strncat(LOCAL_FileNameBuf, "PrologCommons", YAP_FILENAME_MAX);
|
|
||||||
if (is_directory(LOCAL_FileNameBuf)) {
|
|
||||||
if (!Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
commons_done = true;
|
|
||||||
}
|
|
||||||
if (dir_done && commons_done)
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
#if __WINDOWS__
|
return Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(Yap_COMMONSDIR)));
|
||||||
{
|
|
||||||
size_t buflen;
|
|
||||||
char *pt;
|
|
||||||
/* couldn't find it where it was supposed to be,
|
|
||||||
let's try using the executable */
|
|
||||||
if (!GetModuleFileName(NULL, LOCAL_FileNameBuf, YAP_FILENAME_MAX)) {
|
|
||||||
Yap_WinError("could not find executable name");
|
|
||||||
/* do nothing */
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
buflen = strlen(LOCAL_FileNameBuf);
|
|
||||||
pt = LOCAL_FileNameBuf + buflen;
|
|
||||||
while (*--pt != '\\') {
|
|
||||||
/* skip executable */
|
|
||||||
if (pt == LOCAL_FileNameBuf) {
|
|
||||||
FileError(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil,
|
|
||||||
"could not find executable name");
|
|
||||||
/* do nothing */
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
while (*--pt != '\\') {
|
|
||||||
/* skip parent directory "bin\\" */
|
|
||||||
if (pt == LOCAL_FileNameBuf) {
|
|
||||||
FileError(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil,
|
|
||||||
"could not find executable name");
|
|
||||||
/* do nothing */
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* now, this is a possible location for the ROOT_DIR, let's look for a share
|
|
||||||
* directory here */
|
|
||||||
pt[1] = '\0';
|
|
||||||
/* grosse */
|
|
||||||
strncat(LOCAL_FileNameBuf, "lib\\Yap", YAP_FILENAME_MAX);
|
|
||||||
libdir = Yap_AllocCodeSpace(strlen(LOCAL_FileNameBuf) + 1);
|
|
||||||
strncpy(libdir, LOCAL_FileNameBuf, strlen(LOCAL_FileNameBuf) + 1);
|
|
||||||
pt[1] = '\0';
|
|
||||||
strncat(LOCAL_FileNameBuf, "share", YAP_FILENAME_MAX);
|
|
||||||
}
|
|
||||||
strncat(LOCAL_FileNameBuf, "\\", YAP_FILENAME_MAX);
|
|
||||||
len = strlen(LOCAL_FileNameBuf);
|
|
||||||
strncat(LOCAL_FileNameBuf, "Yap", YAP_FILENAME_MAX);
|
|
||||||
if (!dir_done && is_directory(LOCAL_FileNameBuf)) {
|
|
||||||
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
|
|
||||||
return FALSE;
|
|
||||||
dir_done = true;
|
|
||||||
}
|
|
||||||
LOCAL_FileNameBuf[len] = '\0';
|
|
||||||
strncat(LOCAL_FileNameBuf, "PrologCommons", YAP_FILENAME_MAX);
|
|
||||||
if (!commons_done && is_directory(LOCAL_FileNameBuf)) {
|
|
||||||
if (!Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf))))
|
|
||||||
return FALSE;
|
|
||||||
commons_done = true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
return dir_done && commons_done;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int libraries_directories(USES_REGS1) {
|
static Int libraries_directories(USES_REGS1) {
|
||||||
@ -1131,7 +1042,14 @@ static int volume_header(char *file) {
|
|||||||
|
|
||||||
int Yap_volume_header(char *file) { return volume_header(file); }
|
int Yap_volume_header(char *file) { return volume_header(file); }
|
||||||
|
|
||||||
const char *Yap_getcwd(const char *cwd, size_t cwdlen) {
|
const char *Yap_getcwd(char *cwd, size_t cwdlen) {
|
||||||
|
if (virtual_cwd[0]) {
|
||||||
|
if (!cwd) {
|
||||||
|
cwd = malloc(cwdlen + 1);
|
||||||
|
}
|
||||||
|
strcpy(cwd, virtual_cwd);
|
||||||
|
return cwd;
|
||||||
|
}
|
||||||
#if _WIN32 || defined(__MINGW32__)
|
#if _WIN32 || defined(__MINGW32__)
|
||||||
if (GetCurrentDirectory(cwdlen, (char *)cwd) == 0) {
|
if (GetCurrentDirectory(cwdlen, (char *)cwd) == 0) {
|
||||||
Yap_WinError("GetCurrentDirectory failed");
|
Yap_WinError("GetCurrentDirectory failed");
|
||||||
@ -1161,174 +1079,7 @@ static Int working_directory(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
if (t2 == TermEmptyAtom || t2 == TermDot)
|
if (t2 == TermEmptyAtom || t2 == TermDot)
|
||||||
return true;
|
return true;
|
||||||
return ChDir(RepAtom(AtomOfTerm(t2))->StrOfAE);
|
return Yap_ChDir(RepAtom(AtomOfTerm(t2))->StrOfAE);
|
||||||
}
|
|
||||||
|
|
||||||
/** Yap_findFile(): tries to locate a file, no expansion should be performed/
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* @param isource the proper file
|
|
||||||
* @param idef the default name fothe file, ie, startup.yss
|
|
||||||
* @param root the prefix
|
|
||||||
* @param result the output
|
|
||||||
* @param access verify whether the file has access permission
|
|
||||||
* @param ftype saved state, object, saved file, prolog file
|
|
||||||
* @param expand_root expand $ ~, etc
|
|
||||||
* @param in_lib library file
|
|
||||||
*
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
const char *Yap_findFile(const char *isource, const char *idef,
|
|
||||||
const char *iroot, char *result, bool access,
|
|
||||||
YAP_file_type_t ftype, bool expand_root, bool in_lib) {
|
|
||||||
|
|
||||||
char *save_buffer = NULL;
|
|
||||||
const char *root = iroot, *source = isource;
|
|
||||||
int rc = FAIL_RESTORE;
|
|
||||||
int try
|
|
||||||
= 0;
|
|
||||||
bool abspath = false;
|
|
||||||
//__android_log_print(ANDROID_LOG_ERROR, "YAPDroid " __FUNCTION__,
|
|
||||||
// "try=%d %s %s", try, isource, iroot) ; }
|
|
||||||
while (rc == FAIL_RESTORE) {
|
|
||||||
// means we failed this iteration
|
|
||||||
bool done = false;
|
|
||||||
// { CACHE_REGS
|
|
||||||
switch (try ++) {
|
|
||||||
case 0: // path or file name is given;
|
|
||||||
root = iroot;
|
|
||||||
if (idef || isource) {
|
|
||||||
source = (isource ? isource : idef);
|
|
||||||
}
|
|
||||||
if (source) {
|
|
||||||
abspath = Yap_IsAbsolutePath(source);
|
|
||||||
}
|
|
||||||
if (!abspath && !root && ftype == YAP_BOOT_PL) {
|
|
||||||
root = YAP_PL_SRCDIR;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 1: // library directory is given in command line
|
|
||||||
if (in_lib && ftype == YAP_SAVED_STATE) {
|
|
||||||
root = iroot;
|
|
||||||
source = (isource ? isource : idef);
|
|
||||||
} else {
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 2: // use environment variable YAPLIBDIR
|
|
||||||
#if HAVE_GETENV
|
|
||||||
if (in_lib) {
|
|
||||||
if (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ) {
|
|
||||||
root = getenv("YAPLIBDIR");
|
|
||||||
} else if (ftype == YAP_BOOT_PL) {
|
|
||||||
root = getenv("YAPSHAREDIR"
|
|
||||||
"/pl");
|
|
||||||
if (root == NULL) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
save_buffer = getFileNameBuffer();
|
|
||||||
strncpy(save_buffer, root, YAP_FILENAME_MAX);
|
|
||||||
strncat(save_buffer, "/pl", YAP_FILENAME_MAX);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
source = (isource ? isource : idef);
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
done = true;
|
|
||||||
break;
|
|
||||||
case 3: // use compilation variable YAPLIBDIR
|
|
||||||
if (in_lib) {
|
|
||||||
source = (isource ? isource : idef);
|
|
||||||
if (ftype == YAP_PL) {
|
|
||||||
root = YAP_SHAREDIR;
|
|
||||||
} else if (ftype == YAP_BOOT_PL) {
|
|
||||||
root = YAP_SHAREDIR;
|
|
||||||
strcat(root,"/pl");
|
|
||||||
} else {
|
|
||||||
root = YAP_LIBDIR;
|
|
||||||
}
|
|
||||||
} else
|
|
||||||
done = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4: // WIN stuff: registry
|
|
||||||
#if __WINDOWS
|
|
||||||
if (in_lib) {
|
|
||||||
source = (ftype == YAP_PL || ftype == YAP_QLY ? "library" : "startup");
|
|
||||||
source = Yap_RegistryGetString(source);
|
|
||||||
root = NULL;
|
|
||||||
} else
|
|
||||||
#endif
|
|
||||||
done = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 5: // search from the binary
|
|
||||||
#ifndef __ANDROID__
|
|
||||||
{
|
|
||||||
done = true;
|
|
||||||
} break;
|
|
||||||
#endif
|
|
||||||
{
|
|
||||||
const char *pt = Yap_FindExecutable();
|
|
||||||
|
|
||||||
if (pt) {
|
|
||||||
if (ftype == YAP_BOOT_PL) {
|
|
||||||
#if __ANDROID__
|
|
||||||
root = "../../../files/Yap/pl";
|
|
||||||
#else
|
|
||||||
root = "../../share/Yap/pl";
|
|
||||||
#endif
|
|
||||||
} else {
|
|
||||||
root = (ftype == YAP_SAVED_STATE || ftype == YAP_OBJ
|
|
||||||
? "../../lib/Yap"
|
|
||||||
: "../../share/Yap");
|
|
||||||
}
|
|
||||||
if (root == iroot) {
|
|
||||||
done = true;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!save_buffer)
|
|
||||||
save_buffer = getFileNameBuffer();
|
|
||||||
if (Yap_findFile(source, NULL, root, save_buffer, access, ftype,
|
|
||||||
expand_root, in_lib))
|
|
||||||
root = save_buffer;
|
|
||||||
else
|
|
||||||
done = true;
|
|
||||||
} else {
|
|
||||||
done = true;
|
|
||||||
}
|
|
||||||
source = (isource ? isource : idef);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 6: // default, try current directory
|
|
||||||
if (!isource && ftype == YAP_SAVED_STATE)
|
|
||||||
source = idef;
|
|
||||||
root = NULL;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (save_buffer)
|
|
||||||
freeFileNameBuffer(save_buffer);
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (done)
|
|
||||||
continue;
|
|
||||||
// { CACHE_REGS __android_log_print(ANDROID_LOG_ERROR, __FUNCTION__,
|
|
||||||
// "root= %s %s ", root, source) ; }
|
|
||||||
const char *work = PlExpandVars(source, root, result);
|
|
||||||
|
|
||||||
if (save_buffer)
|
|
||||||
freeFileNameBuffer(save_buffer);
|
|
||||||
|
|
||||||
// expand names in case you have
|
|
||||||
// to add a prefix
|
|
||||||
if (!access || Yap_Exists(work)) {
|
|
||||||
return work; // done
|
|
||||||
} else if (abspath)
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int true_file_name(USES_REGS1) {
|
static Int true_file_name(USES_REGS1) {
|
||||||
@ -1396,10 +1147,10 @@ static Int true_file_name3(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
root = RepAtom(AtomOfTerm(t2))->StrOfAE;
|
root = RepAtom(AtomOfTerm(t2))->StrOfAE;
|
||||||
}
|
}
|
||||||
if (!Yap_findFile(RepAtom(AtomOfTerm(t))->StrOfAE, NULL, root,
|
char tmp[YAP_FILENAME_MAX + 1];
|
||||||
LOCAL_FileNameBuf, false, YAP_PL, false, false))
|
if (!Yap_AbsoluteFile(RepAtom(AtomOfTerm(t))->StrOfAE, tmp, true))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
return Yap_unify(ARG3, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)));
|
return Yap_unify(ARG3, MkAtomTerm(Yap_LookupAtom(tmp)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Executes $SHELL under Prolog */
|
/* Executes $SHELL under Prolog */
|
||||||
@ -1416,7 +1167,7 @@ static Int p_sh(USES_REGS1) { /* sh */
|
|||||||
shell = (char *)getenv("SHELL");
|
shell = (char *)getenv("SHELL");
|
||||||
if (shell == NULL)
|
if (shell == NULL)
|
||||||
shell = "/bin/sh";
|
shell = "/bin/sh";
|
||||||
if (system(shell) < 0) {
|
if (system(Yap_VFAlloc(shell)) < 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil, "%s in sh/0",
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil, "%s in sh/0",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
@ -1622,10 +1373,12 @@ static Int p_mv(USES_REGS1) { /* rename(+OldName,+NewName) */
|
|||||||
} else if (!IsAtomTerm(t2)) {
|
} else if (!IsAtomTerm(t2)) {
|
||||||
Yap_Error(TYPE_ERROR_ATOM, t2, "second argument to rename/2 not atom");
|
Yap_Error(TYPE_ERROR_ATOM, t2, "second argument to rename/2 not atom");
|
||||||
} else {
|
} else {
|
||||||
oldname = (RepAtom(AtomOfTerm(t1)))->StrOfAE;
|
oldname = Yap_VFAlloc((RepAtom(AtomOfTerm(t1)))->StrOfAE);
|
||||||
newname = (RepAtom(AtomOfTerm(t2)))->StrOfAE;
|
newname = Yap_VFAlloc((RepAtom(AtomOfTerm(t2)))->StrOfAE);
|
||||||
if ((r = link(oldname, newname)) == 0 && (r = unlink(oldname)) != 0)
|
if ((r = link(oldname, newname)) == 0 && (r = unlink(oldname)) != 0)
|
||||||
unlink(newname);
|
unlink(newname);
|
||||||
|
free(oldname);
|
||||||
|
free(newname);
|
||||||
if (r != 0) {
|
if (r != 0) {
|
||||||
#if HAVE_STRERROR
|
#if HAVE_STRERROR
|
||||||
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, t2, "%s in rename(%s,%s)",
|
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, t2, "%s in rename(%s,%s)",
|
||||||
@ -1751,39 +1504,19 @@ static Int p_host_type(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Int p_yap_home(USES_REGS1) {
|
static Int p_yap_home(USES_REGS1) {
|
||||||
Term out = MkAtomTerm(Yap_LookupAtom(YAP_ROOTDIR));
|
Term out;
|
||||||
return (Yap_unify(out, ARG1));
|
|
||||||
|
out = MkAtomTerm(Yap_LookupAtom(Yap_ROOTDIR));
|
||||||
|
return Yap_unify(out, ARG1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int p_yap_paths(USES_REGS1) {
|
static Int p_yap_paths(USES_REGS1) {
|
||||||
Term out1, out2, out3;
|
Term out1, out2, out3;
|
||||||
const char *env_destdir = getenv("DESTDIR");
|
|
||||||
char destdir[YAP_FILENAME_MAX + 1];
|
|
||||||
|
|
||||||
if (env_destdir) {
|
out1 = MkAtomTerm(Yap_LookupAtom(Yap_LIBDIR));
|
||||||
strncat(destdir, env_destdir, YAP_FILENAME_MAX);
|
out2 = MkAtomTerm(Yap_LookupAtom(Yap_SHAREDIR));
|
||||||
strncat(destdir, "/", YAP_FILENAME_MAX);
|
out3 = MkAtomTerm(Yap_LookupAtom(Yap_BINDIR));
|
||||||
strncat(destdir, YAP_LIBDIR, YAP_FILENAME_MAX);
|
|
||||||
out1 = MkAtomTerm(Yap_LookupAtom(destdir));
|
|
||||||
} else {
|
|
||||||
out1 = MkAtomTerm(Yap_LookupAtom(YAP_LIBDIR));
|
|
||||||
}
|
|
||||||
if (env_destdir) {
|
|
||||||
strncat(destdir, env_destdir, YAP_FILENAME_MAX);
|
|
||||||
strncat(destdir, "/", YAP_FILENAME_MAX);
|
|
||||||
strncat(destdir, YAP_SHAREDIR, YAP_FILENAME_MAX);
|
|
||||||
out2 = MkAtomTerm(Yap_LookupAtom(destdir));
|
|
||||||
} else {
|
|
||||||
out2 = MkAtomTerm(Yap_LookupAtom(YAP_SHAREDIR));
|
|
||||||
}
|
|
||||||
if (env_destdir) {
|
|
||||||
strncat(destdir, env_destdir, YAP_FILENAME_MAX);
|
|
||||||
strncat(destdir, "/", YAP_FILENAME_MAX);
|
|
||||||
strncat(destdir, YAP_BINDIR, YAP_FILENAME_MAX);
|
|
||||||
out3 = MkAtomTerm(Yap_LookupAtom(destdir));
|
|
||||||
} else {
|
|
||||||
out3 = MkAtomTerm(Yap_LookupAtom(YAP_BINDIR));
|
|
||||||
}
|
|
||||||
return (Yap_unify(out1, ARG1) && Yap_unify(out2, ARG2) &&
|
return (Yap_unify(out1, ARG1) && Yap_unify(out2, ARG2) &&
|
||||||
Yap_unify(out3, ARG3));
|
Yap_unify(out3, ARG3));
|
||||||
}
|
}
|
||||||
@ -1864,7 +1597,7 @@ static Int p_win32(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Int p_ld_path(USES_REGS1) {
|
static Int p_ld_path(USES_REGS1) {
|
||||||
return Yap_unify(ARG1, MkAtomTerm(Yap_LookupAtom(YAP_LIBDIR)));
|
return Yap_unify(ARG1, MkAtomTerm(Yap_LookupAtom(Yap_DLLDIR)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int p_address_bits(USES_REGS1) {
|
static Int p_address_bits(USES_REGS1) {
|
||||||
|
@ -678,7 +678,7 @@ static Int term_to_string(USES_REGS1) {
|
|||||||
Term t2 = Deref(ARG2), rc = false, t1 = Deref(ARG1);
|
Term t2 = Deref(ARG2), rc = false, t1 = Deref(ARG1);
|
||||||
const char *s;
|
const char *s;
|
||||||
if (IsVarTerm(t2)) {
|
if (IsVarTerm(t2)) {
|
||||||
s = Yap_TermToString(ARG1,LOCAL_encoding,
|
s = Yap_TermToBuffer(ARG1, LOCAL_encoding,
|
||||||
Quote_illegal_f | Handle_vars_f);
|
Quote_illegal_f | Handle_vars_f);
|
||||||
if (!s || !MkStringTerm(s)) {
|
if (!s || !MkStringTerm(s)) {
|
||||||
Yap_Error(RESOURCE_ERROR_HEAP, t1,
|
Yap_Error(RESOURCE_ERROR_HEAP, t1,
|
||||||
@ -699,7 +699,7 @@ static Int term_to_atom(USES_REGS1) {
|
|||||||
Term t2 = Deref(ARG2), ctl, rc = false;
|
Term t2 = Deref(ARG2), ctl, rc = false;
|
||||||
Atom at;
|
Atom at;
|
||||||
if (IsVarTerm(t2)) {
|
if (IsVarTerm(t2)) {
|
||||||
const char *s = Yap_TermToString(Deref(ARG1), LOCAL_encoding,
|
const char *s = Yap_TermToBuffer(Deref(ARG1), LOCAL_encoding,
|
||||||
Quote_illegal_f | Handle_vars_f);
|
Quote_illegal_f | Handle_vars_f);
|
||||||
if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) {
|
if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) {
|
||||||
Yap_Error(RESOURCE_ERROR_HEAP, t2,
|
Yap_Error(RESOURCE_ERROR_HEAP, t2,
|
||||||
|
59
os/yapio.h
59
os/yapio.h
@ -22,11 +22,14 @@
|
|||||||
#undef HAVE_LIBREADLINE
|
#undef HAVE_LIBREADLINE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "YapStreams.h"
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
|
||||||
#include "YapIOConfig.h"
|
#include "YapIOConfig.h"
|
||||||
#include <Yatom.h>
|
#include <Yatom.h>
|
||||||
|
#include <VFS.h>
|
||||||
|
|
||||||
#ifndef _PL_WRITE_
|
#ifndef _PL_WRITE_
|
||||||
|
|
||||||
@ -45,6 +48,13 @@ typedef struct AliasDescS {
|
|||||||
/* parser stack, used to be AuxSp, now is ASP */
|
/* parser stack, used to be AuxSp, now is ASP */
|
||||||
#define ParserAuxSp LOCAL_ScannerStack
|
#define ParserAuxSp LOCAL_ScannerStack
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @return a new VFS that will support /assets
|
||||||
|
*/
|
||||||
|
|
||||||
|
extern VFS_t *Yap_InitAssetManager( void );
|
||||||
|
|
||||||
/* routines in parser.c */
|
/* routines in parser.c */
|
||||||
extern VarEntry *Yap_LookupVar(const char *);
|
extern VarEntry *Yap_LookupVar(const char *);
|
||||||
extern Term Yap_VarNames(VarEntry *, Term);
|
extern Term Yap_VarNames(VarEntry *, Term);
|
||||||
@ -76,8 +86,9 @@ extern int Yap_PlGetWchar(void);
|
|||||||
extern int Yap_PlFGetchar(void);
|
extern int Yap_PlFGetchar(void);
|
||||||
extern int Yap_GetCharForSIGINT(void);
|
extern int Yap_GetCharForSIGINT(void);
|
||||||
extern Int Yap_StreamToFileNo(Term);
|
extern Int Yap_StreamToFileNo(Term);
|
||||||
extern int Yap_OpenStream(FILE *, char *, Term, int);
|
extern int Yap_OpenStream(const char*, const char*, Term);
|
||||||
extern char *Yap_TermToString(Term t, encoding_t encoding, int flags);
|
extern int Yap_FileStream(FILE*, char *, Term, int);
|
||||||
|
extern char *Yap_TermToBuffer(Term t, encoding_t encoding, int flags);
|
||||||
extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length,
|
extern char *Yap_HandleToString(yhandle_t l, size_t sz, size_t *length,
|
||||||
encoding_t *encoding, int flags);
|
encoding_t *encoding, int flags);
|
||||||
extern int Yap_GetFreeStreamD(void);
|
extern int Yap_GetFreeStreamD(void);
|
||||||
@ -92,10 +103,6 @@ extern int Yap_growheap_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
|
|||||||
extern int Yap_growstack_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
|
extern int Yap_growstack_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
|
||||||
extern int Yap_growtrail_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
|
extern int Yap_growtrail_in_parser(tr_fr_ptr *, TokEntry **, VarEntry **);
|
||||||
|
|
||||||
extern bool Yap_IsAbsolutePath(const char *p);
|
|
||||||
extern Atom Yap_TemporaryFile(const char *prefix, int *fd);
|
|
||||||
extern const char *Yap_AbsoluteFile(const char *spec, char *obuf, bool expand);
|
|
||||||
|
|
||||||
typedef enum mem_buf_source {
|
typedef enum mem_buf_source {
|
||||||
MEM_BUF_MALLOC = 1,
|
MEM_BUF_MALLOC = 1,
|
||||||
MEM_BUF_USER = 2
|
MEM_BUF_USER = 2
|
||||||
@ -108,8 +115,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,
|
||||||
@ -147,8 +152,46 @@ INLINE_ONLY inline EXTERN Term MkCharTerm(Int c) {
|
|||||||
return MkAtomTerm(Yap_ULookupAtom(cs));
|
return MkAtomTerm(Yap_ULookupAtom(cs));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
INLINE_ONLY inline EXTERN char *Yap_VF(const char *path){
|
||||||
|
char out[YAP_FILENAME_MAX+1], *p = (char *)path;
|
||||||
|
extern char virtual_cwd[];
|
||||||
|
|
||||||
|
if ( virtual_cwd[0] == 0 || Yap_IsAbsolutePath(path, false)) {
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
strcpy(out, virtual_cwd);
|
||||||
|
strcat(out, "/" );
|
||||||
|
strcat(out, p);
|
||||||
|
strcpy(p, out);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
INLINE_ONLY inline EXTERN char *Yap_VFAlloc(const char *path){
|
||||||
|
char *out;
|
||||||
|
extern char virtual_cwd[];
|
||||||
|
|
||||||
|
out = (char *)malloc(YAP_FILENAME_MAX+1);
|
||||||
|
if ( virtual_cwd[0] == 0 || !Yap_IsAbsolutePath(path, false)) {
|
||||||
|
return (char *)path;
|
||||||
|
}
|
||||||
|
strcpy(out, virtual_cwd);
|
||||||
|
strcat(out, "/" );
|
||||||
|
strcat(out, path);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
/// UT when yap started
|
/// UT when yap started
|
||||||
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 *bufi,
|
||||||
|
size_t nchars USES_REGS);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -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.
|
||||||
|
|
||||||
|
|
||||||
|
@ -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)
|
||||||
|
|
||||||
@ -68,8 +68,8 @@ if (CMAKE_MAJOR_VERSION GREATER 2)
|
|||||||
|
|
||||||
|
|
||||||
install(TARGETS horus HorusCli
|
install(TARGETS horus HorusCli
|
||||||
RUNTIME DESTINATION ${bindir}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls}
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
@ -42,9 +42,9 @@ if (GECODE_FOUND)
|
|||||||
include_directories (${GECODE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${GECODE_VERSION})
|
include_directories (${GECODE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${GECODE_VERSION})
|
||||||
|
|
||||||
install(TARGETS gecode_yap
|
install(TARGETS gecode_yap
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls}
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gecode.yap
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gecode.yap
|
||||||
|
@ -46,16 +46,14 @@ 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)
|
||||||
|
|
||||||
install(TARGETS cudd
|
install(TARGETS cudd
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls}
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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_)
|
||||||
|
@ -7,7 +7,7 @@ if (YAP_ROOT)
|
|||||||
set( YAP_INCLUDE_DIR ../../include )
|
set( YAP_INCLUDE_DIR ../../include )
|
||||||
set( YAP_PL_LIBRARY_DIR ${libpl} )
|
set( YAP_PL_LIBRARY_DIR ${libpl} )
|
||||||
set( YAP_LIBRARY libYap )
|
set( YAP_LIBRARY libYap )
|
||||||
set( YAP_DLLS ${dlls} )
|
set( YAP_DLLS ${YAP_INSTALL_DLLDIR} )
|
||||||
|
|
||||||
else()
|
else()
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ target_link_libraries(Problogbdd
|
|||||||
)
|
)
|
||||||
|
|
||||||
install(TARGETS Problogbdd
|
install(TARGETS Problogbdd
|
||||||
RUNTIME DESTINATION ${bindir}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ target_link_libraries(Problogbdd-Lfi
|
|||||||
)
|
)
|
||||||
|
|
||||||
install(TARGETS Problogbdd-Lfi
|
install(TARGETS Problogbdd-Lfi
|
||||||
RUNTIME DESTINATION ${bindir}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -148,9 +148,9 @@ IF (CUDD_FOUND)
|
|||||||
)
|
)
|
||||||
|
|
||||||
install(TARGETS bddem
|
install(TARGETS bddem
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls}
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -171,9 +171,9 @@ IF (CUDD_FOUND)
|
|||||||
add_subDIRECTORY ( approx/simplecuddLPADs )
|
add_subDIRECTORY ( approx/simplecuddLPADs )
|
||||||
|
|
||||||
install(TARGETS cplint
|
install(TARGETS cplint
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls}
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
INSTALL(FILES ${CPLINT_PROGRAMS} DESTINATION ${libpl})
|
INSTALL(FILES ${CPLINT_PROGRAMS} DESTINATION ${libpl})
|
||||||
|
@ -26,7 +26,7 @@ target_link_libraries(LPADbdd
|
|||||||
)
|
)
|
||||||
|
|
||||||
install(TARGETS LPADbdd
|
install(TARGETS LPADbdd
|
||||||
RUNTIME DESTINATION ${bindir}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -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);
|
static YAP_Bool compute_prob(void);
|
||||||
|
|
||||||
variables createVars(YAP_Term t,DdManager * mgr, int create_dot, char inames[1000][20])
|
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);
|
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 */
|
/* opens a file */
|
||||||
{
|
{
|
||||||
FILE *fp;
|
FILE *fp;
|
||||||
|
|
||||||
if ((fp = fopen(filename, mode)) == NULL)
|
if ((fp = fopen(file_name, mode)) == NULL)
|
||||||
{
|
{
|
||||||
perror(filename);
|
perror(file_name);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
return fp;
|
return fp;
|
||||||
|
@ -103,8 +103,8 @@ endif( THRUST_INCLUDE_DIR )
|
|||||||
)
|
)
|
||||||
|
|
||||||
install(TARGETS libcuda
|
install(TARGETS libcuda
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls}
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
install(FILES ${PL_SOURCES}
|
install(FILES ${PL_SOURCES}
|
||||||
|
@ -42,9 +42,9 @@ if (GECODE_FOUND)
|
|||||||
include_directories (${GECODE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${GECODE_VERSION})
|
include_directories (${GECODE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${GECODE_VERSION})
|
||||||
|
|
||||||
install(TARGETS gecode_yap
|
install(TARGETS gecode_yap
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls}
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gecode.yap
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gecode.yap
|
||||||
|
@ -11,7 +11,7 @@ include_directories (${JAVA_INCLUDE_DIRS} ${JNI_INCLUDE_DIRS} )
|
|||||||
|
|
||||||
# set(YAP_SYSTEM_OPTIONS "jpl " ${YAP_SYSTEM_OPTIONS} PARENT_SCOPE)
|
# set(YAP_SYSTEM_OPTIONS "jpl " ${YAP_SYSTEM_OPTIONS} PARENT_SCOPE)
|
||||||
install(TARGETS jplYap
|
install(TARGETS jplYap
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls}
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
|
@ -1,21 +1,22 @@
|
|||||||
p#include <string.h>
|
p #include<string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "Yap.h"
|
#include "Yap.h"
|
||||||
#include "cut_c.h"
|
#include "cut_c.h"
|
||||||
|
|
||||||
MYDDAS_UTIL_CONNECTION
|
extern MYDDAS_UTIL_CONNECTION
|
||||||
myddas_init_initialize_connection(void *conn, void *enviromment, MYDDAS_API api,
|
myddas_init_initialize_connection(void *conn, void *enviromment,
|
||||||
|
MYDDAS_API api,
|
||||||
MYDDAS_UTIL_CONNECTION next);
|
MYDDAS_UTIL_CONNECTION next);
|
||||||
|
|
||||||
MYDDAS_UTIL_CONNECTION
|
extern MYDDAS_UTIL_CONNECTION
|
||||||
myddas_util_add_connection(void *conn, void *enviromment, MYDDAS_API api);
|
myddas_util_add_connection(void *conn, void *enviromment, MYDDAS_API api);
|
||||||
|
|
||||||
MYDDAS_UTIL_PREDICATE
|
extern MYDDAS_UTIL_PREDICATE
|
||||||
myddas_init_initialize_predicate(const char *pred_name, int pred_arity,
|
myddas_init_initialize_predicate(const char *pred_name, int pred_arity,
|
||||||
const char *pred_module,
|
const char *pred_module,
|
||||||
MYDDAS_UTIL_PREDICATE next);
|
MYDDAS_UTIL_PREDICATE next);
|
||||||
|
|
||||||
MYDDAS_UTIL_PREDICATE
|
extern MYDDAS_UTIL_PREDICATE
|
||||||
myddas_util_find_predicate(const char *pred_name, Int pred_arity,
|
myddas_util_find_predicate(const char *pred_name, Int pred_arity,
|
||||||
const char *pred_module, MYDDAS_UTIL_PREDICATE list);
|
const char *pred_module, MYDDAS_UTIL_PREDICATE list);
|
||||||
|
@ -25,9 +25,9 @@
|
|||||||
add_lib(Yapmysql ${MYSQL_SOURCES})
|
add_lib(Yapmysql ${MYSQL_SOURCES})
|
||||||
target_link_libraries(Yapmysql ${MYSQL_LIBRARIES} libYap)
|
target_link_libraries(Yapmysql ${MYSQL_LIBRARIES} libYap)
|
||||||
install(TARGETS Yapmysql
|
install(TARGETS Yapmysql
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls}
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
include_directories(${MYSQL_INCLUDE_DIR} ..)
|
include_directories(${MYSQL_INCLUDE_DIR} ..)
|
||||||
|
@ -29,9 +29,9 @@ set_target_properties (Yapodbc PROPERTIES
|
|||||||
|
|
||||||
|
|
||||||
install(TARGETS Yapodbc
|
install(TARGETS Yapodbc
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls}
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
else()
|
else()
|
||||||
|
@ -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(
|
||||||
|
@ -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
|
||||||
|
@ -28,8 +28,8 @@ set_property(GLOBAL APPEND PROPERTY COMPILE_DEFINITIONS
|
|||||||
-DMYDDAS_POSTGRES=1)
|
-DMYDDAS_POSTGRES=1)
|
||||||
|
|
||||||
install(TARGETS Yappostgres
|
install(TARGETS Yappostgres
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls}
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
endif (PostgreSQL_FOUND)
|
endif (PostgreSQL_FOUND)
|
||||||
|
@ -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)
|
||||||
@ -71,7 +70,7 @@ if (ANDROID)
|
|||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
install(TARGETS Yapsqlite3
|
install(TARGETS Yapsqlite3
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls}
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
)
|
)
|
||||||
|
@ -294,8 +294,8 @@ const char* jniStrError(int errnum, char* buf, size_t buflen) {
|
|||||||
// char *strerror_r(int errnum, char *buf, size_t n);
|
// char *strerror_r(int errnum, char *buf, size_t n);
|
||||||
return strerror_r(errnum, buf, buflen);
|
return strerror_r(errnum, buf, buflen);
|
||||||
#else
|
#else
|
||||||
int rc = strerror_r(errnum, buf, buflen);
|
char *rc = strerror_r(errnum, buf, buflen);
|
||||||
if (rc != 0) {
|
if (rc != NULL) {
|
||||||
// (POSIX only guarantees a value other than 0. The safest
|
// (POSIX only guarantees a value other than 0. The safest
|
||||||
// way to implement this function is to use C++ and overload on the
|
// way to implement this function is to use C++ and overload on the
|
||||||
// type of strerror_r to accurately distinguish GNU from POSIX.)
|
// type of strerror_r to accurately distinguish GNU from POSIX.)
|
||||||
|
@ -29,9 +29,9 @@ target_link_libraries(Py4YAP libYap ${PYTHON_LIBRARIES})
|
|||||||
|
|
||||||
|
|
||||||
install(TARGETS Py4YAP
|
install(TARGETS Py4YAP
|
||||||
RUNTIME DESTINATION ${bindir}
|
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
|
||||||
LIBRARY DESTINATION ${libdir}
|
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
ARCHIVE DESTINATION ${libdir}
|
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -54,6 +54,6 @@ add_to_group( PYTHON_PL pl_library )
|
|||||||
set_target_properties (YAPPython PROPERTIES PREFIX "")
|
set_target_properties (YAPPython PROPERTIES PREFIX "")
|
||||||
|
|
||||||
install(TARGETS YAPPython
|
install(TARGETS YAPPython
|
||||||
LIBRARY DESTINATION ${dlls}
|
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
RUNTIME DESTINATION ${dlls}
|
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
|
||||||
ARCHIVE DESTINATION ${dlls} )
|
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} )
|
||||||
|
@ -27,7 +27,7 @@ PyObject *py_ModDict;
|
|||||||
|
|
||||||
VFS_t pystream;
|
VFS_t pystream;
|
||||||
|
|
||||||
static void *py_open(const char *name, const char *io_mode) {
|
static void *py_open(VFS_t *me, int sno, const char *name, const char *io_mode) {
|
||||||
#if HAVE_STRCASESTR
|
#if HAVE_STRCASESTR
|
||||||
if (strcasestr(name, "//python/") == name)
|
if (strcasestr(name, "//python/") == name)
|
||||||
name += strlen("//python/");
|
name += strlen("//python/");
|
||||||
@ -35,11 +35,15 @@ static void *py_open(const char *name, const char *io_mode) {
|
|||||||
if (strstr(name, "//python/") == name)
|
if (strstr(name, "//python/") == name)
|
||||||
name += strlen("//python/");
|
name += strlen("//python/");
|
||||||
#endif
|
#endif
|
||||||
|
StreamDesc *st = YAP_RepStreamFromId(sno);
|
||||||
// we assume object is already open, so there is no need to open it.
|
// we assume object is already open, so there is no need to open it.
|
||||||
PyObject *stream = string_to_python(name, true, NULL);
|
PyObject *stream = string_to_python(name, true, NULL);
|
||||||
if (stream == Py_None)
|
if (stream == Py_None)
|
||||||
return NULL;
|
return NULL;
|
||||||
Py_INCREF(stream);
|
Py_INCREF(stream);
|
||||||
|
st->vfs_handle = stream;
|
||||||
|
st->vfs = me;
|
||||||
|
st->status = Append_Stream_f | Output_Stream_f;
|
||||||
return stream;
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ INCLUDE(UseSWIG)
|
|||||||
include(FindPythonModule)
|
include(FindPythonModule)
|
||||||
|
|
||||||
list (APPEND pl_library ${CMAKE_CURRENT_SOURCE_DIR}/prolog/yapi.yap )
|
list (APPEND pl_library ${CMAKE_CURRENT_SOURCE_DIR}/prolog/yapi.yap )
|
||||||
set (PYTHON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/yap4py/yapi.py ${CMAKE_CURRENT_SOURCE_DIR}/yap4py/__init__.py ${CMAKE_CURRENT_SOURCE_DIR}/yap4py/__main__.py)
|
set (PYTHON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/yap4py/yapi.py ${CMAKE_CURRENT_SOURCE_DIR}/yap4py/__main__.py)
|
||||||
|
|
||||||
|
|
||||||
SET_SOURCE_FILES_PROPERTIES(../../swig/yap.i PROPERTIES CPLUSPLUS ON)
|
SET_SOURCE_FILES_PROPERTIES(../../swig/yap.i PROPERTIES CPLUSPLUS ON)
|
||||||
@ -22,6 +22,7 @@ set(YAP4PY_PY yap4py/__init__.py yap4py/__main__.py yap4py/yapi.py)
|
|||||||
configure_file("setup.py.in" setup.py)
|
configure_file("setup.py.in" setup.py)
|
||||||
configure_file("MANIFEST.in" ${CMAKE_CURRENT_BINARY_DIR}/MANIFEST.in)
|
configure_file("MANIFEST.in" ${CMAKE_CURRENT_BINARY_DIR}/MANIFEST.in)
|
||||||
configure_file("YAP4PY.md" README.md)
|
configure_file("YAP4PY.md" README.md)
|
||||||
|
configure_file(yap4py/__init__.py.in yap4py/__init__.py)
|
||||||
|
|
||||||
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH} ${CMAKE_CURRENT_BINARY_DIR}/yap4py/include
|
INCLUDE_DIRECTORIES(${PYTHON_INCLUDE_PATH} ${CMAKE_CURRENT_BINARY_DIR}/yap4py/include
|
||||||
)
|
)
|
||||||
@ -71,7 +72,7 @@ endif()
|
|||||||
|
|
||||||
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --ignore-installed .
|
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --ignore-installed .
|
||||||
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})"
|
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})"
|
||||||
DEPENDS Py4YAP ${CMAKE_BINARY_DIR}/${YAP_STARTUP} ${dlls} )
|
DEPENDS Py4YAP ${CMAKE_BINARY_DIR}/${YAP_STARTUP} ${YAP_INSTALL_DLLDIR} )
|
||||||
|
|
||||||
|
|
||||||
install(FILES ${YAP4PY_PL} DESTINATION ${libpl} )
|
install(FILES ${YAP4PY_PL} DESTINATION ${libpl} )
|
||||||
|
@ -9,6 +9,8 @@ import platform
|
|||||||
global yap_lib_path
|
global yap_lib_path
|
||||||
yap_lib_path = os.path.dirname(__file__)
|
yap_lib_path = os.path.dirname(__file__)
|
||||||
|
|
||||||
|
if @CONDA_BUILD@ == "1":
|
||||||
|
# do not do nothing
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
def load( dll ):
|
def load( dll ):
|
||||||
dll = glob.glob(os.path.join(yap_lib_path,dll))[0]
|
dll = glob.glob(os.path.join(yap_lib_path,dll))[0]
|
||||||
@ -23,3 +25,7 @@ else:
|
|||||||
if platform.system() == 'Apple':
|
if platform.system() == 'Apple':
|
||||||
load('libYap.dylib')
|
load('libYap.dylib')
|
||||||
load('libPy4YAP.dylib' )
|
load('libPy4YAP.dylib' )
|
||||||
|
else:
|
||||||
|
load('libYap.os')
|
||||||
|
load('libPy4YAP.os' )
|
||||||
|
|
@ -81,9 +81,9 @@ extensions=[Extension('_yap', native_sources,
|
|||||||
('MINOR_VERSION', '0'),
|
('MINOR_VERSION', '0'),
|
||||||
('_YAP_NOT_INSTALLED_', '1'),
|
('_YAP_NOT_INSTALLED_', '1'),
|
||||||
('YAP_PYTHON', '1')],
|
('YAP_PYTHON', '1')],
|
||||||
runtime_library_dirs=['yap4py','${RCMAKE_INSTALL_LIBDIR}','${CMAKE_INSTALL_BINDIR}'],
|
runtime_library_dirs=['yap4py','${RCMAKE_INSTALL_FULL_LIBDIR}','${CMAKE_INSTALL_FULL_BINDIR}'],
|
||||||
swig_opts=['-modern', '-c++', '-py3','-I${RELATIVE_SOURCE}/CXX'],
|
swig_opts=['-modern', '-c++', '-py3','-I${RELATIVE_SOURCE}/CXX'],
|
||||||
library_dirs=['../../..','../../../CXX','../../packages/python',"${dlls}","${CMAKE_INSTALL_BINDIR}", '.'],
|
library_dirs=['../../..','../../../CXX','../../packages/python',"${YAP_INSTALL_FULL_DLLDIR}","${CMAKE_INSTALL_FULL_BINDIR}", '.'],
|
||||||
extra_link_args=my_extra_link_args,
|
extra_link_args=my_extra_link_args,
|
||||||
extra_compile_args=['-g3','-O0'],
|
extra_compile_args=['-g3','-O0'],
|
||||||
libraries=['Yap','${GMP_LIBRARIES}'],
|
libraries=['Yap','${GMP_LIBRARIES}'],
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user