diff --git a/C/c_interface.c b/C/c_interface.c index 85ce12a72..cafa94147 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -2106,45 +2106,42 @@ X_API void YAP_ClearExceptions(void) { X_API int YAP_InitConsult(int mode, const char *fname, char **full, int *osnop) { - CACHE_REGS - int sno; - BACKUP_MACHINE_REGS(); - const char *fl = NULL; - int lvl = push_text_stack(); - if (mode == YAP_BOOT_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); + CACHE_REGS + int sno; + BACKUP_MACHINE_REGS(); + const char *fl = NULL; + if (mode == YAP_BOOT_MODE) { + mode = YAP_CONSULT_MODE; } - } else { - pop_text_stack(lvl); + if (fname == NULL || fname[0] == '\0') { + 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); strcpy(d, fl); bool consulted = (mode == YAP_CONSULT_MODE); Term tat = MkAtomTerm(Yap_LookupAtom(d)); sno = Yap_OpenStream(tat, "r", MkAtomTerm(Yap_LookupAtom(fname)), 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); + if (sno < 0 || !Yap_ChDir(dirname((char *)d))) { *full = NULL; return -1; } LOCAL_PrologMode = UserMode; - - Yap_init_consult(consulted, pop_output_text_stack__(lvl, fl)); +*full = pop_output_text_stack__(lvl, fl); + Yap_init_consult(consulted,*full); RECOVER_MACHINE_REGS(); UNLOCK(GLOBAL_Stream[sno].streamlock); return sno; diff --git a/C/yap-args.c b/C/yap-args.c index ae4867f11..19fd28ee3 100755 --- a/C/yap-args.c +++ b/C/yap-args.c @@ -153,22 +153,25 @@ const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR, * recursive consulting. * * */ -static bool consult(const char *b_file USES_REGS) { +static bool load_file(const char *b_file USES_REGS) { Term t; 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_compile2 = Yap_MkFunctor(Yap_LookupAtom("c_compile"), 1); /* consult in C */ int lvl = push_text_stack(); char *full; - /* the consult mode does not matter here, really */ + /* the consult mode does not matter here, really */ if ((osno = Yap_CheckAlias(AtomLoopStream)) < 0) { osno = 0; } 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); pop_text_stack(lvl); exit(1); @@ -177,6 +180,8 @@ static bool consult(const char *b_file USES_REGS) { pop_text_stack(lvl); return false; } + __android_log_print( + ANDROID_LOG_INFO, "YAPDroid", "do reset %s ",b_file); do { CACHE_REGS @@ -197,7 +202,7 @@ static bool consult(const char *b_file USES_REGS) { FunctorOfTerm(t) == functor_command1)) { t = ArgOfTerm(1, t); 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); } else { YAP_RunGoalOnce(t); @@ -206,7 +211,7 @@ static bool consult(const char *b_file USES_REGS) { YAP_CompileClause(t); } 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, (long int)errd->errorLine, errd->classAsText, errd->errorAsText); } @@ -221,16 +226,82 @@ static bool consult(const char *b_file USES_REGS) { 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, - const char *s2, ...) { - if (ok1 && s1) - return s1; - if (ok2) - return s2; - return NULL; -} + static const char *sel( + testf test, const void *info, const char *s1, ...) { + const char *fmt = s1; +va_list ap; + char *buf = malloc(FILENAME_MAX + 1); +__android_log_print( + 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) { CACHE_REGS @@ -256,103 +327,130 @@ static void Yap_set_locations(YAP_init_args *iap) { // --_not useful in Android, WIN32; /// -- DESTDIR/ in Anaconda /// -- /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__ - NULL, + "/", #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 - false); - /// BINDIR: where the OS stores header files, namely libYap... - Yap_BINDIR = sel(true, iap->BINDIR != NULL, iap->BINDIR, true, -#if __ANDROID__ - NULL, -#else + EOLIST + ); + + /// BINDIR: where the OS stores header files, namely libYap... + Yap_BINDIR = sel( is_dir, Yap_ROOTDIR, iap->BINDIR, + getenv("YAPBINDIR"), +#if !defined(__ANDROID__) join(getenv("DESTDIR"), YAP_BINDIR), #endif - false); + join(Yap_ROOTDIR, "/bin"), + EOLIST); + /// LIBDIR: where the OS stores dynamic libraries, namely libYap... - Yap_LIBDIR = sel(true, iap->LIBDIR != NULL, iap->LIBDIR, true, -#if __ANDROID__ - NULL, -#else + Yap_LIBDIR = sel( is_dir, Yap_ROOTDIR, iap->LIBDIR, +#if !defined(__ANDROID__) join(getenv("DESTDIR"), YAP_LIBDIR), #endif - false); + join(Yap_ROOTDIR, "/lib"), + EOLIST); + /// DLLDIR: where libraries can find expicitely loaded DLLs - Yap_DLLDIR = sel(true, iap->DLLDIR != NULL, iap->DLLDIR, true, -#if __ANDROID__ - NULL, -#else - join(getenv("DESTDIR"), YAP_DLLDIR), + Yap_DLLDIR = sel(is_dir, Yap_LIBDIR, iap->DLLDIR, + getenv("YAPLIBDIR"), +#if !defined(__ANDROID__) + join(getenv("DESTDIR"), YAP_DLLDIR), + join(Yap_LIBDIR, "/yap"), #endif - false); + EOLIST); + /// INCLUDEDIR: where the OS stores header files, namely libYap... - Yap_INCLUDEDIR = sel(true, iap->INCLUDEDIR != NULL, iap->INCLUDEDIR, true, -#if __ANDROID__ - NULL, -#else - join(getenv("DESTDIR"), YAP_INCLUDEDIR), + Yap_INCLUDEDIR = sel(is_dir, Yap_ROOTDIR, iap->INCLUDEDIR, +#if !defined(__ANDROID__) + join(getenv("DESTDIR"), YAP_INCLUDEDIR), #endif - false); + join(Yap_ROOTDIR, "/include"), + EOLIST); + /// SHAREDIR: where OS & ARCH independent files live - Yap_SHAREDIR = sel(true, iap->SHAREDIR != NULL, iap->SHAREDIR, true, -#if __ANDROID__ - "/assets", -#else - join(getenv("DESTDIR"), YAP_SHAREDIR), + Yap_SHAREDIR = sel( is_dir, Yap_ROOTDIR, iap->SHAREDIR, + getenv("YAPSHAREDIR"), +#if !defined(__ANDROID__) + join(getenv("DESTDIR"), YAP_SHAREDIR), + join(Yap_ROOTDIR, "/share"), + "/assets", #endif - false); + join(Yap_ROOTDIR, "/files"), + EOLIST); /// 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__ + YAP_PLDIR, "/assets/Yap", #else join(getenv("DESTDIR"), YAP_PLDIR), + join(Yap_SHAREDIR, "/Yap"), #endif - false); + EOLIST); /// ``COMMONSDIR: Prolog Commons - Yap_COMMONSDIR = sel(true, iap->COMMONSDIR != NULL, iap->COMMONSDIR, true, + Yap_COMMONSDIR = sel(is_dir, Yap_SHAREDIR, iap->COMMONSDIR, #if __ANDROID__ "/assets/PrologCommons", #else join(getenv("DESTDIR"), YAP_SHAREDIR "/PrologCommons"), + join(Yap_SHAREDIR, "PrologCommons"), #endif - false); + EOLIST); /// BOOTPLDIR: where we can find Prolog bootstrap files - Yap_BOOTSTRAP = sel(true, iap->BOOTSTRAP != NULL, iap->BOOTSTRAP, true, -#if __ANDROID__ - "/assets/Yap/pl/boot.yap", -#else - join(getenv("DESTDIR"), YAP_BOOTSTRAP), -#endif - false); + Yap_BOOTSTRAP = sel( is_file, NULL, iap->BOOTSTRAP, + YAP_BOOTSTRAP, + EOLIST); /// 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__ - "/assets/Yap/pl/boot.yap", + "/assets/Yap/pl", #else - join(getenv("DESTDIR"), YAP_BOOTFILE), + join(Yap_PLDIR, "/pl"), #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 Yap_OUTPUT_STARTUP = - sel(false, iap->OUTPUT_STARTUP != NULL, iap->OUTPUT_STARTUP, true, -#if __ANDROID__ - NULL, + sel( is_wfile, Yap_AbsoluteFile(".",false), iap->OUTPUT_STARTUP, +#if defined(__ANDROID__) +EOLIST, #else - join(getenv("DESTDIR"), YAP_OUTPUT_STARTUP), + YAP_OUTPUT_STARTUP, #endif - false); + "startup.yss", +EOLIST); + 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__ - NULL, +EOLIST, #else - join(getenv("DESTDIR"), YAP_INPUT_STARTUP), + join(getenv("DESTDIR"), YAP_INPUT_STARTUP), #endif - false); - if (Yap_ROOTDIR) + join(Yap_DLLDIR, "/startup.yss"), + "/usr/local/lib/Yap/startup.yss", + "/usr/lib/Yap/startup.yss", + EOLIST); + + if (Yap_ROOTDIR) setAtomicGlobalPrologFlag(HOME_FLAG, MkAtomTerm(Yap_LookupAtom(Yap_ROOTDIR))); 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(); YAP_init_args *iap = x; memset(iap, 0, sizeof(YAP_init_args)); + iap->Argc = argc; + iap->Argv = argv; #if __ANDROID__ iap->boot_file_type = YAP_BOOT_PL; iap->INPUT_STARTUP = NULL; iap->assetManager = NULL; + return YAP_BOOT_PL; #else iap->boot_file_type = YAP_QLY; iap->INPUT_STARTUP = saved_state; -#endif - iap->Argc = argc; - iap->Argv = argv; 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 do_bootstrap = yap_init->boot_file_type == YAP_BOOT_PL; struct ssz_t minfo; - + __android_log_print( + ANDROID_LOG_INFO, "YAPDroid", "start init "); if (YAP_initialized) /* ignore repeated calls to YAP_Init */ return; @@ -1039,16 +1139,20 @@ X_API void YAP_Init(YAP_init_args *yap_init) { Yap_ExecutionMode = yap_init->ExecutionMode; Yap_set_locations(yap_init); - if (do_bootstrap || !try_restore || + if (Yap_INPUT_STARTUP==NULL) + try_restore = false; + if (do_bootstrap || !try_restore || !Yap_SavedInfo(Yap_INPUT_STARTUP, &minfo.Trail, &minfo.Stack, &minfo.Heap)) { init_globals(yap_init); start_modules(); CurrentModule = PROLOG_MODULE; - TermEof = MkAtomTerm(Yap_LookupAtom("end_of_file")); + TermEof = MkAtomTerm(Yap_LookupAtom("end_of_file")); 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, MkAtomTerm(Yap_LookupAtom(Yap_BOOTFILE))); setBooleanGlobalPrologFlag(SAVED_PROGRAM_FLAG, false); @@ -1056,6 +1160,8 @@ X_API void YAP_Init(YAP_init_args *yap_init) { if (yap_init->QuietMode) { setVerbosity(TermSilent); } + __android_log_print( + ANDROID_LOG_INFO, "YAPDroid", "restore %s ",Yap_INPUT_STARTUP ); Yap_Restore(Yap_INPUT_STARTUP); init_globals(yap_init); diff --git a/CMakeLists.txt b/CMakeLists.txt index 74a07d0c7..9b31c68d8 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -320,6 +320,7 @@ set(YAP_ROOTDIR ${prefix}) # libdir defined above set(YAP_DATADIR ${CMAKE_INSTALL_FULL_DATADIR}) set(YAP_INCLUDEDIR ${CMAKE_INSTALL_FULL_INCLUDEDIR}/Yap) +set(YAP_BINDIR ${CMAKE_INSTALL_FULL_BINDIR}) set(YAP_LIBDIR ${CMAKE_INSTALL_FULL_LIBDIR}) set(YAP_DLLDIR ${CMAKE_INSTALL_FULL_LIBDIR}/Yap) set(YAP_PLDIR ${CMAKE_INSTALL_FULL_DATADIR}/Yap) @@ -532,8 +533,16 @@ include_directories(utf8proc packages/myddas packages/myddas/sqlite3/src ) set_property(SOURCE ${LIBYAP_SOURCES} APPEND PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1) +IF (WITH_SWIG) + find_host_package(SWIG) + # macro_log_feature (SWIG_FOUND "Swig" + # "Use SWIG Interface Generator " + # "http://www.swig.org" ON) +ENDIF (WITH_SWIG) + IF (WITH_MYDDAS) if (ANDROID) + include_directories (packages/swig/android) else() add_definitions(-DUSE_MYDDAS=1 -DMYDDAS_SQLITE3=1) @@ -553,14 +562,6 @@ IF (WITH_MYDDAS) endif(WITH_MYDDAS) -IF (WITH_SWIG) - find_host_package(SWIG) - # macro_log_feature (SWIG_FOUND "Swig" - # "Use SWIG Interface Generator " - # "http://www.swig.org" ON) -ENDIF (WITH_SWIG) - - IF (WITH_PYTHON) include(python ) diff --git a/CXX/yapq.hh b/CXX/yapq.hh index 7fcf764c0..c7a96a9f7 100644 --- a/CXX/yapq.hh +++ b/CXX/yapq.hh @@ -270,6 +270,8 @@ public: inline void setArgv(char **fl) { Argv = fl; }; inline char **getArgv() { return Argv; }; + + inline void setROOTDIR(char *fl) { ROOTDIR = fl; }; }; /** @@ -293,7 +295,14 @@ public: YAPEngine(YAPEngineArgs *cargs) { engine_args = cargs; // 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); +#endif }; /// construct a new engine, including aaccess to callbacks /// construct a new engine using argc/argv list of arguments YAPEngine(int argc, char *argv[], diff --git a/config.h.cmake b/config.h.cmake index f24df26d4..16547a3bc 100644 --- a/config.h.cmake +++ b/config.h.cmake @@ -2030,7 +2030,7 @@ significant byte first (like Motorola and SPARC, unlike Intel). */ /* name of Commons library */ #ifndef YAP_COMMONSDIR -#define YAP COMMONSDIR "${YAP_DATADIR}/PrologCommmons" +#define YAP_COMMONSDIR "${YAP_DATADIR}/PrologCommmons" #endif diff --git a/library/android.yap b/library/android.yap new file mode 100644 index 000000000..13e33bde3 --- /dev/null +++ b/library/android.yap @@ -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]. \ No newline at end of file diff --git a/os/assets.c b/os/assets.c index ed1dac028..b19fb5b15 100644 --- a/os/assets.c +++ b/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) ); // strcpy(dir, fname); // char *d = basename(dir); - am = AAssetManager_open(Yap_assetManager(), fname, mode); + am = AAssetManager_open(Yap_assetManager(), fname, io_mode); //if (am==NULL) // __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) { // 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 (!am) { + __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "failed %s <%s>", fname, io_mode); + return NULL; } // 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_handle = NULL; st->status = Seekable_Stream_f|Input_Stream_f; - return st; + return st->file; } else { // should be done, but if not GLOBAL_Stream[sno].vfs_handle = am; diff --git a/os/iopreds.c b/os/iopreds.c index f163624ff..dae2ecfd4 100644 --- a/os/iopreds.c +++ b/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, CurrentModule == 0 ? "prolog" : RepAtom(AtomOfTerm(CurrentModule))->StrOfAE, - name, sno); + RepAtom(name)->StrOfAE, sno); if (io_mode == NULL) Yap_Error(PERMISSION_ERROR_NEW_ALIAS_FOR_STREAM, MkIntegerTerm(sno), "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; if (fname) { - if ((vfsp = vfs_owner(fname)) != NULL && - vfsp->open(vfsp, fname, io_mode, sno)) { - // read, write, append - user_name = st->user_name; - st->vfs = vfsp; - UNLOCK(st->streamlock); - } else { - st->file = fopen(fname, io_mode); - if (st->file == NULL) { - UNLOCK(st->streamlock); - if (errno == ENOENT && !strchr(io_mode, 'r')) { - PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s: %s", fname, - strerror(errno)); - } else { - PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, tin, "%s: %s", fname, - strerror(errno)); - } - } - st->vfs = NULL; - } - if (!st->file && !st->vfs) { - PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s", fname); - /* extract BACK info passed through the stream descriptor */ - 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; + if ((vfsp = vfs_owner(fname)) != NULL) { + if (vfsp->open(vfsp, fname, io_mode, sno)) { + // read, write, append + user_name = st->user_name; + st->vfs = vfsp; + UNLOCK(st->streamlock); + __android_log_print( + ANDROID_LOG_INFO, "YAPDroid", "got %d ", sno); + } else { + UNLOCK(st->streamlock); + __android_log_print( + ANDROID_LOG_INFO, "YAPDroid", "failed %s ",fname); +return false; + } + } else { + st->file = fopen(fname, io_mode); + if (st->file == NULL) { + __android_log_print( + ANDROID_LOG_INFO, "YAPDroid", "failed %s ",fname); + UNLOCK(st->streamlock); + if (errno == ENOENT && !strchr(io_mode, 'r')) { + PlIOError(EXISTENCE_ERROR_SOURCE_SINK, tin, "%s: %s", fname, + strerror(errno)); + } else { + PlIOError(PERMISSION_ERROR_OPEN_SOURCE_SINK, tin, "%s: %s", fname, + strerror(errno)); + } + return false; + } - 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 - st->file = _popen(buf, io_mode); + st->file = _popen(buf, io_mode); #else - st->file = popen(buf, io_mode); + st->file = popen(buf, io_mode); #endif - fname = "popen"; - user_name = tin; - st->status |= Popen_Stream_f; - pop_text_stack(i); - } else { - Yap_ThrowError(DOMAIN_ERROR_SOURCE_SINK, tin, "open"); - } - } + fname = "popen"; + user_name = tin; + st->status |= Popen_Stream_f; + pop_text_stack(i); + } else { + Yap_ThrowError(DOMAIN_ERROR_SOURCE_SINK, tin, "open"); + } + } if (!strchr(io_mode, 'b') && binary_file(fname)) { st->status |= Binary_Stream_f; } diff --git a/os/readterm.c b/os/readterm.c index 74d5e419b..4a12db042 100644 --- a/os/readterm.c +++ b/os/readterm.c @@ -376,10 +376,10 @@ static Term syntax_error(TokEntry *errtok, int sno, Term cmod, Int newpos, bool TokEntry *tok = LOCAL_tokptr; Int start_line = tok->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 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->parserFirstLine = start_line; diff --git a/os/sysbits.c b/os/sysbits.c index a211b7ed6..1f0794b2b 100644 --- a/os/sysbits.c +++ b/os/sysbits.c @@ -355,7 +355,7 @@ bool Yap_ChDir(const char *path) { int lvl = push_text_stack(); const char *qpath = Yap_AbsoluteFile(path, true); - //__android_log_print(ANDROID_LOG_INFO, "YAPDroid", "chdir %s", path); + __android_log_print(ANDROID_LOG_INFO, "YAPDroid", "chdir %s", path); VFS_t *v; if ((v = vfs_owner(qpath))) { rc = v->chdir(v, (qpath)); diff --git a/packages/myddas/CMakeLists.txt b/packages/myddas/CMakeLists.txt index bdfa0503e..8ad4309c2 100644 --- a/packages/myddas/CMakeLists.txt +++ b/packages/myddas/CMakeLists.txt @@ -53,7 +53,6 @@ SET_PROPERTY(SOURCE ${MYDDAS_SOURCES} ${MYDDAS_UTIL_SOURCES} ${MYDDAS_HEADERS} PROPERTY COMPILE_DEFINITIONS YAP_KERNEL=1 ) -MY_add_dependencies(myddas plmyddas) add_subdirectory(pl) diff --git a/packages/myddas/pl/CMakeLists.txt b/packages/myddas/pl/CMakeLists.txt index 1ae27c3e8..09320f558 100644 --- a/packages/myddas/pl/CMakeLists.txt +++ b/packages/myddas/pl/CMakeLists.txt @@ -9,74 +9,36 @@ set(MYDDAS_YPP myddas_prolog2sql_optimizer.ypp) set(MYDDAS_DRIVERS - "myddas_driver.ypp" + myddas_driver.ypp ) - - - if (ANDROID) - set (MYDDAS_PREFIX ${YAP_INSTALL_DATADIR} ) -else() - set (MYDDAS_PREFIX ${CMAKE_CURRENT_BINARY_DIR} ) -endif() - -get_property(MYDDAS_FLAGS GLOBAL PROPERTY COMPILE_DEFINITIONS) - -function(cpp_compile output filename) - get_filename_component(base ${filename} NAME_WE) - set(base_abs ${MYDDAS_PREFIX}/${base}) - set(outfile ${base_abs}.yap) - set(${output} ${${output}} ${outfile} PARENT_SCOPE) - IF (MSVC) - add_custom_command( - OUTPUT ${outfile} - COMMAND ${CMAKE_C_COMPILER} ${MYDDAS_FLAGS} /EP /P ${outfile} ${CMAKE_CURRENT_SOURCE_DIR}/${filename} - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${filename}") - ELSE (MSVC) - add_custom_command( - OUTPUT ${outfile} - COMMAND ${CMAKE_C_COMPILER} ${MYDDAS_FLAGS} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/${filename} -o ${outfile} - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${filename}") - ENDIF (MSVC) - set_source_files_properties(${outfile} PROPERTIES GENERATED TRUE) -endfunction() - -if (ANDROID) -set (MYDDAS_PL_OUTDIR ${YAP_APP_DIR}/src/generated/assets/Yap ) -else() -set (MYDDAS_PL_OUTDIR ${CMAKE_CURRENT_BINARY_DIR} ) -endif() - -function(cpp_driver output dbms filename) - set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap) - set(${output} ${${output}} ${outfile} PARENT_SCOPE) - IF (MSVC) - add_custom_command( - OUTPUT ${outfile} - COMMAND ${CMAKE_C_COMPILER} -D${dbms} /EP /P ${outfile} ${CMAKE_CURRENT_SOURCE_DIR}/${filename} - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${filename}") - else () - add_custom_command( - OUTPUT ${outfile} - COMMAND ${CMAKE_C_COMPILER} -D${dbms} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/${filename} -o ${outfile} - DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${filename}") - ENDIF (MSVC) - set_source_files_properties(${outfile} PROPERTIES GENERATED TRUE) -endfunction() - set(MYDDAS_DBMS sqlite3 postgres odbc) -foreach (file ${MYDDAS_YPP}) - cpp_compile(MYDDAS_YAP ${file}) -endforeach () -foreach (driver ${MYDDAS_DBMS}) - cpp_driver(MYDDAS_YAP ${driver} myddas_driver.ypp) -endforeach () +if (ANDROID) + 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) +foreach (filename ${MYDDAS_YPP}) + get_filename_component(base ${filename} NAME_WE) + set(base_abs ${MYDDAS_PL_OUTDIR}/${base}) + set(outfile ${base_abs}.yap) + execute_process( + COMMAND ${CMAKE_C_COMPILER} ${MYDDAS_FLAGS} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/${filename} -o ${outfile} + ) + set_source_files_properties(outfile PROPERTIES GENERATED TRUE) +endforeach () +foreach (dbms ${MYDDAS_DBMS} ) + set(outfile ${MYDDAS_PL_OUTDIR}/myddas_${dbms}.yap) + execute_process( + COMMAND ${CMAKE_C_COMPILER} -D${dbms} -x c -E -P -w ${CMAKE_CURRENT_SOURCE_DIR}/myddas_driver.ypp -o ${outfile} + ) -list (APPEND MYDDAS_YAP ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/sqlitest.yap ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/chinook.db) -add_to_group(MYDDAS_YAP pl_library ) + set_source_files_properties(outfile PROPERTIES GENERATED TRUE) -add_custom_target(plmyddas ALL DEPENDS ${MYDDAS_YAP} ) +endforeach() - install(FILES ${MYDDAS_YAP} - DESTINATION ${YAP_INSTALL_DATADIR} - ) + set( MYDDAS_YAP ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/sqlitest.yap ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/chinook.db) + add_to_group(MYDDAS_YAP pl_library ) + file(INSTALL ${MYDDAS_YAP} + DESTINATION ${MYDDAS_PL_OUTDIR} ) diff --git a/packages/python/swig/prolog/yapi.yap b/packages/python/swig/prolog/yapi.yap index 63e69147a..a540f0ad6 100644 --- a/packages/python/swig/prolog/yapi.yap +++ b/packages/python/swig/prolog/yapi.yap @@ -73,8 +73,9 @@ python_query( Caller, String ) :- query_to_answer( Goal, VarNames, Status, Bindings), Caller.port := Status, write_query_answer( Bindings ), - nl(user_error), - maplist(in_dict(Caller.answer, Bindings), Bindings). + nl(user_error), + maplist(in_dict(Caller.answer, Bindings), Bindings). +>>>>>>> 37d5dcedc17b8c63cd9fa213454edb37816a130f /** * diff --git a/packages/python/swig/yap4py/yapi.py b/packages/python/swig/yap4py/yapi.py index faba19c8c..3763ad04b 100644 --- a/packages/python/swig/yap4py/yapi.py +++ b/packages/python/swig/yap4py/yapi.py @@ -78,16 +78,20 @@ class Query (YAPQuery): super().__init__(g) self.engine = engine self.port = "call" - self.bindings = None - self.answer = {} def __iter__(self): return self + def done(self): + return self.port == "fail" or self.port == "exit" + def __next__(self): - if self.port == "fail": - raise IndexError() - return self.next() + self.answer = {} + if self.port == "fail" or self.port == "exit": + raise StopIteration() + if self.next(): + return self.answer + raise StopIteration() def name( name, arity): try: @@ -141,7 +145,7 @@ class YAPShell: # # vs is the list of variables # you can print it out, the left-side is the variable name, # the right side wraps a handle to a variable - import pdb; pdb.set_trace() + # import pdb; pdb.set_trace() # #pdb.set_trace() # atom match either symbols, or if no symbol exists, sttrings, In this case # variable names should match strings @@ -151,14 +155,13 @@ class YAPShell: # return try: engine = self.engine - bindings = [] + bindings = [] loop = False - g = python_query(self, query) - self.q = Query( engine, g ) - while self.q.next(): - bindings += [self.q.answer] - if self.q.port == "exit": - break + q = Query( engine, python_query( engine, query) ) + for answer in q: + bindings += [answer] + if g.done(): + return bindings if loop: continue s = input("more(;), all(*), no(\\n), python(#)? ").lstrip() @@ -177,10 +180,8 @@ class YAPShell: if self.q: self.q.close() self.q = None - if bindings: - return True,bindings print("No (more) answers") - return False, None + return bindings except Exception as e: if not self.q: return False, None diff --git a/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap b/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap index 4b4be4e88..09f21f89b 100644 --- a/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap +++ b/packages/python/yap_kernel/yap_ipython/prolog/jupyter.yap @@ -42,7 +42,7 @@ jupyter_cell(Caller, _, Line ) :- catch( python_query(Query,Line), error(A,B), - system_error(A,B) + (writeln(A,B),system_error(A,B)) ). restreams(call) :- diff --git a/packages/python/yap_kernel/yap_ipython/yapi.py b/packages/python/yap_kernel/yap_ipython/yapi.py index 6e964ee83..ad47d4818 100644 --- a/packages/python/yap_kernel/yap_ipython/yapi.py +++ b/packages/python/yap_kernel/yap_ipython/yapi.py @@ -550,7 +550,7 @@ class YAPRun(InteractiveShell): self.yapeng.mgoal(errors(self,text),"user",True) return self.errors - def jupyter_query(self, s): + def prolog(self, s): # # construct a self.queryuery from a one-line string # self.query is opaque to Python @@ -590,7 +590,7 @@ class YAPRun(InteractiveShell): if found: sys.stderr.write('Completed, with '+str(self.answers)+'\n') result.result = self.answers - return result + return result.results except Exception as e: sys.stderr.write('Exception '+str(e)+'in query '+ str(self.query)+ @@ -736,7 +736,7 @@ class YAPRun(InteractiveShell): # run the new command using the given tracer # # tracer.runfunc(f,self,cell,state) - self.jupyter_query( cell ) + self.prolog( cell ) # state = tracer.runfunc(jupyter_query( self, cell ) ) self.shell.last_execution_succeeded = True result.result = [] @@ -814,12 +814,15 @@ class YAPRun(InteractiveShell): If the line terminates on a `*/` or starts on a `%` we assume the line is a comment. """ - s0 = s.rstrip(' \n\t\i') - [program,x,query] = s0.rpartition('\n') - if query[-1] == '.': - return s,'',False,0 - (query, _,loop, sols) = self.clean_end(query) - return (program, query, loop, sols) + try: + s0 = s.rstrip(' \n\t\i') + [program,x,query] = s0.rpartition('\n') + if query[-1] == '.': + return s,'',False,0 + (query, _,loop, sols) = self.clean_end(query) + return (program, query, loop, sols) + except: + return (s,'',true,1) # global #globals = {} diff --git a/packages/swig/android/CMakeLists.txt b/packages/swig/android/CMakeLists.txt index 868d7fed2..b46f9a6c9 100644 --- a/packages/swig/android/CMakeLists.txt +++ b/packages/swig/android/CMakeLists.txt @@ -1,84 +1,68 @@ - # This is a CMake file for SWIG and Android + # This is a CMake file for SWIG and Android - set (SWIG_CXX_DIR ${YAP_APP_DIR}/src/generated/jni) -FILE( MAKE_DIRECTORY ${YAP_APP_DIR}/src/generated/java/pt/up/yap/lib ) -FILE( MAKE_DIRECTORY ${YAP_APP_DIR}/src/generated/assets) -FILE( MAKE_DIRECTORY ${YAP_APP_DIR}/src/generated/jni) - set ( pllib ${YAP_APP_DIR}/src/generated/assets/Yap ) + set(JAVA_SWIG_OUTDIR ${CMAKE_SOURCE_DIR}/../yaplib/src/generated/java/pt/up/yap/lib) + set(SWIG_CXX_DIR ${CMAKE_BINARY_DIR}/src/generated/jni) + FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/generated/java/pt/up/yap/lib) + FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/generated/assets/Yap/pl) + FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/generated/assets/so) + FILE(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/src/generated/jni) + set(YAP_ASSETS ${CMAKE_SOURCE_DIR}/../yaplib/src/generated/assets/Yap) - set ( SWIG_SOURCES ${CMAKE_SOURCE_DIR}/packages/swig/yap.i ) - SET_SOURCE_FILES_PROPERTIES(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON) + set(SWIG_SOURCES ${CMAKE_SOURCE_DIR}/packages/swig/yap.i) + SET_SOURCE_FILES_PROPERTIES(${SWIG_SOURCES} PROPERTIES CPLUSPLUS ON) - include_directories ( - ${CMAKE_SOURCE_DIR}/CXX - ) - set( GMP_ROOT ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI} ) - set (GMP_INCLUDE_DIRS ${GMP_ROOT}) - set (GMP_LIBRARIES ${GMP_ROOT}/libgmp.so) - -# -# add_custom_target (pllib -# COMMAND ${CMAKE_COMMAND} -E make_directory ${YAP_INSTALL_DATADIR} -# COMMAND ${CMAKE_COMMAND} -E copy ${pl_library} ${YAP_INSTALL_DATADIR} -# COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/android.yap ${YAP_INSTALL_DATADIR} -# DEPENDS ${pl_library} -#) -# -# add_custom_target (pllibpl -# COMMAND ${CMAKE_COMMAND} -E make_directory ${YAP_INSTALL_DATADIR}/pl -# COMMAND ${CMAKE_COMMAND} -E copy ${pl_boot_library} ${YAP_INSTALL_DATADIR}/pl -#DEPENDS pllib ${pl_boot_library} -# ) -# add_custom_target (pllibos ALL -# COMMAND ${CMAKE_COMMAND} -E make_directory ${YAP_INSTALL_DATADIR}/os -# COMMAND ${CMAKE_COMMAND} -E copy ${pl_os_library} ${YAP_INSTALL_DATADIR}/os -#DEPENDS pllibpl ${pl_os_library} -# ) -# -# add_custom_command (OUTPUT ${CMAKE_SWIG_OUTPUT}/swig_streamer.cpp -# COMMAND ${SWIG_EXECUTABLE} -c++ -java -package ${SWIG_MODULE_NAME} -O -outdir ${CMAKE_SWIG_OUTDIR} -addextern -I${CMAKE_CURRENT_SOURCE_DIR} -o ${CMAKE_SWIG_OUTPUT}/swig_streamer.cpp -oh ${CMAKE_SWIG_OUTPUT}/swig_streamer.hh streamer.i -# DEPENDS streamer.i -# ) -# -# add_custom_command (OUTPUT ${CMAKE_SWIG_OUTPUT}/yap_swig.cpp -# COMMAND ${SWIG_EXECUTABLE} -c++ -java -package ${SWIG_MODULE_NAME} -O -outdir ${CMAKE_SWIG_OUTDIR} -addextern -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/include -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/os -I${CMAKE_SOURCE_DIR}/OPTYap -I${CMAKE_BINARY_DIR} -I${GMP_INCLUDE_DIRS} -DX_API="" -o ${CMAKE_SWIG_OUTPUT}/yap_swig.cpp -oh ${CMAKE_SWIG_OUTPUT}/yap_swig.hh ${SWIG_SOURCES} -# DEPENDS pllibos ${SWIG_SOURCES} YAP++) -# + include_directories( + ${CMAKE_SOURCE_DIR}/CXX + ) + set(GMP_ROOT ${CMAKE_SOURCE_DIR}/../gmp/${ANDROID_ABI}) + set(GMP_INCLUDE_DIRS ${GMP_ROOT}) + set(GMP_LIBRARIES ${GMP_ROOT}/libgmp.so) - add_library(YAPJava OBJECT - ${SWIG_CXX_DIR}/streamer_swig.cxx - ${SWIG_CXX_DIR}/yapi_swig.cxx - streamer.cpp - ) + file(INSTALL ${pl_library} DESTINATION ${YAP_ASSETS}) + file(INSTALL ${CMAKE_CURRENT_SOURCE_DIR}/android.yap DESTINATION ${YAP_ASSETS}) - set_target_properties(YAPJava PROPERTIES LINKER_LANGUAGE CXX) + file(INSTALL ${pl_boot_library} DESTINATION ${YAP_ASSETS}/pl) + file(INSTALL ${pl_os_library} DESTINATION ${YAP_ASSETS}/os) + + + execute_process(COMMAND swig -c++ -java -package pt.up.yap.lib -O -outdir ${JAVA_SWIG_OUTDIR} -addextern -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/include -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/os -I${CMAKE_SOURCE_DIR}/OPTYap -I${CMAKE_BINARY_DIR} -I${GMP_INCLUDE_DIRS} -DX_API -o ${SWIG_CXX_DIR}/yapi_swig.cxx ${SWIG_SOURCES} + ) + + execute_process(COMMAND ${SWIG_EXECUTABLE} -c++ -java -package pt.up.yap.lib -O -outdir ${JAVA_SWIG_OUTDIR} -addextern -I${CMAKE_CURRENT_SOURCE_DIR} -o ${SWIG_CXX_DIR}/streamer_swig.cxx streamer.i + ) + + + add_library(YAPJava OBJECT + ${CMAKE_BINARY_DIR}/src/generated/jni/streamer_swig.cxx + ${CMAKE_BINARY_DIR}/src/generated/jni/yapi_swig.cxx + streamer.cpp + ) + + set_target_properties(YAPJava PROPERTIES LINKER_LANGUAGE CXX) # GMP_FOUND - true if GMP/MPIR was found # GMP_INCLUDE_DIRS - include search path # GMP_LIBRARIES - libraries to link with #config.h needs this (TODO: change in code latter) - include_directories( .;${GMP_INCLUDE_DIRS};${CMAKE_SOURCE_DIR}/include;${CMAKE_SOURCE_DIR}/H;${CMAKE_SOURCE_DIR}/H/generated;${CMAKE_SOURCE_DIR}/os;${CMAKE_SOURCE_DIR}/OPTYap;${CMAKE_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR} ) - - - + include_directories(.;${GMP_INCLUDE_DIRS};${CMAKE_SOURCE_DIR}/include;${CMAKE_SOURCE_DIR}/H;${CMAKE_SOURCE_DIR}/H/generated;${CMAKE_SOURCE_DIR}/os;${CMAKE_SOURCE_DIR}/OPTYap;${CMAKE_BINARY_DIR};${CMAKE_CURRENT_SOURCE_DIR}) if (FALSE) - set (SWIG_ADD_MODULE YAPJava SHARED CPLUSPLUS ${SWIG_SOURCES} ) - # Define swig module with given name and specified language + set(SWIG_ADD_MODULE YAPJava SHARED CPLUSPLUS ${SWIG_SOURCES}) + # Define swig module with given name and specified language - set (SWIG_LINK_LIBRARIES YAPJava YAP++ libYAP ) - #- Link libraries to swig module + set(SWIG_LINK_LIBRARIES YAPJava YAP++ libYAP) + #- Link libraries to swig module - add_library (YAPJavaTop SHARED - main.cpp main.h - ) + add_library(YAPJavaTop SHARED + main.cpp main.h + ) - target_link_libraries( YAPJavaTop ${SWIG_MODULE_${YAPJava}_REAL_NAME} YAP++ libYap android) + target_link_libraries(YAPJavaTop ${SWIG_MODULE_${YAPJava}_REAL_NAME} YAP++ libYap android) - endif() + endif () diff --git a/pl/attributes.yap b/pl/attributes.yap index 1b53282b4..1a1ff8aec 100644 --- a/pl/attributes.yap +++ b/pl/attributes.yap @@ -165,7 +165,7 @@ prolog:copy_term(Term, Copy, Gs) :- -> Gs = [], copy_term(Term, Copy) ; findall(Term-Gs, - '$attributes':residuals_and_delete_attributes(Vs, Gs, Term), + attributes:residuals_and_delete_attributes(Vs, Gs, Term), [Copy-Gs]) ). diff --git a/pl/boot.yap b/pl/boot.yap index e57399718..815604cc3 100644 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -476,9 +476,7 @@ If this hook preodicate succeeds it must instantiate the _Action_ argument to t :- 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). diff --git a/pl/top.yap b/pl/top.yap index aa90af689..00d5bf2ca 100644 --- a/pl/top.yap +++ b/pl/top.yap @@ -494,6 +494,7 @@ write_query_answer( Bindings ) :- '$write_goal_output'(G1, First, NG, Next, IG), '$write_vars_and_goals'(LG, Next, IG). + '$write_goal_output'(var([V|VL]), First, [var([V|VL])|L], next, L) :- !, ( First = first -> true ; format(user_error,',~n',[]) ), format(user_error,'~a',[V]), @@ -513,13 +514,12 @@ write_query_answer( Bindings ) :- G = [_|_], !, % dump on string first so that we can check whether we actually % had any output from the solver. - term_to_string( G, String), + format(string(String),Format,G), ( String == `` -> % we didn't IG = NG, First = Next ; % we did - ( First = first -> true ; format(user_error,',~n',[]) ), format(user_error, '~N~s', [String]), NG = [G|IG] ). diff --git a/pl/undefined.yap b/pl/undefined.yap index d2125e996..fd2d14731 100644 --- a/pl/undefined.yap +++ b/pl/undefined.yap @@ -102,29 +102,41 @@ undefined_query(G0, M0, Cut) :- '$undefp_search'(M0:G0, MG) :- '$pred_exists'(unknown_predicate_handler(_,_,_,_), user), '$yap_strip_module'(M0:G0, EM0, GM0), - user:unknown_predicate_handler(GM0,EM0,M1:G1), - !, - expand_goal(M1:G1, MG). -'$undefp_search'(MG, FMG) :- - expand_goal(MG, FMG). + user:unknown_predicate_handler(GM0,EM0,MG), + !. +'$undefp_search'(M0:G0, M:G) :- +'$get_undefined_predicates'(G, M0, G0, M), !. :- abolish('$undefp'/2). % undef handler -'$undefp'([M0|G0], Action) :- +'$undefp'([M0|G0],_) :- +start_low_level_trace, % make sure we do not loop on undefined predicates - yap_flag( unknown, Action, fail), - '$stop_creeping'(Current), - % yap_flag( debug, Debug, false), - ( - '$undefp_search'(M0:G0, NM:NG), - ( M0 \== NM -> true ; G0 \== NG ), - NG \= fail - -> - yap_flag( unknown, _, Action), - % yap_flag( debug, _, Debug), + setup_call_catcher_cleanup( + '$undef_set'(Action,Debug,Current), + '$search_def'(M0,G0,MG), + Port, + '$undef_reset'(Port,M0:G0,MG,Action,Debug,Current) + ). + +'$undef_set'(Action,Debug,Current) :- + yap_flag( unknown, Action, fail), + 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 -> @@ -132,11 +144,12 @@ undefined_query(G0, M0, Cut) :- '$start_creep'([NM|NG], creep) ; '$execute0'(NG, NM) - ) - ; - yap_flag( unknown, _, Action), - '$handle_error'(Action,G0,M0) - ). + ). +'$undef_reset'(_,M0:G0,_NG,Action,Debug,_Current) :- + yap_flag( unknown, _, Action), + yap_flag( debug, _, Debug), +'$start_creep'([prolog|true], creep), +'$handle_error'(Action,G0,M0). :- '$undefp_handler'('$undefp'(_,_), prolog).