Fix Reference arity
It was still hard-coded to `0` when I switched it to a struct, but it
needs to be the words size of the non-header terms.
@@ -8,6 +8,7 @@ use crate::borrow::CloneToProcess;
use crate::erts::{scheduler, HeapAlloc, Node};
use super::{AsTerm, Term};
+use crate::to_word_size;
pub type Number = u64;
@@ -23,7 +24,7 @@ impl Reference {
/// Create a new `Reference` struct
pub fn new(scheduler_id: scheduler::ID, number: Number) -> Self {
Self {
- header: Term::make_header(0, Term::FLAG_REFERENCE),
+ header: Term::make_header(arity(), Term::FLAG_REFERENCE),
scheduler_id,
number,
}
@@ -49,6 +50,14 @@ impl Reference {
pub fn number(&self) -> Number {
self.number
}
+
+ /// The size of the non-header fields in bytes
+ const ARITY_IN_BYTES: usize = mem::size_of::<Self>() - mem::size_of::<Term>();
+
+ /// The size of the non-header fields in words
+ fn arity() -> usize {
+ to_word_size(Self::ARITY_IN_BYTES)
+ }
}
unsafe impl AsTerm for Reference {
@@ -64,6 +73,7 @@ impl CloneToProcess for Reference {
let ptr = heap.alloc(word_size)?.as_ptr() as *mut Self;
let byte_size = mem::size_of_val(self);
ptr::copy_nonoverlapping(self as *const Self, ptr, byte_size);
+ dbg!(ptr);
Ok(Term::make_boxed(ptr))
}
