]> Repositorios git - scryer-prolog.git/commitdiff
correct inlining calling in last call context
authorMark Thom <[email protected]>
Sun, 3 Mar 2019 05:57:07 +0000 (22:57 -0700)
committerMark Thom <[email protected]>
Sun, 3 Mar 2019 05:57:07 +0000 (22:57 -0700)
Cargo.lock
src/prolog/lib/builtins.pl
src/prolog/lib/lists.pl
src/prolog/machine/machine_state.rs
src/prolog/machine/machine_state_impl.rs
src/prolog/machine/system_calls.rs

index 8ec9cd09ee83274fe5c79368fc2fe1d378deda12..ef109bb754e6843a778d7ac005a02695a56949d0 100644 (file)
@@ -87,6 +87,7 @@ dependencies = [
 [[package]]
 name = "prolog_parser"
 version = "0.8.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "num 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "ordered-float 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -112,7 +113,7 @@ dependencies = [
  "downcast 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "num 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "ordered-float 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
- "prolog_parser 0.8.1",
+ "prolog_parser 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
  "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
@@ -151,6 +152,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
 "checksum num-traits 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "cacfcab5eb48250ee7d0c7896b51a2c5eec99c1feea5f32025635f5ae4b00070"
 "checksum num-traits 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "630de1ef5cc79d0cdd78b7e33b81f083cbfe90de0f4b2b2f07f905867c70e9fe"
 "checksum ordered-float 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "58d25b6c0e47b20d05226d288ff434940296e7e2f8b877975da32f862152241f"
+"checksum prolog_parser 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6da85e0cfa5a604edf65f753e629db37bfd04af93a09a1df5576d2197a2f7af3"
 "checksum redox_syscall 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "ab105df655884ede59d45b7070c8a65002d921461ee813a024558ca16030eea0"
 "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76"
 "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096"
index a8372b4e4be09cbcbcffc659fb86b0fe5b6a2a2b..217ee1a4b4f0d8dcbd2c8ca784d8247bc94351f7 100644 (file)
@@ -613,70 +613,8 @@ match_builtins(string, 1).
 match_builtins(float, 1).
 match_builtins(nonvar, 1).
 match_builtins(var, 1).
-match_builtins(call, 0).
-match_builtins(call, 1).
-match_builtins(call, 2).
-match_builtins(call, 3).
-match_builtins(call, 4).
-match_builtins(call, 5).
-match_builtins(call, 6).
-match_builtins(call, 7).
-match_builtins(call, 8).
-match_builtins(call, 9).
-match_builtins(call, 10).
-match_builtins(call, 11).
-match_builtins(call, 12).
-match_builtins(call, 13).
-match_builtins(call, 14).
-match_builtins(call, 15).
-match_builtins(call, 16).
-match_builtins(call, 17).
-match_builtins(call, 18).
-match_builtins(call, 19).
-match_builtins(call, 20).
-match_builtins(call, 21).
-match_builtins(call, 22).
-match_builtins(call, 23).
-match_builtins(call, 24).
-match_builtins(call, 25).
-match_builtins(call, 26).
-match_builtins(call, 27).
-match_builtins(call, 28).
-match_builtins(call, 29).
-match_builtins(call, 30).
-match_builtins(call, 31).
-match_builtins(call, 32).
-match_builtins(call, 33).
-match_builtins(call, 34).
-match_builtins(call, 35).
-match_builtins(call, 36).
-match_builtins(call, 37).
-match_builtins(call, 38).
-match_builtins(call, 39).
-match_builtins(call, 40).
-match_builtins(call, 41).
-match_builtins(call, 42).
-match_builtins(call, 43).
-match_builtins(call, 44).
-match_builtins(call, 45).
-match_builtins(call, 46).
-match_builtins(call, 47).
-match_builtins(call, 48).
-match_builtins(call, 49).
-match_builtins(call, 50).
-match_builtins(call, 51).
-match_builtins(call, 52).
-match_builtins(call, 53).
-match_builtins(call, 54).
-match_builtins(call, 55).
-match_builtins(call, 56).
-match_builtins(call, 57).
-match_builtins(call, 58).
-match_builtins(call, 59).
-match_builtins(call, 60).
-match_builtins(call, 61).
-match_builtins(call, 62).
-match_builtins(call, 63).
+match_builtins(call, N) :-
+    between:between(0, 63, N).
 
 '$iterate_predicate_list'([Name/Arity|Preds], Name/Arity).
 '$iterate_predicate_list'([_|Preds], Pred) :-
index 1c5317da4c976a2b22d0d7e0287da3f81869a684..078b9674fcaa23e874144b8d6a80ba9a7e32a264 100644 (file)
@@ -86,3 +86,4 @@ maplist(_, [], [], [], [], [], [], [], []).
 maplist(Cont, [E1|E1s], [E2|E2s], [E3|E3s], [E4|E4s], [E5|E5s], [E6|E6s], [E7|E7s], [E8|E8s]) :-
     call(Cont, E1, E2, E3, E4, E5, E6, E7),
     maplist(Cont, E1s, E2s, E3s, E4s, E5s, E6s, E7s, E8s).
+    
index 287b19c9288adf984364750964c41d15159c06be..e634351c4176f12f853eb2621ea97bc022f4d17c 100644 (file)
@@ -747,8 +747,13 @@ pub(crate) trait CallPolicy: Any {
                     machine_st.setup_built_in_call(built_in.clone());
                     self.call_builtin(machine_st, &built_in, indices)?;
                 },
-                ClauseType::Inlined(inlined) =>
-                    machine_st.execute_inlined(&inlined),
+                ClauseType::Inlined(inlined) => {
+                    machine_st.execute_inlined(&inlined);
+
+                    if machine_st.last_call {
+                        machine_st.p = CodePtr::Local(machine_st.cp);
+                    }
+                },
                 ClauseType::Op(..) | ClauseType::Named(..) => {
                     let module = name.owning_module();
 
index 675f93834a4c3443993b1ce19693ce2bee5a57ce..9e6c41a5a6d8cf4e60f50fff77261cab813abdbe 100644 (file)
@@ -1768,7 +1768,7 @@ impl MachineState {
                 let d = self.store(self.deref(self[r1].clone()));
 
                 match d {
-                    Addr::Con(Constant::Atom(..)) | Addr::Con(Constant::Char(_)) => {},
+                    Addr::Con(Constant::Atom(..)) | Addr::Con(Constant::Char(_)) => self.p += 1,
                     _ => self.fail = true
                 };
             },
@@ -1776,7 +1776,7 @@ impl MachineState {
                 let d = self.store(self.deref(self[r1].clone()));
 
                 match d {
-                    Addr::Con(_) => {},
+                    Addr::Con(_) => self.p += 1,
                     _ => self.fail = true
                 };
             },
@@ -1784,7 +1784,7 @@ impl MachineState {
                 let d = self.store(self.deref(self[r1].clone()));
 
                 match d {
-                    Addr::Con(Constant::Number(Number::Integer(_))) => {},
+                    Addr::Con(Constant::Number(Number::Integer(_))) => self.p += 1,
                     _ => self.fail = true
                 };
             },
@@ -1792,7 +1792,7 @@ impl MachineState {
                 let d = self.store(self.deref(self[r1].clone()));
 
                 match d {
-                    Addr::Str(_) | Addr::Lis(_) => {},
+                    Addr::Str(_) | Addr::Lis(_) => self.p += 1,
                     _ => self.fail = true
                 };
             },
@@ -1800,7 +1800,7 @@ impl MachineState {
                 let d = self.store(self.deref(self[r1].clone()));
 
                 match d {
-                    Addr::Con(Constant::Number(Number::Float(_))) => {},
+                    Addr::Con(Constant::Number(Number::Float(_))) => self.p += 1,
                     _ => self.fail = true
                 };
             },
@@ -1808,7 +1808,7 @@ impl MachineState {
                 let d = self.store(self.deref(self[r1].clone()));
 
                 match d {
-                    Addr::Con(Constant::Number(Number::Rational(_))) => {},
+                    Addr::Con(Constant::Number(Number::Rational(_))) => self.p += 1,
                     _ => self.fail = true
                 };
             },
@@ -1816,7 +1816,7 @@ impl MachineState {
                 let d = self.store(self.deref(self[r1].clone()));
 
                 match d {
-                    Addr::Con(Constant::String(_)) => {},
+                    Addr::Con(Constant::String(_)) => self.p += 1,
                     _ => self.fail = true
                 };
             },
@@ -1825,14 +1825,14 @@ impl MachineState {
 
                 match d {
                     Addr::AttrVar(_) | Addr::HeapCell(_) | Addr::StackCell(..) => self.fail = true,
-                    _ => {}
+                    _ => self.p += 1
                 };
             },
             &InlinedClauseType::IsVar(r1) => {
                 let d = self.store(self.deref(self[r1].clone()));
 
                 match d {
-                    Addr::AttrVar(_) | Addr::HeapCell(_) | Addr::StackCell(_,_) => {},
+                    Addr::AttrVar(_) | Addr::HeapCell(_) | Addr::StackCell(_,_) => self.p += 1,
                     _ => self.fail = true
                 };
             },
@@ -1840,13 +1840,11 @@ impl MachineState {
                 let d = self.store(self.deref(self[r1].clone()));
 
                 match d {
-                    Addr::Con(Constant::String(ref s)) if s.is_expandable() => {},
+                    Addr::Con(Constant::String(ref s)) if s.is_expandable() => self.p += 1,
                     _ => self.fail = true
                 };
             }
         }
-
-        self.set_p();
     }
 
     fn try_functor_unify_components(&mut self, name: Addr, arity: Addr) {
@@ -2208,8 +2206,13 @@ impl MachineState {
                 try_or_fail!(self, call_policy.call_n(self, arity, indices)),
             &ClauseType::Hook(ref hook) =>
                 try_or_fail!(self, call_policy.compile_hook(self, hook)),
-            &ClauseType::Inlined(ref ct) =>
-                self.execute_inlined(ct),
+            &ClauseType::Inlined(ref ct) => {
+                self.execute_inlined(ct);
+                
+                if lco {
+                    self.p = CodePtr::Local(self.cp);
+                }
+            },
             &ClauseType::Named(ref name, _, ref idx) | &ClauseType::Op(OpDecl(.., ref name), ref idx) =>
                 try_or_fail!(self, call_policy.context_call(self, name.clone(), arity, idx.clone(),
                                                             indices)),
index 5cd345062d7f95970cff12c6661c84be97184271..bd1ce50455f8471488435e583ff9297e1ba2dd28 100644 (file)
@@ -186,7 +186,7 @@ impl MachineState {
     pub(super)
     fn set_p(&mut self) {
         if self.last_call {
-            self.p = CodePtr::Local(self.cp.clone());
+            self.p = CodePtr::Local(self.cp);
         } else {
             self.p += 1;
         }