]> Repositorios git - scryer-prolog.git/commitdiff
expand goals in initialization directives.
authorMark Thom <[email protected]>
Wed, 2 Oct 2019 05:25:17 +0000 (23:25 -0600)
committerMark Thom <[email protected]>
Wed, 2 Oct 2019 05:25:17 +0000 (23:25 -0600)
src/prolog/machine/term_expansion.rs
src/prolog/toplevel.pl

index 3880ac416d75ceb5618c5faa52ec2274e7da63a5..645f6fc3273aeac327e022a0e286f67ad153ffb7 100644 (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 {
index 0119a801cb85dd526fd833ea8c4a4c225f381a31..2fd6ffb63a88e4e346b0a8a2112a3aa83d2ce23d 100644 (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), !
+    ).