fix term expansion bug
This commit is contained in:
@@ -53,7 +53,7 @@ impl MachineState {
|
||||
let mut parser = Parser::new(inner, atom_tbl, self.flags);
|
||||
let term = parser.read_term(composite_op!(op_dir))?;
|
||||
|
||||
Ok(write_term_to_heap(&term, self).0)
|
||||
Ok(write_term_to_heap(&term, self).heap_loc)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,9 +73,17 @@ fn modify_head_of_queue(machine_st: &mut MachineState, queue: &mut SubtermDeque,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn write_term_to_heap(term: &Term, machine_st: &mut MachineState) -> (usize, HeapVarDict) {
|
||||
let h = machine_st.heap.h;
|
||||
pub(crate) struct TermWriteResult {
|
||||
pub(crate) heap_loc: usize,
|
||||
pub(crate) max_var_length: usize, // maximum length of the variable names encountered.
|
||||
pub(crate) var_dict: HeapVarDict,
|
||||
}
|
||||
|
||||
pub(crate) fn write_term_to_heap(term: &Term, machine_st: &mut MachineState) -> TermWriteResult
|
||||
{
|
||||
let heap_loc = machine_st.heap.h;
|
||||
|
||||
let mut max_var_length = 0;
|
||||
let mut queue = SubtermDeque::new();
|
||||
let mut var_dict = HeapVarDict::new();
|
||||
|
||||
@@ -108,10 +116,12 @@ pub(crate) fn write_term_to_heap(term: &Term, machine_st: &mut MachineState) ->
|
||||
continue;
|
||||
}
|
||||
},
|
||||
&TermRef::AnonVar(Level::Root)
|
||||
| &TermRef::Var(Level::Root, ..)
|
||||
| &TermRef::Constant(Level::Root, ..) =>
|
||||
&TermRef::AnonVar(Level::Root) | &TermRef::Constant(Level::Root, ..) =>
|
||||
machine_st.heap.push(HeapCellValue::Addr(term.as_addr(h))),
|
||||
&TermRef::Var(Level::Root, _, ref name) => {
|
||||
max_var_length = std::cmp::max(max_var_length, name.len());
|
||||
machine_st.heap.push(HeapCellValue::Addr(term.as_addr(h)));
|
||||
},
|
||||
&TermRef::AnonVar(_) => {
|
||||
if let Some((arity, site_h)) = queue.pop_front() {
|
||||
if arity > 1 {
|
||||
@@ -134,6 +144,7 @@ pub(crate) fn write_term_to_heap(term: &Term, machine_st: &mut MachineState) ->
|
||||
}
|
||||
}
|
||||
|
||||
max_var_length = std::cmp::max(max_var_length, var.len());
|
||||
continue;
|
||||
},
|
||||
_ => {}
|
||||
@@ -142,5 +153,5 @@ pub(crate) fn write_term_to_heap(term: &Term, machine_st: &mut MachineState) ->
|
||||
modify_head_of_queue(machine_st, &mut queue, term, h);
|
||||
}
|
||||
|
||||
(h, var_dict)
|
||||
TermWriteResult { heap_loc, var_dict, max_var_length }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user