call verify_attributes/3 once per module

This commit is contained in:
Mark Thom
2019-02-12 18:12:18 -07:00
parent 06021e2373
commit 7edc2567a8
2 changed files with 17 additions and 7 deletions

View File

@@ -64,7 +64,7 @@ false :- '$fail'.
Module : Predicate :-
( atom(Module) -> '$module_call'(Module, Predicate)
; throw(error(type_error(atom, Module), (:)))
; throw(error(type_error(atom, Module), (:)/2))
).
% flags.

View File

@@ -11,14 +11,24 @@ iterate([Var|VarBindings], [Value|ValueBindings], [ListOfGoalLists | ListsCubed]
iterate(VarBindings, ValueBindings, ListsCubed).
iterate([], [], []).
gather_modules(Attrs, []) :- var(Attrs), !.
gather_modules([Attr|Attrs], [Module|Modules]) :-
'$module_of'(Module, Attr), % write the owning module of Attr to Module.
gather_modules(Attrs, Modules).
verify_attrs([Module|Modules], Var, Value, [Goals|ListOfGoalLists]) :-
catch(Module:verify_attributes(Var, Value, Goals),
error(evaluation_error((M:verify_attributes)/3), verify_attrs/3),
Goals = []),
verify_attrs(Modules, Var, Value, ListOfGoalLists).
verify_attrs([], _, _, []).
call_verify_attributes(Attrs, _, _, []) :-
var(Attrs), !.
call_verify_attributes([Attr|Attrs], Var, Value, [Goals|ListOfGoalLists]) :-
'$module_of'(M, Attr), % write the owning module of Attr to M.
catch(M:verify_attributes(Var, Value, Goals),
error(evaluation_error((M:verify_attributes)/3), verify_attributes/3),
Goals = []),
call_verify_attributes(Attrs, Var, Value, ListOfGoalLists).
call_verify_attributes([Attr|Attrs], Var, Value, ListOfGoalLists) :-
gather_modules([Attr|Attrs], Modules0),
sort(Modules0, Modules),
verify_attrs(Modules, Var, Value, ListOfGoalLists).
call_goals([ListOfGoalLists | ListsCubed]) :-
call_goals_0(ListOfGoalLists),