From 08b18af8a06f7816b1092c589909b2c8a40d1568 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Mon, 1 Feb 2021 14:48:13 -0700 Subject: [PATCH] call attribute variable goals with module resolution --- src/indexing.rs | 1 - src/loader.pl | 1 + src/machine/attributed_variables.pl | 35 ++++++++++------------------- 3 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/indexing.rs b/src/indexing.rs index 8a231514..9359e18c 100644 --- a/src/indexing.rs +++ b/src/indexing.rs @@ -1019,7 +1019,6 @@ impl CodeOffsets { .or_insert(sdeq![]); let is_initial_index = code.is_empty(); - code.push_back(compute_index(is_initial_index, index)); for constant in &overlapping_constants { diff --git a/src/loader.pl b/src/loader.pl index f8f766f7..88d65770 100644 --- a/src/loader.pl +++ b/src/loader.pl @@ -56,6 +56,7 @@ load_loop(Stream, Evacuable) :- ; var(Term) -> instantiation_error(load/1) ; expand_terms_and_goals(Term, Terms), + nl, write('Terms:'), write(Terms), nl, nl, !, ( var(Terms) -> instantiation_error(load/1) diff --git a/src/machine/attributed_variables.pl b/src/machine/attributed_variables.pl index 386ff101..b5049e3a 100644 --- a/src/machine/attributed_variables.pl +++ b/src/machine/attributed_variables.pl @@ -1,5 +1,6 @@ :- module('$atts', []). + driver(Vars, Values) :- iterate(Vars, Values, ListOfListsOfGoalLists), !, @@ -13,12 +14,6 @@ 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). -*/ gather_modules(Attrs, []) :- var(Attrs), !. gather_modules([Module:_|Attrs], [Module|Modules]) :- @@ -30,38 +25,32 @@ call_verify_attributes([], _, _, []). call_verify_attributes([Attr|Attrs], Var, Value, ListOfGoalLists) :- gather_modules([Attr|Attrs], Modules0), sort(Modules0, Modules), - verify_attrs(Modules, Var, Value, ListOfGoalLists). % verify_attrs(Modules, Var, Value, ListOfGoalLists). - -verify_attrs([Module|Modules], Var, Value, [Goals|ListOfGoalLists]) :- - catch(Module:verify_attributes(Var, Value, Goals), - error(evaluation_error((Module:verify_attributes)/3), verify_attributes/3), - Goals = []), verify_attrs(Modules, Var, Value, ListOfGoalLists). -verify_attrs([], _, _, []). -/* -verify_attrs([Module|Modules], Var, Value, [Goals|ListOfGoalLists]) :- + +verify_attrs([Module|Modules], Var, Value, [Module-Goals|ListOfGoalLists]) :- catch(Module:verify_attributes(Var, Value, Goals), error(evaluation_error((Module:verify_attributes)/3), verify_attributes/3), Goals = []), verify_attrs(Modules, Var, Value, ListOfGoalLists). verify_attrs([], _, _, []). -*/ + call_goals([ListOfGoalLists | ListsCubed]) :- call_goals_0(ListOfGoalLists), call_goals(ListsCubed). call_goals([]). -call_goals_0([GoalList | GoalLists]) :- - ( var(GoalList), throw(error(instantiation_error, call_goals_0/1)) +call_goals_0([Module-GoalList | GoalLists]) :- + ( var(GoalList), + throw(error(instantiation_error, call_goals_0/1)) ; true ), - call_goals_1(GoalList), + call_goals_1(GoalList, Module), call_goals_0(GoalLists). call_goals_0([]). -call_goals_1([Goal | Goals]) :- - call(Goal), - call_goals_1(Goals). -call_goals_1([]). +call_goals_1([Goal | Goals], Module) :- + call(Module:Goal), + call_goals_1(Goals, Module). +call_goals_1([], _). -- 2.54.0