Merge /home/vsc/yap
This commit is contained in:
commit
c21c0079dc
@ -2106,45 +2106,42 @@ X_API void YAP_ClearExceptions(void) {
|
|||||||
|
|
||||||
X_API int YAP_InitConsult(int mode, const char *fname, char **full,
|
X_API int YAP_InitConsult(int mode, const char *fname, char **full,
|
||||||
int *osnop) {
|
int *osnop) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
int sno;
|
int sno;
|
||||||
BACKUP_MACHINE_REGS();
|
BACKUP_MACHINE_REGS();
|
||||||
const char *fl = NULL;
|
const char *fl = NULL;
|
||||||
int lvl = push_text_stack();
|
if (mode == YAP_BOOT_MODE) {
|
||||||
if (mode == YAP_BOOT_MODE) {
|
mode = YAP_CONSULT_MODE;
|
||||||
mode = YAP_CONSULT_MODE;
|
|
||||||
}
|
|
||||||
if (fname == NULL || fname[0] == '\0') {
|
|
||||||
fl = Yap_BOOTFILE;
|
|
||||||
}
|
|
||||||
if (fname) {
|
|
||||||
fl = Yap_AbsoluteFile(fname, true);
|
|
||||||
if (!fl || !fl[0]) {
|
|
||||||
pop_text_stack(lvl);
|
|
||||||
*full = NULL;
|
|
||||||
return -1;
|
|
||||||
} else {
|
|
||||||
*full = pop_output_text_stack(lvl, fl);
|
|
||||||
}
|
}
|
||||||
} else {
|
if (fname == NULL || fname[0] == '\0') {
|
||||||
pop_text_stack(lvl);
|
fl = Yap_BOOTFILE;
|
||||||
|
}
|
||||||
|
if (!fname || !(fl = Yap_AbsoluteFile(fname, true)) || !fl[0]) {
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "failed ABSOLUTEFN %s ", fl);
|
||||||
|
*full = NULL;
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "done init_ consult %s ",fl);
|
||||||
|
|
||||||
lvl = push_text_stack();
|
int lvl = push_text_stack();
|
||||||
char *d = Malloc(strlen(fl) + 1);
|
char *d = Malloc(strlen(fl) + 1);
|
||||||
strcpy(d, fl);
|
strcpy(d, fl);
|
||||||
bool consulted = (mode == YAP_CONSULT_MODE);
|
bool consulted = (mode == YAP_CONSULT_MODE);
|
||||||
Term tat = MkAtomTerm(Yap_LookupAtom(d));
|
Term tat = MkAtomTerm(Yap_LookupAtom(d));
|
||||||
sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)),
|
sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)),
|
||||||
LOCAL_encoding);
|
LOCAL_encoding);
|
||||||
if (sno < 0 || !Yap_ChDir(dirname((char *)d))) {
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "OpenStream got %d ",sno);
|
||||||
pop_text_stack(lvl);
|
pop_text_stack(lvl);
|
||||||
|
if (sno < 0 || !Yap_ChDir(dirname((char *)d))) {
|
||||||
*full = NULL;
|
*full = NULL;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
LOCAL_PrologMode = UserMode;
|
LOCAL_PrologMode = UserMode;
|
||||||
|
*full = pop_output_text_stack__(lvl, fl);
|
||||||
Yap_init_consult(consulted, pop_output_text_stack__(lvl, fl));
|
Yap_init_consult(consulted,*full);
|
||||||
RECOVER_MACHINE_REGS();
|
RECOVER_MACHINE_REGS();
|
||||||
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
UNLOCK(GLOBAL_Stream[sno].streamlock);
|
||||||
return sno;
|
return sno;
|
||||||
|
10
C/parser.c
10
C/parser.c
@ -58,14 +58,14 @@ extern const char *Yap_tokText(void *tokptr);
|
|||||||
static void syntax_msg(const char *msg, ...) {
|
static void syntax_msg(const char *msg, ...) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
va_list ap;
|
va_list ap;
|
||||||
if (!LOCAL_ErrorMessage ||
|
if (!LOCAL_Error_TYPE ||
|
||||||
(LOCAL_Error_TYPE == SYNTAX_ERROR &&
|
(LOCAL_Error_TYPE == SYNTAX_ERROR &&
|
||||||
LOCAL_tokptr->TokPos < LOCAL_ActiveError->parserPos)) {
|
LOCAL_toktide->TokPos < LOCAL_ActiveError->parserPos)) {
|
||||||
if (!LOCAL_ErrorMessage) {
|
if (!LOCAL_ErrorMessage) {
|
||||||
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE + 1);
|
LOCAL_ErrorMessage = malloc(MAX_ERROR_MSG_SIZE + 1);
|
||||||
}
|
}
|
||||||
LOCAL_ActiveError->parserLine = LOCAL_tokptr->TokLine;
|
LOCAL_ActiveError->parserLine = LOCAL_toktide->TokLine;
|
||||||
LOCAL_ActiveError->parserPos = LOCAL_tokptr->TokPos;
|
LOCAL_ActiveError->parserPos = LOCAL_toktide->TokPos;
|
||||||
va_start(ap, msg);
|
va_start(ap, msg);
|
||||||
vsnprintf(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE, msg, ap);
|
vsnprintf(LOCAL_ErrorMessage, MAX_ERROR_MSG_SIZE, msg, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
@ -939,7 +939,7 @@ Term Yap_Parse(UInt prio, encoding_t enc, Term cmod) {
|
|||||||
Yap_CloseSlots(sls);
|
Yap_CloseSlots(sls);
|
||||||
}
|
}
|
||||||
if (LOCAL_tokptr != NULL && LOCAL_tokptr->Tok != Ord(eot_tok)) {
|
if (LOCAL_tokptr != NULL && LOCAL_tokptr->Tok != Ord(eot_tok)) {
|
||||||
LOCAL_Error_TYPE = SYNTAX_ERROR;
|
LOCAL_Error_TYPE =SYNTAX_ERROR;
|
||||||
if (LOCAL_tokptr->TokNext) {
|
if (LOCAL_tokptr->TokNext) {
|
||||||
size_t sz = strlen("bracket or operator expected.");
|
size_t sz = strlen("bracket or operator expected.");
|
||||||
LOCAL_ErrorMessage =malloc(sz+1);
|
LOCAL_ErrorMessage =malloc(sz+1);
|
||||||
|
262
C/yap-args.c
262
C/yap-args.c
@ -153,22 +153,25 @@ const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR,
|
|||||||
* recursive consulting.
|
* recursive consulting.
|
||||||
*
|
*
|
||||||
* */
|
* */
|
||||||
static bool consult(const char *b_file USES_REGS) {
|
static bool load_file(const char *b_file USES_REGS) {
|
||||||
Term t;
|
Term t;
|
||||||
int c_stream, osno, oactive;
|
int c_stream, osno, oactive;
|
||||||
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);
|
||||||
|
|
||||||
/* consult in C */
|
/* consult in C */
|
||||||
int lvl = push_text_stack();
|
int lvl = push_text_stack();
|
||||||
char *full;
|
char *full;
|
||||||
/* the consult mode does not matter here, really */
|
/* the consult mode does not matter here, really */
|
||||||
if ((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) {
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "done init_ consult %s ",b_file);
|
||||||
|
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);
|
||||||
pop_text_stack(lvl);
|
pop_text_stack(lvl);
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -177,6 +180,8 @@ static bool consult(const char *b_file USES_REGS) {
|
|||||||
pop_text_stack(lvl);
|
pop_text_stack(lvl);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "do reset %s ",b_file);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -197,7 +202,7 @@ static bool consult(const char *b_file USES_REGS) {
|
|||||||
FunctorOfTerm(t) == functor_command1)) {
|
FunctorOfTerm(t) == functor_command1)) {
|
||||||
t = ArgOfTerm(1, t);
|
t = ArgOfTerm(1, t);
|
||||||
if (IsApplTerm(t) && FunctorOfTerm(t) == functor_compile2) {
|
if (IsApplTerm(t) && FunctorOfTerm(t) == functor_compile2) {
|
||||||
consult(RepAtom(AtomOfTerm(ArgOfTerm(1, t)))->StrOfAE);
|
load_file(RepAtom(AtomOfTerm(ArgOfTerm(1, t)))->StrOfAE);
|
||||||
Yap_ResetException(LOCAL_ActiveError);
|
Yap_ResetException(LOCAL_ActiveError);
|
||||||
} else {
|
} else {
|
||||||
YAP_RunGoalOnce(t);
|
YAP_RunGoalOnce(t);
|
||||||
@ -206,7 +211,7 @@ static bool consult(const char *b_file USES_REGS) {
|
|||||||
YAP_CompileClause(t);
|
YAP_CompileClause(t);
|
||||||
}
|
}
|
||||||
yap_error_descriptor_t *errd;
|
yap_error_descriptor_t *errd;
|
||||||
if ((errd = Yap_GetException(LOCAL_ActiveError))) {
|
if ((errd = Yap_GetException(LOCAL_ActiveError)) && (errd->errorNo != YAP_NO_ERROR)) {
|
||||||
fprintf(stderr, "%s:%ld:0: Error %s %s Found\n", errd->errorFile,
|
fprintf(stderr, "%s:%ld:0: Error %s %s Found\n", errd->errorFile,
|
||||||
(long int)errd->errorLine, errd->classAsText, errd->errorAsText);
|
(long int)errd->errorLine, errd->classAsText, errd->errorAsText);
|
||||||
}
|
}
|
||||||
@ -221,16 +226,82 @@ static bool consult(const char *b_file USES_REGS) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char * EOLIST ="EOLINE";
|
||||||
|
|
||||||
|
|
||||||
|
static bool is_dir( const char *path, const void *info) {
|
||||||
|
|
||||||
|
if (Yap_isDirectory( path ))
|
||||||
|
return true;
|
||||||
|
char s[YAP_FILENAME_MAX + 1];
|
||||||
|
Int i = strlen(path);
|
||||||
|
strncpy(s, path, YAP_FILENAME_MAX);
|
||||||
|
while (--i) {
|
||||||
|
if (Yap_dir_separator((int)path[i]))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (i == 0) {
|
||||||
|
s[0] = '.';
|
||||||
|
i = 1;
|
||||||
|
}
|
||||||
|
s[i] = '\0';
|
||||||
|
return
|
||||||
|
strcmp(info,s) == 0 ||
|
||||||
|
Yap_isDirectory( s );
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is_file( const char *path, const void *info) {
|
||||||
|
|
||||||
|
return Yap_Exists( path );
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool is_wfile( const char *path, const void *info) {
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
typedef bool testf(const char *s, const void *info);
|
||||||
|
|
||||||
|
|
||||||
///
|
///
|
||||||
///
|
///
|
||||||
static const char *sel(bool dir, bool ok1, const char *s1, bool ok2,
|
static const char *sel(
|
||||||
const char *s2, ...) {
|
testf test, const void *info, const char *s1, ...) {
|
||||||
if (ok1 && s1)
|
const char *fmt = s1;
|
||||||
return s1;
|
va_list ap;
|
||||||
if (ok2)
|
char *buf = malloc(FILENAME_MAX + 1);
|
||||||
return s2;
|
__android_log_print(
|
||||||
return NULL;
|
ANDROID_LOG_INFO, "YAPDroid", "try %s", s1);
|
||||||
}
|
|
||||||
|
va_start(ap, s1);
|
||||||
|
while (fmt != EOLIST) {
|
||||||
|
__android_log_print( ANDROID_LOG_INFO, "YAPDroid", "loop %s", fmt);
|
||||||
|
|
||||||
|
if (fmt == NULL || fmt[0]=='\0') {
|
||||||
|
fmt = va_arg(ap, const char *);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
strncpy(buf, fmt, FILENAME_MAX); // Yap_AbsoluteFile(fmt,true), FILENAME_MAX);
|
||||||
|
__android_log_print( ANDROID_LOG_INFO, "YAPDroid", "triyimh %s", buf);
|
||||||
|
if (test(buf,info)) {
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "got %s", buf);
|
||||||
|
buf = realloc(buf, strlen(buf) + 1);
|
||||||
|
va_end(ap);
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "tried %s, failed", buf);
|
||||||
|
fmt = va_arg(ap, const char *);
|
||||||
|
}
|
||||||
|
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "failed search ");
|
||||||
|
va_end(ap);
|
||||||
|
free(buf);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static const char *join(const char *s0, const char *s1) {
|
static const char *join(const char *s0, const char *s1) {
|
||||||
CACHE_REGS
|
CACHE_REGS
|
||||||
@ -256,103 +327,130 @@ static void Yap_set_locations(YAP_init_args *iap) {
|
|||||||
// --_not useful in Android, WIN32;
|
// --_not useful in Android, WIN32;
|
||||||
/// -- DESTDIR/ in Anaconda
|
/// -- DESTDIR/ in Anaconda
|
||||||
/// -- /usr/locall in most Unix style systems
|
/// -- /usr/locall in most Unix style systems
|
||||||
Yap_ROOTDIR = sel(true, iap->ROOTDIR != NULL, iap->ROOTDIR, true,
|
Yap_ROOTDIR = sel( is_dir, NULL,
|
||||||
|
iap->ROOTDIR,
|
||||||
|
getenv("YAPROOTDIR"),
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
NULL,
|
"/",
|
||||||
#else
|
#else
|
||||||
join(getenv("DESTDIR"), YAP_ROOTDIR),
|
join(getenv("DESTDIR"), YAP_ROOTDIR),
|
||||||
|
join(getenv("DESTDIR"), join(getenv("ḦOME"),".local")),
|
||||||
|
join(getenv("DESTDIR"), "/usr/local"),
|
||||||
|
join(getenv("DESTDIR"), "/usr"),
|
||||||
|
join(getenv("DESTDIR"), "/opt"),
|
||||||
#endif
|
#endif
|
||||||
false);
|
EOLIST
|
||||||
/// BINDIR: where the OS stores header files, namely libYap...
|
);
|
||||||
Yap_BINDIR = sel(true, iap->BINDIR != NULL, iap->BINDIR, true,
|
|
||||||
#if __ANDROID__
|
/// BINDIR: where the OS stores header files, namely libYap...
|
||||||
NULL,
|
Yap_BINDIR = sel( is_dir, Yap_ROOTDIR, iap->BINDIR,
|
||||||
#else
|
getenv("YAPBINDIR"),
|
||||||
|
#if !defined(__ANDROID__)
|
||||||
join(getenv("DESTDIR"), YAP_BINDIR),
|
join(getenv("DESTDIR"), YAP_BINDIR),
|
||||||
#endif
|
#endif
|
||||||
false);
|
join(Yap_ROOTDIR, "/bin"),
|
||||||
|
EOLIST);
|
||||||
|
|
||||||
/// LIBDIR: where the OS stores dynamic libraries, namely libYap...
|
/// LIBDIR: where the OS stores dynamic libraries, namely libYap...
|
||||||
Yap_LIBDIR = sel(true, iap->LIBDIR != NULL, iap->LIBDIR, true,
|
Yap_LIBDIR = sel( is_dir, Yap_ROOTDIR, iap->LIBDIR,
|
||||||
#if __ANDROID__
|
#if !defined(__ANDROID__)
|
||||||
NULL,
|
|
||||||
#else
|
|
||||||
join(getenv("DESTDIR"), YAP_LIBDIR),
|
join(getenv("DESTDIR"), YAP_LIBDIR),
|
||||||
#endif
|
#endif
|
||||||
false);
|
join(Yap_ROOTDIR, "/lib"),
|
||||||
|
EOLIST);
|
||||||
|
|
||||||
/// DLLDIR: where libraries can find expicitely loaded DLLs
|
/// DLLDIR: where libraries can find expicitely loaded DLLs
|
||||||
Yap_DLLDIR = sel(true, iap->DLLDIR != NULL, iap->DLLDIR, true,
|
Yap_DLLDIR = sel(is_dir, Yap_LIBDIR, iap->DLLDIR,
|
||||||
#if __ANDROID__
|
getenv("YAPLIBDIR"),
|
||||||
NULL,
|
#if !defined(__ANDROID__)
|
||||||
#else
|
join(getenv("DESTDIR"), YAP_DLLDIR),
|
||||||
join(getenv("DESTDIR"), YAP_DLLDIR),
|
join(Yap_LIBDIR, "/yap"),
|
||||||
#endif
|
#endif
|
||||||
false);
|
EOLIST);
|
||||||
|
|
||||||
/// INCLUDEDIR: where the OS stores header files, namely libYap...
|
/// INCLUDEDIR: where the OS stores header files, namely libYap...
|
||||||
Yap_INCLUDEDIR = sel(true, iap->INCLUDEDIR != NULL, iap->INCLUDEDIR, true,
|
Yap_INCLUDEDIR = sel(is_dir, Yap_ROOTDIR, iap->INCLUDEDIR,
|
||||||
#if __ANDROID__
|
#if !defined(__ANDROID__)
|
||||||
NULL,
|
join(getenv("DESTDIR"), YAP_INCLUDEDIR),
|
||||||
#else
|
|
||||||
join(getenv("DESTDIR"), YAP_INCLUDEDIR),
|
|
||||||
#endif
|
#endif
|
||||||
false);
|
join(Yap_ROOTDIR, "/include"),
|
||||||
|
EOLIST);
|
||||||
|
|
||||||
/// SHAREDIR: where OS & ARCH independent files live
|
/// SHAREDIR: where OS & ARCH independent files live
|
||||||
Yap_SHAREDIR = sel(true, iap->SHAREDIR != NULL, iap->SHAREDIR, true,
|
Yap_SHAREDIR = sel( is_dir, Yap_ROOTDIR, iap->SHAREDIR,
|
||||||
#if __ANDROID__
|
getenv("YAPSHAREDIR"),
|
||||||
"/assets",
|
#if !defined(__ANDROID__)
|
||||||
#else
|
join(getenv("DESTDIR"), YAP_SHAREDIR),
|
||||||
join(getenv("DESTDIR"), YAP_SHAREDIR),
|
join(Yap_ROOTDIR, "/share"),
|
||||||
|
"/assets",
|
||||||
#endif
|
#endif
|
||||||
false);
|
join(Yap_ROOTDIR, "/files"),
|
||||||
|
EOLIST);
|
||||||
/// PLDIR: where we can find Prolog files
|
/// PLDIR: where we can find Prolog files
|
||||||
Yap_PLDIR = sel(true, iap->PLDIR != NULL, iap->PLDIR, true,
|
Yap_PLDIR = sel( is_dir, Yap_SHAREDIR, iap->PLDIR,
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
|
YAP_PLDIR,
|
||||||
"/assets/Yap",
|
"/assets/Yap",
|
||||||
#else
|
#else
|
||||||
join(getenv("DESTDIR"), YAP_PLDIR),
|
join(getenv("DESTDIR"), YAP_PLDIR),
|
||||||
|
join(Yap_SHAREDIR, "/Yap"),
|
||||||
#endif
|
#endif
|
||||||
false);
|
EOLIST);
|
||||||
/// ``COMMONSDIR: Prolog Commons
|
/// ``COMMONSDIR: Prolog Commons
|
||||||
Yap_COMMONSDIR = sel(true, iap->COMMONSDIR != NULL, iap->COMMONSDIR, true,
|
Yap_COMMONSDIR = sel(is_dir, Yap_SHAREDIR, iap->COMMONSDIR,
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
"/assets/PrologCommons",
|
"/assets/PrologCommons",
|
||||||
#else
|
#else
|
||||||
join(getenv("DESTDIR"), YAP_SHAREDIR "/PrologCommons"),
|
join(getenv("DESTDIR"), YAP_SHAREDIR "/PrologCommons"),
|
||||||
|
join(Yap_SHAREDIR, "PrologCommons"),
|
||||||
#endif
|
#endif
|
||||||
false);
|
EOLIST);
|
||||||
/// 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( is_file, NULL, iap->BOOTSTRAP,
|
||||||
#if __ANDROID__
|
YAP_BOOTSTRAP,
|
||||||
"/assets/Yap/pl/boot.yap",
|
EOLIST);
|
||||||
#else
|
|
||||||
join(getenv("DESTDIR"), YAP_BOOTSTRAP),
|
|
||||||
#endif
|
|
||||||
false);
|
|
||||||
/// BOOTFILE: where we can find the core Prolog boot file
|
/// BOOTFILE: where we can find the core Prolog boot file
|
||||||
Yap_BOOTFILE = sel(false, iap->BOOTFILE != NULL, iap->BOOTFILE, true,
|
|
||||||
|
const char * Yap_PLBOOTDIR = sel( is_dir, Yap_PLDIR,
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
"/assets/Yap/pl/boot.yap",
|
"/assets/Yap/pl",
|
||||||
#else
|
#else
|
||||||
join(getenv("DESTDIR"), YAP_BOOTFILE),
|
join(Yap_PLDIR, "/pl"),
|
||||||
#endif
|
#endif
|
||||||
false);
|
EOLIST);
|
||||||
|
|
||||||
|
Yap_BOOTFILE = sel( is_wfile, Yap_PLBOOTDIR, iap->BOOTFILE,
|
||||||
|
#if __ANDROID__
|
||||||
|
"/assets/Yap/pl/boot.yap",
|
||||||
|
#else
|
||||||
|
join(Yap_PLBOOTDIR, "/boot.yap"),
|
||||||
|
#endif
|
||||||
|
EOLIST);
|
||||||
/// STARTUP: where we can find the core Prolog bootstrap file
|
/// STARTUP: where we can find the core Prolog bootstrap file
|
||||||
Yap_OUTPUT_STARTUP =
|
Yap_OUTPUT_STARTUP =
|
||||||
sel(false, iap->OUTPUT_STARTUP != NULL, iap->OUTPUT_STARTUP, true,
|
sel( is_wfile, Yap_AbsoluteFile(".",false), iap->OUTPUT_STARTUP,
|
||||||
#if __ANDROID__
|
#if defined(__ANDROID__)
|
||||||
NULL,
|
EOLIST,
|
||||||
#else
|
#else
|
||||||
join(getenv("DESTDIR"), YAP_OUTPUT_STARTUP),
|
YAP_OUTPUT_STARTUP,
|
||||||
#endif
|
#endif
|
||||||
false);
|
"startup.yss",
|
||||||
|
EOLIST);
|
||||||
|
|
||||||
Yap_INPUT_STARTUP =
|
Yap_INPUT_STARTUP =
|
||||||
sel(false, iap->INPUT_STARTUP != NULL, iap->INPUT_STARTUP, true,
|
sel( is_file, Yap_DLLDIR, iap->INPUT_STARTUP,
|
||||||
|
"startup.yss",
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
NULL,
|
EOLIST,
|
||||||
#else
|
#else
|
||||||
join(getenv("DESTDIR"), YAP_INPUT_STARTUP),
|
join(getenv("DESTDIR"), YAP_INPUT_STARTUP),
|
||||||
#endif
|
#endif
|
||||||
false);
|
join(Yap_DLLDIR, "/startup.yss"),
|
||||||
if (Yap_ROOTDIR)
|
"/usr/local/lib/Yap/startup.yss",
|
||||||
|
"/usr/lib/Yap/startup.yss",
|
||||||
|
EOLIST);
|
||||||
|
|
||||||
|
if (Yap_ROOTDIR)
|
||||||
setAtomicGlobalPrologFlag(HOME_FLAG,
|
setAtomicGlobalPrologFlag(HOME_FLAG,
|
||||||
MkAtomTerm(Yap_LookupAtom(Yap_ROOTDIR)));
|
MkAtomTerm(Yap_LookupAtom(Yap_ROOTDIR)));
|
||||||
if (Yap_PLDIR)
|
if (Yap_PLDIR)
|
||||||
@ -461,17 +559,18 @@ X_API YAP_file_type_t Yap_InitDefaults(void *x, char *saved_state, int argc,
|
|||||||
LOCAL_TextBuffer = Yap_InitTextAllocator();
|
LOCAL_TextBuffer = Yap_InitTextAllocator();
|
||||||
YAP_init_args *iap = x;
|
YAP_init_args *iap = x;
|
||||||
memset(iap, 0, sizeof(YAP_init_args));
|
memset(iap, 0, sizeof(YAP_init_args));
|
||||||
|
iap->Argc = argc;
|
||||||
|
iap->Argv = argv;
|
||||||
#if __ANDROID__
|
#if __ANDROID__
|
||||||
iap->boot_file_type = YAP_BOOT_PL;
|
iap->boot_file_type = YAP_BOOT_PL;
|
||||||
iap->INPUT_STARTUP = NULL;
|
iap->INPUT_STARTUP = NULL;
|
||||||
iap->assetManager = NULL;
|
iap->assetManager = NULL;
|
||||||
|
return YAP_BOOT_PL;
|
||||||
#else
|
#else
|
||||||
iap->boot_file_type = YAP_QLY;
|
iap->boot_file_type = YAP_QLY;
|
||||||
iap->INPUT_STARTUP = saved_state;
|
iap->INPUT_STARTUP = saved_state;
|
||||||
#endif
|
|
||||||
iap->Argc = argc;
|
|
||||||
iap->Argv = argv;
|
|
||||||
return YAP_QLY;
|
return YAP_QLY;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1006,7 +1105,8 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
|
|||||||
bool try_restore = yap_init->boot_file_type == YAP_QLY;
|
bool try_restore = yap_init->boot_file_type == YAP_QLY;
|
||||||
bool do_bootstrap = yap_init->boot_file_type == YAP_BOOT_PL;
|
bool do_bootstrap = yap_init->boot_file_type == YAP_BOOT_PL;
|
||||||
struct ssz_t minfo;
|
struct ssz_t minfo;
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "start init ");
|
||||||
if (YAP_initialized)
|
if (YAP_initialized)
|
||||||
/* ignore repeated calls to YAP_Init */
|
/* ignore repeated calls to YAP_Init */
|
||||||
return;
|
return;
|
||||||
@ -1039,6 +1139,8 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
|
|||||||
Yap_ExecutionMode = yap_init->ExecutionMode;
|
Yap_ExecutionMode = yap_init->ExecutionMode;
|
||||||
Yap_set_locations(yap_init);
|
Yap_set_locations(yap_init);
|
||||||
|
|
||||||
|
if (Yap_INPUT_STARTUP==NULL)
|
||||||
|
try_restore = false;
|
||||||
if (do_bootstrap || !try_restore ||
|
if (do_bootstrap || !try_restore ||
|
||||||
!Yap_SavedInfo(Yap_INPUT_STARTUP, &minfo.Trail, &minfo.Stack,
|
!Yap_SavedInfo(Yap_INPUT_STARTUP, &minfo.Trail, &minfo.Stack,
|
||||||
&minfo.Heap)) {
|
&minfo.Heap)) {
|
||||||
@ -1046,9 +1148,11 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
|
|||||||
|
|
||||||
start_modules();
|
start_modules();
|
||||||
CurrentModule = PROLOG_MODULE;
|
CurrentModule = PROLOG_MODULE;
|
||||||
TermEof = MkAtomTerm(Yap_LookupAtom("end_of_file"));
|
TermEof = MkAtomTerm(Yap_LookupAtom("end_of_file"));
|
||||||
LOCAL_consult_level = -1;
|
LOCAL_consult_level = -1;
|
||||||
consult(Yap_BOOTSTRAP PASS_REGS);
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "init %s ", Yap_BOOTSTRAP);
|
||||||
|
load_file(Yap_BOOTSTRAP PASS_REGS);
|
||||||
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
|
setAtomicGlobalPrologFlag(RESOURCE_DATABASE_FLAG,
|
||||||
MkAtomTerm(Yap_LookupAtom(Yap_BOOTFILE)));
|
MkAtomTerm(Yap_LookupAtom(Yap_BOOTFILE)));
|
||||||
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false);
|
setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false);
|
||||||
@ -1056,6 +1160,8 @@ X_API void YAP_Init(YAP_init_args *yap_init) {
|
|||||||
if (yap_init->QuietMode) {
|
if (yap_init->QuietMode) {
|
||||||
setVerbosity(TermSilent);
|
setVerbosity(TermSilent);
|
||||||
}
|
}
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "restore %s ",Yap_INPUT_STARTUP );
|
||||||
Yap_Restore(Yap_INPUT_STARTUP);
|
Yap_Restore(Yap_INPUT_STARTUP);
|
||||||
init_globals(yap_init);
|
init_globals(yap_init);
|
||||||
|
|
||||||
|
@ -320,6 +320,7 @@ set(YAP_ROOTDIR ${prefix})
|
|||||||
# libdir defined above
|
# libdir defined above
|
||||||
set(YAP_DATADIR ${CMAKE_INSTALL_FULL_DATADIR})
|
set(YAP_DATADIR ${CMAKE_INSTALL_FULL_DATADIR})
|
||||||
set(YAP_INCLUDEDIR ${CMAKE_INSTALL_FULL_INCLUDEDIR}/Yap)
|
set(YAP_INCLUDEDIR ${CMAKE_INSTALL_FULL_INCLUDEDIR}/Yap)
|
||||||
|
set(YAP_BINDIR ${CMAKE_INSTALL_FULL_BINDIR})
|
||||||
set(YAP_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR})
|
set(YAP_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR})
|
||||||
set(YAP_DLLDIR ${CMAKE_INSTALL_FULL_LIBDIR}/Yap)
|
set(YAP_DLLDIR ${CMAKE_INSTALL_FULL_LIBDIR}/Yap)
|
||||||
set(YAP_PLDIR ${CMAKE_INSTALL_FULL_DATADIR}/Yap)
|
set(YAP_PLDIR ${CMAKE_INSTALL_FULL_DATADIR}/Yap)
|
||||||
@ -854,8 +855,8 @@ if (WITH_JAVA)
|
|||||||
if (APPLE)
|
if (APPLE)
|
||||||
set(CMAKE_MACOSX_RPATH 1)
|
set(CMAKE_MACOSX_RPATH 1)
|
||||||
find_library (JLI jli ${JAVA_AWT_DIR}/jli)
|
find_library (JLI jli ${JAVA_AWT_DIR}/jli)
|
||||||
find_library (JAL JavaApplicationLauncher FRAMEWORK ONLY PATH /System/Library/PrivateFrameworks)
|
#find_library (JAL JavaApplicationLauncher FRAMEWORK ONLY PATH /System/Library/PrivateFrameworks)
|
||||||
find_library (JL JavaLaunching FRAMEWORK ONLY PATH /System/Library/PrivateFrameworks)
|
#find_library (JL JavaLaunching FRAMEWORK ONLY PATH /System/Library/PrivateFrameworks)
|
||||||
list(APPEND CMAKE_INSTALL_RPATH ${JAVA_AWT_DIR}/jli)
|
list(APPEND CMAKE_INSTALL_RPATH ${JAVA_AWT_DIR}/jli)
|
||||||
list(APPEND JNI_LIBRARIES ${JLI};${JAL};${JL})
|
list(APPEND JNI_LIBRARIES ${JLI};${JAL};${JL})
|
||||||
endif()
|
endif()
|
||||||
|
@ -270,6 +270,8 @@ public:
|
|||||||
inline void setArgv(char **fl) { Argv = fl; };
|
inline void setArgv(char **fl) { Argv = fl; };
|
||||||
|
|
||||||
inline char **getArgv() { return Argv; };
|
inline char **getArgv() { return Argv; };
|
||||||
|
|
||||||
|
inline void setROOTDIR(char *fl) { ROOTDIR = fl; };
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -293,7 +295,14 @@ public:
|
|||||||
YAPEngine(YAPEngineArgs *cargs) {
|
YAPEngine(YAPEngineArgs *cargs) {
|
||||||
engine_args = cargs;
|
engine_args = cargs;
|
||||||
// doInit(cargs->boot_file_type);
|
// doInit(cargs->boot_file_type);
|
||||||
|
__android_log_print(
|
||||||
|
ANDROID_LOG_INFO, "YAPDroid", "start engine ");
|
||||||
|
#ifdef __ANDROID__
|
||||||
|
doInit(YAP_BOOT_PL, cargs);
|
||||||
|
|
||||||
|
#else
|
||||||
doInit(YAP_QLY, cargs);
|
doInit(YAP_QLY, cargs);
|
||||||
|
#endif
|
||||||
}; /// construct a new engine, including aaccess to callbacks
|
}; /// construct a new engine, including aaccess to callbacks
|
||||||
/// construct a new engine using argc/argv list of arguments
|
/// construct a new engine using argc/argv list of arguments
|
||||||
YAPEngine(int argc, char *argv[],
|
YAPEngine(int argc, char *argv[],
|
||||||
|
@ -2030,7 +2030,7 @@ significant byte first (like Motorola and SPARC, unlike Intel). */
|
|||||||
|
|
||||||
/* name of Commons library */
|
/* name of Commons library */
|
||||||
#ifndef YAP_COMMONSDIR
|
#ifndef YAP_COMMONSDIR
|
||||||
#define YAP COMMONSDIR "${YAP_DATADIR}/PrologCommmons"
|
#define YAP_COMMONSDIR "${YAP_DATADIR}/PrologCommmons"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,16 +1,15 @@
|
|||||||
|
|
||||||
if (WITH_DOCS)
|
if (WITH_DOCS)
|
||||||
|
|
||||||
|
|
||||||
set (TOP_DIR YES)
|
set (TOP_DIR YES)
|
||||||
|
|
||||||
set(DOCS_SOURCE_DIR ${CMAKE_SOURCE_DIR}/docs)
|
set(DOCS_SOURCE_DIR ${CMAKE_SOURCE_DIR}/docs)
|
||||||
|
|
||||||
SET (CMAKE_HTML_EXTRA_)
|
SET (CMAKE_HTML_EXTRA_)
|
||||||
|
|
||||||
SET( EXT
|
SET( EXT
|
||||||
${DOCS_SOURCE_DIR}/custom/application.js
|
${DOCS_SOURCE_DIR}/custom/application.js
|
||||||
${DOCS_SOURCE_DIR}/custom/assets
|
${DOCS_SOURCE_DIR}/custom/assets
|
||||||
${DOCS_SOURCE_DIR}/custom/bootstrap.min.css
|
${DOCS_SOURCE_DIR}/custom/bootstrap.min.css
|
||||||
${DOCS_SOURCE_DIR}/custom/bootstrap.min.js
|
${DOCS_SOURCE_DIR}/custom/bootstrap.min.js
|
||||||
${DOCS_SOURCE_DIR}/custom/customdoxygen.css
|
${DOCS_SOURCE_DIR}/custom/customdoxygen.css
|
||||||
@ -27,123 +26,122 @@ SET( EXT
|
|||||||
${DOCS_SOURCE_DIR}/custom/yap.css
|
${DOCS_SOURCE_DIR}/custom/yap.css
|
||||||
)
|
)
|
||||||
|
|
||||||
foreach(i ${CMAKE_HTML_EXTRA_})
|
foreach(i ${CMAKE_HTML_EXTRA_})
|
||||||
string(APPEND CMAKE_HTML_EXTRA ${i} " ")
|
string(APPEND CMAKE_HTML_EXTRA ${i} " ")
|
||||||
endforeach(i ${CMAKE_HTML_EXTRA_})
|
endforeach(i ${CMAKE_HTML_EXTRA_})
|
||||||
|
|
||||||
|
|
||||||
set(DOC_DIRS_EXCLUDE_
|
set(DOC_DIRS_EXCLUDE_
|
||||||
${CMAKE_SOURCE_DIR}/build
|
${CMAKE_SOURCE_DIR}/build
|
||||||
${CMAKE_SOURCE_DIR}/Debug
|
${CMAKE_SOURCE_DIR}/Debug
|
||||||
${CMAKE_SOURCE_DIR}/packages/jpl
|
${CMAKE_SOURCE_DIR}/packages/jpl
|
||||||
${CMAKE_SOURCE_DIR}/packages/swi
|
${CMAKE_SOURCE_DIR}/packages/swi
|
||||||
${CMAKE_SOURCE_DIR}/packages/Problog/problog_examples
|
${CMAKE_SOURCE_DIR}/packages/Problog/problog_examples
|
||||||
${CMAKE_SOURCE_DIR}/packages/myddas/sqlite3/src
|
${CMAKE_SOURCE_DIR}/packages/myddas/sqlite3/src
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/6.0.1
|
${CMAKE_SOURCE_DIR}/packages/gecode/6.0.1
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/6.0.0
|
${CMAKE_SOURCE_DIR}/packages/gecode/6.0.0
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/5.1.0
|
${CMAKE_SOURCE_DIR}/packages/gecode/5.1.0
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/5.0.0
|
${CMAKE_SOURCE_DIR}/packages/gecode/5.0.0
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/4.4.0
|
${CMAKE_SOURCE_DIR}/packages/gecode/4.4.0
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/4.2.1
|
${CMAKE_SOURCE_DIR}/packages/gecode/4.2.1
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/4.2.0
|
${CMAKE_SOURCE_DIR}/packages/gecode/4.2.0
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/4.0.0
|
${CMAKE_SOURCE_DIR}/packages/gecode/4.0.0
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/3.7.3
|
${CMAKE_SOURCE_DIR}/packages/gecode/3.7.3
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/3.7.2
|
${CMAKE_SOURCE_DIR}/packages/gecode/3.7.2
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/3.7.1
|
${CMAKE_SOURCE_DIR}/packages/gecode/3.7.1
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/3.7.0
|
${CMAKE_SOURCE_DIR}/packages/gecode/3.7.0
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/3.6.0
|
${CMAKE_SOURCE_DIR}/packages/gecode/3.6.0
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/dev
|
${CMAKE_SOURCE_DIR}/packages/gecode/dev
|
||||||
${CMAKE_SOURCE_DIR}/packages/cplint
|
${CMAKE_SOURCE_DIR}/packages/cplint
|
||||||
${CMAKE_SOURCE_DIR}/packages/CLPBN/examples
|
${CMAKE_SOURCE_DIR}/packages/CLPBN/examples
|
||||||
${CMAKE_SOURCE_DIR}/packages/CLPBN/horus
|
${CMAKE_SOURCE_DIR}/packages/CLPBN/horus
|
||||||
${CMAKE_SOURCE_DIR}/packages/cuda
|
${CMAKE_SOURCE_DIR}/packages/cuda
|
||||||
${CMAKE_SOURCE_DIR}/packages/prosqlite
|
${CMAKE_SOURCE_DIR}/packages/prosqlite
|
||||||
${CMAKE_SOURCE_DIR}/packages/pyswip
|
${CMAKE_SOURCE_DIR}/packages/pyswip
|
||||||
${CMAKE_SOURCE_DIR}/packages/python/yap_kernel
|
${CMAKE_SOURCE_DIR}/packages/python/yap_kernel
|
||||||
${CMAKE_SOURCE_DIR}/packages/python/swig
|
${CMAKE_SOURCE_DIR}/packages/python/swig
|
||||||
${CMAKE_SOURCE_DIR}/packages/yap-lbfgs/liblbfgs-1.10
|
${CMAKE_SOURCE_DIR}/packages/yap-lbfgs/liblbfgs-1.10
|
||||||
${CMAKE_SOURCE_DIR}/packages/swi-minisat2
|
${CMAKE_SOURCE_DIR}/packages/swi-minisat2
|
||||||
${CMAKE_SOURCE_DIR}/library/dialect/swi/os
|
${CMAKE_SOURCE_DIR}/library/dialect/swi/os
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
set(DOCS_EXCLUDE_
|
set(DOCS_EXCLUDE_
|
||||||
${CMAKE_SOURCE_DIR}/C/traced_absmi_insts.h
|
${CMAKE_SOURCE_DIR}/C/traced_absmi_insts.h
|
||||||
${CMAKE_SOURCE_DIR}/H/globals.h
|
${CMAKE_SOURCE_DIR}/H/globals.h
|
||||||
${CMAKE_SOURCE_DIR}/OPTYap/locks_alpha_funcs.h
|
${CMAKE_SOURCE_DIR}/OPTYap/locks_alpha_funcs.h
|
||||||
${CMAKE_SOURCE_DIR}/OPTYap/locks_mips_funcs.h
|
${CMAKE_SOURCE_DIR}/OPTYap/locks_mips_funcs.h
|
||||||
${CMAKE_SOURCE_DIR}/OPTYap/locks_sparc.h
|
${CMAKE_SOURCE_DIR}/OPTYap/locks_sparc.h
|
||||||
${CMAKE_SOURCE_DIR}/*/bprolog/*
|
${CMAKE_SOURCE_DIR}/*/bprolog/*
|
||||||
${CMAKE_SOURCE_DIR}/*/prism/*
|
${CMAKE_SOURCE_DIR}/*/prism/*
|
||||||
${CMAKE_SOURCE_DIR}/*/gecode/[345]*
|
${CMAKE_SOURCE_DIR}/*/gecode/[345]*
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/gecode3_yap.cc
|
${CMAKE_SOURCE_DIR}/packages/gecode/gecode3_yap.cc
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/gecode4_yap.cc
|
${CMAKE_SOURCE_DIR}/packages/gecode/gecode4_yap.cc
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/gecode5_yap.cc
|
${CMAKE_SOURCE_DIR}/packages/gecode/gecode5_yap.cc
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/gecode3.yap
|
${CMAKE_SOURCE_DIR}/packages/gecode/gecode3.yap
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/gecode4.yap
|
${CMAKE_SOURCE_DIR}/packages/gecode/gecode4.yap
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/gecode5.yap
|
${CMAKE_SOURCE_DIR}/packages/gecode/gecode5.yap
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/gecode3_yap_hand_written.yap
|
${CMAKE_SOURCE_DIR}/packages/gecode/gecode3_yap_hand_written.yap
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/gecode4_yap_hand_written.yap
|
${CMAKE_SOURCE_DIR}/packages/gecode/gecode4_yap_hand_written.yap
|
||||||
${CMAKE_SOURCE_DIR}/packages/gecode/gecode5_yap_hand_written.yap
|
${CMAKE_SOURCE_DIR}/packages/gecode/gecode5_yap_hand_written.yap
|
||||||
*/CMakeFiles/*
|
*/CMakeFiles/*
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach(i ${DOCS_EXCLUDE_})
|
foreach(i ${DOCS_EXCLUDE_})
|
||||||
string(APPEND DOCS_EXCLUDE ${i} " ")
|
string(APPEND DOCS_EXCLUDE ${i} " ")
|
||||||
endforeach(i ${DOCS_EXCLUDE_})
|
endforeach(i ${DOCS_EXCLUDE_})
|
||||||
|
|
||||||
|
|
||||||
foreach(i ${DOCS_DIR_EXCLUDE_})
|
foreach(i ${DOCS_DIR_EXCLUDE_})
|
||||||
string(APPEND DOCS_DIR_EXCLUDE ${i} " ")
|
string(APPEND DOCS_DIR_EXCLUDE ${i} " ")
|
||||||
endforeach(i ${DOCS_DIR_EXCLUDE_})
|
endforeach(i ${DOCS_DIR_EXCLUDE_})
|
||||||
|
|
||||||
|
|
||||||
# add a target to generate API documentation with Doxygen
|
# add a target to generate API documentation with Doxygen
|
||||||
|
|
||||||
|
|
||||||
set(doxyfile_in ${CMAKE_SOURCE_DIR}/docs/Doxyfile.in)
|
set(doxyfile_in ${CMAKE_SOURCE_DIR}/docs/Doxyfile.in)
|
||||||
|
|
||||||
add_subdirectory(../packages/raptor/doc ${CMAKE_BINARY_DIR}/packages/raptor/doc)
|
add_subdirectory(../packages/raptor/doc ${CMAKE_BINARY_DIR}/packages/raptor/doc)
|
||||||
|
|
||||||
SET(DOC_INPUT_FILES_
|
SET(DOC_INPUT_FILES_
|
||||||
${CMAKE_SOURCE_DIR}/docs/md
|
${CMAKE_SOURCE_DIR}/docs/md
|
||||||
${CMAKE_SOURCE_DIR}/pl
|
${CMAKE_SOURCE_DIR}/pl
|
||||||
${CMAKE_SOURCE_DIR}/packages/ProbLog
|
${CMAKE_SOURCE_DIR}/CXX
|
||||||
${CMAKE_SOURCE_DIR}/CXX
|
${CMAKE_SOURCE_DIR}/OPTYap
|
||||||
${CMAKE_SOURCE_DIR}/OPTYap
|
${CMAKE_SOURCE_DIR}/C
|
||||||
${CMAKE_SOURCE_DIR}/C
|
${CMAKE_SOURCE_DIR}/H
|
||||||
${CMAKE_SOURCE_DIR}/H
|
${CMAKE_SOURCE_DIR}/include
|
||||||
${CMAKE_SOURCE_DIR}/include
|
${CMAKE_SOURCE_DIR}/os
|
||||||
${CMAKE_SOURCE_DIR}/os
|
${CMAKE_SOURCE_DIR}/library
|
||||||
${CMAKE_SOURCE_DIR}/library
|
${CMAKE_SOURCE_DIR}/swi/library
|
||||||
${CMAKE_SOURCE_DIR}/swi/library
|
${CMAKE_SOURCE_DIR}/packages
|
||||||
#${CMAKE_SOURCE_DIR}/packages
|
${CMAKE_SOURCE_DIR}/BEAM
|
||||||
${CMAKE_SOURCE_DIR}/BEAM
|
)
|
||||||
)
|
|
||||||
|
|
||||||
foreach(i ${DOC_INPUT_FILES_})
|
foreach(i ${DOC_INPUT_FILES_})
|
||||||
|
|
||||||
string(APPEND DOC_INPUT_FILES ${i} " ")
|
string(APPEND DOC_INPUT_FILES ${i} " ")
|
||||||
endforeach(i ${DOC_INPUT_FILES_})
|
endforeach(i ${DOC_INPUT_FILES_})
|
||||||
|
|
||||||
set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
set(doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile)
|
||||||
configure_file(${doxyfile_in} ${doxyfile} @ONLY)
|
configure_file(${doxyfile_in} ${doxyfile} @ONLY)
|
||||||
|
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/docs/source/conf.py.in source/conf.py)
|
configure_file(${CMAKE_SOURCE_DIR}/docs/source/conf.py.in source/conf.py)
|
||||||
configure_file(${CMAKE_SOURCE_DIR}/docs/source/index.rst source/index.rst)
|
configure_file(${CMAKE_SOURCE_DIR}/docs/source/index.rst source/index.rst)
|
||||||
|
|
||||||
add_custom_target(docs
|
add_custom_target(docs
|
||||||
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
|
COMMAND ${DOXYGEN_EXECUTABLE} ${doxyfile}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
if (EXISTS ${CMAKE_CURRENT_BINARY_DIR}/html)
|
if (EXISTS ${CMAKE_CURRENT_BINARY_DIR}/html)
|
||||||
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION ${docdir})
|
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/html DESTINATION ${docdir})
|
||||||
|
|
||||||
install(FILES ${CODES} DESTINATION ${docdir})
|
install(FILES ${CODES} DESTINATION ${docdir})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
@ -5,7 +5,7 @@ This text includes instructions to download and install YAP.
|
|||||||
|
|
||||||
[TOC]
|
[TOC]
|
||||||
|
|
||||||
## Downloading YAP {#Download}
|
@section Download Downloading YAP
|
||||||
|
|
||||||
The latest development version of Yap-6 is available source-only
|
The latest development version of Yap-6 is available source-only
|
||||||
through GIT repositories. The main reference repository is at
|
through GIT repositories. The main reference repository is at
|
||||||
@ -26,7 +26,7 @@ The first argument is the repository, the last argument is the (optional) target
|
|||||||
|
|
||||||
There are a variety of graphical interfaces to `git`, including GitHub's own [GitHub Desktop](https://desktop.github.com/) that supports Microsoft Windows and Apple OSX. A list with GUI applications, editor integration, and much more can be found at the [git Wiki](https://git.wiki.kernel.org/index.php/InterfacesFrontendsAndTools),
|
There are a variety of graphical interfaces to `git`, including GitHub's own [GitHub Desktop](https://desktop.github.com/) that supports Microsoft Windows and Apple OSX. A list with GUI applications, editor integration, and much more can be found at the [git Wiki](https://git.wiki.kernel.org/index.php/InterfacesFrontendsAndTools),
|
||||||
|
|
||||||
### Download Options
|
@subsection DownloadOptions Download Options
|
||||||
|
|
||||||
It may be useful to know:
|
It may be useful to know:
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ to only include the last `XX` commits.
|
|||||||
version of doxygen adapted to Prolog that was used to generate
|
version of doxygen adapted to Prolog that was used to generate
|
||||||
these documents.
|
these documents.
|
||||||
|
|
||||||
## CompilingYAP Compiling YAP
|
@section CompilingYAP Compiling YAP
|
||||||
|
|
||||||
|
|
||||||
YAP-6.3.4 is a [cmake](www.cmake.org) based
|
YAP-6.3.4 is a [cmake](www.cmake.org) based
|
||||||
@ -53,7 +53,7 @@ generate Makefiles, Ninja, Apple's XCode, VisualStudio and ANdroid
|
|||||||
Studio, and because it includes packaging suppport, The steps required
|
Studio, and because it includes packaging suppport, The steps required
|
||||||
to install core YAP under `cmake` are presented in detail next.
|
to install core YAP under `cmake` are presented in detail next.
|
||||||
|
|
||||||
### Compilation The compiler
|
@subsubsection Compilation The compiler
|
||||||
|
|
||||||
*Status as of early 2017*
|
*Status as of early 2017*
|
||||||
|
|
||||||
@ -70,7 +70,7 @@ to install core YAP under `cmake` are presented in detail next.
|
|||||||
YAP compiles cleanly under cross-compilers, and we have used the
|
YAP compiles cleanly under cross-compilers, and we have used the
|
||||||
crosss-compilation system [mxe](http://mxe.cc/) system with good results.
|
crosss-compilation system [mxe](http://mxe.cc/) system with good results.
|
||||||
|
|
||||||
### cmake
|
@subsection cmake cmake
|
||||||
|
|
||||||
All Linux and BSD distributions include `cmake`, so
|
All Linux and BSD distributions include `cmake`, so
|
||||||
does [Homebrew](https://brew.sh/)
|
does [Homebrew](https://brew.sh/)
|
||||||
@ -85,7 +85,7 @@ the [CMake site](https://www.cmake.org).
|
|||||||
If you have an older Linux you may need to compile from source,
|
If you have an older Linux you may need to compile from source,
|
||||||
available at GitHub.
|
available at GitHub.
|
||||||
|
|
||||||
### Ensure that you have other necessary packages installed:
|
@subsection extrapacks Ensure that you have other necessary packages installed:
|
||||||
|
|
||||||
+ YAP requires [gmp]{https://gmplib.org/} for infinite precision
|
+ YAP requires [gmp]{https://gmplib.org/} for infinite precision
|
||||||
integer and rational. Please ensure the development pacakage
|
integer and rational. Please ensure the development pacakage
|
||||||
@ -106,7 +106,7 @@ available at GitHub.
|
|||||||
|
|
||||||
+ make sure to install Python-3, and not Python-2,
|
+ make sure to install Python-3, and not Python-2,
|
||||||
|
|
||||||
### Compiling Compile and Install
|
@subsection Compiling2 Compile and Install
|
||||||
|
|
||||||
1: Create a directory, say `Build` and `cd` to the directory (`cd Build`).
|
1: Create a directory, say `Build` and `cd` to the directory (`cd Build`).
|
||||||
*YAP should not be compiled at its rootxo directory, some packages do not allow for that.
|
*YAP should not be compiled at its rootxo directory, some packages do not allow for that.
|
||||||
@ -120,7 +120,7 @@ available at GitHub.
|
|||||||
5: If you feel satisfied with the result, do `make install`.
|
5: If you feel satisfied with the result, do `make install`.
|
||||||
* In most systems you will need to be superuser in order to do `make install` and `make info` on the standard directories.
|
* In most systems you will need to be superuser in order to do `make install` and `make info` on the standard directories.
|
||||||
|
|
||||||
#### Tuning the Functionality of YAP
|
@subsection TuningYAP the Functionality of YAP
|
||||||
|
|
||||||
By default, YAP supports tabling, depth first search, and most features found in
|
By default, YAP supports tabling, depth first search, and most features found in
|
||||||
modern Prologs. In some cases, you may want to suport extra features, or reduce system size.
|
modern Prologs. In some cases, you may want to suport extra features, or reduce system size.
|
||||||
@ -181,7 +181,7 @@ You can also use `xcodebuild` from the command line.
|
|||||||
|
|
||||||
Bext follow instructions to fully compile YAP:
|
Bext follow instructions to fully compile YAP:
|
||||||
|
|
||||||
### Compilation Notes for OSX/Brew
|
@subsection TuningBrew Compilation Notes for OSX/Brew
|
||||||
|
|
||||||
Next follows a detailed description of a full install of YAP, including all the packages that YAP can use:
|
Next follows a detailed description of a full install of YAP, including all the packages that YAP can use:
|
||||||
|
|
||||||
@ -214,7 +214,7 @@ brew install cudd
|
|||||||
cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl ..
|
cmake -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl ..
|
||||||
~~~~~
|
~~~~~
|
||||||
|
|
||||||
### Compilation Notes for Android
|
@sususbsection TuningDroid Compilation Notes for Android
|
||||||
|
|
||||||
Next we present the compilation process for Android. The environment is an OSX, but steps
|
Next we present the compilation process for Android. The environment is an OSX, but steps
|
||||||
should be similar for Linux machines. We assume you have downloaded both the Android NDK and the Android SDK.
|
should be similar for Linux machines. We assume you have downloaded both the Android NDK and the Android SDK.
|
||||||
|
@ -1,23 +1,21 @@
|
|||||||
@defgroup YAPProgramming Programming in YAP
|
Programming in YAP {#YAPProgramming}
|
||||||
|
=================
|
||||||
@{
|
|
||||||
|
|
||||||
[TOC]
|
[TOC]
|
||||||
|
|
||||||
@}
|
|
||||||
|
|
||||||
@defgroup load_files Loading and Organizing YAP Programs
|
@defgroup load_files Loading and Organizing YAP Programs
|
||||||
|
@ingroup YAPProgramming
|
||||||
@{
|
@{
|
||||||
|
|
||||||
We present the main predicates and directives available to load
|
We present the main predicates and directives available to load
|
||||||
files and to control the Prolog environment.
|
files and to control the Prolog environment.
|
||||||
|
[TOC]
|
||||||
[TOC]
|
|
||||||
|
|
||||||
@}
|
@}
|
||||||
|
|
||||||
@defgroup YAPModules The YAP Module system
|
@section YAPModules The YAP Module system
|
||||||
|
@ingroup YAPProgramming
|
||||||
|
|
||||||
@{
|
@{
|
||||||
The YAP module system is based on the Quintus/SISCtus module
|
The YAP module system is based on the Quintus/SISCtus module
|
||||||
@ -57,7 +55,7 @@ We present the main predicates and directives available to load
|
|||||||
it starts consulting a file, and resets it at the end. One can set
|
it starts consulting a file, and resets it at the end. One can set
|
||||||
the type-in module permanently by using the built-in `module/1`.
|
the type-in module permanently by using the built-in `module/1`.
|
||||||
|
|
||||||
### Explicit Naming {#ExplicitNaming}
|
@subsection ExplicitNaming Explicit Naming
|
||||||
|
|
||||||
The module system allows one to _explicitly_ specify the source mode for
|
The module system allows one to _explicitly_ specify the source mode for
|
||||||
a clause by prefixing a clause with its module, say:
|
a clause by prefixing a clause with its module, say:
|
||||||
@ -245,9 +243,9 @@ We present the main predicates and directives available to load
|
|||||||
|
|
||||||
The state of the module system after this error is undefined.
|
The state of the module system after this error is undefined.
|
||||||
|
|
||||||
### Built-In predicates {#ModuleBuiltins)
|
@subsection ModuleBuiltins Built-In predicates
|
||||||
|
|
||||||
@\pred module(+ M:atom,+ L:list ) is directive
|
@pred module(+ M:atom,+ L:list ) is directive
|
||||||
the current file defines module _M_ with exports _L_. The list may include
|
the current file defines module _M_ with exports _L_. The list may include
|
||||||
|
|
||||||
+ predicate indicators
|
+ predicate indicators
|
||||||
|
@ -7,8 +7,8 @@ We next describe how to invoke YAP in Unix systems.
|
|||||||
|
|
||||||
[TOC]
|
[TOC]
|
||||||
|
|
||||||
Running YAP Interactively {#Running_YAP_Interactively}
|
@section Running_YAP_Interactively Running YAP Interactively
|
||||||
--------------------------
|
|
||||||
|
|
||||||
Most often you will want to use YAP in interactive mode. Assuming that
|
Most often you will want to use YAP in interactive mode. Assuming that
|
||||||
YAP is in the user's search path, the top-level can be invoked under
|
YAP is in the user's search path, the top-level can be invoked under
|
||||||
@ -87,7 +87,7 @@ the environment variable YAPBINDIR.
|
|||||||
|
|
||||||
+ YAP will try to find library files from the YAPSHAREDIR/library directory.
|
+ YAP will try to find library files from the YAPSHAREDIR/library directory.
|
||||||
|
|
||||||
Running Prolog Files {#Running_Prolog_Files}
|
@section RunningScripts Running Prolog Files
|
||||||
--------------------
|
--------------------
|
||||||
|
|
||||||
YAP can also be used to run Prolog files as scripts, at least in
|
YAP can also be used to run Prolog files as scripts, at least in
|
||||||
|
@ -56,7 +56,7 @@ Please do refer to the SWI-Prolog home page:
|
|||||||
|
|
||||||
for more information on SWI-Prolog and the SWI packages.
|
for more information on SWI-Prolog and the SWI packages.
|
||||||
|
|
||||||
#### Compatibility with the C-Prolog interpreter {#ChYProlog}
|
@section ChYProlog Compatibility with the C-Prolog interpreter
|
||||||
|
|
||||||
|
|
||||||
YAP was designed so that most C-Prolog programs should run under YAP
|
YAP was designed so that most C-Prolog programs should run under YAP
|
||||||
@ -97,8 +97,7 @@ or by using:
|
|||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
|
|
||||||
Compatibility with the Quintus and SICStus Prolog systems
|
@section QuiSics Compatibility with the Quintus and SICStus Prolog systems
|
||||||
---------------------------------------------------------
|
|
||||||
|
|
||||||
The Quintus Prolog system was the first Prolog compiler to use Warren's
|
The Quintus Prolog system was the first Prolog compiler to use Warren's
|
||||||
Abstract Machine. This system was very influential in the Prolog
|
Abstract Machine. This system was very influential in the Prolog
|
||||||
@ -130,8 +129,9 @@ SICStus Prolog or SWI-Prolog.
|
|||||||
|
|
||||||
+ This list is incomplete.
|
+ This list is incomplete.
|
||||||
|
|
||||||
Compatibility with the ISO Prolog standard
|
|
||||||
------------------------------------------
|
@section ISOCompat Compatibility with the ISO Prolog standard
|
||||||
|
|
||||||
|
|
||||||
The Prolog standard was developed by ISO/IEC JTC1/SC22/WG17, the
|
The Prolog standard was developed by ISO/IEC JTC1/SC22/WG17, the
|
||||||
international standardization working group for the programming language
|
international standardization working group for the programming language
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
NOTE: this version of YAP is still experimental, documentation may be missing or out of date.
|
NOTE: this version of YAP is still experimental, documentation may be missing or out of date.
|
||||||
|
|
||||||
## Introduction
|
@section Introduction Introduction
|
||||||
|
|
||||||
This document provides User information on version 6.3.4 of
|
This document provides User information on version 6.3.4 of
|
||||||
YAP (<em>Yet Another Prolog</em>). The YAP Prolog System is a
|
YAP (<em>Yet Another Prolog</em>). The YAP Prolog System is a
|
||||||
|
19
library/android.yap
Normal file
19
library/android.yap
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
%:- start_low_level_trace.
|
||||||
|
|
||||||
|
:- module(user).
|
||||||
|
:- yap_flag(verbose,normal).
|
||||||
|
|
||||||
|
query( String ) :-
|
||||||
|
yap_flag(typein_module, Mod),
|
||||||
|
atomic_to_term( String, Goal, VarNames ),
|
||||||
|
query_to_answer( Mod:Goal, VarNames, Status, Bindings),
|
||||||
|
output( Bindings, Status) .
|
||||||
|
|
||||||
|
output( Bindings, Status) :-
|
||||||
|
(Status == answer -> true ;
|
||||||
|
Status == exit ->true
|
||||||
|
),
|
||||||
|
write_query_answer( Bindings ),
|
||||||
|
nl(user_error).
|
||||||
|
|
||||||
|
%:- [sqlitest].
|
Binary file not shown.
@ -2,14 +2,14 @@
|
|||||||
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||||
|
|
||||||
(function(mod) {
|
(function(mod) {
|
||||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||||
mod(require("codemirror/lib/codemirror"));
|
mod(require("../../lib/codemirror"));
|
||||||
else if (typeof define == "function" && define.amd) // AMD
|
else if (typeof define == "function" && define.amd) // AMD
|
||||||
define([ "codemirror/lib/codemirror" ], mod);
|
define(["../../lib/codemirror"], mod);
|
||||||
else // Plain browser env
|
else // Plain browser env
|
||||||
mod(CodeMirror);
|
mod(CodeMirror);
|
||||||
})(function(CodeMirror) {
|
})(function(CodeMirror) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
||||||
function chain(stream, state, f) {
|
function chain(stream, state, f) {
|
||||||
@ -17,7 +17,8 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
return f(stream, state);
|
return f(stream, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
var cm_;
|
var cm_ = null;
|
||||||
|
var document = CodeMirror.doc;
|
||||||
var curLine;
|
var curLine;
|
||||||
|
|
||||||
/*******************************
|
/*******************************
|
||||||
@ -34,9 +35,26 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
parserConfig.groupedIntegers || false; /* tag{k:v, ...} */
|
parserConfig.groupedIntegers || false; /* tag{k:v, ...} */
|
||||||
var unicodeEscape =
|
var unicodeEscape =
|
||||||
parserConfig.unicodeEscape || true; /* \uXXXX and \UXXXXXXXX */
|
parserConfig.unicodeEscape || true; /* \uXXXX and \UXXXXXXXX */
|
||||||
var multiLineQuoted = parserConfig.multiLineQuoted || true; /* "...\n..." */
|
var multiLineQuoted = parserConfig.multiLineQuotedd || true;
|
||||||
var quoteType = parserConfig.quoteType ||
|
var singleQuoted = "atom";
|
||||||
{'"' : "string", "'" : "qatom", "`" : "bqstring"};
|
if (parserConfig.singleQuote === "string" ||
|
||||||
|
parserConfig.singleQuote === "codes" ||
|
||||||
|
parserConfig.singleQuote === "chars")
|
||||||
|
singleQuoted = parserConfig.singleQuote;
|
||||||
|
var doubleQuoted = "string";
|
||||||
|
if (parserConfig.doubleQuote === "atom" ||
|
||||||
|
parserConfig.doubleQuote === "codes" ||
|
||||||
|
parserConfig.doubleQuote === "chars")
|
||||||
|
doubleQuoted = parserConfig.doubleQuote;
|
||||||
|
var backQuoted = "atom";
|
||||||
|
if (parserConfig.backQuote === "string" ||
|
||||||
|
parserConfig.backQuote === "codes" ||
|
||||||
|
parserConfig.backQuote === "chars")
|
||||||
|
backQuoted = parserConfig.backQuote;
|
||||||
|
|
||||||
|
var quoteType = {"\"" : doubleQuoted, "`" : backQuoted, "'" : singleQuoted};
|
||||||
|
|
||||||
|
var singletonVars = new Map();
|
||||||
|
|
||||||
var isSingleEscChar = /[abref\\'"nrtsv]/;
|
var isSingleEscChar = /[abref\\'"nrtsv]/;
|
||||||
var isOctalDigit = /[0-7]/;
|
var isOctalDigit = /[0-7]/;
|
||||||
@ -55,25 +73,23 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
var exportedMsgs = [];
|
var exportedMsgs = [];
|
||||||
|
|
||||||
function getLine(stream) {
|
function getLine(stream) {
|
||||||
|
if (stream)
|
||||||
return stream.lineOracle.line;
|
return stream.lineOracle.line;
|
||||||
// return cm_.getDoc().getCursor().line;
|
if (document == null)
|
||||||
|
return 0;
|
||||||
|
return document.getCursor().line;
|
||||||
}
|
}
|
||||||
|
|
||||||
// var ed =
|
// var ed =
|
||||||
// window.document.getElementsByClassName("CodeMirror")[0].CodeMirror.doc.getEditor();
|
// window.document.getElementsByClassName("CodeMirror")[0].CodeMirror.doc.getEditor();
|
||||||
|
|
||||||
function rmError(stream) {
|
function rmError(document,stream) {
|
||||||
if (cm_ == null)
|
|
||||||
return;
|
|
||||||
var doc = cm_.getDoc();
|
|
||||||
var l = getLine(stream);
|
var l = getLine(stream);
|
||||||
// stream.lineOracle.line;
|
|
||||||
for (var i = 0; i < errorFound.length; i++) {
|
for (var i = 0; i < errorFound.length; i++) {
|
||||||
var elLine = doc.getLineNumber(errorFound[i].line);
|
var elLine = errorFound[i].document.getLineNumber(errorFound[i].line);
|
||||||
if (elLine == null || l === elLine) {
|
if (elLine == null || l === elLine) {
|
||||||
errorFound.splice(i, 1);
|
errorFound.splice(i, 1);
|
||||||
i -= 1;
|
i -= 1;
|
||||||
console.log(-elLine);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -81,30 +97,29 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
function mkError(stream, severity, msg) {
|
function mkError(stream, severity, msg) {
|
||||||
if (stream.pos == 0)
|
if (stream.pos == 0)
|
||||||
return;
|
return;
|
||||||
var l = cm_.getDoc().getLineHandle(getLine(stream));
|
var l = getLine(stream);
|
||||||
var found = errorFound.find(function(
|
var found = errorFound.find(function(
|
||||||
element) { return element.line === l && element.to == stream.pos; });
|
element) { return element.line === l && element.to == stream.pos; });
|
||||||
if (!found) {
|
if (!found) {
|
||||||
console.log( getLine(stream) );
|
//console.log(getLine(stream));
|
||||||
errorFound.push({
|
errorFound.push({
|
||||||
"line" : l,
|
"line" : l,
|
||||||
"from" : stream.start,
|
"from" : stream.start,
|
||||||
"to" : stream.pos,
|
"to" : stream.pos,
|
||||||
severity : severity,
|
severity : severity,
|
||||||
message : msg
|
message : msg,
|
||||||
|
document: document
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function exportErrors(text) {
|
function exportErrors(text) {
|
||||||
if (cm_ == null)
|
if (document == null)
|
||||||
return;
|
return;
|
||||||
var doc = cm_.getDoc();
|
|
||||||
|
|
||||||
exportedMsgs.length = 0;
|
exportedMsgs.length = 0;
|
||||||
for (var i = 0; i < errorFound.length; i += 1) {
|
for (var i = 0; i < errorFound.length; i += 1) {
|
||||||
var e = errorFound[i];
|
var e = errorFound[i];
|
||||||
var l = doc.getLineNumber(e.line);
|
var l = document.getLineNumber(e.line);
|
||||||
if (l == null) {
|
if (l == null) {
|
||||||
errorFound.splice(i, 1);
|
errorFound.splice(i, 1);
|
||||||
i -= 1;
|
i -= 1;
|
||||||
@ -120,6 +135,30 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
return exportedMsgs;
|
return exportedMsgs;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function maybeSingleton(stream, key) {
|
||||||
|
//console.log(key);
|
||||||
|
var v = singletonVars.get(key);
|
||||||
|
if (v != undefined) {
|
||||||
|
v.singleton = false;
|
||||||
|
} else {
|
||||||
|
singletonVars.set(
|
||||||
|
key, {'singleton' : true, 'from' : stream.start, to : stream.pos});
|
||||||
|
}
|
||||||
|
//console.log(singletonVars);
|
||||||
|
}
|
||||||
|
|
||||||
|
function outputSingletonVars(stream) {
|
||||||
|
var key, v;
|
||||||
|
for (var key in singletonVars.keys()) {
|
||||||
|
var v = singletonVars[key];
|
||||||
|
if (v != undefined && v.singleton) {
|
||||||
|
mkError(stream, "warning", key + " singleton variable");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
singletonVars.clear();
|
||||||
|
// console.log("reset");
|
||||||
|
}
|
||||||
|
|
||||||
CodeMirror.registerHelper("lint", "prolog", exportErrors);
|
CodeMirror.registerHelper("lint", "prolog", exportErrors);
|
||||||
|
|
||||||
/*******************************
|
/*******************************
|
||||||
@ -260,6 +299,8 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
function plTokenBase(stream, state) {
|
function plTokenBase(stream, state) {
|
||||||
var ch = stream.next();
|
var ch = stream.next();
|
||||||
|
|
||||||
|
state.curToken = ch;
|
||||||
|
|
||||||
if (ch == "(") {
|
if (ch == "(") {
|
||||||
if (state.lastType == "functor") {
|
if (state.lastType == "functor") {
|
||||||
state.nesting.push({
|
state.nesting.push({
|
||||||
@ -282,6 +323,7 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
|
|
||||||
if (ch == "{" && state.lastType == "tag") {
|
if (ch == "{" && state.lastType == "tag") {
|
||||||
state.nesting.push({
|
state.nesting.push({
|
||||||
|
marker: ch,
|
||||||
tag : state.tagName,
|
tag : state.tagName,
|
||||||
column : stream.column(),
|
column : stream.column(),
|
||||||
leftCol : state.tagColumn,
|
leftCol : state.tagColumn,
|
||||||
@ -292,8 +334,12 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
return ret("dict_open", "bracket");
|
return ret("dict_open", "bracket");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ch == "/" && stream.eat("*"))
|
if (ch == "/") {
|
||||||
return chain(stream, state, plTokenComment);
|
var next = stream.peek();
|
||||||
|
if (next == '*') {
|
||||||
|
return chain(stream, state, plTokenComment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (ch == "%") {
|
if (ch == "%") {
|
||||||
stream.skipToEnd();
|
stream.skipToEnd();
|
||||||
@ -305,14 +351,22 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
if (isSoloChar.test(ch)) {
|
if (isSoloChar.test(ch)) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case ")": {
|
case ")": {
|
||||||
|
if (state.nesting.marker != "(") {
|
||||||
|
mkError(stream, "error", state.nesting.marker + " closed by )");
|
||||||
|
}
|
||||||
state.nesting.pop();
|
state.nesting.pop();
|
||||||
} break;
|
} break;
|
||||||
case "]":
|
case "]":
|
||||||
|
if (state.nesting.marker != "[") {
|
||||||
|
mkError(stream, "error", state.nesting.marker + " closed by ]");
|
||||||
|
}
|
||||||
state.nesting.pop();
|
state.nesting.pop();
|
||||||
return ret("list_close", "bracket");
|
return ret("list_close", "bracket");
|
||||||
case "}": {
|
case "}": {
|
||||||
var nest = nesting(state);
|
if (state.nesting.marker != "{") {
|
||||||
|
mkError(stream, "error", state.nesting.marker + " closed by }");
|
||||||
|
}
|
||||||
|
var nest = nesting(state);
|
||||||
var type = (nest && nest.tag) ? "dict_close" : "brace_term_close";
|
var type = (nest && nest.tag) ? "dict_close" : "brace_term_close";
|
||||||
|
|
||||||
state.nesting.pop();
|
state.nesting.pop();
|
||||||
@ -323,22 +377,38 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
state.commaAtEOL = true;
|
state.commaAtEOL = true;
|
||||||
nextArg(state);
|
nextArg(state);
|
||||||
/*FALLTHROUGH*/
|
/*FALLTHROUGH*/
|
||||||
|
if (!state.commaAtEOL)
|
||||||
|
stream.eatSpace();
|
||||||
|
var nch = stream.peek();
|
||||||
|
if (nch == ';' || nch == ',') {
|
||||||
|
mkError(stream, "error", "\",\" followed by " + stream.peek());
|
||||||
|
return ret("solo", "error", ",");
|
||||||
|
}
|
||||||
if (isControl(state)) {
|
if (isControl(state)) {
|
||||||
if (!state.commaAtEOL)
|
if ("[" != ch) {
|
||||||
stream.eatSpace();
|
|
||||||
if (!stream.peek("[")) {
|
|
||||||
if (state.inBody) {
|
if (state.inBody) {
|
||||||
state.goalStart = true;
|
state.goalStart = true;
|
||||||
} else {
|
} else {
|
||||||
|
mkError(stream, "error", "\",\" followed by " + stream.peek());
|
||||||
return ret("solo", "error", ",");
|
return ret("solo", "error", ",");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return ret('solo', 'tag', ",");
|
||||||
} break;
|
} break;
|
||||||
case ";":
|
case ";":
|
||||||
|
if (!state.commaAtEOL)
|
||||||
|
stream.eatSpace();
|
||||||
|
ch = stream.peek();
|
||||||
|
if (ch == ';' || ch == ',') {
|
||||||
|
mkError(stream, "error", "\",\" followed by " + stream.peek());
|
||||||
|
return ret("solo", "error", ";");
|
||||||
|
}
|
||||||
if (isControl(state)) {
|
if (isControl(state)) {
|
||||||
if (!state.inBody)
|
if (!state.inBody) {
|
||||||
|
mkError(stream, "error", "unexpected ;");
|
||||||
return ret("solo", "error", ";");
|
return ret("solo", "error", ";");
|
||||||
|
}
|
||||||
state.goalStart = true;
|
state.goalStart = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -399,8 +469,10 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
if (stream.eat(/'/)) { /* 0' */
|
if (stream.eat(/'/)) { /* 0' */
|
||||||
var next = stream.next();
|
var next = stream.next();
|
||||||
if (next == "\\") {
|
if (next == "\\") {
|
||||||
if (!readEsc(stream))
|
if (!readEsc(stream)) {
|
||||||
|
mkError(stream, "error", "bad escape");
|
||||||
return ret("error", "error");
|
return ret("error", "error");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return ret("code", "number");
|
return ret("code", "number");
|
||||||
}
|
}
|
||||||
@ -423,22 +495,27 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
mkError(stream, "error", "Clause over before closing all brackets");
|
mkError(stream, "error", "Clause over before closing all brackets");
|
||||||
state.nesting = [];
|
state.nesting = [];
|
||||||
}
|
}
|
||||||
// var start = cm_.getCursor("end");
|
// var start = cm_.getCursor("end");
|
||||||
//cm_.setBookmark(start, {"widget" : document.createTextNode("•")});
|
// cm_.setBookmark(start, {"widget" :
|
||||||
|
// document.createTextNode("•")});
|
||||||
state.inBody = false;
|
state.inBody = false;
|
||||||
state.goalStart = true;
|
state.goalStart = true;
|
||||||
|
outputSingletonVars(stream);
|
||||||
stream.eat(ch);
|
stream.eat(ch);
|
||||||
|
state.headStart = true;
|
||||||
return ret("fullstop", "def", atom);
|
return ret("fullstop", "def", atom);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (atom === ":-" && state.headStart) {
|
if (atom === ":-" && state.headStart) {
|
||||||
|
state.headStart = false;
|
||||||
|
state.inBody = true;
|
||||||
|
state.goalStart = true;
|
||||||
return ret("directive", "attribute", atom);
|
return ret("directive", "attribute", atom);
|
||||||
|
|
||||||
} else if (isNeck.test(atom)) {
|
} else if (isNeck.test(atom)) {
|
||||||
state.inBody = true;
|
state.inBody = true;
|
||||||
state.goalStart = true;
|
state.goalStart = true;
|
||||||
return ret("neck", "property", atom);
|
return ret("neck", "def", atom);
|
||||||
} else if (isControl(state) && isControlOp.test(atom)) {
|
} else if (isControl(state) && isControlOp.test(atom)) {
|
||||||
state.goalStart = true;
|
state.goalStart = true;
|
||||||
return ret("symbol", "meta", atom);
|
return ret("symbol", "meta", atom);
|
||||||
@ -446,7 +523,7 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
return ret("symbol", "meta", atom);
|
return ret("symbol", "meta", atom);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
stream.eatWhile(/[\w_]/);
|
stream.eatWhile(/\w/);
|
||||||
if (composeGoalWithDots) {
|
if (composeGoalWithDots) {
|
||||||
while (stream.peek() == ".") {
|
while (stream.peek() == ".") {
|
||||||
stream.eat('.');
|
stream.eat('.');
|
||||||
@ -455,20 +532,22 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
stream.backUp(1);
|
stream.backUp(1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
} else if (/[\w_]/.test(ch)) {
|
} else if (/\w/.test(ch)) {
|
||||||
stream.eatWhile(/[\w_]/);
|
stream.eatWhile(/\w/);
|
||||||
} else if (ch == "'") {
|
} else if (ch == "'") {
|
||||||
|
|
||||||
stream.eat();
|
stream.eat();
|
||||||
|
|
||||||
stream.eatWhile(/[\w_]/);
|
stream.eatWhile(/[\w_]/);
|
||||||
if (ch == ".") {
|
if (ch == ".") {
|
||||||
|
mkError(stream, "error", "bad dotted name");
|
||||||
return ret("atom", "error");
|
return ret("atom", "error");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var word = stream.current();
|
var word = stream.current();
|
||||||
|
state.curToken = word;
|
||||||
var extra = "";
|
var extra = "";
|
||||||
if (stream.peek() == "{" && dicts) {
|
if (stream.peek() == "{" && dicts) {
|
||||||
state.tagName = word; /* tmp state extension */
|
state.tagName = word; /* tmp state extension */
|
||||||
@ -478,24 +557,26 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
if (word.length == 1) {
|
if (word.length == 1) {
|
||||||
return ret("var", "variable-2", word);
|
return ret("var", "variable-2", word);
|
||||||
} else {
|
} else {
|
||||||
var sec = word.charAt(1);
|
return ret("var", "variable-2", word);
|
||||||
if (sec == sec.toUpperCase())
|
|
||||||
return ret("var", "variable-2", word);
|
|
||||||
}
|
}
|
||||||
return ret("var", "variable-2", word);
|
} else if (ch.match(/[A-Z]/)) {
|
||||||
} else if (ch == ch.toUpperCase()) {
|
maybeSingleton(stream, word);
|
||||||
return ret("var", "variable-1", word);
|
return ret("var", "variable-1", word);
|
||||||
} else if (stream.peek() == "(") {
|
}
|
||||||
state.functorName = word; /* tmp state extension */
|
if (state.headStart) {
|
||||||
state.functorColumn = stream.column();
|
|
||||||
if (state.headStart) {
|
|
||||||
state.headStart = false;
|
state.headStart = false;
|
||||||
if (state.headFunctor != word) {
|
if (state.headFunctor !== word) {
|
||||||
state.headFunctor = word;
|
state.headFunctor = word;
|
||||||
return ret("functor", "def", word);
|
return ret("functor", "def", word);
|
||||||
}
|
}
|
||||||
|
return ret("functor", "atom", word);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (builtins[word] && isControl(state))
|
|
||||||
|
if (stream.peek() == "(") {
|
||||||
|
state.functorName = word; /* tmp state extension */
|
||||||
|
state.functorColumn = stream.column();
|
||||||
|
if (builtins[word] && isControl(state))
|
||||||
return ret("functor", "keyword", word);
|
return ret("functor", "keyword", word);
|
||||||
return ret("functor", "atom", word);
|
return ret("functor", "atom", word);
|
||||||
} else if ((extra = stream.eatSpace())) {
|
} else if ((extra = stream.eatSpace())) {
|
||||||
@ -519,8 +600,9 @@ CodeMirror.defineMode("prolog", function(conf, parserConfig) {
|
|||||||
if (builtins[word] && isControl(state))
|
if (builtins[word] && isControl(state))
|
||||||
return ret("functor", "keyword", w);
|
return ret("functor", "keyword", w);
|
||||||
return ret("functor", "atom", w);
|
return ret("functor", "atom", w);
|
||||||
} else if (builtins[word] && isControl(state))
|
} else if (builtins[word] && isControl(state)) {
|
||||||
return ret("atom", "keyword", word);
|
return ret("atom", "keyword", word);
|
||||||
|
}
|
||||||
return ret("atom", "atom", word);
|
return ret("atom", "atom", word);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -666,7 +748,7 @@ IfTrue
|
|||||||
|
|
||||||
CodeMirror.defineOption(
|
CodeMirror.defineOption(
|
||||||
"prologKeys", true, function(cm, editor, prev) {
|
"prologKeys", true, function(cm, editor, prev) {
|
||||||
cm_ = cm;
|
document = cm.getDoc();
|
||||||
if (prev && prev != CodeMirror.Init)
|
if (prev && prev != CodeMirror.Init)
|
||||||
cm.removeKeyMap("prolog");
|
cm.removeKeyMap("prolog");
|
||||||
if (true) {
|
if (true) {
|
||||||
@ -1336,10 +1418,9 @@ IfTrue
|
|||||||
setArgAlignment(state);
|
setArgAlignment(state);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (state.curLine == null || state.pos == 0)
|
|
||||||
rmError(stream);
|
|
||||||
|
|
||||||
var style = state.tokenize(stream, state);
|
var style = state.tokenize(stream, state);
|
||||||
|
//console.log(state.curToken);
|
||||||
|
|
||||||
if (stream.eol()) {
|
if (stream.eol()) {
|
||||||
if (stream.pos > 0)
|
if (stream.pos > 0)
|
||||||
@ -1386,7 +1467,7 @@ IfTrue
|
|||||||
blockCommentEnd : "*/",
|
blockCommentEnd : "*/",
|
||||||
blockCommentContinue : " * ",
|
blockCommentContinue : " * ",
|
||||||
comment : "%",
|
comment : "%",
|
||||||
fold : "indent"
|
matchBrackets : true
|
||||||
};
|
};
|
||||||
return external;
|
return external;
|
||||||
});
|
});
|
||||||
|
10
os/assets.c
10
os/assets.c
@ -77,18 +77,20 @@ open_asset(VFS_t *me, const char *fname, const char *io_mode, int sno) {
|
|||||||
// AAssetDir *dp = AAssetManager_openDir( Yap_assetManager(), dirname(dir) );
|
// AAssetDir *dp = AAssetManager_openDir( Yap_assetManager(), dirname(dir) );
|
||||||
// strcpy(dir, fname);
|
// strcpy(dir, fname);
|
||||||
// char *d = basename(dir);
|
// char *d = basename(dir);
|
||||||
am = AAssetManager_open(Yap_assetManager(), fname, mode);
|
am = AAssetManager_open(Yap_assetManager(), fname, io_mode);
|
||||||
//if (am==NULL)
|
//if (am==NULL)
|
||||||
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "failed open %s <%s>", fname, strerror(errno) );
|
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "failed open %s <%s>", fname, strerror(errno) );
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "open %s <%s>", fname, io_mode);
|
||||||
// while (dp) {
|
// while (dp) {
|
||||||
// char *f = AAssetDir_getNextFileName(dp);
|
// char *f = AAssetDir_getNextFileName(dp);
|
||||||
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "open %s <%s>", f, d);
|
// __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "open %s <%s>", fname, mode);
|
||||||
// if (f && strcasecmp(d,f) == 0) {
|
// if (f && strcasecmp(d,f) == 0) {
|
||||||
//
|
//
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
if (!am) {
|
if (!am) {
|
||||||
|
__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "failed %s <%s>", fname, io_mode);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// try not to use it as an asset
|
// try not to use it as an asset
|
||||||
@ -111,7 +113,7 @@ open_asset(VFS_t *me, const char *fname, const char *io_mode, int sno) {
|
|||||||
st->vfs = NULL;
|
st->vfs = NULL;
|
||||||
st->vfs_handle = NULL;
|
st->vfs_handle = NULL;
|
||||||
st->status = Seekable_Stream_f|Input_Stream_f;
|
st->status = Seekable_Stream_f|Input_Stream_f;
|
||||||
return st;
|
return st->file;
|
||||||
} else {
|
} else {
|
||||||
// should be done, but if not
|
// should be done, but if not
|
||||||
GLOBAL_Stream[sno].vfs_handle = am;
|
GLOBAL_Stream[sno].vfs_handle = am;
|
||||||
|
134
os/iopreds.c
134
os/iopreds.c
@ -1135,7 +1135,7 @@ bool Yap_initStream(int sno, FILE *fd, Atom name, const char *io_mode,
|
|||||||
ANDROID_LOG_INFO, "YAPDroid", "init %s %s:%s stream <%d>", io_mode,
|
ANDROID_LOG_INFO, "YAPDroid", "init %s %s:%s stream <%d>", io_mode,
|
||||||
CurrentModule == 0 ? "prolog"
|
CurrentModule == 0 ? "prolog"
|
||||||
: RepAtom(AtomOfTerm(CurrentModule))->StrOfAE,
|
: RepAtom(AtomOfTerm(CurrentModule))->StrOfAE,
|
||||||
name, sno);
|
RepAtom(name)->StrOfAE, sno);
|
||||||
if (io_mode == NULL)
|
if (io_mode == NULL)
|
||||||
Yap_Error(PERMISSION_ERROR_NEW_ALIAS_FOR_STREAM, MkIntegerTerm(sno),
|
Yap_Error(PERMISSION_ERROR_NEW_ALIAS_FOR_STREAM, MkIntegerTerm(sno),
|
||||||
"File opened with NULL Permissions");
|
"File opened with NULL Permissions");
|
||||||
@ -1242,74 +1242,80 @@ static bool fill_stream(int sno, StreamDesc *st, Term tin, const char *io_mode,
|
|||||||
|
|
||||||
st->file = NULL;
|
st->file = NULL;
|
||||||
if (fname) {
|
if (fname) {
|
||||||
if ((vfsp = vfs_owner(fname)) != NULL &&
|
if ((vfsp = vfs_owner(fname)) != NULL) {
|
||||||
vfsp->open(vfsp, fname, io_mode, sno)) {
|
if (vfsp->open(vfsp, fname, io_mode, sno)) {
|
||||||
// read, write, append
|
// read, write, append
|
||||||
user_name = st->user_name;
|
user_name = st->user_name;
|
||||||
st->vfs = vfsp;
|
st->vfs = vfsp;
|
||||||
UNLOCK(st->streamlock);
|
UNLOCK(st->streamlock);
|
||||||
} else {
|
__android_log_print(
|
||||||
st->file = fopen(fname, io_mode);
|
ANDROID_LOG_INFO, "YAPDroid", "got %d ", sno);
|
||||||
if (st->file == NULL) {
|
} else {
|
||||||
UNLOCK(st->streamlock);
|
UNLOCK(st->streamlock);
|
||||||
if (errno == ENOENT && !strchr(io_mode, 'r')) {
|
__android_log_print(
|
||||||
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s: %s", fname,
|
ANDROID_LOG_INFO, "YAPDroid", "failed %s ",fname);
|
||||||
strerror(errno));
|
return false;
|
||||||
} else {
|
}
|
||||||
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, tin, "%s: %s", fname,
|
} else {
|
||||||
strerror(errno));
|
st->file = fopen(fname, io_mode);
|
||||||
}
|
if (st->file == NULL) {
|
||||||
}
|
__android_log_print(
|
||||||
st->vfs = NULL;
|
ANDROID_LOG_INFO, "YAPDroid", "failed %s ",fname);
|
||||||
}
|
UNLOCK(st->streamlock);
|
||||||
if (!st->file && !st->vfs) {
|
if (errno == ENOENT && !strchr(io_mode, 'r')) {
|
||||||
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s", fname);
|
PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s: %s", fname,
|
||||||
/* extract BACK info passed through the stream descriptor */
|
strerror(errno));
|
||||||
return false;
|
} else {
|
||||||
}
|
PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, tin, "%s: %s", fname,
|
||||||
} else if (IsApplTerm(tin)) {
|
strerror(errno));
|
||||||
Functor f = FunctorOfTerm(tin);
|
}
|
||||||
if (f == FunctorAtom || f == FunctorString || f == FunctorCodes1 ||
|
return false;
|
||||||
f == FunctorCodes || f == FunctorChars1 || f == FunctorChars) {
|
}
|
||||||
if (strchr(io_mode, 'r')) {
|
|
||||||
return Yap_OpenBufWriteStream(PASS_REGS1);
|
|
||||||
} else {
|
|
||||||
int j = push_text_stack();
|
|
||||||
const char *buf;
|
|
||||||
|
|
||||||
buf = Yap_TextTermToText(tin PASS_REGS);
|
|
||||||
if (!buf) {
|
|
||||||
pop_text_stack(j);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
buf = pop_output_text_stack(j, buf);
|
|
||||||
Atom nat = Yap_LookupAtom(Yap_StrPrefix(buf, 32));
|
|
||||||
sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding,
|
|
||||||
MEM_BUF_MALLOC, nat,
|
|
||||||
MkAtomTerm(NameOfFunctor(f)));
|
|
||||||
pop_text_stack(j);
|
|
||||||
return Yap_OpenBufWriteStream(PASS_REGS1);
|
|
||||||
}
|
|
||||||
} else if (!strcmp(RepAtom(NameOfFunctor(f))->StrOfAE, "popen")) {
|
|
||||||
const char *buf;
|
|
||||||
int i = push_text_stack();
|
|
||||||
buf = Yap_TextTermToText(ArgOfTerm(1, tin) PASS_REGS);
|
|
||||||
if (buf == NULL) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
} else if (IsApplTerm(tin)) {
|
||||||
|
Functor f = FunctorOfTerm(tin);
|
||||||
|
if (f == FunctorAtom || f == FunctorString || f == FunctorCodes1 ||
|
||||||
|
f == FunctorCodes || f == FunctorChars1 || f == FunctorChars) {
|
||||||
|
if (strchr(io_mode, 'r')) {
|
||||||
|
return Yap_OpenBufWriteStream(PASS_REGS1);
|
||||||
|
} else {
|
||||||
|
int j = push_text_stack();
|
||||||
|
const char *buf;
|
||||||
|
|
||||||
|
buf = Yap_TextTermToText(tin PASS_REGS);
|
||||||
|
if (!buf) {
|
||||||
|
pop_text_stack(j);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
buf = pop_output_text_stack(j, buf);
|
||||||
|
Atom nat = Yap_LookupAtom(Yap_StrPrefix(buf, 32));
|
||||||
|
sno = Yap_open_buf_read_stream(buf, strlen(buf) + 1, &LOCAL_encoding,
|
||||||
|
MEM_BUF_MALLOC, nat,
|
||||||
|
MkAtomTerm(NameOfFunctor(f)));
|
||||||
|
pop_text_stack(j);
|
||||||
|
return Yap_OpenBufWriteStream(PASS_REGS1);
|
||||||
|
}
|
||||||
|
} else if (!strcmp(RepAtom(NameOfFunctor(f))->StrOfAE, "popen")) {
|
||||||
|
const char *buf;
|
||||||
|
int i = push_text_stack();
|
||||||
|
buf = Yap_TextTermToText(ArgOfTerm(1, tin) PASS_REGS);
|
||||||
|
if (buf == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
#if _WIN32
|
#if _WIN32
|
||||||
st->file = _popen(buf, io_mode);
|
st->file = _popen(buf, io_mode);
|
||||||
#else
|
#else
|
||||||
st->file = popen(buf, io_mode);
|
st->file = popen(buf, io_mode);
|
||||||
#endif
|
#endif
|
||||||
fname = "popen";
|
fname = "popen";
|
||||||
user_name = tin;
|
user_name = tin;
|
||||||
st->status |= Popen_Stream_f;
|
st->status |= Popen_Stream_f;
|
||||||
pop_text_stack(i);
|
pop_text_stack(i);
|
||||||
} else {
|
} else {
|
||||||
Yap_ThrowError(DOMAIN_ERROR_SOURCE_SINK, tin, "open");
|
Yap_ThrowError(DOMAIN_ERROR_SOURCE_SINK, tin, "open");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!strchr(io_mode, 'b') && binary_file(fname)) {
|
if (!strchr(io_mode, 'b') && binary_file(fname)) {
|
||||||
st->status |= Binary_Stream_f;
|
st->status |= Binary_Stream_f;
|
||||||
}
|
}
|
||||||
|
@ -376,10 +376,10 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
|
|||||||
TokEntry *tok = LOCAL_tokptr;
|
TokEntry *tok = LOCAL_tokptr;
|
||||||
Int start_line = tok->TokLine;
|
Int start_line = tok->TokLine;
|
||||||
Int err_line = errtok->TokLine;
|
Int err_line = errtok->TokLine;
|
||||||
Int end_line = GetCurInpLine(GLOBAL_Stream + sno);
|
Int startpos = tok->TokPos;
|
||||||
Int startpos = tok->TokPos;
|
|
||||||
Int errpos = errtok->TokPos;
|
Int errpos = errtok->TokPos;
|
||||||
Int endpos = GetCurInpPos(GLOBAL_Stream + sno);
|
Int end_line = GetCurInpLine(GLOBAL_Stream + sno);
|
||||||
|
Int endpos = GetCurInpPos(GLOBAL_Stream + sno);
|
||||||
|
|
||||||
Yap_local.ActiveError->errorNo = SYNTAX_ERROR;
|
Yap_local.ActiveError->errorNo = SYNTAX_ERROR;
|
||||||
Yap_local.ActiveError->parserFirstLine = start_line;
|
Yap_local.ActiveError->parserFirstLine = start_line;
|
||||||
@ -402,15 +402,8 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
|
|||||||
#endif
|
#endif
|
||||||
if (GLOBAL_Stream[sno].status & Seekable_Stream_f)
|
if (GLOBAL_Stream[sno].status & Seekable_Stream_f)
|
||||||
{
|
{
|
||||||
while (tok && tok->Tok != Error_tok && tok != errtok)
|
err_line = LOCAL_ActiveError->parserLine;
|
||||||
{
|
errpos = LOCAL_ActiveError->parserPos -1;
|
||||||
if (tok->TokNext)
|
|
||||||
tok = tok->TokNext;
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
err_line = tok->TokLine;
|
|
||||||
errpos = tok->TokPos -1;
|
|
||||||
if (errpos <= startpos)
|
if (errpos <= startpos)
|
||||||
{
|
{
|
||||||
o = malloc(1);
|
o = malloc(1);
|
||||||
@ -457,7 +450,7 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
|
|||||||
o[0] = '\0';
|
o[0] = '\0';
|
||||||
while (tok)
|
while (tok)
|
||||||
{
|
{
|
||||||
if (tok->Tok == Error_tok)
|
if (tok->Tok == Error_tok || tok == LOCAL_toktide )
|
||||||
{
|
{
|
||||||
o = realloc(o, strlen(o) + 1);
|
o = realloc(o, strlen(o) + 1);
|
||||||
Yap_local.ActiveError->parserTextA = o;
|
Yap_local.ActiveError->parserTextA = o;
|
||||||
@ -488,15 +481,17 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Yap_local.ActiveError->parserPos = errpos;
|
Yap_local.ActiveError->parserPos = errpos;
|
||||||
Yap_local.ActiveError->parserLine = err_line;
|
Yap_local.ActiveError->parserLine = err_line;
|
||||||
/* 0: strat, error, end line */
|
/* 0: strat, error, end line */
|
||||||
/*2 msg */
|
/*2 msg */
|
||||||
/* 1: file */
|
/* 1: file */
|
||||||
if (!msg)
|
|
||||||
msg = "unspecified";
|
|
||||||
Yap_local.ActiveError->culprit =
|
Yap_local.ActiveError->culprit =
|
||||||
|
(char*)msg;
|
||||||
|
if (Yap_local.ActiveError->errorMsg) {
|
||||||
Yap_local.ActiveError->errorMsg = (char*)msg;
|
Yap_local.ActiveError->errorMsg = (char*)msg;
|
||||||
Yap_local.ActiveError->errorMsgLen = strlen(msg);
|
Yap_local.ActiveError->errorMsgLen = strlen(Yap_local.ActiveError->errorMsg);
|
||||||
|
}
|
||||||
|
|
||||||
clean_vars(LOCAL_VarTable);
|
clean_vars(LOCAL_VarTable);
|
||||||
clean_vars(LOCAL_AnonVarTable);
|
clean_vars(LOCAL_AnonVarTable);
|
||||||
if (Yap_ExecutionMode == YAP_BOOT_MODE)
|
if (Yap_ExecutionMode == YAP_BOOT_MODE)
|
||||||
@ -904,7 +899,7 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool
|
|||||||
v_vnames = get_varnames(fe, tokstart);
|
v_vnames = get_varnames(fe, tokstart);
|
||||||
else
|
else
|
||||||
v_vnames = 0L;
|
v_vnames = 0L;
|
||||||
if (fe->t && trueGlobalPrologFlag(SINGLE_VAR_WARNINGS_FLAG))
|
if (fe->t && fe->reading_clause && trueGlobalPrologFlag(SINGLE_VAR_WARNINGS_FLAG))
|
||||||
{
|
{
|
||||||
warn_singletons(fe, tokstart);
|
warn_singletons(fe, tokstart);
|
||||||
}
|
}
|
||||||
|
@ -355,7 +355,7 @@ bool Yap_ChDir(const char *path) {
|
|||||||
int lvl = push_text_stack();
|
int lvl = push_text_stack();
|
||||||
|
|
||||||
const char *qpath = Yap_AbsoluteFile(path, true);
|
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(qpath))) {
|
if ((v = vfs_owner(qpath))) {
|
||||||
rc = v->chdir(v, (qpath));
|
rc = v->chdir(v, (qpath));
|
||||||
|
@ -680,12 +680,13 @@ static Int term_to_string(USES_REGS1) {
|
|||||||
}
|
}
|
||||||
return Yap_unify(ARG2, MkStringTerm(s));
|
return Yap_unify(ARG2, MkStringTerm(s));
|
||||||
} else if (!IsStringTerm(t2)) {
|
} else if (!IsStringTerm(t2)) {
|
||||||
Yap_Error(TYPE_ERROR_STRING, t2, "string_to_ter®m/2");
|
Yap_Error(TYPE_ERROR_STRING, t2, "term_to_string/3");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
s = StringOfTerm(t2);
|
s = StringOfTerm(t2);
|
||||||
}
|
}
|
||||||
return (rc = readFromBuffer(s, TermNil)) != 0L && Yap_unify(rc, ARG1);
|
yhandle_t y1 = Yap_InitHandle( t1 );
|
||||||
|
return (rc = readFromBuffer(s, TermNil)) != 0L && Yap_unify(rc, Yap_PopHandle(y1));
|
||||||
}
|
}
|
||||||
|
|
||||||
static Int term_to_atom(USES_REGS1) {
|
static Int term_to_atom(USES_REGS1) {
|
||||||
|
@ -1,12 +1,13 @@
|
|||||||
The Problog-I Language and Learning System {#problog}
|
@defgroup problog The Problog-I Language and Learning System
|
||||||
=====================================
|
|
||||||
|
|
||||||
[TOC]
|
@{
|
||||||
|
|
||||||
This document is intended as a user guide for the users of ProbLog-I.
|
This document is intended as a user guide for the users of ProbLog-I.
|
||||||
ProbLog is a probabilistic Prolog, a probabilistic logic programming
|
ProbLog is a probabilistic Prolog, a probabilistic logic programming
|
||||||
language, which is integrated in YAP-Prolog. Most of the work in ProbLog is now based on(Prolog-II), but we still maintain ProbLog-I in order to experiment with close integration of probabilistic nd logical systems.
|
language, which is integrated in YAP-Prolog. Most of the work in ProbLog is now based on(Prolog-II), but we still maintain ProbLog-I in order to experiment with close integration of probabilistic nd logical systems.
|
||||||
|
|
||||||
|
[TOC]
|
||||||
|
|
||||||
@section InstallingProbLog Installing ProbLog
|
@section InstallingProbLog Installing ProbLog
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,6 +48,8 @@ refactoring (trivial):
|
|||||||
#define JPL_C_LIB_VERSION_PATCH 4
|
#define JPL_C_LIB_VERSION_PATCH 4
|
||||||
#define JPL_C_LIB_VERSION_STATUS "alpha"
|
#define JPL_C_LIB_VERSION_STATUS "alpha"
|
||||||
|
|
||||||
|
#define JPL_DEBUG
|
||||||
|
|
||||||
#ifndef JPL_DEBUG
|
#ifndef JPL_DEBUG
|
||||||
/*#define DEBUG(n, g) ((void)0) */
|
/*#define DEBUG(n, g) ((void)0) */
|
||||||
#define DEBUG_LEVEL 4
|
#define DEBUG_LEVEL 4
|
||||||
@ -640,7 +642,7 @@ static JNIEnv*
|
|||||||
jni_env(void) /* economically gets a JNIEnv pointer, valid for this thread */
|
jni_env(void) /* economically gets a JNIEnv pointer, valid for this thread */
|
||||||
{ JNIEnv *env;
|
{ JNIEnv *env;
|
||||||
|
|
||||||
switch( (*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_1_8) )
|
switch( (*jvm)->GetEnv(jvm, (void**)&env, JNI_VERSION_9) )
|
||||||
{ case JNI_OK:
|
{ case JNI_OK:
|
||||||
return env;
|
return env;
|
||||||
case JNI_EDETACHED:
|
case JNI_EDETACHED:
|
||||||
@ -1819,20 +1821,20 @@ jni_create_jvm_c(
|
|||||||
char *cpoptp;
|
char *cpoptp;
|
||||||
JavaVMOption opt[MAX_JVM_OPTIONS];
|
JavaVMOption opt[MAX_JVM_OPTIONS];
|
||||||
int r;
|
int r;
|
||||||
jint n;
|
jint n = 1;
|
||||||
int optn = 0;
|
int optn = 0;
|
||||||
JNIEnv *env;
|
JNIEnv *env;
|
||||||
|
|
||||||
JPL_DEBUG(1, Sdprintf( "[creating JVM with 'java.class.path=%s']\n", classpath));
|
JPL_DEBUG(1, Sdprintf( "[creating JVM with 'java.class.path=%s']\n", classpath));
|
||||||
vm_args.version = JNI_VERSION_1_6; /* "Java 1.2 please" */
|
vm_args.version = JNI_VERSION_1_6zzzz; /* "Java 1.2 please" */
|
||||||
if ( classpath )
|
if ( classpath )
|
||||||
{
|
{
|
||||||
cpoptp = (char *)malloc(strlen(classpath)+20);
|
cpoptp = (char *)malloc(strlen(classpath) + strlen("-Djava.class.path=")+1);
|
||||||
strcpy( cpoptp, "-Djava.class.path="); /* was cpopt */
|
strcpy(cpoptp, "-Djava.class.path="); /* was cpopt */
|
||||||
strcat( cpoptp, classpath); /* oughta check length... */
|
strcat(cpoptp, classpath); /* oughta check length... */
|
||||||
vm_args.options = opt;
|
vm_args.options = opt;
|
||||||
opt[optn].optionString = cpoptp; /* was cpopt */
|
opt[optn].optionString = cpoptp; /* was cpopt */
|
||||||
optn++;
|
optn++;
|
||||||
}
|
}
|
||||||
/* opt[optn++].optionString = "-Djava.compiler=NONE"; */
|
/* opt[optn++].optionString = "-Djava.compiler=NONE"; */
|
||||||
/* opt[optn].optionString = "exit"; // I don't understand this yet... */
|
/* opt[optn].optionString = "exit"; // I don't understand this yet... */
|
||||||
@ -1841,10 +1843,12 @@ jni_create_jvm_c(
|
|||||||
/* opt[optn++].extraInfo = jvm_abort; // this function has been moved to jpl_extras.c */
|
/* opt[optn++].extraInfo = jvm_abort; // this function has been moved to jpl_extras.c */
|
||||||
/* opt[optn++].optionString = "-Xcheck:jni"; // extra checking of JNI calls */
|
/* opt[optn++].optionString = "-Xcheck:jni"; // extra checking of JNI calls */
|
||||||
#if __YAP_PROLOG__
|
#if __YAP_PROLOG__
|
||||||
opt[optn++].optionString = "-Xmx512m"; // give java enough space
|
opt[optn].optionString = malloc(strlen("-Xmx512m")+1); // give java enough space
|
||||||
|
strcpy(opt[optn++].optionString,"-Xmx512m"); // give java enough space
|
||||||
#if defined(__APPLE__)
|
#if defined(__APPLE__)
|
||||||
// I can't make jpl work with AWT graphics, without creating the extra thread.
|
// I can't make jpl work with AWT graphics, without creating the extra thread.
|
||||||
opt[optn++].optionString = "-Djava.awt.headless=true";
|
opt[optn].optionString = malloc(strlen("-Djava.awt.headless=true") + 1); // give java enough space
|
||||||
|
strcpy(opt[optn++].optionString, "-Djava.awt.headless=true"); // give java enough space
|
||||||
#endif
|
#endif
|
||||||
// opt[optn++].optionString = "-XstartOnFirstThread";
|
// opt[optn++].optionString = "-XstartOnFirstThread";
|
||||||
#endif
|
#endif
|
||||||
@ -1853,6 +1857,7 @@ jni_create_jvm_c(
|
|||||||
/* opt[optn++].extraInfo = fprintf; // no O/P, then SEGV */
|
/* opt[optn++].extraInfo = fprintf; // no O/P, then SEGV */
|
||||||
/* opt[optn++].extraInfo = xprintf; // one message, then SEGV */
|
/* opt[optn++].extraInfo = xprintf; // one message, then SEGV */
|
||||||
/* opt[optn++].optionString = "-verbose:jni"; */
|
/* opt[optn++].optionString = "-verbose:jni"; */
|
||||||
|
opt[optn].optionString = NULL;
|
||||||
|
|
||||||
if ( jvm_dia != NULL )
|
if ( jvm_dia != NULL )
|
||||||
{
|
{
|
||||||
|
@ -13,9 +13,13 @@ set(MYDDAS_DRIVERS
|
|||||||
)
|
)
|
||||||
set(MYDDAS_DBMS sqlite3 postgres odbc)
|
set(MYDDAS_DBMS sqlite3 postgres odbc)
|
||||||
|
|
||||||
|
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()
|
||||||
get_property(MYDDAS_FLAGS GLOBAL PROPERTY COMPILE_DEFINITIONS)
|
get_property(MYDDAS_FLAGS GLOBAL PROPERTY COMPILE_DEFINITIONS)
|
||||||
foreach (filename in ${MYDDAS_YPP})
|
foreach (filename ${MYDDAS_YPP})
|
||||||
get_filename_component(base ${filename} NAME_WE)
|
get_filename_component(base ${filename} NAME_WE)
|
||||||
set(base_abs ${MYDDAS_PL_OUTDIR}/${base})
|
set(base_abs ${MYDDAS_PL_OUTDIR}/${base})
|
||||||
set(outfile ${base_abs}.yap)
|
set(outfile ${base_abs}.yap)
|
||||||
@ -24,7 +28,7 @@ foreach (filename in ${MYDDAS_YPP})
|
|||||||
)
|
)
|
||||||
set_source_files_properties(outfile PROPERTIES GENERATED TRUE)
|
set_source_files_properties(outfile PROPERTIES GENERATED TRUE)
|
||||||
endforeach ()
|
endforeach ()
|
||||||
foreach (dbms in ${MYDDAS_DBMS} )
|
foreach (dbms ${MYDDAS_DBMS} )
|
||||||
set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap)
|
set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap)
|
||||||
execute_process(
|
execute_process(
|
||||||
COMMAND ${CMAKE_C_COMPILER} -D${dbms} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/myddas_driver.ypp -o ${outfile}
|
COMMAND ${CMAKE_C_COMPILER} -D${dbms} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/myddas_driver.ypp -o ${outfile}
|
||||||
@ -35,6 +39,6 @@ foreach (dbms in ${MYDDAS_DBMS} )
|
|||||||
endforeach()
|
endforeach()
|
||||||
|
|
||||||
set( MYDDAS_YAP ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/sqlitest.yap ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/chinook.db)
|
set( MYDDAS_YAP ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/sqlitest.yap ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/chinook.db)
|
||||||
#add_to_group(MYDDAS_YAP pl_library )
|
add_to_group(MYDDAS_YAP pl_library )
|
||||||
file(INSTALL ${MYDDAS_YAP}
|
file(INSTALL ${MYDDAS_YAP}
|
||||||
DESTINATION ${MYDDAS_PL_OUTDIR} )
|
DESTINATION ${MYDDAS_PL_OUTDIR} )
|
||||||
|
@ -156,11 +156,10 @@ static bool entry_to_dictionary(PyObject *dict, Term targ,
|
|||||||
*/
|
*/
|
||||||
PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
||||||
//
|
//
|
||||||
YAP_Term yt = YAP_GetFromSlot(t);
|
|
||||||
switch (PL_term_type(t)) {
|
switch (PL_term_type(t)) {
|
||||||
case PL_VARIABLE: {
|
case PL_VARIABLE: {
|
||||||
if (yt == 0) {
|
if (t == 0) {
|
||||||
Yap_ThrowError(SYSTEM_ERROR_INTERNAL, yt, "in term_to_python");
|
Yap_ThrowError(SYSTEM_ERROR_INTERNAL, t, "in term_to_python");
|
||||||
}
|
}
|
||||||
PyObject *out = PyTuple_New(1);
|
PyObject *out = PyTuple_New(1);
|
||||||
PyTuple_SET_ITEM(out, 0, PyLong_FromLong((YAP_Int)YAP_GetFromSlot(t)));
|
PyTuple_SET_ITEM(out, 0, PyLong_FromLong((YAP_Int)YAP_GetFromSlot(t)));
|
||||||
@ -169,6 +168,7 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
|||||||
return term_to_nametuple("v", 1, out);
|
return term_to_nametuple("v", 1, out);
|
||||||
};
|
};
|
||||||
case PL_ATOM: {
|
case PL_ATOM: {
|
||||||
|
YAP_Term yt = YAP_GetFromSlot(t);
|
||||||
YAP_Atom at = YAP_AtomOfTerm(yt);
|
YAP_Atom at = YAP_AtomOfTerm(yt);
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
@ -189,6 +189,7 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case PL_STRING: {
|
case PL_STRING: {
|
||||||
|
YAP_Term yt = YAP_GetFromSlot(t);
|
||||||
const char *s = NULL;
|
const char *s = NULL;
|
||||||
if (YAP_IsAtomTerm(yt)) {
|
if (YAP_IsAtomTerm(yt)) {
|
||||||
s = YAP_AtomName(YAP_AtomOfTerm(yt));
|
s = YAP_AtomName(YAP_AtomOfTerm(yt));
|
||||||
@ -389,6 +390,9 @@ PyObject *term_to_python(term_t t, bool eval, PyObject *o, bool cvt) {
|
|||||||
else
|
else
|
||||||
return Py_None;
|
return Py_None;
|
||||||
}
|
}
|
||||||
|
if (fun == FUNCTOR_var1) {
|
||||||
|
return Py_None;
|
||||||
|
}
|
||||||
atom_t name;
|
atom_t name;
|
||||||
int arity;
|
int arity;
|
||||||
|
|
||||||
|
@ -155,6 +155,8 @@ else if (PyDict_Check(pVal)) {
|
|||||||
Py_ssize_t pos = 0, tot = PyDict_Size(pVal);
|
Py_ssize_t pos = 0, tot = PyDict_Size(pVal);
|
||||||
PyObject *key, *value;
|
PyObject *key, *value;
|
||||||
Term f, *opt = &f, t, to;
|
Term f, *opt = &f, t, to;
|
||||||
|
if (tot == 0)
|
||||||
|
return MkAtomTerm( Yap_LookupAtom("{}"));
|
||||||
while (PyDict_Next(pVal, &pos, &key, &value)) {
|
while (PyDict_Next(pVal, &pos, &key, &value)) {
|
||||||
Term t0[2];
|
Term t0[2];
|
||||||
t0[0] = python_to_term__(key);
|
t0[0] = python_to_term__(key);
|
||||||
|
@ -70,16 +70,16 @@ extern bool init_python_vfs(void);
|
|||||||
|
|
||||||
extern atom_t ATOM_true, ATOM_false, ATOM_colon, ATOM_dot, ATOM_none, ATOM_t,
|
extern atom_t ATOM_true, ATOM_false, ATOM_colon, ATOM_dot, ATOM_none, ATOM_t,
|
||||||
ATOM_comma, ATOM_builtin, ATOM_V, ATOM_A, ATOM_self, ATOM_nil,
|
ATOM_comma, ATOM_builtin, ATOM_V, ATOM_A, ATOM_self, ATOM_nil,
|
||||||
ATOM_brackets, ATOM_curly_brackets;
|
ATOM_brackets, ATOM_curly_brackets;
|
||||||
|
|
||||||
extern functor_t FUNCTOR_dollar1, FUNCTOR_abs1, FUNCTOR_all1, FUNCTOR_any1,
|
extern functor_t FUNCTOR_dollar1, FUNCTOR_abs1, FUNCTOR_all1, FUNCTOR_any1,
|
||||||
FUNCTOR_as2, FUNCTOR_bin1, FUNCTOR_brackets1, FUNCTOR_comma2, FUNCTOR_dir1,
|
FUNCTOR_as2, FUNCTOR_bin1, FUNCTOR_brackets1, FUNCTOR_comma2, FUNCTOR_dir1,
|
||||||
FUNCTOR_float1, FUNCTOR_int1, FUNCTOR_iter1, FUNCTOR_iter2, FUNCTOR_long1,
|
FUNCTOR_float1, FUNCTOR_int1, FUNCTOR_iter1, FUNCTOR_var1, FUNCTOR_iter2, FUNCTOR_long1, FUNCTOR_var1,
|
||||||
FUNCTOR_len1, FUNCTOR_curly1, FUNCTOR_ord1, FUNCTOR_range1, FUNCTOR_range2,
|
FUNCTOR_len1, FUNCTOR_curly1, FUNCTOR_ord1, FUNCTOR_range1, FUNCTOR_range2,
|
||||||
FUNCTOR_range3, FUNCTOR_sum1, FUNCTOR_pointer1, FUNCTOR_complex2,
|
FUNCTOR_range3, FUNCTOR_sum1, FUNCTOR_pointer1, FUNCTOR_complex2,
|
||||||
FUNCTOR_plus2, FUNCTOR_sub2, FUNCTOR_mul2, FUNCTOR_div2, FUNCTOR_hat2,
|
FUNCTOR_plus2, FUNCTOR_sub2, FUNCTOR_mul2, FUNCTOR_div2, FUNCTOR_hat2,
|
||||||
FUNCTOR_colon2, FUNCTOR_comma2, FUNCTOR_equal2, FUNCTOR_sqbrackets2,
|
FUNCTOR_colon2, FUNCTOR_comma2, FUNCTOR_equal2, FUNCTOR_sqbrackets2,
|
||||||
FUNCTOR_dot2;
|
FUNCTOR_dot2, FUNCTOR_var1;
|
||||||
|
|
||||||
extern X_API PyObject *py_Main;
|
extern X_API PyObject *py_Main;
|
||||||
extern X_API PyObject *py_Yapex;
|
extern X_API PyObject *py_Yapex;
|
||||||
|
@ -591,7 +591,6 @@ static long get_len_of_range(long lo, long hi, long step) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#if PY_MAJOR_VERSION >= 3
|
||||||
/*
|
|
||||||
static PyStructSequence_Field pnull[] = {
|
static PyStructSequence_Field pnull[] = {
|
||||||
{"A1", NULL}, {"A2", NULL}, {"A3", NULL}, {"A4", NULL}, {"A5", NULL},
|
{"A1", NULL}, {"A2", NULL}, {"A3", NULL}, {"A4", NULL}, {"A5", NULL},
|
||||||
{"A6", NULL}, {"A7", NULL}, {"A8", NULL}, {"A9", NULL}, {"A9", NULL},
|
{"A6", NULL}, {"A7", NULL}, {"A8", NULL}, {"A9", NULL}, {"A9", NULL},
|
||||||
@ -601,133 +600,7 @@ static long get_len_of_range(long lo, long hi, long step) {
|
|||||||
{"A24", NULL}, {"A25", NULL}, {"A26", NULL}, {"A27", NULL}, {"A28", NULL},
|
{"A24", NULL}, {"A25", NULL}, {"A26", NULL}, {"A27", NULL}, {"A28", NULL},
|
||||||
{"A29", NULL}, {"A29", NULL}, {"A30", NULL}, {"A31", NULL}, {"A32", NULL},
|
{"A29", NULL}, {"A29", NULL}, {"A30", NULL}, {"A31", NULL}, {"A32", NULL},
|
||||||
{NULL, NULL}};
|
{NULL, NULL}};
|
||||||
*/
|
|
||||||
|
|
||||||
static PyObject *structseq_str(PyObject *iobj) {
|
|
||||||
|
|
||||||
/* buffer and type size were chosen well considered. */
|
|
||||||
#define REPR_BUFFER_SIZE 512
|
|
||||||
#define TYPE_MAXSIZE 100
|
|
||||||
|
|
||||||
PyStructSequence *obj = (PyStructSequence *)iobj;
|
|
||||||
PyTypeObject *typ = Py_TYPE(obj);
|
|
||||||
bool removelast = false;
|
|
||||||
Py_ssize_t len, i;
|
|
||||||
char buf[REPR_BUFFER_SIZE];
|
|
||||||
char *endofbuf, *pbuf = buf;
|
|
||||||
/* pointer to end of writeable buffer; safes space for "...)\0" */
|
|
||||||
endofbuf = &buf[REPR_BUFFER_SIZE - 5];
|
|
||||||
|
|
||||||
/* "typename(", limited to TYPE_MAXSIZE */
|
|
||||||
len =
|
|
||||||
strlen(typ->tp_name) > TYPE_MAXSIZE ? TYPE_MAXSIZE : strlen(typ->tp_name);
|
|
||||||
strncpy(pbuf, typ->tp_name, len);
|
|
||||||
pbuf += len;
|
|
||||||
*pbuf++ = '(';
|
|
||||||
|
|
||||||
for (i = 0; i < ((PyStructSequence *)obj)->ob_base.ob_size; i++) {
|
|
||||||
PyObject *val, *repr;
|
|
||||||
const char *crepr;
|
|
||||||
|
|
||||||
val = PyStructSequence_GET_ITEM(obj, i);
|
|
||||||
repr = PyObject_Str(val);
|
|
||||||
if (repr == NULL)
|
|
||||||
return Py_None;
|
|
||||||
crepr = PyUnicode_AsUTF8(repr);
|
|
||||||
if (crepr == NULL) {
|
|
||||||
Py_DECREF(repr);
|
|
||||||
return Py_None;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* + 3: keep space for ", " */
|
|
||||||
len = strlen(crepr) + 2;
|
|
||||||
if ((pbuf + len) <= endofbuf) {
|
|
||||||
strcpy(pbuf, crepr);
|
|
||||||
pbuf += strlen(crepr);
|
|
||||||
*pbuf++ = ',';
|
|
||||||
*pbuf++ = ' ';
|
|
||||||
removelast = 1;
|
|
||||||
Py_DECREF(repr);
|
|
||||||
} else {
|
|
||||||
strcpy(pbuf, "...");
|
|
||||||
pbuf += 3;
|
|
||||||
removelast = 0;
|
|
||||||
Py_DECREF(repr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (removelast) {
|
|
||||||
/* overwrite last ", " */
|
|
||||||
pbuf -= 2;
|
|
||||||
}
|
|
||||||
*pbuf++ = ')';
|
|
||||||
*pbuf = '\0';
|
|
||||||
|
|
||||||
return PyUnicode_FromString(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *structseq_repr(PyObject *iobj) {
|
|
||||||
|
|
||||||
/* buffer and type size were chosen well considered. */
|
|
||||||
#define REPR_BUFFER_SIZE 512
|
|
||||||
#define TYPE_MAXSIZE 100
|
|
||||||
|
|
||||||
PyStructSequence *obj = (PyStructSequence *)iobj;
|
|
||||||
PyTypeObject *typ = Py_TYPE(obj);
|
|
||||||
bool removelast = false;
|
|
||||||
Py_ssize_t len, i;
|
|
||||||
char buf[REPR_BUFFER_SIZE];
|
|
||||||
char *endofbuf, *pbuf = buf;
|
|
||||||
/* pointer to end of writeable buffer; safes space for "...)\0" */
|
|
||||||
endofbuf = &buf[REPR_BUFFER_SIZE - 5];
|
|
||||||
|
|
||||||
/* "typename(", limited to TYPE_MAXSIZE */
|
|
||||||
len =
|
|
||||||
strlen(typ->tp_name) > TYPE_MAXSIZE ? TYPE_MAXSIZE : strlen(typ->tp_name);
|
|
||||||
strncpy(pbuf, typ->tp_name, len);
|
|
||||||
pbuf += len;
|
|
||||||
*pbuf++ = '(';
|
|
||||||
|
|
||||||
for (i = 0; i < ((PyStructSequence *)obj)->ob_base.ob_size; i++) {
|
|
||||||
PyObject *val, *repr;
|
|
||||||
const char *crepr;
|
|
||||||
|
|
||||||
val = PyStructSequence_GET_ITEM(obj, i);
|
|
||||||
repr = PyObject_Repr(val);
|
|
||||||
if (repr == NULL)
|
|
||||||
return NULL;
|
|
||||||
crepr = PyUnicode_AsUTF8(repr);
|
|
||||||
if (crepr == NULL) {
|
|
||||||
Py_DECREF(repr);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* + 3: keep space for ", " */
|
|
||||||
len = strlen(crepr) + 2;
|
|
||||||
if ((pbuf + len) <= endofbuf) {
|
|
||||||
strcpy(pbuf, crepr);
|
|
||||||
pbuf += strlen(crepr);
|
|
||||||
*pbuf++ = ',';
|
|
||||||
*pbuf++ = ' ';
|
|
||||||
removelast = 1;
|
|
||||||
Py_DECREF(repr);
|
|
||||||
} else {
|
|
||||||
strcpy(pbuf, "...");
|
|
||||||
pbuf += 3;
|
|
||||||
removelast = 0;
|
|
||||||
Py_DECREF(repr);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (removelast) {
|
|
||||||
/* overwrite last ", " */
|
|
||||||
pbuf -= 2;
|
|
||||||
}
|
|
||||||
*pbuf++ = ')';
|
|
||||||
*pbuf = '\0';
|
|
||||||
|
|
||||||
return PyUnicode_FromString(buf);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static bool legal_symbol(const char *s) {
|
static bool legal_symbol(const char *s) {
|
||||||
@ -743,7 +616,7 @@ static bool legal_symbol(const char *s) {
|
|||||||
PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
|
PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
|
||||||
PyTypeObject *typp;
|
PyTypeObject *typp;
|
||||||
PyObject *key = PyUnicode_FromString(s), *d;
|
PyObject *key = PyUnicode_FromString(s), *d;
|
||||||
if (!legal_symbol(s)) {
|
if (legal_symbol(s)) {
|
||||||
|
|
||||||
if (!Py_f2p) {
|
if (!Py_f2p) {
|
||||||
PyObject *o1;
|
PyObject *o1;
|
||||||
@ -761,32 +634,41 @@ PyObject *term_to_nametuple(const char *s, arity_t arity, PyObject *tuple) {
|
|||||||
if ((d = PyList_GetItem(Py_f2p, arity - 1)) && PyDict_Contains(d, key)) {
|
if ((d = PyList_GetItem(Py_f2p, arity - 1)) && PyDict_Contains(d, key)) {
|
||||||
typp = (PyTypeObject *)d;
|
typp = (PyTypeObject *)d;
|
||||||
} else {
|
} else {
|
||||||
typp = calloc(sizeof(PyTypeObject), 1);
|
PyStructSequence_Desc *desc = PyMem_Calloc(sizeof(PyStructSequence_Desc), 1);
|
||||||
PyStructSequence_Desc *desc = calloc(sizeof(PyStructSequence_Desc), 1);
|
char *tnp;
|
||||||
desc->name = PyMem_Malloc(strlen(s) + 1);
|
desc->name = tnp = PyMem_Malloc(strlen(s) + 1);
|
||||||
|
strcpy(tnp, s);
|
||||||
desc->doc = "YAPTerm";
|
desc->doc = "YAPTerm";
|
||||||
desc->fields = NULL;
|
desc->fields = pnull;
|
||||||
desc->n_in_sequence = arity;
|
desc->n_in_sequence = arity;
|
||||||
|
typp = PyStructSequence_NewType(desc);
|
||||||
|
typp->tp_name = desc->name;
|
||||||
|
|
||||||
if (PyStructSequence_InitType2(typp, desc) < 0)
|
if (PyStructSequence_InitType2(typp, desc) < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
// typp->tp_flags &= ~Py_TPFLAGS_HEAPTYPE;
|
typp->tp_traverse = NULL;
|
||||||
// typp->tp_flags &= ~Py_TPFLAGS_HAVE_GC;
|
typp->tp_flags |=
|
||||||
// typp->tp_str = structseq_str;
|
// Py_TPFLAGS_TUPLE_SUBCLASS|
|
||||||
typp->tp_repr = structseq_repr;
|
Py_TPFLAGS_BASETYPE|
|
||||||
// typp = PyStructSequence_NewType(desc);
|
Py_TPFLAGS_HEAPTYPE;
|
||||||
// don't do this: we cannot add a type as an atribute.
|
// don't do this: we cannot add a type as an atribute.
|
||||||
// PyModule_AddGObject(py_Main, s, (PyObject *)typp);
|
// PyModule_AddGObject(py_Main, s, (PyObject *)typp);
|
||||||
if (d && !PyDict_Contains(d, key))
|
if (d && !PyDict_Contains(d, key)) {
|
||||||
PyDict_SetItem(d, key, (PyObject*)typp);
|
PyDict_SetItem(d, key, (void*)typp);
|
||||||
|
Py_INCREF(key);
|
||||||
|
Py_INCREF(typp);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
PyObject *o = PyStructSequence_New(typp);
|
PyObject *o = PyStructSequence_New(typp);
|
||||||
Py_INCREF(typp);
|
Py_INCREF(typp);
|
||||||
arity_t i;
|
arity_t i;
|
||||||
for (i = 0; i < arity; i++) {
|
for (i = 0; i < arity; i++) {
|
||||||
PyObject *pArg = PyTuple_GET_ITEM(tuple, i);
|
PyObject *pArg = PyTuple_GET_ITEM(tuple, i);
|
||||||
|
if (pArg) {
|
||||||
Py_INCREF(pArg);
|
Py_INCREF(pArg);
|
||||||
if (pArg)
|
|
||||||
PyStructSequence_SET_ITEM(o, i, pArg);
|
PyStructSequence_SET_ITEM(o, i, pArg);
|
||||||
|
|
||||||
|
}
|
||||||
// PyObject_Print(pArg,stderr,0);fputc('\n',stderr);
|
// PyObject_Print(pArg,stderr,0);fputc('\n',stderr);
|
||||||
}
|
}
|
||||||
//((PyStructSequence *)o)->ob_base.ob_size = arity;
|
//((PyStructSequence *)o)->ob_base.ob_size = arity;
|
||||||
@ -860,6 +742,9 @@ PyObject *compound_to_pytree(term_t t, PyObject *context, bool cvt) {
|
|||||||
atom_t name;
|
atom_t name;
|
||||||
int arity;
|
int arity;
|
||||||
|
|
||||||
|
if (PL_is_variable(t)) {
|
||||||
|
return term_to_python(t, false, context, cvt);
|
||||||
|
}
|
||||||
o = find_obj(context, t, false);
|
o = find_obj(context, t, false);
|
||||||
AOK(PL_get_name_arity(t, &name, &arity), NULL);
|
AOK(PL_get_name_arity(t, &name, &arity), NULL);
|
||||||
if (arity == 0)
|
if (arity == 0)
|
||||||
@ -876,27 +761,26 @@ PyObject *compound_to_pytree(term_t t, PyObject *context, bool cvt) {
|
|||||||
if (!(s = PL_atom_chars(name))) {
|
if (!(s = PL_atom_chars(name))) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
term_t tleft;
|
Term tleft;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
PyObject *out = PyTuple_New(arity);
|
PyObject *out = PyTuple_New(arity);
|
||||||
DebugPrintf("Tuple %p\n", o);
|
if (CHECKNULL(t, out) == NULL) {
|
||||||
tleft = PL_new_term_ref();
|
PyErr_Print();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
//DebugPrintf("Tuple %s/%d = %p\n", name, arity, out);
|
||||||
for (i = 0; i < arity; i++) {
|
for (i = 0; i < arity; i++) {
|
||||||
PyObject *pArg;
|
PyObject *pArg;
|
||||||
AOK(PL_get_arg(i + 1, t, tleft), NULL);
|
tleft = ArgOfTerm(i + 1, Yap_GetFromSlot(t));
|
||||||
pArg = term_to_python(tleft, false, NULL, cvt);
|
pArg = yap_to_python(tleft, false, NULL, cvt);
|
||||||
if (pArg) {
|
if (pArg) {
|
||||||
/* pArg reference stolen here: */
|
/* pArg reference stolen here: */
|
||||||
PyTuple_SET_ITEM(out, i, pArg);
|
PyTuple_SET_ITEM(out, i, pArg);
|
||||||
Py_INCREF(pArg);
|
Py_INCREF(pArg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (CHECKNULL(t, out) == NULL) {
|
PyObject *c = lookupPySymbol(s, out, NULL);
|
||||||
PyErr_Print();
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
PyObject *c = lookupPySymbol(s, o, NULL);
|
|
||||||
|
|
||||||
if (c && PyCallable_Check(c)) {
|
if (c && PyCallable_Check(c)) {
|
||||||
PyObject *n = PyTuple_New(arity);
|
PyObject *n = PyTuple_New(arity);
|
||||||
@ -904,7 +788,14 @@ PyObject *compound_to_pytree(term_t t, PyObject *context, bool cvt) {
|
|||||||
PyTuple_SET_ITEM(n, 1, out);
|
PyTuple_SET_ITEM(n, 1, out);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
return term_to_nametuple(s, arity, out);
|
if (cvt)
|
||||||
|
return term_to_nametuple(s, arity, out);
|
||||||
|
else {
|
||||||
|
PyObject *rc = PyTuple_New(2);
|
||||||
|
PyTuple_SetItem(rc, 0, PyUnicode_FromString(s));
|
||||||
|
PyTuple_SetItem(rc, 1, out);
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1135,7 +1026,13 @@ PyObject *compound_to_pyeval(term_t t, PyObject *context, bool cvt) {
|
|||||||
// PyObject_Print(rc, stderr, 0);
|
// PyObject_Print(rc, stderr, 0);
|
||||||
// DebugPrintf("CallObject %p\n", rc);
|
// DebugPrintf("CallObject %p\n", rc);
|
||||||
} else {
|
} else {
|
||||||
|
if (cvt)
|
||||||
rc = term_to_nametuple(s, arity, pArgs);
|
rc = term_to_nametuple(s, arity, pArgs);
|
||||||
|
else {
|
||||||
|
rc = PyTuple_New(2);
|
||||||
|
PyTuple_SetItem(rc, 0, ys);
|
||||||
|
PyTuple_SetItem(rc, 1, pArgs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc;
|
return rc;
|
||||||
|
@ -8,10 +8,16 @@
|
|||||||
|
|
||||||
YAP_Term TermErrStream, TermOutStream;
|
YAP_Term TermErrStream, TermOutStream;
|
||||||
|
|
||||||
static void pyflush(StreamDesc *st) {
|
static void py_flush(int sno) {
|
||||||
|
StreamDesc *st = YAP_GetStreamFromId(sno);
|
||||||
|
PyObject *fl =
|
||||||
|
PyObject_GetAttrString(st->u.private_data, "flush");
|
||||||
|
if (fl) {
|
||||||
|
PyObject_CallFunctionObjArgs(fl,
|
||||||
|
NULL);
|
||||||
|
}
|
||||||
#if 0
|
#if 0
|
||||||
st->u.w_irl.ptr[0] = '\0';
|
// fprintf(stderr,"%s\n", st->u.w_irl.buf);
|
||||||
fprintf(stderr,"%s\n", st->u.w_irl.buf);
|
|
||||||
term_t tg = python_acquire_GIL();
|
term_t tg = python_acquire_GIL();
|
||||||
if (st->user_name == TermOutStream){
|
if (st->user_name == TermOutStream){
|
||||||
PySys_WriteStdout("%s", st->u.w_irl.buf);
|
PySys_WriteStdout("%s", st->u.w_irl.buf);
|
||||||
@ -31,13 +37,13 @@ static int py_putc(int sno, int ch) {
|
|||||||
StreamDesc *st = YAP_GetStreamFromId(sno);
|
StreamDesc *st = YAP_GetStreamFromId(sno);
|
||||||
#if 0
|
#if 0
|
||||||
if (false && (st->user_name == TermOutStream || st->user_name == TermErrStream)) {
|
if (false && (st->user_name == TermOutStream || st->user_name == TermErrStream)) {
|
||||||
size_t sz = put_utf8(st->u.w_irl.ptr, ch);
|
size_t sz = put_utf8(st->u.w_irl.ptr, ch);
|
||||||
if (sz > 0) {
|
if (sz > 0) {
|
||||||
st->u.w_irl.ptr += sz;
|
st->u.w_irl.ptr += sz;
|
||||||
if (ch == '\n' || st->u.w_irl.ptr - st->u.w_irl.buf > 256)
|
if ( st->u.w_irl.ptr - st->u.w_irl.buf > 256)
|
||||||
{pyflush(st); }
|
{py_flush(sno); }
|
||||||
}
|
}
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
unsigned char s[2];
|
unsigned char s[2];
|
||||||
@ -50,8 +56,8 @@ static int py_putc(int sno, int ch) {
|
|||||||
python_release_GIL(g0);
|
python_release_GIL(g0);
|
||||||
if ((err = PyErr_Occurred())) {
|
if ((err = PyErr_Occurred())) {
|
||||||
PyErr_SetString(
|
PyErr_SetString(
|
||||||
err,
|
err,
|
||||||
"Error in put\n"); // %s:%s:%d!\n", __FILE__, __FUNCTION__, __LINE__);
|
"Error in put\n"); // %s:%s:%d!\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
}
|
}
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
@ -63,13 +69,13 @@ static int py_wputc(int sno, int ch) {
|
|||||||
StreamDesc *st = YAP_GetStreamFromId(sno);
|
StreamDesc *st = YAP_GetStreamFromId(sno);
|
||||||
#if 0
|
#if 0
|
||||||
if (false && (st->user_name == TermOutStream || st->user_name == TermErrStream)) {
|
if (false && (st->user_name == TermOutStream || st->user_name == TermErrStream)) {
|
||||||
size_t sz = put_utf8(st->u.w_irl.ptr, ch);
|
size_t sz = put_utf8(st->u.w_irl.ptr, ch);
|
||||||
if (sz > 0) {
|
if (sz > 0) {
|
||||||
st->u.w_irl.ptr += sz;
|
st->u.w_irl.ptr += sz;
|
||||||
if (ch == '\n' || st->u.w_irl.ptr - st->u.w_irl.buf > 256)
|
if ( st->u.w_irl.ptr - st->u.w_irl.buf > 256)
|
||||||
{pyflush(st); }
|
{py_flush(sno); }
|
||||||
}
|
}
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
unsigned char s[8];
|
unsigned char s[8];
|
||||||
@ -82,8 +88,8 @@ static int py_wputc(int sno, int ch) {
|
|||||||
python_release_GIL(g0);
|
python_release_GIL(g0);
|
||||||
if ((err = PyErr_Occurred())) {
|
if ((err = PyErr_Occurred())) {
|
||||||
PyErr_SetString(
|
PyErr_SetString(
|
||||||
err,
|
err,
|
||||||
"Error in put\n"); // %s:%s:%d!\n", __FILE__, __FUNCTION__, __LINE__);
|
"Error in put\n"); // %s:%s:%d!\n", __FILE__, __FUNCTION__, __LINE__);
|
||||||
}
|
}
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
@ -112,16 +118,16 @@ static void *py_open(VFS_t *me, const char *name, const char *io_mode,
|
|||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
if (!outbuf)
|
if (!outbuf)
|
||||||
outbuf = ( unsigned char *)malloc(1024);
|
outbuf = ( unsigned char *)malloc(1024);
|
||||||
st->u.w_irl.ptr = st->u.w_irl.buf = outbuf;
|
st->u.w_irl.ptr = st->u.w_irl.buf = outbuf;
|
||||||
|
|
||||||
|
|
||||||
]\]
|
]\]
|
||||||
st->user_name = TermOutStream;
|
st->user_name = TermOutStream;
|
||||||
} else if (strcmp(name, "sys.stderr") == 0) {
|
} else if (strcmp(name, "sys.stderr") == 0) {
|
||||||
st->user_name = TermErrStream;
|
st->user_name = TermErrStream;
|
||||||
if (!errbuf)
|
if (!errbuf)
|
||||||
errbuf = ( unsigned char *)malloc(1024);
|
errbuf = ( unsigned char *)malloc(1024);
|
||||||
st->u.w_irl.ptr = st->u.w_irl.buf = errbuf;
|
st->u.w_irl.ptr = st->u.w_irl.buf = errbuf;
|
||||||
// } else if (strcmp(name, "input") == 0) {
|
// } else if (strcmp(name, "input") == 0) {
|
||||||
//pystream = PyObject_Call(pystream, PyTuple_New(0), NULL);
|
//pystream = PyObject_Call(pystream, PyTuple_New(0), NULL);
|
||||||
@ -131,18 +137,11 @@ static void *py_open(VFS_t *me, const char *name, const char *io_mode,
|
|||||||
st->vfs = me;
|
st->vfs = me;
|
||||||
st->file = NULL;
|
st->file = NULL;
|
||||||
python_release_GIL(ctk);
|
python_release_GIL(ctk);
|
||||||
|
if (st->status & (Output_Stream_f | Append_Stream_f))
|
||||||
|
py_flush(sno);
|
||||||
return st;
|
return st;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void py_flush(int sno) {
|
|
||||||
StreamDesc *s = YAP_GetStreamFromId(sno);
|
|
||||||
term_t tg = python_acquire_GIL();
|
|
||||||
PyObject *flush = PyObject_GetAttrString(s->u.private_data, "flush");
|
|
||||||
pyflush(s);
|
|
||||||
PyObject_CallFunction(flush, NULL);
|
|
||||||
python_release_GIL(tg);
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool py_close(int sno) {
|
static bool py_close(int sno) {
|
||||||
StreamDesc *st = YAP_RepStreamFromId(sno);
|
StreamDesc *st = YAP_RepStreamFromId(sno);
|
||||||
if (st->status & (Output_Stream_f | Append_Stream_f))
|
if (st->status & (Output_Stream_f | Append_Stream_f))
|
||||||
@ -158,49 +157,36 @@ static bool py_close(int sno) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool pygetLine(StreamDesc *rl_iostream, int sno) {
|
static bool pygetLine(StreamDesc *rl_iostream, int sno) {
|
||||||
// term_t ctk = python_acquire_GIL();
|
|
||||||
const char *myrl_line;
|
const char *myrl_line;
|
||||||
PyObject *user_line, *readl = NULL;
|
PyObject *user_line;
|
||||||
PyObject *err;
|
PyObject *err;
|
||||||
StreamDesc *s = YAP_GetStreamFromId(sno);
|
StreamDesc *s = YAP_GetStreamFromId(sno);
|
||||||
// term_t tg = python_acquire_GIL();
|
term_t tg = python_acquire_GIL();
|
||||||
PyObject_Print(s->u.private_data,stderr,0);
|
// PyObject_Print(s->u.private_data,stderr,0);
|
||||||
if (PyFunction_Check( s->u.private_data )) {
|
if (PyFunction_Check( s->u.private_data )) {
|
||||||
readl = s->u.private_data;
|
user_line = PyObject_CallFunctionObjArgs( s->u.private_data ,
|
||||||
|
NULL);
|
||||||
|
} else if ( s->u.private_data == NULL) {
|
||||||
|
PyObject *readl =
|
||||||
|
PyObject_GetAttrString(s->u.private_data, "readline");
|
||||||
|
if (!readl) {
|
||||||
|
readl =
|
||||||
|
PyObject_GetAttrString(s->u.private_data, "read");
|
||||||
}
|
}
|
||||||
if (!strcmp(RepAtom(s->name)->StrOfAE, "user_input")) {
|
if (readl)
|
||||||
// note that input may change
|
user_line = PyObject_CallFunctionObjArgs(readl,
|
||||||
readl = PythonLookupSpecial("input");
|
NULL);
|
||||||
}
|
}
|
||||||
if (readl == NULL) {
|
python_release_GIL(tg);
|
||||||
readl = PythonLookup("readline", s->u.private_data);
|
if ((err = PyErr_Occurred())) {
|
||||||
|
if (PyErr_GivenExceptionMatches(err, PyExc_EOFError))
|
||||||
|
return NULL;
|
||||||
|
PyErr_Print();
|
||||||
|
Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), NULL);
|
||||||
}
|
}
|
||||||
if (readl == NULL) {
|
|
||||||
readl = PythonLookup("read", s->u.private_data);
|
|
||||||
}
|
|
||||||
if (readl == NULL) {
|
|
||||||
if ((err = PyErr_Occurred())) {
|
|
||||||
PyErr_Print();
|
|
||||||
Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
user_line = PyObject_CallFunctionObjArgs(readl,
|
|
||||||
NULL);
|
|
||||||
if ((err = PyErr_Occurred())) {
|
|
||||||
PyErr_Print();
|
|
||||||
Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), err);
|
|
||||||
}
|
|
||||||
myrl_line = PyUnicode_AsUTF8(user_line);
|
myrl_line = PyUnicode_AsUTF8(user_line);
|
||||||
if (myrl_line == NULL)
|
if (myrl_line == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
if ((err = PyErr_Occurred())) {
|
|
||||||
|
|
||||||
if (PyErr_GivenExceptionMatches(err, PyExc_EOFError))
|
|
||||||
return NULL;
|
|
||||||
PyErr_Print();
|
|
||||||
Yap_ThrowError(SYSTEM_ERROR_GET_FAILED, YAP_MkIntTerm(sno), err);
|
|
||||||
|
|
||||||
}
|
|
||||||
rl_iostream->u.irl.ptr = rl_iostream->u.irl.buf = (unsigned char *)myrl_line;
|
rl_iostream->u.irl.ptr = rl_iostream->u.irl.buf = (unsigned char *)myrl_line;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -247,11 +233,11 @@ static int py_wgetc(int sno) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@brief Yap_ReadlinePeekChar peeks the next char from the
|
@brief Yap_ReadlinePeekChar peeks the next char from the
|
||||||
readline buffer, but does not actually grab it.
|
readline buffer, but does not actually grab it.
|
||||||
|
|
||||||
The idea is to take advantage of the buffering. Special care must be taken
|
The idea is to take advantage of the buffering. Special care must be taken
|
||||||
with EOF, though.
|
with EOF, though.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
static int py_peek(int sno) {
|
static int py_peek(int sno) {
|
||||||
@ -280,7 +266,7 @@ static int py_peek(int sno) {
|
|||||||
static int64_t py_seek(int sno, int64_t where, int how) {
|
static int64_t py_seek(int sno, int64_t where, int how) {
|
||||||
StreamDesc *g0 = YAP_RepStreamFromId(sno);
|
StreamDesc *g0 = YAP_RepStreamFromId(sno);
|
||||||
term_t s0 = python_acquire_GIL();
|
term_t s0 = python_acquire_GIL();
|
||||||
PyObject *fseek = PyObject_GetAttrString(g0->u.private_data, "seek");
|
PyObject *fseek = PyObject_GetAttrString(g0->u.private_data, "seek");
|
||||||
PyObject *pyr = PyObject_CallFunctionObjArgs(fseek, PyLong_FromLong(where),
|
PyObject *pyr = PyObject_CallFunctionObjArgs(fseek, PyLong_FromLong(where),
|
||||||
PyLong_FromLong(how), NULL);
|
PyLong_FromLong(how), NULL);
|
||||||
python_release_GIL(s0);
|
python_release_GIL(s0);
|
||||||
@ -311,7 +297,7 @@ bool init_python_vfs(void) {
|
|||||||
initialized = true;
|
initialized = true;
|
||||||
pystream.name = "python stream";
|
pystream.name = "python stream";
|
||||||
pystream.vflags =
|
pystream.vflags =
|
||||||
VFS_CAN_WRITE | VFS_CAN_EXEC | VFS_CAN_READ | VFS_HAS_PREFIX;
|
VFS_CAN_WRITE | VFS_CAN_EXEC | VFS_CAN_READ | VFS_HAS_PREFIX;
|
||||||
pystream.prefix = "/python/";
|
pystream.prefix = "/python/";
|
||||||
pystream.suffix = NULL;
|
pystream.suffix = NULL;
|
||||||
pystream.open = py_open;
|
pystream.open = py_open;
|
||||||
|
@ -26,6 +26,23 @@ static foreign_t python_len(term_t tobj, term_t tf) {
|
|||||||
len = PyObject_Length(o);
|
len = PyObject_Length(o);
|
||||||
pyErrorAndReturn(PL_unify_int64(tf, len));
|
pyErrorAndReturn(PL_unify_int64(tf, len));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static foreign_t python_represent( term_t name, term_t tobj) {
|
||||||
|
term_t stackp = python_acquire_GIL();
|
||||||
|
PyObject *e;
|
||||||
|
|
||||||
|
e = term_to_python(tobj, false, NULL, false);
|
||||||
|
if (e == NULL) {
|
||||||
|
python_release_GIL(stackp);
|
||||||
|
pyErrorAndReturn(false);
|
||||||
|
}
|
||||||
|
bool b = python_assign(name, e, NULL);
|
||||||
|
python_release_GIL(stackp);
|
||||||
|
pyErrorAndReturn(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static foreign_t python_clear_errors(void) {
|
static foreign_t python_clear_errors(void) {
|
||||||
PyErr_Clear();
|
PyErr_Clear();
|
||||||
return true;
|
return true;
|
||||||
@ -744,6 +761,7 @@ install_t install_pypreds(void) {
|
|||||||
PL_register_foreign("python_index", 3, python_index, 0);
|
PL_register_foreign("python_index", 3, python_index, 0);
|
||||||
PL_register_foreign("python_field", 3, python_field, 0);
|
PL_register_foreign("python_field", 3, python_field, 0);
|
||||||
PL_register_foreign("python_assign", 2, assign_python, 0);
|
PL_register_foreign("python_assign", 2, assign_python, 0);
|
||||||
|
PL_register_foreign("python_represents", 2, python_represent, 0);
|
||||||
PL_register_foreign("python_export", 2, python_export, 0);
|
PL_register_foreign("python_export", 2, python_export, 0);
|
||||||
PL_register_foreign("python_function", 1, python_function, 0);
|
PL_register_foreign("python_function", 1, python_function, 0);
|
||||||
PL_register_foreign("python_slice", 4, python_slice, 0);
|
PL_register_foreign("python_slice", 4, python_slice, 0);
|
||||||
|
@ -1,4 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* @file python.c
|
||||||
|
*
|
||||||
|
* @brief data structures and init for Py4YAP library
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup PY4YAP
|
||||||
|
* @ingroup python
|
||||||
|
* @brief make Python talk to YAP
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
|
||||||
#include "py4yap.h"
|
#include "py4yap.h"
|
||||||
#include <VFS.h>
|
#include <VFS.h>
|
||||||
@ -18,7 +30,7 @@ functor_t FUNCTOR_dollar1, FUNCTOR_abs1, FUNCTOR_all1, FUNCTOR_any1, FUNCTOR_as2
|
|||||||
FUNCTOR_range3, FUNCTOR_sum1, FUNCTOR_pointer1, FUNCTOR_complex2,
|
FUNCTOR_range3, FUNCTOR_sum1, FUNCTOR_pointer1, FUNCTOR_complex2,
|
||||||
FUNCTOR_plus2, FUNCTOR_sub2, FUNCTOR_mul2, FUNCTOR_div2, FUNCTOR_hat2,
|
FUNCTOR_plus2, FUNCTOR_sub2, FUNCTOR_mul2, FUNCTOR_div2, FUNCTOR_hat2,
|
||||||
FUNCTOR_colon2, FUNCTOR_comma2, FUNCTOR_equal2, FUNCTOR_sqbrackets2,
|
FUNCTOR_colon2, FUNCTOR_comma2, FUNCTOR_equal2, FUNCTOR_sqbrackets2,
|
||||||
FUNCTOR_dot2, FUNCTOR_brackets1;
|
FUNCTOR_dot2, FUNCTOR_brackets1, FUNCTOR_var1;
|
||||||
|
|
||||||
X_API PyObject *py_Atoms;
|
X_API PyObject *py_Atoms;
|
||||||
X_API PyObject *py_Yapex;
|
X_API PyObject *py_Yapex;
|
||||||
@ -98,6 +110,7 @@ static void install_py_constants(void) {
|
|||||||
FUNCTOR_comma2 = PL_new_functor(PL_new_atom(","), 2);
|
FUNCTOR_comma2 = PL_new_functor(PL_new_atom(","), 2);
|
||||||
FUNCTOR_equal2 = PL_new_functor(PL_new_atom("="), 2);
|
FUNCTOR_equal2 = PL_new_functor(PL_new_atom("="), 2);
|
||||||
FUNCTOR_sqbrackets2 = PL_new_functor(PL_new_atom("[]"), 2);
|
FUNCTOR_sqbrackets2 = PL_new_functor(PL_new_atom("[]"), 2);
|
||||||
|
FUNCTOR_var1 = PL_new_functor(PL_new_atom("$VAR"), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
foreign_t end_python(void) {
|
foreign_t end_python(void) {
|
||||||
@ -127,3 +140,5 @@ X_API bool do_init_python(void) {
|
|||||||
// python_output();
|
// python_output();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
python_run_command/1,
|
python_run_command/1,
|
||||||
python_run_script/2,
|
python_run_script/2,
|
||||||
python_assign/3,
|
python_assign/3,
|
||||||
|
python_represents/2,
|
||||||
python_import/1,
|
python_import/1,
|
||||||
array_to_python_list/4,
|
array_to_python_list/4,
|
||||||
array_to_python_tuple/4,
|
array_to_python_tuple/4,
|
||||||
|
@ -6,7 +6,9 @@ INCLUDE(UseSWIG)
|
|||||||
include(FindPythonModule)
|
include(FindPythonModule)
|
||||||
|
|
||||||
list (APPEND pl_library ${CMAKE_CURRENT_SOURCE_DIR}/prolog/yapi.yap )
|
list (APPEND pl_library ${CMAKE_CURRENT_SOURCE_DIR}/prolog/yapi.yap )
|
||||||
set (PYTHON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/yap4py/yapi.py ${CMAKE_CURRENT_SOURCE_DIR}/yap4py/__main__.py)
|
set (PYTHON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/yap4py/yapi.py
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/yap4py/systuples.py
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/yap4py/__main__.py)
|
||||||
|
|
||||||
|
|
||||||
SET_SOURCE_FILES_PROPERTIES(../../swig/yap.i PROPERTIES CPLUSPLUS ON)
|
SET_SOURCE_FILES_PROPERTIES(../../swig/yap.i PROPERTIES CPLUSPLUS ON)
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
|
The YAP Prolog System {#main}
|
||||||
|
===========
|
||||||
|
|
||||||
<center>
|
|
||||||

|

|
||||||
</center>
|
</center>
|
||||||
|
|
||||||
NOTE: this version of YAP is still experimental, documentation may be out of date.
|
NOTE: this version of YAP is still experimental, documentation may be out of date.
|
||||||
|
|
||||||
## Introduction
|
Introduction
|
||||||
|
++++++++++
|
||||||
|
|
||||||
This document provides User information on version 6.3.4 of
|
This document provides User information on version 6.3.4 of
|
||||||
YAP (<em>Yet Another Prolog</em>). The YAP Prolog System is a
|
YAP (*Yet Another Prolog*). The YAP Prolog System is a
|
||||||
high-performance Prolog compiler developed at Universidade do
|
high-performance Prolog compiler developed at Universidade do
|
||||||
Porto. YAP supports stream Input/Output, sockets, modules,
|
Porto. YAP supports stream Input/Output, sockets, modules,
|
||||||
exceptions, Prolog debugger, C-interface, dynamic code, internal
|
exceptions, Prolog debugger, C-interface, dynamic code, internal
|
||||||
@ -16,7 +18,6 @@ Porto. YAP supports stream Input/Output, sockets, modules,
|
|||||||
|
|
||||||
We explicitly allow both commercial and non-commercial use of YAP.
|
We explicitly allow both commercial and non-commercial use of YAP.
|
||||||
|
|
||||||
|
|
||||||
YAP is based on the David H. D. Warren's WAM (Warren Abstract Machine),
|
YAP is based on the David H. D. Warren's WAM (Warren Abstract Machine),
|
||||||
with several optimizations for better performance. YAP follows the
|
with several optimizations for better performance. YAP follows the
|
||||||
Edinburgh tradition, and was originally designed to be largely
|
Edinburgh tradition, and was originally designed to be largely
|
||||||
@ -47,47 +48,33 @@ different licenses.
|
|||||||
|
|
||||||
If you have a question about this software, desire to add code, found a
|
If you have a question about this software, desire to add code, found a
|
||||||
bug, want to request a feature, or wonder how to get further assistance,
|
bug, want to request a feature, or wonder how to get further assistance,
|
||||||
please send e-mail to <yap-users AT lists.sourceforge.net>. To
|
please send e-mail to `yap-users AT lists.sourceforge.net. To
|
||||||
subscribe to the mailing list, visit the page
|
subscribe to the mailing list, visit the [YAP Mailing list page](https://lists.sourceforge.net/lists/listinfo/yap-users).
|
||||||
<https://lists.sourceforge.net/lists/listinfo/yap-users>.
|
|
||||||
|
|
||||||
On-line documentation is available for [YAP](http://www.dcc.fp.pt/~vsc/yap/)
|
On-line documentation is available for [YAP](http://www.dcc.fp.pt/~vsc/yap/)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
The packages are, in alphabetical order:
|
The packages are, in alphabetical order:
|
||||||
|
|
||||||
+ The CHR package developed by Tom Schrijvers,
|
+ The CHR package developed by Tom Schrijvers, Christian Holzbaur, and Jan Wielemaker.
|
||||||
Christian Holzbaur, and Jan Wielemaker.
|
|
||||||
|
|
||||||
+ The CLP(BN) package and Horus toolkit developed by Tiago Gomes, and Vítor Santos Costa.
|
+ The CLP(BN) package and Horus toolkit developed by Tiago Gomes, and Vítor Santos Costa.
|
||||||
|
|
||||||
+ The CLP(R) package developed by Leslie De Koninck, Bart Demoen, Tom
|
+ The CLP(R) package developed by Leslie De Koninck, Bart Demoen, Tom Schrijvers, and Jan Wielemaker, based on the CLP(Q,R) implementation by Christian Holzbaur.
|
||||||
Schrijvers, and Jan Wielemaker, based on the CLP(Q,R) implementation
|
|
||||||
by Christian Holzbaur.
|
|
||||||
|
|
||||||
+ The CPLint package developed by Fabrizio Riguzzi's research
|
+ The CPLint package developed by Fabrizio Riguzzi's research laboratory at the [University of Ferrara](http://www.ing.unife.it/Docenti/FabrizioRiguzzi/).
|
||||||
laboratory at the [University of Ferrara](http://www.ing.unife.it/Docenti/FabrizioRiguzzi/)
|
|
||||||
|
|
||||||
+ The CUDA interface package developed by Carlos Martínez, Jorge
|
+ The CUDA interface package developed by Carlos Martínez, Jorge Buenabad, Inês Dutra and Vítor Santos Costa.
|
||||||
Buenabad, Inês Dutra and Vítor Santos Costa.
|
|
||||||
|
|
||||||
+ The [GECODE](http://www.gecode.org) interface package developed by Denys Duchier and Vítor Santos Costa.
|
+ The [GECODE](http://www.gecode.org) interface package developed by Denys Duchier and Vítor Santos Costa.
|
||||||
|
|
||||||
+ The [JPL](http://www.swi-prolog.org/packages/jpl/) (Java-Prolog Library) package developed by .
|
+ The [JPL](http://www.swi-prolog.org/packages/jpl/) (Java-Prolog Library) package developed by .
|
||||||
|
|
||||||
The minisat SAT solver interface developed by Michael Codish,
|
+ The minisat SAT solver interface developed by Michael Codish, Vitaly Lagoon, and Peter J. Stuckey.
|
||||||
Vitaly Lagoon, and Peter J. Stuckey.
|
|
||||||
|
|
||||||
+ The MYDDAS relational data-base interface developed at the
|
+ The MYDDAS relational data-base interface developed at the Universidade do Porto by Tiago Soares, Michel Ferreira, and Ricardo Rocha.
|
||||||
Universidade do Porto by Tiago Soares, Michel Ferreira, and Ricardo Rocha.
|
|
||||||
|
|
||||||
+ The [PRISM](http://rjida.meijo-u.ac.jp/prism/) logic-based
|
+ The [PRISM](http://rjida.meijo-u.ac.jp/prism/) logic-based programming system for statistical modeling developed at the Sato Research Laboratory, TITECH, Japan.
|
||||||
programming system for statistical modeling developed at the Sato
|
|
||||||
Research Laboratory, TITECH, Japan.
|
|
||||||
|
|
||||||
+ The ProbLog 1 system developed by the [ProbLog](https://dtai.cs.kuleuven.be/problog) team in the
|
+ The ProbLog 1 system developed by the [ProbLog](https://dtai.cs.kuleuven.be/problog) team in the DTAI group of KULeuven.
|
||||||
DTAI group of KULeuven.
|
|
||||||
|
|
||||||
+ The [R](http://stoics.org.uk/~nicos/sware/packs/real/) interface package developed by Nicos Angelopoulos,
|
+ The [R](http://stoics.org.uk/~nicos/sware/packs/real/) interface package developed by Nicos Angelopoulos, Vítor Santos Costa, João Azevedo, Jan Wielemaker, and Rui Camacho.
|
||||||
Vítor Santos Costa, João Azevedo, Jan Wielemaker, and Rui Camacho.
|
|
||||||
|
@ -25,18 +25,19 @@
|
|||||||
|
|
||||||
|
|
||||||
:- python_import(yap4py.yapi).
|
:- python_import(yap4py.yapi).
|
||||||
|
:- python_import(json).
|
||||||
%:- python_import(gc).
|
%:- python_import(gc).
|
||||||
|
|
||||||
:- meta_predicate( yapi_query(:,+) ).
|
:- meta_predicate( yapi_query(:,+) ).
|
||||||
|
|
||||||
%:- start_low_level_trace.
|
%:- start_low_level_trace.
|
||||||
|
|
||||||
%% @pred yapi_query( + VarList, - Dictionary)
|
%% @pred yapi_query( + VarList, - Dictionary)
|
||||||
%%
|
%%
|
||||||
%% dictionary, Examples
|
%% dictionary, Examples
|
||||||
%%
|
%%
|
||||||
%%
|
%%
|
||||||
yapi_query( VarNames, Self ) :-
|
yapi_query( VarNames, Self ) :-
|
||||||
show_answer(VarNames, Dict),
|
show_answer(VarNames, Dict),
|
||||||
Self.bindings := Dict.
|
Self.bindings := Dict.
|
||||||
|
|
||||||
@ -47,6 +48,9 @@ set_preds :-
|
|||||||
fail,
|
fail,
|
||||||
current_predicate(P, Q),
|
current_predicate(P, Q),
|
||||||
functor(Q,P,A),
|
functor(Q,P,A),
|
||||||
|
|
||||||
|
current_predicate(P, Q),
|
||||||
|
functor(Q,P,A),
|
||||||
atom_string(P,S),
|
atom_string(P,S),
|
||||||
catch(
|
catch(
|
||||||
:= yap4py.yapi.named( S, A),
|
:= yap4py.yapi.named( S, A),
|
||||||
@ -70,21 +74,46 @@ argi(N,I,I1) :-
|
|||||||
|
|
||||||
python_query( Caller, String ) :-
|
python_query( Caller, String ) :-
|
||||||
atomic_to_term( String, Goal, VarNames ),
|
atomic_to_term( String, Goal, VarNames ),
|
||||||
query_to_answer( Goal, VarNames, Status, Bindings),
|
query_to_answer( Goal, _, Status, VarNames, Bindings),
|
||||||
Caller.port := Status,
|
Caller.port := Status,
|
||||||
write_query_answer( Bindings ),
|
output(Caller, Bindings).
|
||||||
nl(user_error),
|
|
||||||
Caller.answer := {},
|
output( _, Bindings ) :-
|
||||||
maplist(in_dict(Caller.answer), Bindings).
|
write_query_answer( Bindings ),
|
||||||
|
fail.
|
||||||
|
output( Caller, Bindings ) :-
|
||||||
|
answer := {},
|
||||||
|
foldl(ground_dict(answer), Bindings, [], Ts),
|
||||||
|
term_variables( Ts, Hidden),
|
||||||
|
foldl(bv, Hidden , 0, _),
|
||||||
|
maplist(into_dict(answer),Ts),
|
||||||
|
Caller.answer := json.dumps(answer),
|
||||||
|
S := Caller.answer,
|
||||||
|
format(user_error, '~nor ~s~n~n',S),
|
||||||
|
fail.
|
||||||
|
output(_Caller, _Bindings).
|
||||||
|
|
||||||
|
bv(V,I,I1) :-
|
||||||
|
atomic_concat(['__',I],V),
|
||||||
|
I1 is I+1.
|
||||||
|
|
||||||
|
into_dict(D,V0=T) :-
|
||||||
|
python_represents(D[V0], T).
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
ground_dict(_Dict,var([_V]), I, I) :-
|
||||||
|
!.
|
||||||
|
ground_dict(_Dict,var([V,V]), I, I) :-
|
||||||
|
!.
|
||||||
|
ground_dict(Dict, nonvar([V0|Vs],T),I0, [V0=T| I0]) :-
|
||||||
|
!,
|
||||||
|
ground_dict(Dict, var([V0|Vs]),I0, I0).
|
||||||
|
ground_dict(Dict, var([V0,V1|Vs]), I, I) :-
|
||||||
|
!,
|
||||||
|
Dict[V1] := V0,
|
||||||
|
ground_dict(Dict, var([V0|Vs]), I, I).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
in_dict(Dict, var([V0,V|Vs])) :- !,
|
|
||||||
Dict[V] := V0,
|
|
||||||
in_dict( Dict, var([V0|Vs])).
|
|
||||||
in_dict(_Dict, var([_],_G)) :- !.
|
|
||||||
in_dict(Dict, nonvar([V0|Vs],G)) :- !,
|
|
||||||
term_to_atom(G,A,_),
|
|
||||||
Dict[V0] := A,
|
|
||||||
in_dict( Dict, nonvar(Vs, G) ).
|
|
||||||
in_dict(_Dict, nonvar([],_G)) :- !.
|
|
||||||
in_dict(_, _)
|
|
||||||
|
41
packages/python/swig/yap4py/systuples.py
Normal file
41
packages/python/swig/yap4py/systuples.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
asserta = namedtuple('asserta', 'clause')
|
||||||
|
assertz = namedtuple('assertz', 'clause')
|
||||||
|
bindvars = namedtuple('bindvars', 'list')
|
||||||
|
compile = namedtuple('compile', 'file')
|
||||||
|
compdletionsile = namedtuple('completions', 'text self')
|
||||||
|
dbms = namedtuple('dbms', 'filedbms')
|
||||||
|
errors = namedtuple('errors', 'fileng engee')
|
||||||
|
foreign = namedtuple('foreign', 'filedbms')
|
||||||
|
jupyter_query = namedtuple('jupyter_query', 'engine program query')
|
||||||
|
library = namedtuple('library', 'listfiles')
|
||||||
|
load_files = namedtuple('load_file', 'file opts')
|
||||||
|
ostreams = namedtuple('ostreams', ' text')
|
||||||
|
prolog_library=namedtuple('prolog_library', 'listfiles')
|
||||||
|
python_query = namedtuple('python_query', 'engine query')
|
||||||
|
set_prolog_flag = namedtuple('set_prolog_flag', 'flag new_value')
|
||||||
|
show_answer = namedtuple('show_answer', 'vars dict')
|
||||||
|
streams = namedtuple('streams', 'text')
|
||||||
|
v = namedtuple('_', 'slot')
|
||||||
|
v0 = namedtuple('v', 'slot')
|
||||||
|
yap_query = namedtuple('yap_query', 'query owner')
|
||||||
|
yapi_query = namedtuple('yapi_query', 'vars dict')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,22 +1,12 @@
|
|||||||
import readline
|
import readline
|
||||||
from yap4py.yap import *
|
from yap4py.yap import *
|
||||||
|
from yap4py.systuples import *
|
||||||
from os.path import join, dirname
|
from os.path import join, dirname
|
||||||
from collections import namedtuple
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
yap_lib_path = dirname(__file__)
|
yap_lib_path = dirname(__file__)
|
||||||
|
|
||||||
bindvars = namedtuple('bindvars', 'list')
|
|
||||||
compile = namedtuple('compile', 'file')
|
|
||||||
jupyter_query = namedtuple('jupyter_query', 'vars dict')
|
|
||||||
library = namedtuple('library', 'listfiles')
|
|
||||||
prolog_library = namedtuple('prolog_library', 'listfiles')
|
|
||||||
python_query = namedtuple('python_query', 'vars dict')
|
|
||||||
set_prolog_flag = namedtuple('set_prolog_flag', 'flag new_value')
|
|
||||||
show_answer = namedtuple('show_answer', 'vars dict')
|
|
||||||
v0 = namedtuple('v', 'slot')
|
|
||||||
yap_query = namedtuple('yap_query', 'query owner')
|
|
||||||
yapi_query = namedtuple('yapi_query', 'vars dict')
|
|
||||||
|
|
||||||
|
|
||||||
class Engine( YAPEngine ):
|
class Engine( YAPEngine ):
|
||||||
@ -78,16 +68,20 @@ class Query (YAPQuery):
|
|||||||
super().__init__(g)
|
super().__init__(g)
|
||||||
self.engine = engine
|
self.engine = engine
|
||||||
self.port = "call"
|
self.port = "call"
|
||||||
self.bindings = None
|
|
||||||
self.answer = {}
|
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def done(self):
|
||||||
|
return self.port == "fail" or self.port == "exit"
|
||||||
|
|
||||||
def __next__(self):
|
def __next__(self):
|
||||||
if self.port == "fail":
|
self.answer = {}
|
||||||
raise IndexError()
|
if self.port == "fail" or self.port == "exit":
|
||||||
return self.next()
|
raise StopIteration()
|
||||||
|
if self.next():
|
||||||
|
return self.answer
|
||||||
|
raise StopIteration()
|
||||||
|
|
||||||
def name( name, arity):
|
def name( name, arity):
|
||||||
try:
|
try:
|
||||||
@ -136,12 +130,12 @@ class YAPShell:
|
|||||||
# construct a query from a one-line string
|
# construct a query from a one-line string
|
||||||
# q is opaque to Python
|
# q is opaque to Python
|
||||||
#
|
#
|
||||||
#q = engine.query(python_query(self, s))
|
# q = engine.query(python_query(self, s))
|
||||||
#
|
#
|
||||||
# # vs is the list of variables
|
# # vs is the list of variables
|
||||||
# you can print it out, the left-side is the variable name,
|
# you can print it out, the left-side is the variable name,
|
||||||
# the right side wraps a handle to a variable
|
# the right side wraps a handle to a variable
|
||||||
import pdb; pdb.set_trace()
|
# import pdb; pdb.set_trace()
|
||||||
# #pdb.set_trace()
|
# #pdb.set_trace()
|
||||||
# atom match either symbols, or if no symbol exists, sttrings, In this case
|
# atom match either symbols, or if no symbol exists, sttrings, In this case
|
||||||
# variable names should match strings
|
# variable names should match strings
|
||||||
@ -153,12 +147,11 @@ class YAPShell:
|
|||||||
engine = self.engine
|
engine = self.engine
|
||||||
bindings = []
|
bindings = []
|
||||||
loop = False
|
loop = False
|
||||||
g = python_query(self, query)
|
q = Query( engine, python_query( engine, query) )
|
||||||
self.q = Query( engine, g )
|
for answer in q:
|
||||||
while self.q.next():
|
bindings += [answer]
|
||||||
bindings += [self.q.answer]
|
if q.done():
|
||||||
if self.q.port == "exit":
|
return bindings
|
||||||
break
|
|
||||||
if loop:
|
if loop:
|
||||||
continue
|
continue
|
||||||
s = input("more(;), all(*), no(\\n), python(#)? ").lstrip()
|
s = input("more(;), all(*), no(\\n), python(#)? ").lstrip()
|
||||||
@ -177,10 +170,8 @@ class YAPShell:
|
|||||||
if self.q:
|
if self.q:
|
||||||
self.q.close()
|
self.q.close()
|
||||||
self.q = None
|
self.q = None
|
||||||
if bindings:
|
|
||||||
return True,bindings
|
|
||||||
print("No (more) answers")
|
print("No (more) answers")
|
||||||
return False, None
|
return bindings
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if not self.q:
|
if not self.q:
|
||||||
return False, None
|
return False, None
|
||||||
|
@ -2040,7 +2040,7 @@ class InteractiveShell(SingletonConfigurable):
|
|||||||
list where you want the completer to be inserted."""
|
list where you want the completer to be inserted."""
|
||||||
|
|
||||||
newcomp = types.MethodType(completer,self.Completer)
|
newcomp = types.MethodType(completer,self.Completer)
|
||||||
self.Completer.matchers.insert(pos,newcomp)
|
self.Completer.matches.insert(pos,newcomp)
|
||||||
|
|
||||||
def set_completer_frame(self, frame=None):
|
def set_completer_frame(self, frame=None):
|
||||||
"""Set the frame of the completer."""
|
"""Set the frame of the completer."""
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
:- yap_flag(gc_trace,verbose).
|
:- yap_flag(gc_trace,verbose).
|
||||||
/*
|
/*
|
||||||
:- module( jupyter,
|
:- module( jupyter,
|
||||||
[jupyter_query/3,
|
[jupyter_queryl/3,
|
||||||
blank/1,
|
blank/1,
|
||||||
streams/2
|
streams/2
|
||||||
]
|
]
|
||||||
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
:- python_import(sys).
|
:- python_import(sys).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
jupyter_query(Caller, Cell, Line ) :-
|
jupyter_query(Caller, Cell, Line ) :-
|
||||||
jupyter_cell(Caller, Cell, Line).
|
jupyter_cell(Caller, Cell, Line).
|
||||||
|
|
||||||
@ -38,7 +40,7 @@ jupyter_cell( _Caller, _, Line ) :-
|
|||||||
blank( Line ),
|
blank( Line ),
|
||||||
!.
|
!.
|
||||||
jupyter_cell(Caller, _, Line ) :-
|
jupyter_cell(Caller, _, Line ) :-
|
||||||
Query = Caller,
|
Query = Caller,
|
||||||
catch(
|
catch(
|
||||||
python_query(Query,Line),
|
python_query(Query,Line),
|
||||||
error(A,B),
|
error(A,B),
|
||||||
@ -67,7 +69,7 @@ jupyter_consult(Cell) :-
|
|||||||
(
|
(
|
||||||
Options = [],
|
Options = [],
|
||||||
open_mem_read_stream( Cell, Stream),
|
open_mem_read_stream( Cell, Stream),
|
||||||
load_files(user:'jupyter cell',[stream(Stream)| Options])
|
load_files(Stream,[stream(Stream)| Options])
|
||||||
),
|
),
|
||||||
error(A,B),
|
error(A,B),
|
||||||
(close(Stream), system_error(A,B))
|
(close(Stream), system_error(A,B))
|
||||||
|
@ -5,6 +5,7 @@ from typing import List
|
|||||||
from traitlets import Bool
|
from traitlets import Bool
|
||||||
|
|
||||||
|
|
||||||
|
from yap4py.systuples import *
|
||||||
from yap4py.yapi import *
|
from yap4py.yapi import *
|
||||||
from IPython.core.completer import Completer
|
from IPython.core.completer import Completer
|
||||||
# import IPython.core
|
# import IPython.core
|
||||||
@ -18,23 +19,8 @@ from ipython_genutils.py3compat import builtin_mod
|
|||||||
|
|
||||||
from yap_kernel.displayhook import ZMQShellDisplayHook
|
from yap_kernel.displayhook import ZMQShellDisplayHook
|
||||||
|
|
||||||
from collections import namedtuple
|
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
use_module = namedtuple('use_module', 'file')
|
|
||||||
bindvars = namedtuple('bindvars', 'list')
|
|
||||||
library = namedtuple('library', 'list')
|
|
||||||
v = namedtuple('_', 'slot')
|
|
||||||
load_files = namedtuple('load_files', 'file ofile args')
|
|
||||||
python_query = namedtuple('python_query', 'query_mgr string')
|
|
||||||
jupyter_query = namedtuple('jupyter_query', 'self text query')
|
|
||||||
enter_cell = namedtuple('enter_cell', 'self' )
|
|
||||||
exit_cell = namedtuple('exit_cell', 'self' )
|
|
||||||
completions = namedtuple('completions', 'txt self' )
|
|
||||||
errors = namedtuple('errors', 'self text' )
|
|
||||||
streams = namedtuple('streams', 'text' )
|
|
||||||
nostreams = namedtuple('nostreams', ' text' )
|
|
||||||
|
|
||||||
global engine
|
global engine
|
||||||
|
|
||||||
def tracefunc(frame, event, arg, indent=[0]):
|
def tracefunc(frame, event, arg, indent=[0]):
|
||||||
@ -70,7 +56,7 @@ class YAPInputSplitter(InputSplitter):
|
|||||||
logical_line_transforms=None):
|
logical_line_transforms=None):
|
||||||
self._buffer_raw = []
|
self._buffer_raw = []
|
||||||
self._validate = True
|
self._validate = True
|
||||||
self.yapeng = engine
|
self.engine = engine
|
||||||
self.shell = shell
|
self.shell = shell
|
||||||
|
|
||||||
if physical_line_transforms is not None:
|
if physical_line_transforms is not None:
|
||||||
@ -503,7 +489,7 @@ class YAPCompleter(Completer):
|
|||||||
magic_res = self.magic_matches(text)
|
magic_res = self.magic_matches(text)
|
||||||
return text, magic_res
|
return text, magic_res
|
||||||
self.matches = []
|
self.matches = []
|
||||||
prolog_res = self.shell.yapeng.mgoal(completions(text, self), "user",True)
|
prolog_res = self.shell.engine.mgoal(completions(text, self), "user",True)
|
||||||
return text, self.matches
|
return text, self.matches
|
||||||
|
|
||||||
|
|
||||||
@ -515,18 +501,19 @@ class YAPRun(InteractiveShell):
|
|||||||
|
|
||||||
def __init__(self, shell):
|
def __init__(self, shell):
|
||||||
self.shell = shell
|
self.shell = shell
|
||||||
self.yapeng = JupyterEngine()
|
self.engine = JupyterEngine()
|
||||||
global engine
|
global engine
|
||||||
engine = self.yapeng
|
engine = self.engine
|
||||||
self.errors = []
|
self.errors = []
|
||||||
self.query = None
|
self.query = None
|
||||||
self.os = None
|
self.os = None
|
||||||
self.it = None
|
self.it = None
|
||||||
self.port = None
|
self.port = "None"
|
||||||
self.answers = None
|
self.answers = None
|
||||||
self.bindings = dicts = []
|
self.bindings = dicts = []
|
||||||
self.shell.yapeng = self.yapeng
|
self.shell.engine = self.engine
|
||||||
self._get_exc_info = shell._get_exc_info
|
self._get_exc_info = shell._get_exc_info
|
||||||
|
self.iterations = 0
|
||||||
|
|
||||||
|
|
||||||
def showtraceback(self, exc_info):
|
def showtraceback(self, exc_info):
|
||||||
@ -547,62 +534,46 @@ class YAPRun(InteractiveShell):
|
|||||||
return self.errors
|
return self.errors
|
||||||
self.errors=[]
|
self.errors=[]
|
||||||
(text,_,_,_) = self.clean_end(text)
|
(text,_,_,_) = self.clean_end(text)
|
||||||
self.yapeng.mgoal(errors(self,text),"user",True)
|
self.engine.mgoal(errors(self,text),"user",True)
|
||||||
return self.errors
|
return self.errors
|
||||||
|
|
||||||
def jupyter_query(self, s):
|
def prolog(self, s, result):
|
||||||
#
|
#
|
||||||
# construct a self.queryuery from a one-line string
|
# construct a self.queryuery from a one-line string
|
||||||
# self.query is opaque to Python
|
# self.query is opaque to Python
|
||||||
try:
|
try:
|
||||||
program,squery,stop,howmany = self.prolog_cell(s)
|
program,squery,_ ,howmany = self.prolog_cell(s)
|
||||||
found = False
|
|
||||||
# sys.settrace(tracefunc)
|
# sys.settrace(tracefunc)
|
||||||
if self.query and self.os == program+squery:
|
if self.query and self.os == (program,squery):
|
||||||
howmany += self.iterations
|
howmany += self.iterations
|
||||||
found = howmany != 0
|
|
||||||
else:
|
else:
|
||||||
if self.query:
|
if self.query:
|
||||||
self.query.close()
|
self.query.close()
|
||||||
self.query = None
|
self.query = None
|
||||||
self.port = None
|
self.answers = []
|
||||||
self.answers = None
|
self.os = (program,squery)
|
||||||
self.os = program+squery
|
|
||||||
self.iterations = 0
|
self.iterations = 0
|
||||||
pg = jupyter_query( self, program, squery)
|
pg = jupyter_query(self.engine,program,squery)
|
||||||
self.query = self.yapeng.query(pg)
|
self.query = Query(self.engine, pg)
|
||||||
self.answers = []
|
self.answers = []
|
||||||
self.port = "call"
|
for answer in self.query:
|
||||||
self.answer = {}
|
self.answers += [answer]
|
||||||
while self.query.next():
|
|
||||||
#sys.stderr.write('B '+str( self.answer) +'\n')
|
|
||||||
#sys.stderr.write('C '+ str(self.port) +'\n'+'\n')
|
|
||||||
found = True
|
|
||||||
self.answers += [self.answer]
|
|
||||||
self.iterations += 1
|
self.iterations += 1
|
||||||
if self.port == "exit":
|
|
||||||
self.os = None
|
self.os = None
|
||||||
#sys.stderr.write('Done, with'+str(self.answers)+'\n')
|
self.query.close()
|
||||||
result.result = True,self.bindings
|
self.query = None
|
||||||
return result
|
if self.answers:
|
||||||
if stop or howmany == self.iterations:
|
sys.stderr.write('Completed, with '+str(self.answers)+'\n')
|
||||||
result.result = True, self.answers
|
result.result = self.answers
|
||||||
return result
|
return result.result
|
||||||
if found:
|
|
||||||
sys.stderr.write('Done, with '+str(self.answers)+'\n')
|
|
||||||
else:
|
|
||||||
self.os = None
|
|
||||||
self.query.close()
|
|
||||||
self.query = None
|
|
||||||
sys.stderr.write('Fail\n')
|
|
||||||
result.result = True,self.bindings
|
|
||||||
return result
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.stderr.write('Exception '+str(e)+'in query '+ str(self.query)+
|
sys.stderr.write('Exception '+str(e)+'in query '+ str(self.query)+
|
||||||
':'+pg+'\n '+str( self.bindings)+ '\n')
|
'\n '+str( self.bindings)+ '\n')
|
||||||
has_raised = True
|
has_raised = True
|
||||||
result.result = False
|
result.result = []
|
||||||
return result
|
return result.result
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -698,13 +669,11 @@ class YAPRun(InteractiveShell):
|
|||||||
except:
|
except:
|
||||||
line = ""
|
line = ""
|
||||||
self.shell.last_execution_succeeded = True
|
self.shell.last_execution_succeeded = True
|
||||||
self.shell.run_cell_magic(magic, line, body)
|
result.result = self.shell.run_cell_magic(magic, line, body)
|
||||||
result.result = True
|
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
linec = True
|
linec = True
|
||||||
rcell = cell[1:].strip()
|
rcell = cell[1:].strip()
|
||||||
print(cell)
|
|
||||||
try:
|
try:
|
||||||
[magic,cell] = rcell.split(maxsplit = 1, sep = '\n')
|
[magic,cell] = rcell.split(maxsplit = 1, sep = '\n')
|
||||||
except:
|
except:
|
||||||
@ -721,13 +690,13 @@ class YAPRun(InteractiveShell):
|
|||||||
# can fill in the output value.
|
# can fill in the output value.
|
||||||
self.shell.displayhook.exec_result = result
|
self.shell.displayhook.exec_result = result
|
||||||
if self.syntaxErrors(cell):
|
if self.syntaxErrors(cell):
|
||||||
result.result = False
|
result.result = []
|
||||||
return
|
return
|
||||||
has_raised = False
|
has_raised = False
|
||||||
try:
|
try:
|
||||||
builtin_mod.input = input
|
builtin_mod.input = input
|
||||||
self.shell.input = input
|
self.shell.input = input
|
||||||
self.yapeng.mgoal(streams(True),"user", True)
|
self.engine.mgoal(streams(True),"user", True)
|
||||||
if cell.strip('\n \t'):
|
if cell.strip('\n \t'):
|
||||||
#create a Trace object, telling it what to ignore, and whether to
|
#create a Trace object, telling it what to ignore, and whether to
|
||||||
# do tracing or line-counting or both.
|
# do tracing or line-counting or both.
|
||||||
@ -740,16 +709,17 @@ class YAPRun(InteractiveShell):
|
|||||||
# def f(self, cell, state):
|
# def f(self, cell, state):
|
||||||
# state = self.jupyter_query( cell )
|
# state = self.jupyter_query( cell )
|
||||||
|
|
||||||
# run the new command using the given tracer
|
# run the new command using the given tracer
|
||||||
#
|
#
|
||||||
# tracer.runfunc(f,self,cell,state)
|
# tracer.runfunc(f,self,cell,state)
|
||||||
self.jupyter_query( cell )
|
answers = self.prolog( cell, result )
|
||||||
# state = tracer.runfunc(jupyter_query( self, cell ) )
|
# state = tracer.runfunc(hist
|
||||||
self.shell.last_execution_succeeded = True
|
# er_query( self, cell ) )
|
||||||
result.result = True
|
self.shell.last_execution_succeeded = True
|
||||||
|
result.result = answers
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
has_raised = True
|
has_raised = True
|
||||||
result.result = False
|
result.result = []
|
||||||
try:
|
try:
|
||||||
(etype, value, tb) = e
|
(etype, value, tb) = e
|
||||||
traceback.print_exception(etype, value, tb)
|
traceback.print_exception(etype, value, tb)
|
||||||
@ -773,8 +743,8 @@ class YAPRun(InteractiveShell):
|
|||||||
# Each cell is a *single* input, regardless of how many lines it has
|
# Each cell is a *single* input, regardless of how many lines it has
|
||||||
self.shell.execution_count += 1
|
self.shell.execution_count += 1
|
||||||
|
|
||||||
self.yapeng.mgoal(streams(False),"user", True)
|
self.engine.mgoal(streams(False),"user", True)
|
||||||
return result
|
return
|
||||||
|
|
||||||
def clean_end(self,s):
|
def clean_end(self,s):
|
||||||
"""
|
"""
|
||||||
@ -809,7 +779,7 @@ class YAPRun(InteractiveShell):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def prolog_cell(self,s):
|
def prolog_cell(self,s):
|
||||||
"""
|
"""
|
||||||
Trasform a text into program+query. A query is the
|
Trasform a text into program+query. A query is the
|
||||||
last line if the last line is non-empty and does not terminate
|
last line if the last line is non-empty and does not terminate
|
||||||
@ -821,12 +791,15 @@ class YAPRun(InteractiveShell):
|
|||||||
If the line terminates on a `*/` or starts on a `%` we assume the line
|
If the line terminates on a `*/` or starts on a `%` we assume the line
|
||||||
is a comment.
|
is a comment.
|
||||||
"""
|
"""
|
||||||
s0 = s.rstrip(' \n\t\i')
|
try:
|
||||||
[program,x,query] = s0.rpartition('\n')
|
s0 = s.rstrip(' \n\t\i')
|
||||||
if query[-1] == '.':
|
[program,x,query] = s0.rpartition('\n')
|
||||||
return s,'',False,0
|
if query[-1] == '.':
|
||||||
(query, _,loop, sols) = self.clean_end(query)
|
return s,'',False,0
|
||||||
return (program, query, loop, sols)
|
(query, _,loop, sols) = self.clean_end(query)
|
||||||
|
return (program, query, loop, sols)
|
||||||
|
except:
|
||||||
|
return (s,'',true,1)
|
||||||
|
|
||||||
# global
|
# global
|
||||||
#globals = {}
|
#globals = {}
|
||||||
|
@ -165,7 +165,7 @@ prolog:copy_term(Term, Copy, Gs) :-
|
|||||||
-> Gs = [],
|
-> Gs = [],
|
||||||
copy_term(Term, Copy)
|
copy_term(Term, Copy)
|
||||||
; findall(Term-Gs,
|
; findall(Term-Gs,
|
||||||
'$attributes':residuals_and_delete_attributes(Vs, Gs, Term),
|
attributes:residuals_and_delete_attributes(Vs, Gs, Term),
|
||||||
[Copy-Gs])
|
[Copy-Gs])
|
||||||
).
|
).
|
||||||
|
|
||||||
|
@ -476,9 +476,7 @@ If this hook preodicate succeeds it must instantiate the _Action_ argument to t
|
|||||||
|
|
||||||
:- ensure_loaded('../pl/pathconf.yap').
|
:- ensure_loaded('../pl/pathconf.yap').
|
||||||
|
|
||||||
:- current_prolog_fkag(android,true), ensure_loaded('../pl/android.yap').
|
:- current_prolog_flag(android,true), ensure_loaded('../android.yap').
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
:- set_prolog_flag(unknown,error).
|
:- set_prolog_flag(unknown,error).
|
||||||
|
|
||||||
|
@ -389,16 +389,18 @@ version(T) :-
|
|||||||
fail.
|
fail.
|
||||||
'$set_toplevel_hook'(_).
|
'$set_toplevel_hook'(_).
|
||||||
|
|
||||||
query_to_answer(G, V, Status, Bindings) :-
|
query_to_answer(G, V, Status, Vs, Bindings ) :-
|
||||||
gated_call( true, (G,'$delayed_goals'(G, V, Vs, LGs, _DCP)), Status, '$answer'( Status, LGs, Vs, Bindings) ).
|
gated_call( true, (G,'$delayed_goals'(G, V, Vs, LGs, _DCP)), Status, '$answer'( Status, LGs, Vs, Bindings ) ).
|
||||||
|
|
||||||
'$answer'( exit, LGs, Vs, Bindings) :-
|
'$answer'( exit, LGs, Vs, Bindings ) :-
|
||||||
!,
|
!,
|
||||||
'$process_answer'(Vs, LGs, Bindings).
|
'$sort'(Vs, NVs),
|
||||||
'$answer'( answer, LGs, Vs, Bindings) :-
|
'$prep_answer_var_by_var'(NVs, Bindings , LGs).
|
||||||
!,
|
'$answer'( answer, LGs, Vs, Bindings) :-
|
||||||
'$process_answer'(Vs, LGs, Bindings).
|
!,
|
||||||
'$answer'(!, _, _, _).
|
'$sort'(Vs, NVs),
|
||||||
|
'$prep_answer_var_by_var'(NVs, Bindings , LGs).
|
||||||
|
'$answer'(!, _, _,_).
|
||||||
'$answer'(fail,_,_,_).
|
'$answer'(fail,_,_,_).
|
||||||
'$answer'(exception(E),_,_,_) :-
|
'$answer'(exception(E),_,_,_) :-
|
||||||
'$LoopError'(E,error).
|
'$LoopError'(E,error).
|
||||||
|
17
pl/top.yap
17
pl/top.yap
@ -330,10 +330,10 @@ live :-
|
|||||||
|
|
||||||
|
|
||||||
'$process_answer'(Vs, LGs, Bindings) :-
|
'$process_answer'(Vs, LGs, Bindings) :-
|
||||||
'$purge_dontcares'(Vs,IVs),
|
'$purge_dontcares'(Vs,IVs),
|
||||||
'$sort'(IVs, NVs),
|
'$sort'(IVs, NVs),
|
||||||
'$prep_answer_var_by_var'(NVs, LAnsw, LGs),
|
'$prep_answer_var_by_var'(NVs, LAnsw, LGs),
|
||||||
'$name_vars_in_goals'(LAnsw, Vs, Bindings).
|
'$name_vars_in_goals'(LAnsw, Vs, Bindings).
|
||||||
|
|
||||||
%
|
%
|
||||||
% *-> at this point would require compiler support, which does not exist.
|
% *-> at this point would require compiler support, which does not exist.
|
||||||
@ -494,8 +494,6 @@ write_query_answer( Bindings ) :-
|
|||||||
'$write_goal_output'(G1, First, NG, Next, IG),
|
'$write_goal_output'(G1, First, NG, Next, IG),
|
||||||
'$write_vars_and_goals'(LG, Next, IG).
|
'$write_vars_and_goals'(LG, Next, IG).
|
||||||
|
|
||||||
'$goal_to_string'(Format, G, String) :-
|
|
||||||
format(codes(String),Format,G).
|
|
||||||
|
|
||||||
'$write_goal_output'(var([V|VL]), First, [var([V|VL])|L], next, L) :- !,
|
'$write_goal_output'(var([V|VL]), First, [var([V|VL])|L], next, L) :- !,
|
||||||
( First = first -> true ; format(user_error,',~n',[]) ),
|
( First = first -> true ; format(user_error,',~n',[]) ),
|
||||||
@ -516,14 +514,13 @@ write_query_answer( Bindings ) :-
|
|||||||
G = [_|_], !,
|
G = [_|_], !,
|
||||||
% dump on string first so that we can check whether we actually
|
% dump on string first so that we can check whether we actually
|
||||||
% had any output from the solver.
|
% had any output from the solver.
|
||||||
'$goal_to_string'(Format, G, String),
|
format(string(String),Format,G),
|
||||||
( String == [] ->
|
( String == `` ->
|
||||||
% we didn't
|
% we didn't
|
||||||
IG = NG, First = Next
|
IG = NG, First = Next
|
||||||
;
|
;
|
||||||
% we did
|
% we did
|
||||||
( First = first -> true ; format(user_error,',~n',[]) ),
|
format(user_error, '~N~s', [String]),
|
||||||
format(user_error, '~s', [String]),
|
|
||||||
NG = [G|IG]
|
NG = [G|IG]
|
||||||
).
|
).
|
||||||
'$write_goal_output'(_-G, First, [G|NG], next, NG) :- !,
|
'$write_goal_output'(_-G, First, [G|NG], next, NG) :- !,
|
||||||
|
@ -102,29 +102,40 @@ undefined_query(G0, M0, Cut) :-
|
|||||||
'$undefp_search'(M0:G0, MG) :-
|
'$undefp_search'(M0:G0, MG) :-
|
||||||
'$pred_exists'(unknown_predicate_handler(_,_,_,_), user),
|
'$pred_exists'(unknown_predicate_handler(_,_,_,_), user),
|
||||||
'$yap_strip_module'(M0:G0, EM0, GM0),
|
'$yap_strip_module'(M0:G0, EM0, GM0),
|
||||||
user:unknown_predicate_handler(GM0,EM0,M1:G1),
|
user:unknown_predicate_handler(GM0,EM0,MG),
|
||||||
!,
|
!.
|
||||||
expand_goal(M1:G1, MG).
|
'$undefp_search'(M0:G0, M:G) :-
|
||||||
'$undefp_search'(MG, FMG) :-
|
'$get_undefined_predicates'(G, M0, G0, M), !.
|
||||||
expand_goal(MG, FMG).
|
|
||||||
|
|
||||||
|
|
||||||
:- abolish('$undefp'/2).
|
:- abolish('$undefp'/2).
|
||||||
|
|
||||||
|
|
||||||
% undef handler
|
% undef handler
|
||||||
'$undefp'([M0|G0], Action) :-
|
'$undefp'([M0|G0],_) :-
|
||||||
% make sure we do not loop on undefined predicates
|
% make sure we do not loop on undefined predicates
|
||||||
yap_flag( unknown, Action, fail),
|
setup_call_catcher_cleanup(
|
||||||
'$stop_creeping'(Current),
|
'$undef_set'(Action,Debug,Current),
|
||||||
% yap_flag( debug, Debug, false),
|
'$search_def'(M0,G0,MG),
|
||||||
(
|
Port,
|
||||||
'$undefp_search'(M0:G0, NM:NG),
|
'$undef_reset'(Port,M0:G0,MG,Action,Debug,Current)
|
||||||
( M0 \== NM -> true ; G0 \== NG ),
|
).
|
||||||
NG \= fail
|
|
||||||
->
|
'$undef_set'(Action,Debug,Current) :-
|
||||||
yap_flag( unknown, _, Action),
|
yap_flag( unknown, Action, fail),
|
||||||
% yap_flag( debug, _, Debug),
|
yap_flag( debug, Debug, false),
|
||||||
|
'$stop_creeping'(Current).
|
||||||
|
|
||||||
|
'$search_def'(M0,G0,NG:NM) :-
|
||||||
|
'$undefp_search'(M0:G0, NM:NG),
|
||||||
|
!,
|
||||||
|
'$pred_exists'(NG,NM).
|
||||||
|
|
||||||
|
'$undef_reset'(exit,_G0,NG:NM,Action,Debug,Current) :-
|
||||||
|
yap_flag( unknown, _, Action),
|
||||||
|
yap_flag( debug, _, Debug),
|
||||||
|
nonvar(NG),
|
||||||
|
nonvar(NM),
|
||||||
(
|
(
|
||||||
Current == true
|
Current == true
|
||||||
->
|
->
|
||||||
@ -132,11 +143,12 @@ undefined_query(G0, M0, Cut) :-
|
|||||||
'$start_creep'([NM|NG], creep)
|
'$start_creep'([NM|NG], creep)
|
||||||
;
|
;
|
||||||
'$execute0'(NG, NM)
|
'$execute0'(NG, NM)
|
||||||
)
|
).
|
||||||
;
|
'$undef_reset'(_,M0:G0,_NG,Action,Debug,_Current) :-
|
||||||
yap_flag( unknown, _, Action),
|
yap_flag( unknown, _, Action),
|
||||||
'$handle_error'(Action,G0,M0)
|
yap_flag( debug, _, Debug),
|
||||||
).
|
'$start_creep'([prolog|true], creep),
|
||||||
|
'$handle_error'(Action,G0,M0).
|
||||||
|
|
||||||
:- '$undefp_handler'('$undefp'(_,_), prolog).
|
:- '$undefp_handler'('$undefp'(_,_), prolog).
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @file yapor.yap
|
* @file yapor.yap
|
||||||
* @author VITOR SANTOS COSTA <vsc@VITORs-MBP-2.lan>
|
* @author VITOR SANTOS COSTA <vsc@VITORs-MBP-2.lan>
|
||||||
|
Reference in New Issue
Block a user