make attribute_goals a nonterminal

This commit is contained in:
Mark Thom
2019-10-03 23:29:18 -06:00
parent b61ed65208
commit 0a84f183fe
5 changed files with 41 additions and 42 deletions

View File

@@ -2,23 +2,25 @@
'$copy_attr_list'/2, '$get_attr'/2, '$put_attr'/2, '$copy_attr_list'/2, '$get_attr'/2, '$put_attr'/2,
'$absent_from_list'/2, '$get_from_list'/3, '$absent_from_list'/2, '$get_from_list'/3,
'$add_to_list'/3, '$del_attr'/3, '$del_attr_step'/3, '$add_to_list'/3, '$del_attr'/3, '$del_attr_step'/3,
'$del_attr_buried'/4]). '$del_attr_buried'/4, '$default_attr_list'/4]).
:- use_module(library(dcgs)). :- use_module(library(dcgs)).
:- use_module(library(terms)). :- use_module(library(terms)).
:- op(1199, fx, attribute). :- op(1199, fx, attribute).
% represent the list of attributes belonging to a variable, /* represent the list of attributes belonging to a variable,
% of a particular module, as a list of terms of the form of a particular module, as a list of terms of the form
% Module:put_atts(V, ListOfAtts). Module:put_atts(V, ListOfAtts). */
'$default_attr_list'(Module, V, ListOfAtts) :- '$default_attr_list'(Module, V) -->
Module:get_atts(V, Attributes), { Module:get_atts(V, Attributes) },
'$default_attr_list'(Attributes, Module, V, ListOfAtts). '$default_attr_list'(Attributes, Module, V).
'$default_attr_list'([PG | PGs], Module, AttrVar, [Module:put_atts(AttrVar, PG) | Gs]) :- '$default_attr_list'([PG | PGs], Module, AttrVar) -->
'$default_attr_list'(PGs, Module, AttrVar, Gs). ( { '$module_of'(Module, PG) } -> [Module:put_atts(AttrVar, PG)]
'$default_attr_list'([], _, _, []). ; { true } ),
'$default_attr_list'(PGs, Module, AttrVar).
'$default_attr_list'([], _, _) --> [].
'$absent_attr'(V, Attr) :- '$absent_attr'(V, Attr) :-
'$get_attr_list'(V, Ls), '$get_attr_list'(V, Ls),

View File

@@ -1,6 +1,7 @@
:- module(dif, [dif/2]). :- module(dif, [dif/2]).
:- use_module(library(atts)). :- use_module(library(atts)).
:- use_module(library(dcgs)).
:- use_module(library(lists), [append/3]). :- use_module(library(lists), [append/3]).
:- attribute dif/1. :- attribute dif/1.
@@ -43,10 +44,11 @@ dif(X, Y) :- X \== Y,
dif_set_variables(YVars, X, Y) dif_set_variables(YVars, X, Y)
). ).
gather_dif_goals([], _). gather_dif_goals([]) --> [].
gather_dif_goals([(X \== Y) | Goals0], [dif(X, Y) | Goals]) :- gather_dif_goals([(X \== Y) | Goals]) -->
gather_dif_goals(Goals0, Goals). [dif(X, Y)],
gather_dif_goals(Goals).
attribute_goals(X, Goals) :- attribute_goals(X) -->
get_atts(X, +dif(Goals0)), { get_atts(X, +dif(Goals)) },
gather_dif_goals(Goals0, Goals). gather_dif_goals(Goals).

View File

