]> Repositorios git - scryer-prolog.git/commitdiff
indexing bug fixes, corrections to ,
authorMark Thom <[email protected]>
Sun, 24 Dec 2017 22:44:40 +0000 (15:44 -0700)
committerMark Thom <[email protected]>
Sun, 24 Dec 2017 22:44:40 +0000 (15:44 -0700)
Cargo.lock
src/prolog/ast.rs
src/prolog/builtins.rs
src/prolog/indexing.rs
src/prolog/io.rs
src/prolog/machine.rs
src/prolog/macros.rs

index bcb30e0c75cedda153291d521de381559ff638b4..56e97a19c5c4c431f71771f8bdf2ea84ff2dbd02 100644 (file)
@@ -1,6 +1,6 @@
 [root]
 name = "rusty-wam"
-version = "0.7.3"
+version = "0.7.4"
 dependencies = [
  "lazy_static 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
  "num 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
index ee86c1b331fc8ca508adec65f17274a1e2e6fea6..77f065869f7658f30461ef26b823ccdf88b0ec3e 100644 (file)
@@ -729,8 +729,7 @@ pub enum BuiltInInstruction {
     IsVar(RegType),
     ResetBlock,
     SetBall,
-    SetNeckCutPoint(Terminal),
-    SetNonNeckCutPoint(Terminal),
+    SetCutPoint,
     Succeed,
     Unify,
     UnwindStack
index 3dce6392bd7d36bc9202570376be2a055c45b7cb..cdb7f53e401ef949794d9848b312d884fb21e399 100644 (file)
@@ -121,7 +121,7 @@ fn get_builtins() -> Code {
          deallocate!(),
          goto!(88, 3),
          try_me_else!(25), // ','/3, 88.
-         switch_on_term!(4, 0, 0, 0),
+         switch_on_term!(4, 1, 0, 0),
          indexed_try!(4),
          retry!(11),
          trust!(14),
@@ -133,7 +133,7 @@ fn get_builtins() -> Code {
                unify_variable!(perm_v!(1)),
                get_var_in_fact!(perm_v!(3), 3)],
          query![put_value!(perm_v!(3), 1)],
-         set_non_neck_cp!(non_terminal!()),
+         set_cp!(),
          query![put_unsafe_value!(2, 1),
                 put_unsafe_value!(1, 2),
                 put_value!(perm_v!(3), 3)],
@@ -143,30 +143,32 @@ fn get_builtins() -> Code {
          fact![get_constant!(Constant::from("!"), temp_v!(1)),
                get_constant!(Constant::from("!"), temp_v!(2))],
          query![put_value!(temp_v!(3), 1)],
-         set_neck_cp!(terminal!()),
+         set_cp!(),
          trust_me!(),
          allocate!(1),
          fact![get_constant!(Constant::from("!"), temp_v!(1)),
                get_var_in_fact!(perm_v!(1), 2)],
          query![put_value!(temp_v!(3), 1)],
-         set_non_neck_cp!(non_terminal!()),
+         set_cp!(),
          query![put_value!(perm_v!(1), 1)],
          deallocate!(),
          execute_n!(1),
-         retry_me_else!(7),
+         retry_me_else!(8),
          allocate!(1),
          fact![get_constant!(Constant::from("!"), temp_v!(2)),
                get_var_in_fact!(perm_v!(1), 3)],
+         neck_cut!(non_terminal!()),
          call_n!(1),
          query![put_value!(perm_v!(1), 1)],
          deallocate!(),
-         set_non_neck_cp!(terminal!()),
-         retry_me_else!(7),
+         set_cp!(),
+         retry_me_else!(8), // 121.
          allocate!(3),
          fact![get_structure!(String::from(","), 2, temp_v!(2)),
                unify_variable!(perm_v!(2)),
                unify_variable!(perm_v!(1)),
-               get_var_in_fact!(perm_v!(3), 3)],         
+               get_var_in_fact!(perm_v!(3), 3)],
+         neck_cut!(non_terminal!()),
          call_n!(1),
          query![put_unsafe_value!(2, 1),
                 put_unsafe_value!(1, 2),
@@ -175,12 +177,12 @@ fn get_builtins() -> Code {
          goto!(88, 3),
          trust_me!(),
          allocate!(1),
-         fact![get_var_in_fact!(perm_v!(1), 2)],
+         fact![get_var_in_fact!(perm_v!(1), 2)],         
          call_n!(1),
          query![put_value!(perm_v!(1), 1)],
          deallocate!(),
          execute_n!(1),
-         allocate!(2), // (->)/2, 134.
+         allocate!(2), // (->)/2, 136.
          get_level!(),
          fact![get_var_in_fact!(perm_v!(2), 2)],
          call_n!(1),
@@ -254,7 +256,7 @@ pub fn build_code_dir() -> (Code, CodeDir, OpDir)
 
     code_dir.insert((String::from(";"), 2), (PredicateKeyType::BuiltIn, 76));
     code_dir.insert((String::from(","), 2), (PredicateKeyType::BuiltIn, 81));    
-    code_dir.insert((String::from("->"), 2), (PredicateKeyType::BuiltIn, 134));
+    code_dir.insert((String::from("->"), 2), (PredicateKeyType::BuiltIn, 136));
     
     (builtin_code, code_dir, op_dir)
 }
index f087c8317786a5d3d61ac8029db0146af0d6a220..3d94ec02c7e9cf9f79cc3e023f2591c536677200 100644 (file)
@@ -116,6 +116,15 @@ impl CodeOffsets {
         flattened_index
     }
 
+    fn adjust_internal_index(index: IntIndex) -> IntIndex
+    {
+        match index {
+            IntIndex::Internal(o) => IntIndex::Internal(o + 1),
+            IntIndex::External(o) => IntIndex::External(o),
+            _ => IntIndex::Fail
+        }
+    }
+    
     fn switch_on_constant(con_ind: HashMap<Constant, ThirdLevelIndex>, prelude: &mut CodeDeque)
                           -> IntIndex
     {
@@ -130,24 +139,11 @@ impl CodeOffsets {
             IntIndex::Internal(1)
         } else {
             con_ind.values().next()
-                   .map(|i| *i)
+                   .map(|index| Self::adjust_internal_index(*index))
                    .unwrap_or(IntIndex::Fail)
         }
     }
 
-    fn switch_on_list(mut lists: ThirdLevelIndex, prelude: &mut CodeDeque) -> IntIndex
-    {
-        if lists.len() > 1 {
-            Self::cap_choice_seq_with_trust(&mut lists);
-            prelude.extend(lists.into_iter().map(|i| Line::from(i)));
-            IntIndex::Internal(0)
-        } else {
-            lists.first()
-                 .map(|i| IntIndex::External(i.offset()))
-                 .unwrap_or(IntIndex::Fail)
-        }
-    }
-
     fn switch_on_structure(str_ind: HashMap<(Atom, usize), ThirdLevelIndex>, prelude: &mut CodeDeque)
                            -> IntIndex
     {
@@ -162,11 +158,23 @@ impl CodeOffsets {
             IntIndex::Internal(1)
         } else {
             str_ind.values().next()
-                   .map(|i| *i)
+                   .map(|index| Self::adjust_internal_index(*index))
                    .unwrap_or(IntIndex::Fail)
         }
     }
 
+    fn switch_on_list(mut lists: ThirdLevelIndex, prelude: &mut CodeDeque) -> IntIndex
+    {
+        if lists.len() > 1 {
+            Self::cap_choice_seq_with_trust(&mut lists);
+            prelude.extend(lists.into_iter().map(|i| Line::from(i)));
+            IntIndex::Internal(0)
+        } else {
+            lists.first()
+                 .map(|i| IntIndex::External(i.offset()))
+                 .unwrap_or(IntIndex::Fail)
+        }
+    }
 
     fn switch_on_str_offset_from(str_loc: IntIndex, prelude_len: usize, con_loc: IntIndex)
                                  -> usize
@@ -186,7 +194,7 @@ impl CodeOffsets {
         match con_loc {
             IntIndex::External(offset) => offset + prelude_len + 1,
             IntIndex::Fail => 0,
-            IntIndex::Internal(offset) => offset,
+            IntIndex::Internal(offset) => offset, 
         }
     }
 
index d63b700db0a956822028731c1266d24cc808521f..5780dec38434454079ccc39f24be7a1936797c4f 100644 (file)
@@ -183,10 +183,8 @@ impl fmt::Display for BuiltInInstruction {
                 write!(f, "reset_block"),
             &BuiltInInstruction::SetBall =>
                 write!(f, "set_ball"),
-            &BuiltInInstruction::SetNeckCutPoint(terminal) =>
-                write!(f, "set_neck_cp {}", terminal),
-            &BuiltInInstruction::SetNonNeckCutPoint(terminal) =>
-                write!(f, "set_non_neck_cp {}", terminal),
+            &BuiltInInstruction::SetCutPoint =>
+                write!(f, "set_cp"),
             &BuiltInInstruction::Succeed =>
                 write!(f, "true"),
             &BuiltInInstruction::UnwindStack =>
@@ -399,7 +397,7 @@ pub fn eval<'a, 'b: 'a>(wam: &'a mut Machine, tl: &'b TopLevel) -> EvalSession<'
                 Ok(rule) => rule,
                 Err(e) => return EvalSession::ParserError(e)                
             };
-
+            
             wam.add_rule(rule, compiled_rule)
         },
         &TopLevel::Query(ref query) => {
index 047a05f154186c4018cc66e0eda9227debb91708..4ea6dc2c21fe008eaa1386eec393601f53c34004 100644 (file)
@@ -1666,24 +1666,17 @@ impl MachineState {
 
                 self.p += 1;
             },
-            &BuiltInInstruction::SetNeckCutPoint(terminal) => {
+            &BuiltInInstruction::SetCutPoint => {
                 let nb = self.store(self.deref(self[temp_v!(1)].clone()));
 
                 match nb {
                     Addr::Con(Constant::Usize(nb)) => {
+                        self.or_stack.truncate(nb);
                         self.b = nb;
-                        self.neck_cut(terminal);
-                    },
-                    _ => self.fail = true
-                };
-            },
-            &BuiltInInstruction::SetNonNeckCutPoint(terminal) => {
-                let nb = self.store(self.deref(self[temp_v!(1)].clone()));
+                        
+                        self.tidy_trail();
 
-                match nb {
-                    Addr::Con(Constant::Usize(nb)) => {
-                        self.b = nb;
-                        self.non_neck_cut(terminal);
+                        self.p += 1;
                     },
                     _ => self.fail = true
                 };
@@ -1731,7 +1724,7 @@ impl MachineState {
                 self.fail = true;
             },
             &BuiltInInstruction::IsAtomic(r) => {
-                let d = self.deref(self[r].clone());
+                let d = self.store(self.deref(self[r].clone()));
 
                 match d {
                     Addr::Con(_) => self.p += 1,
@@ -1739,7 +1732,7 @@ impl MachineState {
                 };
             },
             &BuiltInInstruction::IsVar(r) => {
-                let d = self.deref(self[r].clone());
+                let d = self.store(self.deref(self[r].clone()));
 
                 match d {
                     Addr::HeapCell(_) | Addr::StackCell(_,_) => self.p += 1,
@@ -2026,11 +2019,10 @@ impl MachineState {
         }
     }
 
-    fn non_neck_cut(&mut self, term: Terminal)
+    fn neck_cut(&mut self, term: Terminal)
     {
         let b = self.b;
-        let e = self.e;
-        let b0 = self.and_stack[e].b0; // STACK[E+2+1]
+        let b0 = self.b0;
 
         if b > b0 {
             self.b = b0;
@@ -2041,13 +2033,14 @@ impl MachineState {
             self.p = self.cp;
         } else {
             self.p += 1;
-        }
+        }        
     }
 
-    fn neck_cut(&mut self, term: Terminal)
+    fn non_neck_cut(&mut self, term: Terminal)
     {
         let b = self.b;
-        let b0 = self.b0;
+        let e = self.e;
+        let b0 = self.and_stack[e].b0; // STACK[E+2+1]
 
         if b > b0 {
             self.b = b0;
@@ -2058,7 +2051,7 @@ impl MachineState {
             self.p = self.cp;
         } else {
             self.p += 1;
-        }        
+        }
     }
     
     fn execute_cut_instr(&mut self, instr: &CutInstruction) {
index c31e5f59cd1850cccd4516ff593ff720199815c8..bd7e72ccfe1622247d9ee2ed8280f967240a3cdd 100644 (file)
@@ -165,12 +165,6 @@ macro_rules! proceed {
     )
 }
 
-macro_rules! terminal {
-    () => (
-        Terminal::Terminal
-    )
-}
-
 macro_rules! non_terminal {
     () => (
         Terminal::Non
@@ -183,6 +177,12 @@ macro_rules! cut {
     )
 }
 
+macro_rules! neck_cut {
+    ($term:expr) => (
+        Line::Cut(CutInstruction::NeckCut($term))
+    )
+}
+
 macro_rules! get_current_block {
     () => (
         Line::BuiltIn(BuiltInInstruction::GetCurrentBlock)
@@ -303,15 +303,9 @@ macro_rules! get_cp {
     )
 }
 
-macro_rules! set_neck_cp {
-    ($term:expr) => (
-        Line::BuiltIn(BuiltInInstruction::SetNeckCutPoint($term))
-    )
-}
-
-macro_rules! set_non_neck_cp {
-    ($term:expr) => (
-        Line::BuiltIn(BuiltInInstruction::SetNonNeckCutPoint($term))
+macro_rules! set_cp {
+    () => (
+        Line::BuiltIn(BuiltInInstruction::SetCutPoint)
     )
 }