]> Repositorios git - scryer-prolog.git/commitdiff
fix allocator bug.
authorMark Thom <[email protected]>
Sun, 11 Feb 2018 22:21:30 +0000 (15:21 -0700)
committerMark Thom <[email protected]>
Sun, 11 Feb 2018 22:21:30 +0000 (15:21 -0700)
src/prolog/allocator.rs
src/prolog/codegen.rs
src/prolog/debray_allocator.rs
src/prolog/io.rs

index aa30a415788261f0cd78e882c6dc7db2a5b3358f..cd9f523b11857978efc625a73244fc4a41d377cd 100644 (file)
@@ -18,7 +18,6 @@ pub trait Allocator<'a>
     fn reset(&mut self);
     fn reset_contents(&mut self) {}
     fn reset_arg(&mut self, usize);
-    fn reset_arg_at_head(&mut self, &'a Term);
     
     fn advance_arg(&mut self);
 
index 91b54dad9ee00e7f2bffef6c4aa146719435095b..d8ad9e41bf8b3f21d075a133dca428410e53cf9a 100644 (file)
@@ -574,7 +574,7 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
         let mut code = Vec::new();
 
         if let &QueryTerm::Term(ref term) = p0 {
-            self.marker.reset_arg_at_head(term);
+            self.marker.reset_arg(term.arity());
             self.compile_seq_prelude(&conjunct_info, &mut code);
 
             if let &Term::Clause(..) = term {
@@ -586,8 +586,6 @@ impl<'a, TermMarker: Allocator<'a>> CodeGenerator<'a, TermMarker>
                 }
             }
 
-            // self.marker.reset_arg_at_head(term);
-
             let iter = ChunkedIterator::from_rule_body(p1, clauses);
             try!(self.compile_seq(iter, &conjunct_info, &mut code, false));
 
index fdfba43bf3b52644ebae139fc5926389b90485c1..0e86efe9bc66edb56bd18f4bb4527b8873e5b269 100644 (file)
@@ -21,7 +21,7 @@ impl<'a> DebrayAllocator<'a> {
             _ => false
         }
     }
-    
+
     fn occurs_shallowly_in_head(&self, var: &'a Var, r: usize) -> bool
     {
         match self.bindings.get(var).unwrap() {
@@ -188,7 +188,7 @@ impl<'a> DebrayAllocator<'a> {
                      _ => false
                  }
         }
-    }    
+    }
 }
 
 impl<'a> Allocator<'a> for DebrayAllocator<'a>
@@ -202,7 +202,7 @@ impl<'a> Allocator<'a> for DebrayAllocator<'a>
             in_use: BTreeSet::new()
         }
     }
-    
+
     fn mark_anon_var<Target>(&mut self, lvl: Level, target: &mut Vec<Target>)
         where Target: CompilationTarget<'a>
     {
@@ -263,22 +263,20 @@ impl<'a> Allocator<'a> for DebrayAllocator<'a>
             RegType::Perm(0) => {
                 let pr = cell.get().norm();
                 self.record_register(var, pr);
-                
+
                 (pr, true)
             },
-            r => (r, false)            
+            r => (r, false)
         };
 
         match lvl {
             Level::Shallow => {
                 let k = self.arg_c;
 
-                if !r.is_perm() {                    
-                    if self.is_curr_arg_distinct_from(var) {
-                        self.evacuate_arg(term_loc.chunk_num(), target);
-                    }
+                if self.is_curr_arg_distinct_from(var) {
+                    self.evacuate_arg(term_loc.chunk_num(), target);
                 }
-                
+
                 self.arg_c += 1;
 
                 cell.set(VarReg::ArgAndNorm(r, k));
@@ -304,14 +302,14 @@ impl<'a> Allocator<'a> for DebrayAllocator<'a>
             Level::Deep =>
                 target.push(Target::subterm_to_value(r))
         };
-        
+
         if !r.is_perm() {
             let o = r.reg_num();
 
             self.contents.insert(o, var);
             self.record_register(var, r);
             self.in_use.insert(o);
-        }        
+        }
     }
 
     fn reset(&mut self) {
@@ -324,7 +322,7 @@ impl<'a> Allocator<'a> for DebrayAllocator<'a>
         self.contents.clear();
         self.in_use.clear();
     }
-    
+
     fn advance_arg(&mut self) {
         self.arg_c += 1;
     }
@@ -332,7 +330,7 @@ impl<'a> Allocator<'a> for DebrayAllocator<'a>
     fn bindings(&self) -> &AllocVarDict<'a> {
         &self.bindings
     }
-    
+
     fn bindings_mut(&mut self) -> &mut AllocVarDict<'a> {
         &mut self.bindings
     }
@@ -340,24 +338,9 @@ impl<'a> Allocator<'a> for DebrayAllocator<'a>
     fn take_bindings(self) -> AllocVarDict<'a> {
         self.bindings
     }
-    
+
     fn reset_arg(&mut self, arity: usize) {
         self.arg_c   = 1;
         self.temp_lb = arity + 1;
     }
-
-    fn reset_arg_at_head(&mut self, term: &'a Term) {
-        self.arg_c = 1;
-        self.temp_lb = term.arity() + 1;
-
-        match term {
-            &Term::Clause(_, _, ref subterms, _) =>
-                for (idx, tr) in subterms.iter().enumerate() {
-                    if let &Term::Var(_, _) = tr.as_ref() {
-                        self.in_use.insert(idx + 1);
-                    }
-                },
-            _ => {}
-        };
-    }
 }
index 0affc7224a6a9312021a5745ea3cb3ecf6f08326..55d0d9eed8f7f98535fb2147a51c8bf662ccf554 100644 (file)
@@ -517,7 +517,7 @@ fn compile_decl<'a, 'b: 'a>(wam: &'a mut Machine, tl: &'b TopLevel, queue: &'b V
             if let Err(e) = compile_appendix(&mut code, queue) {
                 return EvalSession::from(e);
             };
-            
+
             if !code.is_empty() {
                 if let Some(name) = tl.name() {
                     wam.add_user_code(name, tl.arity(), code)