From 057e2d80566a92af7d29a308439c6fc6483ecc9c Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Thu, 19 Mar 2020 20:41:58 -0600 Subject: [PATCH] provide contextual information in the return value of try_in_situ_result --- src/prolog/machine/machine_state.rs | 20 ++++++++++---------- src/prolog/macros.rs | 6 ------ 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/src/prolog/machine/machine_state.rs b/src/prolog/machine/machine_state.rs index ec6efb5f..62cbf9c2 100644 --- a/src/prolog/machine/machine_state.rs +++ b/src/prolog/machine/machine_state.rs @@ -437,15 +437,15 @@ impl MachineState { } } -fn try_in_situ_lookup(name: ClauseName, arity: usize, indices: &IndexStore) -> Option +fn try_in_situ_lookup(name: ClauseName, arity: usize, indices: &IndexStore) -> Option { match indices.in_situ_code_dir.get(&(name.clone(), arity)) { - Some(p) => Some(*p), + Some(p) => Some(LocalCodePtr::InSituDirEntry(*p)), None => match indices.code_dir.get(&(name, arity)) { Some(ref idx) => { if let IndexPtr::Index(p) = idx.0.borrow().0 { - Some(p) + Some(LocalCodePtr::DirEntry(p)) } else { None } @@ -464,12 +464,12 @@ fn try_in_situ( ) -> CallResult { if let Some(p) = try_in_situ_lookup(name.clone(), arity, indices) { if last_call { - machine_st.execute_at_index(arity, LocalCodePtr::DirEntry(p)); + machine_st.execute_at_index(arity, p); } else { - machine_st.call_at_index(arity, LocalCodePtr::DirEntry(p)); + machine_st.call_at_index(arity, p); } - machine_st.p = in_situ_dir_entry!(p); + machine_st.p = CodePtr::Local(p); Ok(()) } else { let stub = MachineError::functor_stub(name.clone(), arity); @@ -760,10 +760,10 @@ pub(crate) trait CallPolicy: Any { machine_st.compare_term(qt); return_from_clause!(machine_st.last_call, machine_st) } - &BuiltInClauseType::Nl => { + &BuiltInClauseType::Nl => { write!(current_output_stream, "\n").unwrap(); current_output_stream.flush().unwrap(); - + return_from_clause!(machine_st.last_call, machine_st) } &BuiltInClauseType::Read => { @@ -997,7 +997,7 @@ impl CallPolicy for CWILCallPolicy { current_input_stream, current_output_stream )?; - + self.increment(machine_st) } @@ -1016,7 +1016,7 @@ impl CallPolicy for CWILCallPolicy { current_input_stream, current_output_stream, )?; - + self.increment(machine_st) } } diff --git a/src/prolog/macros.rs b/src/prolog/macros.rs index 7968aa34..1f85e39a 100644 --- a/src/prolog/macros.rs +++ b/src/prolog/macros.rs @@ -211,12 +211,6 @@ macro_rules! dir_entry { }; } -macro_rules! in_situ_dir_entry { - ($idx:expr) => { - CodePtr::Local(LocalCodePtr::InSituDirEntry($idx)) - }; -} - macro_rules! set_code_index { ($idx:expr, $ip:expr, $mod_name:expr) => {{ let mut idx = $idx.0.borrow_mut(); -- 2.54.0