diff --git a/pl/consult.yap b/pl/consult.yap index 1760b51b3..0f2fd89c4 100755 --- a/pl/consult.yap +++ b/pl/consult.yap @@ -247,8 +247,6 @@ load_files(Files,Opts) :- ), !, '$lf_opt'(if, TOpts, If), ( var(If) -> If = true ; true ), - '$lf_opt'(encoding, TOpts, Encoding), - '$set_encoding'(Stream, Encoding), '$lf_opt'(imports, TOpts, Imports), '$start_lf'(If, Mod, Stream, TOpts, File, Imports), close(Stream). @@ -333,6 +331,8 @@ use_module(M,F,Is) :- '$lf_opt'('$context_module', TOpts, ContextModule), '$msg_level'( TOpts, Verbosity), % format( 'I=~w~n', [Verbosity=UserFile] ), + '$lf_opt'(encoding, TOpts, Encoding), + '$set_encoding'(Stream, Encoding), % export to process b_setval('$lf_status', TOpts), '$reset_if'(OldIfLevel), @@ -392,12 +392,13 @@ use_module(M,F,Is) :- '$bind_module'(Mod, UseModule), % ( File = '/Users/vsc/Yap/bins/threads/share/Yap/error.pl' -> start_low_level_trace ; stop_low_level_trace ), '$lf_opt'(imports, TOpts, Imports), - '$import_to_current_module'(File, ContextModule, Imports, TOpts), + '$import_to_current_module'(File, ContextModule, Imports, _, TOpts), '$lf_opt'(reexport, TOpts, Reexport), ( Reexport == false -> true ; '$lf_opt'('$parent_topts', TOpts, OldTOpts), '$lf_opt'('$context_module', OldTOpts, OldContextModule), - '$import_to_current_module'(File, OldContextModule, Imports, TOpts) + '$import_to_current_module'(File, OldContextModule, Imports, _, TOpts), + '$extend_exports'(ContextModule, Imports) ), ( LC == 0 -> prompt(_,' |: ') ; true), ( OldMode == off -> '$exit_system_mode' ; true ), @@ -441,20 +442,13 @@ use_module(M,F,Is) :- '$bind_module'(_, load_files). '$bind_module'(Mod, use_module(Mod)). -'$import_to_current_module'(File, ContextModule, Imports, TOpts) :- +'$import_to_current_module'(File, ContextModule, Imports, RemainingImports, TOpts) :- recorded('$module','$module'(File, Module, ModExports),_), Module \= ContextModule, !, '$lf_opt'('$call', TOpts, Call), - '$convert_for_export'(Imports, ModExports, Module, ContextModule, TranslationTab, _RemainingImports, Goal), -% format( 'O=~w~n', [(TranslationTab,ContextModule)] ), + '$convert_for_export'(Imports, ModExports, Module, ContextModule, TranslationTab, RemainingImports, Goal), '$add_to_imports'(TranslationTab, Module, ContextModule). -'$import_to_current_module'(_, _, _, _). - -'$reexport_lf'(Imports, TOpts, Mod, ContextModule) :- - '$lf_opt'('$call', TOpts, Goal), - ( var(Imports) -> Imports = all ; true ), - '$reexport'(Imports, Mod, ContextModule, Goal). - +'$import_to_current_module'(_, _, _, _, _). '$start_reconsulting'(F) :- recorda('$reconsulted','$',_), @@ -658,14 +652,15 @@ prolog_load_context(term_position, '$stream_position'(0,Line,0,0,0)) :- % be imported from any module. '$file_loaded'(Stream, M, Imports, TOpts) :- '$file_name'(Stream, F), - '$ensure_file_loaded'(F, M, Imports, TOpts). + '$ensure_file_loaded'(F, M, F1), +% format( 'IL=~w~n', [(F1:Imports->M)] ), + '$import_to_current_module'(F1, M, Imports, _, TOpts). -'$ensure_file_loaded'(F, M, Imports, TOpts) :- +'$ensure_file_loaded'(F, M, F1) :- recorded('$module','$module'(F1,_NM,_P),_), recorded('$lf_loaded','$lf_loaded'(F1,_),_), - same_file(F1,F), !, - '$import_to_current_module'(F1, M, Imports, TOpts). -'$ensure_file_loaded'(F, _M, _, _TOpts) :- + same_file(F1,F), !. +'$ensure_file_loaded'(F, _M, F1) :- recorded('$lf_loaded','$lf_loaded'(F1,_),_), same_file(F1,F), !. @@ -674,16 +669,16 @@ prolog_load_context(term_position, '$stream_position'(0,Line,0,0,0)) :- % be imported from any module. '$file_unchanged'(Stream, M, Imports, TOpts) :- '$file_name'(Stream, F), - '$ensure_file_unchanged'(F, M, Imports, TOpts). + '$ensure_file_unchanged'(F, M, F1), +% format( 'IU=~w~n', [(F1:Imports->M)] ), + '$import_to_current_module'(F1, M, Imports, _, TOpts). -'$ensure_file_unchanged'(F, M, Imports, TOpts) :- +'$ensure_file_unchanged'(F, M, F1) :- recorded('$module','$module'(F1,_NM,_P),_), recorded('$lf_loaded','$lf_loaded'(F1,Age),R), same_file(F1,F), !, - '$file_is_unchanged'(F, R, Age), -% format( 'I=~w~n', [M=Imports] ), - '$import_to_current_module'(F1, M, Imports, TOpts). -'$ensure_file_unchanged'(F, _M, _, _TOpts) :- + '$file_is_unchanged'(F, R, Age). +'$ensure_file_unchanged'(F, _M, F1) :- recorded('$lf_loaded','$lf_loaded'(F1,Age),R), same_file(F1,F), !, '$file_is_unchanged'(F, R, Age). @@ -752,7 +747,7 @@ remove_from_path(New) :- '$check_path'(New,Path), fail. '$remove_multifile_clauses'(_). - +% inform the file has been loaded and is now available. '$loaded'(Stream, UserFile, M, OldF, Line, Reconsult, F, Dir, Opts) :- '$file_name'(Stream, F0), ( F0 == user_input, nonvar(UserFile) -> UserFile = F ; F = F0 ), diff --git a/pl/modules.yap b/pl/modules.yap index 956eb698f..b62f4bbba 100644 --- a/pl/modules.yap +++ b/pl/modules.yap @@ -85,6 +85,22 @@ module(N) :- sort( AllExports0, AllExports ), recorda('$module','$module'(F,Module,AllExports),_). +'$extend_exports'(Module, NewExports) :- + '$convert_for_export'(all, NewExports, Module, Module, _TranslationTab, NewExports1, load_files), + recorded('$module','$module'(F,Module,OriginalExports),R), + '$add_exports'( NewExports1, OriginalExports, Exports ), + erase(R), + sort( Exports, AllExports ), + recorda('$module','$module'(F,Module,AllExports),_), + fail. +'$extend_exports'(_F, _Module, _NewExports). + +'$add_exports'( [], Exports, Exports ). +'$add_exports'( [PI|NewExports], OriginalExports, [PI|Exports] ) :- + % do not check for redefinitions, at least for now. + '$add_exports'( NewExports, OriginalExports, Exports ). + + % redefining a previously-defined file, no problem. '$add_preexisting_module_on_file'(F, F, Mod, Exports, R) :- !, erase(R), @@ -654,29 +670,29 @@ export_resource(Resource) :- export_list(Module, List) :- recorded('$module','$module'(_,Module,List),_). -'$convert_for_export'(all, Exports, _Module, _ContextModule, Tab, Exports, _) :- - '$simple_conversion'(Exports, Tab). +'$convert_for_export'(all, Exports, _Module, _ContextModule, Tab, MyExports, _) :- + '$simple_conversion'(Exports, Tab, MyExports). '$convert_for_export'([], Exports, Module, ContextModule, Tab, MyExports, Goal) :- '$clean_conversion'([], Exports, Module, ContextModule, Tab, MyExports, Goal). '$convert_for_export'([P1|Ps], Exports, Module, ContextModule, Tab, MyExports, Goal) :- '$clean_conversion'([P1|Ps], Exports, Module, ContextModule, Tab, MyExports, Goal). '$convert_for_export'(except(Excepts), Exports, Module, ContextModule, Tab, MyExports, Goal) :- '$neg_conversion'(Excepts, Exports, Module, ContextModule, MyExports, Goal), - '$simple_conversion'(MyExports, Tab). + '$simple_conversion'(MyExports, Tab, _). -'$simple_conversion'([], []). -'$simple_conversion'([F/N|Exports], [F/N-F/N|Tab]) :- - '$simple_conversion'(Exports, Tab). -'$simple_conversion'([F//N|Exports], [F/N2-F/N2|Tab]) :- +'$simple_conversion'([], [], []). +'$simple_conversion'([F/N|Exports], [F/N-F/N|Tab], [F/N|E]) :- + '$simple_conversion'(Exports, Tab, E). +'$simple_conpversion'([F//N|Exports], [F/N2-F/N2|Tab], [F/N2|E]) :- N2 is N+1, - '$simple_conversion'(Exports, Tab). -'$simple_conversion'([F/N as NF|Exports], [F/N-NF/N|Tab]) :- - '$simple_conversion'(Exports, Tab). -'$simple_conversion'([F//N as BF|Exports], [F/N2-NF/N2|Tab]) :- + '$simple_conversion'(Exports, Tab, E). +'$simple_conversion'([F/N as NF|Exports], [F/N-NF/N|Tab], [NF/N|E]) :- + '$simple_conversion'(Exports, Tab, E). +'$simple_conversion'([F//N as BF|Exports], [F/N2-NF/N2|Tab], [NF/N2|E]) :- N2 is N+1, - '$simple_conversion'(Exports, Tab). -'$simple_conversion'([op(Prio,Assoc,Name)|Exports], [op(Prio,Assoc,Name)|Tab]) :- - '$simple_conversion'(Exports, Tab). + '$simple_conversion'(Exports, Tab, E). +'$simple_conversion'([op(Prio,Assoc,Name)|Exports], [op(Prio,Assoc,Name)|Tab], [op(Prio,Assoc,Name)|E]) :- + '$simple_conversion'(Exports, Tab, E). '$clean_conversion'([], _, _, _, [], [], _). '$clean_conversion'([(N1/A1 as N2)|Ps], List, Module, ContextModule, [N1/A1-N2/A1|Tab], [N2/A1|MyExports], Goal) :- !, @@ -684,7 +700,7 @@ export_list(Module, List) :- -> '$clean_conversion'(Ps, List, Module, ContextModule, Tab, MyExports, Goal) ; - '$bad_export'(N1/A1, Module, ContextModule) + '$bad_export'((N1/A1 as A2), Module, ContextModule) ). '$clean_conversion'([N1/A1|Ps], List, Module, ContextModule, [N1/A1-N1/A1|Tab], [N1/A1|MyExports], Goal) :- !, ( @@ -694,7 +710,7 @@ export_list(Module, List) :- ; '$bad_export'(N1/A1, Module, ContextModule) ). -'$clean_conversion'([N1//A1|Ps], List, Module, ContextModule, [N1/A2-N1/A2|Tab], [P1|MyExports], Goal) :- !, +'$clean_conversion'([N1//A1|Ps], List, Module, ContextModule, [N1/A2-N1/A2|Tab], [N1/A2|MyExports], Goal) :- !, A2 is A1+2, ( lists:memberchk(N1/A2, List) @@ -703,6 +719,15 @@ export_list(Module, List) :- ; '$bad_export'(N1//A1, Module, ContextModule) ). +'$clean_conversion'([N1//A1 as N2|Ps], List, Module, ContextModule, [N2/A2-N1/A2|Tab], [N2/A2|MyExports], Goal) :- !, + A2 is A1+2, + ( + lists:memberchk(N2/A2, List) + -> + '$clean_conversion'(Ps, List, Module, ContextModule, Tab, MyExports, Goal) + ; + '$bad_export'((N1//A1 as A2), Module, ContextModule) + ). '$clean_conversion'([op(Prio,Assoc,Name)|Ps], List, Module, ContextModule, [op(Prio,Assoc,Name)|Tab], [op(Prio,Assoc,Name)|MyExports], Goal) :- !, ( lists:memberchk(op(Prio,Assoc,Name), List)