Merge /home/vsc/yap

This commit is contained in:
Vitor Santos Costa 2018-06-26 10:16:27 +01:00
commit 510ba1b804
21 changed files with 179 additions and 176 deletions

View File

@ -2167,7 +2167,7 @@ X_API FILE *YAP_TermToStream(Term t) {
X_API void YAP_EndConsult(int sno, int *osnop, const char *full) { X_API void YAP_EndConsult(int sno, int *osnop, const char *full) {
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
Yap_CloseStream(sno); Yap_CloseStream(sno);
Yap_ChDir(full); Yap_ChDir(dirname(full));
if (osnop >= 0) if (osnop >= 0)
Yap_AddAlias(AtomLoopStream, *osnop); Yap_AddAlias(AtomLoopStream, *osnop);
Yap_end_consult(); Yap_end_consult();

View File

@ -351,18 +351,26 @@ static inline void clean_dirty_tr(tr_fr_ptr TR0 USES_REGS) {
} }
} }
#define expand_stack(S0,SP,SF,TYPE) \
size_t sz = SF-S0, used = SP-S0; \
S0 = Realloc(S0, (1024+sz)*sizeof(TYPE) PASS_REGS); \
SP = S0+used; SF = S0+sz;
static int copy_complex_term(register CELL *pt0, register CELL *pt0_end, static int copy_complex_term(register CELL *pt0, register CELL *pt0_end,
int share, int copy_att_vars, CELL *ptf, int share, int copy_att_vars, CELL *ptf,
CELL *HLow USES_REGS) { CELL *HLow USES_REGS) {
struct cp_frame *to_visit0, int lvl = push_text_stack();
*to_visit = (struct cp_frame *)Yap_PreAllocCodeSpace(); struct cp_frame *to_visit0, *to_visit = Malloc(1024*sizeof(struct cp_frame));
struct cp_frame *to_visit_max;
CELL *HB0 = HB; CELL *HB0 = HB;
tr_fr_ptr TR0 = TR; tr_fr_ptr TR0 = TR;
int ground = TRUE; int ground = TRUE;
HB = HLow; HB = HLow;
to_visit0 = to_visit; to_visit0 = to_visit;
to_visit_max = to_visit+1024;
loop: loop:
while (pt0 < pt0_end) { while (pt0 < pt0_end) {
register CELL d0; register CELL d0;
@ -382,8 +390,8 @@ loop:
*ptf = AbsPair(HR); *ptf = AbsPair(HR);
ptf++; ptf++;
#ifdef RATIONAL_TREES #ifdef RATIONAL_TREES
if (to_visit + 1 >= (struct cp_frame *)AuxSp) { if (to_visit >= to_visit_max-32) {
goto heap_overflow; expand_stack(to_visit0, to_visit, to_visit_max, struct cp_frame);
} }
to_visit->start_cp = pt0; to_visit->start_cp = pt0;
to_visit->end_cp = pt0_end; to_visit->end_cp = pt0_end;
@ -395,8 +403,9 @@ loop:
to_visit++; to_visit++;
#else #else
if (pt0 < pt0_end) { if (pt0 < pt0_end) {
if (to_visit + 1 >= (CELL **)AuxSp) { if (to_visit + 32 >= to_visit_max - 32) {
goto heap_overflow; expand_stack(to_visit0, to_visit, to_visit_max, struct cp_frame);
} }
to_visit->start_cp = pt0; to_visit->start_cp = pt0;
to_visit->end_cp = pt0_end; to_visit->end_cp = pt0_end;
@ -493,8 +502,8 @@ loop:
ptf++; ptf++;
/* store the terms to visit */ /* store the terms to visit */
#ifdef RATIONAL_TREES #ifdef RATIONAL_TREES
if (to_visit + 1 >= (struct cp_frame *)AuxSp) { if (to_visit + 1 >= to_visit_max) {
goto heap_overflow; expand_stack(to_visit0, to_visit, to_visit_max, struct cp_frame);
} }
to_visit->start_cp = pt0; to_visit->start_cp = pt0;
to_visit->end_cp = pt0_end; to_visit->end_cp = pt0_end;
@ -507,7 +516,7 @@ loop:
#else #else
if (pt0 < pt0_end) { if (pt0 < pt0_end) {
if (to_visit++ >= (CELL **)AuxSp) { if (to_visit++ >= (CELL **)AuxSp) {
goto heap_overflow; expand_stack(to_visit0, to_visit, to_visit_max, struct cp_frame);
} }
to_visit->start_cp = pt0; to_visit->start_cp = pt0;
to_visit->end_cp = pt0_end; to_visit->end_cp = pt0_end;
@ -593,6 +602,7 @@ loop:
HB = HB0; HB = HB0;
clean_dirty_tr(TR0 PASS_REGS); clean_dirty_tr(TR0 PASS_REGS);
/* follow chain of multi-assigned variables */ /* follow chain of multi-assigned variables */
pop_text_stack(lvl);
return 0; return 0;
overflow: overflow:
@ -611,26 +621,9 @@ overflow:
} }
#endif #endif
reset_trail(TR0); reset_trail(TR0);
pop_text_stack(lvl);
return -1; return -1;
heap_overflow:
/* oops, we're in trouble */
HR = HLow;
/* we've done it */
/* restore our nice, friendly, term to its original state */
HB = HB0;
#ifdef RATIONAL_TREES
while (to_visit > to_visit0) {
to_visit--;
pt0 = to_visit->start_cp;
pt0_end = to_visit->end_cp;
ptf = to_visit->to;
*pt0 = to_visit->oldv;
}
#endif
reset_trail(TR0);
return -2;
trail_overflow: trail_overflow:
/* oops, we're in trouble */ /* oops, we're in trouble */
HR = HLow; HR = HLow;
@ -647,6 +640,7 @@ trail_overflow:
} }
#endif #endif
reset_trail(TR0); reset_trail(TR0);
pop_text_stack(lvl);
return -4; return -4;
} }

View File

@ -217,8 +217,7 @@ void *Yap_InitTextAllocator(void) {
static size_t MaxTmp(USES_REGS1) { static size_t MaxTmp(USES_REGS1) {
return ((char *)LOCAL_TextBuffer->buf + LOCAL_TextBuffer->sz) - return 1025;
(char *)LOCAL_TextBuffer->ptr;
} }
static Term Globalize(Term v USES_REGS) { static Term Globalize(Term v USES_REGS) {
@ -282,7 +281,7 @@ static void *codes2buf(Term t0, void *b0, bool *get_codes USES_REGS) {
return NULL; return NULL;
} }
if (!IsAtomTerm(hd)) { if (!IsAtomTerm(hd)) {
Yap_ThrowError(TYPE_ERROR_CHARACTER, hd, "scanning list of atoms"); Yap_ThrowError(TYPE_ERROR_CHARACTER, hd, "scanning list of texts");
return NULL; return NULL;
} }
const char *code = RepAtom(AtomOfTerm(hd))->StrOfAE; const char *code = RepAtom(AtomOfTerm(hd))->StrOfAE;
@ -441,7 +440,7 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
LOCAL_ActiveError->errorRawTerm = inp->val.t; LOCAL_ActiveError->errorRawTerm = inp->val.t;
} }
if (LOCAL_Error_TYPE != YAP_NO_ERROR) { if (LOCAL_Error_TYPE != YAP_NO_ERROR) {
pop_text_stack(lvl); Yap_ThrowError(LOCAL_Error_TYPE, inp->val.t, "Converting to text from term ");
return NULL; return NULL;
} }
@ -508,7 +507,6 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
s = Malloc(2 * MaxTmp(PASS_REGS1)); s = Malloc(2 * MaxTmp(PASS_REGS1));
if (snprintf(s, MaxTmp(PASS_REGS1) - 1, Int_FORMAT, if (snprintf(s, MaxTmp(PASS_REGS1) - 1, Int_FORMAT,
IntegerOfTerm(inp->val.t)) < 0) { IntegerOfTerm(inp->val.t)) < 0) {
pop_text_stack(lvl);
AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), s, char); AUX_ERROR(inp->val.t, 2 * MaxTmp(PASS_REGS1), s, char);
} }
return pop_output_text_stack(lvl, s); return pop_output_text_stack(lvl, s);
@ -528,7 +526,6 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) {
char *s; char *s;
s = Malloc(MaxTmp()); s = Malloc(MaxTmp());
if (!Yap_mpz_to_string(Yap_BigIntOfTerm(inp->val.t), s, MaxTmp() - 1, 10)) { if (!Yap_mpz_to_string(Yap_BigIntOfTerm(inp->val.t), s, MaxTmp() - 1, 10)) {
pop_text_stack(lvl);
AUX_ERROR(inp->val.t, MaxTmp(PASS_REGS1), s, char); AUX_ERROR(inp->val.t, MaxTmp(PASS_REGS1), s, char);
} }
return inp->val.uc = pop_output_text_stack(lvl, s); return inp->val.uc = pop_output_text_stack(lvl, s);

View File

@ -1,3 +1,4 @@
/************************************************************************* /*************************************************************************
* * * *
* Yap Prolog * * Yap Prolog *
@ -15,12 +16,10 @@
* * * *
*************************************************************************/ *************************************************************************/
/* static char SccsId[] = "X 4.3.3"; */ /* static char SccsId[] = "X 4.3.3"; */
#include "Yap.h" #include "Yap.h"
#include "YapHeap.h" #include "YapHeap.h"
#include "YapInterface.h" #include "YapInterface.h"
#include "YapStreams.h" #include "YapStreams.h"
#include "config.h"
#include "iopreds.h" #include "iopreds.h"
#if HAVE_UNISTD_H #if HAVE_UNISTD_H
@ -159,15 +158,15 @@ static bool consult(const char *b_file USES_REGS) {
Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1); Functor functor_query = Yap_MkFunctor(Yap_LookupAtom("?-"), 1);
Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1); Functor functor_command1 = Yap_MkFunctor(Yap_LookupAtom(":-"), 1);
Functor functor_compile2 = Yap_MkFunctor(Yap_LookupAtom("c_compile"), 1); Functor functor_compile2 = Yap_MkFunctor(Yap_LookupAtom("c_compile"), 1);
char *full;
/* consult in C */ /* consult in C */
int lvl = push_text_stack(); int lvl = push_text_stack();
- char *full = Malloc(YAP_FILENAME_MAX + 1); char *full = Malloc(YAP_FILENAME_MAX + 1);
full[0] = '\0'; full[0] = '\0';
/* the consult mode does not matter here, really */ /* the consult mode does not matter here, really */
vvvif ((osno = Yap_CheckAlias(AtomLoopStream)) < 0) if ((osno = Yap_CheckAlias(AtomLoopStream)) < 0) {
osno = 0; osno = 0;
}
c_stream = YAP_InitConsult(YAP_BOOT_MODE, b_file, &full, &oactive); c_stream = YAP_InitConsult(YAP_BOOT_MODE, b_file, &full, &oactive);
if (c_stream < 0) { if (c_stream < 0) {
fprintf(stderr, "[ FATAL ERROR: could not open file %s ]\n", b_file); fprintf(stderr, "[ FATAL ERROR: could not open file %s ]\n", b_file);
@ -183,9 +182,7 @@ static bool consult(const char *b_file USES_REGS) {
CACHE_REGS CACHE_REGS
YAP_Reset(YAP_FULL_RESET, false); YAP_Reset(YAP_FULL_RESET, false);
Yap_StartSlots(); Yap_StartSlots();
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "read %s <%d>", b_file, Term vs = MkVarTerm(), pos = MkVarTerm();
GLOBAL_Stream[c_stream].linecount);
Term vs = YAP_MkVarTerm(), pos = MkVarTerm();
t = YAP_ReadClauseFromStream(c_stream, vs, pos); t = YAP_ReadClauseFromStream(c_stream, vs, pos);
// Yap_GetNèwSlot(t); // Yap_GetNèwSlot(t);
if (t == TermEof) if (t == TermEof)
@ -321,7 +318,7 @@ static void Yap_set_locations(YAP_init_args *iap) {
/// BOOTPLDIR: where we can find Prolog bootstrap files /// BOOTPLDIR: where we can find Prolog bootstrap files
Yap_BOOTSTRAP = sel(true, iap->BOOTSTRAP != NULL, iap->BOOTSTRAP, true, Yap_BOOTSTRAP = sel(true, iap->BOOTSTRAP != NULL, iap->BOOTSTRAP, true,
#if __ANDROID__ #if __ANDROID__
"/assets/Yap/pl/boot,yap", "/assets/Yap/pl/boot.yap",
#else #else
join(getenv("DESTDIR"), YAP_BOOTSTRAP), join(getenv("DESTDIR"), YAP_BOOTSTRAP),
#endif #endif
@ -981,7 +978,7 @@ static void end_init(YAP_init_args *iap) {
YAP_initialized = true; YAP_initialized = true;
if (iap->HaltAfterBoot) Yap_exit(0); if (iap->HaltAfterBoot) Yap_exit(0);
LOCAL_PrologMode &= ~BootMode; LOCAL_PrologMode &= ~BootMode;
CurrentModule = USER_MODULE CurrentModule = USER_MODULE;
} }
static void start_modules(void) { static void start_modules(void) {
@ -1059,9 +1056,8 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
} }
YAP_RunGoalOnce(TermInitProlog); YAP_RunGoalOnce(TermInitProlog);
if (yap_init->install && Yap_OUTPUT_STARTUP) { if (yap_init->install && Yap_OUTPUT_STARTUP) {
>>>>>>> ff2b867ec3c3831e10b8465e0a9e3c1a03e3d4d2
Term t = MkAtomTerm(Yap_LookupAtom(Yap_OUTPUT_STARTUP)); Term t = MkAtomTerm(Yap_LookupAtom(Yap_OUTPUT_STARTUP));
Term g = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("qsave_program"), 1), Term g = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("qsave_program"), 1),
1, &t); 1, &t);
YAP_RunGoalOnce(g); YAP_RunGoalOnce(g);

View File

@ -161,6 +161,7 @@ public:
// fprintf(stderr,"ap=%p arity=%d text=%s", ap, ap->ArityOfPE, s); // fprintf(stderr,"ap=%p arity=%d text=%s", ap, ap->ArityOfPE, s);
// Yap_DebugPlWrite(out); // Yap_DebugPlWrite(out);
if (tout == 0L) { if (tout == 0L) {
return;
throw YAPError(); throw YAPError();
} }
ap = getPred(tout, nts); ap = getPred(tout, nts);

View File

@ -114,7 +114,7 @@ public:
/// It i; /// It i;
///}; ///};
/// build a query from a term /// build a query from a term
YAPQuery(YAPTerm t) : YAPPredicate((goal = t.term()), nts) { YAPQuery(YAPTerm t) : YAPPredicate((goal = t.term()), (nts = &ARG1)) {
BACKUP_MACHINE_REGS(); BACKUP_MACHINE_REGS();
openQuery(); openQuery();
names = YAPPairTerm(TermNil) ; names = YAPPairTerm(TermNil) ;

View File

@ -289,7 +289,7 @@ public:
/** /**
* @brief Compound Term * @brief Compound Term
*/ */
class X_API YAPApplTerm : public YAPTerm { class X_API YAPApplTerm : public YAPTerm {
friend class YAPTerm; friend class YAPTerm;
public: public:

View File

@ -56,14 +56,20 @@ opportunity. Initial value is 10,000. May be changed. A value of 0
~~~ ~~~
*/ */
/**< `answer_format` how to present answers, default is `~p`. */
YAP_FLAG(ANSWER_FORMAT_FLAG, "answer_format", true, isatom, "~p", NULL),
#if __APPLE__ #if __APPLE__
YAP_FLAG(APPLE_FLAG, "apple", false, booleanFlag, "true", NULL), /**< YAP_FLAG(APPLE_FLAG, "apple", false, booleanFlag, "true", NULL), /**<
read-only boolean, a machine running an Apple Operating System */ read-only boolean, a machine running an Apple Operating System */
#endif #endif
/**< `answer_format` how to present answers, default is `~p`. */
YAP_FLAG(ANSWER_FORMAT_FLAG, "answer_format", true, isatom, "~p", NULL),
#if __ANDROID__
YAP_FLAG(ANDROID_FLAG, "android", false, booleanFlag, "true", NULL), /**<
read-only boolean, a machine running an Google's Android version of the Linux Operating System */
#endif
YAP_FLAG(ARCH_FLAG, "arch", false, isatom, YAP_ARCH, NULL), /**< YAP_FLAG(ARCH_FLAG, "arch", false, isatom, YAP_ARCH, NULL), /**<
`apple`: read-only atom, it describes the ISA used in this version of YAP. `apple`: read-only atom, it describes the ISA used in this version of YAP.
Available from YAP_AEH. Available from YAP_AEH.

View File

@ -114,7 +114,8 @@ INLINE_ONLY Term Yap_ensure_atom__(const char *fu, const char *fi,
#define AUX_ERROR(t, n, s, TYPE) \ #define AUX_ERROR(t, n, s, TYPE) \
if (s + (n + 1) > (TYPE *)AuxSp) { \ if (s + (n + 1) > (TYPE *)AuxSp) { \
LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \ pop_text_stack(lvl); \
LOCAL_Error_TYPE = RESOURCE_ERROR_AUXILIARY_STACK; \
LOCAL_Error_Size = n * sizeof(TYPE); \ LOCAL_Error_Size = n * sizeof(TYPE); \
return NULL; \ return NULL; \
} }

View File

@ -215,6 +215,8 @@ static bool set_cwd(VFS_t *me, const char *dirName) {
if (GLOBAL_cwd) { if (GLOBAL_cwd) {
free(GLOBAL_cwd); free(GLOBAL_cwd);
} }
if (!is_dir_a(me,dirName))
dirName = dirname(dirName);
GLOBAL_cwd = malloc(strlen(dirName)+1); GLOBAL_cwd = malloc(strlen(dirName)+1);
strcpy(GLOBAL_cwd, dirName); strcpy(GLOBAL_cwd, dirName);
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "chdir %s", GLOBAL_cwd); __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "chdir %s", GLOBAL_cwd);

View File

@ -639,72 +639,67 @@ static Int file_directory_name(USES_REGS1) { /* file_directory_name(Stream,N) */
static Int list_directory(USES_REGS1) { static Int list_directory(USES_REGS1) {
Term tf = MkAtomTerm(Yap_LookupAtom("[]")); Term tf = MkAtomTerm(Yap_LookupAtom("[]"));
yhandle_t sl = Yap_InitSlot(tf); yhandle_t sl = Yap_InitSlot(tf);
VFS_t *vfsp;
char *buf = (char *)AtomName(AtomOfTerm(ARG1)); char *buf = (char *)AtomName(AtomOfTerm(ARG1));
#if defined(__MINGW32__) || _MSC_VER if ((vfsp = vfs_owner(buf))) {
struct _finddata_t c_file; void *de;
char bs[BUF_SIZE]; const char *dp;
long hFile;
bs[0] = '\0'; if ((de = vfsp->opendir(vfsp, buf)) == NULL) {
#if HAVE_STRNCPY
strncpy(bs, buf, BUF_SIZE);
#else
strcpy(bs, buf);
#endif
#if HAVE_STRNCAT
strncat(bs, "/*", BUF_SIZE);
#else
strcat(bs, "/*");
#endif
if ((hFile = _findfirst(bs, &c_file)) == -1L) {
return (Yap_Unify(ARD2, tf));
}
YAP_PutInSlot(sl, YAP_MkPairTerm(YAP_MkAtomTerm(YAP_LookupAtom(c_file.name)),
YAP_GetFromSlot(sl)));
while (_findnext(hFile, &c_file) == 0) {
YAP_Term ti = YAP_MkAtomTerm(YAP_LookupAtom(c_file.name));
YAP_PutInSlot(sl, YAP_MkPairTerm(ti, YAP_GetFromSlot(sl)));
}
_findclose(hFile);
#else
#if __ANDROID__
{
const char *dirName = buf + strlen("/assets/");
AAssetManager *mgr = GLOBAL_VFS->priv;
AAssetDir *de;
const char *dp;
if ((de = AAssetManager_openDir(mgr, dirName)) == NULL) {
PlIOError(PERMISSION_ERROR_INPUT_STREAM, ARG1, "%s in list_directory", PlIOError(PERMISSION_ERROR_INPUT_STREAM, ARG1, "%s in list_directory",
strerror(errno)); strerror(errno));
} }
while ((dp = AAssetDir_getNextFileName(de))) { while ((dp = vfsp->nextdir( de))) {
YAP_Term ti = MkAtomTerm(Yap_LookupAtom(dp)); YAP_Term ti = MkAtomTerm(Yap_LookupAtom(dp));
Yap_PutInHandle(sl, MkPairTerm(ti, Yap_GetFromHandle(sl))); Yap_PutInHandle(sl, MkPairTerm(ti, Yap_GetFromHandle(sl)));
} }
AAssetDir_close(de); vfsp->closedir( de);
} } else {
#if defined(__MINGW32__) || _MSC_VER
struct _finddata_t c_file;
char bs[BUF_SIZE];
long hFile;
bs[0] = '\0';
#if HAVE_STRNCPY
strncpy(bs, buf, BUF_SIZE);
#else
strcpy(bs, buf);
#endif #endif
#if HAVE_OPENDIR #if HAVE_STRNCAT
{ strncat(bs, "/*", BUF_SIZE);
DIR *de; #else
struct dirent *dp; strcat(bs, "/*");
#endif
if ((hFile = _findfirst(bs, &c_file)) == -1L) {
return (Yap_Unify(ARD2, tf));
}
YAP_PutInSlot(sl, YAP_MkPairTerm(YAP_MkAtomTerm(YAP_LookupAtom(c_file.name)),
YAP_GetFromSlot(sl)));
while (_findnext(hFile, &c_file) == 0) {
YAP_Term ti = YAP_MkAtomTerm(YAP_LookupAtom(c_file.name));
YAP_PutInSlot(sl, YAP_MkPairTerm(ti, YAP_GetFromSlot(sl)));
}
_findclose(hFile);
#elif HAVE_OPENDIR
{
DIR *de;
struct dirent *dp;
if ((de = opendir(buf)) == NULL) { if ((de = opendir(buf)) == NULL) {
PlIOError(PERMISSION_ERROR_INPUT_STREAM, ARG1, "%s in list_directory", PlIOError(PERMISSION_ERROR_INPUT_STREAM, ARG1, "%s in list_directory",
strerror(errno)); strerror(errno));
return false; return false;
} }
while ((dp = readdir(de))) { while ((dp = readdir(de))) {
Term ti = MkAtomTerm(Yap_LookupAtom(dp->d_name)); Term ti = MkAtomTerm(Yap_LookupAtom(dp->d_name));
Yap_PutInSlot(sl, MkPairTerm(ti, Yap_GetFromSlot(sl))); Yap_PutInSlot(sl, MkPairTerm(ti, Yap_GetFromSlot(sl)));
} }
closedir(de); closedir(de);
} }
#endif /* HAVE_OPENDIR */ #endif /* HAVE_OPENDIR */
#endif }
tf = Yap_GetFromSlot(sl); tf = Yap_GetFromSlot(sl);
return Yap_unify(ARG2, tf); return Yap_unify(ARG2, tf);
} }

View File

@ -1398,7 +1398,7 @@ Term Yap_BufferToTerm(const char *s, Term opts) {
Term rval; Term rval;
int sno; int sno;
encoding_t l = ENC_ISO_UTF8; encoding_t l = ENC_ISO_UTF8;
sno = Yap_open_buf_read_stream((char *)s, strlen((const char *)s), &l, sno = Yap_open_buf_read_stream((char *)s, strlen((const char *)s)+1, &l,
MEM_BUF_USER); MEM_BUF_USER);
GLOBAL_Stream[sno].status |= CloseOnException_Stream_f; GLOBAL_Stream[sno].status |= CloseOnException_Stream_f;
@ -1544,17 +1544,11 @@ static Int read_term_from_string(USES_REGS1) {
static Int atomic_to_term(USES_REGS1) { static Int atomic_to_term(USES_REGS1) {
Term t1 = Deref(ARG1); Term t1 = Deref(ARG1);
if (IsVarTerm(t1)) { int l = push_text_stack();
Yap_Error(INSTANTIATION_ERROR, t1, "read_term_from_string/3"); const char *s = Yap_TextToUTF8Buffer(t1 PASS_REGS);
return (FALSE); Int rc = Yap_BufferToTerm(s, add_output(ARG2, add_names(ARG3, TermNil)));
} else if (!IsAtomicTerm(t1)) { pop_text_stack(l);
Yap_Error(TYPE_ERROR_ATOMIC, t1, "read_term_from_atomic/3"); return rc;
return (FALSE);
} else {
Term t = Yap_AtomicToString(t1 PASS_REGS);
const unsigned char *us = UStringOfTerm(t);
return Yap_UBufferToTerm(us, add_output(ARG2, add_names(ARG3, TermNil)));
}
} }
static Int atom_to_term(USES_REGS1) { static Int atom_to_term(USES_REGS1) {

View File

@ -92,29 +92,37 @@ bool Yap_isDirectory(const char *FileName) {
#endif #endif
} }
Int exists_directory(USES_REGS1) {
int lvl = push_text_stack();
const char *path = Yap_AbsoluteFile(Yap_TextTermToText(Deref(ARG1) PASS_REGS),true);
bool rc = Yap_isDirectory(path);
pop_text_stack(lvl);
return rc;
}
bool Yap_Exists(const char *f) { bool Yap_Exists(const char *f) {
VFS_t *vfs; VFS_t *vfs;
f = Yap_VFAlloc(f); f = Yap_VFAlloc(f);
if ((vfs = vfs_owner(f))) { if ((vfs = vfs_owner(f))) {
return vfs->exists(vfs, f); return vfs->exists(vfs, f);
} }
#if _WIN32 #if _WIN32
if (_access(f, 0) == 0) if (_access(f, 0) == 0)
return true; return true;
if (errno == EINVAL) { if (errno == EINVAL) {
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "bad flags to access"); Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "bad flags to access");
} }
return false; return false;
#elif HAVE_ACCESS #elif HAVE_ACCESS
if (access(f, F_OK) == 0) { if (access(f, F_OK) == 0) {
return true; return true;
} }
if (errno == EINVAL) { if (errno == EINVAL) {
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "bad flags to access"); Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, "bad flags to access");
} }
return false; return false;
#else #else
Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil, Yap_Error(SYSTEM_ERROR_INTERNAL, TermNil,
"access not available in this configuration"); "access not available in this configuration");
return false; return false;
#endif #endif
@ -346,14 +354,14 @@ bool Yap_ChDir(const char *path) {
bool rc = false; bool rc = false;
int lvl = push_text_stack(); int lvl = push_text_stack();
const char *qpath = Yap_AbsoluteFile(path, true);
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "chdir %s", path); __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "chdir %s", path);
VFS_t *v; VFS_t *v;
if ((v = vfs_owner(path))) { if ((v = vfs_owner(qpath))) {
rc = v->chdir(v, path); rc = v->chdir(v, (qpath));
pop_text_stack(lvl); pop_text_stack(lvl);
return rc; return rc;
} }
const char *qpath = Yap_AbsoluteFile(path, true);
#if _WIN32 #if _WIN32
rc = true; rc = true;
if (qpath != NULL && qpath[0] && if (qpath != NULL && qpath[0] &&
@ -615,6 +623,8 @@ do_glob(const char *spec, bool glob_vs_wordexp) {
} }
return tf; return tf;
} }
#elif __ANDROID__
return MkPairTerm(MkAtomTerm(Yap_LookupAtom(spec)), TermNil);
#elif HAVE_WORDEXP || HAVE_GLOB #elif HAVE_WORDEXP || HAVE_GLOB
char u[YAP_FILENAME_MAX + 1]; char u[YAP_FILENAME_MAX + 1];
const char *espec = u; const char *espec = u;
@ -1866,7 +1876,8 @@ void Yap_InitSysPreds(void) {
Yap_InitCPred("$yap_paths", 3, p_yap_paths, SafePredFlag); Yap_InitCPred("$yap_paths", 3, p_yap_paths, SafePredFlag);
Yap_InitCPred("$dir_separator", 1, p_dir_sp, SafePredFlag); Yap_InitCPred("$dir_separator", 1, p_dir_sp, SafePredFlag);
Yap_InitCPred("libraries_directories", 2, libraries_directories, 0); Yap_InitCPred("libraries_directories", 2, libraries_directories, 0);
Yap_InitCPred("system_library", 1, system_library, 0); Yap_InitCPred("system_library", 1, system_library, 0);
Yap_InitCPred("exists_directory", 1, exists_directory, 0);
Yap_InitCPred("commons_library", 1, commons_library, 0); Yap_InitCPred("commons_library", 1, commons_library, 0);
Yap_InitCPred("$getenv", 2, p_getenv, SafePredFlag); Yap_InitCPred("$getenv", 2, p_getenv, SafePredFlag);
Yap_InitCPred("$putenv", 2, p_putenv, SafePredFlag | SyncPredFlag); Yap_InitCPred("$putenv", 2, p_putenv, SafePredFlag | SyncPredFlag);

View File

@ -72,7 +72,7 @@ foreach (driver ${MYDDAS_DBMS})
cpp_driver(MYDDAS_YAP ${driver} myddas_driver.ypp) cpp_driver(MYDDAS_YAP ${driver} myddas_driver.ypp)
endforeach () endforeach ()
#list (APPEND MYDDAS_YAP ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/test.yap ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/chinook.db) list (APPEND MYDDAS_YAP ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/test.yap ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/chinook.db)
add_to_group(MYDDAS_YAP pl_library ) add_to_group(MYDDAS_YAP pl_library )
add_custom_target(plmyddas ALL DEPENDS ${MYDDAS_YAP} ) add_custom_target(plmyddas ALL DEPENDS ${MYDDAS_YAP} )

View File

@ -1,5 +1,6 @@
:- compile(library(myddas)). :- compile(library(maplist)).
:- use_module(library(myddas)).
main :- main :-
init, init,
@ -11,19 +12,27 @@ main_ :-
main_ . main_ .
init :- init :-
db_open(sqlite3, '/data/user/0/pt.up.yap.yapdroid/files/Yap/chinook.db', _, _),
db_open(sqlite3, '/assets/Yap/chinook.db', _, _), start_low_level_trace,
writeln('chinook has landed'), db_open(sqlite3, '/data/user/0/pt.up.yap.yapdroid/files/Yap/chinook.db', _, _),
writeln('chinook has landed').
go :-
stop_low_level_trace,
db_import('Artist', artist), db_import('Artist', artist),
writeln(('Artist -> artist')),
db_import('Album', album), db_import('Album', album),
db_import('Track', track). writeln(('Album -> album')),
db_import('Track', track),
writeln(('Track -> track')).
go :- go :-
db_get_attributes_types(album,Als), db_get_attributes_types(album,Als),
format('~w -> ~w~n',[album,Als]),
db_get_attributes_types(track,Ts), db_get_attributes_types(track,Ts),
db_get_attributes_types(artist,As), format('~w -> ~w~n',[track,Ts]),
writeln(As:Als:Ts). db_get_attributes_types(artist,As),
format('~w -> ~w~n',[artist,As]).
go :- go :-
db_number_of_fields(album,Als), db_number_of_fields(album,Als),
db_number_of_fields(track,Ts), db_number_of_fields(track,Ts),
@ -31,11 +40,13 @@ go :-
writeln(As:Als:Ts). writeln(As:Als:Ts).
go :- go :-
db_describe(album, Desc), writeln(Desc) ; db_describe(album, Desc), writeln(album:Desc).
db_describe(track, Desc), writeln(Desc) ;
db_describe(artist, Desc), writeln(Desc).
go :- go :-
db_show_tables(Desc), writeln(Desc). db_describe(track, Desc), writeln(track:Desc).
go :-
db_describe(artist, Desc), writeln(artist:Desc).
go :-
db_show_tables(Desc), writeln(tables:Desc).
go :- go :-
db_show_tables(table(T)), db_show_tables(table(T)),
db_describe(T,tableinfo(FieldID,Type,Null,Primary,Default,'')), db_describe(T,tableinfo(FieldID,Type,Null,Primary,Default,'')),

View File

@ -61,6 +61,7 @@ and_put(int sno, int ch) {
buff0 += ch; buff0 += ch;
if (ch=='\n' || buff0.length() == 128) { //buff0+= '\0'; if (ch=='\n' || buff0.length() == 128) { //buff0+= '\0';
streamerInstance->display(buff0); streamerInstance->display(buff0);
buff0.clear();
} }
return ch; return ch;
} }

View File

@ -14,6 +14,14 @@
%include std_string.i %include std_string.i
%include std_vector.i %include std_vector.i
#if __ANDROID__
%include "arrays_java.i";
// %inline %{
static YAPTerm Temp[1];
// %}
// %typemap(javapackage) std::vector<YAPTerm> "pt.up.yap.YAPTerm"
//%template(VectorOfTerm) std::vector<YAPTerm>;
#endif
%feature("novaluewrapper") std::vector<Term>; %feature("novaluewrapper") std::vector<Term>;
@ -34,10 +42,6 @@ class YAPEngine;
#if __ANDROID__
#endif
#ifdef SWIGPYTHON #ifdef SWIGPYTHON
#include <py4yap.h> #include <py4yap.h>
@ -60,10 +64,6 @@ class YAPEngine;
return NULL; return NULL;
} }
#endif #endif
#ifdef SWIGJAVA0
%typemap(javapackage) std::vector<YAPTerm> "pt.up.yap.YAPTerm"
%template(VectorOfTerm) std::vector<YAPTerm>;
#endif
} }
%} %}

