support number/1
This commit is contained in:
@@ -74,6 +74,7 @@ pub enum InlinedClauseType {
|
|||||||
IsAtomic(RegType),
|
IsAtomic(RegType),
|
||||||
IsCompound(RegType),
|
IsCompound(RegType),
|
||||||
IsInteger(RegType),
|
IsInteger(RegType),
|
||||||
|
IsNumber(RegType),
|
||||||
IsRational(RegType),
|
IsRational(RegType),
|
||||||
IsFloat(RegType),
|
IsFloat(RegType),
|
||||||
IsNonVar(RegType),
|
IsNonVar(RegType),
|
||||||
@@ -103,6 +104,7 @@ ref_thread_local! {
|
|||||||
m.insert(("atomic", 1), ClauseType::Inlined(InlinedClauseType::IsAtomic(r1)));
|
m.insert(("atomic", 1), ClauseType::Inlined(InlinedClauseType::IsAtomic(r1)));
|
||||||
m.insert(("compound", 1), ClauseType::Inlined(InlinedClauseType::IsCompound(r1)));
|
m.insert(("compound", 1), ClauseType::Inlined(InlinedClauseType::IsCompound(r1)));
|
||||||
m.insert(("integer", 1), ClauseType::Inlined(InlinedClauseType::IsInteger(r1)));
|
m.insert(("integer", 1), ClauseType::Inlined(InlinedClauseType::IsInteger(r1)));
|
||||||
|
m.insert(("number", 1), ClauseType::Inlined(InlinedClauseType::IsNumber(r1)));
|
||||||
m.insert(("rational", 1), ClauseType::Inlined(InlinedClauseType::IsRational(r1)));
|
m.insert(("rational", 1), ClauseType::Inlined(InlinedClauseType::IsRational(r1)));
|
||||||
m.insert(("float", 1), ClauseType::Inlined(InlinedClauseType::IsFloat(r1)));
|
m.insert(("float", 1), ClauseType::Inlined(InlinedClauseType::IsFloat(r1)));
|
||||||
m.insert(("nonvar", 1), ClauseType::Inlined(InlinedClauseType::IsNonVar(r1)));
|
m.insert(("nonvar", 1), ClauseType::Inlined(InlinedClauseType::IsNonVar(r1)));
|
||||||
@@ -136,6 +138,7 @@ impl InlinedClauseType {
|
|||||||
&InlinedClauseType::IsAtom(..) => "atom",
|
&InlinedClauseType::IsAtom(..) => "atom",
|
||||||
&InlinedClauseType::IsAtomic(..) => "atomic",
|
&InlinedClauseType::IsAtomic(..) => "atomic",
|
||||||
&InlinedClauseType::IsCompound(..) => "compound",
|
&InlinedClauseType::IsCompound(..) => "compound",
|
||||||
|
&InlinedClauseType::IsNumber(..) => "number",
|
||||||
&InlinedClauseType::IsInteger(..) => "integer",
|
&InlinedClauseType::IsInteger(..) => "integer",
|
||||||
&InlinedClauseType::IsRational(..) => "rational",
|
&InlinedClauseType::IsRational(..) => "rational",
|
||||||
&InlinedClauseType::IsFloat(..) => "float",
|
&InlinedClauseType::IsFloat(..) => "float",
|
||||||
|
|||||||
@@ -474,6 +474,23 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<TermMarker> {
|
|||||||
code.push(fail!());
|
code.push(fail!());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
&InlinedClauseType::IsNumber(..) => match terms[0].as_ref() {
|
||||||
|
&Term::Constant(_, Constant::Float(_)) |
|
||||||
|
&Term::Constant(_, Constant::Rational(_)) |
|
||||||
|
&Term::Constant(_, Constant::Integer(_)) |
|
||||||
|
&Term::Constant(_, Constant::Fixnum(_)) |
|
||||||
|
&Term::Constant(_, Constant::Usize(_)) => {
|
||||||
|
code.push(succeed!());
|
||||||
|
}
|
||||||
|
&Term::Var(ref vr, ref name) => {
|
||||||
|
self.marker.reset_arg(1);
|
||||||
|
let r = self.mark_non_callable(name.clone(), 1, term_loc, vr, code);
|
||||||
|
code.push(is_number!(r));
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
code.push(fail!());
|
||||||
|
}
|
||||||
|
},
|
||||||
&InlinedClauseType::IsNonVar(..) => match terms[0].as_ref() {
|
&InlinedClauseType::IsNonVar(..) => match terms[0].as_ref() {
|
||||||
&Term::AnonVar => {
|
&Term::AnonVar => {
|
||||||
code.push(fail!());
|
code.push(fail!());
|
||||||
@@ -489,7 +506,8 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<TermMarker> {
|
|||||||
},
|
},
|
||||||
&InlinedClauseType::IsInteger(..) => match terms[0].as_ref() {
|
&InlinedClauseType::IsInteger(..) => match terms[0].as_ref() {
|
||||||
&Term::Constant(_, Constant::Integer(_)) |
|
&Term::Constant(_, Constant::Integer(_)) |
|
||||||
&Term::Constant(_, Constant::Fixnum(_)) => {
|
&Term::Constant(_, Constant::Fixnum(_)) |
|
||||||
|
&Term::Constant(_, Constant::Usize(_)) => {
|
||||||
code.push(succeed!());
|
code.push(succeed!());
|
||||||
}
|
}
|
||||||
&Term::Var(ref vr, ref name) => {
|
&Term::Var(ref vr, ref name) => {
|
||||||
|
|||||||
@@ -2390,6 +2390,29 @@ impl MachineState {
|
|||||||
_ => self.fail = true,
|
_ => self.fail = true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
&InlinedClauseType::IsNumber(r1) => {
|
||||||
|
match self.store(self.deref(self[r1])) {
|
||||||
|
Addr::Float(_) => self.p += 1,
|
||||||
|
d => match Number::try_from((d, &self.heap)) {
|
||||||
|
Ok(Number::Fixnum(_)) => {
|
||||||
|
self.p += 1;
|
||||||
|
}
|
||||||
|
Ok(Number::Integer(_)) => {
|
||||||
|
self.p += 1;
|
||||||
|
}
|
||||||
|
Ok(Number::Rational(n)) => {
|
||||||
|
if n.denom() == &1 {
|
||||||
|
self.p += 1;
|
||||||
|
} else {
|
||||||
|
self.fail = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
self.fail = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
&InlinedClauseType::IsRational(r1) => {
|
&InlinedClauseType::IsRational(r1) => {
|
||||||
let d = self.store(self.deref(self[r1]));
|
let d = self.store(self.deref(self[r1]));
|
||||||
|
|
||||||
|
|||||||
@@ -219,6 +219,12 @@ macro_rules! is_rational {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! is_number {
|
||||||
|
($r:expr) => {
|
||||||
|
call_clause!(ClauseType::Inlined(InlinedClauseType::IsNumber($r)), 1, 0)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! is_nonvar {
|
macro_rules! is_nonvar {
|
||||||
($r:expr) => {
|
($r:expr) => {
|
||||||
call_clause!(ClauseType::Inlined(InlinedClauseType::IsNonVar($r)), 1, 0)
|
call_clause!(ClauseType::Inlined(InlinedClauseType::IsNonVar($r)), 1, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user