codegen fix

This commit is contained in:
Mark Thom
2016-10-30 00:19:25 -06:00
parent 63075c9739
commit 509b7838c7
3 changed files with 14 additions and 9 deletions

View File

@@ -59,7 +59,7 @@ pub fn compile_query<'a>(t: &'a Term) -> Program
let mut counter : usize = max_reg_used; // r + 1; let mut counter : usize = max_reg_used; // r + 1;
for t in terms { for t in terms {
if t.is_variable() && !variable_allocs.contains_key(t.name()) { if t.is_variable() && !variable_allocs.contains_key(t.name()) {
counter += 1; counter += 1;
variable_allocs.insert(t.name(), (counter, false)); variable_allocs.insert(t.name(), (counter, false));
@@ -71,9 +71,12 @@ pub fn compile_query<'a>(t: &'a Term) -> Program
max_reg_used = counter; max_reg_used = counter;
for t in terms.iter().rev() { for t in terms.iter().rev() {
let r = if t.is_variable() { if t.is_variable() {
variable_allocs.get(t.name()).unwrap().0 counter -= 1;
} else { continue;
}
let r = {
let oc = counter; let oc = counter;
counter -= 1; counter -= 1;
oc oc
@@ -85,7 +88,7 @@ pub fn compile_query<'a>(t: &'a Term) -> Program
&Term::Clause(ref atom, ref terms) => &Term::Clause(ref atom, ref terms) =>
stack.push(IntTerm::UnfinishedClause(r, atom, terms)), stack.push(IntTerm::UnfinishedClause(r, atom, terms)),
_ => {} _ => {}
}; };
} }
}, },
IntTerm::FinishedAtom(r, atom) => IntTerm::FinishedAtom(r, atom) =>
@@ -112,7 +115,7 @@ pub fn compile_query<'a>(t: &'a Term) -> Program
} else { } else {
query.push(MachineInstruction::SetValue(counter)); query.push(MachineInstruction::SetValue(counter));
counter += 1; counter += 1;
} }
} }
max_reg_used = counter - 1; max_reg_used = counter - 1;

View File

@@ -170,7 +170,9 @@ impl MachineState {
self.registers[reg] = self.heap[self.h].clone(); self.registers[reg] = self.heap[self.h].clone();
self.h += 1; self.h += 1;
} }
}; };
self.s += 1;
}, },
MachineInstruction::UnifyValue(reg) => { MachineInstruction::UnifyValue(reg) => {
let s = self.s; let s = self.s;

View File

@@ -35,8 +35,8 @@ fn l0_repl<'a>() {
let program = compile_fact(&fact); let program = compile_fact(&fact);
ms = MachineState::new(); ms = MachineState::new();
ms.program = Some(program); ms.program = Some(program);
println!("Program stored."); println!("Program stored.");
}, },
Ok(TopLevel::Query(query)) => { Ok(TopLevel::Query(query)) => {