make attribute_goals a nonterminal
This commit is contained in:
@@ -2,23 +2,25 @@
|
||||
'$copy_attr_list'/2, '$get_attr'/2, '$put_attr'/2,
|
||||
'$absent_from_list'/2, '$get_from_list'/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(terms)).
|
||||
|
||||
:- op(1199, fx, attribute).
|
||||
|
||||
% represent the list of attributes belonging to a variable,
|
||||
% of a particular module, as a list of terms of the form
|
||||
% Module:put_atts(V, ListOfAtts).
|
||||
'$default_attr_list'(Module, V, ListOfAtts) :-
|
||||
Module:get_atts(V, Attributes),
|
||||
'$default_attr_list'(Attributes, Module, V, ListOfAtts).
|
||||
/* represent the list of attributes belonging to a variable,
|
||||
of a particular module, as a list of terms of the form
|
||||
Module:put_atts(V, ListOfAtts). */
|
||||
'$default_attr_list'(Module, V) -->
|
||||
{ Module:get_atts(V, Attributes) },
|
||||
'$default_attr_list'(Attributes, Module, V).
|
||||
|
||||
'$default_attr_list'([PG | PGs], Module, AttrVar, [Module:put_atts(AttrVar, PG) | Gs]) :-
|
||||
'$default_attr_list'(PGs, Module, AttrVar, Gs).
|
||||
'$default_attr_list'([], _, _, []).
|
||||
'$default_attr_list'([PG | PGs], Module, AttrVar) -->
|
||||
( { '$module_of'(Module, PG) } -> [Module:put_atts(AttrVar, PG)]
|
||||
; { true } ),
|
||||
'$default_attr_list'(PGs, Module, AttrVar).
|
||||
'$default_attr_list'([], _, _) --> [].
|
||||
|
||||
'$absent_attr'(V, Attr) :-
|
||||
'$get_attr_list'(V, Ls),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
:- module(dif, [dif/2]).
|
||||
|
||||
:- use_module(library(atts)).
|
||||
:- use_module(library(dcgs)).
|
||||
:- use_module(library(lists), [append/3]).
|
||||
|
||||
:- attribute dif/1.
|
||||
@@ -43,10 +44,11 @@ dif(X, Y) :- X \== Y,
|
||||
dif_set_variables(YVars, X, Y)
|
||||
).
|
||||
|
||||
gather_dif_goals([], _).
|
||||
gather_dif_goals([(X \== Y) | Goals0], [dif(X, Y) | Goals]) :-
|
||||
gather_dif_goals(Goals0, Goals).
|
||||
gather_dif_goals([]) --> [].
|
||||
gather_dif_goals([(X \== Y) | Goals]) -->
|
||||
[dif(X, Y)],
|
||||
gather_dif_goals(Goals).
|
||||
|
||||
attribute_goals(X, Goals) :-
|
||||
get_atts(X, +dif(Goals0)),
|
||||
gather_dif_goals(Goals0, Goals).
|
||||
attribute_goals(X) -->
|
||||
{ get_atts(X, +dif(Goals)) },
|
||||
gather_dif_goals(Goals).
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
:- module(freeze, [freeze/2]).
|
||||
|
||||
:- use_module(library(atts)).
|
||||
:- use_module(library(dcgs)).
|
||||
|
||||
:- attribute frozen/1.
|
||||
|
||||
@@ -20,13 +21,14 @@ freeze(X, Goal) :-
|
||||
put_atts(Fresh, frozen(Goal)),
|
||||
Fresh = X.
|
||||
|
||||
gather_freeze_goals(Attrs, _, _) :-
|
||||
var(Attrs), !.
|
||||
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(Attrs), ! }.
|
||||
gather_freeze_goals([frozen(X) | _], Var) -->
|
||||
[freeze(Var, X)],
|
||||
{ ! }.
|
||||
gather_freeze_goals([_ | Attrs], Var) -->
|
||||
gather_freeze_goals(Attrs, Var).
|
||||
|
||||
attribute_goals(X, Goals) :-
|
||||
'$get_attr_list'(X, Attrs),
|
||||
gather_freeze_goals(Attrs, X, Goals).
|
||||
attribute_goals(X) -->
|
||||
{ '$get_attr_list'(X, Attrs) },
|
||||
gather_freeze_goals(Attrs, X).
|
||||
|
||||
@@ -277,7 +277,7 @@ impl Machine {
|
||||
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(SI.as_bytes()), true);
|
||||
|
||||
|
||||
wam.compile_top_level();
|
||||
wam.compile_scryerrc();
|
||||
|
||||
|
||||
@@ -6,13 +6,6 @@ driver(QueryVars, AttrVars) :-
|
||||
call_attribute_goals(Modules, AttrVars),
|
||||
'$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) :-
|
||||
nonvar(Goals0),
|
||||
Goals0 = [Goal | Goals],
|
||||
@@ -33,18 +26,18 @@ call_project_attributes([Module|Modules], QueryVars, AttrVars) :-
|
||||
|
||||
call_attribute_goals([], _).
|
||||
call_attribute_goals([Module | Modules], AttrVars) :-
|
||||
call_goals(AttrVars, Module),
|
||||
call_goals(AttrVars, Module, Goals),
|
||||
enqueue_goals(Goals),
|
||||
call_attribute_goals(Modules, AttrVars).
|
||||
|
||||
call_goals([], _).
|
||||
call_goals([AttrVar|AttrVars], Module) :-
|
||||
( catch(Module:attribute_goals(AttrVar, Goal),
|
||||
error(evaluation_error((Module:attribute_goals)/2), attribute_goals/2),
|
||||
atts:'$default_attr_list'(Module, AttrVar, Goal)),
|
||||
nonvar(Goal) -> enqueue_goal(Goal)
|
||||
; true
|
||||
call_goals([], _, []).
|
||||
call_goals([AttrVar|AttrVars], Module, Goals) :-
|
||||
( catch(Module:attribute_goals(AttrVar, Goals, RGoals),
|
||||
error(evaluation_error((Module:attribute_goals)/3), attribute_goals/3),
|
||||
atts:'$default_attr_list'(Module, AttrVar, Goals, RGoals)) -> true
|
||||
; true
|
||||
),
|
||||
call_goals(AttrVars, Module).
|
||||
call_goals(AttrVars, Module, RGoals).
|
||||
|
||||
gather_modules([], [], _).
|
||||
gather_modules([AttrVar|AttrVars], Modules, Modules0) :-
|
||||
|
||||
Reference in New Issue
Block a user