From: Mark Thom Date: Wed, 13 Feb 2019 01:12:18 +0000 (-0700) Subject: call verify_attributes/3 once per module X-Git-Tag: v0.8.110~259 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=7edc2567a879ac2dbf04ae253fb51a2239317625;p=scryer-prolog.git call verify_attributes/3 once per module --- diff --git a/src/prolog/lib/builtins.pl b/src/prolog/lib/builtins.pl index 211bbc58..02721d6e 100644 --- a/src/prolog/lib/builtins.pl +++ b/src/prolog/lib/builtins.pl @@ -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. diff --git a/src/prolog/machine/attributed_variables.pl b/src/prolog/machine/attributed_variables.pl index c72c9e24..9bfa7b27 100644 --- a/src/prolog/machine/attributed_variables.pl +++ b/src/prolog/machine/attributed_variables.pl @@ -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),