]> Repositorios git - scryer-prolog.git/commitdiff
do not print unbound vars at toplevel
authorMark Thom <[email protected]>
Sat, 23 Mar 2019 15:43:05 +0000 (09:43 -0600)
committerMark Thom <[email protected]>
Sat, 23 Mar 2019 15:43:05 +0000 (09:43 -0600)
src/prolog/machine/mod.rs
src/prolog/write.rs

index 624dbefa5ace5132bc65f7d77e34bbe46d54cd1d..584aad8716aad90e707d8a9b35611b645ac5a648 100644 (file)
@@ -249,7 +249,18 @@ impl Machine {
 
         Ok(())
     }
-
+    
+    pub fn remove_unbound_vars(&self, heap_locs: &mut HeapVarDict) {
+        for (var, addr) in heap_locs.clone() {
+            match self.machine_st.store(self.machine_st.deref(addr.clone())) {
+                new_addr =>
+                    if addr.is_ref() && new_addr == addr {
+                        heap_locs.remove(&var);
+                    }
+            }
+        }
+    }
+    
     pub fn add_batched_code(&mut self, code: Code, code_dir: CodeDir)
     {
         // error detection has finished, so update the master index of keys.
index 59c82ac2eafba4a7878e7d4fa9b57b1b65ef99b1..78c59ba816a00b5527ab7cb5b5caa8c5fa6ebdb7 100644 (file)
@@ -373,6 +373,8 @@ pub fn print(wam: &mut Machine, result: EvalSession) {
     match result {
         EvalSession::InitialQuerySuccess(alloc_locs, mut heap_locs) => {            
             loop {
+                wam.remove_unbound_vars(&mut heap_locs);
+                
                 if wam.or_stack_is_empty() {
                     if heap_locs.is_empty() {
                         println!("true.");