View File

@ -55,8 +55,8 @@
+ specialise versions for some built-ins, if we are aware of the + specialise versions for some built-ins, if we are aware of the
run-time execution mode run-time execution mode
The user has some control over this process, through some The user has control over this process, through
built-ins and through execution flsgs. built-ins and through prolog flags.
*/ */
@ -93,7 +93,7 @@ compile_expressions :- set_value('$c_arith',true).
After a call to this predicate, arithmetical expressions will not be compiled. After a call to this predicate, arithmetical expressions will not be compiled.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~
?- source, do_not_compile_expressions. ?- source, do_not_compile_expressions.
yes yes
?- [user]. ?- [user].
@ -111,8 +111,8 @@ p(A):-
q(A):- q(A):-
A is 22. A is 22.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~~~~~~~
*/ */
do_not_compile_expressions :- set_value('$c_arith',[]). do_not_compile_expressions :- set_value('$c_arith',[]).
@ -132,6 +132,7 @@ do_c_built_in('$do_error'( Error, Goal), M, Head,
throw(error(Error,M:(Head :- Goal))) throw(error(Error,M:(Head :- Goal)))
) :- !. ) :- !.
do_c_built_in(system_error( Error, Goal), M, Head, ErrorG) :- do_c_built_in(system_error( Error, Goal), M, Head, ErrorG) :-
!,
do_c_built_in('$do_error'( Error, Goal), M, Head, ErrorG). do_c_built_in('$do_error'( Error, Goal), M, Head, ErrorG).
do_c_built_in(X is Y, M, H, P) :- do_c_built_in(X is Y, M, H, P) :-
primitive(X), !, primitive(X), !,
@ -149,8 +150,10 @@ do_c_built_in(X is Y, _, _, P) :-
'$drop_is'(X0, X, P0, P) '$drop_is'(X0, X, P0, P)
). ).
do_c_built_in(phrase(NT,Xs), Mod, H, NTXsNil) :- do_c_built_in(phrase(NT,Xs), Mod, H, NTXsNil) :-
!,
'$_arith':do_c_built_in(phrase(NT,Xs,[]), Mod, H, NTXsNil). '$_arith':do_c_built_in(phrase(NT,Xs,[]), Mod, H, NTXsNil).
do_c_built_in(phrase(NT,Xs0,Xs), Mod, _, NewGoal) :- do_c_built_in(phrase(NT,Xs0,Xs), Mod, _, NewGoal) :-
!,
'$c_built_in_phrase'(NT, Xs0, Xs, Mod, NewGoal ). '$c_built_in_phrase'(NT, Xs0, Xs, Mod, NewGoal ).
do_c_built_in(Comp0, _, _, R) :- % now, do it for comparisons do_c_built_in(Comp0, _, _, R) :- % now, do it for comparisons

