]> Repositorios git - scryer-prolog.git/commitdiff
fix attributed variables bug causing weighted_maximum/3 example to omit a variable... v0.8.115
authorMark Thom <[email protected]>
Sun, 20 Oct 2019 20:50:46 +0000 (14:50 -0600)
committerMark Thom <[email protected]>
Sun, 20 Oct 2019 20:50:46 +0000 (14:50 -0600)
Cargo.toml
README.md
src/prolog/lib/clpb.pl
src/prolog/lib/dif.pl
src/prolog/lib/freeze.pl
src/prolog/lib/lists.pl
src/prolog/machine/attributed_variables.rs
src/prolog/machine/machine_state_impl.rs
src/prolog/machine/mod.rs

index c39d3b12c4bc17e46ad6187aa4d70eed8dd3a898..e770aea9282757b594fd106f5606aafad61b92a4 100644 (file)
@@ -1,6 +1,6 @@
 [package]
 name = "scryer-prolog"
-version = "0.8.114"
+version = "0.8.115"
 authors = ["Mark Thom <[email protected]>"]
 build = "build.rs"
 repository = "https://github.com/mthom/scryer-prolog"
index 57d71b1ee3c19f60d2d27f5c59b11ec892618872..564c757c291fadc6e2b5895fb32875a66c28582c 100644 (file)
--- a/README.md
+++ b/README.md
@@ -93,7 +93,7 @@ strings.
 
 First, install the latest stable version of
 [Rust](https://www.rust-lang.org/en-US/install.html) using your
-preferred method. Then install the latest Scryer Prolog with cargo,
+preferred method. Then install Scryer Prolog with cargo,
 like so:
 
 ```
@@ -101,13 +101,27 @@ $> cargo install scryer-prolog
 ```
 
 cargo will download and install the libraries Scryer Prolog uses
-automatically. You can find the `scryer-prolog` executable in
-`~/.cargo/bin`.
+automatically from crates.io. You can find the `scryer-prolog`
+executable in `~/.cargo/bin`.
+
+Publishing Rust crates to crates.io and pushing to git are entirely
+distinct, independent processes, so to be sure you have the latest
+commit, it is recommended to clone directly from this git repository,
+which can be done as follows:
+
+```
+$> git clone https://github.com/mthom/scryer-prolog
+$> cd scryer-prolog
+$> cargo run [--release]
+```
+
+The optional `--release` flag will perform various optimizations,
+producing a faster executable.
 
 Note on compatibility: Scryer Prolog should work on Linux, Mac OS X,
 and BSD variants on which Rust runs. Windows support hinges on
 rustyline and Termion being functional in that environment, which to
-my knowledge is not currently the case.
+my knowledge is not presently the case.
 
 ## Built-in predicates
 
index d35b488c1d4d9a5b6624ccab8ddad7b93ad1d27c..2b140a72db24680e8292138a6bc809cf5dfce9bf 100644 (file)
@@ -1159,7 +1159,7 @@ labeling_var(V) :- V == 1, !.
 labeling_var(V) :- domain_error(clpb_variable, V).
 
 variables_in_index_order(Vs0, Vs) :-
-        maplist(var_with_index, Vs0, IVs0),
+        maplist(var_with_index, Vs0, IVs0),    
         keysort(IVs0, IVs),
         pairs_values(IVs, Vs).
 
@@ -1245,7 +1245,7 @@ bdd_count(Node, VNum, Count) :-
                 bdd_pow(Low, V, VNum, LPow),
                 bdd_pow(High, V, VNum, HPow),
                 Count0 is LPow*LCount + HPow*HCount,
-                Count = Count0
+               Count0 = Count
             )
         ).
 
@@ -1358,7 +1358,7 @@ weighted_maximum(Ws, Vars, Max) :-
         pairs_values(IVs1, VarsIndexOrder),
         % Pairs is a list of Var-Weight terms, in index order of Vars
         pairs_keys_values(Pairs, VarsIndexOrder, WeightsIndexOrder),
-        bdd_maximum(BDD, Pairs, Max),
+        bdd_maximum(BDD, Pairs, Max), %% A,B are in BDD, but not C; A,B,C *are* in Pairs.
         max_labeling(BDD, Pairs).
 
 max_labeling(1, Pairs) :- max_upto(Pairs, _, _).
@@ -1509,7 +1509,7 @@ max_variable_node(Node, V0-N0, V-N) :-
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
 
 ands_fusion(Ands0, Ands) :-
-        maplist(with_variables, Ands0, Pairs0),
+        maplist(with_variables, Ands0, Pairs0),        
         keysort(Pairs0, Pairs),
         group_pairs_by_key(Pairs, Groups),
         pairs_values(Groups, Andss),
index 77cfee571cabe48d3e9b6a0b25be84024ee4d01e..347e9d13571dbc1268a89ddb53059c2820c2d08e 100644 (file)
@@ -51,4 +51,5 @@ gather_dif_goals([(X \== Y) | Goals]) -->
 
 attribute_goals(X) -->
     { get_atts(X, +dif(Goals)) },
-    gather_dif_goals(Goals).
+    gather_dif_goals(Goals),
+    { put_atts(X, -dif(_)) }.
index 96e3dda5b9f01d775dcd5b5847345d5e1c734cb2..049e024b53d22b74cc505041a3162241028b0dde 100644 (file)
@@ -26,6 +26,7 @@ gather_freeze_goals(Attrs, _) -->
     !.
 gather_freeze_goals([frozen(X) | _], Var) -->
     [freeze(Var, X)],
