]> Repositorios git - scryer-prolog.git/commitdiff
make attribute_goals a nonterminal
authorMark Thom <[email protected]>
Fri, 4 Oct 2019 05:29:18 +0000 (23:29 -0600)
committerMark Thom <[email protected]>
Fri, 4 Oct 2019 05:29:18 +0000 (23:29 -0600)
src/prolog/lib/atts.pl
src/prolog/lib/dif.pl
src/prolog/lib/freeze.pl
src/prolog/machine/mod.rs
src/prolog/machine/project_attributes.pl

index 96f3129621318c95f9c2e6035e3c1c8965422f62..a86fd55ce0af7348cea7fdbf5ba919f29366e457 100644 (file)
@@ -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).
-
-'$default_attr_list'([PG | PGs], Module, AttrVar, [Module:put_atts(AttrVar, PG) | Gs]) :-
-    '$default_attr_list'(PGs, Module, AttrVar, Gs).
-'$default_attr_list'([], _, _, []).
+/* 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_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),
index 991db075f6ed1d9ff32de014bcf0ea8cedf1d440..77cfee571cabe48d3e9b6a0b25be84024ee4d01e 100644 (file)
@@ -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).
index d3a92eaf24535515d460143955bbe79612f9c1ef..4a3c05b81343a1dbcaa65caa44b50e953fbb50d1 100644 (file)
@@ -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).
index 7247170d96fb9c2379e6b9458d04104da54bd3ea..a77268c273002941ebf2f5876f5fedfb8cbf66e8 100644 (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(NON_ISO.as_bytes()), true);
         compile_user_module(&mut wam, parsing_stream(SI.as_bytes()), true);
-
+        
         wam.compile_top_level();
         wam.compile_scryerrc();
 
index f6a149837d1b59c26fe92fa79183c48c7fad10a5..bf12addf15868c5f5abb4ecc989160134031ac8c 100644 (file)
@@ -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) :-