From 2e9be3d0d4a23194ec2e3660cf161c2336cf4797 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Mon, 19 Mar 2018 15:41:06 +0000 Subject: [PATCH] droid --- C/c_interface.c | 5 +- C/cdmgr.c | 3 +- C/flags.c | 3 +- C/load_foreign.c | 5 +- C/tracer.c | 4 +- C/yap-args.c | 13 ++--- CMakeLists.txt | 3 +- CXX/yapdb.hh | 2 +- CXX/yapq.hh | 2 +- CXX/yapt.hh | 29 ++++++---- H/Yap.h | 1 + library/dialect/swi/os/pl-yap.h | 4 -- os/assets.c | 8 +-- os/readterm.c | 5 +- os/yapio.h | 6 +-- packages/myddas/myddas.h | 1 + packages/myddas/myddas_shared.c | 15 +----- packages/myddas/pl/CMakeLists.txt | 2 +- packages/myddas/pl/myddas.ypp | 3 +- packages/myddas/sqlite3/CMakeLists.txt | 3 ++ packages/myddas/sqlite3/myddas_sqlite3.c | 62 ++++++++++++++++++++-- packages/myddas/sqlite3/test.yap | 28 +++++----- packages/swig/android/CMakeLists.txt | 1 + packages/swig/android/streamer.cpp | 67 +++++++++++++++--------- packages/swig/android/streamer.h | 6 ++- packages/swig/yap.i | 6 ++- pl/CMakeLists.txt | 2 + pl/arith.yap | 3 +- pl/boot.yap | 11 +++- pl/imports.yap | 1 + 30 files changed, 194 insertions(+), 110 deletions(-) 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/cdmgr.c b/C/cdmgr.c index d72d2f7bf..42e36803f 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -36,6 +36,7 @@ static char SccsId[] = "@(#)cdmgr.c 1.1 05/02/98"; #include #include #include +#include static void retract_all(PredEntry *, int); static void add_first_static(PredEntry *, yamop *, int); @@ -1741,7 +1742,7 @@ bool Yap_addclause(Term t, yamop *cp, Term tmode, Term mod, Term *t4ref) /* The only problem we have now is when we need to throw away Indexing blocks */ - if (pflags & IndexedPredFlag) { + if (pflags & IndexedPredFlag && p->cs.p_code.NOfClauses > 1) { Yap_AddClauseToIndex(p, cp, mode == asserta); } if (pflags & (SpiedPredFlag | CountPredFlag | ProfiledPredFlag)) { 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/load_foreign.c b/C/load_foreign.c index adb75e4c0..ea4d8ee97 100644 --- a/C/load_foreign.c +++ b/C/load_foreign.c @@ -45,6 +45,9 @@ Int p_load_foreign(USES_REGS1) { StringList new; bool returncode = FALSE; yhandle_t CurSlot = Yap_StartSlots(); +#if __ANDROID__ +return true; +#endif // Yap_DebugPlWrite(ARG1); printf("%s\n", " \n"); // Yap_DebugPlWrite(ARG2); printf("%s\n", " \n"); @@ -94,7 +97,7 @@ Int p_load_foreign(USES_REGS1) { } else { f = RepAtom(libs->name)->StrOfAE; } - Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, ARG3, + Yap_Error(SYSTEM_ERROR_OPERATING_SYSTEM, ARG3, "Foreign module %s does not have initialization function %s", f, InitProcName); return false; 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/CMakeLists.txt b/CMakeLists.txt index 4c0410eb0..841762ce7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -706,9 +706,8 @@ IF ( ANDROID) - #target_link_libraries(libYap ${CMAKE_SOURCE_DIR}/../sqlite-android/jni/${ANDROID_ABI}/libsqliteX.so android log ) + target_link_libraries(libYap ${CMAKE_SOURCE_DIR}/../sqlite-android/jni/${ANDROID_ABI}/libsqliteX.so android log ) - target_link_libraries(libYap android log ) ENDIF () 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/yapq.hh b/CXX/yapq.hh index cf5f31101..2ffd213ba 100644 --- a/CXX/yapq.hh +++ b/CXX/yapq.hh @@ -338,7 +338,7 @@ public: /// current directory for the engine bool call(YAPPredicate ap, YAPTerm ts[]); /// current directory for the engine - bool goalt(YAPTerm Yt) { return Yt.term(); }; + bool goal(YAPTerm Yt, YAPModule module) { return mgoal(Yt.term(),module.term()); }; /// current directory for the engine bool mgoal(Term t, Term tmod); /// current directory for the engine diff --git a/CXX/yapt.hh b/CXX/yapt.hh index 7f43481bd..edc4f154d 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)); } @@ -322,20 +322,27 @@ public: RECOVER_MACHINE_REGS(); }; YAPApplTerm(YAPFunctor f, YAPTerm ts[]); - YAPApplTerm(const std::string s, std::vector ts); + YAPApplTerm(const std::string s, unsigned int arity) { mk(Yap_MkNewApplTerm(Yap_MkFunctor(Yap_LookupAtom(s.c_str()), arity), arity)); }; + YAPApplTerm(const std::string s, std::vector ts); YAPApplTerm(YAPFunctor f); inline Functor functor() { return FunctorOfTerm(gt()); } inline YAPFunctor getFunctor() { return YAPFunctor(FunctorOfTerm(gt())); } - Term getArg(arity_t i) { - BACKUP_MACHINE_REGS(); - Term t0 = gt(); - Term tf; - tf = ArgOfTerm(i, t0); - RECOVER_MACHINE_REGS(); - return tf; - }; - virtual bool isVar() { return false; } /// type check for unbound + Term getArg(arity_t i) { + BACKUP_MACHINE_REGS(); + Term t0 = gt(); + Term tf; + tf = ArgOfTerm(i, t0); + RECOVER_MACHINE_REGS(); + return tf; + }; + void putArg(int i, YAPTerm t) { + BACKUP_MACHINE_REGS(); + Term t0 = gt(); + RepAppl(t0)[i] = t.term(); + RECOVER_MACHINE_REGS(); + }; + virtual bool isVar() { return false; } /// type check for unbound virtual bool isAtom() { return false; } /// type check for atom virtual bool isInteger() { return false; } /// type check for integer virtual bool isFloat() { return false; } /// type check for floating-point diff --git a/H/Yap.h b/H/Yap.h index 630dd4b26..aa55fc997 100755 --- a/H/Yap.h +++ b/H/Yap.h @@ -263,6 +263,7 @@ extern size_t Yap_page_size; #define M1 ((CELL)(1024 * 1024)) #define M2 ((CELL)(2048 * 1024)) +typedef YAP_UInt CELL; #if ALIGN_LONGS typedef CELL SFLAGS; #else 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..5a5cd0231 100644 --- a/packages/myddas/myddas.h +++ b/packages/myddas/myddas.h @@ -15,6 +15,7 @@ typedef struct myddas_global *MYDDAS_GLOBAL; #include "myddas_util.h" + #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..3808de728 100644 --- a/packages/myddas/myddas_shared.c +++ b/packages/myddas/myddas_shared.c @@ -680,26 +680,16 @@ void Yap_MYDDAS_delete_all_myddas_structs(void) { void init_myddas(void) { CACHE_REGS if (myddas_initialised) - return; + 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/myddas/pl/CMakeLists.txt b/packages/myddas/pl/CMakeLists.txt index 7990e261e..7438710ff 100644 --- a/packages/myddas/pl/CMakeLists.txt +++ b/packages/myddas/pl/CMakeLists.txt @@ -72,6 +72,7 @@ foreach (driver ${MYDDAS_DBMS}) cpp_driver(MYDDAS_YAP ${driver} myddas_driver.ypp) endforeach () +list (APPEND MYDDAS_YAP ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/test.yap ${CMAKE_CURRENT_SOURCE_DIR}/../sqlite3/chinook.db) add_to_group(MYDDAS_YAP pl_library ) add_custom_target(plmyddas ALL DEPENDS ${MYDDAS_YAP} ) @@ -79,4 +80,3 @@ add_custom_target(plmyddas ALL DEPENDS ${MYDDAS_YAP} ) install(FILES ${MYDDAS_YAP} DESTINATION ${libpl} ) - diff --git a/packages/myddas/pl/myddas.ypp b/packages/myddas/pl/myddas.ypp index f3a04f280..84fc35943 100644 --- a/packages/myddas/pl/myddas.ypp +++ b/packages/myddas/pl/myddas.ypp @@ -243,8 +243,7 @@ db_open(odbc,Connection,ODBCEntry,User,Password) :- %% sqlite3 db_open(sqlite3,Connection,File,User,Password) :- '$error_checks'(db_open(sqlite3,Connection,File,User,Password)), - absolute_file_name(File,FullFile,[access(exist),file_errors(error),expand(true)]), - c_sqlite3_connect(FullFile,User,Password,Con), + c_sqlite3_connect(File,User,Password,Con), set_value(Connection,Con). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% diff --git a/packages/myddas/sqlite3/CMakeLists.txt b/packages/myddas/sqlite3/CMakeLists.txt index 3f3877072..7dc998cde 100644 --- a/packages/myddas/sqlite3/CMakeLists.txt +++ b/packages/myddas/sqlite3/CMakeLists.txt @@ -53,3 +53,6 @@ install(TARGETS sqlite4YAP LIBRARY DESTINATION ${YAP_INSTALL_DLLDIR} ) endif() + + file (INSTALL chinook.db test.yap DESTINATION ${libpl}) + diff --git a/packages/myddas/sqlite3/myddas_sqlite3.c b/packages/myddas/sqlite3/myddas_sqlite3.c index f48b87d49..ceff03c50 100644 --- a/packages/myddas/sqlite3/myddas_sqlite3.c +++ b/packages/myddas/sqlite3/myddas_sqlite3.c @@ -77,7 +77,7 @@ static Int c_sqlite3_get_database(USES_REGS1); static Int c_sqlite3_change_database(USES_REGS1); static Int c_sqlite3_connect(USES_REGS1) { - + printf("hello darkness\n"); Term arg_file = Deref(ARG1); Term arg_db = ARG4; @@ -96,7 +96,56 @@ static Int c_sqlite3_connect(USES_REGS1) { if (new == NULL) { #ifdef DEBUG - fprintf(stderr, "ERROR: ** c_db_my_connect ** Error allocating memory\n"); + fprintf(stderr, "ERROR: ** c_db_my_connect ** Error allocating memory\n");135761 ) +03-16 17:31:30.590 25588-25588/? E/YAPDroid: 4011d 240 0 FAIL RETRY: prolog:$user_expansion(user:main, _135757:_135758 ) +03-16 17:31:30.590 25588-25588/? E/YAPDroid: 4012d 173 0 CALL: prolog:$import_expansion(user:main, _135760:_135761 ) +03-16 17:31:30.590 25588-25588/? E/YAPDroid: 4013d 239 0 CALL: prolog:$imported_predicate(main, user, _135761, _135760 ) +03-16 17:31:30.590 25588-25588/? E/YAPDroid: 4014d 255 0 CALL: prolog:$is_system_predicate(main, prolog ) +03-16 17:31:30.590 25588-25588/? E/YAPDroid: 4015d 255 0 FAIL RETRY: prolog:$imported_predicate(main, user, _135761, _135760 ) +03-16 17:31:30.590 25588-25588/? E/YAPDroid: 4016d 239 0 CALL: prolog:$undefined(main, user ) +03-16 17:31:30.590 25588-25588/? E/YAPDroid: 4017d 239 0 FAIL RETRY: prolog:$import_expansion(user:main, _135760:_135761 ) +03-16 17:31:30.590 25588-25588/? E/YAPDroid: 4018d 173 0 CALL: prolog:$meta_expansion(user:main, user, [], _1048348 ) +03-16 17:31:30.590 25588-25588/? E/YAPDroid: 4019d 238 0 CALL: prolog:$yap_strip_module(user:main, _135763, _1048327 ) +03-16 17:31:30.590 25588-25588/? E/YAPDroid: 4020d 238 0 CALL: prolog:functor(main, _135766, _135767 ) +03-16 17:31:30.590 25588-25588/? E/YAPDroid: 4021d 238 0 CALL: prolog:$meta_predicate(main, user, 0, _1048328 ) +03-16 17:31:30.590 25588-25588/? E/YAPDroid: 4022d 238 0 FAIL RETRY: prolog:$meta_expansion(user:main, user, [], _1048348 ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4023d 173 0 CALL: prolog:$yap_strip_module(user:main, _135763, _135764 ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4024d 173 0 CALL: prolog:$yap_strip_module(user:main, _135765, _135766 ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4025d 173 0 CALL: prolog:$end_goal_expansion(main, _135738, _135740, user, user, user, :-user:main ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4026d 173 0 CALL: prolog:$match_mod(main, user, user, user, _135738 ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4027d 173 0 CALL: prolog:$is_system_predicate(main, user ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4028d 173 0 TRY_OR +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4029d 216 0 CALL: prolog:==(user, user ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4030d 216 0 CALL: prolog:==(user, user ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4031d 173 0 CALL: prolog:$c_built_in(main, user, :-user:main, _1048378 ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4032d 209 0 CALL: prolog:get_value('$c_arith', true ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4033d 173 0 CALL: prolog:do_c_built_in(main, user, :-user:main, _1048378 ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4034d 220 0 CALL: prolog:$compop(main, _1048340, _1048341, _1048343 ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4035d 220 0 FAIL RETRY: prolog:do_c_built_in(main, user, :-user:main, _1048378 ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4036d 220 0 CALL: prolog:$yap_strip_module(user:main, _135770, _135771 ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4037d 220 0 CALL: prolog:$match_mod(main, user, user, user, _135740 ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4038d 220 0 CALL: prolog:$is_system_predicate(main, user ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4039d 220 0 TRY_OR +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4040d 236 0 CALL: prolog:==(user, user ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4041d 236 0 CALL: prolog:==(user, user ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4042d 220 0 CALL: prolog:$yap_strip_module(user: (:-main), _135727, _135728 ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4043d 158 0 TRY_OR +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4044d 172 0 CALL: prolog:==(158, 158 ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4045d 105 0 CALL: prolog:$yap_strip_module(user: (:-main), _1048434, _135775 ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4046d 105 0 TRY_OR +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4047d 105 0 CALL: prolog:$process_directive(main, reconsult, user, [], '$stream_position'(1342,80,1,0) ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4048d 130 0 FAIL RETRY: prolog:$process_directive(main, reconsult, user, [], '$stream_position'(1342,80,1,0) ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4049d 130 0 FAIL RETRY: prolog:$process_directive(main, reconsult, user, [], '$stream_position'(1342,80,1,0) ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4050d 130 0 CALL: prolog:$all_directives(main ) +03-16 17:31:30.591 25588-25588/? E/YAPDroid: 4051d 130 0 CALL: prolog:$directive(main ) +03-16 17:31:30.592 25588-25588/? E/YAPDroid: 4052d 130 0 FAIL RETRY: prolog:$process_directive(main, reconsult, user, [], '$stream_position'(1342,80,1,0) ) +03-16 17:31:30.592 25588-25588/? E/YAPDroid: 4053d 130 0 CALL: prolog:current_prolog_flag(language_mode, iso ) +03-16 17:31:30.592 25588-25588/? E/YAPDroid: 4054d 130 0 FAIL RETRY: prolog:$process_directive(main, reconsult, user, [], '$stream_position'(1342,80,1,0) ) +03-16 17:31:30.592 25588-25588/? E/YAPDroid: 4055d 130 0 CALL: prolog:$execute(user:main ) +03-16 17:31:30.592 25588-25588/? E/YAPDroid: 4056d 130 0 CALL: user:main +03-16 17:31:30.592 25588-25588/? E/YAPDroid: 4057d 130 0 CALL: user:init +03-16 17:31:30.592 25588-25588/? E/YAPDroid: 4058d 130 0 CALL: user:db_open(sqlite3, '/data/user/0/pt.up.yap.yapdroid/files/Yap/chinook.db', _1048428, _1048429 ) +03-16 17:31:30.592 25588-25588/? E/YAPDroid: 4059d 130 0 CALL: user:db_open(sqlite3, myddas, '/data/user/0/pt.up.yap.yapdr #endif return FALSE; } @@ -664,15 +713,18 @@ static void Yap_InitBackMYDDAS_SQLITE3Preds(void) { } X_API void init_sqlite3(void) { - // Yap_InitMYDDAS_SQLITE3Preds(); - // Yap_InitBackMYDDAS_SQLITE3Preds(); + Term cm = CurrentModule; + CurrentModule = PROLOG_MODULE; + Yap_InitMYDDAS_SQLITE3Preds(); + Yap_InitBackMYDDAS_SQLITE3Preds(); + CurrentModule = cm; } #if _ANDROID_ //JNIEXPORT void JNICALL lib_yap_up_pt_init_sqlite(JNIEnv *env); // JNIEXPORT void JNICALL lib_yap_up_pt_init_sqlite(JNIEnv *env) { -// init_sqlite3(); +init_sqlite3(); } #endif diff --git a/packages/myddas/sqlite3/test.yap b/packages/myddas/sqlite3/test.yap index afbcd481f..b550b970e 100644 --- a/packages/myddas/sqlite3/test.yap +++ b/packages/myddas/sqlite3/test.yap @@ -1,21 +1,18 @@ -:- [library(myddas)]. - -:- initialization(main). +:- compile(library(myddas)). main :- - setup_call_cleanup( - init, - main_ , - (trace, - close)). + init, + main_, + close. main_ :- go, fail. main_ . init :- - db_open(sqlite3, '~/Yap/Chinook/Chinook_Sqlite.sqlite', _, _), + db_open(sqlite3, '/data/user/0/pt.up.yap.yapdroid/files/Yap/chinook.db', _, _), + writeln('chinook has landed'), db_import('Artist', artist), db_import('Album', album), db_import('Track', track). @@ -25,26 +22,24 @@ init :- db_get_attributes_types(track,Ts), db_get_attributes_types(artist,As), writeln(As:Als:Ts). - go :- db_number_of_fields(album,Als), db_number_of_fields(track,Ts), db_number_of_fields(artist,As), writeln(As:Als:Ts). - go :- +go :- db_describe(album, Desc), writeln(Desc) ; db_describe(track, Desc), writeln(Desc) ; db_describe(artist, Desc), writeln(Desc). - - go :- +go :- db_show_tables(Desc), writeln(Desc). - go :- +go :- db_show_tables(table(T)), db_describe(T,tableinfo(FieldID,Type,Null,Primary,Default,'')), writeln(T:tableinfo(FieldID,Type,Null,Primary,Default,'')). - go :- +go :- go_cut0. @@ -79,3 +74,6 @@ go_cut1 :- close :- db_close. + +:- main. + 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..6e0fb4957 100644 --- a/packages/swig/android/streamer.cpp +++ b/packages/swig/android/streamer.cpp @@ -1,15 +1,21 @@ // -// Created by vsc on 7/6/17. +// Created by vsc on 7/6/17-> // -/* File : example.cxx */ +/* File : example->cxx */ #include "streamer.h" +extern "C" { + +extern void Java_pt_up_yap_streamerJNI_swig_1module_1init(void); + +} static AndroidStreamer * streamerInstance = 0; void setStreamer(AndroidStreamer* streamer) { streamerInstance = streamer; + Java_pt_up_yap_streamerJNI_swig_1module_1init(); } AndroidStreamer& getStreamer() { @@ -25,13 +31,11 @@ extern "C" { #include #include -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 +87,34 @@ 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) { + if (andstream) + return; + andstream = new VFS_t(); + + andstream->name = "android output window"; + 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_Term ts[1], args[1], goal; + ts[0] = MkAtomTerm(Yap_LookupAtom("android")); + args[0] = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("library"),1), 1, ts); + goal = Yap_MkApplTerm(Yap_MkFunctor(Yap_LookupAtom("compile"),1), 1, args); + YAP_RunGoalOnce(goal); + } + + +} \ 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..b890488a9 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(+,:)). @@ -461,3 +461,12 @@ If this hook predicate succeeds it must instantiate the _Action_ argument to th :- ensure_loaded('../pl/pathconf.yap'). :- yap_flag(user:unknown,error). + + +:- compile('../myddas'). + +:- start_low_level_trace. + +%:- db_open(sqlite3, '/asssets/Yap/chinook.db', _, _). + +:- compile('../test'). 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).