fix bugs revealed by src/tests/builtins.pl
This commit is contained in:
@@ -67,6 +67,10 @@ impl TryFrom<HeapCellValue> for Literal {
|
||||
(ArenaHeaderTag::Rational, n) => {
|
||||
Ok(Literal::Rational(n))
|
||||
}
|
||||
(ArenaHeaderTag::F64, f) => {
|
||||
// remove this redundancy.
|
||||
Ok(Literal::Float(F64Ptr(f)))
|
||||
}
|
||||
_ => {
|
||||
Err(())
|
||||
}
|
||||
|
||||
@@ -446,6 +446,8 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
let mut iter = stackful_post_order_iter(&mut machine_st.heap, term_addr);
|
||||
|
||||
while let Some(addr) = iter.next() {
|
||||
let addr = unmark_cell_bits!(addr);
|
||||
|
||||
read_heap_cell!(addr,
|
||||
(HeapCellValueTag::Lis) => {
|
||||
let tail = term_stack.pop().unwrap();
|
||||
@@ -459,7 +461,6 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
}
|
||||
(HeapCellValueTag::Cons | HeapCellValueTag::CStr | HeapCellValueTag::Fixnum |
|
||||
HeapCellValueTag::Char | HeapCellValueTag::F64) => {
|
||||
let addr = unmark_cell_bits!(addr);
|
||||
term_stack.push(Term::Literal(Cell::default(), Literal::try_from(addr).unwrap()));
|
||||
}
|
||||
(HeapCellValueTag::Atom, (name, arity)) => {
|
||||
@@ -490,7 +491,7 @@ impl<'a, LS: LoadState<'a>> Loader<'a, LS> {
|
||||
));
|
||||
}
|
||||
}
|
||||
(HeapCellValueTag::PStrOffset, h) => {
|
||||
(HeapCellValueTag::PStrLoc, h) => {
|
||||
let string = cell_as_atom_cell!(iter.heap[h]).get_name();
|
||||
let tail = term_stack.pop().unwrap();
|
||||
|
||||
|
||||
@@ -966,9 +966,8 @@ impl MachineState {
|
||||
loop {
|
||||
match self.read(stream, &indices.op_dir) {
|
||||
Ok(term_write_result) => {
|
||||
let term = self.registers[2];
|
||||
let term = self.store(self.deref(self.registers[2]));
|
||||
unify_fn!(self, heap_loc_as_cell!(term_write_result.heap_loc), term);
|
||||
let term = self.store(self.deref(term));
|
||||
|
||||
if self.fail {
|
||||
return Ok(());
|
||||
|
||||
@@ -2847,15 +2847,15 @@ impl MachineState {
|
||||
}
|
||||
&QueryInstruction::SetLocalValue(reg) => {
|
||||
let addr = self.deref(self[reg]);
|
||||
let h = self.heap.len();
|
||||
let stored_v = self.store(addr);
|
||||
|
||||
if addr < Ref::heap_cell(h) {
|
||||
self.heap.push(addr);
|
||||
return;
|
||||
if stored_v.is_stack_var() {
|
||||
let h = self.heap.len();
|
||||
self.heap.push(heap_loc_as_cell!(h));
|
||||
(self.bind_fn)(self, Ref::heap_cell(h), stored_v);
|
||||
} else {
|
||||
self.heap.push(stored_v);
|
||||
}
|
||||
|
||||
self.heap.push(heap_loc_as_cell!(h));
|
||||
(self.bind_fn)(self, Ref::heap_cell(h), addr);
|
||||
}
|
||||
&QueryInstruction::SetVariable(reg) => {
|
||||
let h = self.heap.len();
|
||||
@@ -2956,6 +2956,7 @@ impl MachineState {
|
||||
return false;
|
||||
}
|
||||
|
||||
let addr = self.store(self.deref(addr));
|
||||
let mut iter = stackful_preorder_iter(&mut self.heap, addr);
|
||||
|
||||
while let Some(value) = iter.next() {
|
||||
@@ -3624,9 +3625,15 @@ impl MachineState {
|
||||
return false;
|
||||
}
|
||||
|
||||
let value = self.registers[1];
|
||||
let value = self.store(self.deref(self.registers[1]));
|
||||
|
||||
if value.is_stack_var() {
|
||||
return true;
|
||||
}
|
||||
|
||||
for v in stackful_preorder_iter(&mut self.heap, value) {
|
||||
let v = unmark_cell_bits!(v);
|
||||
|
||||
if v.is_var() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -846,6 +846,6 @@ mod tests {
|
||||
wam.heap.push(pstr_as_cell!(atom!("a string")));
|
||||
wam.heap.push(empty_list_as_cell!());
|
||||
|
||||
assert!(!wam.is_cyclic_term(heap_loc_as_cell!(0)));
|
||||
assert!(!wam.is_cyclic_term(pstr_loc_as_cell!(0)));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user