expand goals in initialization directives.

This commit is contained in:
Mark Thom
2019-10-01 23:25:17 -06:00
parent c0ad3231f5
commit 239ffb205b
2 changed files with 16 additions and 1 deletions

View File

@@ -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 {

View File

@@ -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), !
).