From: Mark Thom Date: Fri, 4 Oct 2019 05:29:18 +0000 (-0600) Subject: make attribute_goals a nonterminal X-Git-Tag: v0.8.110~20 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=0a84f183fee4e5890238634ccb3eccf81c16c8af;p=scryer-prolog.git make attribute_goals a nonterminal --- diff --git a/src/prolog/lib/atts.pl b/src/prolog/lib/atts.pl index 96f31296..a86fd55c 100644 --- a/src/prolog/lib/atts.pl +++ b/src/prolog/lib/atts.pl @@ -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), diff --git a/src/prolog/lib/dif.pl b/src/prolog/lib/dif.pl index 991db075..77cfee57 100644 --- a/src/prolog/lib/dif.pl +++ b/src/prolog/lib/dif.pl @@ -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). diff --git a/src/prolog/lib/freeze.pl b/src/prolog/lib/freeze.pl index d3a92eaf..4a3c05b8 100644 --- a/src/prolog/lib/freeze.pl +++ b/src/prolog/lib/freeze.pl @@ -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). diff --git a/src/prolog/machine/mod.rs b/src/prolog/machine/mod.rs index 7247170d..a77268c2 100644 --- a/src/prolog/machine/mod.rs +++ b/src/prolog/machine/mod.rs @@ -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(); diff --git a/src/prolog/machine/project_attributes.pl b/src/prolog/machine/project_attributes.pl index f6a14983..bf12addf 100644 --- a/src/prolog/machine/project_attributes.pl +++ b/src/prolog/machine/project_attributes.pl @@ -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) :-