From f9e6b7fec5e8e12db35726dfbc8547270a747a8e Mon Sep 17 00:00:00 2001 From: Mark Thom Date: Sun, 12 Aug 2018 23:17:34 -0600 Subject: [PATCH] get rid of dynamic lookup for $call_with_default_policy. --- src/prolog/ast.rs | 3 --- src/prolog/machine/machine_state.rs | 18 +++++++++--------- src/prolog/machine/machine_state_impl.rs | 6 +++--- src/prolog/machine/system_calls.rs | 8 -------- 4 files changed, 12 insertions(+), 23 deletions(-) diff --git a/src/prolog/ast.rs b/src/prolog/ast.rs index 47f06da5..7c5bc6e1 100644 --- a/src/prolog/ast.rs +++ b/src/prolog/ast.rs @@ -709,7 +709,6 @@ pub struct Rule { #[derive(Copy, Clone, PartialEq)] pub enum SystemClauseType { - CallWithDefaultPolicy, CheckCutPoint, GetBValue, GetSCCCleaner, @@ -742,7 +741,6 @@ impl SystemClauseType { pub fn name(&self) -> ClauseName { match self { - &SystemClauseType::CallWithDefaultPolicy => clause_name!("$call_with_default_policy"), &SystemClauseType::CheckCutPoint => clause_name!("$check_cp"), &SystemClauseType::GetBValue => clause_name!("$get_b_value"), &SystemClauseType::GetSCCCleaner => clause_name!("$get_scc_cleaner"), @@ -774,7 +772,6 @@ impl SystemClauseType { pub fn from(name: &str, arity: usize) -> Option { match (name, arity) { - ("$call_with_default_policy", 1) => Some(SystemClauseType::CallWithDefaultPolicy), ("$check_cp", 1) => Some(SystemClauseType::CheckCutPoint), ("$get_b_value", 1) => Some(SystemClauseType::GetBValue), ("$get_scc_cleaner", 1) => Some(SystemClauseType::GetSCCCleaner), diff --git a/src/prolog/machine/machine_state.rs b/src/prolog/machine/machine_state.rs index 32c8d923..73be6ceb 100644 --- a/src/prolog/machine/machine_state.rs +++ b/src/prolog/machine/machine_state.rs @@ -429,8 +429,8 @@ pub(crate) trait CallPolicy: Any { Ok(()) } - fn context_call<'a>(&mut self, machine_st: &mut MachineState, name: ClauseName, arity: usize, - idx: CodeIndex, code_dirs: Box + 'a>) + fn context_call(&mut self, machine_st: &mut MachineState, name: ClauseName, arity: usize, + idx: CodeIndex, code_dirs: CodeDirs) -> CallResult { if machine_st.last_call { @@ -441,7 +441,7 @@ pub(crate) trait CallPolicy: Any { } fn try_call<'a>(&mut self, machine_st: &mut MachineState, name: ClauseName, arity: usize, - idx: CodeIndex, code_dirs: Box + 'a>) + idx: CodeIndex, code_dirs: CodeDirs) -> CallResult { match idx.0.borrow().0 { @@ -478,7 +478,7 @@ pub(crate) trait CallPolicy: Any { } fn try_execute<'a>(&mut self, machine_st: &mut MachineState, name: ClauseName, - arity: usize, idx: CodeIndex, code_dirs: Box + 'a>) + arity: usize, idx: CodeIndex, code_dirs: CodeDirs) -> CallResult { match idx.0.borrow().0 { @@ -515,7 +515,7 @@ pub(crate) trait CallPolicy: Any { } fn call_builtin<'a>(&mut self, machine_st: &mut MachineState, ct: &BuiltInClauseType, - code_dirs: Box + 'a>) + code_dirs: CodeDirs) -> CallResult { match ct { @@ -651,7 +651,7 @@ pub(crate) trait CallPolicy: Any { } fn call_n<'a>(&mut self, machine_st: &mut MachineState, arity: usize, - code_dirs: Box + 'a>) + code_dirs: CodeDirs) -> CallResult { if let Some((name, arity)) = machine_st.setup_call_n(arity) { @@ -699,7 +699,7 @@ pub(crate) trait CallPolicy: Any { impl CallPolicy for CWILCallPolicy { fn context_call<'a>(&mut self, machine_st: &mut MachineState, name: ClauseName, - arity: usize, idx: CodeIndex, code_dirs: Box + 'a>) + arity: usize, idx: CodeIndex, code_dirs: CodeDirs) -> CallResult { self.prev_policy.context_call(machine_st, name, arity, idx, code_dirs)?; @@ -731,7 +731,7 @@ impl CallPolicy for CWILCallPolicy { } fn call_builtin<'a>(&mut self, machine_st: &mut MachineState, ct: &BuiltInClauseType, - code_dirs: Box + 'a>) + code_dirs: CodeDirs) -> CallResult { self.prev_policy.call_builtin(machine_st, ct, code_dirs)?; @@ -739,7 +739,7 @@ impl CallPolicy for CWILCallPolicy { } fn call_n<'a>(&mut self, machine_st: &mut MachineState, arity: usize, - code_dirs: Box + 'a>) + code_dirs: CodeDirs) -> CallResult { self.prev_policy.call_n(machine_st, arity, code_dirs)?; diff --git a/src/prolog/machine/machine_state_impl.rs b/src/prolog/machine/machine_state_impl.rs index df4301bd..f199f058 100644 --- a/src/prolog/machine/machine_state_impl.rs +++ b/src/prolog/machine/machine_state_impl.rs @@ -1830,14 +1830,14 @@ impl MachineState { match ct { &ClauseType::BuiltIn(ref ct) => - try_or_fail!(self, call_policy.call_builtin(self, ct, Box::new(code_dirs))), + try_or_fail!(self, call_policy.call_builtin(self, ct, code_dirs)), &ClauseType::CallN => - try_or_fail!(self, call_policy.call_n(self, arity, Box::new(code_dirs))), + try_or_fail!(self, call_policy.call_n(self, arity, code_dirs)), &ClauseType::Inlined(ref ct) => self.execute_inlined(ct), &ClauseType::Named(ref name, ref idx) | &ClauseType::Op(ref name, _, ref idx) => try_or_fail!(self, call_policy.context_call(self, name.clone(), arity, idx.clone(), - Box::new(code_dirs))), + code_dirs)), &ClauseType::System(ref ct) => try_or_fail!(self, self.system_call(ct, code_dirs, call_policy, cut_policy)) }; diff --git a/src/prolog/machine/system_calls.rs b/src/prolog/machine/system_calls.rs index 2b1a4306..d4eec167 100644 --- a/src/prolog/machine/system_calls.rs +++ b/src/prolog/machine/system_calls.rs @@ -187,14 +187,6 @@ impl MachineState { -> CallResult { match ct { - // this system call is only to be used within the builtins module. - // TODO: in the future I'd like to use serde to serialize/deserialize builtins - // and thereby avoid this kludge, but for now it's ok. - &SystemClauseType::CallWithDefaultPolicy => - if let Some(builtins) = code_dirs.modules.get(&clause_name!("builtins")) { - let mut call_policy = DefaultCallPolicy {}; - return call_policy.call_n(self, 1, Box::new(builtins)); - }, &SystemClauseType::CheckCutPoint => { let addr = self.store(self.deref(self[temp_v!(1)].clone())); -- 2.54.0