From 33ab3ac1536d129c923e73998ddf0dc0a8a6cb93 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Fri, 27 Jan 2017 23:26:25 -0700 Subject: [PATCH] codegen bug fix. --- src/l1/codegen.rs | 12 +++++++++++- src/main.rs | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/l1/codegen.rs b/src/l1/codegen.rs index b0027d9e..6579ef0b 100644 --- a/src/l1/codegen.rs +++ b/src/l1/codegen.rs @@ -137,6 +137,8 @@ trait CompilationTarget<'a> { fn argument_to_value(usize, usize) -> Self; fn subterm_to_variable(usize) -> Self; fn subterm_to_value(usize) -> Self; + + fn clause_arg_to_instr(usize) -> Self; } impl<'a> CompilationTarget<'a> for FactInstruction { @@ -165,6 +167,10 @@ impl<'a> CompilationTarget<'a> for FactInstruction { fn subterm_to_value(val: usize) -> Self { FactInstruction::UnifyValue(val) } + + fn clause_arg_to_instr(val: usize) -> Self { + FactInstruction::UnifyVariable(val) + } } impl<'a> CompilationTarget<'a> for QueryInstruction { @@ -193,6 +199,10 @@ impl<'a> CompilationTarget<'a> for QueryInstruction { fn subterm_to_value(val: usize) -> Self { QueryInstruction::SetValue(val) } + + fn clause_arg_to_instr(val: usize) -> Self { + QueryInstruction::SetValue(val) + } } fn to_structure<'a, Target>(tm: &mut TermMarker<'a>, @@ -212,7 +222,7 @@ fn non_var_subterm<'a, Target>(tm: &mut TermMarker<'a>, cell: &'a Cell) where Target: CompilationTarget<'a> { tm.mark_non_var(Level::Deep, cell); - Target::subterm_to_value(cell.get()) // should be to_value?? + Target::clause_arg_to_instr(cell.get()) } fn var_term<'a, Target>(tm: &mut TermMarker<'a>, diff --git a/src/main.rs b/src/main.rs index f221409d..00878d92 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,13 +29,13 @@ fn l1_repl() { Ok(TopLevel::Fact(fact)) => { let mut compiled_fact = compile_fact(&fact); let index = ms.code.len(); - + ms.code.append(&mut compiled_fact); ms.code_dir.insert((fact.name().clone(), fact.arity()), index); }, Ok(TopLevel::Query(query)) => { let compiled_query = compile_query(&query); - + for instruction in &compiled_query { ms.execute_query_instr(instruction); -- 2.54.0