+    { put_atts(Var, -frozen(_)) },
     !.
 gather_freeze_goals([_ | Attrs], Var) -->
     gather_freeze_goals(Attrs, Var).
index c7d8e6a3a44dc31eda1e7960590263f8d8a9ad9e..4fc5de96c6ba9b9522e22445272c49e7630f1906 100644 (file)
@@ -3,6 +3,7 @@
                  maplist/4, maplist/5, maplist/6, maplist/7,
                  maplist/8, maplist/9]).
 
+
 length(Xs, N) :-
     var(N), !,
     '$skip_max_list'(M, -1, Xs, Xs0),
@@ -30,17 +31,22 @@ length_rundown([_|Xs], N) :-
     N1 is N-1,
     length_rundown(Xs, N1).
 
+
 member(X, [X|_]).
 member(X, [_|Xs]) :- member(X, Xs).
 
+
 select(X, [X|Xs], Xs).
 select(X, [Y|Xs], [Y|Ys]) :- select(X, Xs, Ys).
 
+
 append([], R, R).
 append([X|L], R, [X|S]) :- append(L, R, S).
 
+
 memberchk(X, Xs) :- member(X, Xs), !.
 
+
 reverse(Xs, Ys) :-
     (  nonvar(Xs) -> reverse(Xs, Ys, [], Xs)
     ;  reverse(Ys, Xs, [], Ys)
@@ -50,6 +56,7 @@ reverse([], [], YsRev, YsRev).
 reverse([X1|Xs], [Y1|Ys], YsPreludeRev, Xss) :-
     reverse(Xs, Ys, [Y1|YsPreludeRev], Xss).
 
+
 maplist(_, []).
 maplist(Cont1, [E1|E1s]) :-
     call(Cont1, E1),
index 638c403b7581d7412de61d41d5b52b20c46b54bf..80fd11bcfd58c2cf13e3f60ac9146bd2cf3beb08 100644 (file)
@@ -131,24 +131,17 @@ impl MachineState {
     }
 
     pub(super) fn verify_attr_interrupt(&mut self, p: usize) {
-        let rs = MAX_ARITY;
-
-        // store temp vars in perm vars slots along with self.b0 and
-        // self.num_of_args. why self.b0? if we return to a NeckCut
-        // after finishing the interrupt, it won't work correctly if
-        // self.b == self.b0. we must change it back when we return,
-        // as if nothing happened.
-        self.allocate(rs + 2);
+        self.allocate(self.num_of_args + 2);
 
         let e = self.e;
         self.and_stack[e].interrupt_cp = self.attr_var_init.cp;
 
-        for i in 1..rs + 1 {
+        for i in 1 .. self.num_of_args + 1 {
             self.and_stack[e][i] = self[RegType::Temp(i)].clone();
         }
 
-        self.and_stack[e][rs + 1] = Addr::Con(Constant::Usize(self.b0));
-        self.and_stack[e][rs + 2] = Addr::Con(Constant::Usize(self.num_of_args));
+        self.and_stack[e][self.num_of_args + 1] = Addr::Con(Constant::Usize(self.b0));
+        self.and_stack[e][self.num_of_args + 2] = Addr::Con(Constant::Usize(self.num_of_args));
 
         self.verify_attributes();
 
index 32a067745ef1eac11b9c0028e0808a51cd258c53..16495c1e0e9bf901b683f5d32e6f5d0a0457cbf6 100644 (file)
@@ -754,7 +754,7 @@ impl MachineState {
                       offset += 1;
                   } else {
                       self.trail[i - offset] = self.trail[i];
-                  },     
+                  },
                 TrailRef::Ref(Ref::StackCell(fr, _)) => {
                     let fr_gi = self.and_stack[fr].global_index;
                     let b_gi = if !self.or_stack.is_empty() {
@@ -775,7 +775,7 @@ impl MachineState {
         self.tr -= offset;
         self.trail.truncate(self.tr);
     }
-        
+
     #[inline]
     fn write_char_to_string(&mut self, s: &mut StringList, c: char) -> bool {
         self.pstr_trail(s.clone());
@@ -3231,6 +3231,8 @@ impl MachineState {
                 )
             ),
         };
+
+        self.last_call = false;
     }
 
     pub(super) fn execute_ctrl_instr(
@@ -3266,7 +3268,7 @@ impl MachineState {
                 self.b0 = self.b;
                 self.p += offset;
             }
-            &ControlInstruction::Proceed => self.p = CodePtr::Local(self.cp.clone()),
+            &ControlInstruction::Proceed => self.p = CodePtr::Local(self.cp.clone())
         };
     }
 
index 21ed9670a683b715a50a1a692101a004ad9238ef..c8ea15c49ef57c371c971d5864b153fc2cd4273f 100644 (file)
@@ -1112,12 +1112,12 @@ impl MachineState {
 
             match self.p {
                 CodePtr::VerifyAttrInterrupt(_) => {
-                    self.p = CodePtr::Local(self.attr_var_init.cp);
+                    self.p = CodePtr::Local(self.attr_var_init.cp);                    
 
                     let instigating_p = CodePtr::Local(self.attr_var_init.instigating_p);
                     let instigating_instr = code_repo.lookup_instr(false, &instigating_p).unwrap();
 
-                    if instigating_instr.as_ref().is_head_instr() {
+                    if !instigating_instr.as_ref().is_head_instr() {
                         let cp = self.p.local();
                         self.run_verify_attr_interrupt(cp);
                     } else if !self.verify_attr_stepper(indices, policies, code_repo, prolog_stream) {