Merge /Users/vsc/github/yap-6.3

This commit is contained in:
Vitor Santos Costa 2017-12-11 17:22:24 +00:00
commit 237430afb4
118 changed files with 5759 additions and 278836 deletions

View File

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

View File

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

View File

@ -17,7 +17,11 @@
/* for freeBSD9.1 */
#define _WITH_DPRINTF
#ifdef __APPLE__
#ifdef CONDA_BUILD
#undef HAVE_FMEMOPEN
#endif
#ifdef __APPLE__
#include "fmemopen.h"
#endif
@ -209,8 +213,8 @@ bool YAP_get_blob(Term t, void **blob, size_t *len, blob_type_t **type) {
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 (len)

File diff suppressed because it is too large Load Diff

View File

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

View File

@ -4911,17 +4911,17 @@ static Int cont_current_key_integer(USES_REGS1) {
return Yap_unify(term, ARG1) && Yap_unify(term, ARG2);
}
Term Yap_FetchTermFromDB(DBTerm *ref) {
Term Yap_FetchTermFromDB(void *ref) {
CACHE_REGS
return GetDBTerm(ref, FALSE PASS_REGS);
}
Term Yap_FetchClauseTermFromDB(DBTerm *ref) {
Term Yap_FetchClauseTermFromDB(void *ref) {
CACHE_REGS
return GetDBTerm(ref, TRUE PASS_REGS);
}
Term Yap_PopTermFromDB(DBTerm *ref) {
Term Yap_PopTermFromDB(void *ref) {
CACHE_REGS
Term t = GetDBTerm(ref, FALSE PASS_REGS);
@ -5304,7 +5304,7 @@ static void ReleaseTermFromDB(DBTerm *ref USES_REGS) {
FreeDBSpace((char *)ref);
}
void Yap_ReleaseTermFromDB(DBTerm *ref) {
void Yap_ReleaseTermFromDB(void *ref) {
CACHE_REGS
ReleaseTermFromDB(ref PASS_REGS);
}

View File

@ -303,14 +303,14 @@ static char tmpbuf[YAP_BUF_SIZE];
}
#include "YapErrors.h"
//
void Yap_pushErrorContext(yap_error_descriptor_t *new_error) {
new_error->top_error = LOCAL_ActiveError;
LOCAL_ActiveError = new_error;
}
yap_error_descriptor_t *Yap_popErrorContext(void) {
yap_error_descriptor_t *new_error = LOCAL_ActiveError;
yap_error_descriptor_t *new_error = LOCAL_ActiveError;
LOCAL_ActiveError = LOCAL_ActiveError->top_error;
return new_error;
}
@ -386,10 +386,10 @@ yamop *Yap_Error__(const char *file, const char *function, int lineno,
Yap_RestartYap(1);
}
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->classAsText =
Yap_LookupAtom(Yap_errorClassName(LOCAL_ActiveError->errorClass));
Yap_errorClassName(LOCAL_ActiveError->errorClass);
LOCAL_ActiveError->errorLine = lineno;
LOCAL_ActiveError->errorFunction = function;
LOCAL_ActiveError->errorFile = file;

View File

@ -2039,10 +2039,10 @@ static Int jump_env(USES_REGS1) {
// LOCAL_Error_TYPE = ERROR_EVENT;
Term t1 = ArgOfTerm(1, t);
if (IsApplTerm(t1) && IsAtomTerm((t2 = ArgOfTerm(1, t1)))) {
LOCAL_ActiveError->errorAsText = AtomOfTerm(t2);
LOCAL_ActiveError->classAsText = NameOfFunctor(FunctorOfTerm(t1));
LOCAL_ActiveError->errorAsText = RepAtom(AtomOfTerm(t2))->StrOfAE;
LOCAL_ActiveError->classAsText = RepAtom(NameOfFunctor(FunctorOfTerm(t1)))->StrOfAE;
} else if (IsAtomTerm(t)) {
LOCAL_ActiveError->errorAsText = AtomOfTerm(t1);
LOCAL_ActiveError->errorAsText = RepAtom(AtomOfTerm(t1))->StrOfAE;
LOCAL_ActiveError->classAsText = NULL;
}
} else {

View File

@ -159,25 +159,18 @@ int Yap_CloseForeignFile(void *handle) {
* LoadForeign(ofiles,libs,proc_name,init_proc) dynamically loads foreign
* 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) {
CACHE_REGS
LOCAL_ErrorMessage = NULL;
while (libs) {
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__
if ((libs->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY)) == NULL)
#else
if ((libs->handle = dlopen(LOCAL_FileNameBuf, RTLD_LAZY | RTLD_GLOBAL)) ==
if ((libs->handle = dlopen(file, RTLD_LAZY | RTLD_GLOBAL)) ==
NULL)
#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
other routines */
const char *file = AtomName(ofiles->name);
if (!Yap_findFile(file, NULL, NULL, LOCAL_FileNameBuf, true, YAP_OBJ, true,
true)) {
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)) ==
if ((ofiles->handle = dlopen(file, RTLD_LAZY | RTLD_GLOBAL)) ==
NULL)
#endif
{
if (LOCAL_ErrorMessage == NULL) {
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE);

View File

@ -597,8 +597,32 @@ static void RestoreHashPreds(USES_REGS1) {}
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) {
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); }
@ -632,34 +656,26 @@ static pred_flags_t read_predFlags(FILE *stream) {
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) {
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;
if (!checkChars(stream, "#!/bin/sh\nexec_dir=${YAPBINDIR:-"))
if (!maybe_read_bytes( stream, s, 2048) )
return NIL;
while ((ch = read_byte(stream)) != '\n')
;
if (!checkChars(stream, "exec $exec_dir/yap $0 \"$@\"\nsaved "))
if (strstr(s, h0)!= s)
return NIL;
while ((ch = read_byte(stream)) != ',')
*p++ = ch;
*p++ = '\0';
at = Yap_LookupAtom(s);
while ((ch = read_byte(stream)))
;
if ((p=strstr(s, h1)) == NULL) {
return NIL;
}
p += strlen(h1);
q = strchr(p,',');
if (!q)
return NIL;
q[0] = '\0';
at = Yap_LookupAtom(p);
return at;
}
@ -674,13 +690,22 @@ static Int get_header(USES_REGS1) {
return FALSE;
}
if (!(stream = Yap_GetInputStream(t1, "header scanning in qload"))) {
return FALSE;
return false;
}
if ((at = do_header(stream)) == NIL)
rc = FALSE;
else
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)
rc = false;
else {
rc = Yap_unify(ARG2, MkAtomTerm(at));
return rc;
}
LOCAL_RestartEnv = sighold;
return rc;
}
static void ReadHash(FILE *stream) {
@ -1072,10 +1097,10 @@ static Int qload_program(USES_REGS1) {
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
FILE *stream = Yap_OpenRestore(s, lib_dir);
FILE *stream = Yap_OpenRestore(s);
if (!stream)
return -1;
GLOBAL_RestoreFile = s;

View File

@ -87,7 +87,7 @@ void initIO(void);
static int myread(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 putout(CELL);
static Int putcellptr(CELL *);
@ -123,7 +123,7 @@ static void restore_heap(void);
static void ShowAtoms(void);
static void ShowEntries(PropEntry *);
#endif
static int OpenRestore(const char *, const char *, CELL *, CELL *, CELL *,
static int OpenRestore(const char *, CELL *, CELL *, CELL *,
CELL *, FILE **);
static void CloseRestore(void);
#ifndef _WIN32
@ -233,7 +233,7 @@ static Int OldHeapUsed;
static CELL which_save;
/* 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;
char flags[6];
int i = 0;
@ -1307,10 +1307,11 @@ static void ShowAtoms() {
#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) {
CACHE_REGS
int mode;
char tmp[YAP_FILENAME_MAX+1];
if ((mode = check_header(Astate, ATrail, AStack, AHeap PASS_REGS)) ==
FAIL_RESTORE)
@ -1318,9 +1319,8 @@ static int commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail,
LOCAL_PrologMode = BootMode;
if (Yap_HeapBase) {
if (falseGlobalPrologFlag(HALT_AFTER_CONSULT_FLAG) && !silentMode()) {
Yap_findFile(s, NULL, NULL, LOCAL_FileNameBuf2, true, YAP_QLY, true,
true);
fprintf(stderr, "%% Restoring file %s\n", LOCAL_FileNameBuf2);
Yap_AbsoluteFile(s, tmp, true);
fprintf(stderr, "%% Restoring file %s\n", tmp);
}
Yap_CloseStreams(TRUE);
}
@ -1333,7 +1333,7 @@ static int commit_to_saved_state(char *s, CELL *Astate, CELL *ATrail,
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) {
int mode;
@ -1355,18 +1355,13 @@ static int try_open(char *inpf, CELL *Astate, CELL *ATrail, CELL *AStack,
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,
FILE **streamp) {
CACHE_REGS
int mode;
char fname[YAP_FILENAME_MAX + 1];
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,
if (fname && fname[0] && (mode = try_open(fname, Astate, ATrail, AStack, AHeap,
streamp)) != FAIL_RESTORE) {
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
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,
"incorrect saved state ");
} 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,
"could not open saved state");
}
return FAIL_RESTORE;
}
FILE *Yap_OpenRestore(const char *inpf, const char *YapLibDir) {
FILE *Yap_OpenRestore(const char *inpf) {
FILE *stream = NULL;
if (!inpf)
inpf = "startup.yss";
if (!YapLibDir) {
YapLibDir = YAP_LIBDIR;
}
OpenRestore(inpf, YapLibDir, NULL, NULL, NULL, NULL, &stream);
OpenRestore(inpf, NULL, NULL, NULL, NULL, &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
* state
*/
int Yap_SavedInfo(const char *FileName, const char *YapLibDir, CELL *ATrail,
int Yap_SavedInfo(const char *FileName, CELL *ATrail,
CELL *AStack, CELL *AHeap) {
return DO_ONLY_CODE;
CELL MyTrail, MyStack, MyHeap, MyState;
int mode;
mode = OpenRestore(FileName, YapLibDir, &MyState, &MyTrail, &MyStack, &MyHeap,
mode = OpenRestore(FileName, &MyState, &MyTrail, &MyStack, &MyHeap,
NULL);
if (mode == FAIL_RESTORE) {
return -1;
@ -1554,13 +1546,13 @@ static void FreeRecords(void) {
* This function is called when wanting only to restore the heap and
* associated registers
*/
static int Restore(char *s, char *lib_dir USES_REGS) {
static int Restore(char *s_dir USES_REGS) {
int restore_mode;
OPCODE old_ops[_std_top + 1];
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)
return (FALSE);
Yap_ShutdownLoadForeign();
@ -1612,9 +1604,9 @@ static int Restore(char *s, char *lib_dir USES_REGS) {
return restore_mode;
}
int Yap_SavedStateRestore(char *s, char *lib_dir) {
int Yap_SavedStateRestore(char *s) {
CACHE_REGS
return Restore(s, lib_dir PASS_REGS);
return Restore(s PASS_REGS);
}
static Int p_restore(USES_REGS1) {
@ -1640,7 +1632,7 @@ static Int p_restore(USES_REGS1) {
Yap_Error(TYPE_ERROR_LIST, t1, "restore/1");
return (FALSE);
}
if ((mode = Restore(s, NULL PASS_REGS)) == DO_ONLY_CODE) {
if ((mode = Restore(s PASS_REGS)) == DO_ONLY_CODE) {
Yap_RestartYap(3);
}
return (mode != FAIL_RESTORE);

View File

@ -689,12 +689,12 @@ static int send_error_message(char s[]) {
}
static wchar_t read_quoted_char(int *scan_nextp,
struct stream_desc *inp_stream) {
struct stream_desc *st) {
int ch;
/* escape sequence */
do_switch:
ch = getchrq(inp_stream);
ch = getchrq(st);
switch (ch) {
case 10:
return 0;
@ -705,7 +705,7 @@ do_switch:
case 'b':
return '\b';
case 'c':
while (chtype((ch = getchrq(inp_stream))) == BS)
while (chtype((ch = getchrq(st))) == BS)
;
{
if (ch == '\\') {
@ -732,7 +732,7 @@ do_switch:
wchar_t wc = '\0';
for (i = 0; i < 4; i++) {
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch >= '0' && ch <= '9') {
wc += (ch - '0') << ((3 - i) * 4);
} else if (ch >= 'a' && ch <= 'f') {
@ -750,7 +750,7 @@ do_switch:
wchar_t wc = '\0';
for (i = 0; i < 8; i++) {
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch >= '0' && ch <= '9') {
wc += (ch - '0') << ((7 - i) * 4);
} else if (ch >= 'a' && ch <= 'f') {
@ -777,7 +777,7 @@ do_switch:
if (trueGlobalPrologFlag(ISO_FLAG)) {
return send_error_message("invalid escape sequence");
} else {
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch == '?') { /* delete character */
return 127;
} else if (ch >= 'a' && ch < 'z') { /* hexa */
@ -800,13 +800,13 @@ do_switch:
/* follow ISO */
{
unsigned char so_far = ch - '0';
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch >= '0' && ch < '8') { /* octal */
so_far = so_far * 8 + (ch - '0');
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch >= '0' && ch < '8') { /* octal */
so_far = so_far * 8 + (ch - '0');
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch != '\\') {
return send_error_message("invalid octal escape sequence");
}
@ -826,19 +826,19 @@ do_switch:
/* hexadecimal character (YAP allows empty hexadecimal */
{
unsigned char so_far = 0;
ch = getchrq(inp_stream);
ch = getchrq(st);
if (my_isxdigit(ch, 'f', 'F')) { /* hexa */
so_far =
so_far * 16 + (chtype(ch) == NU
? ch - '0'
: (my_isupper(ch) ? ch - 'A' : ch - 'a') + 10);
ch = getchrq(inp_stream);
ch = getchrq(st);
if (my_isxdigit(ch, 'f', 'F')) { /* hexa */
so_far =
so_far * 16 + (chtype(ch) == NU
? ch - '0'
: (my_isupper(ch) ? ch - 'A' : ch - 'a') + 10);
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch == '\\') {
return so_far;
} else {
@ -890,7 +890,7 @@ static int num_send_error_message(char s[]) {
/* 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 val = 0L, base = ch - '0';
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;
*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
* do this (have mercy)
@ -909,7 +909,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
if (--left == 0)
number_overflow();
base = 10 * base + ch - '0';
ch = getchr(inp_stream);
ch = getchr(st);
}
if (ch == '\'') {
if (base > 36) {
@ -919,7 +919,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
if (--left == 0)
number_overflow();
*sp++ = ch;
ch = getchr(inp_stream);
ch = getchr(st);
if (base == 0) {
CACHE_REGS
wchar_t ascii = ch;
@ -927,11 +927,11 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
if (ch == '\\' &&
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 */
if (scan_extra)
*chp = getchr(inp_stream);
*chp = getchr(st);
if (sign == -1) {
return MkIntegerTerm(-ascii);
}
@ -951,7 +951,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
val = oval * base + chval;
if (oval != (val - chval) / base) /* overflow */
has_overflow = (has_overflow || TRUE);
ch = getchr(inp_stream);
ch = getchr(st);
}
}
} 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)
number_overflow();
*sp++ = ch;
ch = getchr(inp_stream);
ch = getchr(st);
while (my_isxdigit(ch, 'F', 'f')) {
Int oval = val;
int chval =
@ -971,17 +971,17 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
val = val * 16 + chval;
if (oval != (val - chval) / 16) /* overflow */
has_overflow = TRUE;
ch = getchr(inp_stream);
ch = getchr(st);
}
*chp = ch;
} else if (ch == 'o' && base == 0) {
might_be_float = FALSE;
base = 8;
ch = getchr(inp_stream);
ch = getchr(st);
} else if (ch == 'b' && base == 0) {
might_be_float = FALSE;
base = 2;
ch = getchr(inp_stream);
ch = getchr(st);
} else {
val = base;
base = 10;
@ -1002,7 +1002,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
val = val * base + ch - '0';
if (val / base != oval || val - oval * base != ch - '0') /* overflow */
has_overflow = TRUE;
ch = getchr(inp_stream);
ch = getchr(st);
}
if (might_be_float && (ch == '.' || ch == 'e' || ch == 'E')) {
int has_dot = (ch == '.');
@ -1010,7 +1010,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
unsigned char *dp;
int dc;
if (chtype(ch = getchr(inp_stream)) != NU) {
if (chtype(ch = getchr(st)) != NU) {
if (ch == 'e' || ch == 'E') {
if (trueGlobalPrologFlag(ISO_FLAG))
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)
number_overflow();
*sp++ = ch;
} while (chtype(ch = getchr(inp_stream)) == NU);
} while (chtype(ch = getchr(st)) == NU);
}
}
if (ch == 'e' || ch == 'E') {
if (--left == 0)
number_overflow();
*sp++ = ch;
ch = getchr(inp_stream);
ch = getchr(st);
if (ch == '-') {
if (--left == 0)
number_overflow();
*sp++ = '-';
ch = getchr(inp_stream);
ch = getchr(st);
} else if (ch == '+') {
ch = getchr(inp_stream);
ch = getchr(st);
}
if (chtype(ch) != NU) {
CACHE_REGS
@ -1071,7 +1071,7 @@ static Term get_num(int *chp, int *chbuffp, StreamDesc *inp_stream, int sign) {
if (--left == 0)
number_overflow();
*sp++ = ch;
} while (chtype(ch = getchr(inp_stream)) == NU);
} while (chtype(ch = getchr(st)) == NU);
}
*sp = '\0';
*chp = ch;
@ -1257,7 +1257,7 @@ const char *Yap_tokText(void *tokptre) {
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;
HR += 5;
h0[0] = AbsAppl(h0 + 2);
@ -1272,7 +1272,7 @@ static void open_comment(int ch, StreamDesc *inp_stream USES_REGS) {
LOCAL_CommentsTail = h0 + 1;
h0 += 2;
h0[0] = (CELL)FunctorMinus;
h0[1] = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
h0[1] = Yap_StreamPosition(st - GLOBAL_Stream);
h0[2] = TermNil;
LOCAL_CommentsNextChar = h0 + 2;
LOCAL_CommentsBuff = (wchar_t *)malloc(1024 * sizeof(wchar_t));
@ -1301,14 +1301,14 @@ static void close_comment(USES_REGS1) {
// mark that we reached EOF,
// next token will be end_of_file)
static void mark_eof(struct stream_desc *inp_stream) {
inp_stream->status |= Push_Eof_Stream_f;
static void mark_eof(struct stream_desc *st) {
st->status |= Push_Eof_Stream_f;
}
#define add_ch_to_buff(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) {
CACHE_REGS
@ -1324,14 +1324,15 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
LOCAL_AnonVarTable = NULL;
l = NULL;
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) {
ch = getchr(inp_stream);
ch = getchr(st);
}
*tposp = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
Yap_setCurrentSourceLocation(inp_stream);
LOCAL_StartLineCount = inp_stream->linecount;
LOCAL_StartLinePos = inp_stream->linepos;
*tposp = Yap_StreamPosition(st - GLOBAL_Stream);
Yap_setCurrentSourceLocation(st);
LOCAL_StartLineCount = st->linecount;
LOCAL_StartLinePos = st->linepos;
do {
int quote, isvar;
unsigned char *charp, *mp;
@ -1350,22 +1351,22 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
p = t;
restart:
while (chtype(ch) == BS) {
ch = getchr(inp_stream);
ch = getchr(st);
}
t->TokPos = GetCurInpPos(inp_stream);
t->TokPos = GetCurInpPos(st);
switch (chtype(ch)) {
case CC:
if (store_comments) {
open_comment(ch, inp_stream PASS_REGS);
open_comment(ch, st PASS_REGS);
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);
if (chtype(ch) != EF) {
ch = getchr(inp_stream);
ch = getchr(st);
if (chtype(ch) == CC) {
extend_comment(ch PASS_REGS);
goto continue_comment;
@ -1373,7 +1374,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
}
close_comment(PASS_REGS1);
} else {
while ((ch = getchr(inp_stream)) != 10 && chtype(ch) != EF)
while ((ch = getchr(st)) != 10 && 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) {
/* we found a comment before reading characters */
while (chtype(ch) == BS) {
ch = getchr(inp_stream);
ch = getchr(st);
}
*tposp = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
Yap_setCurrentSourceLocation(inp_stream);
*tposp = Yap_StreamPosition(st - GLOBAL_Stream);
Yap_setCurrentSourceLocation(st);
}
goto restart;
} else {
t->Tok = Ord(kind = eot_tok);
mark_eof(inp_stream);
mark_eof(st);
t->TokInfo = TermEof;
}
break;
@ -1398,14 +1399,14 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
case UL:
case LC: {
int32_t och = ch;
ch = getchr(inp_stream);
ch = getchr(st);
size_t sz = 512;
TokImage = Malloc(sz PASS_REGS);
scan_name:
charp = (unsigned char *)TokImage;
isvar = (chtype(och) != LC);
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)) {
unsigned char *p0 = TokImage;
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);
}
add_ch_to_buff(ch);
ch = getchr(inp_stream);
ch = getchr(st);
}
add_ch_to_buff('\0');
if (!isvar) {
@ -1459,7 +1460,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
cha = ch;
cherr = 0;
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) {
p->Tok = eot_tok;
t->TokInfo = TermError;
@ -1471,7 +1472,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
if (cherr) {
TokEntry *e;
t->Tok = Number_tok;
t->TokPos = GetCurInpPos(inp_stream);
t->TokPos = GetCurInpPos(st);
e = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
if (e == NULL) {
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->TokInfo = (Term)Yap_LookupVar("E");
t->TokPos = GetCurInpPos(inp_stream);
t->TokPos = GetCurInpPos(st);
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
if (e2 == NULL) {
return TrailSpaceError(p, l);
@ -1530,7 +1531,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
if (ch == '(')
solo_flag = FALSE;
t->TokInfo = MkAtomTerm(AtomE);
t->TokPos = GetCurInpPos(inp_stream);
t->TokPos = GetCurInpPos(st);
e2 = (TokEntry *)AllocScannerMemory(sizeof(TokEntry));
if (e2 == NULL) {
return TrailSpaceError(p, l);
@ -1557,7 +1558,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
charp = TokImage;
quote = ch;
len = 0;
ch = getchrq(inp_stream);
ch = getchrq(st);
size_t sz = 1024;
while (TRUE) {
@ -1577,23 +1578,23 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
break;
}
if (ch == quote) {
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch != quote)
break;
add_ch_to_buff(ch);
ch = getchrq(inp_stream);
ch = getchrq(st);
} else if (ch == '\\' &&
Yap_GetModuleEntry(CurrentModule)->flags & M_CHARESCAPE) {
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);
}
if (scan_next) {
ch = getchrq(inp_stream);
ch = getchrq(st);
}
} else {
add_ch_to_buff(ch);
ch = getchrq(inp_stream);
ch = getchrq(st);
}
++len;
}
@ -1628,9 +1629,9 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
if (ch == '\0') {
int pch;
t->Tok = Ord(kind = eot_tok);
pch = Yap_peek(inp_stream - GLOBAL_Stream);
pch = Yap_peek(st - GLOBAL_Stream);
if (chtype(pch) == EF) {
mark_eof(inp_stream);
mark_eof(st);
t->TokInfo = TermEof;
} else {
t->TokInfo = TermNewLine;
@ -1638,11 +1639,11 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
t->TokInfo = TermEof;
return l;
} else
ch = getchr(inp_stream);
ch = getchr(st);
break;
case SY: {
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 == '%')) {
t->Tok = Ord(kind = eot_tok);
// consume...
@ -1655,7 +1656,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
if (ch == '`')
goto quoted_string;
och = ch;
ch = getchr(inp_stream);
ch = getchr(st);
if (och == '.') {
if (chtype(ch) == BS || chtype(ch) == EF || ch == '%') {
t->Tok = Ord(kind = eot_tok);
@ -1664,7 +1665,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
return l;
}
if (chtype(ch) == EF) {
mark_eof(inp_stream);
mark_eof(st);
t->TokInfo = TermEof;
} else {
t->TokInfo = TermNewLine;
@ -1675,12 +1676,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
if (och == '/' && ch == '*') {
if (store_comments) {
CHECK_SPACE();
open_comment('/', inp_stream PASS_REGS);
open_comment('/', st PASS_REGS);
while ((och != '*' || ch != '/') && chtype(ch) != EF) {
och = ch;
CHECK_SPACE();
extend_comment(ch PASS_REGS);
ch = getchr(inp_stream);
ch = getchr(st);
}
if (chtype(ch) != EF) {
CHECK_SPACE();
@ -1690,7 +1691,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
} else {
while ((och != '*' || ch != '/') && chtype(ch) != EF) {
och = ch;
ch = getchr(inp_stream);
ch = getchr(st);
}
}
if (chtype(ch) == EF) {
@ -1699,15 +1700,15 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
break;
} else {
/* leave comments */
ch = getchr(inp_stream);
ch = getchr(st);
if (t == l) {
/* we found a comment before reading characters */
while (chtype(ch) == BS) {
ch = getchr(inp_stream);
ch = getchr(st);
}
CHECK_SPACE();
*tposp = Yap_StreamPosition(inp_stream - GLOBAL_Stream);
Yap_setCurrentSourceLocation(inp_stream);
*tposp = Yap_StreamPosition(st - GLOBAL_Stream);
Yap_setCurrentSourceLocation(st);
}
}
goto restart;
@ -1721,7 +1722,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
return l;
}
if (chtype(ch) == EF) {
mark_eof(inp_stream);
mark_eof(st);
t->TokInfo = TermEof;
} else {
t->TokInfo = TermNl;
@ -1733,7 +1734,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
TokImage = Malloc(sz);
charp = TokImage;
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)) {
sz = Yap_Min(sz * 2, sz + MBYTE);
TokImage = Realloc(TokImage, sz);
@ -1764,7 +1765,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
unsigned char chs[2];
chs[0] = ch;
chs[1] = '\0';
ch = getchr(inp_stream);
ch = getchr(st);
t->TokInfo = MkAtomTerm(Yap_ULookupAtom(chs));
t->Tok = Ord(kind = Name_tok);
if (ch == '(')
@ -1773,7 +1774,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
case BK:
och = ch;
ch = getchr(inp_stream);
ch = getchr(st);
{
unsigned char chs[10];
TokImage = charp = chs;
@ -1783,12 +1784,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
}
if (och == '(') {
while (chtype(ch) == BS) {
ch = getchr(inp_stream);
ch = getchr(st);
}
if (ch == ')') {
t->TokInfo = TermEmptyBrackets;
t->Tok = Ord(kind = Name_tok);
ch = getchr(inp_stream);
ch = getchr(st);
solo_flag = FALSE;
break;
} else if (!solo_flag) {
@ -1797,12 +1798,12 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
}
} else if (och == '[') {
while (chtype(ch) == BS) {
ch = getchr(inp_stream);
ch = getchr(st);
};
if (ch == ']') {
t->TokInfo = TermNil;
t->Tok = Ord(kind = Name_tok);
ch = getchr(inp_stream);
ch = getchr(st);
solo_flag = FALSE;
break;
}
@ -1827,26 +1828,26 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
cur_qq = qq;
}
t->TokInfo = (CELL)qq;
if (inp_stream->status & Seekable_Stream_f) {
qq->start.byteno = fseek(inp_stream->file, 0, 0);
if (st->status & Seekable_Stream_f) {
qq->start.byteno = fseek(st->file, 0, 0);
} else {
qq->start.byteno = inp_stream->charcount - 1;
qq->start.byteno = st->charcount - 1;
}
qq->start.lineno = inp_stream->linecount;
qq->start.linepos = inp_stream->linepos - 1;
qq->start.charno = inp_stream->charcount - 1;
qq->start.lineno = st->linecount;
qq->start.linepos = st->linepos - 1;
qq->start.charno = st->charcount - 1;
t->Tok = Ord(kind = QuasiQuotes_tok);
ch = getchr(inp_stream);
ch = getchr(st);
solo_flag = FALSE;
break;
}
while (chtype(ch) == BS) {
ch = getchr(inp_stream);
ch = getchr(st);
};
if (ch == '}') {
t->TokInfo = TermBraces;
t->Tok = Ord(kind = Name_tok);
ch = getchr(inp_stream);
ch = getchr(st);
solo_flag = FALSE;
break;
}
@ -1863,16 +1864,16 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
}
cur_qq = NULL;
t->TokInfo = (CELL)qq;
if (inp_stream->status & Seekable_Stream_f) {
qq->mid.byteno = fseek(inp_stream->file, 0, 0);
if (st->status & Seekable_Stream_f) {
qq->mid.byteno = fseek(st->file, 0, 0);
} else {
qq->mid.byteno = inp_stream->charcount - 1;
qq->mid.byteno = st->charcount - 1;
}
qq->mid.lineno = inp_stream->linecount;
qq->mid.linepos = inp_stream->linepos - 1;
qq->mid.charno = inp_stream->charcount - 1;
qq->mid.lineno = st->linecount;
qq->mid.linepos = st->linepos - 1;
qq->mid.charno = st->charcount - 1;
t->Tok = Ord(kind = QuasiQuotes_tok);
ch = getchr(inp_stream);
ch = getchr(st);
sz = 1024;
TokImage = Malloc(sz);
if (!TokImage) {
@ -1885,11 +1886,11 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
charp = TokImage;
quote = ch;
len = 0;
ch = getchrq(inp_stream);
ch = getchrq(st);
while (TRUE) {
if (ch == '|') {
ch = getchrq(inp_stream);
ch = getchrq(st);
if (ch != '}') {
} else {
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) {
Free(TokImage);
mark_eof(inp_stream);
mark_eof(st);
t->Tok = Ord(kind = eot_tok);
t->TokInfo = TermOutOfHeapError;
break;
} else {
charp += put_utf8(charp, ch);
ch = getchrq(inp_stream);
ch = getchrq(st);
}
if (charp > (unsigned char *)AuxSp - 1024) {
/* 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);
qq->text = (unsigned char *)mp;
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
if (inp_stream->status & Seekable_Stream_f) {
qq->end.byteno = fseek(inp_stream->file, 0, 0);
if (st->status & Seekable_Stream_f) {
qq->end.byteno = fseek(st->file, 0, 0);
} else {
qq->end.byteno = inp_stream->charcount - 1;
qq->end.byteno = st->charcount - 1;
}
qq->end.lineno = inp_stream->linecount;
qq->end.linepos = inp_stream->linepos - 1;
qq->end.charno = inp_stream->charcount - 1;
qq->end.lineno = st->linecount;
qq->end.linepos = st->linepos - 1;
qq->end.charno = st->charcount - 1;
if (!(t->TokInfo)) {
return CodeSpaceError(t, p, l);
}
Yap_ReleasePreAllocCodeSpace((CODEADDR)TokImage);
solo_flag = FALSE;
ch = getchr(inp_stream);
ch = getchr(st);
break;
}
t->Tok = Ord(kind = Ponctuation_tok);
break;
case EF:
mark_eof(inp_stream);
mark_eof(st);
t->Tok = Ord(kind = eot_tok);
t->TokInfo = TermEof;
return l;
@ -1966,7 +1967,7 @@ TokEntry *Yap_tokenizer(struct stream_desc *inp_stream, bool store_comments,
p->TokNext = e;
e->Tok = Error_tok;
e->TokInfo = MkAtomTerm(Yap_LookupAtom(LOCAL_ErrorMessage));
e->TokPos = GetCurInpPos(inp_stream);
e->TokPos = GetCurInpPos(st);
e->TokNext = NULL;
LOCAL_ErrorMessage = NULL;
p = e;

View File

@ -1091,15 +1091,15 @@ bool set_clause_info(yamop *codeptr, PredEntry *pp) {
Term ts[2];
void *begin;
if (pp->ArityOfPE == 0) {
LOCAL_ActiveError->prologPredName = (Atom) pp->FunctorOfPred;
LOCAL_ActiveError->prologPredName = RepAtom((Atom) pp->FunctorOfPred)->StrOfAE;
LOCAL_ActiveError->prologPredArity = 0;
} else {
LOCAL_ActiveError->prologPredName = NameOfFunctor(pp->FunctorOfPred);
LOCAL_ActiveError->prologPredName = RepAtom(NameOfFunctor(pp->FunctorOfPred))->StrOfAE;
LOCAL_ActiveError->prologPredArity = pp->ArityOfPE;
}
LOCAL_ActiveError->prologPredModule =
(pp->ModuleOfPred ? pp->ModuleOfPred : TermProlog);
LOCAL_ActiveError->prologPredFile = pp->src.OwnerFile;
(pp->ModuleOfPred ? RepAtom(AtomOfTerm(pp->ModuleOfPred))->StrOfAE : "prolog");
LOCAL_ActiveError->prologPredFile = RepAtom(pp->src.OwnerFile)->StrOfAE;
if (codeptr->opc == UNDEF_OPCODE) {
LOCAL_ActiveError->prologPredFirstLine = 0;
LOCAL_ActiveError->prologPredLine = 0;

View File

@ -1349,13 +1349,13 @@ static Int p_statistics_lu_db_size(USES_REGS1) {
}
static Int p_executable(USES_REGS1) {
char tmp[YAP_FILENAME_MAX+1];
if (GLOBAL_argv && GLOBAL_argv[0])
Yap_findFile(GLOBAL_argv[0], NULL, NULL, LOCAL_FileNameBuf, true, YAP_EXE,
true, true);
Yap_AbsoluteFile(GLOBAL_argv[0], tmp, true);
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) {

View File

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

View File

@ -501,7 +501,7 @@ unsigned char *Yap_readText(seq_tv_t *inp, size_t *lengp) {
#endif
if (inp->type & YAP_STRING_TERM) {
// 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;
}
if (inp->type & YAP_STRING_CHARS) {

View File

@ -87,7 +87,7 @@ static char *send_tracer_message(char *start, char *name, arity_t arity,
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);
size_t sz;
if (sn == NULL) {

View File

@ -1255,7 +1255,7 @@ static void wrputref(CODEADDR ref, int Quote_illegal,
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
int sno = Yap_open_buf_write_stream(enc, flags);
const char *sf;

View File

@ -1,33 +1,41 @@
/*************************************************************************
* *
* Yap Prolog *
* *
* Yap Prolog Was Developed At Nccup - Universidade Do Porto *
* *
* Copyright L.Damas, V.S.Costa And Universidade Do Porto 1985-1997 *
* *
**************************************************************************
* *
* File: Yap.C *
* Last Rev: *
* Mods: *
* Comments: Yap's Main File: parse arguments *
* *
*************************************************************************/
* *
* Yap Prolog *
* *
* Yap Prolog Was Developed At Nccup - Universidade Do Porto *
* *
* Copyright L.Damas, V.S.Costa And Universidade Do Porto 1985-1997 *
* *
**************************************************************************
* *
* File: Yap.C * Last
*Rev:
* Mods:
** Comments: Yap's Main File: parse arguments *
* *
*************************************************************************/
/* static char SccsId[] = "X 4.3.3"; */
#include "Yap.h"
#include "YapHeap.h"
#include "YapInterface.h"
#include "YapStreams.h"
#include "config.h"
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_STDINT_H
#include <stdint.h>
#endif
#include <stddef.h>
#include <stdlib.h>
#ifdef _MSC_VER /* Microsoft's Visual C++ Compiler */
#ifdef HAVE_UNISTD_H
#undef HAVE_UNISTD_H
@ -35,28 +43,352 @@
#endif
#include <stdio.h>
#if HAVE_STRING_H
#include <string.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#if HAVE_DIRECT_H
#include <direct.h>
#endif
#ifndef YAP_ROOTDIR
#if HAVE_LIBGEN_H
#include <libgen.h>
char
*YAP_BINDIR,
*YAP_ROOTDIR,
*YAP_SHAREDIR,
*YAP_LIBDIR,
*YAP_YAPLIB;
#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) {
fprintf(stderr, "\n[ Valid switches for command line arguments: ]\n");
fprintf(stderr, " -? Shows this screen\n");
@ -97,8 +429,9 @@ static void print_usage(void) {
defined(YAPOR_THREADS)
fprintf(stderr, " -w Number of workers (default: %d)\n",
DEFAULT_NUMBERWORKERS);
fprintf(stderr, " -sl Loop scheduler executions before look for hiden "
"shared work (default: %d)\n",
fprintf(stderr,
" -sl Loop scheduler executions before look for hiden "
"shared work (default: %d)\n",
DEFAULT_SCHEDULERLOOP);
fprintf(stderr, " -d Value of delayed release of load (default: %d)\n",
DEFAULT_DELAYEDRELEASELOAD);
@ -147,54 +480,38 @@ static int dump_runtime_variables(void) {
return 1;
}
YAP_file_type_t Yap_InitDefaults(YAP_init_args *iap, char saved_state[],
int argc, char *argv[]) {
X_API YAP_file_type_t Yap_InitDefaults(void *x, char *saved_state, int argc,
char *argv[]) {
if (!LOCAL_TextBuffer)
LOCAL_TextBuffer = Yap_InitTextAllocator();
YAP_init_args *iap = x;
memset(iap, 0, sizeof(YAP_init_args));
#if __ANDROID__
iap->boot_file_type = YAP_BOOT_PL;
iap->SavedState = NULL;
iap->assetManager = NULL;
#else
iap->boot_file_type = YAP_QLY;
iap->SavedState = saved_state;
#endif
iap->Argc = argc;
iap->Argv = argv;
iap->YapLibDir = YAP_YAPLIB;
return iap->boot_file_type;
return YAP_QLY;
}
/**
* @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[],
YAP_init_args *iap) {
char *p;
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);
while (--argc > 0) {
p = *++argv;
@ -219,8 +536,9 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
iap->YapPrologBootFile = *++argv;
argc--;
} else {
iap->YapPrologBootFile = "boot.yap";
iap->YapPrologBootFile = NULL;
}
iap->bootstrapping = true;
break;
case '?':
print_usage();
@ -474,9 +792,8 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
else {
argc--;
if (argc == 0) {
fprintf(
stderr,
" [ YAP unrecoverable error: missing goal for option 'z' ]\n");
fprintf(stderr, " [ YAP unrecoverable error: missing goal for "
"option 'z' ]\n");
exit(EXIT_FAILURE);
}
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="))) {
GLOBAL_Home = p + strlen("-home=");
} else if (!strncmp("-cwd=", p, strlen("-cwd="))) {
#if __WINDOWS__
if (_chdir(p + strlen("-cwd=")) < 0) {
#else
if (chdir(p + strlen("-cwd=")) < 0) {
#endif
if (!Yap_ChDir(p + strlen("-cwd="))) {
fprintf(stderr, " [ YAP unrecoverable error in setting cwd: %s ]\n",
strerror(errno));
}
@ -537,9 +850,8 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
else {
argc--;
if (argc == 0) {
fprintf(
stderr,
" [ YAP unrecoverable error: missing paths for option 'p' ]\n");
fprintf(stderr, " [ YAP unrecoverable error: missing paths for "
"option 'p' ]\n");
exit(EXIT_FAILURE);
}
argv++;
@ -583,3 +895,270 @@ X_API YAP_file_type_t YAP_parse_yap_arguments(int argc, char *argv[],
}
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;
}

View File

@ -7,18 +7,18 @@ cmake_minimum_required(VERSION 3.4)
# value of 3.4.0 or lower.
include(CMakeToolsHelpers OPTIONAL)
project(YAP)
include(FeatureSummary)
include(GNUInstallDirs)
project(YAP)
set(YAP_APP_DIR "${CMAKE_SOURCE_DIR}/../..")
cmake_policy(VERSION 3.4)
set( CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}" "${CMAKE_SOURCE_DIR}/cmake")
set(ANACONDA $ENV{CONDA_BUILD} CACHE BOOL "Anaconda Environment")
message(STATUS "ANACONDA found: ${ANACONDA}")
set(ANACONDA $ENV{CONDA_BUILD} CACHE BOOL "Anaconda Environment")
message(STATUS "ANACONDA found: ${ANACONDA}")
include(CheckIncludeFiles)
include(CheckLibraryExists)
@ -219,9 +219,10 @@ if (ANACONDA)
#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(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_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)
endif()
@ -249,6 +250,7 @@ if (APPLE)
endif ()
endif ()
set(prefix ${CMAKE_INSTALL_PREFIX}) #BINDIR})
set(bindir ${CMAKE_INSTALL_PREFIX}/bin) #BINDIR})
set(includedir ${CMAKE_INSTALL_PREFIX}/include) #INCLUDEDIR})
@ -268,22 +270,26 @@ set(dlls ${libdir}/Yap)
set(YAP_ROOTDIR ${prefix})
# erootdir -> rootdir
# bindir defined above
# libdir defined above
set(YAP_SHAREDIR ${datarootdir})
set(YAP_BINDIR ${bindir})
set(YAP_INCLUDEDIR ${includedir})
set(YAP_ROOTDIR ${prefix})
set(YAP_LIBDIR ${dlls})
set(YAP_DATADIR ${CMAKE_INSTALL_FULL_DATADIR})
set(YAP_INCLUDEDIR ${CMAKE_INSTALL_FULL_INCLUDEDIR}/Yap)
set(YAP_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR})
set(YAP_DLLDIR ${CMAKE_INSTALL_FULL_LIBDIR}/Yap)
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(java NO-POLICY-SCOPE)
include(cudd )
include(java )
set(pl_library "" CACHE INTERNAL "prolog library files")
set(pl_os_library "" CACHE INTERNAL "prolog os files")
@ -396,6 +402,36 @@ if (${C_COMPILER} MATCHES "Intel")
set(HAVE_GCC 1)
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
if (HAVE_GCC)
set_property(DIRECTORY APPEND PROPERTY COMPILE_OPTIONS -Wall)
@ -458,19 +494,19 @@ endif ()
OPTION(WITH_SWIG " Enable SWIG interfaces to foreign languages" ON)
IF (WITH_SWIG OR ANDROID)
IF (WITH_SWIG)
find_host_package(SWIG)
# macro_log_feature (SWIG_FOUND "Swig"
# "Use SWIG Interface Generator "
# "http://www.swig.org" ON)
ENDIF (WITH_SWIG OR ANDROID)
ENDIF (WITH_SWIG)
option(WITH_PYTHON
"Allow Python->YAP and YAP->Python" ON)
IF (WITH_PYTHON)
include(python NO_POLICY_SCOPE)
include(python )
ENDIF (WITH_PYTHON)
@ -528,6 +564,7 @@ endif ()
set(YAP_STARTUP startup.yss)
set(YAP_BOOTFILE boot.yap )
## define system
# 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)
# 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
H/generated
@ -614,11 +630,6 @@ ADD_SUBDIRECTORY(library)
ADD_SUBDIRECTORY(swi/library "swiLibrary")
if (ANDROID)
target_link_libraries(libYap android log)
endif ()
set_target_properties(libYap
PROPERTIES OUTPUT_NAME Yap
)
@ -638,8 +649,9 @@ if (PYTHONLIBS_FOUND AND SWIG_FOUND)
endif ()
IF (SWIG_FOUND OR ANDROID)
add_subDIRECTORY(packages/swig NO_POLICY_SCOPE)
IF ( ANDROID)
add_subDIRECTORY(packages/swig )
target_link_libraries(libYap android log)
ENDIF ()
@ -789,9 +801,9 @@ set_target_properties(yap-bin PROPERTIES OUTPUT_NAME yap)
target_link_libraries(yap-bin libYap)
install(TARGETS libYap yap-bin
RUNTIME DESTINATION ${bindir}
LIBRARY DESTINATION ${libdir}
ARCHIVE DESTINATION ${libdir}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_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
"NOT WITH_YAPOR_THOR; NOT WITH_SYSTEM_MMAP" OFF)
if (NOT ANDROID)
add_subDIRECTORY(library/lammpi)
if (MPI_C_FOUND)
@ -822,19 +836,26 @@ if (MPI_C_FOUND)
endif ()
endif (MPI_C_FOUND)
endif(NOT ANDROID)
## add_subDIRECTORY(utils)
#
install(FILES ${INCLUDE_HEADERS} ${CONFIGURATION_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/Yap )
macro_display_feature_log()
if (POLICY CMP0058)
cmake_policy(SET CMP0058 NEW)
endif (POLICY CMP0058)
include(Config NO_POLICY_SCOPE)
include(Config )
feature_summary(WHAT ENABLED_FEATURES DISABLED_FEATURES
INCLUDE_QUIET_PACKAGES
)

View File

@ -18,9 +18,9 @@ else()
MY_target_link_libraries(YAP++ ${CMAKE_DL_LIBS} libYap)
MY_install(TARGETS YAP++
LIBRARY DESTINATION ${libdir}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${libdir}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
endif()

View File

@ -88,7 +88,9 @@ protected:
PredEntry *ap;
/// 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; };
@ -122,7 +124,7 @@ protected:
///
/// It is just a call to getPred
inline YAPPredicate(Term t) {
CELL *v = NULL;
CELL *v = nullptr;
YAPTerm tt = YAPTerm(t);
ap = getPred(tt, v);
}
@ -131,7 +133,7 @@ protected:
///
/// It is just a call to getPred
inline YAPPredicate(YAPTerm t) {
Term *v = nullptr;
CELL *v = nullptr;
ap = getPred(t, v);
}
@ -275,13 +277,13 @@ public:
*/
class X_API YAPFLIP : public YAPPredicate {
public:
YAPFLIP(CPredicate call, YAPAtom name, uintptr_t arity,
YAPModule module = YAPModule(), CPredicate retry = 0,
CPredicate cut = 0, size_t extra = 0, bool test = false)
YAPFLIP(YAP_UserCPred call, YAPAtom name, YAP_Arity arity,
YAPModule module = YAPModule(), YAP_UserCPred retry = 0,
YAP_UserCPred cut = 0, YAP_Arity extra = 0, bool test = false)
: YAPPredicate(name, arity, module) {
if (retry) {
Yap_InitCPredBackCut(name.getName(), arity, extra, call, retry, cut,
UserCPredFlag);
YAP_UserBackCutCPredicate(name.getName(), call, retry, cut, arity, extra
);
} else {
if (test) {
YAP_UserCPredicate(name.getName(), call, arity);

View File

@ -12,14 +12,14 @@ extern "C" {
#include "YapInterface.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);
X_API void YAP_UserCPredicate(const char *, YAP_UserCPred, arity_t arity);
X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred, arity_t,
YAP_Term);
X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred, YAP_UserCPred,
arity_t, arity_t);
YAP_Arity, YAP_Arity);
#if YAP_PYTHON
X_API bool do_init_python(void);
@ -625,7 +625,7 @@ Term YAPEngine::fun(Term t)
return 0;
}
DBTerm *pt = Yap_StoreTermInDB(Yap_GetFromSlot(o), arity);
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %ld", o);
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "out %d", o);
YAP_LeaveGoal(false, &q);
Yap_CloseHandles(q.CurSlot);
Term rc = Yap_PopTermFromDB(pt);
@ -751,8 +751,8 @@ bool YAPQuery::next()
}
if (result)
{
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %d %s %ld",
q_state, vnames.text(), LOCAL_CurSlot);
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "vnames %d %s %d",
q_state, names.text(), LOCAL_CurSlot);
}
else
{
@ -892,6 +892,8 @@ static size_t Yap_AndroidMax, Yap_AndroidSz;
extern void (*Yap_DisplayWithJava)(int c);
static YAPCallback *cb = new YAPCallback();
void Yap_displayWithJava(int c)
{
char *ptr = Yap_AndroidBufp;
@ -914,57 +916,56 @@ void Yap_displayWithJava(int c)
if (c == '\n')
{
Yap_AndroidBufp[Yap_AndroidSz] = '\0';
curren->run(Yap_AndroidBufp);
cb->run(Yap_AndroidBufp);
Yap_AndroidSz = 0;
}
}
#endif
void YAPEngine::doInit(YAP_file_type_t BootMode)
{
if ((BootMode = YAP_Init(&engine_args->init_args)) == YAP_FOUND_BOOT_ERROR)
if ((BootMode = YAP_Init(engine_args)) == YAP_FOUND_BOOT_ERROR)
{
return;
throw YAPError();
}
/* Begin preprocessor code */
/* 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();
#if YAP_PYTHON
do_init_python();
#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);
if (initq.next())
{
initq.cut();
initq.cut();
}
CurrentModule = TermUser;
}
YAPEngine::YAPEngine(int argc, char *argv[],
YAPCallback *cb)
YAPCallback *cb)
: _callback(0) { // a single engine can be active
YAP_file_type_t BootMode;
engine_args = new YAPEngineArgs();
BootMode = YAP_parse_yap_arguments(argc, argv, &engine_args->init_args);
BootMode = YAP_parse_yap_arguments(argc, argv, engine_args);
// delYAPCallback()b
// if (cb)
// setYAPCallback(cb);
doInit(BootMode);
doInit(BootMode);
}
YAPPredicate::YAPPredicate(YAPAtom at)
{
CACHE_REGS
@ -986,7 +987,7 @@ YAPEngine::YAPEngine(int argc, char *argv[],
}
/// 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
Term m = Yap_CurrentModule(), t = tt.term();
@ -1009,9 +1010,11 @@ YAPEngine::YAPEngine(int argc, char *argv[],
else if (IsPairTerm(t))
{
Term ts[2];
ts[0] = t;
ts[1] = m;
t = Yap_MkApplTerm(FunctorCsult, 2, ts);
Functor FunctorConsult = Yap_MkFunctor(Yap_LookupAtom("consult"), 1);
ts[1] = t;
ts[0] = m;
t = Yap_MkApplTerm(FunctorModule, 2, ts);
t = Yap_MkApplTerm(FunctorConsult, 1, &t);
tt.put(t);
outp = RepAppl(t) + 1;
}
@ -1104,7 +1107,7 @@ YAPEngine::YAPEngine(int argc, char *argv[],
if (LOCAL_ActiveError->prologPredLine)
{
s += "\n";
s += LOCAL_ActiveError->prologPredFile->StrOfAE;
s += LOCAL_ActiveError->prologPredFile;
s += ":";
sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredLine);
s += buf; // std::to_string(LOCAL_ActiveError->prologPredLine) ;
@ -1112,7 +1115,7 @@ YAPEngine::YAPEngine(int argc, char *argv[],
s += ":0 ";
s += LOCAL_ActiveError->prologPredModule;
s += ":";
s += (LOCAL_ActiveError->prologPredName)->StrOfAE;
s += (LOCAL_ActiveError->prologPredName);
s += "/";
sprintf(buf, "%ld", (long int)LOCAL_ActiveError->prologPredArity);
s += // std::to_string(LOCAL_ActiveError->prologPredArity);
@ -1120,13 +1123,13 @@ YAPEngine::YAPEngine(int argc, char *argv[],
}
s += " error ";
if (LOCAL_ActiveError->classAsText != nullptr)
s += LOCAL_ActiveError->classAsText->StrOfAE;
s += LOCAL_ActiveError->classAsText;
s += ".";
s += LOCAL_ActiveError->errorAsText->StrOfAE;
s += LOCAL_ActiveError->errorAsText;
s += ".\n";
if (LOCAL_ActiveError->errorTerm)
{
Term t = LOCAL_ActiveError->errorTerm->Entry;
Term t = Yap_PopTermFromDB(LOCAL_ActiveError->errorTerm);
if (t)
{
s += "error term is: ";

View File

@ -85,8 +85,16 @@ X_API extern void YAP_UserCPredicate(const char *, YAP_UserCPred,
X_API extern void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred,
YAP_Arity, YAP_Term);
X_API extern void UserBackCPredicate(const char *name, int *init(), int *cont(),
int arity, int extra);
X_API extern void YAP_UserBackCPredicate(const char *name,
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);

View File

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

View File

@ -112,7 +112,18 @@ public:
inline Term term() {
return gt();
} /// from YAPTerm to Term (internal YAP representation)
inline void bind(Term b) { LOCAL_HandleBase[t] = b; }
YAPTerm arg(int i) {
BACKUP_MACHINE_REGS();
Term t0 = gt();
YAPTerm tf;
if (!IsApplTerm(t0) && !IsPairTerm(t))
return (Term)0;
tf = YAPTerm(ArgOfTerm(i, t0) );
RECOVER_MACHINE_REGS();
return tf;
};
inline void bind(Term b) { LOCAL_HandleBase[t] = b; }
inline void bind(YAPTerm *b) { LOCAL_HandleBase[t] = b->term(); }
/// from YAPTerm to Term (internal YAP representation)
/// fetch a sub-term
@ -183,7 +194,7 @@ public:
virtual bool isGround() { return Yap_IsGroundTerm(gt()); } /// term is ground
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) {
BACKUP_MACHINE_REGS();
Term tf = 0;
@ -230,7 +241,7 @@ public:
char *os;
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();
return 0;
}
@ -324,7 +335,7 @@ public:
RECOVER_MACHINE_REGS();
return tf;
};
virtual bool isVar() { return false; } /// type check for unbound
virtual bool isVar() { return false; } /// type check for unbound
virtual bool isAtom() { return false; } /// type check for atom
virtual bool isInteger() { return false; } /// type check for integer
virtual bool isFloat() { return false; } /// type check for floating-point
@ -354,6 +365,9 @@ public:
YAPPairTerm();
Term getHead() { return (HeadOfTerm(gt())); }
Term getTail() { return (TailOfTerm(gt())); }
YAPTerm car() { return YAPTerm(HeadOfTerm(gt())); }
bool nil() { return gt() == TermNil; }
YAPPairTerm cdr() { return YAPPairTerm(TailOfTerm(gt())); }
std::vector<Term> listToArray() {
Term *tailp;
Term t1 = gt();
@ -479,7 +493,7 @@ public:
* Term Representation of an Atom
*/
class X_API YAPAtomTerm : public YAPTerm {
friend class YAPModule;
friend class YAPModule;
// Constructor: receives a C-atom;
YAPAtomTerm(Term t) : YAPTerm(t) { IsAtomTerm(t); }
@ -487,15 +501,17 @@ public:
YAPAtomTerm(Atom a) { mk(MkAtomTerm(a)); }
// Constructor: receives an atom;
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[]);
// 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);
// Constructor: receives a sequence of wchar_ts, whatever they may be;
YAPAtomTerm(wchar_t *s);
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
YAPAtomTerm(wchar_t *s, size_t len);
bool isVar() { return false; } /// type check for unbound
// Constructor: receives a sequence of n wchar_ts, whatever they may be;
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 isAtom() { return true; } /// type check for atom
bool isInteger() { return false; } /// type check for integer
bool isFloat() { return false; } /// type check for floating-point

View File

@ -96,7 +96,7 @@ typedef struct ExtraAtomEntryStruct {
#define USE_OFFSETS_IN_PROPS 0
#endif
typedef SFLAGS PropFlags;
typedef CELL PropFlags;
/* basic property entry structure */
typedef struct PropEntryStruct {

View File

@ -151,6 +151,9 @@ typedef void *(*fptr_t)(void);
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 */
#include "YapDefs.h"

View File

@ -193,8 +193,8 @@ static inline Term options(Term inp) {
return Yap_IsGroundTerm(inp) ? inp : TermZERO;
}
static inline Term rootdir(Term inp) {
return MkAtomTerm(Yap_LookupAtom(YAP_ROOTDIR));
static inline const char * rootdir(Term inp) {
return Yap_ROOTDIR;
}
// INLINE_ONLY inline EXTERN Term ok( Term inp );

View File

@ -236,7 +236,7 @@ process, namely, on choice-points.
YAP_FLAG(GMP_VERSION_FLAG, "gmp_version", false, isatom, "4.8.12", NULL),
YAP_FLAG(HALT_AFTER_CONSULT_FLAG, "halt_after_consult", false, booleanFlag,
"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
`c:\Yap` in Windows system. Can only be set at configure time

View File

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

View File

@ -292,6 +292,9 @@ extern void Yap_InitInlines(void);
extern int Yap_eq(Term, Term);
/* 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_InitBackIO(void);
extern void Yap_InitIOPreds(void);
@ -306,7 +309,6 @@ extern void Yap_CloseReadline(void);
extern bool Yap_InitReadline(Term t);
extern void Yap_InitItDeepenPreds(void);
extern struct AliasDescS *Yap_InitStandardAliases(void);
extern struct vfs *Yap_InitAssetManager(void);
/* load_foreign.c */
extern void Yap_InitLoadForeign(void);
@ -355,16 +357,16 @@ extern void Yap_InitReadUtil(void);
/* qly.c */
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);
/* range.c */
extern void Yap_InitRange(void);
/* save.c */
extern int Yap_SavedInfo(const char *, const char *, CELL *, CELL *, CELL *);
extern int Yap_SavedStateRestore(char *, char *);
extern FILE *Yap_OpenRestore(const char *, const char *);
extern int Yap_SavedInfo(const char *, CELL *, CELL *, CELL *);
extern int Yap_SavedStateRestore(char *);
extern FILE *Yap_OpenRestore(const char *);
extern void Yap_InitSavePreds(void);
/* scanner.c */
@ -417,7 +419,7 @@ extern AAssetManager *Yap_assetManager;
extern void *Yap_openAssetFile(const char *path);
extern bool Yap_isAsset(const char *path);
#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_systime_interval(Int *, Int *);
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_AbsoluteFileInBuffer(const char *spec, char *outp, size_t sz,
bool ok);
extern const char *Yap_findFile(const char *isource, const char *idef,
const char *root, char *result, bool access,
YAP_file_type_t ftype, bool expand_root, bool in_lib);
extern bool Yap_ChDir(const char *path);
bool Yap_isDirectory(const char *FileName);
extern bool Yap_Exists(const char *f);
/* threads.c */
extern void Yap_InitThreadPreds(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 struct AtomEntryStruct *Yap_lookupBlob(void *blob, size_t len, void *type,
int *newp);
extern void *Yap_RepStreamFromId(int sno);
/* opt.preds.c */
extern void Yap_init_optyap_preds(void);

View File

@ -1306,10 +1306,10 @@ void Yap_UpdateTimestamps(PredEntry *);
void Yap_ErDBE(DBRef);
DBTerm *Yap_StoreTermInDB(Term, int);
DBTerm *Yap_StoreTermInDBPlusExtraSpace(Term, UInt, UInt *);
Term Yap_FetchTermFromDB(DBTerm *);
Term Yap_FetchClauseTermFromDB(DBTerm *);
Term Yap_PopTermFromDB(DBTerm *);
void Yap_ReleaseTermFromDB(DBTerm *);
Term Yap_FetchTermFromDB(void *);
Term Yap_FetchClauseTermFromDB(void *);
Term Yap_PopTermFromDB(void *);
void Yap_ReleaseTermFromDB(void *);
/* init.c */
Atom Yap_GetOp(OpEntry *, int *, int);
@ -1598,8 +1598,8 @@ bool Yap_PutException(Term t);
INLINE_ONLY inline EXTERN bool Yap_HasException(void) {
return LOCAL_BallTerm != NULL;
}
INLINE_ONLY inline EXTERN DBTerm *Yap_RefToException(void) {
DBTerm *dbt = LOCAL_BallTerm;
INLINE_ONLY inline EXTERN void *Yap_RefToException(void) {
void *dbt = LOCAL_BallTerm;
LOCAL_BallTerm = NULL;
return dbt;
}

View File

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

273190
TAGS

File diff suppressed because one or more lines are too long

View File

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

View File

@ -131,7 +131,6 @@ BEAM/beam.h
${CMAKE_SOURCE_DIR}/H/YapOpcodes.h
${CMAKE_SOURCE_DIR}/H/YapSignals.h
${CMAKE_SOURCE_DIR}/H/YapTags.h
${CMAKE_SOURCE_DIR}/H/YapTerm.h
${CMAKE_SOURCE_DIR}/H/YapText.h
${CMAKE_SOURCE_DIR}/H/Yapproto.h
${CMAKE_SOURCE_DIR}/H/Yatom.h
@ -206,6 +205,7 @@ set (INCLUDE_HEADERS
${CMAKE_SOURCE_DIR}/include/YapInterface.h
${CMAKE_SOURCE_DIR}/include/YapRegs.h
${CMAKE_SOURCE_DIR}/include/YapStreams.h
${CMAKE_SOURCE_DIR}/include/YapTerm.h
${CMAKE_SOURCE_DIR}/include/blobs.h
${CMAKE_SOURCE_DIR}/include/c_interface.h
${CMAKE_SOURCE_DIR}/include/clause_list.h

View File

@ -1,4 +1,5 @@
/*--------------------------------------------------------------------------
* This file is autogenerated from config.h.in
* during the cmake configuration of your project. If you need to make changes
@ -1360,6 +1361,11 @@ signal. */
#cmakedefine HAVE_STRNLEN ${HAVE_STRNLEN}
#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. */
#ifndef 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}"
#endif
/* saved state file */
#ifndef YAP_BOOTFILE
#define YAP_BOOTFILE "${YAP_BOOTFILE}"
#endif
/* date of compilation */
#ifndef YAP_TIMESTAMP
#define YAP_TIMESTAMP ${YAP_TIMESTAMP}
@ -1964,7 +1975,7 @@ significant byte first (like Motorola and SPARC, unlike Intel). */
#endif
#ifndef YAP_IS_MOVABLE
/* name of YAP instaii */
#ifndef YAP_ROOTDIR
#define YAP_ROOTDIR "${YAP_ROOTDIR}"
@ -1972,17 +1983,17 @@ significant byte first (like Motorola and SPARC, unlike Intel). */
/* name of YAP binaries */
#ifndef YAP_BINDIR
#define YAP_BINDIR "${YAP_ROOTDIR}/bin"
#define YAP_BINDIR "${YAP_BINDIR}"
#endif
/* name of YAP library */
#ifndef YAP_LIBDIR
#define YAP_LIBDIR "${YAP_ROOTDIR}/lib"
#define YAP_LIBDIR "${YAP_LIBDIR}"
#endif
/* name of YAP DLL library */
#ifndef YAP_YAPLIB
#define YAP_YAPLIB "${YAP_LIBDIR}/Yap"
#ifndef YAP_DLLDIR
#define YAP_DLLDIR "${YAP_LIBDIR}/Yap"
#endif
/* name of YAP JIT library */
@ -1994,13 +2005,14 @@ significant byte first (like Motorola and SPARC, unlike Intel). */
#define YAP_SHAREDIR "${YAP_ROOTDIR}/share"
#endif
#else
extern char
*YAP_BINDIR,
*YAP_ROOTDIR,
*YAP_SHAREDIR,
*YAP_LIBDIR,
*YAP_YAPLIB;
/* name of YAP PL library */
#ifndef YAP_PLDIR
#define YAP_PLDIR "${YAP_SHAREDIR}/Yap"
#endif
/* name of Commons library */
#ifndef YAP_COMMONSDIR
#define YAP COMMONSDIR "${YAP_SHAREDIR}/PrologCommmons"
#endif

View File

@ -58,7 +58,7 @@ include_directories(../../CXX)
install(TARGETS qtyap
RUNTIME DESTINATION ${bindir}
RUNTIME DESTINATION ${CMAKE_INSTALL_FULL_BIINDIR}
)
ENDIF(Qt5Widgets_FOUND)

View File

@ -105,13 +105,15 @@ static void exec_top_level(int BootMode, YAP_init_args *iap) {
YAP_Reset(YAP_FULL_RESET);
do_top_goal(YAP_MkAtomTerm(livegoal));
livegoal = YAP_FullLookupAtom("$live");
}
YAP_Exit(EXIT_SUCCESS);
}
YAP_Exit(EXIT_SUCCESS);
}
// FILE *debugf;
#ifdef LIGHT
int _main(int argc, char **argv)
#else
int main(int argc, char **argv)
@ -121,6 +123,7 @@ int main(int argc, char **argv)
int i;
YAP_init_args init_args;
BootMode = init_standard_system(argc, argv, &init_args);
if (BootMode == YAP_BOOT_ERROR) {
fprintf(stderr, "[ FATAL ERROR: could not find saved state ]\n");
exit(1);

View File

@ -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:

View File

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

View File

@ -50,23 +50,10 @@
#include <stdio.h>
#include <stdlib.h>
#ifdef YAP_H
/* The YAP main types */
#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
#include <stdint.h>
#endif
@ -74,21 +61,6 @@
#include <inttypes.h>
#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,
still widely used.
@ -103,79 +75,26 @@ typedef int _Bool;
typedef bool YAP_Bool;
#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
#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 void *YAP_PredEntryPtr;
typedef size_t YAP_Arity;
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 struct YAP_pred_entry *YAP_PredEntryPtr;
typedef void *YAP_PredEntryPtr;
typedef YAP_Bool (*YAP_UserCPred)(void);
@ -187,6 +106,9 @@ typedef int (*YAP_agc_hook)(void *_Atom);
typedef encoding_t YAP_encoding_t;
#if __ANDROID__
#include <android/asset_manager.h>
#include <android/native_activity.h>
#endif
typedef struct YAP_thread_attr_struct {
@ -207,10 +129,11 @@ typedef enum {
YAP_SAVED_STATE = 0x0004,
YAP_OBJ = 0x0008,
YAP_PL = 0x0010,
YAP_BOOT_PL = 0x0030,
YAP_BOOT_PL = 0x0030,
YAP_QLY = 0x0040,
YAP_EXE = 0x0080,
YAP_FOUND_BOOT_ERROR = 0x0100
YAP_FOUND_BOOT_ERROR = 0x0100,
YAP_DIR = 0x0200
} YAP_file_type_t;
#define YAP_ANY_FILE (0x00ff)
@ -252,9 +175,15 @@ typedef enum {
#define YAP_RECONSULT_MODE 1
#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 {
//> boot type as suggested by the user
YAP_file_type_t boot_file_type;
//> boot type as suggested by the user
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
const char *SavedState;
//> if NON-0, minimal size for Heap or Code Area
@ -275,10 +204,16 @@ typedef struct yap_boot_params {
size_t AttsSize;
//> if NON-0, maximal size for AttributeVarStack
size_t MaxAttsSize;
//> if NON-NULL, value for YAPLIBDIR
const char *YapLibDir;
//> if NON-NULL, value for YAPSSHAREDIR, that is, default value for libraries
const char *YapShareDir;
//> if NON-NULL, value for YAPROOTDIR
const char *YapRootDir;
//> if NON-NULL, value for YAPLIBDIR
const char *YapLibDir;
//> if NON-NULL, value for YAPSHAREDIR, that is, default value for libraries
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
const char *YapPrologBootFile;
//> if NON-NULL, name for a Prolog file to use when initializing
@ -322,6 +257,10 @@ typedef struct yap_boot_params {
int QuietMode;
//> 0, maintain default, > 0 use fd-1, < 0 close
int inp, out, err;
#if __ANDROID__
//> android asset support
AAssetManager *assetManager;
#endif
/* support nf's ypp preprocessor code */
#define YAP_MAX_YPP_DEFS 100
char *def_var[YAP_MAX_YPP_DEFS];
@ -344,11 +283,6 @@ typedef struct yap_boot_params {
char *ErrorCause;
} 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 */
typedef struct {
unsigned long b; //> choice-point at entry

View File

@ -176,51 +176,51 @@ INLINE_ONLY extern inline Term Yap_ensure_atom__(const char *fu, const char *fi,
/// go back t
} yap_error_stage_t;
/// a Prolo goal that caused a bug
/// a Prolog goal that caused a bug
typedef struct error_prolog_source {
YAP_Int prologPredCl;
YAP_UInt prologPredLine;
YAP_UInt prologPredFirstLine;
YAP_UInt prologPredLastLine;
YAP_Atom prologPredName;
YAP_UInt prologPredArity;
YAP_Term prologPredModule;
YAP_Atom prologPredFile;
struct DB_TERM *errorGoal;
typedef struct yap_error_prolog_source {
intptr_t prologPredCl;
uintptr_t prologPredLine;
uintptr_t prologPredFirstLine;
uintptr_t prologPredLastLine;
const char * prologPredName;
uintptr_t prologPredArity;
const char * prologPredModule;
const char * prologPredFile;
void *errorGoal;
struct error_prolog_source *errorParent;
} error_prolog_source_t;
} yap_error_prolog_source_t;
/// 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;
yap_error_class_number errorClass;
YAP_Atom errorAsText;
YAP_Atom classAsText;
const char * errorAsText;
const char * classAsText;
yap_error_number errorNo;
YAP_Int errorLine;
intptr_t errorLine;
const char *errorFunction;
const char *errorFile;
// struct error_prolog_source *errorSource;
YAP_Int prologPredCl;
YAP_UInt prologPredLine;
YAP_UInt prologPredFirstLine;
YAP_UInt prologPredLastLine;
YAP_Atom prologPredName;
YAP_UInt prologPredArity;
YAP_Term prologPredModule;
YAP_Atom prologPredFile;
YAP_UInt prologParserLine;
YAP_UInt prologParserFirstLine;
YAP_UInt prologParserLastLine;
YAP_Atom prologParserName;
YAP_Atom prologParserFile;
YAP_Bool prologConsulting;
struct DB_TERM *errorTerm;
YAP_Term rawErrorTerm, rawExtraErrorTerm;
intptr_t prologPredCl;
uintptr_t prologPredLine;
uintptr_t prologPredFirstLine;
uintptr_t prologPredLastLine;
const char * prologPredName;
uintptr_t prologPredArity;
const char * prologPredModule;
const char * prologPredFile;
uintptr_t prologParserLine;
uintptr_t prologParserFirstLine;
uintptr_t prologParserLastLine;
const char * prologParserName;
const char * prologParserFile;
bool prologConsulting;
void *errorTerm;
uintptr_t rawErrorTerm, rawExtraErrorTerm;
char *errorMsg;
size_t errorMsgLen;
struct yap_error_descriptor *top_error;
struct s_yap_error_descriptor *top_error;
} yap_error_descriptor_t;
/// compatibility with existing code..

View File

@ -268,18 +268,19 @@ extern X_API void YAP_UserCPredicateWithArgs(const char *, YAP_UserCPred,
extern X_API void YAP_UserBackCPredicate(const char *, YAP_UserCPred,
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(),
int
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_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) */
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
/// 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);
@ -474,6 +475,16 @@ extern X_API void YAP_SetOutputMessage(void);
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_FlushAllStreams(void);

View File

@ -136,9 +136,9 @@ FILE *open_memstream(char **buf, size_t *len);
#endif
#if __ANDROID__
#undef HAVE_FMEMOPEN
#undef HAVE_OPEN_MEMSTREAM
//extern FILE * fmemopen(void *buf, size_t size, const char *mode);
#define HAVE_FMEMOPEN 1
#define HAVE_OPEN_MEMSTREAM 1
#endif
#if HAVE_FMEMOPEN

View File

@ -17,9 +17,6 @@
#include "YapTermConfig.h"
#include "config.h"
typedef void *Functor;
typedef void *Atom;
#endif
#if HAVE_STDINT_H
@ -29,6 +26,22 @@ typedef void *Atom;
#include <inttypes.h>
#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) \
(((CELL)(X) + (sizeof(TYPE) - 1)) & ~(sizeof(TYPE) - 1))
@ -45,59 +58,98 @@ typedef void *Atom;
#if defined(PRIdPTR)
typedef intptr_t Int;
typedef uintptr_t UInt;
typedef intptr_t YAP_Int;
typedef uintptr_t YAP_UInt;
#elif defined(_WIN64)
typedef int64_t Int;
typedef uint64_t UInt;
typedef int64_t YAP_Int;
typedef uint64_t YAP_UInt;
#elif defined(_WIN32)
typedef int32_t Int;
typedef uint32_t UInt;
typedef int32_t YAP_Int;
typedef uint32_t YAP_UInt;
#elif SIZEOF_LONG_INT == SIZEOF_INT_P
typedef long int Int;
typedef unsigned long int UInt;
typedef long int YAP_Int;
typedef unsigned long int YAP_UInt;
#elif SIZEOF_INT == SIZEOF_INT_P
typedef int Int;
typedef unsigned int UInt;
typedef int YAP_Int;
typedef unsigned int YAP_UInt;
#else
#error Yap require integer types of the same size as a pointer
#endif
/* */ typedef short int Short;
/* */ typedef unsigned short int UShort;
/* */ typedef short int YAP_Short;
/* */ 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 int16_t SBITS16;
typedef uint32_t BITS32;
typedef YAP_CELL CELL;
typedef YAP_Term Term;
#define WordSize sizeof(BITS16)
#define CellSize sizeof(CELL)
#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"
/*************************************************************************************************
type casting macros
*************************************************************************************************/
typedef UInt Term;
typedef Int yhandle_t;
typedef double Float;
#if SIZEOF_INT < SIZEOF_INT_P
#define SHORT_INTS 1
#else

View File

@ -19,4 +19,4 @@ cd $PREFIX/conda
# Remove the created lib64 directory
rm -rf $PREFIX/conda
rm -rf $PREFIX/conda

View File

@ -9,6 +9,7 @@ requirements:
- cmake
- swig
- gmp
- ninja
- readline
- python
- r
@ -16,8 +17,7 @@ requirements:
- pkgconfig
- make
run:
- python
- pythonlab
- jupyterlab
- readline
- gmp
- r

View File

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

View File

@ -3142,7 +3142,7 @@ term_t Yap_CvtTerm(term_t ts) {
}
char *PL_cwd(char *cwd, size_t cwdlen) {
return (char *)Yap_getcwd((const char *)cwd, cwdlen);
return (char *)Yap_getcwd(cwd, cwdlen);
}
/**

View File

@ -78,9 +78,9 @@ if (MPI_C_FOUND)
add_definitions (-DHAVE_MPI_H=1)
install(TARGETS yap_mpi
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
)
endif (MPI_C_FOUND)

View File

@ -15,8 +15,8 @@ if (MATLAB_FOUND)
target_link_libraries(matlab libYap $(MATLAB_LIBRARIES) )
install(TARGETS matlab
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls} )
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} )
endif (MATLAB_FOUND)

View File

@ -6,8 +6,8 @@ target_link_libraries(matrix libYap)
set_target_properties (matrix PROPERTIES PREFIX "")
install(TARGETS matrix
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls}
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
)

View File

@ -10,5 +10,5 @@ set_target_properties (yap_random PROPERTIES PREFIX "")
endif()
MY_install(TARGETS yap_random
LIBRARY DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls} )
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} )

View File

@ -26,6 +26,6 @@ TARGET_INCLUDE_DIRECTORIES (regexp PUBLIC BEFORE
${CMAKE_TOP_SOURCE_DIR}/include;${CMAKE_CURRENT_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR} )
install(TARGETS regexp
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls} )
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} )

View File

@ -11,6 +11,6 @@ target_link_libraries(yap_rl libYap)
set_target_properties (yap_rl PROPERTIES PREFIX "")
install(TARGETS yap_rl
LIBRARY DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls} )
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} )

View File

@ -39,8 +39,8 @@ set_target_properties (sys PROPERTIES PREFIX "")
endif()
MY_install(TARGETS sys
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls} )
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} )
configure_file ("sys_config.h.cmake" "sys_config.h" )

View File

@ -13,9 +13,9 @@ target_link_libraries(tries libYap)
set_target_properties (tries PROPERTIES PREFIX "")
install(TARGETS tries
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls})
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR})
set ( ITRIES_SOURCES
@ -34,7 +34,7 @@ target_link_libraries(itries libYap)
set_target_properties (itries PROPERTIES PREFIX "")
install(TARGETS itries
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls} )
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} )

View File

@ -7,7 +7,10 @@ set (YAPOS_SOURCES
console.c
files.c
fmem.c
fmemopen.c
# fmemopen.c
#android/fmemopen.c
# android/fopencookie.c
# android/open_memstream.c
format.c
iopreds.c
mem.c

View File

@ -33,214 +33,192 @@ static char SccsId[] = "%W% %G%";
// for native asset manager
#include <sys/types.h>
#if __ANDROID__0
#if __ANDROID__
static AAssetManager * getMgr(struct vfs *me)
{
return me->priv[0].mgr;
#include <android/asset_manager.h>
#include <android/native_activity.h>
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;
}
void
Java_pt_up_yap_app_YAPDroid_load(JNIEnv *env,
jobject assetManager) {
AAssetManager *mgr = AAssetManager_fromJava(env, assetManager);
if (mgr == NULL) {
return;
}
VFS_t *me = GLOBAL_VFS;
while ( strcmp(me->name, "/assets") == 0)
me = me->next;
me->priv[0].mgr = mgr;
}
static bool
open_asset(struct vfs *me, struct stream_desc *st, const char *fname, const char
*io_mode)
{
AAssetManager *mgr;
int mode;
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);
}
static void *
open_asset__(VFS_t *me, int sno, const char *fname, const char *io_mode) {
int mode;
const void *buf;
if (strchr(io_mode, 'B'))
mode = AASSET_MODE_BUFFER;
else
{
mode = AASSET_MODE_UNKNOWN;
}
AAsset *a = AAssetManager_open(mgr , fname, mode);
mode = AASSET_MODE_BUFFER;
else {
mode = AASSET_MODE_UNKNOWN;
}
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
off64_t sz = AAsset_getLength64(a), sz0 = 0;
int fd;
if ((fd = AAsset_openFileDescriptor64(a, &sz0, &sz)) >= 0) {
// can use it as red-only file
st->file = fdopen( fd, "r");
st->vfs = me;
st->vfs_handle = a;
return true;
} else if ((buf = AAsset_getBuffer(a)) ) {
// copy to memory
bool rc = Yap_set_stream_to_buf(st, buf, sz);
AAsset_close(a);
return rc;
StreamDesc *st = GLOBAL_Stream + sno;
if ((buf = AAsset_getBuffer(a))) {
// copy to memory
bool rc = Yap_set_stream_to_buf(st, buf, sz);
if (rc) AAsset_close(a);
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
GLOBAL_Stream[sno].vfs_handle = a;
st->vfs = me;
st->status = Input_Stream_f;
return a;
}
// should be done, but if not
st->vfs_handle = a;
st->vfs = me;
return true;
}
if (me->next) {
return me->next->open(me->next, st, fname, io_mode);
}
return NULL;
}
static bool
close_asset(struct stream_desc *st)
{
AAsset_close(st->vfs_handle);
return true;
close_asset(int sno) {
AAsset_close(GLOBAL_Stream[sno].vfs_handle);
return true;
}
static int64_t seek64(struct stream_desc *st, int64_t offset, int whence)
{
return AAsset_seek64(st->vfs_handle, offset, whence);
static int64_t seek64(int sno, int64_t offset, int whence) {
return AAsset_seek64(GLOBAL_Stream[sno].vfs_handle, offset, whence);
}
static int getc_asset(struct stream_desc *st)
{
int ch;
if ( AAsset_read (st->vfs_handle, &ch, 1) )
return ch;
return -1;
static int getc_asset(int sno) {
int ch;
if (AAsset_read(GLOBAL_Stream[sno].vfs_handle, &ch, 1))
return ch;
return -1;
}
static void *opendir_a(struct vfs *me, const char *dirName)
{
return (void *)AAssetManager_openDir (getMgr(me), dirName);
static void *opendir_a(VFS_t *me, const char *dirName) {
dirName += strlen(me->prefix) + 1;
return (void *) AAssetManager_openDir(Yap_assetManager, dirName);
}
static const char *readdir_a(void *dirHandle)
{
return AAssetDir_getNextFileName ((AAssetDir *)dirHandle);
static const char *readdir_a(void *dirHandle) {
return AAssetDir_getNextFileName((AAssetDir *) dirHandle);
}
static bool closedir_a(void *dirHandle)
{
AAssetDir_close ((AAssetDir *)dirHandle);
return true;
static bool closedir_a(void *dirHandle) {
AAssetDir_close((AAssetDir *) dirHandle);
return true;
}
static bool stat_a(struct vfs *me, const char *fname, vfs_stat *out)
{
struct stat64 bf;
if (stat64( "/assets", &bf)) {
out->st_dev = bf.st_dev;
out->st_uid = bf.st_uid;
out->st_gid = bf.st_gid;
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_ctimespec, (const void *)&out->st_ctimespec, sizeof(struct timespec));
memcpy(&out->st_birthtimespec, (const void *)&out->st_birthtimespec, sizeof(struct timespec));
}
AAssetManager *mgr = getMgr(me);
AAsset *a = AAssetManager_open(mgr , fname, AASSET_MODE_UNKNOWN);
static bool stat_a(VFS_t *me, const char *fname, vfs_stat *out) {
struct stat bf;
fname += strlen(me->prefix) + 1;
if (stat("/assets", &bf)) {
out->st_dev = bf.st_dev;
out->st_uid = bf.st_uid;
out->st_gid = bf.st_gid;
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_ctimespec, (const void *) &out->st_ctimespec, sizeof(struct timespec));
memcpy(&out->st_birthtimespec, (const void *) &out->st_birthtimespec,
sizeof(struct timespec));
}
AAsset *a = AAssetManager_open(Yap_assetManager, fname, AASSET_MODE_UNKNOWN);
// try not to use it as an asset
out->st_size = AAsset_getLength64(a);
AAsset_close(a);
return true;
out->st_size = AAsset_getLength64(a);
AAsset_close(a);
return true;
}
static
bool is_dir_a(struct vfs *me, const char *dirName)
{
bool rc;
bool is_dir_a(VFS_t *me, const char *dirName) {
bool rc;
dirName += strlen(me->prefix) + 1;
// try not to use it as an asset
AAssetDir *d = AAssetManager_openDir (getMgr(me), dirName);
AAssetDir *d = AAssetManager_openDir(Yap_assetManager, dirName);
if (d == NULL)
return false;
return false;
rc = (AAssetDir_getNextFileName(d) != NULL);
AAssetDir_close(d);
return rc;
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "isdir %s <%p>", dirName, d);
AAssetDir_close(d);
return rc;
}
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
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)
return false;
AAsset_close(d);
return true;
return false;
AAsset_close(d);
return true;
}
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");
if (me->virtual_cwd)
free(me->virtual_cwd);
me->virtual_cwd = malloc( sizeof(dirName) + 1 );
return me!= NULL;
strcpy(virtual_cwd, dirName);
__android_log_print(ANDROID_LOG_INFO, "YAPDroid",
"chdir %s", virtual_cwd);
Yap_do_low_level_trace=1;
return true;
}
#endif
/* create a new alias arg for stream sno */
VFS_t *
Yap_InitAssetManager(void)
{
Yap_InitAssetManager(void) {
#if __ANDROID__O
#if __ANDROID__
VFS_t *me;
/* init standard VFS */
me = (VFS_t *)Yap_AllocCodeSpace(sizeof(struct vfs));
me->name = "/assets";
me->vflags = VFS_CAN_EXEC|VFS_CAN_SEEK|VFS_HAS_PREFIX; /// the main flags describing the operation of the Fs.
me->prefix = "/assets";
/** operations */
me->open = open_asset; /// open an object in this space
me->close= close_asset; /// close the object
me->get_char = getc_asset; /// get an octet to the stream
me->putc = NULL; /// output an octet to the stream
me->seek = seek64; /// jump around the stream
me->opendir = opendir_a; /// open a directory object, if one exists
me->nextdir = readdir_a; /// open a directory object, if one exists
me->closedir = closedir_a; /// close access a directory object
me->stat = stat_a; /// obtain size, age, permissions of a file.
me->isdir = is_dir_a; /// obtain size, age, permissions of a file.
me->exists = exists_a; /// obtain size, age, permissions of a file.
me->chdir = set_cwd; /// chnage working directory.
me->enc = ENC_ISO_UTF8; /// how the file is encoded.
me->parsers = NULL; /// a set of parsers that can read the stream and generate a term
me->writers = NULL;
LOCK(BGL);
me-> next = GLOBAL_VFS;
GLOBAL_VFS = me;
return me;
UNLOCK(BGL);
return me;
/* init standard VFS */
me = (VFS_t *) Yap_AllocCodeSpace(sizeof(struct vfs));
me->name = "/assets";
me->vflags = VFS_CAN_EXEC | VFS_CAN_SEEK |
VFS_HAS_PREFIX; /// the main flags describing the operation of the Fs.
me->prefix = "/assets";
/** operations */
me->open = open_asset__; /// open an object in this space
me->close = close_asset; /// close the object
me->get_char = getc_asset; /// get an octet to the stream
me->put_char = NULL; /// output an octet to the stream
me->seek = seek64; /// jump around the stream
me->opendir = opendir_a; /// open a directory object, if one exists
me->nextdir = readdir_a; /// open a directory object, if one exists
me->closedir = closedir_a; /// close access a directory object
me->stat = stat_a; /// obtain size, age, permissions of a file.
me->isdir = is_dir_a; /// obtain size, age, permissions of a file.
me->exists = exists_a; /// obtain size, age, permissions of a file.
me->chdir = set_cwd; /// chnage working directory.
me->enc = ENC_ISO_UTF8; /// how the file is encoded.
me->parsers = NULL; /// a set of parsers that can read the stream and generate a term
me->writers = NULL;
LOCK(BGL);
me->next = GLOBAL_VFS;
GLOBAL_VFS = me;
return me;
UNLOCK(BGL);
return me;
#else
return NULL;
#endif

View File

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

View File

@ -20,6 +20,11 @@
#define ENCODING_H 1
#include "YapError.h"
#if HAVE_STRING_H
#include <string.h>
#endif
typedef enum {
ENC_OCTET = 0, /// binary files

View File

@ -25,6 +25,7 @@ static char SccsId[] = "%W% %G%";
*/
#include "sysbits.h"
#include "yapio.h"
#if _MSC_VER || defined(__MINGW32__)
#define SYSTEM_STAT _stat
@ -459,7 +460,7 @@ static Int exists_directory(USES_REGS1) {
#if HAVE_STAT
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) {
/* ignore errors while checking a file */
return false;
@ -482,7 +483,7 @@ static Int is_absolute_file_name(USES_REGS1) { /* file_base_name(Stream,N) */
int l = push_text_stack();
const char *buf = Yap_TextTermToText(t PASS_REGS);
if (buf) {
rc = Yap_IsAbsolutePath(buf);
rc = Yap_IsAbsolutePath(buf, true);
} else {
at = AtomOfTerm(t);
#if _WIN32

View File

@ -114,16 +114,18 @@ bool fill_pads(int sno, int sno0, int total, format_info *fg USES_REGS)
return true;
}
bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf, encoding_t enc,
size_t nchars) {
bool Yap_set_stream_to_buf(StreamDesc *st, const char *buf,
size_t nchars USES_REGS) {
FILE *f;
// like any file stream.
st->file = f = fmemopen((void *)buf, nchars, "r");
st->status = Input_Stream_f | InMemory_Stream_f | Seekable_Stream_f;
st->file = f = fmemopen((char *)buf, nchars, "r");
st->status = Input_Stream_f | Seekable_Stream_f | InMemory_Stream_f;
st->vfs = NULL;
st->encoding = enc;
st->encoding = LOCAL_encoding;
Yap_DefaultStreamOps(st);
st->linecount = 0;
st->linepos = st->charcount = 0;
return true;
}
@ -198,9 +200,7 @@ int Yap_open_buf_write_stream(encoding_t enc, memBufSource src) {
// setbuf(st->file, NULL);
st->status |= Seekable_Stream_f;
#else
st->file = fmemopen((void *)buf, nchars, "w");
st->nsize = nchars;
st->nbuf = buf;
st->file = fmemopen((void *)st->nbuf, st->nsize, "w");
if (!st->nbuf) {
return -1;
}
@ -292,17 +292,15 @@ void Yap_MemOps(StreamDesc *st) {
st->stream_getc = PlGetc;
}
static int sssno;
bool Yap_CloseMemoryStream(int sno) {
sssno++;
// if (sssno > 1720) Yap_do_low_level_trace=1;
if ((GLOBAL_Stream[sno].status & Output_Stream_f)) {
if ((GLOBAL_Stream[sno].status & Output_Stream_f) && GLOBAL_Stream[sno].file) {
fflush(GLOBAL_Stream[sno].file);
fclose(GLOBAL_Stream[sno].file);
if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f)
free(GLOBAL_Stream[sno].nbuf);
} else {
if (GLOBAL_Stream[sno].file)
fclose(GLOBAL_Stream[sno].file);
if (GLOBAL_Stream[sno].status & FreeOnClose_Stream_f)
free(GLOBAL_Stream[sno].nbuf);

View File

@ -1,10 +1,12 @@
* Copyright (C) 2007 Eric Blake
/* Copyright (C) 2007 Eric Blake
* Permission to use, copy, modify, and distribute this software
* is freely granted, provided that this notice is preserved.
*
* Modifications for Android written Jul 2009 by Alan Viverette
*/
#if __ANDROID__
/*
FUNCTION
<fmemopen>>---open a stream around a fixed-length string
@ -69,7 +71,7 @@ Supporting OS subroutines required: <<sbrk>>.
#include <errno.h>
#include <string.h>
#include <malloc.h>
#include "stdioext.h"
//#include "stdioext.h"
/* Describe details of an open memstream. */
typedef struct fmemcookie {
@ -172,13 +174,13 @@ fmemseek(void *cookie, fpos_t pos, int whence)
}
else
{
if (c->writeonly &amp;&amp; c->pos < c->eof)
if (c->writeonly && c->pos < c->eof)
{
c->buf[c->pos] = c->saved;
c->saved = '\0';
}
c->pos = offset;
if (c->writeonly &amp;&amp; c->pos < c->eof)
if (c->writeonly && c->pos < c->eof)
{
c->saved = c->buf[c->pos];
c->buf[c->pos] = '\0';
@ -206,9 +208,9 @@ fmemopen(void *buf, size_t size, const char *mode)
int flags;
int dummy;
if ((flags = __sflags (mode, &amp;dummy)) == 0)
if ((flags = __sflags (mode, &dummy)) == 0)
return NULL;
if (!size || !(buf || flags &amp; __SAPP))
if (!size || !(buf || flags & __SAPP))
{
return NULL;
}
@ -225,7 +227,7 @@ fmemopen(void *buf, size_t size, const char *mode)
c->max = size;
/* 9 modes to worry about. */
/* w/a, buf or no buf: Guarantee a NUL after any file writes. */
c->writeonly = (flags &amp; __SWR) != 0;
c->writeonly = (flags & __SWR) != 0;
c->saved = '\0';
if (!buf)
{
@ -233,7 +235,7 @@ fmemopen(void *buf, size_t size, const char *mode)
c->buf = (char *) (c + 1);
*(char *) buf = '\0';
c->pos = c->eof = 0;
c->append = (flags &amp; __SAPP) != 0;
c->append = (flags & __SAPP) != 0;
}
else
{
@ -244,7 +246,7 @@ fmemopen(void *buf, size_t size, const char *mode)
/* a/a+ and buf: position and size at first NUL. */
buf = memchr (c->buf, '\0', size);
c->eof = c->pos = buf ? (char *) buf - c->buf : size;
if (!buf &amp;&amp; c->writeonly)
if (!buf && c->writeonly)
/* a: guarantee a NUL within size even if no writes. */
c->buf[size - 1] = '\0';
c->append = 1;
@ -267,10 +269,12 @@ fmemopen(void *buf, size_t size, const char *mode)
fp->_file = -1;
fp->_flags = flags;
fp->_cookie = c;
fp->_read = flags &amp; (__SRD | __SRW) ? fmemread : NULL;
fp->_write = flags &amp; (__SWR | __SRW) ? fmemwrite : NULL;
fp->_read = flags & (__SRD | __SRW) ? fmemread : NULL;
fp->_write = flags & (__SWR | __SRW) ? fmemwrite : NULL;
fp->_seek = fmemseek;
fp->_close = fmemclose;
return fp;
}
#endif

File diff suppressed because it is too large Load Diff

View File

@ -80,7 +80,7 @@ Int Yap_CloseSocket(int, socket_info, socket_domain);
#endif /* USE_SOCKET */
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 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 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) {
CACHE_REGS
@ -273,7 +273,6 @@ extern FILE *Yap_stderr;
char *Yap_MemExportStreamPtr(int sno);
extern bool Yap_Exists(const char *f);
static inline void freeBuffer(const void *ptr) {
CACHE_REGS
@ -283,8 +282,4 @@ static inline void freeBuffer(const void *ptr) {
free((void *)ptr);
}
/** VFS handling */
VFS_t *Yap_InitAssetManager(void);
#endif

View File

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

View File

@ -829,13 +829,13 @@ static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream,
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
/* preserve value of H after scanning: otherwise we may lose strings
and floats */
LOCAL_tokptr = LOCAL_toktide =
Yap_tokenizer(GLOBAL_Stream + inp_stream, false, &fe->tpos);
Yap_tokenizer(GLOBAL_Stream + sno, false, &fe->tpos);
#if DEBUG
if (GLOBAL_Option[2]) {
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;
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) {
@ -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;
REnv re;
#if EMACS
@ -968,23 +968,23 @@ Term Yap_read_term(int inp_stream, Term opts, bool clause) {
while (true) {
switch (state) {
case YAP_START_PARSING:
state = initParser(opts, &fe, &re, inp_stream, clause);
state = initParser(opts, &fe, &re, sno, clause);
if (state == YAP_PARSING_FINISHED) {
pop_text_stack(lvl);
return 0;
}
break;
case YAP_SCANNING:
state = scan(&re, &fe, inp_stream);
state = scan(&re, &fe, sno);
break;
case YAP_SCANNING_ERROR:
state = scanError(&re, &fe, inp_stream);
state = scanError(&re, &fe, sno);
break;
case YAP_PARSING:
state = parse(&re, &fe, inp_stream);
state = parse(&re, &fe, sno);
break;
case YAP_PARSING_ERROR:
state = parseError(&re, &fe, inp_stream);
state = parseError(&re, &fe, sno);
break;
case YAP_PARSING_FINISHED: {
CACHE_REGS
@ -1021,17 +1021,17 @@ static Int
static Int read_term(
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
int inp_stream;
int sno;
Term out;
/* needs to change LOCAL_output_stream for write */
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
if (inp_stream == -1) {
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
if (sno == -1) {
return (FALSE);
}
out = Yap_read_term(inp_stream, add_output(ARG2, ARG3), false);
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
out = Yap_read_term(sno, add_output(ARG2, ARG3), false);
UNLOCK(GLOBAL_Stream[sno].streamlock);
return out != 0L;
}
@ -1060,7 +1060,7 @@ static const param_t read_clause_defs[] = {READ_CLAUSE_DEFS()};
#undef PAR
static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
int inp_stream) {
int sno) {
CACHE_REGS
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;
}
re->bq = getBackQuotesFlag();
fe->enc = GLOBAL_Stream[inp_stream].encoding;
fe->enc = GLOBAL_Stream[sno].encoding;
fe->sp = 0;
fe->qq = 0;
if (args[READ_CLAUSE_OUTPUT].used) {
@ -1118,12 +1118,12 @@ static xarg *setClauseReadEnv(Term opts, FEnv *fe, struct renv *re,
fe->vp = 0;
}
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 HAVE_FGETPOS
fgetpos(GLOBAL_Stream[inp_stream].file, &re->rpos);
fgetpos(GLOBAL_Stream[sno].file, &re->rpos);
#else
re->cpos = GLOBAL_Stream[inp_stream].charcount;
re->cpos = GLOBAL_Stream[sno].charcount;
#endif
}
re->prio = LOCAL_default_priority;
@ -1166,15 +1166,15 @@ static Int read_clause2(USES_REGS1) {
*/
static Int read_clause(
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
int inp_stream;
int sno;
Term out;
/* needs to change LOCAL_output_stream for write */
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
if (inp_stream < 0)
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
if (sno < 0)
return false;
out = Yap_read_term(inp_stream, add_output(ARG2, ARG3), true);
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
out = Yap_read_term(sno, add_output(ARG2, ARG3), true);
UNLOCK(GLOBAL_Stream[sno].streamlock);
return out != 0;
}
@ -1191,20 +1191,20 @@ static Int read_clause(
*/
#if 0
static Int start_mega(USES_REGS1) {
int inp_stream;
int sno;
Term out;
Term t3 = Deref(ARG3);
yhandle_t h = Yap_InitSlot(ARG2);
TokENtry *tok;
arity_t srity = 0;
/* needs to change LOCAL_output_stream for write */
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read_exo/3");
if (inp_stream < 0)
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read_exo/3");
if (sno < 0)
return false;
/* preserve value of H after scanning: otherwise we may lose strings
and floats */
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 &&
next->Tok == Ponctuation_tok && next->TokInfo == TermOpenBracket) {
bool start = true;
@ -1253,16 +1253,16 @@ static Int source_location(USES_REGS1) {
*/
static Int read2(
USES_REGS1) { /* '$read2'(+Flag,?Term,?Module,?Vars,-Pos,-Err,+Stream) */
int inp_stream;
int sno;
Int out;
/* needs to change LOCAL_output_stream for write */
inp_stream = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
if (inp_stream == -1) {
sno = Yap_CheckTextStream(ARG1, Input_Stream_f, "read/3");
if (sno == -1) {
return (FALSE);
}
out = Yap_read_term(inp_stream, add_output(ARG2, TermNil), false);
UNLOCK(GLOBAL_Stream[inp_stream].streamlock);
out = Yap_read_term(sno, add_output(ARG2, TermNil), false);
UNLOCK(GLOBAL_Stream[sno].streamlock);
return out;
}

View File

@ -144,6 +144,7 @@ int GetFreeStreamD(void) {
return -1;
}
LOCK(GLOBAL_Stream[sno].streamlock);
GLOBAL_Stream[sno].status &= ~Free_Stream_f;
UNLOCK(GLOBAL_StreamDescLock);
GLOBAL_Stream[sno].encoding = LOCAL_encoding;
return sno;
@ -958,8 +959,9 @@ void Yap_CloseStreams(int loud) {
static void CloseStream(int sno) {
CACHE_REGS
fflush(NULL);
if (!(GLOBAL_Stream[sno].status &
//fflush(NULL);
if (GLOBAL_Stream[sno].file &&
!(GLOBAL_Stream[sno].status &
(Null_Stream_f | Socket_Stream_f | InMemory_Stream_f | Pipe_Stream_f)))
fclose(GLOBAL_Stream[sno].file);
#if HAVE_SOCKET

View File

@ -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_shell(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);
#ifdef MACYAP
static int chdir(char *);
/* #define signal skel_signal */
#endif /* MACYAP */
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
/// points at a readable directory
static bool is_directory(const char *FileName) {
bool Yap_isDirectory(const char *FileName) {
VFS_t *vfs;
if ((vfs = vfs_owner(FileName))) {
return vfs->isdir(FileName);
return vfs->isdir(vfs, FileName);
}
#ifdef _WIN32
DWORD dwAtts = GetFileAttributes(FileName);
@ -103,9 +94,9 @@ static bool is_directory(const char *FileName) {
bool Yap_Exists(const char *f) {
VFS_t *vfs;
f = Yap_VFAlloc(f);
if ((vfs = vfs_owner(f))) {
return vfs->exists(f);
return vfs->exists(vfs, f);
}
#if _WIN32
if (_access(f, 0) == 0)
@ -115,8 +106,9 @@ bool Yap_Exists(const char *f) {
}
return false;
#elif HAVE_ACCESS
if (access(f, F_OK) == 0)
if (access(f, F_OK) == 0) {
return true;
}
if (errno == EINVAL) {
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;
#endif
bool Yap_IsAbsolutePath(const char *p0) {
bool Yap_IsAbsolutePath(const char *p0, bool expand) {
// verify first if expansion is needed: ~/ or $HOME/
const char *p = expandVars(p0, LOCAL_FileNameBuf);
const char *p = p0;
bool nrc;
if (expand) {
p = expandVars(p0, LOCAL_FileNameBuf);
}
#if _WIN32 || __MINGW32__
nrc = !PathIsRelative(p);
#else
@ -169,9 +164,10 @@ bool Yap_IsAbsolutePath(const char *p0) {
static const char *PlExpandVars(const char *source, const char *root,
char *result) {
CACHE_REGS
int lvl = push_text_stack();
const char *src = source;
if (!result)
result = BaseMalloc(YAP_FILENAME_MAX + 1);
result = Malloc(YAP_FILENAME_MAX + 1);
if (strlen(source) >= YAP_FILENAME_MAX) {
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil,
@ -194,6 +190,7 @@ static const char *PlExpandVars(const char *source, const char *root,
if (s != NULL)
strncpy(result, s, YAP_FILENAME_MAX);
strcat(result, src);
result = pop_output_text_stack(lvl, result);
return result;
} else {
#if HAVE_GETPWNAM
@ -208,6 +205,7 @@ static const char *PlExpandVars(const char *source, const char *root,
FileError(SYSTEM_ERROR_OPERATING_SYSTEM,
MkAtomTerm(Yap_LookupAtom(source)),
"User %s does not exist in %s", result, source);
pop_text_stack(lvl);
return NULL;
}
strncpy(result, user_passwd->pw_dir, YAP_FILENAME_MAX);
@ -219,6 +217,7 @@ static const char *PlExpandVars(const char *source, const char *root,
return NULL;
#endif
}
result = pop_output_text_stack(lvl, result);
return result;
}
// do VARIABLE expansion
@ -260,9 +259,10 @@ static const char *PlExpandVars(const char *source, const char *root,
if (tocp > YAP_FILENAME_MAX) {
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, MkStringTerm(src),
"path too long");
pop_text_stack(lvl);
return NULL;
}
if (root && !Yap_IsAbsolutePath(source)) {
if (root && !Yap_IsAbsolutePath(source, false)) {
strncpy(result, root, YAP_FILENAME_MAX);
if (root[strlen(root) - 1] != '/')
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);
}
}
result = pop_output_text_stack(lvl, result);
return result;
}
@ -341,14 +342,16 @@ static char *PrologPath(const char *Y, char *X) { return (char *)Y; }
#define HAVE_REALPATH 1
#endif
static bool ChDir(const char *path) {
char virtual_cwd[YAP_FILENAME_MAX + 1];
bool Yap_ChDir(const char *path) {
bool rc = false;
char qp[FILENAME_MAX + 1];
const char *qpath = Yap_AbsoluteFile(path, qp, true);
VFS_t *v;
if ((v = vfs_owner(path))) {
return v->chdir(path);
return v->chdir(v, path);
}
#if _WIN32
rc = true;
@ -366,13 +369,13 @@ static bool ChDir(const char *path) {
}
static const char *myrealpath(const char *path, char *out) {
if (!out)
out = LOCAL_FileNameBuf;
int lvl = push_text_stack();
#if _WIN32
DWORD retval = 0;
// notice that the file does not need to exist
retval = GetFullPathName(path, YAP_FILENAME_MAX, out, NULL);
pop_text_stack(lvl);
if (retval == 0) {
Yap_WinError("Generating a full path name for a file");
return NULL;
@ -383,12 +386,13 @@ static const char *myrealpath(const char *path, char *out) {
char *rc = realpath(path, NULL);
if (rc) {
pop_text_stack(lvl);
return rc;
}
// rc = NULL;
if (errno == ENOENT || errno == EACCES) {
char base[YAP_FILENAME_MAX + 1];
strncpy(base, path, YAP_FILENAME_MAX - 1);
char *base = Malloc(YAP_FILENAME_MAX + 1);
strncpy(base, path, YAP_FILENAME_MAX);
rc = realpath(dirname(base), out);
if (rc) {
@ -412,6 +416,7 @@ static const char *myrealpath(const char *path, char *out) {
}
#endif
strcat(rc, b);
rc = pop_output_text_stack(lvl, rc);
return rc;
}
}
@ -419,6 +424,7 @@ static const char *myrealpath(const char *path, char *out) {
#endif
out = malloc(strlen(path) + 1);
strcpy(out, path);
pop_text_stack(lvl);
return out;
}
@ -924,7 +930,7 @@ static Int make_directory(USES_REGS1) {
#if defined(__MINGW32__) || _MSC_VER
if (_mkdir(fd) == -1) {
#else
if (mkdir(fd, 0777) == -1) {
if (mkdir(Yap_VFAlloc(fd), 0777) == -1) {
#endif
/* return an error number */
return false; // errno?
@ -933,7 +939,7 @@ static Int make_directory(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 (_rmdir(fd) == -1) {
#else
@ -948,106 +954,11 @@ static Int p_rmdir(USES_REGS1) {
static bool initSysPath(Term tlib, Term tcommons, bool dir_done,
bool commons_done) {
CACHE_REGS
int len;
#if __WINDOWS__
{
char *dir;
if ((dir = Yap_RegistryGetString("library")) && is_directory(dir)) {
dir_done = true;
if (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(dir))))
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 (!Yap_unify(tlib, MkAtomTerm(Yap_LookupAtom(Yap_PLDIR))))
return false;
#if __WINDOWS__
{
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;
return Yap_unify(tcommons, MkAtomTerm(Yap_LookupAtom(Yap_COMMONSDIR)));
}
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); }
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 (GetCurrentDirectory(cwdlen, (char *)cwd) == 0) {
Yap_WinError("GetCurrentDirectory failed");
@ -1161,174 +1079,7 @@ static Int working_directory(USES_REGS1) {
}
if (t2 == TermEmptyAtom || t2 == TermDot)
return true;
return 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;
return Yap_ChDir(RepAtom(AtomOfTerm(t2))->StrOfAE);
}
static Int true_file_name(USES_REGS1) {
@ -1396,10 +1147,10 @@ static Int true_file_name3(USES_REGS1) {
}
root = RepAtom(AtomOfTerm(t2))->StrOfAE;
}
if (!Yap_findFile(RepAtom(AtomOfTerm(t))->StrOfAE, NULL, root,
LOCAL_FileNameBuf, false, YAP_PL, false, false))
char tmp[YAP_FILENAME_MAX + 1];
if (!Yap_AbsoluteFile(RepAtom(AtomOfTerm(t))->StrOfAE, tmp, true))
return FALSE;
return Yap_unify(ARG3, MkAtomTerm(Yap_LookupAtom(LOCAL_FileNameBuf)));
return Yap_unify(ARG3, MkAtomTerm(Yap_LookupAtom(tmp)));
}
/* Executes $SHELL under Prolog */
@ -1416,7 +1167,7 @@ static Int p_sh(USES_REGS1) { /* sh */
shell = (char *)getenv("SHELL");
if (shell == NULL)
shell = "/bin/sh";
if (system(shell) < 0) {
if (system(Yap_VFAlloc(shell)) < 0) {
#if HAVE_STRERROR
Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, TermNil, "%s in sh/0",
strerror(errno));
@ -1622,10 +1373,12 @@ static Int p_mv(USES_REGS1) { /* rename(+OldName,+NewName) */
} else if (!IsAtomTerm(t2)) {
Yap_Error(TYPE_ERROR_ATOM, t2, "second argument to rename/2 not atom");
} else {
oldname = (RepAtom(AtomOfTerm(t1)))->StrOfAE;
newname = (RepAtom(AtomOfTerm(t2)))->StrOfAE;
oldname = Yap_VFAlloc((RepAtom(AtomOfTerm(t1)))->StrOfAE);
newname = Yap_VFAlloc((RepAtom(AtomOfTerm(t2)))->StrOfAE);
if ((r = link(oldname, newname)) == 0 && (r = unlink(oldname)) != 0)
unlink(newname);
free(oldname);
free(newname);
if (r != 0) {
#if HAVE_STRERROR
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) {
Term out = MkAtomTerm(Yap_LookupAtom(YAP_ROOTDIR));
return (Yap_unify(out, ARG1));
Term out;
out = MkAtomTerm(Yap_LookupAtom(Yap_ROOTDIR));
return Yap_unify(out, ARG1);
}
static Int p_yap_paths(USES_REGS1) {
Term out1, out2, out3;
const char *env_destdir = getenv("DESTDIR");
char destdir[YAP_FILENAME_MAX + 1];
if (env_destdir) {
strncat(destdir, env_destdir, YAP_FILENAME_MAX);
strncat(destdir, "/", YAP_FILENAME_MAX);
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));
}
out1 = MkAtomTerm(Yap_LookupAtom(Yap_LIBDIR));
out2 = MkAtomTerm(Yap_LookupAtom(Yap_SHAREDIR));
out3 = MkAtomTerm(Yap_LookupAtom(Yap_BINDIR));
return (Yap_unify(out1, ARG1) && Yap_unify(out2, ARG2) &&
Yap_unify(out3, ARG3));
}
@ -1864,7 +1597,7 @@ static Int p_win32(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) {

View File

@ -678,7 +678,7 @@ static Int term_to_string(USES_REGS1) {
Term t2 = Deref(ARG2), rc = false, t1 = Deref(ARG1);
const char *s;
if (IsVarTerm(t2)) {
s = Yap_TermToString(ARG1,LOCAL_encoding,
s = Yap_TermToBuffer(ARG1, LOCAL_encoding,
Quote_illegal_f | Handle_vars_f);
if (!s || !MkStringTerm(s)) {
Yap_Error(RESOURCE_ERROR_HEAP, t1,
@ -699,7 +699,7 @@ static Int term_to_atom(USES_REGS1) {
Term t2 = Deref(ARG2), ctl, rc = false;
Atom at;
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);
if (!s || !(at = Yap_UTF8ToAtom((const unsigned char *)s))) {
Yap_Error(RESOURCE_ERROR_HEAP, t2,

View File

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

View File

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

View File

@ -58,7 +58,7 @@ if (CMAKE_MAJOR_VERSION GREATER 2)
#set_property(TARGET horus PROPERTY CXX_STANDARD 11)
#set_property(TARGET horus PROPERTY CXX_STANDARD_REQUIRED ON)
set_target_properties (horus PROPERTIES PREFIX "" CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
set_target_properties (horus PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED ON)
add_executable (HorusCli HorusCli.cpp)
@ -68,8 +68,8 @@ if (CMAKE_MAJOR_VERSION GREATER 2)
install(TARGETS horus HorusCli
RUNTIME DESTINATION ${bindir}
LIBRARY DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
)
endif()

View File

@ -42,9 +42,9 @@ if (GECODE_FOUND)
include_directories (${GECODE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${GECODE_VERSION})
install(TARGETS gecode_yap
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gecode.yap

View File

@ -46,16 +46,14 @@ IF (CUDD_FOUND)
)
endif()
set_target_properties (cudd PROPERTIES PREFIX "")
add_subdirectory(simplecudd)
add_subdirectory(simplecudd)
add_subdirectory(simplecudd_lfi)
set(YAP_SYSTEM_OPTIONS "cudd " ${YAP_SYSTEM_OPTIONS} PARENT_SCOPE)
install(TARGETS cudd
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
)

View File

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

View File

@ -7,7 +7,7 @@ if (YAP_ROOT)
set( YAP_INCLUDE_DIR ../../include )
set( YAP_PL_LIBRARY_DIR ${libpl} )
set( YAP_LIBRARY libYap )
set( YAP_DLLS ${dlls} )
set( YAP_DLLS ${YAP_INSTALL_DLLDIR} )
else()

View File

@ -25,7 +25,7 @@ target_link_libraries(Problogbdd
)
install(TARGETS Problogbdd
RUNTIME DESTINATION ${bindir}
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
)

View File

@ -29,7 +29,7 @@ target_link_libraries(Problogbdd-Lfi
)
install(TARGETS Problogbdd-Lfi
RUNTIME DESTINATION ${bindir}
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
)

View File

@ -148,9 +148,9 @@ IF (CUDD_FOUND)
)
install(TARGETS bddem
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
)
@ -171,9 +171,9 @@ IF (CUDD_FOUND)
add_subDIRECTORY ( approx/simplecuddLPADs )
install(TARGETS cplint
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
)
INSTALL(FILES ${CPLINT_PROGRAMS} DESTINATION ${libpl})

View File

@ -26,7 +26,7 @@ target_link_libraries(LPADbdd
)
install(TARGETS LPADbdd
RUNTIME DESTINATION ${bindir}
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
)

View File

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

View File

@ -103,8 +103,8 @@ endif( THRUST_INCLUDE_DIR )
)
install(TARGETS libcuda
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
)
install(FILES ${PL_SOURCES}

View File

@ -42,9 +42,9 @@ if (GECODE_FOUND)
include_directories (${GECODE_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/${GECODE_VERSION})
install(TARGETS gecode_yap
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/gecode.yap

View File

@ -11,7 +11,7 @@ include_directories (${JAVA_INCLUDE_DIRS} ${JNI_INCLUDE_DIRS} )
# set(YAP_SYSTEM_OPTIONS "jpl " ${YAP_SYSTEM_OPTIONS} PARENT_SCOPE)
install(TARGETS jplYap
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
)

View File

@ -1,21 +1,22 @@
p#include <string.h>
p #include<string.h>
#include <stdlib.h>
#include "Yap.h"
#include "cut_c.h"
MYDDAS_UTIL_CONNECTION
myddas_init_initialize_connection(void *conn, void *enviromment, MYDDAS_API api,
MYDDAS_UTIL_CONNECTION next);
extern MYDDAS_UTIL_CONNECTION
myddas_init_initialize_connection(void *conn, void *enviromment,
MYDDAS_API api,
MYDDAS_UTIL_CONNECTION next);
MYDDAS_UTIL_CONNECTION
extern MYDDAS_UTIL_CONNECTION
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,
const char *pred_module,
MYDDAS_UTIL_PREDICATE next);
MYDDAS_UTIL_PREDICATE
extern MYDDAS_UTIL_PREDICATE
myddas_util_find_predicate(const char *pred_name, Int pred_arity,
const char *pred_module, MYDDAS_UTIL_PREDICATE list);

View File

@ -25,9 +25,9 @@
add_lib(Yapmysql ${MYSQL_SOURCES})
target_link_libraries(Yapmysql ${MYSQL_LIBRARIES} libYap)
install(TARGETS Yapmysql
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls}
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
)
endif()
include_directories(${MYSQL_INCLUDE_DIR} ..)

View File

@ -29,9 +29,9 @@ set_target_properties (Yapodbc PROPERTIES
install(TARGETS Yapodbc
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
)
else()

View File

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

View File

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

View File

@ -28,8 +28,8 @@ set_property(GLOBAL APPEND PROPERTY COMPILE_DEFINITIONS
-DMYDDAS_POSTGRES=1)
install(TARGETS Yappostgres
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
)
endif (PostgreSQL_FOUND)

View File

@ -60,7 +60,6 @@ set_target_properties(Yapsqlite3
# RPATH ${libdir} VERSION ${LIBYAPTAI_FULL_VERSION}
# SOVERSION ${LIBYAPTAI_MAJOR_VERSION}.${LIBYAPTAI_MINOR_VERSION}
POSITION_INDEPENDENT_CODE TRUE
PREFIX ""
)
target_link_libraries(Yapsqlite3 libYap)
@ -71,7 +70,7 @@ if (ANDROID)
endif ()
install(TARGETS Yapsqlite3
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls}
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR}
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
)

View File

@ -294,8 +294,8 @@ const char* jniStrError(int errnum, char* buf, size_t buflen) {
// char *strerror_r(int errnum, char *buf, size_t n);
return strerror_r(errnum, buf, buflen);
#else
int rc = strerror_r(errnum, buf, buflen);
if (rc != 0) {
char *rc = strerror_r(errnum, buf, buflen);
if (rc != NULL) {
// (POSIX only guarantees a value other than 0. The safest
// way to implement this function is to use C++ and overload on the
// type of strerror_r to accurately distinguish GNU from POSIX.)

View File

@ -29,9 +29,9 @@ target_link_libraries(Py4YAP libYap ${PYTHON_LIBRARIES})
install(TARGETS Py4YAP
RUNTIME DESTINATION ${bindir}
LIBRARY DESTINATION ${libdir}
ARCHIVE DESTINATION ${libdir}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
@ -54,6 +54,6 @@ add_to_group( PYTHON_PL pl_library )
set_target_properties (YAPPython PROPERTIES PREFIX "")
install(TARGETS YAPPython
LIBRARY DESTINATION ${dlls}
RUNTIME DESTINATION ${dlls}
ARCHIVE DESTINATION ${dlls} )
LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR}
RUNTIME DESTINATION ${YAP_INSTALL_DLLDIR}
ARCHIVE DESTINATION ${YAP_INSTALL_DLLDIR} )

View File

@ -27,7 +27,7 @@ PyObject *py_ModDict;
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 (strcasestr(name, "//python/") == name)
name += strlen("//python/");
@ -35,12 +35,16 @@ static void *py_open(const char *name, const char *io_mode) {
if (strstr(name, "//python/") == name)
name += strlen("//python/");
#endif
StreamDesc *st = YAP_RepStreamFromId(sno);
// we assume object is already open, so there is no need to open it.
PyObject *stream = string_to_python(name, true, NULL);
if (stream == Py_None)
return NULL;
Py_INCREF(stream);
return stream;
st->vfs_handle = stream;
st->vfs = me;
st->status = Append_Stream_f | Output_Stream_f;
return stream;
}
static bool py_close(int sno) {

View File

@ -6,7 +6,7 @@ INCLUDE(UseSWIG)
include(FindPythonModule)
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)
@ -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("MANIFEST.in" ${CMAKE_CURRENT_BINARY_DIR}/MANIFEST.in)
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
)
@ -71,7 +72,7 @@ endif()
install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install --ignore-installed .
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} )

View File

@ -9,6 +9,8 @@ import platform
global yap_lib_path
yap_lib_path = os.path.dirname(__file__)
if @CONDA_BUILD@ == "1":
# do not do nothing
if platform.system() == 'Windows':
def load( dll ):
dll = glob.glob(os.path.join(yap_lib_path,dll))[0]
@ -23,3 +25,7 @@ else:
if platform.system() == 'Apple':
load('libYap.dylib')
load('libPy4YAP.dylib' )
else:
load('libYap.os')
load('libPy4YAP.os' )

Some files were not shown because too many files have changed in this diff Show More