}
}
-#[derive(Clone, Copy)]
+#[derive(PartialEq, Eq, Clone, Copy)]
pub enum VarReg {
ArgAndNorm(RegType, usize),
Norm(RegType)
#[derive(Clone, Eq, Hash, PartialEq)]
pub enum Constant {
Atom(TabledRc<Atom>),
- Number(Number),
+ Number(Number),
String(Rc<String>),
Usize(usize),
EmptyList
&Constant::EmptyList =>
write!(f, "[]"),
&Constant::Number(ref n) =>
- write!(f, "{}", n),
+ write!(f, "{}", n),
&Constant::String(ref s) =>
write!(f, "{}", s),
&Constant::Usize(integer) =>
}
}
-#[derive(Clone)]
+#[derive(PartialEq, Eq, Clone)]
pub enum Term {
AnonVar,
Clause(Cell<RegType>, TabledRc<Atom>, Vec<Box<Term>>, Option<Fixity>),
}
pub enum InlinedQueryTerm {
- CompareNumber(CompareNumberQT, Vec<Box<Term>>),
+ CompareNumber(CompareNumberQT, Vec<Box<Term>>),
IsAtomic(Vec<Box<Term>>),
IsCompound(Vec<Box<Term>>),
IsInteger(Vec<Box<Term>>),
IsString(Vec<Box<Term>>),
IsFloat(Vec<Box<Term>>),
IsNonVar(Vec<Box<Term>>),
- IsVar(Vec<Box<Term>>),
+ IsVar(Vec<Box<Term>>),
}
impl InlinedQueryTerm {
pub fn arity(&self) -> usize {
match self {
- &InlinedQueryTerm::CompareNumber(_, _) => 2,
+ &InlinedQueryTerm::CompareNumber(_, _) => 2,
&InlinedQueryTerm::IsAtomic(_) => 1,
&InlinedQueryTerm::IsCompound(_) => 1,
&InlinedQueryTerm::IsFloat(_) => 1,
&InlinedQueryTerm::IsString(_) => 1,
&InlinedQueryTerm::IsNonVar(_) => 1,
&InlinedQueryTerm::IsInteger(_) => 1,
- &InlinedQueryTerm::IsVar(_) => 1,
+ &InlinedQueryTerm::IsVar(_) => 1,
}
}
}
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
// of vars (we get their adjoining cells this way).
pub type JumpStub = Vec<Term>;
pub enum QueryTerm {
Arg(Vec<Box<Term>>),
CallN(Vec<Box<Term>>),
- Catch(Vec<Box<Term>>),
+ Catch(Vec<Box<Term>>),
Cut,
Display(Vec<Box<Term>>),
DuplicateTerm(Vec<Box<Term>>),
&QueryTerm::Arg(_) => 3,
&QueryTerm::Catch(_) => 3,
&QueryTerm::Display(_) => 1,
- &QueryTerm::Throw(_) => 1,
+ &QueryTerm::Throw(_) => 1,
&QueryTerm::DuplicateTerm(_) => 2,
&QueryTerm::Functor(_) => 3,
&QueryTerm::Inlined(ref term) => term.arity(),
pub clauses: Vec<QueryTerm>
}
-
-
#[derive(Clone, Copy)]
pub enum ClauseType<'a> {
Arg,
CallN,
Catch,
+ CompareNumber(CompareNumberQT),
Deep(Level, &'a Cell<RegType>, &'a TabledRc<Atom>, Option<Fixity>),
Display,
DuplicateTerm,
&ClauseType::Arg => "arg",
&ClauseType::CallN => "call",
&ClauseType::Catch => "catch",
+ &ClauseType::CompareNumber(qt) => qt.name(),
&ClauseType::Display => "display",
- &ClauseType::Deep(_, _, name, _) => name.as_str(),
+ &ClauseType::Deep(_, _, name, _) => name.as_str(),
&ClauseType::DuplicateTerm => "duplicate_term",
- &ClauseType::Functor => "functor",
+ &ClauseType::Functor => "functor",
&ClauseType::Is => "is",
&ClauseType::Root(name) => name.as_str(),
&ClauseType::SetupCallCleanup => "setup_call_cleanup",
&ClauseType::Throw => "throw"
}
}
-
+
pub fn level_of_subterms(self) -> Level {
match self {
ClauseType::Deep(..) => Level::Deep,
match self {
&Number::Float(fl) => write!(f, "{}", fl),
&Number::Integer(ref bi) => write!(f, "{}", bi),
- &Number::Rational(ref r) => write!(f, "{}", r)
+ &Number::Rational(ref r) => write!(f, "{}", r)
}
}
}
NumberPair::Rational(n1, n2) => n1 > n2
}
}
-
+
pub fn gte(self, n2: Number) -> bool {
match NumberPair::from(self, n2) {
NumberPair::Integer(n1, n2) => n1 >= n2,
NumberPair::Float(n1, n2) => n1 == n2,
NumberPair::Rational(n1, n2) => n1 == n2
}
- }
+ }
}
pub enum NumberPair {
(Number::Float(n1), Number::Float(n2)) =>
NumberPair::Float(n1, n2),
(Number::Rational(n1), Number::Rational(n2)) =>
- NumberPair::Rational(n1, n2),
+ NumberPair::Rational(n1, n2),
(Number::Integer(n1), Number::Float(n2)) =>
Self::integer_float_pair(n1, n2),
(Number::Float(n1), Number::Integer(n2)) =>
Number::Integer(Rc::new(&*n1 * &*n2)),
NumberPair::Rational(r1, r2) =>
Number::Rational(Rc::new(&*r1 * &*r2))
- }
+ }
}
}
-
+
impl Div<Number> for Number {
type Output = Number;
pub enum BuiltInInstruction {
CleanUpBlock,
- CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
+ CompareNumber(CompareNumberQT, ArithmeticTerm, ArithmeticTerm),
EraseBall,
Fail,
GetArgCall,
GotoCall(usize, usize), // p, arity.
GotoExecute(usize, usize), // p, arity.
JmpByCall(usize, usize), // arity, global_offset.
- JmpByExecute(usize, usize),
+ JmpByExecute(usize, usize),
IsCall(RegType, ArithmeticTerm),
IsExecute(RegType, ArithmeticTerm),
Proceed,
&ControlInstruction::ThrowCall => true,
&ControlInstruction::ThrowExecute => true,
&ControlInstruction::GetCleanerCall => true,
- &ControlInstruction::GotoCall(..) => true,
+ &ControlInstruction::GotoCall(..) => true,
&ControlInstruction::GotoExecute(..) => true,
&ControlInstruction::Proceed => true,
&ControlInstruction::IsCall(..) => true,
_ => false
}
}
-
+
pub fn as_var(&self) -> Option<Ref> {
match self {
&Addr::HeapCell(hc) => Some(Ref::HeapCell(hc)),
pub fn with_capacity(cap: usize) -> Self {
Heap { heap: Vec::with_capacity(cap), h: 0 }
}
-
+
pub fn push(&mut self, val: HeapCellValue) {
self.heap.push(val);
self.h += 1;
pub fn append(&mut self, vals: Vec<HeapCellValue>) {
let n = vals.len();
-
+
self.heap.extend(vals.into_iter());
self.h += n;
}