From 7d3d9bcf41ecd66369f4472b7b99a29005cbc529 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Wed, 28 Mar 2012 14:35:09 +0100 Subject: [PATCH] fix module stuff. --- pl/boot.yap | 12 +++++++++--- pl/messages.yap | 2 ++ pl/modules.yap | 36 +++++++++++++++++++++--------------- 3 files changed, 32 insertions(+), 18 deletions(-) diff --git a/pl/boot.yap b/pl/boot.yap index 011d2bab0..aeb23f838 100644 --- a/pl/boot.yap +++ b/pl/boot.yap @@ -422,11 +422,17 @@ true :- true. '$compile'(G, L, G0, Mod) ). +% +% check if current module redefines an imported predicate. +% and remove import. +% '$not_imported'(H, Mod) :- - recorded('$import','$import'(NM,Mod,NH,H,_,_),_), - NM \= Mod, !, + recorded('$import','$import'(NM,Mod,NH,H,_,_),R), + NM \= Mod, functor(NH,N,Ar), - '$do_error'(permission_error(modify, static_procedure, NM:N/Ar), consult). + print_message(warning,redefine_imported(Mod,NM,N/Ar)), + erase(R), + fail. '$not_imported'(_, _). diff --git a/pl/messages.yap b/pl/messages.yap index 889d91755..909548a82 100644 --- a/pl/messages.yap +++ b/pl/messages.yap @@ -126,6 +126,8 @@ system_message(functionality(Library)) --> [ '~q not available' - [Library] ]. system_message(import(Pred,To,From,private)) --> [ 'Importing private predicate ~w:~w to ~w.' - [From,Pred,To] ]. +system_message(redefine_imported(M,M0,PI)) --> + [ 'Module ~w redefines imported predicate ~w:~w.' - [M,M0,PI] ]. system_message(leash([])) --> [ 'No leashing.' ]. system_message(leash([A|B])) --> diff --git a/pl/modules.yap b/pl/modules.yap index 2124f5e3e..c7c335257 100644 --- a/pl/modules.yap +++ b/pl/modules.yap @@ -142,18 +142,24 @@ module(N) :- '$use_preds'(P,Publics,Mod,M), '$use_preds'(Ps,Publics,Mod,M). '$use_preds'(N/K,Publics,M,Mod) :- - ( lists:memberchk(N/K,Publics) -> true ; - print_message(warning,import(N/K,Mod,M,private)) - ), - '$do_import'(N, K, M, Mod). -'$use_preds'(N//K0,Publics,M,Mod) :- - K is K0+2, - ( lists:memberchk(N/K,Publics) -> true ; + ( lists:memberchk(N/K,Publics) -> true ; print_message(warning,import(N/K,Mod,M,private)) - ), - '$do_import'(N, K, M, Mod). + ), + '$do_import'(N, K, M, Mod). +'$use_preds'(N//K0,Publics,M,Mod) :- + K is K0+2, + ( lists:memberchk(N/K,Publics) -> true ; + print_message(warning,import(N/K,Mod,M,private)) + ), + '$do_import'(N, K, M, Mod). +% +% ignore imports that we do export +% +'$do_import'(N, K, M, T) :- + recorded('$module','$module'(_F,T,MyExports),_), + lists:member(N/K,MyExports), !. '$do_import'(N, K, M, T) :- functor(G,N,K), '$follow_import_chain'(M,G,M0,G0), @@ -169,16 +175,16 @@ module(N) :- ). '$follow_import_chain'(M,G,M0,G0) :- - recorded('$import','$import'(M1,M,G1,G,_,_),_), !, + recorded('$import','$import'(M1,M,G1,G,_,_),_), M \= M1, !, '$follow_import_chain'(M1,G1,M0,G0). '$follow_import_chain'(M,G,M,G). '$check_import'(M,T,N,K) :- - recorded('$import','$import'(MI,T,_,_,N,K),R), - \+ '$module_produced by'(M,T,N,K), !, - format(user_error,"NAME CLASH: ~w was already imported to module ~w;~n",[MI:N/K,T]), - format(user_error," Do you want to import it from ~w ? [y or n] ",M), - repeat, + recorded('$import','$import'(MI,T,_,_,N,K),R), + \+ '$module_produced by'(M,T,N,K), !, + format(user_error,"NAME CLASH: ~w was already imported to module ~w;~n",[MI:N/K,T]), + format(user_error," Do you want to import it from ~w ? [y or n] ",M), + repeat, get0(C), '$skipeol'(C), ( C is "y" -> erase(R), !; C is "n" -> !, fail;