]> Repositorios git - scryer-prolog.git/commitdiff
correctly handle anonymous variables when reading
authorMark Thom <[email protected]>
Tue, 16 Oct 2018 04:11:55 +0000 (22:11 -0600)
committerMark Thom <[email protected]>
Tue, 16 Oct 2018 04:11:55 +0000 (22:11 -0600)
src/prolog/read.rs

index 8ea8c4141753fb4aab0ec064c6965409232d57bd..2a40aa94c4e930101c051dc27797cf0a62365526 100644 (file)
@@ -118,12 +118,21 @@ pub(crate) fn write_term_to_heap(term: &Term, machine_st: &mut MachineState) ->
                 }
             },
             &TermRef::AnonVar(Level::Root)
-                | &TermRef::Var(Level::Root, ..)
-                | &TermRef::Constant(Level::Root, ..) =>
+          | &TermRef::Var(Level::Root, ..)
+          | &TermRef::Constant(Level::Root, ..) =>
                 machine_st.heap.push(HeapCellValue::Addr(term.as_addr(h))),
-            &TermRef::AnonVar(_) =>
-                continue,
+            &TermRef::AnonVar(_) => {
+                if let Some((arity, site_h)) = queue.pop_front() {
+                    if arity > 1 {
+                        queue.push_front((arity - 1, site_h + 1));
+                    }
+                }
+
+                continue;
+            },
             &TermRef::Var(_, _, ref var) => {
+                let v = var.as_str();
+                
                 if let Some((arity, site_h)) = queue.pop_front() {
                     if let Some(addr) = var_dict.get(var).cloned() {
                         machine_st.heap[site_h] = HeapCellValue::Addr(addr);