View File

@ -303,8 +303,8 @@ initialize_prolog :-
'qly.yap', 'qly.yap',
'spy.yap', 'spy.yap',
'udi.yap']. 'udi.yap'].
%:- stop_low_level_trace.
%:- start_low_level_trace.
:- meta_predicate(log_event(+,:)). :- meta_predicate(log_event(+,:)).
@ -316,14 +316,13 @@ initialize_prolog :-
:- ['protect.yap']. :- ['protect.yap'].
version(yap,[6,3]). version(yap,[6,4]).
:- op(1150,fx,(mode)). :- op(1150,fx,(mode)).
:- dynamic 'extensions_to_present_answer'/1. :- dynamic 'extensions_to_present_answer'/1.
:- ['arrays.yap']. :- ['arrays.yap'].
%:- start_low_level_trace.
:- multifile user:portray_message/2. :- multifile user:portray_message/2.
@ -396,6 +395,7 @@ yap_hacks:cut_by(CP) :- '$$cut_by'(CP).
:- style_check([+discontiguous,+multiple,+single_var]). :- style_check([+discontiguous,+multiple,+single_var]).
% %
% moved this to init_gc in gc.c to separate the alpha % moved this to init_gc in gc.c to separate the alpha
% %
@ -479,5 +479,4 @@ If this hook preodicate succeeds it must instantiate the _Action_ argument to t
:- ensure_loaded('../pl/pathconf.yap'). :- ensure_loaded('../pl/pathconf.yap').
:- yap_flag(user:unknown,error). :- yap_flag(user:unknown,error).
%% @} %% @}

