simplify detecting undefined goal_ and term_expansion
This commit is contained in:
@@ -4851,6 +4851,14 @@ impl Machine {
|
||||
try_or_throw!(self.machine_st, self.add_non_counted_backtracking());
|
||||
self.machine_st.p = self.machine_st.cp;
|
||||
}
|
||||
&Instruction::CallPredicateDefined(_) => {
|
||||
self.machine_st.fail = !self.predicate_defined();
|
||||
self.machine_st.p += 1;
|
||||
}
|
||||
&Instruction::ExecutePredicateDefined(_) => {
|
||||
self.machine_st.fail = !self.predicate_defined();
|
||||
self.machine_st.p = self.machine_st.cp;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3771,6 +3771,39 @@ impl Machine {
|
||||
self.machine_st.fail = !self.indices.modules.contains_key(&module_name);
|
||||
}
|
||||
|
||||
pub(crate) fn predicate_defined(&self) -> bool {
|
||||
let module_name = cell_as_atom!(self.machine_st.store(self.machine_st.deref(
|
||||
self.machine_st.registers[1]
|
||||
)));
|
||||
|
||||
let name = cell_as_atom!(self.machine_st.store(self.machine_st.deref(
|
||||
self.machine_st.registers[2]
|
||||
)));
|
||||
|
||||
let arity = match Number::try_from(self.machine_st.store(self.machine_st.deref(
|
||||
self.machine_st.registers[3]
|
||||
))) {
|
||||
Ok(Number::Fixnum(n)) => n.get_num() as usize,
|
||||
Ok(Number::Integer(n)) => {
|
||||
if let Some(n) = n.to_usize() {
|
||||
n
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
unreachable!()
|
||||
}
|
||||
};
|
||||
|
||||
self.indices.get_predicate_code_index(
|
||||
name,
|
||||
arity,
|
||||
module_name,
|
||||
).map(|index| index.local().is_some())
|
||||
.unwrap_or(false)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn no_such_predicate(&mut self) -> CallResult {
|
||||
let module_name = cell_as_atom!(self.machine_st.store(self.machine_st.deref(
|
||||
|
||||
Reference in New Issue
Block a user