]> Repositorios git - scryer-prolog.git/commitdiff
clean up call clause stuff.
authorMark Thom <[email protected]>
Tue, 27 Mar 2018 00:16:39 +0000 (18:16 -0600)
committerMark Thom <[email protected]>
Tue, 27 Mar 2018 00:16:39 +0000 (18:16 -0600)
src/prolog/machine/machine_state.rs
src/prolog/machine/machine_state_impl.rs

index c27cbb93b7226af9574f5356c380d2946c492e13..87a35947080cbd12ff53e757692a35d68b59b800 100644 (file)
@@ -215,6 +215,17 @@ pub struct MachineState {
 pub(crate) type CallResult = Result<(), Vec<HeapCellValue>>;
 
 pub(crate) trait CallPolicy: Any {
+    fn context_call<'a>(&mut self, machine_st: &mut MachineState, code_dirs: CodeDirs<'a>,
+                        name: ClauseName, arity: usize, lco: bool)
+                        -> CallResult
+    {
+        if lco {
+            self.try_execute(machine_st, code_dirs, name, arity)
+        } else {
+            self.try_call(machine_st, code_dirs, name, arity)
+        }
+    }
+    
     fn try_call<'a>(&mut self, machine_st: &mut MachineState, code_dirs: CodeDirs<'a>,
                     name: ClauseName, arity: usize)
                     -> CallResult
@@ -408,11 +419,7 @@ pub(crate) trait CallPolicy: Any {
             },
             &ClauseType::CallN =>
                 if let Some((name, arity)) = machine_st.setup_call_n(arity) {
-                    if lco {
-                        self.try_execute(machine_st, code_dirs, name, arity)
-                    } else {
-                        self.try_call(machine_st, code_dirs, name, arity)
-                    }
+                    self.context_call(machine_st, code_dirs, name, arity, lco)
                 } else {
                     Ok(())
                 },
@@ -510,11 +517,7 @@ pub(crate) trait CallPolicy: Any {
                 Ok(())
             },
             &ClauseType::Named(ref name) | &ClauseType::Op(ref name, _) =>
-                if lco {
-                    self.try_execute(machine_st, code_dirs, name.clone(), arity)
-                } else {
-                    self.try_call(machine_st, code_dirs, name.clone(), arity)
-                },
+                self.context_call(machine_st, code_dirs, name.clone(), arity, lco),
             &ClauseType::CallWithInferenceLimit => {
                 machine_st.goto_ptr(CodePtr::DirEntry(393, clause_name!("builtin")), 3, lco);
                 Ok(())
index fc0dc06b0f1ffc5d722cdacfb1413e42c2609e0f..73ae9e152c0a9a638905a74cbcaf7659de1456eb 100644 (file)
@@ -1285,14 +1285,14 @@ impl MachineState {
 
                 self.compare_numbers(cmp, n1, n2);
             },
-            &BuiltInInstruction::DefaultSetCutPoint(r) => {
-                let mut cut_policy = DefaultCutPolicy {};
-                cut_policy.cut(self, r);
-            },
             &BuiltInInstruction::DefaultRetryMeElse(o) => {
                 let mut call_policy = DefaultCallPolicy {};
                 try_or_fail!(self, call_policy.retry_me_else(self, o));
             },
+            &BuiltInInstruction::DefaultSetCutPoint(r) => {
+                let mut cut_policy = DefaultCutPolicy {};
+                cut_policy.cut(self, r);
+            },
             &BuiltInInstruction::DefaultTrustMe => {
                 let mut call_policy = DefaultCallPolicy {};
                 try_or_fail!(self, call_policy.trust_me(self));