get rid of dynamic lookup for
$call_with_default_policy.
This commit is contained in:
@@ -709,7 +709,6 @@ pub struct Rule {
|
|||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq)]
|
#[derive(Copy, Clone, PartialEq)]
|
||||||
pub enum SystemClauseType {
|
pub enum SystemClauseType {
|
||||||
CallWithDefaultPolicy,
|
|
||||||
CheckCutPoint,
|
CheckCutPoint,
|
||||||
GetBValue,
|
GetBValue,
|
||||||
GetSCCCleaner,
|
GetSCCCleaner,
|
||||||
@@ -742,7 +741,6 @@ impl SystemClauseType {
|
|||||||
|
|
||||||
pub fn name(&self) -> ClauseName {
|
pub fn name(&self) -> ClauseName {
|
||||||
match self {
|
match self {
|
||||||
&SystemClauseType::CallWithDefaultPolicy => clause_name!("$call_with_default_policy"),
|
|
||||||
&SystemClauseType::CheckCutPoint => clause_name!("$check_cp"),
|
&SystemClauseType::CheckCutPoint => clause_name!("$check_cp"),
|
||||||
&SystemClauseType::GetBValue => clause_name!("$get_b_value"),
|
&SystemClauseType::GetBValue => clause_name!("$get_b_value"),
|
||||||
&SystemClauseType::GetSCCCleaner => clause_name!("$get_scc_cleaner"),
|
&SystemClauseType::GetSCCCleaner => clause_name!("$get_scc_cleaner"),
|
||||||
@@ -774,7 +772,6 @@ impl SystemClauseType {
|
|||||||
|
|
||||||
pub fn from(name: &str, arity: usize) -> Option<SystemClauseType> {
|
pub fn from(name: &str, arity: usize) -> Option<SystemClauseType> {
|
||||||
match (name, arity) {
|
match (name, arity) {
|
||||||
("$call_with_default_policy", 1) => Some(SystemClauseType::CallWithDefaultPolicy),
|
|
||||||
("$check_cp", 1) => Some(SystemClauseType::CheckCutPoint),
|
("$check_cp", 1) => Some(SystemClauseType::CheckCutPoint),
|
||||||
("$get_b_value", 1) => Some(SystemClauseType::GetBValue),
|
("$get_b_value", 1) => Some(SystemClauseType::GetBValue),
|
||||||
("$get_scc_cleaner", 1) => Some(SystemClauseType::GetSCCCleaner),
|
("$get_scc_cleaner", 1) => Some(SystemClauseType::GetSCCCleaner),
|
||||||
|
|||||||
@@ -429,8 +429,8 @@ pub(crate) trait CallPolicy: Any {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn context_call<'a>(&mut self, machine_st: &mut MachineState, name: ClauseName, arity: usize,
|
fn context_call(&mut self, machine_st: &mut MachineState, name: ClauseName, arity: usize,
|
||||||
idx: CodeIndex, code_dirs: Box<CodeDirsAdapter<'a> + 'a>)
|
idx: CodeIndex, code_dirs: CodeDirs)
|
||||||
-> CallResult
|
-> CallResult
|
||||||
{
|
{
|
||||||
if machine_st.last_call {
|
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,
|
fn try_call<'a>(&mut self, machine_st: &mut MachineState, name: ClauseName, arity: usize,
|
||||||
idx: CodeIndex, code_dirs: Box<CodeDirsAdapter<'a> + 'a>)
|
idx: CodeIndex, code_dirs: CodeDirs)
|
||||||
-> CallResult
|
-> CallResult
|
||||||
{
|
{
|
||||||
match idx.0.borrow().0 {
|
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,
|
fn try_execute<'a>(&mut self, machine_st: &mut MachineState, name: ClauseName,
|
||||||
arity: usize, idx: CodeIndex, code_dirs: Box<CodeDirsAdapter<'a> + 'a>)
|
arity: usize, idx: CodeIndex, code_dirs: CodeDirs)
|
||||||
-> CallResult
|
-> CallResult
|
||||||
{
|
{
|
||||||
match idx.0.borrow().0 {
|
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,
|
fn call_builtin<'a>(&mut self, machine_st: &mut MachineState, ct: &BuiltInClauseType,
|
||||||
code_dirs: Box<CodeDirsAdapter<'a> + 'a>)
|
code_dirs: CodeDirs)
|
||||||
-> CallResult
|
-> CallResult
|
||||||
{
|
{
|
||||||
match ct {
|
match ct {
|
||||||
@@ -651,7 +651,7 @@ pub(crate) trait CallPolicy: Any {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn call_n<'a>(&mut self, machine_st: &mut MachineState, arity: usize,
|
fn call_n<'a>(&mut self, machine_st: &mut MachineState, arity: usize,
|
||||||
code_dirs: Box<CodeDirsAdapter<'a> + 'a>)
|
code_dirs: CodeDirs)
|
||||||
-> CallResult
|
-> CallResult
|
||||||
{
|
{
|
||||||
if let Some((name, arity)) = machine_st.setup_call_n(arity) {
|
if let Some((name, arity)) = machine_st.setup_call_n(arity) {
|
||||||
@@ -699,7 +699,7 @@ pub(crate) trait CallPolicy: Any {
|
|||||||
|
|
||||||
impl CallPolicy for CWILCallPolicy {
|
impl CallPolicy for CWILCallPolicy {
|
||||||
fn context_call<'a>(&mut self, machine_st: &mut MachineState, name: ClauseName,
|
fn context_call<'a>(&mut self, machine_st: &mut MachineState, name: ClauseName,
|
||||||
arity: usize, idx: CodeIndex, code_dirs: Box<CodeDirsAdapter<'a> + 'a>)
|
arity: usize, idx: CodeIndex, code_dirs: CodeDirs)
|
||||||
-> CallResult
|
-> CallResult
|
||||||
{
|
{
|
||||||
self.prev_policy.context_call(machine_st, name, arity, idx, code_dirs)?;
|
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,
|
fn call_builtin<'a>(&mut self, machine_st: &mut MachineState, ct: &BuiltInClauseType,
|
||||||
code_dirs: Box<CodeDirsAdapter<'a> + 'a>)
|
code_dirs: CodeDirs)
|
||||||
-> CallResult
|
-> CallResult
|
||||||
{
|
{
|
||||||
self.prev_policy.call_builtin(machine_st, ct, code_dirs)?;
|
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,
|
fn call_n<'a>(&mut self, machine_st: &mut MachineState, arity: usize,
|
||||||
code_dirs: Box<CodeDirsAdapter<'a> + 'a>)
|
code_dirs: CodeDirs)
|
||||||
-> CallResult
|
-> CallResult
|
||||||
{
|
{
|
||||||
self.prev_policy.call_n(machine_st, arity, code_dirs)?;
|
self.prev_policy.call_n(machine_st, arity, code_dirs)?;
|
||||||
|
|||||||
@@ -1830,14 +1830,14 @@ impl MachineState {
|
|||||||
|
|
||||||
match ct {
|
match ct {
|
||||||
&ClauseType::BuiltIn(ref 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 =>
|
&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) =>
|
&ClauseType::Inlined(ref ct) =>
|
||||||
self.execute_inlined(ct),
|
self.execute_inlined(ct),
|
||||||
&ClauseType::Named(ref name, ref idx) | &ClauseType::Op(ref name, _, ref idx) =>
|
&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(),
|
try_or_fail!(self, call_policy.context_call(self, name.clone(), arity, idx.clone(),
|
||||||
Box::new(code_dirs))),
|
code_dirs)),
|
||||||
&ClauseType::System(ref ct) =>
|
&ClauseType::System(ref ct) =>
|
||||||
try_or_fail!(self, self.system_call(ct, code_dirs, call_policy, cut_policy))
|
try_or_fail!(self, self.system_call(ct, code_dirs, call_policy, cut_policy))
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -187,14 +187,6 @@ impl MachineState {
|
|||||||
-> CallResult
|
-> CallResult
|
||||||
{
|
{
|
||||||
match ct {
|
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 => {
|
&SystemClauseType::CheckCutPoint => {
|
||||||
let addr = self.store(self.deref(self[temp_v!(1)].clone()));
|
let addr = self.store(self.deref(self[temp_v!(1)].clone()));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user