throw exception when predicate not found
This commit is contained in:
@@ -12,9 +12,9 @@ pub trait CopierTarget
|
||||
fn deref(&self, Addr) -> Addr;
|
||||
fn stack(&mut self) -> &mut AndStack;
|
||||
|
||||
// duplicate_term(L1, L2) uses Cheney's algorithm to copy the term at
|
||||
// L1 to L2. forwarding_terms is kept to restore the innards of L1
|
||||
// after it's been copied to L2.
|
||||
// duplicate_term(L1, L2) uses Cheney's algorithm to copy the term
|
||||
// at L1 to L2. trail is kept to restore the innards of L1 after
|
||||
// it's been copied to L2.
|
||||
fn duplicate_term(&mut self, a: Addr) where Self: IndexMut<usize, Output=HeapCellValue>
|
||||
{
|
||||
let mut trail: Vec<(Ref, HeapCellValue)>= Vec::new();
|
||||
@@ -31,13 +31,13 @@ pub trait CopierTarget
|
||||
match a.clone() {
|
||||
Addr::Lis(a) => {
|
||||
self[scan] = HeapCellValue::Addr(Addr::Lis(self.threshold()));
|
||||
|
||||
|
||||
let hcv = self[a].clone();
|
||||
self.push(hcv);
|
||||
|
||||
|
||||
let hcv = self[a+1].clone();
|
||||
self.push(hcv);
|
||||
|
||||
|
||||
scan += 1;
|
||||
},
|
||||
Addr::HeapCell(_) | Addr::StackCell(_, _) => {
|
||||
|
||||
@@ -210,11 +210,11 @@ pub struct MachineState {
|
||||
|
||||
pub(crate) type CallResult = Result<(), Vec<HeapCellValue>>;
|
||||
|
||||
fn predicate_existence_error(name: ClauseName, arity: usize) -> Vec<HeapCellValue>
|
||||
fn predicate_existence_error(name: ClauseName, arity: usize, h: usize) -> Vec<HeapCellValue>
|
||||
{
|
||||
let name = HeapCellValue::Addr(Addr::Con(Constant::Atom(name)));
|
||||
|
||||
let mut error = functor!("existence_error", 2, [heap_atom!("procedure"), heap_str!(4)]);
|
||||
let mut error = functor!("existence_error", 2, [heap_atom!("procedure"), heap_str!(3 + h)]);
|
||||
error.append(&mut functor!("/", 2, [name, heap_integer!(arity)], Fixity::In));
|
||||
|
||||
error
|
||||
@@ -238,7 +238,7 @@ pub(crate) trait CallPolicy: Any {
|
||||
{
|
||||
match idx.0.get() {
|
||||
IndexPtr::Undefined =>
|
||||
return Err(predicate_existence_error(name, arity)),
|
||||
return Err(predicate_existence_error(name, arity, machine_st.heap.h)),
|
||||
IndexPtr::Index(compiled_tl_index) => {
|
||||
let module_name = idx.1;
|
||||
|
||||
@@ -258,7 +258,7 @@ pub(crate) trait CallPolicy: Any {
|
||||
{
|
||||
match idx.0.get() {
|
||||
IndexPtr::Undefined =>
|
||||
return Err(predicate_existence_error(name, arity)),
|
||||
return Err(predicate_existence_error(name, arity, machine_st.heap.h)),
|
||||
IndexPtr::Index(compiled_tl_index) => {
|
||||
let module_name = idx.1;
|
||||
|
||||
|
||||
@@ -925,6 +925,13 @@ impl MachineState {
|
||||
self.p = CodePtr::DirEntry(59, clause_name!("builtin"));
|
||||
}
|
||||
|
||||
fn unwind_stack(&mut self) {
|
||||
self.b = self.block;
|
||||
self.or_stack.truncate(self.b);
|
||||
|
||||
self.fail = true;
|
||||
}
|
||||
|
||||
fn throw_exception(&mut self, hcv: Vec<HeapCellValue>) {
|
||||
let h = self.heap.h;
|
||||
|
||||
@@ -1535,12 +1542,8 @@ impl MachineState {
|
||||
let addr = self.deref(self[temp_v!(1)].clone());
|
||||
self.reset_block(addr);
|
||||
},
|
||||
&BuiltInInstruction::UnwindStack => {
|
||||
self.b = self.block;
|
||||
self.or_stack.truncate(self.b);
|
||||
|
||||
self.fail = true;
|
||||
},
|
||||
&BuiltInInstruction::UnwindStack =>
|
||||
self.unwind_stack(),
|
||||
&BuiltInInstruction::InternalCallN =>
|
||||
self.handle_internal_call_n(call_policy, code_dirs),
|
||||
&BuiltInInstruction::Fail => {
|
||||
|
||||
Reference in New Issue
Block a user