minor cleanup.

This commit is contained in:
Mark Thom
2018-02-08 18:29:45 -07:00
parent 1b4d1c04c9
commit df3e8b8fce
4 changed files with 51 additions and 51 deletions

View File

@@ -155,7 +155,7 @@ impl RegType {
} }
} }
#[derive(Clone, Copy)] #[derive(PartialEq, Eq, Clone, Copy)]
pub enum VarReg { pub enum VarReg {
ArgAndNorm(RegType, usize), ArgAndNorm(RegType, usize),
Norm(RegType) Norm(RegType)
@@ -306,7 +306,7 @@ pub enum Fixity {
#[derive(Clone, Eq, Hash, PartialEq)] #[derive(Clone, Eq, Hash, PartialEq)]
pub enum Constant { pub enum Constant {
Atom(TabledRc<Atom>), Atom(TabledRc<Atom>),
Number(Number), Number(Number),
String(Rc<String>), String(Rc<String>),
Usize(usize), Usize(usize),
EmptyList EmptyList
@@ -320,7 +320,7 @@ impl fmt::Display for Constant {
&Constant::EmptyList => &Constant::EmptyList =>
write!(f, "[]"), write!(f, "[]"),
&Constant::Number(ref n) => &Constant::Number(ref n) =>
write!(f, "{}", n), write!(f, "{}", n),
&Constant::String(ref s) => &Constant::String(ref s) =>
write!(f, "{}", s), write!(f, "{}", s),
&Constant::Usize(integer) => &Constant::Usize(integer) =>
@@ -329,7 +329,7 @@ impl fmt::Display for Constant {
} }
} }
#[derive(Clone)] #[derive(PartialEq, Eq, Clone)]
pub enum Term { pub enum Term {
AnonVar, AnonVar,
Clause(Cell<RegType>, TabledRc<Atom>, Vec<Box<Term>>, Option<Fixity>), Clause(Cell<RegType>, TabledRc<Atom>, Vec<Box<Term>>, Option<Fixity>),
@@ -339,7 +339,7 @@ pub enum Term {
} }
pub enum InlinedQueryTerm { pub enum InlinedQueryTerm {
CompareNumber(CompareNumberQT, Vec<Box<Term>>), CompareNumber(CompareNumberQT, Vec<Box<Term>>),
IsAtomic(Vec<Box<Term>>), IsAtomic(Vec<Box<Term>>),
IsCompound(Vec<Box<Term>>), IsCompound(Vec<Box<Term>>),
IsInteger(Vec<Box<Term>>), IsInteger(Vec<Box<Term>>),
@@ -347,13 +347,13 @@ pub enum InlinedQueryTerm {
IsString(Vec<Box<Term>>), IsString(Vec<Box<Term>>),
IsFloat(Vec<Box<Term>>), IsFloat(Vec<Box<Term>>),
IsNonVar(Vec<Box<Term>>), IsNonVar(Vec<Box<Term>>),
IsVar(Vec<Box<Term>>), IsVar(Vec<Box<Term>>),
} }
impl InlinedQueryTerm { impl InlinedQueryTerm {
pub fn arity(&self) -> usize { pub fn arity(&self) -> usize {
match self { match self {
&InlinedQueryTerm::CompareNumber(_, _) => 2, &InlinedQueryTerm::CompareNumber(_, _) => 2,
&InlinedQueryTerm::IsAtomic(_) => 1, &InlinedQueryTerm::IsAtomic(_) => 1,
&InlinedQueryTerm::IsCompound(_) => 1, &InlinedQueryTerm::IsCompound(_) => 1,
&InlinedQueryTerm::IsFloat(_) => 1, &InlinedQueryTerm::IsFloat(_) => 1,
@@ -361,7 +361,7 @@ impl InlinedQueryTerm {
&InlinedQueryTerm::IsString(_) => 1, &InlinedQueryTerm::IsString(_) => 1,
&InlinedQueryTerm::IsNonVar(_) => 1, &InlinedQueryTerm::IsNonVar(_) => 1,
&InlinedQueryTerm::IsInteger(_) => 1, &InlinedQueryTerm::IsInteger(_) => 1,
&InlinedQueryTerm::IsVar(_) => 1, &InlinedQueryTerm::IsVar(_) => 1,
} }
} }
} }
@@ -376,6 +376,19 @@ pub enum CompareNumberQT {
Equal Equal
} }
impl CompareNumberQT {
fn name<'a>(self) -> &'a str {
match self {
CompareNumberQT::GreaterThan => ">",
CompareNumberQT::LessThan => "<",
CompareNumberQT::GreaterThanOrEqual => ">=",
CompareNumberQT::LessThanOrEqual => "=<",
CompareNumberQT::NotEqual => "=\\=",
CompareNumberQT::Equal => "=:="
}
}
}
// vars of predicate, toplevel offset. Vec<Term> is always a vector // vars of predicate, toplevel offset. Vec<Term> is always a vector
// of vars (we get their adjoining cells this way). // of vars (we get their adjoining cells this way).
pub type JumpStub = Vec<Term>; pub type JumpStub = Vec<Term>;
@@ -383,7 +396,7 @@ pub type JumpStub = Vec<Term>;
pub enum QueryTerm { pub enum QueryTerm {
Arg(Vec<Box<Term>>), Arg(Vec<Box<Term>>),
CallN(Vec<Box<Term>>), CallN(Vec<Box<Term>>),
Catch(Vec<Box<Term>>), Catch(Vec<Box<Term>>),
Cut, Cut,
Display(Vec<Box<Term>>), Display(Vec<Box<Term>>),
DuplicateTerm(Vec<Box<Term>>), DuplicateTerm(Vec<Box<Term>>),
@@ -402,7 +415,7 @@ impl QueryTerm {
&QueryTerm::Arg(_) => 3, &QueryTerm::Arg(_) => 3,
&QueryTerm::Catch(_) => 3, &QueryTerm::Catch(_) => 3,
&QueryTerm::Display(_) => 1, &QueryTerm::Display(_) => 1,
&QueryTerm::Throw(_) => 1, &QueryTerm::Throw(_) => 1,
&QueryTerm::DuplicateTerm(_) => 2, &QueryTerm::DuplicateTerm(_) => 2,
&QueryTerm::Functor(_) => 3, &QueryTerm::Functor(_) => 3,
&QueryTerm::Inlined(ref term) => term.arity(), &QueryTerm::Inlined(ref term) => term.arity(),
@@ -421,13 +434,12 @@ pub struct Rule {
pub clauses: Vec<QueryTerm> pub clauses: Vec<QueryTerm>
} }
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
pub enum ClauseType<'a> { pub enum ClauseType<'a> {
Arg, Arg,
CallN, CallN,
Catch, Catch,
CompareNumber(CompareNumberQT),
Deep(Level, &'a Cell<RegType>, &'a TabledRc<Atom>, Option<Fixity>), Deep(Level, &'a Cell<RegType>, &'a TabledRc<Atom>, Option<Fixity>),
Display, Display,
DuplicateTerm, DuplicateTerm,
@@ -444,17 +456,18 @@ impl<'a> ClauseType<'a> {
&ClauseType::Arg => "arg", &ClauseType::Arg => "arg",
&ClauseType::CallN => "call", &ClauseType::CallN => "call",
&ClauseType::Catch => "catch", &ClauseType::Catch => "catch",
&ClauseType::CompareNumber(qt) => qt.name(),
&ClauseType::Display => "display", &ClauseType::Display => "display",
&ClauseType::Deep(_, _, name, _) => name.as_str(), &ClauseType::Deep(_, _, name, _) => name.as_str(),
&ClauseType::DuplicateTerm => "duplicate_term", &ClauseType::DuplicateTerm => "duplicate_term",
&ClauseType::Functor => "functor", &ClauseType::Functor => "functor",
&ClauseType::Is => "is", &ClauseType::Is => "is",
&ClauseType::Root(name) => name.as_str(), &ClauseType::Root(name) => name.as_str(),
&ClauseType::SetupCallCleanup => "setup_call_cleanup", &ClauseType::SetupCallCleanup => "setup_call_cleanup",
&ClauseType::Throw => "throw" &ClauseType::Throw => "throw"
} }
} }
pub fn level_of_subterms(self) -> Level { pub fn level_of_subterms(self) -> Level {
match self { match self {
ClauseType::Deep(..) => Level::Deep, ClauseType::Deep(..) => Level::Deep,
@@ -531,7 +544,7 @@ impl fmt::Display for Number {
match self { match self {
&Number::Float(fl) => write!(f, "{}", fl), &Number::Float(fl) => write!(f, "{}", fl),
&Number::Integer(ref bi) => write!(f, "{}", bi), &Number::Integer(ref bi) => write!(f, "{}", bi),
&Number::Rational(ref r) => write!(f, "{}", r) &Number::Rational(ref r) => write!(f, "{}", r)
} }
} }
} }
@@ -558,7 +571,7 @@ impl Number {
NumberPair::Rational(n1, n2) => n1 > n2 NumberPair::Rational(n1, n2) => n1 > n2
} }
} }
pub fn gte(self, n2: Number) -> bool { pub fn gte(self, n2: Number) -> bool {
match NumberPair::from(self, n2) { match NumberPair::from(self, n2) {
NumberPair::Integer(n1, n2) => n1 >= n2, NumberPair::Integer(n1, n2) => n1 >= n2,
@@ -597,7 +610,7 @@ impl Number {
NumberPair::Float(n1, n2) => n1 == n2, NumberPair::Float(n1, n2) => n1 == n2,
NumberPair::Rational(n1, n2) => n1 == n2 NumberPair::Rational(n1, n2) => n1 == n2
} }
} }
} }
pub enum NumberPair { pub enum NumberPair {
@@ -655,7 +668,7 @@ impl NumberPair {
(Number::Float(n1), Number::Float(n2)) => (Number::Float(n1), Number::Float(n2)) =>
NumberPair::Float(n1, n2), NumberPair::Float(n1, n2),
(Number::Rational(n1), Number::Rational(n2)) => (Number::Rational(n1), Number::Rational(n2)) =>
NumberPair::Rational(n1, n2), NumberPair::Rational(n1, n2),
(Number::Integer(n1), Number::Float(n2)) => (Number::Integer(n1), Number::Float(n2)) =>
Self::integer_float_pair(n1, n2), Self::integer_float_pair(n1, n2),
(Number::Float(n1), Number::Integer(n2)) => (Number::Float(n1), Number::Integer(n2)) =>
@@ -713,10 +726,10 @@ impl Mul<Number> for Number {
Number::Integer(Rc::new(&*n1 * &*n2)), Number::Integer(Rc::new(&*n1 * &*n2)),
NumberPair::Rational(r1, r2) => NumberPair::Rational(r1, r2) =>
Number::Rational(Rc::new(&*r1 * &*r2)) Number::Rational(Rc::new(&*r1 * &*r2))
} }
} }
} }
impl Div<Number> for Number { impl Div<Number> for Number {
type Output = Number; type Output = Number;
@@ -796,7 +809,7 @@ pub enum ArithmeticInstruction {
pub enum BuiltInInstruction { pub enum BuiltInInstruction {
CleanUpBlock, CleanUpBlock,
CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm), CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
EraseBall, EraseBall,
Fail, Fail,
GetArgCall, GetArgCall,
@@ -849,7 +862,7 @@ pub enum ControlInstruction {
GotoCall(usize, usize), // p, arity. GotoCall(usize, usize), // p, arity.
GotoExecute(usize, usize), // p, arity. GotoExecute(usize, usize), // p, arity.
JmpByCall(usize, usize), // arity, global_offset. JmpByCall(usize, usize), // arity, global_offset.
JmpByExecute(usize, usize), JmpByExecute(usize, usize),
IsCall(RegType, ArithmeticTerm), IsCall(RegType, ArithmeticTerm),
IsExecute(RegType, ArithmeticTerm), IsExecute(RegType, ArithmeticTerm),
Proceed, Proceed,
@@ -877,7 +890,7 @@ impl ControlInstruction {
&ControlInstruction::ThrowCall => true, &ControlInstruction::ThrowCall => true,
&ControlInstruction::ThrowExecute => true, &ControlInstruction::ThrowExecute => true,
&ControlInstruction::GetCleanerCall => true, &ControlInstruction::GetCleanerCall => true,
&ControlInstruction::GotoCall(..) => true, &ControlInstruction::GotoCall(..) => true,
&ControlInstruction::GotoExecute(..) => true, &ControlInstruction::GotoExecute(..) => true,
&ControlInstruction::Proceed => true, &ControlInstruction::Proceed => true,
&ControlInstruction::IsCall(..) => true, &ControlInstruction::IsCall(..) => true,
@@ -967,7 +980,7 @@ impl Addr {
_ => false _ => false
} }
} }
pub fn as_var(&self) -> Option<Ref> { pub fn as_var(&self) -> Option<Ref> {
match self { match self {
&Addr::HeapCell(hc) => Some(Ref::HeapCell(hc)), &Addr::HeapCell(hc) => Some(Ref::HeapCell(hc)),
@@ -1069,7 +1082,7 @@ impl Heap {
pub fn with_capacity(cap: usize) -> Self { pub fn with_capacity(cap: usize) -> Self {
Heap { heap: Vec::with_capacity(cap), h: 0 } Heap { heap: Vec::with_capacity(cap), h: 0 }
} }
pub fn push(&mut self, val: HeapCellValue) { pub fn push(&mut self, val: HeapCellValue) {
self.heap.push(val); self.heap.push(val);
self.h += 1; self.h += 1;
@@ -1086,7 +1099,7 @@ impl Heap {
pub fn append(&mut self, vals: Vec<HeapCellValue>) { pub fn append(&mut self, vals: Vec<HeapCellValue>) {
let n = vals.len(); let n = vals.len();
self.heap.extend(vals.into_iter()); self.heap.extend(vals.into_iter());
self.h += n; self.h += n;
} }

View File

@@ -100,23 +100,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
{ {
match self.marker.bindings().get(name) { match self.marker.bindings().get(name) {
Some(&VarData::Temp(_, t, _)) if t != 0 => RegType::Temp(t), Some(&VarData::Temp(_, t, _)) if t != 0 => RegType::Temp(t),
Some(&VarData::Perm(p)) if p != 0 => Some(&VarData::Perm(p)) if p != 0 => RegType::Perm(p),
/* if let GenContext::Last(chunk_num) = term_loc {
let mut target = Vec::new();
self.marker.evacuate_arg(chunk_num, &mut target);
self.marker.reset_arg(arity);
self.marker.mark_var(name, Level::Shallow, vr, term_loc, &mut target);
if !target.is_empty() {
code.push(Line::Query(target));
}
vr.get().norm()
} else { */
RegType::Perm(p),
//},
_ => { _ => {
let mut target = Vec::new(); let mut target = Vec::new();
@@ -422,7 +406,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
match inner_term[0].as_ref() { match inner_term[0].as_ref() {
&Term::AnonVar => { &Term::AnonVar => {
code.push(fail!()); code.push(fail!());
}, },
&Term::Var(ref vr, ref name) => { &Term::Var(ref vr, ref name) => {
let r = self.mark_non_callable(name, 1, term_loc, vr, code); let r = self.mark_non_callable(name, 1, term_loc, vr, code);
code.push(is_nonvar!(r)); code.push(is_nonvar!(r));
@@ -524,7 +508,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
_ if chunk_num == 0 => { _ if chunk_num == 0 => {
self.marker.reset_arg(term.arity()); self.marker.reset_arg(term.arity());
let iter = term.post_order_iter(); let iter = term.post_order_iter();
let query = self.compile_target(iter, term_loc, is_exposed); let query = self.compile_target(iter, term_loc, is_exposed);
if !query.is_empty() { if !query.is_empty() {

View File

@@ -60,10 +60,13 @@ impl<'a> QueryIterator<'a> {
let state = TermIterState::Clause(0, ClauseType::Display, terms); let state = TermIterState::Clause(0, ClauseType::Display, terms);
QueryIterator { state_stack: vec![state] } QueryIterator { state_stack: vec![state] }
}, },
&QueryTerm::Inlined(InlinedQueryTerm::CompareNumber(_, ref terms)) &QueryTerm::Inlined(InlinedQueryTerm::CompareNumber(qt, ref terms)) => {
| &QueryTerm::Is(ref terms) => { let state = TermIterState::Clause(0, ClauseType::CompareNumber(qt), terms);
let state = TermIterState::Clause(0, ClauseType::Is, terms); QueryIterator { state_stack: vec![state] }
QueryIterator { state_stack: vec![state] } },
&QueryTerm::Is(ref terms) => {
let state = TermIterState::Clause(0, ClauseType::Is, terms);
QueryIterator { state_stack: vec![state] }
}, },
&QueryTerm::Inlined(InlinedQueryTerm::IsAtomic(ref terms)) &QueryTerm::Inlined(InlinedQueryTerm::IsAtomic(ref terms))
| &QueryTerm::Inlined(InlinedQueryTerm::IsInteger(ref terms)) | &QueryTerm::Inlined(InlinedQueryTerm::IsInteger(ref terms))

View File

@@ -554,7 +554,7 @@ macro_rules! check_cp_execute {
macro_rules! get_cleaner_call { macro_rules! get_cleaner_call {
() => ( () => (
Line::Control(ControlInstruction::GetCleanerCall) Line::Control(ControlInstruction::GetCleanerCall)
) )
} }
macro_rules! restore_cut_policy { macro_rules! restore_cut_policy {