only add expanded goals to dynamic clause code
@@ -653,7 +653,7 @@ fn setup_declaration<'a, 'b, 'c>(
}
("initialization", 1) => {
let mut rel_worker = RelationWorker::new(flags, line_num, col_num);
- let query_terms = rel_worker.setup_query(indices, terms, false)?;
+ let (query_terms, _) = rel_worker.setup_query(indices, terms, false, false)?;
let queue = rel_worker.parse_queue(indices)?;
Ok(Declaration::ModuleInitialization(query_terms, queue))
@@ -924,11 +924,14 @@ fn setup_query<'a, 'b, 'c>(
indices: &mut CompositeIndices<'a, 'b, 'c>,
terms: Vec<Box<Term>>,
blocks_cuts: bool,
- ) -> Result<Vec<QueryTerm>, ParserError> {
+ assume_dyn: bool,
+ ) -> Result<(Vec<QueryTerm>, Term), ParserError> {
let mut query_terms = vec![];
let mut work_queue = VecDeque::from(terms);
let mut machine_st = MachineState::new();
+ let mut dynamic_clause_terms = vec![];
+
while let Some(term) = work_queue.pop_front() {
let term = *term;
let op_dir = op_dir(&indices.index_src);
@@ -965,11 +968,22 @@ fn setup_query<'a, 'b, 'c>(
mark_cut_variable(&mut term);
}
+ if assume_dyn {
+ dynamic_clause_terms.push(term.clone());
+ }
+
query_terms.push(self.pre_query_term(indices, term)?);
}
}
- Ok(query_terms)
+ let dynamic_clause_body =
+ if let Some(term) = dynamic_clause_terms.pop() {
+ fold_by_str(dynamic_clause_terms.into_iter(), term, clause_name!(","))
+ } else {
+ Term::Constant(Cell::default(), Constant::Atom(clause_name!("true"), None))
+ };
+
+ Ok((query_terms, dynamic_clause_body))
}
fn setup_hook<'a, 'b, 'c>(
@@ -1003,16 +1017,16 @@ fn setup_rule<'a, 'b, 'c>(
blocks_cuts: bool,
assume_dyn: bool,
) -> Result<Rule, ParserError> {
- let head = *terms.first().cloned().unwrap();
+ let dynamic_term_head = *terms.first().cloned().unwrap();
let post_head_terms: Vec<_> = terms.drain(1 ..).collect();
- let tail = *post_head_terms.first().cloned().unwrap();
+ let (mut query_terms, dynamic_term_body) =
+ self.setup_query(indices, post_head_terms, blocks_cuts, assume_dyn)?;
if assume_dyn {
- self.dynamic_clauses.push((head, tail));
+ self.dynamic_clauses.push((dynamic_term_head, dynamic_term_body));
}
- let mut query_terms = self.setup_query(indices, post_head_terms, blocks_cuts)?;
let clauses = query_terms.drain(1 ..).collect();
let qt = query_terms.pop().unwrap();
@@ -1035,11 +1049,14 @@ fn try_term_to_query<'a, 'b, 'c>(
terms: Vec<Box<Term>>,
blocks_cuts: bool,
) -> Result<TopLevel, ParserError> {
- Ok(TopLevel::Query(self.setup_query(
+ let (result, _) = self.setup_query(
indices,
terms,
blocks_cuts,
- )?))
+ false,
+ )?;
+
+ Ok(TopLevel::Query(result))
}
fn compact_module_scoped_head<'a, 'b, 'c>(
