add unknown flag to set_prolog_flag and current_prolog_flag
This commit is contained in:
@@ -4194,6 +4194,14 @@ impl Machine {
|
||||
self.get_double_quotes();
|
||||
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
||||
}
|
||||
&Instruction::CallGetUnknown => {
|
||||
self.get_unknown();
|
||||
step_or_fail!(self, self.machine_st.p += 1);
|
||||
}
|
||||
&Instruction::ExecuteGetUnknown => {
|
||||
self.get_unknown();
|
||||
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
||||
}
|
||||
&Instruction::CallInstallNewBlock => {
|
||||
self.machine_st.install_new_block(self.machine_st.registers[1]);
|
||||
step_or_fail!(self, self.machine_st.p += 1);
|
||||
@@ -4374,6 +4382,14 @@ impl Machine {
|
||||
self.set_double_quotes();
|
||||
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
||||
}
|
||||
&Instruction::CallSetUnknown => {
|
||||
self.set_unknown();
|
||||
step_or_fail!(self, self.machine_st.p += 1);
|
||||
}
|
||||
&Instruction::ExecuteSetUnknown => {
|
||||
self.set_unknown();
|
||||
step_or_fail!(self, self.machine_st.p = self.machine_st.cp);
|
||||
}
|
||||
&Instruction::CallSetSeed => {
|
||||
self.set_seed();
|
||||
step_or_fail!(self, self.machine_st.p += 1);
|
||||
|
||||
@@ -1027,6 +1027,24 @@ impl Machine {
|
||||
self.machine_st.heap.truncate(target_h);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn undefined_procedure(&mut self, name: Atom, arity: usize) -> CallResult {
|
||||
match self.machine_st.flags.unknown {
|
||||
Unknown::Error => {
|
||||
Err(self.machine_st.throw_undefined_error(name, arity))
|
||||
}
|
||||
Unknown::Fail => {
|
||||
self.machine_st.fail = true;
|
||||
Ok(())
|
||||
}
|
||||
Unknown::Warn => {
|
||||
println!("warning: predicate {}/{} is undefined", name.as_str(), arity);
|
||||
self.machine_st.fail = true;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn try_call(&mut self, name: Atom, arity: usize, idx: IndexPtr) -> CallResult {
|
||||
let compiled_tl_index = idx.p() as usize;
|
||||
@@ -1036,7 +1054,7 @@ impl Machine {
|
||||
self.machine_st.fail = true;
|
||||
}
|
||||
IndexPtrTag::Undefined => {
|
||||
return Err(self.machine_st.throw_undefined_error(name, arity));
|
||||
return self.undefined_procedure(name, arity);
|
||||
}
|
||||
IndexPtrTag::DynamicIndex => {
|
||||
self.machine_st.dynamic_mode = FirstOrNext::First;
|
||||
@@ -1059,7 +1077,7 @@ impl Machine {
|
||||
self.machine_st.fail = true;
|
||||
}
|
||||
IndexPtrTag::Undefined => {
|
||||
return Err(self.machine_st.throw_undefined_error(name, arity));
|
||||
return self.undefined_procedure(name, arity);
|
||||
}
|
||||
IndexPtrTag::DynamicIndex => {
|
||||
self.machine_st.dynamic_mode = FirstOrNext::First;
|
||||
@@ -1088,7 +1106,7 @@ impl Machine {
|
||||
if let Some(idx) = module.code_dir.get(&(name, arity)).cloned() {
|
||||
self.try_call(name, arity, idx.get())
|
||||
} else {
|
||||
Err(self.machine_st.throw_undefined_error(name, arity))
|
||||
self.undefined_procedure(name, arity)
|
||||
}
|
||||
} else {
|
||||
let stub = functor_stub(name, arity);
|
||||
@@ -1107,14 +1125,14 @@ impl Machine {
|
||||
if let Some(idx) = self.indices.code_dir.get(&(name, arity)).cloned() {
|
||||
self.try_execute(name, arity, idx.get())
|
||||
} else {
|
||||
Err(self.machine_st.throw_undefined_error(name, arity))
|
||||
self.undefined_procedure(name, arity)
|
||||
}
|
||||
} else {
|
||||
if let Some(module) = self.indices.modules.get(&module_name) {
|
||||
if let Some(idx) = module.code_dir.get(&(name, arity)).cloned() {
|
||||
self.try_execute(name, arity, idx.get())
|
||||
} else {
|
||||
Err(self.machine_st.throw_undefined_error(name, arity))
|
||||
self.undefined_procedure(name, arity)
|
||||
}
|
||||
} else {
|
||||
let stub = functor_stub(name, arity);
|
||||
|
||||
@@ -5187,6 +5187,20 @@ impl Machine {
|
||||
);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn get_unknown(&mut self) {
|
||||
let a1 = self.deref_register(1);
|
||||
|
||||
self.machine_st.unify_atom(
|
||||
match self.machine_st.flags.unknown {
|
||||
Unknown::Error => atom!("error"),
|
||||
Unknown::Fail => atom!("fail"),
|
||||
Unknown::Warn => atom!("warning"),
|
||||
},
|
||||
a1,
|
||||
);
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn get_scc_cleaner(&mut self) {
|
||||
let dest = self.machine_st.registers[1];
|
||||
@@ -5521,7 +5535,7 @@ impl Machine {
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn set_double_quotes(&mut self) {
|
||||
let atom = cell_as_atom!(self.machine_st.registers[1]);
|
||||
let atom = cell_as_atom!(self.deref_register(1));
|
||||
|
||||
self.machine_st.flags.double_quotes = match atom {
|
||||
atom!("atom") => DoubleQuotes::Atom,
|
||||
@@ -5534,6 +5548,21 @@ impl Machine {
|
||||
};
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn set_unknown(&mut self) {
|
||||
let atom = cell_as_atom!(self.deref_register(1));
|
||||
|
||||
self.machine_st.flags.unknown = match atom {
|
||||
atom!("error") => Unknown::Error,
|
||||
atom!("fail") => Unknown::Fail,
|
||||
atom!("warning") => Unknown::Warn,
|
||||
_ => {
|
||||
self.machine_st.fail = true;
|
||||
return;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub(crate) fn inference_level(&mut self) {
|
||||
let a1 = self.deref_register(1);
|
||||
|
||||
Reference in New Issue
Block a user