From e4e9b09175ffb4d7f0c2fcae0509658d704e73ef Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Sat, 16 Sep 2017 15:25:11 -0600 Subject: [PATCH] fix indexing bug on anonvars. --- src/prolog/codegen.rs | 15 +++++++++------ src/prolog/io.rs | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/prolog/codegen.rs b/src/prolog/codegen.rs index 50377140..d67c32e0 100644 --- a/src/prolog/codegen.rs +++ b/src/prolog/codegen.rs @@ -462,13 +462,16 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker> let mut left_index = 0; for (right_index, clause) in clauses.iter().enumerate() { - if let Some(&Term::Var(_, _)) = clause.first_arg() { - if left_index < right_index { - subseqs.push((left_index, right_index)); - } + match clause.first_arg() { + Some(&Term::Var(_, _)) | Some(&Term::AnonVar) => { + if left_index < right_index { + subseqs.push((left_index, right_index)); + } - subseqs.push((right_index, right_index + 1)); - left_index = right_index + 1; + subseqs.push((right_index, right_index + 1)); + left_index = right_index + 1; + }, + _ => {} } } diff --git a/src/prolog/io.rs b/src/prolog/io.rs index cb005a04..6610c233 100644 --- a/src/prolog/io.rs +++ b/src/prolog/io.rs @@ -254,8 +254,8 @@ pub fn eval<'a, 'b: 'a>(wam: &'a mut Machine, tl: &'b TopLevel) -> EvalSession<' wam.submit_decl(decl), &TopLevel::Predicate(ref clauses) => { let mut cg = CodeGenerator::::new(); - let compiled_pred = cg.compile_predicate(clauses); - + + let compiled_pred = cg.compile_predicate(clauses); wam.add_predicate(clauses, compiled_pred) }, &TopLevel::Fact(ref fact) => { -- 2.54.0