fix functor! size calculations around indexing_code_ptr
This commit is contained in:
@@ -61,10 +61,17 @@ macro_rules! build_functor {
|
|||||||
[$($res:expr),*],
|
[$($res:expr),*],
|
||||||
$res_len:expr,
|
$res_len:expr,
|
||||||
[$($subfunctor:expr),*]) => ({
|
[$($subfunctor:expr),*]) => ({
|
||||||
|
let (inner_functor, cell_size) = indexing_code_ptr($e);
|
||||||
|
let referent = if cell_size == 1 {
|
||||||
|
heap_loc_as_cell!(1u64 + count!($($dt)*) + $res_len)
|
||||||
|
} else {
|
||||||
|
str_loc_as_cell!(1u64 + count!($($dt)*) + $res_len)
|
||||||
|
};
|
||||||
|
|
||||||
build_functor!([$($dt($($value),*)),*],
|
build_functor!([$($dt($($value),*)),*],
|
||||||
[$($res, )* FunctorElement::Cell(str_loc_as_cell!(1u64 + count!($($dt)*) + $res_len))],
|
[$($res, )* FunctorElement::Cell(referent)],
|
||||||
3 + $res_len,
|
1 + cell_size + $res_len,
|
||||||
[$($subfunctor, )* FunctorElement::InnerFunctor(2, indexing_code_ptr($e))])
|
[$($subfunctor, )* FunctorElement::InnerFunctor(cell_size, inner_functor)])
|
||||||
});
|
});
|
||||||
([fixnum($e:expr) $(, $dt:ident($($value:tt),*))*],
|
([fixnum($e:expr) $(, $dt:ident($($value:tt),*))*],
|
||||||
[$($res:expr),*],
|
[$($res:expr),*],
|
||||||
@@ -171,20 +178,14 @@ macro_rules! build_functor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn indexing_code_ptr(code_ptr: IndexingCodePtr) -> Vec<FunctorElement> {
|
pub(crate) fn indexing_code_ptr(code_ptr: IndexingCodePtr) -> (Vec<FunctorElement>, u64) {
|
||||||
match code_ptr {
|
match code_ptr {
|
||||||
IndexingCodePtr::DynamicExternal(o) => {
|
IndexingCodePtr::DynamicExternal(o) => {
|
||||||
functor!(atom!("dynamic_external"), [fixnum(o)])
|
(functor!(atom!("dynamic_external"), [fixnum(o)]), 2)
|
||||||
}
|
|
||||||
IndexingCodePtr::External(o) => {
|
|
||||||
functor!(atom!("external"), [fixnum(o)])
|
|
||||||
}
|
|
||||||
IndexingCodePtr::Internal(o) => {
|
|
||||||
functor!(atom!("internal"), [fixnum(o)])
|
|
||||||
}
|
|
||||||
IndexingCodePtr::Fail => {
|
|
||||||
vec![FunctorElement::Cell(atom_as_cell!(atom!("fail")))]
|
|
||||||
}
|
}
|
||||||
|
IndexingCodePtr::External(o) => (functor!(atom!("external"), [fixnum(o)]), 2),
|
||||||
|
IndexingCodePtr::Internal(o) => (functor!(atom!("internal"), [fixnum(o)]), 2),
|
||||||
|
IndexingCodePtr::Fail => (vec![FunctorElement::Cell(atom_as_cell!(atom!("fail")))], 1),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -242,7 +242,6 @@ impl MachineState {
|
|||||||
c
|
c
|
||||||
}
|
}
|
||||||
(HeapCellValueTag::Atom, (_name, arity)) => {
|
(HeapCellValueTag::Atom, (_name, arity)) => {
|
||||||
// if arity == 0 { c } else { s }
|
|
||||||
debug_assert!(arity == 0);
|
debug_assert!(arity == 0);
|
||||||
c
|
c
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1092,7 +1092,7 @@ pub fn heap_bound_store(heap: &impl SizedHeap, value: HeapCellValue) -> HeapCell
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn print_heap_terms(heap: &Heap, h: usize) {
|
pub fn print_heap_terms(heap: &impl SizedHeap, h: usize) {
|
||||||
for idx in 0..heap.cell_len() {
|
for idx in 0..heap.cell_len() {
|
||||||
let term = heap[idx];
|
let term = heap[idx];
|
||||||
println!("{} : {:?}", h + idx, term);
|
println!("{} : {:?}", h + idx, term);
|
||||||
|
|||||||
@@ -7307,20 +7307,19 @@ impl Machine {
|
|||||||
walk_code(&self.code, index_ptr, |instr| {
|
walk_code(&self.code, index_ptr, |instr| {
|
||||||
let old_len = functors.len();
|
let old_len = functors.len();
|
||||||
instr.enqueue_functors(&mut self.machine_st.arena, &mut functors);
|
instr.enqueue_functors(&mut self.machine_st.arena, &mut functors);
|
||||||
let new_len = functors.len();
|
|
||||||
|
|
||||||
for index in old_len..new_len {
|
for functor in &functors[old_len..] {
|
||||||
let functor_len = functors[index].len();
|
let functor_len = functor.len();
|
||||||
|
|
||||||
match functor_len {
|
match functor_len {
|
||||||
0 => {}
|
0 => {}
|
||||||
1 => {
|
1 => {
|
||||||
functor_list.push(heap_loc_as_cell!(h));
|
functor_list.push(heap_loc_as_cell!(h));
|
||||||
h += cell_index!(Heap::compute_functor_byte_size(&functors[index]));
|
h += cell_index!(Heap::compute_functor_byte_size(functor));
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
functor_list.push(str_loc_as_cell!(h));
|
functor_list.push(str_loc_as_cell!(h));
|
||||||
h += cell_index!(Heap::compute_functor_byte_size(&functors[index]));
|
h += cell_index!(Heap::compute_functor_byte_size(functor));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user