remove Term impl
This commit is contained in:
@@ -17,24 +17,6 @@ pub enum Term {
|
|||||||
Var(Var)
|
Var(Var)
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Term {
|
|
||||||
pub fn name(&self) -> &Atom {
|
|
||||||
match self {
|
|
||||||
&Term::Atom(ref atom) => atom,
|
|
||||||
&Term::Var(ref var) => var,
|
|
||||||
&Term::Clause(ref atom, _) => atom
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn is_variable(&self) -> bool {
|
|
||||||
if let &Term::Var(_) = self {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub enum MachineInstruction {
|
pub enum MachineInstruction {
|
||||||
GetStructure(Atom, usize, usize),
|
GetStructure(Atom, usize, usize),
|
||||||
|
|||||||
@@ -60,10 +60,12 @@ 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 let &Term::Var(ref var) = t.as_ref() {
|
||||||
|
if !variable_allocs.contains_key(var) {
|
||||||
counter += 1;
|
counter += 1;
|
||||||
variable_allocs.insert(t.name(), (counter, false));
|
variable_allocs.insert(var, (counter, false));
|
||||||
} else if !t.is_variable() {
|
}
|
||||||
|
} else {
|
||||||
counter += 1;
|
counter += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -71,7 +73,7 @@ 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() {
|
||||||
if t.is_variable() {
|
if let &Term::Var(_) = t.as_ref() {
|
||||||
counter -= 1;
|
counter -= 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -142,13 +144,15 @@ pub fn compile_fact<'a>(t: &'a Term) -> Program {
|
|||||||
let mut counter : usize = reg;
|
let mut counter : usize = reg;
|
||||||
|
|
||||||
for t in terms {
|
for t in terms {
|
||||||
if t.is_variable() && !variable_allocs.contains_key(t.name()) {
|
if let &Term::Var(ref var) = t.as_ref() {
|
||||||
variable_allocs.insert(t.name(), counter);
|
if !variable_allocs.contains_key(var) {
|
||||||
|
variable_allocs.insert(var, counter);
|
||||||
fact.push(MachineInstruction::UnifyVariable(counter));
|
fact.push(MachineInstruction::UnifyVariable(counter));
|
||||||
counter += 1;
|
counter += 1;
|
||||||
} else if t.is_variable() {
|
} else {
|
||||||
let r = variable_allocs.get(t.name()).unwrap();
|
let r = variable_allocs.get(var).unwrap();
|
||||||
fact.push(MachineInstruction::UnifyValue(*r));
|
fact.push(MachineInstruction::UnifyValue(*r));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
fact.push(MachineInstruction::UnifyVariable(counter));
|
fact.push(MachineInstruction::UnifyVariable(counter));
|
||||||
queue.push_back((counter, t));
|
queue.push_back((counter, t));
|
||||||
|
|||||||
Reference in New Issue
Block a user