complete call_with_inference_limit/3

This commit is contained in:
Mark Thom
2018-08-09 00:31:41 -06:00
parent 3fef717677
commit 0cc4aa77ed
10 changed files with 146 additions and 53 deletions

View File

@@ -85,6 +85,7 @@ impl<'a> CodeDirs<'a> {
pub trait CodeDirsAdapter<'a> {
fn get_code_index(&self, PredicateKey, ClauseName) -> Option<CodeIndex>;
fn get_op(&self, OpDirKey) -> Option<(Specifier, usize, ClauseName)>;
fn op_dir(&self) -> &OpDir;
}
impl<'a> CodeDirsAdapter<'a> for CodeDirs<'a> {
@@ -95,6 +96,10 @@ impl<'a> CodeDirsAdapter<'a> for CodeDirs<'a> {
fn get_op(&self, key: OpDirKey) -> Option<(Specifier, usize, ClauseName)> {
self.op_dir.get(&key).cloned()
}
fn op_dir(&self) -> &OpDir {
&self.op_dir
}
}
impl<'a> CodeDirsAdapter<'a> for &'a Module {
@@ -107,6 +112,10 @@ impl<'a> CodeDirsAdapter<'a> for &'a Module {
fn get_op(&self, key: OpDirKey) -> Option<(Specifier, usize, ClauseName)> {
self.op_dir.get(&key).cloned()
}
fn op_dir(&self) -> &OpDir {
&self.op_dir
}
}
pub(super) struct DuplicateTerm<'a> {
@@ -506,7 +515,7 @@ pub(crate) trait CallPolicy: Any {
}
fn call_builtin<'a>(&mut self, machine_st: &mut MachineState, ct: &BuiltInClauseType,
code_dirs: CodeDirs<'a>)
code_dirs: Box<CodeDirsAdapter<'a> + 'a>)
-> CallResult
{
match ct {
@@ -552,7 +561,7 @@ pub(crate) trait CallPolicy: Any {
&BuiltInClauseType::Read => {
let mut reader = Reader::new(machine_st);
match reader.read_stdin(code_dirs.op_dir) {
match reader.read_stdin(code_dirs.op_dir()) {
Ok(offset) => {
let addr = reader.machine_st[temp_v!(1)].clone();
reader.machine_st.unify(addr, Addr::HeapCell(offset));
@@ -658,8 +667,10 @@ pub(crate) trait CallPolicy: Any {
machine_st.p = CodePtr::CallN(arity, machine_st.p.local());
},
ClauseType::BuiltIn(built_in) =>
machine_st.setup_built_in_call(built_in),
ClauseType::BuiltIn(built_in) => {
machine_st.setup_built_in_call(built_in.clone());
self.call_builtin(machine_st, &built_in, code_dirs)?;
},
ClauseType::Inlined(inlined) =>
machine_st.execute_inlined(&inlined),
ClauseType::Op(..) | ClauseType::Named(..) =>
@@ -720,7 +731,7 @@ impl CallPolicy for CWILCallPolicy {
}
fn call_builtin<'a>(&mut self, machine_st: &mut MachineState, ct: &BuiltInClauseType,
code_dirs: CodeDirs<'a>)
code_dirs: Box<CodeDirsAdapter<'a> + 'a>)
-> CallResult
{
self.prev_policy.call_builtin(machine_st, ct, code_dirs)?;

View File

@@ -1825,7 +1825,7 @@ impl MachineState {
},
&ControlInstruction::CallClause(ClauseType::BuiltIn(ref ct), _, _, lco) => {
self.last_call = lco;
try_or_fail!(self, call_policy.call_builtin(self, ct, code_dirs));
try_or_fail!(self, call_policy.call_builtin(self, ct, Box::new(code_dirs)));
},
&ControlInstruction::CallClause(ClauseType::Inlined(ref ct), ..) =>
self.execute_inlined(ct),
@@ -1892,7 +1892,7 @@ impl MachineState {
pub(super) fn execute_choice_instr(&mut self, instr: &ChoiceInstruction,
call_policy: &mut Box<CallPolicy>)
{
match instr {
match instr {
&ChoiceInstruction::TryMeElse(offset) => {
let n = self.num_of_args;
let gi = self.next_global_index();
@@ -1917,6 +1917,14 @@ impl MachineState {
self.hb = self.heap.h;
self.p += 1;
},
&ChoiceInstruction::DefaultRetryMeElse(offset) => {
let mut call_policy = DefaultCallPolicy {};
try_or_fail!(self, call_policy.retry_me_else(self, offset))
},
&ChoiceInstruction::DefaultTrustMe => {
let mut call_policy = DefaultCallPolicy {};
try_or_fail!(self, call_policy.trust_me(self))
},
&ChoiceInstruction::RetryMeElse(offset) =>
try_or_fail!(self, call_policy.retry_me_else(self, offset)),
&ChoiceInstruction::TrustMe =>