inline comparison instructions.

This commit is contained in:
Mark Thom
2017-12-04 21:01:23 -07:00
parent 8e5aaf02a4
commit cf6a47272a
8 changed files with 110 additions and 123 deletions

View File

@@ -230,12 +230,16 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
ConjunctInfo::new(vs, num_of_chunks, has_deep_cut)
}
fn add_conditional_call_inlined(term: &InlinedQueryTerm, code: &mut Code)
fn add_conditional_call_inlined(_: &InlinedQueryTerm, code: &mut Code)
{
code.push(proceed!());
/*
match term {
&InlinedQueryTerm::IsAtomic(_) | &InlinedQueryTerm::IsVar(_) =>
code.push(proceed!())
};
*/
}
fn add_conditional_call(code: &mut Code, qt: &QueryTerm, pvs: usize)
@@ -276,10 +280,8 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
*ctrl = ControlInstruction::Execute(name, arity),
ControlInstruction::CallN(arity) =>
*ctrl = ControlInstruction::ExecuteN(arity),
ControlInstruction::CompareNumberCall(cmp) =>
*ctrl = ControlInstruction::CompareNumberExecute(cmp),
ControlInstruction::IsCall(r) =>
*ctrl = ControlInstruction::IsExecute(r),
ControlInstruction::IsCall(r, at) =>
*ctrl = ControlInstruction::IsExecute(r, at),
ControlInstruction::CatchCall =>
*ctrl = ControlInstruction::CatchExecute,
ControlInstruction::ThrowCall =>
@@ -293,21 +295,33 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
}
fn compile_inlined(&mut self, term: &'a InlinedQueryTerm, term_loc: GenContext, code: &mut Code)
-> Result<(), ParserError>
{
match term {
&InlinedQueryTerm::CompareNumber(cmp, ref terms) => {
let (mut lcode, at_1) = self.call_arith_eval(terms[0].as_ref(), 1)?;
let (mut rcode, at_2) = self.call_arith_eval(terms[1].as_ref(), 2)?;
code.append(&mut lcode);
code.append(&mut rcode);
code.push(compare_number_instr!(cmp,
at_1.unwrap_or(interm!(1)),
at_2.unwrap_or(interm!(2))));
},
&InlinedQueryTerm::IsAtomic(ref inner_term) =>
match inner_term[0].as_ref() {
&Term::AnonVar | &Term::Clause(_, _, _) | &Term::Cons(_, _, _) => {
code.push(fail!());
},
&Term::Constant(_, _) => {
code.push(succeed!());
},
&Term::Var(ref vr, ref name) => {
let r = self.mark_non_callable(name, 1, term_loc, vr, code);
code.push(is_atomic!(r));
}
},
match inner_term[0].as_ref() {
&Term::AnonVar | &Term::Clause(_, _, _) | &Term::Cons(_, _, _) => {
code.push(fail!());
},
&Term::Constant(_, _) => {
code.push(succeed!());
},
&Term::Var(ref vr, ref name) => {
let r = self.mark_non_callable(name, 1, term_loc, vr, code);
code.push(is_atomic!(r));
}
},
&InlinedQueryTerm::IsVar(ref inner_term) =>
match inner_term[0].as_ref() {
&Term::Constant(_, _) | &Term::Clause(_, _, _) | &Term::Cons(_, _, _) => {
@@ -322,9 +336,12 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
}
}
}
Ok(())
}
fn call_arith_eval(&self, term: &'a Term, target_int: usize) -> Result<Code, ArithmeticError> {
fn call_arith_eval(&self, term: &'a Term, target_int: usize) -> Result<ArithCont, ArithmeticError>
{
let mut evaluator = ArithmeticEvaluator::new(self.marker.bindings(), target_int);
evaluator.eval(term)
}
@@ -360,10 +377,10 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
});
},
&QueryTerm::Inlined(ref term) =>
self.compile_inlined(term, term_loc, code),
self.compile_inlined(term, term_loc, code)?,
&QueryTerm::Is(ref terms) => {
let mut arith_code = self.call_arith_eval(terms[1].as_ref(), 1)?;
code.append(&mut arith_code);
let (mut acode, at) = try!(self.call_arith_eval(terms[1].as_ref(), 1));
code.append(&mut acode);
match terms[0].as_ref() {
&Term::Var(ref vr, ref name) => {
@@ -373,35 +390,26 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
vr,
code);
code.push(is_call!(r));
code.push(is_call!(r, at.unwrap_or(interm!(1))));
},
&Term::Constant(_, Constant::Float(fl)) => {
code.push(query![put_constant!(Level::Shallow,
Constant::Float(fl),
temp_v!(1))]);
code.push(is_call!(temp_v!(1)));
code.push(is_call!(temp_v!(1), at.unwrap_or(interm!(1))));
},
&Term::Constant(_, Constant::Integer(ref bi)) => {
let bi = bi.clone();
code.push(query![put_constant!(Level::Shallow,
Constant::Integer(bi),
temp_v!(1))]);
code.push(is_call!(temp_v!(1)));
code.push(is_call!(temp_v!(1), at.unwrap_or(interm!(1))));
},
_ => {
code.push(fail!());
}
}
},
&QueryTerm::CompareNumber(cmp, ref terms) => {
let mut larith_code = self.call_arith_eval(terms[0].as_ref(), 1)?;
let mut rarith_code = self.call_arith_eval(terms[1].as_ref(), 2)?;
code.append(&mut larith_code);
code.append(&mut rarith_code);
code.push(compare_number_call!(cmp));
},
},
_ if chunk_num == 0 => {
self.marker.reset_arg(term.arity());