@@ -1,6 +1,7 @@
:- module(freeze, [freeze/2]). :- module(freeze, [freeze/2]).
:- use_module(library(atts)). :- use_module(library(atts)).
:- use_module(library(dcgs)).
:- attribute frozen/1. :- attribute frozen/1.
@@ -20,13 +21,14 @@ freeze(X, Goal) :-
put_atts(Fresh, frozen(Goal)), put_atts(Fresh, frozen(Goal)),
Fresh = X. Fresh = X.
gather_freeze_goals(Attrs, _, _) :- gather_freeze_goals(Attrs, _) -->
var(Attrs), !. { var(Attrs), ! }.
gather_freeze_goals([frozen(X) | _], Var, [freeze(Var, X) | _]) :- gather_freeze_goals([frozen(X) | _], Var) -->
!. [freeze(Var, X)],
gather_freeze_goals([_ | Attrs], Var, Goals) :- { ! }.
gather_freeze_goals(Attrs, Var, Goals). gather_freeze_goals([_ | Attrs], Var) -->
gather_freeze_goals(Attrs, Var).
attribute_goals(X, Goals) :- attribute_goals(X) -->
'$get_attr_list'(X, Attrs), { '$get_attr_list'(X, Attrs) },
gather_freeze_goals(Attrs, X, Goals). gather_freeze_goals(Attrs, X).

View File

@@ -277,7 +277,7 @@ impl Machine {
compile_user_module(&mut wam, parsing_stream(LISTS.as_bytes()), true); compile_user_module(&mut wam, parsing_stream(LISTS.as_bytes()), true);
compile_user_module(&mut wam, parsing_stream(NON_ISO.as_bytes()), true); compile_user_module(&mut wam, parsing_stream(NON_ISO.as_bytes()), true);
compile_user_module(&mut wam, parsing_stream(SI.as_bytes()), true); compile_user_module(&mut wam, parsing_stream(SI.as_bytes()), true);
wam.compile_top_level(); wam.compile_top_level();
wam.compile_scryerrc(); wam.compile_scryerrc();

View File

@@ -6,13 +6,6 @@ driver(QueryVars, AttrVars) :-
call_attribute_goals(Modules, AttrVars), call_attribute_goals(Modules, AttrVars),
'$return_from_attribute_goals'. '$return_from_attribute_goals'.
enqueue_goal(Goals0) :-
nonvar(Goals0), Goals0 = [Goal | Goals], !,
enqueue_goals(Goals0). % enqueue lists of goals separately.
enqueue_goal(Goal) :-
nonvar(Goal),
'$enqueue_attribute_goal'(Goal). % enqueue the goal for printing to the toplevel.
enqueue_goals(Goals0) :- enqueue_goals(Goals0) :-
nonvar(Goals0), nonvar(Goals0),
Goals0 = [Goal | Goals], Goals0 = [Goal | Goals],
@@ -33,18 +26,18 @@ call_project_attributes([Module|Modules], QueryVars, AttrVars) :-
call_attribute_goals([], _). call_attribute_goals([], _).
call_attribute_goals([Module | Modules], AttrVars) :- call_attribute_goals([Module | Modules], AttrVars) :-
call_goals(AttrVars, Module), call_goals(AttrVars, Module, Goals),
enqueue_goals(Goals),
call_attribute_goals(Modules, AttrVars). call_attribute_goals(Modules, AttrVars).
call_goals([], _). call_goals([], _, []).
call_goals([AttrVar|AttrVars], Module) :- call_goals([AttrVar|AttrVars], Module, Goals) :-
( catch(Module:attribute_goals(AttrVar, Goal), ( catch(Module:attribute_goals(AttrVar, Goals, RGoals),
error(evaluation_error((Module:attribute_goals)/2), attribute_goals/2), error(evaluation_error((Module:attribute_goals)/3), attribute_goals/3),
atts:'$default_attr_list'(Module, AttrVar, Goal)), atts:'$default_attr_list'(Module, AttrVar, Goals, RGoals)) -> true
nonvar(Goal) -> enqueue_goal(Goal) ; true
; true
), ),
call_goals(AttrVars, Module). call_goals(AttrVars, Module, RGoals).
gather_modules([], [], _). gather_modules([], [], _).
gather_modules([AttrVar|AttrVars], Modules, Modules0) :- gather_modules([AttrVar|AttrVars], Modules, Modules0) :-