diff --git a/C/c_interface.c b/C/c_interface.c index aafa2b0f6..197b035c1 100755 --- a/C/c_interface.c +++ b/C/c_interface.c @@ -1452,11 +1452,10 @@ X_API Term YAP_ReadBuffer(const char *s, Term *tp) { if (*tp) tv = *tp; else - tv = 0; + tv = (Term)0; LOCAL_ErrorMessage = NULL; const unsigned char *us = (const unsigned char *)s; - while (!(t = Yap_BufferToTermWithPrioBindings(us, strlen(s) + 1, TermNil, - GLOBAL_MaxPriority, tv))) { + while (!(t = Yap_BufferToTermWithPrioBindings(us, TermNil, tv, strlen(s) + 1, GLOBAL_MaxPriority))) { if (LOCAL_ErrorMessage) { if (!strcmp(LOCAL_ErrorMessage, "Stack Overflow")) { if (!Yap_dogc(0, NULL PASS_REGS)) { diff --git a/C/flags.c b/C/flags.c index 5dd2fc60c..3a6cab1f1 100644 --- a/C/flags.c +++ b/C/flags.c @@ -1319,8 +1319,7 @@ static bool setInitialValue(bool bootstrap, flag_func f, const char *s, } CACHE_REGS const unsigned char *us = (const unsigned char *)s; - t0 = Yap_BufferToTermWithPrioBindings(us, strlen(s) + 1, TermNil, - GLOBAL_MaxPriority, 0L); + t0 = Yap_BufferToTermWithPrioBindings(us, TermNil, 0L, strlen(s) + 1, GLOBAL_MaxPriority); if (!t0) return false; if (IsAtomTerm(t0) || IsIntTerm(t0)) { diff --git a/C/index.c b/C/index.c index 6fd571344..4b7f67508 100755 --- a/C/index.c +++ b/C/index.c @@ -633,6 +633,7 @@ type_of_verb(rest,passive). */ +#include #include "absmi.h" #include "YapCompile.h" #if DEBUG @@ -2940,13 +2941,15 @@ yamop *Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) { cint.cls = NULL; LOCAL_Error_Size = 0; + if (ap->cs.p_code.NOfClauses < 2) + return NULL; if ((setjres = sigsetjmp(cint.CompilerBotch, 0)) == 3) { restore_machine_regs(); recover_from_failed_susp_on_cls(&cint, 0); if (!Yap_gcl(LOCAL_Error_Size, ap->ArityOfPE + NSlots, ENV, next_pc)) { CleanCls(&cint); Yap_Error(RESOURCE_ERROR_STACK, TermNil, LOCAL_ErrorMessage); - return FAILCODE; + return NULL; } } else if (setjres == 2) { restore_machine_regs(); @@ -2954,7 +2957,7 @@ yamop *Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) { if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) { CleanCls(&cint); Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage); - return FAILCODE; + return NULL; } } else if (setjres == 4) { restore_machine_regs(); @@ -2962,7 +2965,7 @@ yamop *Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) { if (!Yap_growtrail(LOCAL_Error_Size, FALSE)) { CleanCls(&cint); Yap_Error(RESOURCE_ERROR_TRAIL, TermNil, LOCAL_ErrorMessage); - return FAILCODE; + return NULL; } } else if (setjres != 0) { restore_machine_regs(); @@ -2970,7 +2973,7 @@ yamop *Yap_PredIsIndexable(PredEntry *ap, UInt NSlots, yamop *next_pc) { if (!Yap_growheap(FALSE, LOCAL_Error_Size, NULL)) { Yap_Error(RESOURCE_ERROR_HEAP, TermNil, LOCAL_ErrorMessage); CleanCls(&cint); - return FAILCODE; + return NULL; } } restart_index: @@ -2983,7 +2986,7 @@ restart_index: if (compile_index(&cint) == (UInt)FAILCODE) { Yap_ReleaseCMem(&cint); CleanCls(&cint); - return FAILCODE; + return NULL; } #if DEBUG if (GLOBAL_Option['i' - 'a' + 1]) { diff --git a/C/tracer.c b/C/tracer.c index d060c5067..5052c6907 100644 --- a/C/tracer.c +++ b/C/tracer.c @@ -455,7 +455,7 @@ bool low_level_trace__(yap_low_level_port port, PredEntry *pred, CELL *args) { } UNLOCK(Yap_low_level_trace_lock); #if __ANDROID__ - __android_log_print(ANDROID_LOG_DEBUG, "YAPDroid", "%s\n", buf); + __android_log_print(ANDROID_LOG_ERROR, "YAPDroid", "%s\n", buf); #else *b++ = '\n'; *b = '\0'; @@ -510,7 +510,7 @@ not being output. static Int stop_low_level_trace(USES_REGS1) { Yap_do_low_level_trace = FALSE; LOCAL_do_trace_primitives = TRUE; -#if DEBUG_LOCKS +#if DEBUG_LOCKS//// debug_locks = TRUE; #endif return (TRUE); diff --git a/C/yap-args.c b/C/yap-args.c index f7deb5756..481e873a4 100755 --- a/C/yap-args.c +++ b/C/yap-args.c @@ -146,7 +146,7 @@ static void init_globals(YAP_init_args *yap_init) { } const char *Yap_BINDIR, *Yap_ROOTDIR, *Yap_SHAREDIR, *Yap_LIBDIR, *Yap_DLLDIR, - *Yap_PLDIR, *Yap_BOOTSTRAP, *Yap_COMMONSDIR, *Yap_STARTUP, + *Yap_PLDIR, *Yap_BOOTSTRAP, *Yap_COMMONSDIR, *Yap_INPUT_STARTUP, *Yap_OUTPUT_STARTUP, *Yap_BOOTFILE, *Yap_INCLUDEDIR; /* do initial boot by consulting the file boot.yap */ @@ -272,7 +272,7 @@ static void Yap_set_locations(YAP_init_args *iap) { /// DLLDIR: where libraries can find expicitely loaded DLLs Yap_DLLDIR = sel(true, iap->DLLDIR != NULL, iap->DLLDIR, true, #if __ANDROID__ - NULL + NULL, #else join(getenv("DESTDIR"), YAP_DLLDIR), #endif @@ -312,12 +312,12 @@ static void Yap_set_locations(YAP_init_args *iap) { /// BOOTPLDIR: where we can find Prolog bootstrap files Yap_BOOTSTRAP = sel(true, iap->BOOTSTRAP != NULL, iap->BOOTSTRAP, true, #if __ANDROID__ - "/assets/Yap/pl", + "/assets/Yap/pl/boot,yap", #else join(getenv("DESTDIR"), YAP_BOOTSTRAP), #endif false); - /// BOOTFILE: where we can find the core Prolog bootstrap file + /// BOOTFILE: where we can find the core Prolog boot file Yap_BOOTFILE = sel(false, iap->BOOTFILE != NULL, iap->BOOTFILE, true, #if __ANDROID__ "/assets/Yap/pl/boot.yap", @@ -453,7 +453,7 @@ X_API YAP_file_type_t Yap_InitDefaults(void *x, char *saved_state, int argc, memset(iap, 0, sizeof(YAP_init_args)); #if __ANDROID__ iap->boot_file_type = YAP_BOOT_PL; - iap->SavedState = NULL; + iap->INPUT_STARTUP = NULL; iap->assetManager = NULL; #else iap->boot_file_type = YAP_QLY; @@ -970,6 +970,7 @@ static void init_hw(YAP_init_args *yap_init, struct ssz_t *spt) { static YAP_file_type_t end_init(YAP_init_args *yap_init, YAP_file_type_t rc) { YAP_initialized = true; LOCAL_PrologMode &= ~BootMode; + CurrentModule = USER_MODULE; return rc; } @@ -1039,7 +1040,7 @@ X_API YAP_file_type_t YAP_Init(YAP_init_args *yap_init) { init_globals(yap_init); start_modules(); - consult(Yap_BOOTSTRAP PASS_REGS); + consult(Yap_BOOTFILE PASS_REGS); if (yap_init->install && Yap_OUTPUT_STARTUP) { Term t = MkAtomTerm(Yap_LookupAtom(Yap_OUTPUT_STARTUP)); Term g = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("qsave_program"), 1), diff --git a/CXX/yapdb.hh b/CXX/yapdb.hh index d4838b5f3..5f76881ad 100644 --- a/CXX/yapdb.hh +++ b/CXX/yapdb.hh @@ -110,7 +110,7 @@ protected: const unsigned char *us = (const unsigned char *)s0; tnames = MkVarTerm(); tout = - Yap_BufferToTermWithPrioBindings(us, strlen(s0), TermNil, 1200, tnames); + Yap_BufferToTermWithPrioBindings(us, TermNil, tnames, strlen(s0), 1200); // fprintf(stderr,"ap=%p arity=%d text=%s", ap, ap->ArityOfPE, s); // Yap_DebugPlWrite(out); if (tout == 0L) { diff --git a/CXX/yapt.hh b/CXX/yapt.hh index 7f43481bd..08acdd2f3 100644 --- a/CXX/yapt.hh +++ b/CXX/yapt.hh @@ -76,7 +76,7 @@ public: YAPTerm(void *ptr); /// parse string s and construct a term. YAPTerm(char *s) { - Term tp; + Term tp = 0; mk(YAP_ReadBuffer(s, &tp)); } diff --git a/H/Yatom.h b/H/Yatom.h index 507e9bfbd..5168f2d48 100755 --- a/H/Yatom.h +++ b/H/Yatom.h @@ -20,28 +20,21 @@ #ifndef YATOM_H #define YATOM_H 1 -#ifdef USE_OFFSETS - INLINE_ONLY inline EXTERN Atom AbsAtom(AtomEntry *p); +INLINE_ONLY inline EXTERN AtomEntry *RepAtom(Atom a); + +#ifdef USE_OFFSETS INLINE_ONLY inline EXTERN Atom AbsAtom(AtomEntry *p) { return (Atom)(Addr(p) - AtomBase); } -INLINE_ONLY inline EXTERN AtomEntry *RepAtom(Atom a); - INLINE_ONLY inline EXTERN AtomEntry *RepAtom(Atom a) { return (AtomEntry *) (AtomBase + Unsigned (a); } #else - -INLINE_ONLY inline EXTERN Atom AbsAtom(AtomEntry *p); - INLINE_ONLY inline EXTERN Atom AbsAtom(AtomEntry *p) { return (Atom)(p); } - -INLINE_ONLY inline EXTERN AtomEntry *RepAtom(Atom a); - INLINE_ONLY inline EXTERN AtomEntry *RepAtom(Atom a) { return (AtomEntry *)(a); } diff --git a/library/dialect/swi/os/pl-yap.h b/library/dialect/swi/os/pl-yap.h index fd79a3c1e..b1eade077 100644 --- a/library/dialect/swi/os/pl-yap.h +++ b/library/dialect/swi/os/pl-yap.h @@ -226,8 +226,4 @@ atom_t ATOM_; intptr_t system_thread_id(void); #endif -extern Term Yap_BufferToTermWithPrioBindings(const char *s, size_t len, - encoding_t enc, int prio, - Term *bindingsp); - #endif /* PL_YAP_H */ diff --git a/os/assets.c b/os/assets.c index 7f44a5d4f..0ab9adede 100644 --- a/os/assets.c +++ b/os/assets.c @@ -41,8 +41,8 @@ static char SccsId[] = "%W% %G%"; #include -extern void -Java_pt_up_yap_YAPIO_setAssetManager(JNIEnv *env, jclass clazz, jobject assetManager); +extern X_API void +Java_pt_up_yap_yapdroid_YAPDroid_loadAssetManager(JNIEnv *env, jclass clazz, jobject assetManager); jobject *Yap_aref; JNIEnv *Yap_env; @@ -52,8 +52,8 @@ AAssetManager *Yap_assetManager(void) return AAssetManager_fromJava(Yap_env, Yap_aref); } -void -Java_pt_up_yap_YAPIO_setAssetManager(JNIEnv *env, jclass clazz, jobject assetManager) { +X_API void +Java_pt_up_yap_yapdroid_YAPDroid_loadAssetManager(JNIEnv *env, jclass clazz, jobject assetManager) { Yap_aref = (*env)->NewGlobalRef(env,assetManager); Yap_env = env; } diff --git a/os/readterm.c b/os/readterm.c index 7aa7c9ce5..3524a8f58 100644 --- a/os/readterm.c +++ b/os/readterm.c @@ -1385,9 +1385,8 @@ Term Yap_BufferToTerm(const unsigned char *s, Term opts) { return rval; } -X_API Term Yap_BufferToTermWithPrioBindings(const unsigned char *s, size_t len, - Term opts, int prio, - Term bindings) { +X_API Term Yap_BufferToTermWithPrioBindings(const unsigned char *s, Term opts, Term bindings, size_t len, + int prio) { CACHE_REGS Term ctl; diff --git a/os/yapio.h b/os/yapio.h index 3bc389397..8dad6d06d 100644 --- a/os/yapio.h +++ b/os/yapio.h @@ -117,9 +117,9 @@ extern int Yap_open_buf_read_stream(const char *buf, size_t nchars, encoding_t *encp, memBufSource src); extern int Yap_open_buf_write_stream(encoding_t enc, memBufSource src); extern Term Yap_BufferToTerm(const unsigned char *s, Term opts); -extern X_API Term Yap_BufferToTermWithPrioBindings(const unsigned char *s, - size_t sz, Term opts, - int prio, Term bindings); +extern X_API Term +Yap_BufferToTermWithPrioBindings(const unsigned char *s, Term opts, Term bindings, size_t sz, + int prio); extern FILE *Yap_GetInputStream(Term t, const char *m); extern FILE *Yap_GetOutputStream(Term t, const char *m); extern char *Yap_guessFileName(FILE *f, int sno, char *nameb, size_t max); diff --git a/packages/myddas/myddas.h b/packages/myddas/myddas.h index 6a0cd0313..60f115269 100644 --- a/packages/myddas/myddas.h +++ b/packages/myddas/myddas.h @@ -15,6 +15,10 @@ typedef struct myddas_global *MYDDAS_GLOBAL; #include "myddas_util.h" + +static void Yap_InitMYDDAS_SQLITE3Preds(void); +static void Yap_InitBackMYDDAS_SQLITE3Preds(void); + #ifdef MYDDAS_STATS typedef struct myddas_stats_time_struct *MYDDAS_STATS_TIME; typedef struct myddas_global_stats *MYDDAS_GLOBAL_STATS; diff --git a/packages/myddas/myddas_shared.c b/packages/myddas/myddas_shared.c index 506b96c33..4aba9505c 100644 --- a/packages/myddas/myddas_shared.c +++ b/packages/myddas/myddas_shared.c @@ -681,25 +681,15 @@ void init_myddas(void) { CACHE_REGS if (myddas_initialised) return; + init_sqlite3(); myddas_initialised = TRUE; #if defined MYDDAS_ODBC Yap_InitBackMYDDAS_ODBCPreds(); #endif -#if WIN32 - Yap_InitBackMYDDAS_SQLITE3Preds(); -#endif -#if defined USE_MYDDAS - Yap_InitBackMYDDAS_SharedPreds(); -#endif -#if defined MYDDAS_MYSQL - Yap_InitMYDDAS_MySQLPreds(); #endif #if defined MYDDAS_ODBC Yap_InitMYDDAS_ODBCPreds(); #endif -#if WIN32 - Yap_InitMYDDAS_SQLITE3Preds(); -#endif #if defined USE_MYDDAS Yap_InitMYDDAS_SharedPreds(); #endif @@ -743,4 +733,3 @@ int WINAPI win_myddas(HANDLE hinst, DWORD reason, LPVOID reserved) { } #endif -#endif /* USE_MYDDAS*/ diff --git a/packages/swig/android/CMakeLists.txt b/packages/swig/android/CMakeLists.txt index c736e7895..c247bb2e3 100644 --- a/packages/swig/android/CMakeLists.txt +++ b/packages/swig/android/CMakeLists.txt @@ -20,6 +20,7 @@ FILE( MAKE_DIRECTORY ${YAP_APP_DIR}/src/generated/jni) add_custom_target (pllib COMMAND ${CMAKE_COMMAND} -E make_directory ${pllib} COMMAND ${CMAKE_COMMAND} -E copy ${pl_library} ${pllib} + COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/android.yap ${pllib} DEPENDS ${pl_library} ) diff --git a/packages/swig/android/streamer.cpp b/packages/swig/android/streamer.cpp index ce99d8773..af01c0008 100644 --- a/packages/swig/android/streamer.cpp +++ b/packages/swig/android/streamer.cpp @@ -1,7 +1,7 @@ // -// Created by vsc on 7/6/17. +// Created by vsc on 7/6/17-> // -/* File : example.cxx */ +/* File : example->cxx */ #include "streamer.h" @@ -25,13 +25,12 @@ extern "C" { #include #include -extern void Java_pt_up_yap_streamerJNI_swig_1module_1init__(void); +extern void Java_pt_up_yap_streamerJNI_swig_1module_1init(void); -static VFS_t andstream; -void Java_pt_up_yap_streamerJNI_swig_1module_1init__(void) { - // streamerInstance = 0; -} ; + +static VFS_t *andstream; + static std::string buff0; @@ -83,21 +82,28 @@ streamerInstance->display(buff0); } -void -AndroidStreamer::bind() { - buff0 = *new std::string[256]; - andstream.name = "/android/user_error"; - andstream.vflags = VFS_CAN_WRITE | VFS_HAS_PREFIX; - andstream.prefix = "/android"; - andstream.suffix = NULL; - andstream.open = and_open; - andstream.close = and_close; - andstream.get_char = and_get; - andstream.put_char = and_put; - andstream.flush = and_flush; - andstream.seek = and_seek; - andstream.next = GLOBAL_VFS; - GLOBAL_VFS = &andstream; - Yap_InitStdStream(StdOutStream, Output_Stream_f | Append_Stream_f, NULL, &andstream); - Yap_InitStdStream(StdErrStream, Output_Stream_f | Append_Stream_f, NULL, &andstream); -} + +extern "C" { + + +void Java_pt_up_yap_streamerJNI_swig_1module_1init(void) { + andstream = new VFS_t(); + + andstream->name = "/android/user_error"; + andstream->vflags = VFS_CAN_WRITE | VFS_HAS_PREFIX; + andstream->prefix = "/android"; + andstream->suffix = NULL; + andstream->open = and_open; + andstream->close = and_close; + andstream->get_char = and_get; + andstream->put_char = and_put; + andstream->flush = and_flush; + andstream->seek = and_seek; + andstream->next = GLOBAL_VFS; + GLOBAL_VFS = andstream; + Yap_InitStdStream(StdOutStream, Output_Stream_f | Append_Stream_f, NULL, andstream); + Yap_InitStdStream(StdErrStream, Output_Stream_f | Append_Stream_f, NULL, andstream); //streamerInstance = 0; +} ; + + +} \ No newline at end of file diff --git a/packages/swig/android/streamer.h b/packages/swig/android/streamer.h index c713696c8..27b282fa3 100644 --- a/packages/swig/android/streamer.h +++ b/packages/swig/android/streamer.h @@ -9,10 +9,14 @@ #include #include + struct AndroidStreamer { + std::string *buff0; + virtual void display(std::string text) const = 0; virtual ~AndroidStreamer() {} - void bind(); + AndroidStreamer() { buff0 = new std::string[256]; + }; }; void setStreamer(AndroidStreamer* streamer); AndroidStreamer& getStreamer(); diff --git a/packages/swig/yap.i b/packages/swig/yap.i index 7bdd0e545..267115984 100644 --- a/packages/swig/yap.i +++ b/packages/swig/yap.i @@ -60,7 +60,11 @@ class YAPEngine; return NULL; } #endif - } + #ifdef SWIGJAVA0 + %typemap(javapackage) std::vector "pt.up.yap.YAPTerm" + %template(VectorOfTerm) std::vector; + #endif + } %} #ifdef SWIGPYTHON diff --git a/pl/CMakeLists.txt b/pl/CMakeLists.txt index d7a5636f8..6f114ad6b 100644 --- a/pl/CMakeLists.txt +++ b/pl/CMakeLists.txt @@ -8,6 +8,7 @@ set(PL_BOOT_SOURCES boot.yap bootlists.yap bootutils.yap + builtins.yap callcount.yap checker.yap consult.yap @@ -26,6 +27,7 @@ set(PL_BOOT_SOURCES grammar.yap ground.yap hacks.yap + imports.yap init.yap listing.yap load_foreign.yap diff --git a/pl/arith.yap b/pl/arith.yap index a6b5a78d9..1cc22afea 100644 --- a/pl/arith.yap +++ b/pl/arith.yap @@ -342,7 +342,7 @@ expand_expr(Op, X, Y, O, Q, P) :- %% contains_illegal_dcgnt(+Term) is semidet. % % True if Term contains a non-terminal we cannot deal with using -% goal-expansion. The test is too general approximation, but safe. +% goal-expansion. The test is too general an approximation, but safe. '$contains_illegal_dcgnt'(NT) :- functor(NT, _, A), @@ -356,7 +356,6 @@ expand_expr(Op, X, Y, O, Q, P) :- '$harmless_dcgexception'(instantiation_error). % ex: phrase(([1],x:X,[3]),L) '$harmless_dcgexception'(type_error(callable,_)). % ex: phrase(27,L) - :- set_value('$c_arith',true). /** @} diff --git a/pl/boot.yap b/pl/boot.yap index d6286f335..3d14e7ac8 100644 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -293,7 +293,7 @@ initialize_prolog :- 'qly.yap', 'spy.yap', 'udi.yap']. -:- stop_low_level_trace. +%:- stop_low_level_trace. :- meta_predicate(log_event(+,:)). diff --git a/pl/imports.yap b/pl/imports.yap index 77158a199..ae68ae320 100644 --- a/pl/imports.yap +++ b/pl/imports.yap @@ -1,5 +1,6 @@ :- '$mk_dynamic'('$parent_module'(_,_),prolog). + '$get_undefined_predicates'(G, ImportingMod, G0, ExportingMod) :- recorded('$import','$import'(ExportingModI,ImportingMod,G0I,G,_,_),_), '$continue_imported'(ExportingMod, ExportingModI, G0, G0I).