diff --git a/C/init.c b/C/init.c index c9c20ad38..7fbc7d7db 100755 --- a/C/init.c +++ b/C/init.c @@ -984,6 +984,7 @@ void Yap_InitCPredBack_(const char *Name, arity_t Arity, arity_t Extra, static void InitStdPreds(struct yap_boot_params *yapi) { + CurrentModule = PROLOG_MODULE; Yap_InitCPreds(); Yap_InitBackCPreds(); BACKUP_MACHINE_REGS(); diff --git a/C/text.c b/C/text.c index 2409307bd..88c4c2d0d 100644 --- a/C/text.c +++ b/C/text.c @@ -557,10 +557,8 @@ unsigned char *Yap_readText(seq_tv_t *inp USES_REGS) { POPRET( (char*)latin2utf8(inp)); } - if (inp->enc == ENC_ISO_UTF8) { pop_text_stack(lvl); return inp->val.c; - } } if (inp->type & YAP_STRING_WCHARS) { // printf("%S\n",inp->val.w); diff --git a/CXX/yapi.cpp b/CXX/yapi.cpp index e8ffa6272..cc2587370 100644 --- a/CXX/yapi.cpp +++ b/CXX/yapi.cpp @@ -125,6 +125,7 @@ YAPAtomTerm::YAPAtomTerm(char s[]) { // build string CACHE_REGS seq_tv_t inp, out; + inp.enc = LOCAL_encoding; inp.val.c = s; inp.type = YAP_STRING_CHARS; out.type = YAP_STRING_ATOM; @@ -142,7 +143,8 @@ YAPAtomTerm::YAPAtomTerm(char *s, size_t len) { // build string seq_tv_t inp, out; inp.val.c = s; inp.type = YAP_STRING_CHARS; - out.type = YAP_STRING_ATOM | YAP_STRING_NCHARS | YAP_STRING_TRUNC; + inp.enc = LOCAL_encoding; + out.type = YAP_STRING_ATOM | YAP_STRING_NCHARS | YAP_STRING_TRUNC; out.max = len; if (Yap_CVT_Text(&inp, &out PASS_REGS)) mk(MkAtomTerm(out.val.a)); @@ -253,15 +255,78 @@ YAPApplTerm::YAPApplTerm(YAPFunctor f, YAPTerm ts[]) { RECOVER_H(); } -YAPApplTerm::YAPApplTerm(std::string f, std::vector ts) { +YAPApplTerm::YAPApplTerm(const std::string f, std::vector ts) { + BACKUP_H(); + arity_t arity = ts.size(); + Functor ff = Yap_MkFunctor(Yap_LookupAtom(f.c_str()), arity); + Term o = Yap_MkNewApplTerm(ff, arity); + Term *tt = RepAppl(o) + 1; + for (arity_t i = 0; i < arity; i++) + tt[i] = ts[i]; + mk(o); + RECOVER_H(); +} + +YAPApplTerm::YAPApplTerm(const std::string f, std::vector ts) { + BACKUP_H(); + arity_t arity = ts.size(); + Functor ff = Yap_MkFunctor(Yap_LookupAtom(f.c_str()), arity); + Term o = Yap_MkNewApplTerm(ff, arity); + Term *tt = RepAppl(o) + 1; + for (arity_t i = 0; i < arity; i++) + tt[i] = ts[i].term(); + mk(o); + RECOVER_H(); +} + +YAPApplTerm::YAPApplTerm(const std::string f, YAPTerm a1) { BACKUP_H(); - arity_t arity = ts.size(); + arity_t arity = 1; Functor ff = Yap_MkFunctor(Yap_LookupAtom(f.c_str()), arity); Term o = Yap_MkNewApplTerm(ff, arity); Term *tt = RepAppl(o) + 1; - for (arity_t i = 0; i < arity; i++) - tt[i] = ts[i].term(); + tt[0] = a1.term(); mk(o); + RECOVER_H(); +} + +YAPApplTerm::YAPApplTerm(const std::string f, YAPTerm a1, YAPTerm a2) { + BACKUP_H(); + arity_t arity = 2; + Functor ff = Yap_MkFunctor(Yap_LookupAtom(f.c_str()), arity); + Term o = Yap_MkNewApplTerm(ff, arity); + Term *tt = RepAppl(o) + 1; + tt[0] = a1.term(); + tt[1] = a2.term(); + mk(o); + RECOVER_H(); +} + +YAPApplTerm::YAPApplTerm(const std::string f, YAPTerm a1, YAPTerm a2, YAPTerm a3) { + BACKUP_H(); + arity_t arity = 3; + Functor ff = Yap_MkFunctor(Yap_LookupAtom(f.c_str()), arity); + Term o = Yap_MkNewApplTerm(ff, arity); + Term *tt = RepAppl(o) + 1; + tt[0] = a1.term(); + tt[2] = a2.term(); + tt[3] = a3.term(); + mk(o); + RECOVER_H(); +} + +YAPApplTerm::YAPApplTerm(const std::string f, YAPTerm a1, YAPTerm a2, YAPTerm a3, YAPTerm a4) { + BACKUP_H(); + arity_t arity = 4; + Functor ff = Yap_MkFunctor(Yap_LookupAtom(f.c_str()), arity); + Term o = Yap_MkNewApplTerm(ff, arity); + Term *tt = RepAppl(o) + 1; + tt[0] = a1.term(); + tt[2] = a2.term(); + tt[3] = a3.term(); + tt[4] = a4.term(); + mk(o); + RECOVER_H(); } YAPApplTerm::YAPApplTerm(YAPFunctor f) : YAPTerm() { @@ -525,7 +590,7 @@ bool YAPEngine::mgoal(Term t, Term tmod, bool release) { #endif CACHE_REGS BACKUP_MACHINE_REGS(); - Term *ts = nullptr; + Term *ts = nullptr; q.CurSlot = Yap_StartSlots(); q.p = P; q.cp = CP; diff --git a/CXX/yapt.hh b/CXX/yapt.hh index c34ebb18b..c7086702f 100644 --- a/CXX/yapt.hh +++ b/CXX/yapt.hh @@ -295,8 +295,8 @@ class X_API YAPApplTerm : public YAPTerm { friend class YAPTerm; public: - YAPApplTerm(Term t0) { mk(t0); } - YAPApplTerm(Functor f, Term ts[]) { +YAPApplTerm(Term t0) { mk(t0); } +YAPApplTerm(Functor f, Term ts[]) { BACKUP_MACHINE_REGS(); Term t0 = Yap_MkApplTerm(f, f->ArityOfFE, ts); mk(t0); @@ -307,12 +307,17 @@ public: mk(Yap_MkNewApplTerm(Yap_MkFunctor(Yap_LookupAtom(s.c_str()), arity), arity)); }; - YAPApplTerm(const std::string s, std::vector ts); + YAPApplTerm(const std::string s, std::vector ts); + YAPApplTerm(const std::string s, std::vector ts); YAPApplTerm(YAPFunctor f); inline Functor functor() { return FunctorOfTerm(gt()); } inline YAPFunctor getFunctor() { return YAPFunctor(FunctorOfTerm(gt())); } + YAPApplTerm(const std::string f, YAPTerm a1); + YAPApplTerm(const std::string f, YAPTerm a1, YAPTerm a2); + YAPApplTerm(const std::string f, YAPTerm a1, YAPTerm a2, YAPTerm a3); + YAPApplTerm(const std::string f, YAPTerm a1, YAPTerm a2, YAPTerm a3, YAPTerm a4); - Term getArg(arity_t i) { + Term getArg(arity_t i) { BACKUP_MACHINE_REGS(); Term t0 = gt(); Term tf; diff --git a/mkdocs/mkdocs.yml b/mkdocs/mkdocs.yml index 5ba1e8850..7be6ab53e 100644 --- a/mkdocs/mkdocs.yml +++ b/mkdocs/mkdocs.yml @@ -1,7 +1,11 @@ site_name: 'YAP' theme: 'readthedocs' markdown_extensions: -use_directory_urls: false + - smarty + - toc: + permalink: True + - sane_lists + use_directory_urls: false plugins: - search - awesome-pages: diff --git a/os/readterm.c b/os/readterm.c index 4eac3b162..1fdad1a7f 100644 --- a/os/readterm.c +++ b/os/readterm.c @@ -835,11 +835,6 @@ static parser_state_t initParser(Term opts, FEnv *fe, REnv *re, int inp_stream, LOCAL_ErrorMessage = NULL; fe->old_TR = TR; LOCAL_Error_TYPE = YAP_NO_ERROR; - __android_log_print(ANDROID_LOG_INFO, "YAPDroid ", " open %s, %d", - CurrentModule == 0 - ? "prolog" - : RepAtom(AtomOfTerm(CurrentModule))->StrOfAE, - inp_stream); LOCAL_SourceFileName = GLOBAL_Stream[inp_stream].name; LOCAL_eot_before_eof = false; fe->tpos = StreamPosition(inp_stream); diff --git a/os/streams.c b/os/streams.c index 8e5baa2bc..f91cb572b 100644 --- a/os/streams.c +++ b/os/streams.c @@ -1551,11 +1551,7 @@ FILE *Yap_FileDescriptorFromStream(Term t) { return rc; } -void - -Yap_InitBackIO ( - - void) +void Yap_InitBackIO(void) { Yap_InitCPredBack("stream_property", 2, 2, stream_property, cont_stream_property, SafePredFlag | SyncPredFlag); diff --git a/packages/myddas/myddas_shared.c b/packages/myddas/myddas_shared.c index 9674a8571..e150165e3 100644 --- a/packages/myddas/myddas_shared.c +++ b/packages/myddas/myddas_shared.c @@ -15,12 +15,15 @@ * * *************************************************************************/ #include "Yap.h" -#ifdef USE_MYDDAS #include "Yatom.h" -#include "cut_c.h" -#include "myddas.h" #include + + +#ifdef USE_MYDDAS + +#include "myddas.h" + #ifdef MYDDAS_STATS #include "myddas_statistics.h" #endif @@ -678,30 +681,17 @@ void Yap_MYDDAS_delete_all_myddas_structs(void) { #endif } +#endif + void init_myddas(void) { CACHE_REGS + if (myddas_initialised) + { + return; + } +#if USE_MYDDAS Term cm=CurrentModule; CurrentModule = USER_MODULE; - if (myddas_initialised) - return; -#ifdef __ANDROID__ - init_sqlite3(); - #endif -#if defined MYDDAS_ODBC - Yap_InitBackMYDDAS_ODBCPreds(); -#endif -#endif -#if defined MYDDAS_ODBC - Yap_InitMYDDAS_ODBCPreds(); -#endif -#if defined USE_MYDDAS - Yap_InitMYDDAS_SharedPreds(); -#endif -#if defined MYDDAS_TOP_LEVEL && \ - defined MYDDAS_MYSQL // && defined HAVE_LIBREADLINE - Yap_InitMYDDAS_TopLevelPreds(); -#endif -#if USE_MYDDAS #define stringify(X) _stringify(X) #define _stringify(X) #X Yap_REGS.MYDDAS_GLOBAL_POINTER = NULL; @@ -709,12 +699,25 @@ void init_myddas(void) { MkAtomTerm(Yap_LookupAtom(stringify(MYDDAS_VERSION)))); Yap_HaltRegisterHook((HaltHookFunc)Yap_MYDDAS_delete_all_myddas_structs, NULL); + Yap_InitMYDDAS_SharedPreds(); + Yap_InitBackMYDDAS_SharedPreds(); #undef stringify #undef _stringify Yap_MYDDAS_delete_all_myddas_structs(); +#if defined MYDDAS_ODBC + Yap_InitBackMYDDAS_ODBCPreds(); + Yap_InitMYDDAS_ODBCPreds(); +#endif +#if defined MYDDAS_TOP_LEVEL && \ + defined MYDDAS_MYSQL // && defined HAVE_LIBREADLINE + Yap_InitMYDDAS_TopLevelPreds(); #endif c_db_initialize_myddas(PASS_REGS1); - myddas_initialised = TRUE; +#ifdef __ANDROID__ + init_sqlite3(); +#endif +#endif + myddas_initialised = true; CurrentModule = cm; } diff --git a/packages/myddas/pl/myddas.ypp b/packages/myddas/pl/myddas.ypp index 0cd260b4d..ddc20edd7 100644 --- a/packages/myddas/pl/myddas.ypp +++ b/packages/myddas/pl/myddas.ypp @@ -22,6 +22,7 @@ #ifdef DEBUG :- yap_flag(single_var_warnings,on). +:- yap_flag(write_strings,on). #endif #define SWITCH(Contype, G) \ @@ -181,7 +182,7 @@ member/2 ]). -:- set(verbose,silent). +:- set_prolog_flag(verbose,silent). @@ -230,108 +231,108 @@ db_open(postgres,Connection,Host/Db/Port,User,Password) :- integer(Port),!, db_open(postgres,Connection,Host/Db/Port/_,User,Password). % Var to be NULL, the default socket db_open(postgres,Connection,Host/Db/Socket,User,Password) :- !, - db_open(postgres,Connection,Host/Db/0/Socket,User,Password). % 0 is default port + db_open(postgres,Connection,Host/Db/0/Socket,User,Password). % 0 is default port db_open(postgres,Connection,Host/Db,User,Password) :- - db_open(postgres,Connection,Host/Db/0/_,User,Password). % 0 is default port and Var to be NULL, the default socpket + db_open(postgres,Connection,Host/Db/0/_,User,Password). % 0 is default port and Var to be NULL, the default socpket #endif #ifdef MYDDAS_ODBC db_open(odbc,Connection,ODBCEntry,User,Password) :- - '$error_checks'(db_open(odbc,Connection,ODBCEntry,User,Password)), - c_odbc_connect(ODBCEntry,User,Password,Con), - set_value(Connection,Con). + '$error_checks'(db_open(odbc,Connection,ODBCEntry,User,Password)), + c_odbc_connect(ODBCEntry,User,Password,Con), + set_value(Connection,Con). #endif %% sqlite3 db_open(sqlite3,Connection,File,User,Password) :- - '$error_checks'(db_open(sqlite3,Connection,File,User,Password)), - c_sqlite3_connect(File,User,Password,Con), - set_value(Connection,Con). + '$error_checks'(db_open(sqlite3,Connection,File,User,Password)), + c_sqlite3_connect(File,User,Password,Con), + set_value(Connection,Con). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - %% db_close/1 - %% db_close/0 - % - % close a connection _Con_: all its resources are returned, and all undefined - % predicates are abolished. Default is to close `myddas`. +%% db_close/1 +%% db_close/0 +% +% close a connection _Con_: all its resources are returned, and all undefined +% predicates are abolished. Default is to close `myddas`. db_close:- - db_close(myddas). + db_close(myddas). db_close(Protocol):- - '$error_checks'(db_close(Protocol)), - get_value(Protocol,Con), - c_db_connection_type(Con,ConType), - ( '$abolish_all'(Con) ; - set_value(Protocol,[]), % "deletes" atom - C_SWITCH( ConType, disconnect(Con) ) - ). + '$error_checks'(db_close(Protocol)), + get_value(Protocol,Con), + c_db_connection_type(Con,ConType), + ( '$abolish_all'(Con) ; + set_value(Protocol,[]), % "deletes" atom + C_SWITCH( ConType, disconnect(Con) ) + ). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % db_verbose/1 - % - % +% db_verbose/1 +% +% db_verbose(X):- - var(X),!, - get_value(db_verbose,X). + var(X),!, + get_value(db_verbose,X). db_verbose(N):-!, - set_value(db_verbose,N). - %default value + set_value(db_verbose,N). +%default value :- set_value(db_verbose,0). :- set_value(db_verbose_filename,myddas_queries). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % db_module/1 - % - % +% db_module/1 +% +% db_module(X):- - var(X),!, - get_value(db_module,X). + var(X),!, + get_value(db_module,X). db_module(ModuleName):- - set_value(db_module,ModuleName). - % default value + set_value(db_module,ModuleName). +% default value :- db_module(user). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % db_is_database_predicate(+,+,+) - % - % +% db_is_database_predicate(+,+,+) +% +% db_is_database_predicate(Module,PredName,Arity):- - '$error_checks'(db_is_database_predicate(PredName,Arity,Module)), - c_db_check_if_exists_pred(PredName,Arity,Module). + '$error_checks'(db_is_database_predicate(PredName,Arity,Module)), + c_db_check_if_exists_pred(PredName,Arity,Module). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% #ifdef MYDDAS_STATS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % db_stats(+,-) - % - % +% db_stats(+,-) +% +% db_stats(List):- - db_stats(myddas,List). + db_stats(myddas,List). db_stats(Protocol,List):- - '$error_checks'(db_stats(Protocol,List)), - NumberOfStats = 10, - '$make_a_list'(NumberOfStats,ListX1), - ( var(Protocol) -> - c_db_stats(0,ListX1) - ; - get_value(Protocol,Conn), - c_db_stats(Conn,ListX1) - ), - '$make_stats_list'(ListX1,List). + '$error_checks'(db_stats(Protocol,List)), + NumberOfStats = 10, + '$make_a_list'(NumberOfStats,ListX1), + ( var(Protocol) -> + c_db_stats(0,ListX1) + ; + get_value(Protocol,Conn), + c_db_stats(Conn,ListX1) + ), + '$make_stats_list'(ListX1,List). #ifdef DEBUG %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - % db_stats_time(+,-) - % Reference is C pointer (memory reference) +% db_stats_time(+,-) +% Reference is C puuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uuuuu;ointer (memory reference) % db_stats_time(Reference,Time):- '$error_checks'(db_stats_time(Reference,Time)), @@ -449,7 +450,6 @@ db_assert(Connection,PredName):- '$error_checks'(db_insert2(Connection,PredName,Code)), '$get_values_for_insert'(Code,ValuesList,RelName), '$make_atom'(['INSERT INTO `',RelName,'` VALUES '|ValuesList],SQL), - get_value(Connection,Con), c_db_connection_type(Con,ConType), '$write_or_not'(SQL), @@ -685,17 +685,18 @@ db_describe(Connection,Y,Z) :- db_datalog_show_tables :- db_datalog_show_tables(myddas). +db_show_tables :- + '$error_checks'(db_datalog_show_tables), + get_value(myddas,Con), + c_db_connection_type(Con,DBMS), + DBMS:datalog_show_tables. + db_datalog_show_tables(Connection) :- '$error_checks'(db_datalog_show_tables(Connection) ), get_value(Connection,Con), c_db_connection_type(Con,DBMS), switch( DBMS, datalog_show_tables(Connection) ). -db_datalog_show_tables :- - '$error_checks'(db_datalog_show_tables), - get_value(myddas,Con), - c_db_connection_type(Con,DBMS), - DBMS:datalog_show_tables. /** @pred db_show_tables(+,?). diff --git a/packages/myddas/pl/myddas_assert_predicates.ypp b/packages/myddas/pl/myddas_assert_predicates.ypp index ac34345f7..2def14437 100644 --- a/packages/myddas/pl/myddas_assert_predicates.ypp +++ b/packages/myddas/pl/myddas_assert_predicates.ypp @@ -230,7 +230,7 @@ db_abolish(PredName,Arity):- % db_listing:- c_db_connection(Con), - c_db_preds_conn(Con,Module,Name,Arity), + user:c_db_preds_conn(Con,Module,Name,Arity), listing(Module:Name/Arity), fail. db_listing. @@ -243,15 +243,15 @@ db_listing. % db_listing(Module:Name/Arity):-!, c_db_connection(Con), - c_db_preds_conn(Con,Module,Name,Arity), + user:c_db_preds_conn(Con,Module,Name,Arity), listing(Module:Name/Arity). db_listing(Name/Arity):-!, c_db_connection(Con), - c_db_preds_conn(Con,Module,Name,Arity), + user:c_db_preds_conn(Con,Module,Name,Arity), listing(Module:Name/Arity). db_listing(Name):- c_db_connection(Con), - c_db_preds_conn(Con,Module,Name,Arity), + user:c_db_preds_conn(Con,Module,Name,Arity), listing(Module:Name/Arity). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% @@ -260,13 +260,12 @@ db_listing(Name):- % table_arity( Con, ConType, RelationName, Arity ) :- c_db_connection_type(Con,ConType), - writeln( ConType ), % get relation arity ( ConType == mysql -> c_db_my_number_of_fields(RelationName,Con,Arity) ; ConType == postgres -> - c_postgres_number_of_fields(RelationName,Con,Arity) + c_postgres_number_of_fields(RelationName,Con,Arit) ; ConType == odbc -> c_odbc_number_of_fields(RelationName,Con,Arity) diff --git a/packages/myddas/pl/myddas_driver.ypp b/packages/myddas/pl/myddas_driver.ypp index 07db8631f..aadbadef8 100644 --- a/packages/myddas/pl/myddas_driver.ypp +++ b/packages/myddas/pl/myddas_driver.ypp @@ -28,7 +28,7 @@ #define NAME() 'YAPodbc' #define MODULE() user #define INIT() init_odbc -#elif defined( postgres ) +#elif defined( postrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrs ) #undef postgres #define DBMS(x) postgres_##x #define c_DBMS(x) c_postgres_##x @@ -101,7 +101,6 @@ DBMS(result_set)(store_result):- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % DBMS(db_datalog_describe)/2 % diff --git a/packages/myddas/sqlite3/sqlitest.yap b/packages/myddas/sqlite3/sqlitest.yap index a800ffadf..4c34fd54c 100644 --- a/packages/myddas/sqlite3/sqlitest.yap +++ b/packages/myddas/sqlite3/sqlitest.yap @@ -1,4 +1,3 @@ -:- stop_low_level_trace. :- use_module(library(lists)). @@ -14,10 +13,22 @@ main_ :- fail. main_ . +:- if( yap_flag(android,true) ). +init :- + db_open(sqlite3, '/data/user/0/pt.up.yap/files/chinook.db', _, _), + !, + writeln('chinook has landed'). + +init :- + catch(db_open(sqlite3,'chinook.db',_,_), _, fail), + % db_open(sqlite3, 'chinook.db', _, _), + writeln('chinook has landed'). +:- else. init :- db_open(sqlite3, '/data/user/0/pt.up.yap.yapdroid/files/Yap/chinook.db', _, _), % db_open(sqlite3, 'chinook.db', _, _), writeln('chinook has landed'). +:-endif. go :- writeln(('db_import')), diff --git a/packages/python/py4yap.h b/packages/python/py4yap.h index 66c733d2c..08ef95da8 100644 --- a/packages/python/py4yap.h +++ b/packages/python/py4yap.h @@ -8,6 +8,8 @@ #define PASS_REGS #define USES_REGS +#include "Yap.h" + //@{ /** @brief Prolog to Python library diff --git a/packages/python/pypreds.c b/packages/python/pypreds.c index 3053090de..52aa94297 100644 --- a/packages/python/pypreds.c +++ b/packages/python/pypreds.c @@ -591,7 +591,7 @@ static int python_import(term_t mname, term_t mod) { const char *sn, *as = NULL; Term t = Deref(ARG1), sm; if (IsApplTerm(t)) { - Functor f = FunctorOfTerm(t); + Functor f = (Functor)*RepAppl(t); if (f != FunctorAs) return false; do_as = true; diff --git a/packages/python/swig/CMakeLists.txt b/packages/python/swig/CMakeLists.txt index 307a2d379..383a2bb09 100644 --- a/packages/python/swig/CMakeLists.txt +++ b/packages/python/swig/CMakeLists.txt @@ -54,8 +54,7 @@ endif() COMMAND ${SWIG_EXECUTABLE} -c++ -python -O -py3 -module "yap" -addextern -I${CMAKE_SOURCE_DIR}/H -I${CMAKE_SOURCE_DIR}/H/generated -I${CMAKE_SOURCE_DIR}/include -I${CMAKE_SOURCE_DIR}/OPTYap -I${CMAKE_SOURCE_DIR}/os -I${CMAKE_SOURCE_DIR}/utf8proc -I.././.. -I${CMAKE_SOURCE_DIR}/CXX -I${CMAKE_SOURCE_DIR}/packages/python -outdir ${CMAKE_CURRENT_BINARY_DIR}/yap4py -I${GMP_INCLUDE_DIRS} -DX_API="" -o ${CMAKE_CURRENT_BINARY_DIR}/yap4py/yap_wrap.cxx -oh ${CMAKE_CURRENT_BINARY_DIR}/yap4py/yap_wrap.hh ${SWIG_SOURCES} - COMMAND ${PYTHON_EXECUTABLE} setup.py sdist ${bdist} - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${SWIG_SOURCES} Py4YAP YAP++ yap4py/yapi.cpp YAP4PY_PY ) @@ -70,7 +69,9 @@ endif() DEPENDS ${PYTHON_SOURCES} ) - install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m pip install ${PYTHON_USER_INSTALL} --ignore-installed . + install(CODE "execute_process( + COMMAND ${PYTHON_EXECUTABLE} setup.py sdist ${bdist} + COMMAND ${PYTHON_EXECUTABLE} -m pip install ${PYTHON_USER_INSTALL} --ignore-installed . WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})" DEPENDS Py4YAP ${CMAKE_BINARY_DIR}/${YAP_STARTUP} ${YAP_INSTALL_DLLDIR} ) diff --git a/packages/python/swig/setup.py.in b/packages/python/swig/setup.py.in index 763aad825..a37bbaeea 100644 --- a/packages/python/swig/setup.py.in +++ b/packages/python/swig/setup.py.in @@ -84,8 +84,8 @@ native_sources = ["yap4py/yap_wrap.cxx","yap4py/yapi.cpp"] extensions = [Extension('_yap', native_sources, - define_macros=[('MAJOR_VERSION', '1'), - ('MINOR_VERSION', '0'), + define_macros=[('MAJOR_VERSION', '@YAP_MAJOR_VERSION@'), + ('MINOR_VERSION', '@YAP_MINOR_VERSION@'), ('_YAP_NOT_INSTALLED_', '1'), ('YAP_PYTHON', '1'), ('PYTHONSWIG', '1'), @@ -104,7 +104,7 @@ extensions = [Extension('_yap', native_sources, '${CMAKE_SOURCE_DIR}/os', '${CMAKE_SOURCE_DIR}/utf8proc', '${CMAKE_SOURCE_DIR}/packages/python', - '../../..', + '${CMAKE_BINARY_DIR}', '${CMAKE_SOURCE_DIR}/CXX' ] )] diff --git a/packages/python/yap_kernel/CMakeLists.txt b/packages/python/yap_kernel/CMakeLists.txt index 630b141bd..369ae53ea 100644 --- a/packages/python/yap_kernel/CMakeLists.txt +++ b/packages/python/yap_kernel/CMakeLists.txt @@ -185,7 +185,6 @@ yap_ipython/sphinxext/ipython_console_highlighting.py yap_ipython/sphinxext/ipython_directive.py yap_ipython/nbformat.py yap_ipython/paths.py -yap_ipython/_version.py yap_ipython/nbconvert.py yap_ipython/qt.py yap_ipython/html.py @@ -413,23 +412,12 @@ add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/kerne DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/kernel.js ) -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/meta.js - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/misc/editors/meta.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/ - DEPENDS ${CMAKE_SOURCE_DIR}/misc/editors/meta.js - ) - add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/prolog.js COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/misc/editors/yap.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/prolog.js DEPENDS ${CMAKE_SOURCE_DIR}/misc/editors/yap.js ) -add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/mode.js - COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_SOURCE_DIR}/misc/editors/mode.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/ - DEPENDS ${CMAKE_SOURCE_DIR}/misc/editors/mode.js - ) - - foreach(f ${FILES}) add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${f} COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/${f} ${CMAKE_CURRENT_BINARY_DIR}/${f} @@ -441,13 +429,13 @@ endforeach() add_custom_target(YAP_KERNEL ALL - COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} build sdist bdist WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} - DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-32x32.png ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-64x64.png ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/kernel.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/meta.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/prolog.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/mode.js ${OUTS} YAP4PY + DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-32x32.png ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/logo-64x64.png ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/kernel.js ${CMAKE_CURRENT_BINARY_DIR}/yap_kernel/resources/prolog.js ${OUTS} YAP4PY ) install(CODE "execute_process( + COMMAND ${PYTHON_EXECUTABLE} ${SETUP_PY} build sdist bdist COMMAND ${PYTHON_EXECUTABLE} -m pip install ${PYTHON_USER_INSTALL} --ignore-installed --no-deps . COMMAND ${PYTHON_EXECUTABLE} -m yap_kernel.kernelspec ERROR_VARIABLE setupErr diff --git a/packages/swig/android/CMakeLists.txt b/packages/swig/android/CMakeLists.txt index c247bb2e3..418654c62 100644 --- a/packages/swig/android/CMakeLists.txt +++ b/packages/swig/android/CMakeLists.txt @@ -36,12 +36,12 @@ DEPENDS pllibpl ${pl_os_library} ) add_custom_command (OUTPUT ${CMAKE_SWIG_OUTPUT}/swig_streamer.cpp - COMMAND ${SWIG_EXECUTABLE} -c++ -java -package ${SWIG_MODULE_NAME} -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 + 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} -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} + 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++) diff --git a/packages/swig/yap.i b/packages/swig/yap.i index aa5a8b1ce..85b6b92cb 100644 --- a/packages/swig/yap.i +++ b/packages/swig/yap.i @@ -124,6 +124,19 @@ YAPError = _yap.YAPError %typecheck(0) YAPTerm { $1 = !PyUnicode_Check($input); } + %exception { + try { + $action + } catch (const std::out_of_range& e) { + SWIG_exception(SWIG_IndexError, e.what()); + } catch (const std::exception& e) { + SWIG_exception(SWIG_RuntimeError, e.what()); + } catch (...) { + SWIG_exception(SWIG_RuntimeError, "unknown exception"); + } + } + + #else %typemap(in) arity_t { (jlong)($input); } @@ -139,19 +152,6 @@ YAPError = _yap.YAPError // Language independent exception handler // simplified version %include - - %exception { - try { - $action - } catch (const std::out_of_range& e) { - SWIG_exception(SWIG_IndexError, e.what()); - } catch (const std::exception& e) { - SWIG_exception(SWIG_RuntimeError, e.what()); - } catch (...) { - SWIG_exception(SWIG_RuntimeError, "unknown exception"); - } - } - #endif @@ -351,8 +351,9 @@ static void }; %init %{ - PyObject * pYAPError = PyErr_NewException("_yap.YAPError", NULL, NULL); - Py_INCREF(pYAPError); - PyModule_AddObject(m, "YAPError", pYAPError); - +#ifdef SWIGYTHON + PyObject * pYAPError = PyErr_NewException("_yap.YAPError", NULL, NULL); + Py_INCREF(pYAPError); + PyModule_AddObject(m, "YAPError", pYAPError); +#endif %} diff --git a/pl/boot.yap b/pl/boot.yap index 46287f3cb..9d9ac605d 100644 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -478,4 +478,8 @@ If this hook preodicate succeeds it must instantiate the _Action_ argument to t :- ensure_loaded('../pl/pathconf.yap'). :- yap_flag(user:unknown,error). + +:- ensure_loaded('../android.yap'). + + %% @} diff --git a/pl/preds.yap b/pl/preds.yap index 8c6a21fad..127fe10ed 100644 --- a/pl/preds.yap +++ b/pl/preds.yap @@ -112,7 +112,7 @@ undefined results. */ assert_static(C) :- - '$assert'(C , assertz_static, _ ). + '$assert'(C , assertz_static, _ ). /** @pred asserta_static(: _C_) @@ -122,7 +122,7 @@ Adds clause _C_ as the first clause for a static procedure. */ asserta_static(C) :- - '$assert'(C , asserta_static, _ ). + '$assert'(C , asserta_static, _ ). /** @pred assertz_static(: _C_) @@ -142,7 +142,7 @@ static predicates, if source mode was on when they were compiled: */ assertz_static(C) :- - '$assert'(C , assertz_static, _ ). + '$assert'(C , assertz_static, _ ). /** @pred clause(+ _H_, _B_) is iso @@ -158,9 +158,9 @@ This predicate is applicable to static procedures compiled with */ clause(V0,Q) :- - '$yap_strip_module'(V0, M, V), + '$yap_strip_module'(V0, M, V), must_be_of_type( callable, V ), - '$clause'(V,M,Q,_). + '$clause'(V,M,Q,_). /** @pred clause(+ _H_, _B_,- _R_) @@ -170,9 +170,9 @@ to access the reference's value. Note that you may not use erase/1 on the reference on static procedures. */ clause(P,Q,R) :- - '$instance_module'(R,M0), !, - instance(R,T0), - ( T0 = (H :- B) -> Q = B ; H=T0, Q = true), + '$instance_module'(R,M0), !, + instance(R,T0), + ( T0 = (H :- B) -> Q = B ; H=T0, Q = true), '$yap_strip_module'(P, M, T), '$yap_strip_module'(M0:H, M1, H1), ( @@ -183,44 +183,44 @@ clause(P,Q,R) :- M1:H1 = T ). clause(V0,Q,R) :- - '$yap_strip_module'(V0, M, V), + '$yap_strip_module'(V0, M, V), must_be_of_type( callable, V ), - '$clause'(V,M,Q,R). + '$clause'(V,M,Q,R). '$clause'(P,M,Q,R) :- - '$is_exo'(P, M), !, - Q = true, - R = '$exo_clause'(M,P), - '$execute0'(P, M). + '$is_exo'(P, M), !, + Q = true, + R = '$exo_clause'(M,P), + '$execute0'(P, M). '$clause'(P,M,Q,R) :- - '$is_log_updatable'(P, M), !, - '$log_update_clause'(P,M,Q,R). + '$is_log_updatable'(P, M), !, + '$log_update_clause'(P,M,Q,R). '$clause'(P,M,Q,R) :- - '$is_source'(P, M), !, - '$static_clause'(P,M,Q,R). + '$is_source'(P, M), !, + '$static_clause'(P,M,Q,R). '$clause'(P,M,Q,R) :- - '$some_recordedp'(M:P), !, - '$recordedp'(M:P,(P:-Q),R). + '$some_recordedp'(M:P), !, + '$recordedp'(M:P,(P:-Q),R). '$clause'(P,M,Q,R) :- - \+ '$undefined'(P,M), - ( '$is_system_predicate'(P,M) -> true ; - '$number_of_clauses'(P,M,N), N > 0 ), - functor(P,Name,Arity), - '$do_error'(permission_error(access,private_procedure,Name/Arity), - clause(M:P,Q,R)). + \+ '$undefined'(P,M), + ( '$is_system_predicate'(P,M) -> true ; + '$number_of_clauses'(P,M,N), N > 0 ), + functor(P,Name,Arity), + '$do_error'(permission_error(access,private_procedure,Name/Arity), + clause(M:P,Q,R)). '$init_preds' :- - once('$do_static_clause'(_,_,_,_,_)), - fail. + once('$do_static_clause'(_,_,_,_,_)), + fail. '$init_preds' :- - once('$do_log_upd_clause0'(_,_,_,_,_,_)), - fail. + once('$do_log_upd_clause0'(_,_,_,_,_,_)), + fail. '$init_preds' :- - once('$do_log_upd_clause'(_,_,_,_,_,_)), - fail. + once('$do_log_upd_clause'(_,_,_,_,_,_)), + fail. '$init_preds' :- - once('$do_log_upd_clause_erase'(_,_,_,_,_,_)), - fail. + once('$do_log_upd_clause_erase'(_,_,_,_,_,_)), + fail. '$init_preds'. @@ -237,16 +237,16 @@ and _I_ is bound to its position. */ nth_clause(V,I,R) :- - strip_module(V, M1, P), !, - '$nth_clause'(P, M1, I, R). + strip_module(V, M1, P), !, + '$nth_clause'(P, M1, I, R). '$nth_clause'(P,M,I,R) :- - var(I), var(R), !, - '$clause'(P,M,_,R), - '$fetch_nth_clause'(P,M,I,R). + var(I), var(R), !, + '$clause'(P,M,_,R), + '$fetch_nth_clause'(P,M,I,R). '$nth_clause'(P,M,I,R) :- - '$fetch_nth_clause'(P,M,I,R). + '$fetch_nth_clause'(P,M,I,R). /** @pred abolish(+ _P_,+ _N_) @@ -256,19 +256,19 @@ including whether it is dynamic or static, multifile, or meta-predicate, will be lost. */ abolish(N0,A) :- - strip_module(N0, Mod, N), !, - '$abolish'(N,A,Mod). + strip_module(N0, Mod, N), !, + '$abolish'(N,A,Mod). '$abolish'(N,A,M) :- var(N), !, - '$do_error'(instantiation_error,abolish(M:N,A)). + '$do_error'(instantiation_error,abolish(M:N,A)). '$abolish'(N,A,M) :- var(A), !, - '$do_error'(instantiation_error,abolish(M:N,A)). + '$do_error'(instantiation_error,abolish(M:N,A)). '$abolish'(N,A,M) :- - ( recorded('$predicate_defs','$predicate_defs'(N,A,M,_),R) -> erase(R) ), - fail. + ( recorded('$predicate_defs','$predicate_defs'(N,A,M,_),R) -> erase(R) ), + fail. '$abolish'(N,A,M) :- functor(T,N,A), - ( '$is_dynamic'(T, M) -> '$abolishd'(T,M) ; - /* else */ '$abolishs'(T,M) ). + ( '$is_dynamic'(T, M) -> '$abolishd'(T,M) ; + /* else */ '$abolishs'(T,M) ). /** @pred abolish(+ _PredSpec_) is iso @@ -283,141 +283,141 @@ dynamic procedures. Under other modes it will abolish any procedures. */ abolish(X0) :- - strip_module(X0,M,X), - '$abolish'(X,M). + strip_module(X0,M,X), + '$abolish'(X,M). '$abolish'(X,M) :- - current_prolog_flag(language, sicstus), !, - '$new_abolish'(X,M). + current_prolog_flag(language, sicstus), !, + '$new_abolish'(X,M). '$abolish'(X, M) :- - '$old_abolish'(X,M). + '$old_abolish'(X,M). '$new_abolish'(V,M) :- var(V), !, - '$abolish_all'(M). + '$abolish_all_in_module'(M). '$new_abolish'(A/V,M) :- atom(A), var(V), !, - '$abolish_all_atoms'(A,M). + '$abolish_all_atoms'(A,M). '$new_abolish'(Na//Ar1, M) :- - integer(Ar1), - !, - Ar is Ar1+2, - '$new_abolish'(Na//Ar, M). + integer(Ar1), + !, + Ar is Ar1+2, + '$new_abolish'(Na//Ar, M). '$new_abolish'(Na/Ar, M) :- - functor(H, Na, Ar), - '$is_dynamic'(H, M), !, - '$abolishd'(H, M). + functor(H, Na, Ar), + '$is_dynamic'(H, M), !, + '$abolishd'(H, M). '$new_abolish'(Na/Ar, M) :- % succeed for undefined procedures. - functor(T, Na, Ar), - '$undefined'(T, M), !. + functor(T, Na, Ar), + '$undefined'(T, M), !. '$new_abolish'(Na/Ar, M) :- - '$do_error'(permission_error(modify,static_procedure,Na/Ar),abolish(M:Na/Ar)). + '$do_error'(permission_error(modify,static_procedure,Na/Ar),abolish(M:Na/Ar)). '$new_abolish'(T, M) :- - '$do_error'(type_error(predicate_indicator,T),abolish(M:T)). + '$do_error'(type_error(predicate_indicator,T),abolish(M:T)). -'$abolish_all'(M) :- +'$abolish_all_in_module'(M) :- '$current_predicate'(Na, M, S, _), functor(S, Na, Ar), - '$new_abolish'(Na/Ar, M), - fail. -'$abolish_all'(_). + '$new_abolish'(Na/Ar, M), + fail. +'$abolish_all_in_module'(_). '$abolish_all_atoms'(Na, M) :- '$current_predicate'(Na,M,S,_), functor(S, Na, Ar), - '$new_abolish'(Na/Ar, M), - fail. + '$new_abolish'(Na/Ar, M), + fail. '$abolish_all_atoms'(_,_). '$check_error_in_predicate_indicator'(V, Msg) :- - var(V), !, - '$do_error'(instantiation_error, Msg). + var(V), !, + '$do_error'(instantiation_error, Msg). '$check_error_in_predicate_indicator'(M:S, Msg) :- !, - '$check_error_in_module'(M, Msg), - '$check_error_in_predicate_indicator'(S, Msg). + '$check_error_in_module'(M, Msg), + '$check_error_in_predicate_indicator'(S, Msg). '$check_error_in_predicate_indicator'(S, Msg) :- - S \= _/_, - S \= _//_, !, - '$do_error'(type_error(predicate_indicator,S), Msg). + S \= _/_, + S \= _//_, !, + '$do_error'(type_error(predicate_indicator,S), Msg). '$check_error_in_predicate_indicator'(Na/_, Msg) :- - var(Na), !, - '$do_error'(instantiation_error, Msg). + var(Na), !, + '$do_error'(instantiation_error, Msg). '$check_error_in_predicate_indicator'(Na/_, Msg) :- - \+ atom(Na), !, - '$do_error'(type_error(atom,Na), Msg). + \+ atom(Na), !, + '$do_error'(type_error(atom,Na), Msg). '$check_error_in_predicate_indicator'(_/Ar, Msg) :- - var(Ar), !, - '$do_error'(instantiation_error, Msg). + var(Ar), !, + '$do_error'(instantiation_error, Msg). '$check_error_in_predicate_indicator'(_/Ar, Msg) :- - \+ integer(Ar), !, - '$do_error'(type_error(integer,Ar), Msg). + \+ integer(Ar), !, + '$do_error'(type_error(integer,Ar), Msg). '$check_error_in_predicate_indicator'(_/Ar, Msg) :- - Ar < 0, !, - '$do_error'(domain_error(not_less_than_zero,Ar), Msg). + Ar < 0, !, + '$do_error'(domain_error(not_less_than_zero,Ar), Msg). % not yet implemented! %'$check_error_in_predicate_indicator'(Na/Ar, Msg) :- % Ar < maxarity, !, % '$do_error'(type_error(representation_error(max_arity),Ar), Msg). '$check_error_in_module'(M, Msg) :- - var(M), !, - '$do_error'(instantiation_error, Msg). + var(M), !, + '$do_error'(instantiation_error, Msg). '$check_error_in_module'(M, Msg) :- - \+ atom(M), !, - '$do_error'(type_error(atom,M), Msg). + \+ atom(M), !, + '$do_error'(type_error(atom,M), Msg). '$old_abolish'(V,M) :- var(V), !, - ( true -> % current_prolog_flag(language, sicstus) -> - '$do_error'(instantiation_error,abolish(M:V)) - ; - '$abolish_all_old'(M) - ). + ( true -> % current_prolog_flag(language, sicstus) -> + '$do_error'(instantiation_error,abolish(M:V)) + ; + '$abolish_all_old'(M) + ). '$old_abolish'(N/A, M) :- !, - '$abolish'(N, A, M). + '$abolish'(N, A, M). '$old_abolish'(A,M) :- atom(A), !, - ( current_prolog_flag(language, iso) -> - '$do_error'(type_error(predicate_indicator,A),abolish(M:A)) - ; - '$abolish_all_atoms_old'(A,M) - ). + ( current_prolog_flag(language, iso) -> + '$do_error'(type_error(predicate_indicator,A),abolish(M:A)) + ; + '$abolish_all_atoms_old'(A,M) + ). '$old_abolish'([], _) :- !. '$old_abolish'([H|T], M) :- !, '$old_abolish'(H, M), '$old_abolish'(T, M). '$old_abolish'(T, M) :- - '$do_error'(type_error(predicate_indicator,T),abolish(M:T)). + '$do_error'(type_error(predicate_indicator,T),abolish(M:T)). '$abolish_all_old'(M) :- '$current_predicate'(Na, M, S, _), - functor( S, Na, Ar ), - '$abolish'(Na, Ar, M), - fail. + functor( S, Na, Ar ), + '$abolish'(Na, Ar, M), + fail. '$abolish_all_old'(_). '$abolish_all_atoms_old'(Na, M) :- '$current_predicate'(Na, M, S, _), - functor(S, Na, Ar), - '$abolish'(Na, Ar, M), - fail. + functor(S, Na, Ar), + '$abolish'(Na, Ar, M), + fail. '$abolish_all_atoms_old'(_,_). '$abolishs'(G, M) :- '$system_predicate'(G,M), !, - functor(G,Name,Arity), - '$do_error'(permission_error(modify,static_procedure,Name/Arity),abolish(M:G)). + functor(G,Name,Arity), + '$do_error'(permission_error(modify,static_procedure,Name/Arity),abolish(M:G)). '$abolishs'(G, Module) :- - current_prolog_flag(language, sicstus), % only do this in sicstus mode - '$undefined'(G, Module), - functor(G,Name,Arity), - print_message(warning,no_match(abolish(Module:Name/Arity))). + current_prolog_flag(language, sicstus), % only do this in sicstus mode + '$undefined'(G, Module), + functor(G,Name,Arity), + print_message(warning,no_match(abolish(Module:Name/Arity))). '$abolishs'(G, M) :- - '$is_multifile'(G,M), - functor(G,Name,Arity), - recorded('$mf','$mf_clause'(_,Name,Arity,M,_Ref),R), - erase(R), + '$is_multifile'(G,M), + functor(G,Name,Arity), + recorded('$mf','$mf_clause'(_,Name,Arity,M,_Ref),R), + erase(R), % no need erase(Ref), - fail. + fail. '$abolishs'(T, M) :- - recorded('$import','$import'(_,M,_,_,T,_,_),R), - erase(R), - fail. + recorded('$import','$import'(_,M,_,_,T,_,_),R), + erase(R), + fail. '$abolishs'(G, M) :- - '$purge_clauses'(G, M), fail. + '$purge_clauses'(G, M), fail. '$abolishs'(_, _). /** @pred stash_predicate(+ _Pred_) @@ -426,16 +426,16 @@ Make predicate _Pred_ invisible to new code, and to `current_predicate/2`, functor can be declared. **/ stash_predicate(P0) :- - strip_module(P0, M, P), - '$stash_predicate2'(P, M). + strip_module(P0, M, P), + '$stash_predicate2'(P, M). '$stash_predicate2'(V, M) :- var(V), !, - '$do_error'(instantiation_error,stash_predicate(M:V)). + '$do_error'(instantiation_error,stash_predicate(M:V)). '$stash_predicate2'(N/A, M) :- !, - functor(S,N,A), - '$stash_predicate'(S, M) . + functor(S,N,A), + '$stash_predicate'(S, M) . '$stash_predicate2'(PredDesc, M) :- - '$do_error'(type_error(predicate_indicator,PredDesc),stash_predicate(M:PredDesc)). + '$do_error'(type_error(predicate_indicator,PredDesc),stash_predicate(M:PredDesc)). /** @pred hide_predicate(+ _Pred_) Make predicate _Pred_ invisible to `current_predicate/2`, @@ -443,9 +443,9 @@ Make predicate _Pred_ invisible to `current_predicate/2`, **/ hide_predicate(P0) :- - '$yap_strip_module'(P0, M, P), - must_be_of_type(callable, M:P), - '$hide_predicate'(P, M). + '$yap_strip_module'(P0, M, P), + must_be_of_type(callable, M:P), + '$hide_predicate'(P, M). /** @pred predicate_property( _P_, _Prop_) is iso @@ -492,13 +492,13 @@ or built-in. */ predicate_property(Pred,Prop) :- ( - current_predicate(_,Pred), - '$yap_strip_module'(Pred, Mod, TruePred) + current_predicate(_,Pred), + '$yap_strip_module'(Pred, Mod, TruePred) ; '$current_predicate'(_,M,Pred,system), '$yap_strip_module'(M:Pred, Mod, TruePred) ), - + ( '$pred_exists'(TruePred, Mod) -> @@ -506,41 +506,41 @@ predicate_property(Pred,Prop) :- NPred = TruePred ; '$get_undefined_pred'(TruePred, Mod, NPred, M) - ), + ), '$predicate_property'(NPred,M,Mod,Prop). '$predicate_property'(P,M,_,built_in) :- - '$is_system_predicate'(P,M). + '$is_system_predicate'(P,M). '$predicate_property'(P,M,_,source) :- - '$predicate_flags'(P,M,F,F), - F /\ 0x00400000 =\= 0. + '$predicate_flags'(P,M,F,F), + F /\ 0x00400000 =\= 0. '$predicate_property'(P,M,_,tabled) :- - '$predicate_flags'(P,M,F,F), - F /\ 0x00000040 =\= 0. + '$predicate_flags'(P,M,F,F), + F /\ 0x00000040 =\= 0. '$predicate_property'(P,M,_,dynamic) :- - '$is_dynamic'(P,M). + '$is_dynamic'(P,M). '$predicate_property'(P,M,_,static) :- - \+ '$is_dynamic'(P,M), - \+ '$undefined'(P,M). + \+ '$is_dynamic'(P,M), + \+ '$undefined'(P,M). '$predicate_property'(P,M,_,meta_predicate(Q)) :- - functor(P,Na,Ar), - prolog:'$meta_predicate'(Na,M,Ar,Q). + functor(P,Na,Ar), + prolog:'$meta_predicate'(Na,M,Ar,Q). '$predicate_property'(P,M,_,multifile) :- - '$is_multifile'(P,M). + '$is_multifile'(P,M). '$predicate_property'(P,M,_,public) :- - '$is_public'(P,M). + '$is_public'(P,M). '$predicate_property'(P,M,_,thread_local) :- - '$is_thread_local'(P,M). + '$is_thread_local'(P,M). '$predicate_property'(P,M,M,exported) :- - functor(P,N,A), - once(recorded('$module','$module'(_TFN,M,_S,Publics,_L),_)), - lists:memberchk(N/A,Publics). + functor(P,N,A), + once(recorded('$module','$module'(_TFN,M,_S,Publics,_L),_)), + lists:memberchk(N/A,Publics). '$predicate_property'(P,M,M0,imported_from(M0)) :- M \= M0. '$predicate_property'(P,Mod,_,number_of_clauses(NCl)) :- - '$number_of_clauses'(P,Mod,NCl). + '$number_of_clauses'(P,Mod,NCl). '$predicate_property'(P,Mod,_,file(F)) :- - '$owner_file'(P,Mod,F). + '$owner_file'(P,Mod,F). /** @@ -552,22 +552,22 @@ Given predicate _P_, _NCls_ is the number of clauses for indices to those clauses (in bytes). */ predicate_statistics(V,NCls,Sz,ISz) :- var(V), !, - '$do_error'(instantiation_error,predicate_statistics(V,NCls,Sz,ISz)). + '$do_error'(instantiation_error,predicate_statistics(V,NCls,Sz,ISz)). predicate_statistics(P0,NCls,Sz,ISz) :- - strip_module(P0, M, P), - '$predicate_statistics'(P,M,NCls,Sz,ISz). + strip_module(P0, M, P), + '$predicate_statistics'(P,M,NCls,Sz,ISz). '$predicate_statistics'(M:P,_,NCls,Sz,ISz) :- !, - '$predicate_statistics'(P,M,NCls,Sz,ISz). + '$predicate_statistics'(P,M,NCls,Sz,ISz). '$predicate_statistics'(P,M,NCls,Sz,ISz) :- - '$is_log_updatable'(P, M), !, - '$lu_statistics'(P,NCls,Sz,ISz,M). + '$is_log_updatable'(P, M), !, + '$lu_statistics'(P,NCls,Sz,ISz,M). '$predicate_statistics'(P,M,_,_,_) :- - '$is_system_predicate'(P,M), !, fail. + '$is_system_predicate'(P,M), !, fail. '$predicate_statistics'(P,M,_,_,_) :- - '$undefined'(P,M), !, fail. + '$undefined'(P,M), !, fail. '$predicate_statistics'(P,M,NCls,Sz,ISz) :- - '$static_pred_statistics'(P,M,NCls,Sz,ISz). + '$static_pred_statistics'(P,M,NCls,Sz,ISz). /** @pred predicate_erased_statistics( _P_, _NCls_, _Sz_, _IndexSz_) @@ -580,36 +580,36 @@ of space required to store indices to those clauses (in bytes). */ predicate_erased_statistics(P,NCls,Sz,ISz) :- var(P), !, - current_predicate(_,P), - predicate_erased_statistics(P,NCls,Sz,ISz). + current_predicate(_,P), + predicate_erased_statistics(P,NCls,Sz,ISz). predicate_erased_statistics(P0,NCls,Sz,ISz) :- - strip_module(P0,M,P), - '$predicate_erased_statistics'(M:P,NCls,Sz,_,ISz). + strip_module(P0,M,P), + '$predicate_erased_statistics'(M:P,NCls,Sz,_,ISz). /** @pred current_predicate( _A_, _P_) Defines the relation: _P_ is a currently defined predicate whose name is the atom _A_. */ current_predicate(A,T0) :- - '$yap_strip_module'(T0, M, T), + '$yap_strip_module'(T0, M, T), ( var(Mod) -> - '$all_current_modules'(M) + '$all_current_modules'(M) ; - true + true ), (nonvar(T) -> functor(T, A, _) ; true ), - ( - '$current_predicate'(A,M, T, user) + ( + '$current_predicate'(A,M, T, user) ; - (nonvar(T) + (nonvar(T) -> '$imported_predicate'(T, M, T1, M1) ; '$generate_imported_predicate'(T, M, T1, M1) ), - functor(T1, A, _), - \+ '$is_system_predicate'(T1,M1) + functor(T1, A, _), + \+ '$is_system_predicate'(T1,M1) ). /** @pred system_predicate( ?_P_ ) @@ -617,7 +617,7 @@ current_predicate(A,T0) :- Defines the relation: indicator _P_ refers to a currently defined system predicate. */ system_predicate(P0) :- - '$yap_strip_module'(P0, M0, P), + '$yap_strip_module'(P0, M0, P), ( M= M0 ; M0 \= user, M = user ; M0 \= prolog, M = prolog ), ( var(P) @@ -668,7 +668,7 @@ system_predicate(P0) :- */ system_predicate(A, P0) :- - '$yap_strip_module'(P0, M, P), + '$yap_strip_module'(P0, M, P), ( nonvar(P) -> @@ -688,35 +688,35 @@ system_predicate(A, P0) :- _Na_ is the name of the predicate, and _Ar_ its arity. */ current_predicate(F0) :- - '$yap_strip_module'(F0, M, F), - must_bind_to_type( predicate_indicator, F ), - '$c_i_predicate'( F, M ). + '$yap_strip_module'(F0, M, F), + must_bind_to_type( predicate_indicator, F ), + '$c_i_predicate'( F, M ). '$c_i_predicate'( A/N, M ) :- - !, - ( - ground(A/N) - -> - atom(A), integer(N), - functor(S, A, N), - current_predicate(A, M:S) - ; - current_predicate(A, M:S), - functor(S, A, N) - ). + !, + ( + ground(A/N) + -> + atom(A), integer(N), + functor(S, A, N), + current_predicate(A, M:S) + ; + current_predicate(A, M:S), + functor(S, A, N) + ). '$c_i_predicate'( A//N, M ) :- - ( - ground(A) - -> - atom(A), integer(N), - N2 is N+2, - functor(S, A, N2), - current_predicate(A, M:S) - ; - current_predicate(A, M:S), - functor(S, A, N2), - N is N2-2 - ). + ( + ground(A) + -> + atom(A), integer(N), + N2 is N+2, + functor(S, A, N2), + current_predicate(A, M:S) + ; + current_predicate(A, M:S), + functor(S, A, N2), + N is N2-2 + ). /** @pred current_key(? _A_,? _K_) @@ -726,17 +726,17 @@ name is the atom _A_. It can be used to generate all the keys for the internal data-base. */ current_key(A,K) :- - '$current_predicate'(A,idb,K,user). + '$current_predicate'(A,idb,K,user). % do nothing for now. '$noprofile'(_, _). '$ifunctor'(Pred,Na,Ar) :- - (Ar > 0 -> - functor(Pred, Na, Ar) - ; - Pred = Na - ). + (Ar > 0 -> + functor(Pred, Na, Ar) + ; + Pred = Na + ). /** @pred compile_predicates(: _ListOfNameArity_) @@ -752,68 +752,69 @@ of the program that is generated at runtime but does not change during the remainder of the program execution. */ compile_predicates(Ps) :- - '$current_module'(Mod), - '$compile_predicates'(Ps, Mod, compile_predicates(Ps)). + '$current_module'(Mod), + '$compile_predicates'(Ps, Mod, compile_predicates(Ps)). '$compile_predicates'(V, _, Call) :- - var(V), !, - '$do_error'(instantiation_error,Call). + var(V), !, + '$do_error'(instantiation_error,Call). '$compile_predicates'(M:Ps, _, Call) :- - '$compile_predicates'(Ps, M, Call). + '$compile_predicates'(Ps, M, Call). '$compile_predicates'([], _, _). '$compile_predicates'([P|Ps], M, Call) :- - '$compile_predicate'(P, M, Call), - '$compile_predicates'(Ps, M, Call). + '$compile_predicate'(P, M, Call), + '$compile_predicates'(Ps, M, Call). '$compile_predicate'(P, _M, Call) :- - var(P), !, - '$do_error'(instantiation_error,Call). + var(P), !, + '$do_error'(instantiation_error,Call). '$compile_predicate'(M:P, _, Call) :- - '$compile_predicate'(P, M, Call). + '$compile_predicate'(P, M, Call). '$compile_predicate'(Na/Ar, Mod, _Call) :- - functor(G, Na, Ar), - findall([G|B],clause(Mod:G,B),Cls), - abolish(Mod:Na,Ar), - '$add_all'(Cls, Mod). + functor(G, Na, Ar), + findall([G|B],clause(Mod:G,B),Cls), + abolish(Mod:Na,Ar), + '$add_all'(Cls, Mod). '$add_all'([], _). '$add_all'([[G|B]|Cls], Mod) :- - assert_static(Mod:(G:-B)), - '$add_all'(Cls, Mod). + assert_static(Mod:(G:-B)), + '$add_all'(Cls, Mod). clause_property(ClauseRef, file(FileName)) :- - ( recorded('$mf','$mf_clause'(FileName,_Name,_Arity,_Module,ClauseRef),_R) - -> true - ; - instance_property(ClauseRef, 2, FileName) ). + ( recorded('$mf','$mf_clause'(FileName,_Name,_Arity,_Module,ClauseRef),_R) + -> true + ; + instance_property(ClauseRef, 2, FileName) ). clause_property(ClauseRef, source(FileName)) :- - ( recorded('$mf','$mf_clause'(FileName,_Name,_Arity,_Module,ClauseRef),_R) - -> true - ; - instance_property(ClauseRef, 2, FileName) ). + ( recorded('$mf','$mf_clause'(FileName,_Name,_Arity,_Module,ClauseRef),_R) + -> true + ; + instance_property(ClauseRef, 2, FileName) ). clause_property(ClauseRef, line_count(LineNumber)) :- - instance_property(ClauseRef, 4, LineNumber), - LineNumber > 0. + instance_property(ClauseRef, 4, LineNumber), + LineNumber > 0. clause_property(ClauseRef, fact) :- - instance_property(ClauseRef, 3, true). + instance_property(ClauseRef, 3, true). clause_property(ClauseRef, erased) :- - instance_property(ClauseRef, 0, true). + instance_property(ClauseRef, 0, true). clause_property(ClauseRef, predicate(PredicateIndicator)) :- - instance_property(ClauseRef, 1, PredicateIndicator). + instance_property(ClauseRef, 1, PredicateIndicator). '$set_predicate_attribute'(M:N/Ar, Flag, V) :- - functor(P, N, Ar), - '$set_flag'(P, M, Flag, V). + functor(P, N, Ar), + '$set_flag'(P, M, Flag, V). %% '$set_flag'(P, M, trace, off) :- % set a predicate flag % '$set_flag'(P, M, trace, off) :- - '$predicate_flags'(P,M,F,F), + '$predicate_flags'(P,M,F,F), FN is F \/ 0x400000000, - '$predicate_flags'(P,M,F,FN). + '$predicate_flags'(P,M,F,FN). /** @} */ +