From: Mark Thom Date: Wed, 2 Oct 2019 05:25:17 +0000 (-0600) Subject: expand goals in initialization directives. X-Git-Tag: v0.8.110~29 X-Git-Url: https://git.sagredo.dev/?a=commitdiff_plain;h=239ffb205b658b9629cbf31262473a49c598dded;p=scryer-prolog.git expand goals in initialization directives. --- diff --git a/src/prolog/machine/term_expansion.rs b/src/prolog/machine/term_expansion.rs index 3880ac41..645f6fc3 100644 --- a/src/prolog/machine/term_expansion.rs +++ b/src/prolog/machine/term_expansion.rs @@ -307,7 +307,6 @@ impl<'a, R: Read> TermStream<'a, R> { while let Some(term) = terms.pop_front() { match machine_st.try_expand_term(self.wam, &term, CompileTimeHook::GoalExpansion) { Some(term_string) => { - println!("trying to goal expand {}", term_string); let term = self.parse_expansion_output(term_string.as_str(), op_dir)?; match term { diff --git a/src/prolog/toplevel.pl b/src/prolog/toplevel.pl index 0119a801..2fd6ffb6 100644 --- a/src/prolog/toplevel.pl +++ b/src/prolog/toplevel.pl @@ -72,3 +72,19 @@ use_module(Module, QualifiedExports) :- ) ; throw(error(instantiation_error, use_module/2)) ). + +% expand goals in initialization directives. +user:term_expansion(Term0, (:- initialization(ExpandedGoals))) :- + nonvar(Term0), + Term0 = (:- initialization(Goals)), + expand_goals(Goals, ExpandedGoals). + +expand_goals(Goals, ExpandedGoals) :- + nonvar(Goals), + var(ExpandedGoals), + ( Goals = (Goal0, Goals0) -> + ( expand_goal(Goal0, Goal1) -> expand_goals(Goals0, Goals1), ExpandedGoals = (Goal1, Goals1) + ; expand_goals(Goals0, Goals1), ExpandedGoals = (Goal0, Goals1) + ) + ; expand_goal(Goals, ExpandedGoals), ! + ).