From 9be6eb9132255f41082b93424477c5a2b18d9a35 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Fri, 23 Nov 2018 00:01:55 +0000 Subject: [PATCH] small bugs --- C/cdmgr.c | 6 +- C/yap-args.c | 3 +- CXX/yapie.hh | 2 +- H/ATOMS | 1 + docs/md/LIBRARY.md | 11 - docs/md/programming.md | 17 +- library/arg.yap | 2 +- os/alias.c | 1 + os/readterm.c | 5 +- packages/cplint/cplint_yap.c | 6 +- packages/myddas/#example# | 25 -- packages/myddas/MYDDAS.md | 214 +++++++++--------- packages/myddas/example | 2 +- packages/myddas/pl/CMakeLists.txt | 2 +- packages/myddas/pl/myddas.ypp | 19 ++ .../myddas/pl/myddas_assert_predicates.ypp | 2 +- packages/myddas/pl/myddas_driver.ypp | 2 +- packages/myddas/sqlite3/CMakeLists.txt | 2 +- packages/myddas/sqlite3/sqlitest.yap | 3 +- pl/consult.yap | 2 +- pl/control.yap | 13 +- pl/debug.yap | 98 +++++--- pl/pathconf.yap | 12 +- 23 files changed, 234 insertions(+), 216 deletions(-) delete mode 100644 docs/md/LIBRARY.md delete mode 100644 packages/myddas/#example# diff --git a/C/cdmgr.c b/C/cdmgr.c index 30dc65848..3304483a8 100644 --- a/C/cdmgr.c +++ b/C/cdmgr.c @@ -1219,8 +1219,8 @@ static void add_first_dynamic(PredEntry *p, yamop *cp, int spy_flag) { ncp = NEXTOP(ncp, e); ncp->opc = Yap_opcode(_Ystop); ncp->y_u.l.l = cl->ClCode; - // if (!(p->PredFlags & MultiFileFlag) && p->src.OwnerFile == AtomNil) - // p->src.OwnerFile = Yap_ConsultingFile(PASS_REGS1); + if (!(p->PredFlags & MultiFileFlag) && p->src.OwnerFile == AtomNil) + p->src.OwnerFile = Yap_ConsultingFile(PASS_REGS1); } /* p is already locked */ @@ -2429,7 +2429,7 @@ static Int } /* @pred '$new_multifile'(+G,+Mod) - * sets the multi-file flag + * declares rgi/////// the multi-file flag * */ static Int new_multifile(USES_REGS1) { PredEntry *pe; diff --git a/C/yap-args.c b/C/yap-args.c index 6e196d16e..5c13c340f 100755 --- a/C/yap-args.c +++ b/C/yap-args.c @@ -191,13 +191,14 @@ static bool consult(const char *b_file USES_REGS) { fprintf(stderr, "[ SYNTAX ERROR: while parsing stream %s at line %ld ]\n", b_file, GLOBAL_Stream[c_stream].linecount); } else if (IsVarTerm(t) || t == TermNil) { - fprintf(stderr, "[ line: " Int_FORMAT ": term cannot be compiled ]", + fprintf(stderr, "[ line: " Int_FORMAT ": term cannot be compiled ]", GLOBAL_Stream[c_stream].linecount); } else if (IsApplTerm(t) && (FunctorOfTerm(t) == functor_query || FunctorOfTerm(t) == functor_command1)) { t = ArgOfTerm(1, t); if (IsApplTerm(t) && FunctorOfTerm(t) == functor_compile2) { consult(RepAtom(AtomOfTerm(ArgOfTerm(1, t)))->StrOfAE); + Yap_PopException(); } else { YAP_RunGoalOnce(t); } diff --git a/CXX/yapie.hh b/CXX/yapie.hh index 93554e3fa..41deb5911 100644 --- a/CXX/yapie.hh +++ b/CXX/yapie.hh @@ -29,7 +29,7 @@ class X_API YAPPPredicate; /// take information on a Prolog error: class X_API YAPError { - int swigcode; + //int swigcode; yap_error_descriptor_t *info; public: diff --git a/H/ATOMS b/H/ATOMS index 8c2ed1f44..ec470c3fa 100644 --- a/H/ATOMS +++ b/H/ATOMS @@ -106,6 +106,7 @@ A DBref F "$dbref" A DInteger F "$integer" A DebugMeta F "$debug_meta" A DebuggerInput N "debugger_input" +A DebuggerOutput N "debugger_output" A Dec10 N "dec10" A Default N "default" A DevNull N "/dev/null" diff --git a/docs/md/LIBRARY.md b/docs/md/LIBRARY.md deleted file mode 100644 index df4c683e2..000000000 --- a/docs/md/LIBRARY.md +++ /dev/null @@ -1,11 +0,0 @@ -@defgroup library YAP Prolog Library - -@{ - - the library_directory path (set by the - `LIBDIR` variable in the Makefile for YAP). Several files in the - library are originally from the public-domain Edinburgh Prolog library. - -[TOC] - -@} diff --git a/docs/md/programming.md b/docs/md/programming.md index fab7f501d..76a9d513d 100644 --- a/docs/md/programming.md +++ b/docs/md/programming.md @@ -1,23 +1,20 @@ -Programming in YAP {#YAPProgramming} -==================== +@defgroup YAPProgramming Programming in YAP -+ @ref load_files +@{ -+ @ref YAPSyntax - -+ @ref YAPCompilerSettings - -+ @ref Indexing - -+ @ref Deb_Interaction +[TOC] +@} @defgroup load_files Loading and Organizing YAP Programs + @{ We present the main predicates and directives available to load files and to control the Prolog environment. +[TOC] + @} @defgroup YAPModules The YAP Module system diff --git a/library/arg.yap b/library/arg.yap index 6f62842b7..75c30d40f 100644 --- a/library/arg.yap +++ b/library/arg.yap @@ -26,7 +26,7 @@ * * @defgroup args Term Argument Manipulation. * - * @ingroup @library + * @ingroup library * * @{ * diff --git a/os/alias.c b/os/alias.c index 6b8534bb6..b03f86fd4 100644 --- a/os/alias.c +++ b/os/alias.c @@ -50,6 +50,7 @@ static char SccsId[] = "%W% %G%"; * as `stderr`, just accessed in different ways. * + loop_stream: refers to the stream for the file or object being current consulted * + debugger_input: refers to the stream used to send debugger commands, by default `user_input`. + * + debugger_output: refers to the stream used to output debugging, by default `user_error`. * It must always be interactive. */ diff --git a/os/readterm.c b/os/readterm.c index abe03e567..f7122186d 100644 --- a/os/readterm.c +++ b/os/readterm.c @@ -196,8 +196,9 @@ static int parse_quasi_quotations(ReadData _PL_rd ARG_LD) #endif /*O_QUASIQUOTATIONS*/ #define READ_DEFS() \ - PAR("comments", list_filler, READ_COMMENTS) \ - , PAR("module", isatom, READ_MODULE), PAR("priority", nat, READ_PRIORITY), \ + PAR("comments", list_filler, READ_COMMENTS), \ + PAR("module", isatom, READ_MODULE), \ +PAR("priority", nat, READ_PRIORITY), \ PAR("output", filler, READ_OUTPUT), \ PAR("quasi_quotations", filler, READ_QUASI_QUOTATIONS), \ PAR("term_position", filler, READ_TERM_POSITION), \ diff --git a/packages/cplint/cplint_yap.c b/packages/cplint/cplint_yap.c index 23aada4b0..7ffe5ac9f 100644 --- a/packages/cplint/cplint_yap.c +++ b/packages/cplint/cplint_yap.c @@ -138,9 +138,9 @@ static YAP_Bool compute_prob(void) FILE * file; DdNode * array[1]; double prob; - char * onames[1]; + char const * onames[1]; char inames[1000][20]; - char * names[1000]; + char const * names[1000]; tablerow * nodes; arg1=YAP_ARG1; @@ -184,7 +184,7 @@ static YAP_Bool compute_prob(void) array[0]=function; onames[0]="Out"; file = open_file("cpl.dot", "w"); - Cudd_DumpDot(mgr,1,array,names,( char * const*)onames,file); + Cudd_DumpDot(mgr,1,array,names,onames,file); fclose(file); } nodes=init_table(vars.nBVar); diff --git a/packages/myddas/#example# b/packages/myddas/#example# deleted file mode 100644 index 5db1cd52f..000000000 --- a/packages/myddas/#example# +++ /dev/null @@ -1,25 +0,0 @@ - -sqlite3 side: -create table test (id integer, x integer, y integer); -.separator "," -.import /home/vsc/Yap/ILP/HH/DaysInHospital_Y3.csv test - -myddas side: -use_module(library(myddas)). -db_open(sqlite3,con,'../hh',x,x). -db_close(con). - -test 2: -use_module(library(myddas)). -assert(( -t2 :- -db_open(sqlite3,con,'../hh',x,x), -db_import(con,test,test), -test(A,B,C), -writeln(test(A,B,C)), -fail -)). -trace. -t2. - - \ No newline at end of file diff --git a/packages/myddas/MYDDAS.md b/packages/myddas/MYDDAS.md index b6084e935..9e23112c0 100644 --- a/packages/myddas/MYDDAS.md +++ b/packages/myddas/MYDDAS.md @@ -1,101 +1,23 @@ + @defgroup myddas The MYDDAS Data-base interface -@ingroup packages +@ingroup packages +@{ The MYDDAS database project was developed within a FCT project aiming at the development of a highly efficient deductive database system, based on the coupling of the MySQL relational database system with the YAP Prolog system. MYDDAS was later expanded to support the ODBC interface, postgres and sqlite3. -@defgroup Requirements_and_Installation_Guide Requirements and Installation Guide -@ingroup myddas @{ - - Next, we describe how to usen of the YAP with the MYDDAS System. The - use of this system is entirely depend of the MySQL development libraries - or the ODBC development libraries. At least one of the this development - libraries must be installed on the computer system, otherwise MYDDAS - will not compile. The MySQL development libraries from MySQL 3.23 an - above are know to work. We recommend the usage of MySQL versus ODBC, - but it is possible to have both options installed - - At the same time, without any problem. The MYDDAS system automatically - controls the two options. Currently, MYDDAS is know to compile without - problems in Linux. The usage of this system on Windows has not been - tested yet. MYDDAS must be enabled at configure time. This can be done - with the following options: - - + `--enable-myddas` - - This option will detect which development libraries are installed on the computer system, MySQL, ODBC or both, and will compile the Yap system with the support for which libraries it detects; - - + `--enable-myddas-stats` - - This option is only available in MySQL. It includes code to get - statistics from the MYDDAS system; - - - + `--enable-top-level` - - This option is only available in MySQL. It enables the option to interact with the MySQL server in - two different ways. As if we were on the MySQL Client Shell, and as if - we were using Datalog. - @} -@defgroup MYDDAS_Architecture MYDDAS Architecture -@ingroup myddas @{ - The system includes four main blocks that are put together through the - MYDDAS interface: the Yap Prolog compiler, the MySQL database system, an - ODBC level and a Prolog to SQL compiler. Current effort is put on the - MySQL interface rather than on the ODBC interface. If you want to use - the full power of the MYDDAS interface we recommend you to use a MySQL - database. Other databases, such as Oracle, PostGres or Microsoft SQL - Server, can be interfaced through the ODBC layer, but with limited - performance and features support. +@defgroup MYDDAS_ABI MYDDAS Predicates +@ingroup myddas - The main structure of the MYDDAS interface is simple. Prolog queries - involving database goals are translated to SQL using the Prolog to SQL - compiler; then the SQL expression is sent to the database system, which - returns the set of tuples satisfying the query; and finally those tuples - are made available to the Prolog engine as terms. For recursive queries - involving database goals, the YapTab tabling engine provides the - necessary support for an efficient evaluation of such queries. +[TOC] - An important aspect of the MYDDAS interface is that for the programmer - the use of predicates which are defined in database relations is - completely transparent. An example of this transparent support is the - Prolog cut operator, which has exactly the same behaviour from - predicates defined in the Prolog program source code, or from predicates - defined in database as relations. - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Name = 'John Doe', - Number = 123456789 ? - yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - Backtracking can then be used to retrieve the next row - of the relation phonebook. Records with particular field values may be - selected in the same way as in Prolog. (In particular, no mode - specification for database predicates is required). For instance: - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - ?- phonebook(Letter,'John Doe',Letter). - Letter = 'D', - Number = 123456789 ? - yes - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - generates the query - - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - SELECT A.Letter , 'John Doe' , A.Number - FROM 'phonebook' A - WHERE A.Name = 'John Doe'; - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -@} -@defgroup View_Level_Interface View Level Interface -@ingroup myddas @{ +@{ @pred db view(+,+,+). @pred db view(+,+). @@ -185,9 +107,6 @@ To know how to use db `view/3`, please refer to Draxler's Prolog to SQL Compiler Manual. -@defgroup Accessing_Tables_in_Data_Sources_Using_SQL Accessing Tables in Data Sources Using SQL - - @pred db_sql(+,+,?). @pred db_sql(+,?). @@ -209,10 +128,10 @@ ?- db_sql('SELECT * FROM phonebook',LA). LA = ['D','John Doe',123456789] ? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -@} -@defgroup Insertion_of_Rows Insertion of Rows -@ingroup myddas @{ - @pred db_assert(+,+). + + + +@pred db_assert(+,+). @pred db_assert(+). @@ -280,9 +199,6 @@ yes ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -@defgroup Types_of_Attributes Types of Attributes - - @pred db_get_attributes_types(+,+,?). otype for this predicate is the following: @@ -304,9 +220,6 @@ otype for this predicate is the following: where Hello World is the name of the relation and myddas is the connection identifier. -@defgroup Number_of_Fields Number of Fields - - @pred db_number_of_fields(+,?). @pred db_number_of_fields(+,+,?). @@ -331,8 +244,6 @@ otype for this predicate is the following: where `Hello World` is the name of the relation and `myddas` is the connection identifier. -@defgroup Describing_a_Relation Describing a Relation - @pred db_datalog_describe(+,+). @pred db_datalog_describe(+). @@ -372,7 +283,6 @@ otype for this predicate is the following: Term = tableInfo('Letter',char(1),'YES','',null(2),'') ? ; no ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -@defgroup Enumerating_Relations Enumeration Relations Describing_a_Relation Describing a Relation @pred db_datalog_show_tables(+). @@ -412,8 +322,8 @@ otype for this predicate is the following: no ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -@} -@defgroup The_MYDDAS_MySQL_Top_Level The MYDDAS MySQL Top Level @ingroup myddas @{ + + @pred db_top_level(+,+,+,+,+). @pred db_top_level(+,+,+,+). @@ -463,9 +373,7 @@ otype for this predicate is the following: yes ?- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -@} -@defgroup Other_MYDDAS_Properties Other MYDDAS Properties -@ingroup myddas @{ + @pred db_verbose(+). @@ -560,7 +468,97 @@ otype for this predicate is the following: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ You can see the available SQL Modes at the MySQL homepage at . + +@} +@defgroup MYDDAS_INSTall Requirements and Installation Guide +@ingroup myddas +@{ + + Next, we describe how to use YAP plus the MYDDAS System. MYDDAS + includes its own copy of SQLite3, a popular DBMS that is highky + portable. It can also them interface to the MySQL development + libraries, Postgres or the ODBC development libraries. At least one + of the this development libraries must be installed on the computer + system, otherwise MYDDAS will not compile. The MySQL development + libraries from MySQL 3.23 an above are know to work. We recommend + the usage of MySQL versus ODBC, but it is possible to have both + options installed + + At the same time, without any problem. The MYDDAS system automatically + controls the two options. Currently, MYDDAS is know to compile without + problems in Linux. The usage of this system on Windows has not been + tested yet. MYDDAS must be enabled at configure time. This can be done + with the following options: + + + `--enable-myddas` + + This option will detect which development libraries are installed on the computer system, MySQL, ODBC or both, and will compile the Yap system with the support for which libraries it detects; + + + `--enable-myddas-stats` + + This option is only available in MySQL. It includes code to get + statistics from the MYDDAS system; + + + + `--enable-top-level` + + This option is only available in MySQL. It enables the option to interact with the MySQL server in + two different ways. As if we were on the MySQL Client Shell, and as if + we were using Datalog. + +@} + +@defgroup myddasarch MYDDAS Architecture +@ingroup myddas + +@{ + + The system includes four main blocks that are put together through the + MYDDAS interface: the Yap Prolog compiler, the MySQL database system, an + ODBC level and a Prolog to SQL compiler. Current effort is put on the + MySQL interface rather than on the ODBC interface. If you want to use + the full power of the MYDDAS interface we recommend you to use a MySQL + database. Other databases, such as Oracle, PostGres or Microsoft SQL + Server, can be interfaced through the ODBC layer, but with limited + performance and features support. + + The main structure of the MYDDAS interface is simple. Prolog queries + involving database goals are translated to SQL using the Prolog to SQL + compiler; then the SQL expression is sent to the database system, which + returns the set of tuples satisfying the query; and finally those tuples + are made available to the Prolog engine as terms. For recursive queries + involving database goals, the YapTab tabling engine provides the + necessary support for an efficient evaluation of such queries. + + An important aspect of the MYDDAS interface is that for the programmer + the use of predicates which are defined in database relations is + completely transparent. An example of this transparent support is the + Prolog cut operator, which has exactly the same behaviour from + predicates defined in the Prolog program source code, or from predicates + defined in database as relations. - @] + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Name = 'John Doe', + Number = 123456789 ? + yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + Backtracking can then be used to retrieve the next row + of the relation phonebook. Records with particular field values may be + selected in the same way as in Prolog. (In particular, no mode + specification for database predicates is required). For instance: + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + ?- phonebook(Letter,'John Doe',Letter). + Letter = 'D', + Number = 123456789 ? + yes + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + generates the query + + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + SELECT A.Letter , 'John Doe' , A.Number + FROM 'phonebook' A + WHERE A.Name = 'John Doe'; + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + @} - diff --git a/packages/myddas/example b/packages/myddas/example index 53503fc19..ec8a00ebe 100644 --- a/packages/myddas/example +++ b/packages/myddas/example @@ -1,4 +1,4 @@ - + sqlite3 side: create table test (id integer, x integer, y integer); .separator "," diff --git a/packages/myddas/pl/CMakeLists.txt b/packages/myddas/pl/CMakeLists.txt index 24caee6aa..1ae27c3e8 100644 --- a/packages/myddas/pl/CMakeLists.txt +++ b/packages/myddas/pl/CMakeLists.txt @@ -66,7 +66,7 @@ endfunction() set(MYDDAS_DBMS sqlite3 postgres odbc) foreach (file ${MYDDAS_YPP}) - cpp_compile(MYDDAS_YAP ${file}) + cpp_compile(MYDDAS_YAP ${file}) endforeach () foreach (driver ${MYDDAS_DBMS}) cpp_driver(MYDDAS_YAP ${driver} myddas_driver.ypp) diff --git a/packages/myddas/pl/myddas.ypp b/packages/myddas/pl/myddas.ypp index ddc20edd7..d8ac3e667 100644 --- a/packages/myddas/pl/myddas.ypp +++ b/packages/myddas/pl/myddas.ypp @@ -184,7 +184,25 @@ :- set_prolog_flag(verbose,silent). +:- multifile user:file_search_path/2. +:- dynamic user:file_search_path/2. + +user:file_search_path(dataset, C) :- + library_directory(Dir), + ( current_prolog_flag(windows, true) + -> atomic_list_concat([Dir,data], ;, C) + ; + atomic_list_concat([Dir,data], :, C) + ). +user:file_search_path(dataset, '.'). + + +:- multifile user:prolog_file_type/2. + +:- dynamic user:prolog_file_type/2. + +user:prolog_file_type( db, myddas ). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % db_open/5 @@ -245,6 +263,7 @@ db_open(odbc,Connection,ODBCEntry,User,Password) :- %% sqlite3 db_open(sqlite3,Connection,File,User,Password) :- + absolute_file_name(File,DB,[extensions(db),access(write),file_type(myddas),expand(true)]), '$error_checks'(db_open(sqlite3,Connection,File,User,Password)), c_sqlite3_connect(File,User,Password,Con), set_value(Connection,Con). diff --git a/packages/myddas/pl/myddas_assert_predicates.ypp b/packages/myddas/pl/myddas_assert_predicates.ypp index 35046b740..e01ae50c9 100644 --- a/packages/myddas/pl/myddas_assert_predicates.ypp +++ b/packages/myddas/pl/myddas_assert_predicates.ypp @@ -264,7 +264,7 @@ table_arity( Con, ConType, RelationName, Arity ) :- c_db_my_number_of_fields(RelationName,Con,Arity) ; ConType == postgres -> - c_postgres_number_of_fields(RelationName,Con,Arit) + c_postgres_number_of_fields(RelationName,Con,Arity) ; 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 aadbadef8..e60a3894f 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( postrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrs ) +#elif defined( postgres ) #undef postgres #define DBMS(x) postgres_##x #define c_DBMS(x) c_postgres_##x diff --git a/packages/myddas/sqlite3/CMakeLists.txt b/packages/myddas/sqlite3/CMakeLists.txt index 123e8a22c..8c7d95462 100644 --- a/packages/myddas/sqlite3/CMakeLists.txt +++ b/packages/myddas/sqlite3/CMakeLists.txt @@ -66,7 +66,7 @@ if (WITH_SQLITE3) endif() install(FILES ${SQLITE_EXTRA} - DESTINATION ${YAP_INSTALL_DATADIR} + DESTINATION ${YAP_PLDIR}/data ) endif() diff --git a/packages/myddas/sqlite3/sqlitest.yap b/packages/myddas/sqlite3/sqlitest.yap index 131f167bd..531c48bbf 100644 --- a/packages/myddas/sqlite3/sqlitest.yap +++ b/packages/myddas/sqlite3/sqlitest.yap @@ -7,13 +7,12 @@ :- begin_tests(sqlite3). - :- if( yap_flag(android,true) ). test(open) :- db_open(sqlite3, '/data/user/0/pt.up.yap/files/chinook.db', _, _). :- else. test(open) :- - db_open(sqlite3,'chinook.db',_,_). + db_open(sqlite3,dataset('chinook'),_,_). :-endif. test(schema0, all((Tables ==[(table albums), diff --git a/pl/consult.yap b/pl/consult.yap index 26da564a2..75c70e50b 100644 --- a/pl/consult.yap +++ b/pl/consult.yap @@ -930,7 +930,7 @@ nb_setval('$if_level',0). % '$do_startup_reconsult'(_X) :- '$init_win_graphics', - fail.../ + fail. '$do_startup_reconsult'(X) :- catch(load_files(user:X, [silent(true)]), Error, '$LoopError'(Error, consult)), !, diff --git a/pl/control.yap b/pl/control.yap index ae0baa865..1945e8591 100644 --- a/pl/control.yap +++ b/pl/control.yap @@ -471,14 +471,13 @@ b_getval(GlobalVariable, Val) :- it saves the importante data about current streams and debugger state */ -'$debug_state'(state(Trace, Debug, State, SPY_GN, GList, GDList)) :- +'$debug_state'(state(Trace, Debug, State, SPY_GN, GList)) :- '$init_debugger', nb_getval('$trace',Trace), nb_getval('$debug_state',State), current_prolog_flag(debug, Debug), nb_getval('$spy_gn',SPY_GN), - b_getval('$spy_glist',GList), - b_getval('$spy_depth',GDList). + b_getval('$spy_glist',GList). '$debug_stop' :- @@ -486,15 +485,13 @@ b_getval(GlobalVariable, Val) :- b_setval('$trace',off), set_prolog_flag(debug, false), b_setval('$spy_glist',[]), - b_setval('$spy_gdlist',[]), '$disable_debugging'. -'$debug_restart'(state(Trace, Debug, State, SPY_GN, GList, GDList)) :- +'$debug_restart'(state(Trace, Debug, State, SPY_GN, GList)) :- b_setval('$spy_glist',GList), - b_setval('$spy_gdlist',GDList), b_setval('$spy_gn',SPY_GN), set_prolog_flag(debug, Debug), - nb_setval('$debug_state',State), + nb_setval('$debug_state',State), b_setval('$trace',Trace), '$enable_debugging'. @@ -517,7 +514,7 @@ debugging. break :- '$debug_state'(DState), '$debug_start', - '$break'( true ), + '$break'( true ), current_output(OutStream), current_input(InpStream), current_prolog_flag(break_level, BL ), NBL is BL+1, diff --git a/pl/debug.yap b/pl/debug.yap index 8a3f9e58c..5a8575fb9 100644 --- a/pl/debug.yap +++ b/pl/debug.yap @@ -141,7 +141,7 @@ not kept; useful when leap becomes too slow. same as k -+ `s` - skip + `s` - skip YAP will continue execution without showing any messages until returning to the current activation. Spy-points will be ignored in this @@ -300,14 +300,17 @@ be lost. */ '$trace'(Mod:G) :- '$stop_creeping'(_), - ( prolog_flag(debug, false) ; '__NB_getval__'('$debug_status',state(zip,_Border,_Spy), fail) ), + ( prolog_flag(debug, false) ; + '__NB_getval__'('$debug_status',state(zip,_Border,Spy),fail), + ( Spy == ignore ; \+ '$pred_being_spied'(G, Mod) ) + ), !, '$execute_nonstop'(G,Mod). '$trace'(Mod:G) :- '$$save_by'(CP), '$trace_query'(G, Mod, CP, G, EG), gated_call( - '$debugger_input', + '$debugger_io', EG, E, '$continue_debugging'(E) @@ -366,7 +369,7 @@ be lost. '$trace'(Mod:NG). /** - * @pred debugger_input. + * @pred debugger_io. * * set up the stream used for debugging, * - must be interactive. @@ -374,6 +377,10 @@ be lost. * user_input is bound to a file. * */ +'$debugger_io' :- + '$debugger_input', + '$debugger_output'. + '$debugger_input' :- stream_property(_,alias(debugger_input)), !. @@ -390,6 +397,22 @@ be lost. current_prolog_flag(windows, true ), !, open('CONIN$', read, _S, [alias(debugger_input),bom(false)]). +'$debugger_output' :- + stream_property(_,alias(debugger_output)), + !. +'$debugger_output' :- + S = user_error, + stream_property(S,tty(true)), + % stream_property(S,output), + !, + set_stream(S,alias(debugger_output)). +'$debugger_output' :- + current_prolog_flag(unix, true ), !, + open('/dev/tty', write, _S, [alias(debugger_output)]). +'$debugger_output' :- + current_prolog_flag(windows, true ), !, + open('CONOUT$', write, _S, [alias(debugger_output)]). + '$trace_meta_call'( G, M, CP ) :- '$trace_query'(G, M, CP, G, EG ), @@ -528,11 +551,13 @@ be lost. '$id_goal'(L) :- var(L), + !, '__NB_getval__'('$spy_gn',L,fail), /* bump it */ L1 is L+1, /* and save it globaly */ '__NB_setval__'('$spy_gn',L1). +'$id_goal'(_L). /** * @pred '$enter_trace'(+L, 0:G, +Module, +Info) @@ -602,7 +627,7 @@ be lost. '$stop_creeping'(_) , current_prolog_flag(debug, true), '__NB_getval__'('$debug_status',state(Skip,Border,_), fail), - ( Skip == creep -> true; '$id_goal'(GoalNumber) ; GoalNumber =< Border), + ( Skip == creep -> true; '$id_goal'(GoalNumber), GoalNumber =< Border), !, '__NB_setval__'('$debug_status', state(creep, 0, stop)), '$trace_port_'(Port, GoalNumber, G, Module, Info). @@ -700,9 +725,9 @@ be lost. ( '$unleashed'(P) -> '$action'('\n',P,L,G,Module,Info), - put_code(user_error, 10) + put_code(debugger_output, 10) ; - write(user_error,' ? '), + write(debugger_output,' ? '), '$clear_input'(debugger_input), get_char(debugger_input,C), '$action'(C,P,L,G,Module,_Info) @@ -725,8 +750,8 @@ be lost. ; GW = G ), - format(user_error,'~a~a~a (~d) ~q:',[Det,CSPY,SLL,L,P0]), - '$debugger_write'(user_error,GW). + format(debugger_output,'~a~a~a (~d) ~q:',[Det,CSPY,SLL,L,P0]), + '$debugger_write'(debugger_output,GW). '$unleashed'(call) :- get_value('$leash',L), L /\ 2'1000 =:= 0. %' '$unleashed'(exit) :- get_value('$leash',L), L /\ 2'0100 =:= 0. %' @@ -817,17 +842,20 @@ be lost. ), skip( debugger_input, 10), fail. -'$action'(l,_,_CallNumber,_,_,_) :- !, % 'l leap - skip( debugger_input, 10), - '__NB_setval__'('$debug_status', state(leap, 0, stop)). -'$action'(z,_,_CallNumber,_,_,_H) :- !, % 'z zip, fast leap - skip( debugger_input, 10), % 'z - '__NB_setval__'('$debug_status', state(zip, 0, stop)). +'$action'(l,_,CallNumber,_,_,_) :- !, % 'l leap + '$scan_number'(ScanNumber), + ( ScanNumber == 0 -> Goal = CallNumber ; Goal = ScanNumber ), + '__NB_setval__'('$debug_status', state(leap, Goal, stop)). +'$action'(z,_,CallNumber,_,_,_H) :- !, % 'z zip, fast leap + '$scan_number'(ScanNumber), + ( ScanNumber == 0 -> Goal = CallNumber ; Goal = ScanNumber ), + '__NB_setval__'('$debug_status', state(zip, Goal, stop)). % skip first call (for current goal), % stop next time. '$action'(k,_,CallNumber,_,_,_) :- !, % 'k zip, fast leap - skip( debugger_input, 10), % ' - '__NB_setval__'('$debug_status', state(zip, CallNumber, ignore)). + '$scan_number'(ScanNumber), + ( ScanNumber == 0 -> Goal = CallNumber ; Goal = ScanNumber ), + '__NB_setval__'('$debug_status', state(zip, Goal, ignore)). % skip first call (for current goal), % stop next time. '$action'(n,_,_,_,_,_) :- !, % 'n nodebug @@ -835,34 +863,36 @@ be lost. % tell debugger never to stop. '__NB_setval__'('$debug_status', state(zip, 0, ignore)), nodebug. -'$action'(r,_,CallNumber,_,_,_) :- !, % 'r retry - '$scan_number'(ScanNumber), % ' - % set_prolog_flag(debug, true), +'$action'(r,_,CallNumber,_,_,_) :- !, % r retry + '$scan_number'(ScanNumber), ( ScanNumber == 0 -> Goal = CallNumber ; Goal = ScanNumber ), throw(error(event(redo),Goal)). '$action'(s,P,CallNumber,_,_,_) :- !, % 's skip - skip( debugger_input, 10), % ' + '$scan_number'(ScanNumber), + ( ScanNumber == 0 -> Goal = CallNumber ; Goal = ScanNumber ), ( (P=call; P=redo) -> - '__NB_setval__'('$debug_status', state(leap, CallNumber, ignore) ) ; + '__NB_setval__'('$debug_status', state(leap, Goal, ignore) ) ; '$ilgl'(s) % ' ). '$action'(t,P,CallNumber,_,_,_) :- !, % 't fast skip - skip( debugger_input, 10), % ' + '$scan_number'(ScanNumber), + ( ScanNumber == 0 -> Goal = CallNumber ; Goal = ScanNumber ), ( (P=call; P=redo) -> - '__NB_setval__'('$debug_status', state(zip, CallNumber, ignore)) ; + '__NB_setval__'('$debug_status', state(zip, Goal, ignore)) ; '$ilgl'(t) % ' ). '$action'(q,P,CallNumber,_,_,_) :- !, % 'qst skip - skip( debugger_input, 10), % ' + '$scan_number'(ScanNumber), + ( ScanNumber == 0 -> Goal = CallNumber ; Goal = ScanNumber ), ( (P=call; P=redo) -> - '__NB_setval__'('$debug_status', state(leap, CallNumber, stop)) ; + '__NB_setval__'('$debug_status', state(leap, Goal, stop)) ; '$ilgl'(t) % ' ). -'$action'(+,_,_,G,M,_) :- !, % '+ spy this +'$action'(+,_,_,G,M,_) :- !, %% spy this functor(G,F,N), spy(M:(F/N)), - skip( debugger_input, 10), % ' + skip( debugger_input, 10), fail. -'$action'(-,_,_,G,M,_) :- !, % '- nospy this +'$action'(-,_,_,G,M,_) :- !, %% nospy this functor(G,F,N), nospy(M:(F/N)), skip( debugger_input, 10), % ' fail. @@ -935,12 +965,20 @@ be lost. fail. '$scan_number'(Nb) :- - readutil:read_line_to_codes( debugger_input, S), + findall(C, '$get_deb_code'(C), S), S = [_|_], !, number_codes(Nb,S). '$scan_number'(0). +'$get_deb_code'(C) :- + repeat, + get_code( debugger_input, C), + ( C == 10 -> !, fail ; + C == -1 -> !, fail ; + true + ). + '$print_deb_sterm'(G) :- '$get_sterm_list'(L), !, '$deb_get_sterm_in_g'(L,G,A), diff --git a/pl/pathconf.yap b/pl/pathconf.yap index 70d964795..3ee2de25e 100644 --- a/pl/pathconf.yap +++ b/pl/pathconf.yap @@ -27,7 +27,7 @@ This directory is initialized by a rule that calls the system predicate system_library/1. */ :- multifile library_directory/1. - +:- discontiguous library_directory/1. :- dynamic library_directory/1. %% Specifies the set of directories where % one can find Prolog libraries. @@ -55,7 +55,7 @@ library_directory( Dir ) :- library_directories/2. */ :- dynamic commons_directory/1. - +:- discontiguous commons_directory/1. :- multifile commons_directory/1. @@ -72,7 +72,7 @@ commons_directory( Path ):- */ :- multifile foreign_directory/1. - +:- discontiguous foreign_directory/1. :- dynamic foreign_directory/1. %foreign_directory( Path ):- @@ -134,7 +134,7 @@ prolog_file_type(A, executable) :- _DIRECTORY_ must be atoms. The predicate may generate multiple solutions. The predicate is originally defined as follows: -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~prolog +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~pl file_search_path(library, Dir) :- library_directory(Dir). file_search_path(commons, Dir) :- @@ -149,6 +149,8 @@ file_search_path(foreign, Dir) :- foreign_directory(Dir). file_search_path(executable, Dir) :- foreign_directory(Dir). +file_search_path(executable, Dir) :- + foreign_directory(Dir). file_search_path(path, C) :- ( getenv('PATH', A), ( current_prolog_flag(windows, true) @@ -168,7 +170,7 @@ file_search_path(path, C) :- :- multifile file_search_path/2. :- dynamic file_search_path/2. - +:- discontiguous file_search_path/2. file_search_path(library, Dir) :- library_directory(Dir).