From e38bf58e6c0487466dec26e8ccd37a83e7ac4330 Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Tue, 1 May 2018 20:36:19 -0600 Subject: [PATCH] move existence_error function in machine_st_impl.rs --- src/prolog/machine/machine_state.rs | 16 +++------------- src/prolog/machine/machine_state_impl.rs | 10 ++++++++++ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/prolog/machine/machine_state.rs b/src/prolog/machine/machine_state.rs index e5749ef5..17560ef4 100644 --- a/src/prolog/machine/machine_state.rs +++ b/src/prolog/machine/machine_state.rs @@ -209,16 +209,6 @@ pub struct MachineState { pub(crate) type CallResult = Result<(), Vec>; -fn predicate_existence_error(name: ClauseName, arity: usize, h: usize) -> Vec -{ - let name = HeapCellValue::Addr(Addr::Con(Constant::Atom(name))); - - 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 -} - pub(crate) trait CallPolicy: Any { fn context_call(&mut self, machine_st: &mut MachineState, name: ClauseName, arity: usize, idx: CodeIndex, lco: bool) @@ -237,7 +227,7 @@ pub(crate) trait CallPolicy: Any { { match idx.0.borrow().0 { IndexPtr::Undefined => - return Err(predicate_existence_error(name, arity, machine_st.heap.h)), + return Err(machine_st.existence_error(name, arity)), IndexPtr::Index(compiled_tl_index) => { let module_name = idx.0.borrow().1.clone(); @@ -257,7 +247,7 @@ pub(crate) trait CallPolicy: Any { { match idx.0.borrow().0 { IndexPtr::Undefined => - return Err(predicate_existence_error(name, arity, machine_st.heap.h)), + return Err(machine_st.existence_error(name, arity)), IndexPtr::Index(compiled_tl_index) => { let module_name = idx.0.borrow().1.clone(); @@ -430,7 +420,7 @@ pub(crate) trait CallPolicy: Any { if let Some(idx) = code_dirs.get(name.clone(), arity, clause_name!("user")) { self.context_call(machine_st, name, arity, idx, lco) } else { - Err(predicate_existence_error(name, arity, machine_st.heap.h)) + Err(machine_st.existence_error(name, arity)) } } else { Ok(()) diff --git a/src/prolog/machine/machine_state_impl.rs b/src/prolog/machine/machine_state_impl.rs index 71397049..83181aa7 100644 --- a/src/prolog/machine/machine_state_impl.rs +++ b/src/prolog/machine/machine_state_impl.rs @@ -952,6 +952,16 @@ impl MachineState { self.goto_throw(); } + pub(super) fn existence_error(&self, name: ClauseName, arity: usize) -> Vec { + let name = HeapCellValue::Addr(Addr::Con(Constant::Atom(name))); + let h = self.heap.h; + + 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 + } + pub(super) fn setup_call_n(&mut self, arity: usize) -> Option { let addr = self.store(self.deref(self.registers[arity].clone())); -- 2.54.0