From a516d6ad47c23ca6fbb36a8e702a6bb73d2b6968 Mon Sep 17 00:00:00 2001 From: Vitor Santos Costa Date: Tue, 14 Jun 2011 09:04:03 +0100 Subject: [PATCH] more SWI stuff. --- library/dialect/swi.yap | 20 -------------------- pl/consult.yap | 11 ++++++++--- pl/modules.yap | 25 +++++++++++++++++++++++++ pl/utils.yap | 18 ++++++++++++++++++ 4 files changed, 51 insertions(+), 23 deletions(-) diff --git a/library/dialect/swi.yap b/library/dialect/swi.yap index 5f3c0055f..811dfe487 100755 --- a/library/dialect/swi.yap +++ b/library/dialect/swi.yap @@ -10,7 +10,6 @@ chdir/1, compile_aux_clauses/1, convert_time/2, - '$set_source_module'/2, '$declare_module'/5, '$set_predicate_attribute'/3, stamp_date_time/3, @@ -183,25 +182,6 @@ compile_aux_clauses([Cl|Cls]) :- assert_static(M:Cl), compile_aux_clauses(Cls). -'$set_source_module'(Source0, SourceF) :- - prolog_load_context(module, Source0), !, - module(SourceF). -'$set_source_module'(Source0, SourceF) :- - current_module(Source0, SourceF). - -/** '$declare_module'(+Module, +Super, +File, +Line, +Redefine) is det. - -Start a new (source-)module - -@param Module is the name of the module to declare -@param File is the canonical name of the file from which the module - is loaded -@param Line is the line-number of the :- module/2 directive. -@param Redefine If =true=, allow associating the module to a new file -*/ -'$declare_module'(Name, Context, _, _, _) :- - add_import_module(Name, Context, start). - '$set_predicate_attribute'(_, _, _). flag(Key, Old, New) :- diff --git a/pl/consult.yap b/pl/consult.yap index 6ee9988fc..4284b7ee2 100755 --- a/pl/consult.yap +++ b/pl/consult.yap @@ -871,8 +871,8 @@ absolute_file_name(File,Opts,TrueFileName) :- '$type_extension'(Type,Ext), atom_concat([File,Ext],F). '$add_type_extensions'(Type,File,F) :- - user:prolog_file_type(Type, File), - atom_concat([File,Ext],F). + user:prolog_file_type(Ext, Type), + atom_concat([File,'.',Ext],F). '$type_extension'(txt,''). '$type_extension'(prolog,'.yap'). @@ -1050,4 +1050,9 @@ make. '$fetch_stream_alias'(OldStream,Alias) :- stream_property(OldStream, alias(Alias)), !. -'$require'(_Ps, _M). \ No newline at end of file +'$require'(_Ps, _M). + +'$store_clause'('$source_location'(File, Line):Clause, File) :- + assert_static(Clause). + + diff --git a/pl/modules.yap b/pl/modules.yap index 6a259d40a..af68ece02 100644 --- a/pl/modules.yap +++ b/pl/modules.yap @@ -801,3 +801,28 @@ delete_import_module(Mod, ImportModule) :- '$do_error'(type_error(atom,Mod),delete_import_module(Mod, ImportModule)). delete_import_module(Mod, ImportModule) :- '$do_error'(type_error(atom,ImportModule),delete_import_module(Mod, ImportModule)). + +'$set_source_module'(Source0, SourceF) :- + prolog_load_context(module, Source0), !, + module(SourceF). +'$set_source_module'(Source0, SourceF) :- + current_module(Source0, SourceF). + +/** '$declare_module'(+Module, +Super, +File, +Line, +Redefine) is det. + +Start a new (source-)module + +@param Module is the name of the module to declare +@param File is the canonical name of the file from which the module + is loaded +@param Line is the line-number of the :- module/2 directive. +@param Redefine If =true=, allow associating the module to a new file +*/ +'$declare_module'(Name, Context, _, _, _) :- + add_import_module(Name, Context, start). + +module_property(Mod, file(F)) :- + recorded('$module','$module'(F,Mod,_),_). +module_property(Mod, exports(Es)) :- + recorded('$module','$module'(_,Mod,Es),_). + diff --git a/pl/utils.yap b/pl/utils.yap index 01ed7fb0a..c7bf2ae61 100644 --- a/pl/utils.yap +++ b/pl/utils.yap @@ -719,3 +719,21 @@ subsumes_term(A,B) :- \+ \+ terms:subsumes(A,B). +%% file_name_on_path(+File:atom, -OnPath) is det. +% +% True if OnPath a description of File based on the file search +% path. This performs the inverse of absolute_file_name/3. + +file_name_on_path(Path, ShortId) :- + ( file_alias_path(Alias, Dir), + atom_concat(Dir, Local, Path) + -> ( Alias == '.' + -> ShortId = Local + ; file_name_extension(Base, pl, Local) + -> ShortId =.. [Alias, Base] + ; ShortId =.. [Alias, Local] + ) + ; ShortId = Path + ). + +