From 7fa7c8b92a5ff01ece2916b9d9bdf29f2f1d0666 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Santos=20Costa?= Date: Mon, 22 Oct 2012 10:18:26 +0100 Subject: [PATCH] patch module code (by Paulo Moura) --- docs/yap.tex | 3 ++- pl/modules.yap | 38 ++++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/docs/yap.tex b/docs/yap.tex index 4364761a9..71db71ba0 100644 --- a/docs/yap.tex +++ b/docs/yap.tex @@ -2358,7 +2358,8 @@ Add predicates to the public list of the context module. This implies the predicate will be imported into another module if this module is imported with @code{use_module/[1,2]}. Note that predicates are normally exported using the directive @code{module/2}. @code{export/1} is meant -to handle export from dynamically created modules. +to handle export from dynamically created modules. The directive argument +may also be a list of predicates. @item export_list(?@var{Mod},?@var{ListOfPredicateIndicator}) @findex export_list/2 diff --git a/pl/modules.yap b/pl/modules.yap index 4328c2a83..a0df8db24 100644 --- a/pl/modules.yap +++ b/pl/modules.yap @@ -685,32 +685,42 @@ abolish_module(Mod) :- fail. abolish_module(_). -export(P) :- - var(P), - '$do_error'(instantiation_error,export(P)). -export(P) :- - P = F/N, atom(F), number(N), N > 0, !, +export(Resource) :- + var(Resource), + '$do_error'(instantiation_error,export(Resource)). +export([]) :- !. +export([Resource| Resources]) :- !, + export_resource(Resource), + export(Resources). +export(Resource) :- + export_resource(Resource). + +export_resource(Resource) :- + var(Resource), + '$do_error'(instantiation_error,export(Resource)). +export_resource(P) :- + P = F/N, atom(F), number(N), N >= 0, !, '$current_module'(Mod), - ( recorded('$module','$module'(F,Mod,ExportedPreds),R) -> + ( recorded('$module','$module'(File,Mod,ExportedPreds),R) -> erase(R), - recorda('$module','$module'(F,Mod,[P|ExportedPreds]),_) + recorda('$module','$module'(File,Mod,[P|ExportedPreds]),_) ; recorda('$module','$module'(user_input,Mod,[P]),_) ). -export(P0) :- - P0 = F//N, atom(F), number(N), N > 0, !, +export_resource(P0) :- + P0 = F//N, atom(F), number(N), N >= 0, !, N1 is N+2, P = F/N1, '$current_module'(Mod), - ( recorded('$module','$module'(F,Mod,ExportedPreds),R) -> + ( recorded('$module','$module'(File,Mod,ExportedPreds),R) -> erase(R), - recorda('$module','$module'(F,Mod,[P|ExportedPreds]),_) + recorda('$module','$module'(File,Mod,[P|ExportedPreds]),_) ; recorda('$module','$module'(user_input,Mod,[P]),_) ). -export(op(Prio,Assoc,Name)) :- !, +export_resource(op(Prio,Assoc,Name)) :- !, op(Prio,Assoc,prolog:Name). -export(P) :- - '$do_error'(type_error(predicate_indicator,P),export(P)). +export_resource(Resource) :- + '$do_error'(type_error(predicate_indicator,Resource),export(Resource)). export_list(Module, List) :- recorded('$module','$module'(_,Module,List),_).