diff --git a/CMakeLists.txt b/CMakeLists.txt index a558db79b..2e62ef230 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -767,6 +767,8 @@ option(WITH_DOCS "generate YAP docs" OFF) IF (WITH_DOCS) +get_target_property(YAP_SOURCES libYap SOURCES) + add_subDIRECTORY(docs) ENDIF (WITH_DOCS) diff --git a/docs/CMakeLists.txt b/docs/CMakeLists.txt index 6e54b2309..d7187670d 100644 --- a/docs/CMakeLists.txt +++ b/docs/CMakeLists.txt @@ -26,8 +26,7 @@ SET( EXT ${DOCS_SOURCE_DIR}/custom/theme.css ${DOCS_SOURCE_DIR}/custom/yap.css ) - - + foreach(i ${CMAKE_HTML_EXTRA_}) string(APPEND CMAKE_HTML_EXTRA ${i} " ") endforeach(i ${CMAKE_HTML_EXTRA_}) @@ -88,10 +87,6 @@ endforeach(i ${DOCS_EXCLUDE_}) set(doxyfile_in ${CMAKE_SOURCE_DIR}/docs/Doxyfile.in) - - - - add_subdirectory(../packages/raptor/doc ${CMAKE_BINARY_DIR}/packages/raptor/doc) SET(DOC_INPUT_FILES_ diff --git a/library/arg.yap b/library/arg.yap index 20861d0db..6f62842b7 100644 --- a/library/arg.yap +++ b/library/arg.yap @@ -22,30 +22,32 @@ /** -* - -@defgroup args Term Argument Manipulation. - -@ingroup @library - -@{ - -Extends arg/3 by including backtracking through arguments and access -to sub-arguments, - - - arg0/3 - - args/3 - - args0/3 - - genarg/3 - - genarg0/3 - - path_arg/3 - - -It is based on the Quintus Prolog arg library. Except for project, all -predicates use the arg/3 argument pattern. -This file has been included in the YAP library by Vitor Santos Costa, 2008. No error checking is actuallly performed within the package: this left to the C-code thaat implements arg``/3 and -genarg/3. -*/ + * + * + * @defgroup args Term Argument Manipulation. + * + * @ingroup @library + * + * @{ + * + *This library extends arg/3 by supporting backtracking through + *arguments and access to sub-arguments, + * + * - arg0/3 + * - args/3 + * - args0/3 + * - genarg/3 + * - genarg0/3 + * - path_arg/3 + * + * + *It is based on the Quintus Prolog public domain library. Except for + *project, all predicates use the arg/3 argument pattern. This file has + *been included in the YAP library by Vitor Santos Costa, 2008. + * + * No error checking is actuallly performed within the package: this + *left to the C-code that implements arg/3 and genarg/3. + */ /** * @pred arg0( +_Index_, +_Term_ , -_Arg_ ) diff --git a/library/system.yap b/library/system.yap index 8f1640711..3cbdcfa34 100644 --- a/library/system.yap +++ b/library/system.yap @@ -20,8 +20,6 @@ * @author VITOR SANTOS COSTA * @date Wed Nov 18 01:23:45 2015 * - * @brief interaction with the OS, be it Unix, Linux, or Windows. - * * */ @@ -33,6 +31,7 @@ delete_file/1, delete_file/2, directory_files/2, + directory_map/2, environ/2, exec/3, file_exists/2, @@ -61,7 +60,11 @@ working_directory/2 ]). -/** @defgroup operating_system_support, Operating System Functionality + + +/** @defgroup operating_system_support Operating System Functionality + * @brief Portable Interaction with the OS, be it Unix, Linux, OSX, or Windows. + * @ingroup library @{ @@ -74,13 +77,6 @@ are available through the `use_module(library(system))` command. */ -/** @pred file_exists(+ _File_) - - -The atom _File_ corresponds to an existing file. - - -*/ /** @pred file_property(+ _File_,? _Property_) @@ -212,13 +208,6 @@ completes. YAP uses `/bin/sh` in Unix systems and `COMSPEC` in WIN32. -*/ -/** @pred system(+ _Command_,- _Res_) - -Interface to `system`: execute command _Command_ and unify - _Res_ with the result. - - */ /** @pred tmp_file(+_Base_, - _File_) @@ -236,21 +225,6 @@ temporary files. Interface with _tmpnam_: obtain a new, unique file name _File_. -*/ -/** @pred working_directory(- _Old_,+ _New_) - -/** @pred working_directory(- _CurDir_,? _NextDir_) - - -Fetch the current directory at _CurDir_. If _NextDir_ is bound -to an atom, make its value the current working directory. - -Unifies _Old_ with an absolute path to the current working directory -and change working directory to _New_. Use the pattern -`working_directory(CWD, CWD)` to get the current directory. See -also `absolute_file_name/2` and chdir/1. - - */ :- use_module(library(lists), [append/3]). @@ -451,15 +425,11 @@ if there is one. This predicate is backtrackable in Unix systems, but not currently in Win32 configurations. ~~~~~ - ?- environ('HOME',X). + ?- environ('HOME',V). -X = 'C:\\cygwin\\home\\administrator' ? +V = 'C:\\cygwin\\home\\administrator' ? ~~~~~ -*/ -/** @pred environ(+E, -S) - - Given an environment variable _E_ this predicate unifies the second - argument _S_ with its value. _E_ may be bound to an atom, or just be +_EnvVar_ may be bound to an atom, or just be unbound. In the latter case environ/2 will enumerate over all environment variables. @@ -666,6 +636,19 @@ get_shell(Shell, '/c') :- getenv('COMSPEC', Shell). get_shell('/bin/sh','-c'). +/** + * @pred system(+ _S_) + +Passes command _S_ to the Bourne shell (on UNIX environments) or the +current command interpreter in WIN32 environments. +*/ + +/** + * @pred system + +Passes command _S_ to the Bourne shell (on UNIX environments) or the +current command interpreter in WIN32 environments. +*/ system :- default_shell(Command), do_system(Command, _Status, Error), @@ -676,6 +659,13 @@ default_shell(Shell) :- win, !, default_shell('/bin/sh'). +/** @pred system(+ _Command_,- _Res_) + +Interface to `system`: execute command _Command_ and unify + _Res_ with the result. + + +n*/ system(Command, Status) :- G = system(Command, Status), check_command(Command, G), @@ -764,13 +754,6 @@ rename_file(F0, F) :- rename_file(F0, F, Error), handle_system_internal(Error, off, rename_file(F0, F)). -/** - * @pred system(+ _S_) - -Passes command _S_ to the Bourne shell (on UNIX environments) or the -current command interpreter in WIN32 environments. -*/ - /** @pred directory_files(+ _Dir_,+ _List_) @@ -788,4 +771,44 @@ environments, and `findfirst` in WIN32 through the system_library buil directory_files(X,Y) :- list_directory(X,Y). +:- meta_predicate directory_map(+,1,-), + rb_apply(+,+,2,-). + +/** @pred directory_map(+ _Dir_, 1:_P_) + + +Given a directory _Dir_, directory_map/2 visits all files in _Dir_, +and verifies whether `P(F)` holds, where _F_ is the file's absolute +path. + +~~~~~ + ?- directory_map('.', process). +~~~~~ + +The predicates performs a left-recursive traversal. It does not protect against file system errors and it does not check for symbolic links. + +*/ +directory_map(D, P), + working_directory(_, D), + list_directory(D,L), + d_map(L, P). + +d_map([],_,_,_). +d_map(['.'|Fs],D, P) :- + d_map(Fs,D, P). +d_map(['..'|Fs],D, P) :- + d_map(Fs, D, P). +d_map([D|Fs], D, P) :- + absolute_file_name( F, File, [prefix(D)] ), + f_map(File, P), + d_map(Fs, D, P). + +f_map(File, P) :- + catch( file_property( File, type(directory) ), _, fail ), + directory_map( File, P). +f_map(File, P) :- + call(P,File). + + + /** @} */ diff --git a/os/sysbits.c b/os/sysbits.c index 9bf8f8cd5..1c326e769 100644 --- a/os/sysbits.c +++ b/os/sysbits.c @@ -1150,6 +1150,19 @@ const char *Yap_getcwd(char *cwd, size_t cwdlen) { return rc; } +/** @pred working_directory( ?_CurDir_,? _NextDir_) + + +Fetch the current directory at _CurDir_. If _NextDir_ is bound +to an atom, make its value the current working directory. + +Unifies _Old_ with an absolute path to the current working directory +and change working directory to _New_. Use the pattern +`working_directory(CWD, CWD)` to get the current directory. See +also `absolute_file_name/2` and chdir/1. + + +*/ static Int working_directory(USES_REGS1) { char dir[YAP_FILENAME_MAX + 1]; Term t1 = Deref(ARG1), t2; diff --git a/pl/ypp.yap b/pl/ypp.yap index bd1876616..d06e6db93 100644 --- a/pl/ypp.yap +++ b/pl/ypp.yap @@ -3,8 +3,6 @@ * @author Nuno Fonseca (nunofonseca@acm.org), Tiago Soares * @date 2005-05-14 * - * @brief Yap PreProcessing - * * */ %==================================================================================== @@ -32,16 +30,18 @@ ). /** - * @defgroup Ypp Yap PreProcessing + * @defgroup Ypp YAP PreProcessing + * @brief YAP Interface to the C Preprocessor + * * @{ * @ingroup library * - * This program can be used as a preprocessor in the + * This program allows preprocessing in the * style of the `C` language. Currently, it must be used through - * ypp_consult and or ypp_reconsult. + * ypp_consult/1 and or ypp_reconsult/1. See the myddas library for examples of use. * * Notice that ypp uses `#` commands and it is different from the Prolog if/1 - * directive. + * directive. The `ypp` extension should be used for these files. * */ @@ -57,14 +57,26 @@ ypp_state(State):- get_state(State), !. +/** @pred ypp_define(_Name_,_Value_) + * + * Define a new preprocessor symbol _Name_, and bind it to _Value_ (same as `#define`) + */ ypp_define(Name,Value):- ground(Name),ground(Value), store_define(Name,Value). +/** @pred ypp_undefine(_Name_) + * + * Discard a preprocessor symbol _Name_ (same as `#undef`) +*/ ypp_undefine(Name):- ground(Name), del_define(Name). +/** @pred ypp_extcmd(_Cmd_) + * + * Add a preprocessor extension _Cmd_ +*/ ypp_extcmd(Cmd):- ground(Cmd),!, eraseall('____ypp_extcmd'), @@ -73,10 +85,18 @@ ypp_extcmd(Cmd):- \+ ground(Cmd), recorded('____ypp_extcmd',Cmd,_). +/** @pred ypp_consult(_File_) + * + * Preprocess and consult a file. +*/ ypp_consult(File):- (get_state(on)->ypp_file(File,NFile);NFile=File), consult(NFile). +/** @pred ypp_reconsult(_File_) + * + * Preprocess and reconsult a file. +*/ ypp_reconsult(File):- (get_state(on)->ypp_file(File,NFile);NFile=File), reconsult(NFile). diff --git a/swi/library/plunit.pl b/swi/library/plunit.pl index d0e20a312..e5921b06c 100644 --- a/swi/library/plunit.pl +++ b/swi/library/plunit.pl @@ -108,7 +108,7 @@ sicstus :- catch(current_prolog_flag(system_type, _), _, fail). :- if(swi). throw_error(Error_term,Impldef) :- - throw(error(Error_term,context(Impldef,_))). + throw(error(Error_term,Impldef)). :- set_prolog_flag(generate_debug_info, false). :- use_module(library(option)). @@ -126,9 +126,9 @@ set_test_flag(Name, Value) :- throw_error(Error_term,Impldef) :- throw(error(Error_term,i(Impldef))). % SICStus 3 work around -:- use_module(swi). % SWI-Compatibility +%:- use_module(swi). % SWI-Compatibility :- use_module(library(terms)). -:- op(700, xfx, =@=). +%:- op(700, xfx, =@=). '$set_source_module'( In, Out) :- current_source_module(In, Out). @@ -159,7 +159,7 @@ set_test_flag( Name, Val ) :- retractall(test_flag(Name,_)), asserta(test_flag(Name, Val)). -:- op(1150, fx, thread_local). +%:- op(1150, fx, thread_local). user:term_expansion((:- thread_local(PI)), (:- dynamic(PI))) :- prolog_load_context(module, plunit). @@ -255,7 +255,6 @@ loading_tests :- % unit is ended by :- end_tests(UnitName). begin_tests(Unit) :- - trace, begin_tests(Unit, []). begin_tests(Unit, Options) :- @@ -267,30 +266,31 @@ begin_tests(Unit, Options) :- :- if(swi). begin_tests(Unit, Name, File:Line, Options) :- - loading_tests, !, - '$set_source_module'(Context, Context), - ( current_unit(Unit, Name, Context, Options) - -> true - ; retractall(current_unit(Unit, Name, _, _)), - assert(current_unit(Unit, Name, Context, Options)) - ), - '$set_source_module'(Old, Name), - '$declare_module'(Name, test, Context, File, Line, false), - discontiguous(Name:'unit test'/4), -% '$set_predicate_attribute'(Name:'unit test'/4, trace, 0), - discontiguous(Name:'unit body'/2), - asserta(loading_unit(Unit, Name, File, Old)). + loading_tests, !, + prolog_flag(typein_module,Context, Context), + ( current_unit(Unit, Name, Context, Options) + -> true + ; retractall(current_unit(Unit, Name, _, _)), + assert(current_unit(Unit, Name, Context, Options)) + ), + prolog_flag(typein_module,Old, Name), + declare_module(Name, test, Context, File, Line, false), + discontiguous(Name:'unit test'/4), + discontiguous(Name:'unit body'/2), + multifile(Name:'unit test'/4), + multifile(Name:'unit body'/2), + asserta(loading_unit(Unit, Name, File, Old)). begin_tests(Unit, Name, File:_Line, _Options) :- - '$set_source_module'(Old, Old), + prolog_flag(typein_module,Old, Old), asserta(loading_unit(Unit, Name, File, Old)). -'$declare_module'( Name, Class, Context, File, Line, _AllowFile ) :- +declare_module( Name, Class, Context, File, Line, _AllowFile ) :- Name \= Context, !, set_module_property( Name, base(Context) ), set_module_property( Name, class(Class) ), set_module_property( Name, exports([], File, Line) ). -'$declare_module'( Name, _Class, Name, _File, _Line, _AllowFile ) . +declare_module( Name, _Class, Name, _File, _Line, _AllowFile ) . :- else. @@ -327,7 +327,7 @@ end_tests(Unit) :- loading_unit(StartUnit, _, _, _), !, ( Unit == StartUnit -> once(retract(loading_unit(StartUnit, _, _, Old))), - '$set_source_module'(_, Old) + prolog_flag(typein_module,_, Old) ; throw_error(context_error(plunit_close(Unit, StartUnit)), _) ). end_tests(Unit) :- @@ -463,7 +463,7 @@ user:term_expansion(Term, Expanded) :- *******************************/ :- if(swi). -%:- use_module(library(error)). +:- use_module(library(error)). :- else. must_be(list, X) :- !, ( is_list(X) @@ -689,7 +689,7 @@ make_run_tests(Files) :- :- if(swi). -unification_capability(sto_error_incomplete). +%unification_capability(sto_error_incomplete). % can detect some (almost all) STO runs unification_capability(rational_trees). unification_capability(finite_trees). @@ -701,6 +701,7 @@ set_unification_capability(Cap) :- current_unification_capability(Cap) :- current_prolog_flag(occurs_check, Flag), cap_to_flag(Cap, Flag), !. +current_unification_capability(false). cap_to_flag(sto_error_incomplete, error). cap_to_flag(rational_trees, false). @@ -1033,7 +1034,7 @@ cmp(Var =@= Value, Var, variant, Value). % variant/2 is the same =@= % True if Goal succeeded. Det is unified to =true= if Goal left % no choicepoints and =false= otherwise. -:- if((swi|sicstus)). +:- if((swi)). call_det(Goal, Det) :- call_cleanup(Goal,Det0=true), ( var(Det0) -> Det = false ; Det = true ).