View File

@ -252,9 +252,9 @@ compose_message(Throw, _Leve) -->
location(error(syntax_error(_),info(between(_,LN,_), FileName, _ChrPos, _Err)), _ , _) --> location(error(syntax_error(_),info(between(_,LN,_), FileName, _ChrPos, _Err)), _ , _) -->
!, !,
[ '~a:~d:~d ' - [FileName,LN,0] ] . [ '~a:~d:~d ' - [FileName,LN,0] ] .
location(style_check(_,LN,FileName,_ ), Level , LC) --> location(style_check(A,LN,FileName,B ), Level , LC) -->
!, !,
display_consulting( FileName, Level, LC ), display_consulting( FileName, Level,style_check(A,LN,FileName,B ), LC ),
[ '~a:~d:0 ~a ' - [FileName,LN,Level] ] . [ '~a:~d:0 ~a ' - [FileName,LN,Level] ] .
location( error(_,Info), Level, LC ) --> location( error(_,Info), Level, LC ) -->
{ '$error_descriptor'(Info, Desc) }, { '$error_descriptor'(Info, Desc) },
@ -266,7 +266,7 @@ location( error(_,Info), Level, LC ) -->
'$query_exception'(prologPredArity, Desc, Ar) '$query_exception'(prologPredArity, Desc, Ar)
}, },
!, !,
display_consulting( File, Level, LC ), display_consulting( File, Level, Info, LC ),
[ '~s:~d:0 ~a in ~s:~s/~d:'-[File, FilePos,Level,M,Na,Ar] ]. [ '~s:~d:0 ~a in ~s:~s/~d:'-[File, FilePos,Level,M,Na,Ar] ].
location( error(_,Info), Level, LC ) --> location( error(_,Info), Level, LC ) -->
{ '$error_descriptor'(Info, Desc) }, { '$error_descriptor'(Info, Desc) },

View File

@ -74,17 +74,9 @@ Prints a list of all files in the current directory.
*/ */
ls :- ls :-
getcwd(X), getcwd(X),
'$load_system_ls'(X,L), list_directory(X, L),
'$do_print_files'(L). '$do_print_files'(L).
'$load_system_ls'(X,L) :-
'$undefined'(directory_files(X, L), system),
load_files(library(system),[silent(true)]),
fail.
'$load_system_ls'(X,L) :-
system:directory_files(X, L).
'$do_print_files'([]) :- '$do_print_files'([]) :-
nl. nl.
'$do_print_files'([F| Fs]) :- '$do_print_files'([F| Fs]) :-