]> Repositorios git - scryer-prolog.git/commitdiff
track f64 offsets in Literal (#1190)
authorMark Thom <[email protected]>
Thu, 5 May 2022 03:54:46 +0000 (21:54 -0600)
committerMark Thom <[email protected]>
Thu, 5 May 2022 03:54:46 +0000 (21:54 -0600)
13 files changed:
build/instructions_template.rs
src/arena.rs
src/arithmetic.rs
src/forms.rs
src/indexing.rs
src/machine/dispatch.rs
src/machine/heap.rs
src/machine/system_calls.rs
src/parser/ast.rs
src/parser/lexer.rs
src/parser/parser.rs
src/raw_block.rs
src/types.rs

index 988067f8d0a50875204e2819ca4527c14e66bc8e..75a7d60d7cbd3c3f2710ef893af2e8229851e5ec 100644 (file)
@@ -806,6 +806,7 @@ fn generate_instruction_preface() -> TokenStream {
         use crate::parser::ast::*;
         use crate::types::*;
 
+        use fxhash::FxBuildHasher;
         use indexmap::IndexMap;
 
         use std::collections::VecDeque;
@@ -918,8 +919,8 @@ fn generate_instruction_preface() -> TokenStream {
                 IndexingCodePtr,
                 IndexingCodePtr,
             ),
-            SwitchOnConstant(IndexMap<Literal, IndexingCodePtr>),
-            SwitchOnStructure(IndexMap<(Atom, usize), IndexingCodePtr>),
+            SwitchOnConstant(IndexMap<Literal, IndexingCodePtr, FxBuildHasher>),
+            SwitchOnStructure(IndexMap<(Atom, usize), IndexingCodePtr, FxBuildHasher>),
         }
 
         #[derive(Debug, Clone, Copy)]
index e4ec79ff85ea15ffe8697c8df88784709494d309..1c2999fc390b8b52abc1e2c8b545476cefaaef80 100644 (file)
@@ -104,7 +104,9 @@ pub fn lookup_float(offset: usize) -> *mut OrderedFloat<f64> {
 impl F64Table {
     #[inline]
     pub fn new() -> Self {
-        F64Table { block: RawBlock::new() }
+        let table = Self { block: RawBlock::new() };
+        set_f64_tbl_buf_base(table.block.base);
+        table
     }
 
     pub unsafe fn build_with(&mut self, value: f64) -> F64Ptr {
@@ -121,7 +123,7 @@ impl F64Table {
             }
         }
 
-        ptr::write(ptr as *mut f64, value);
+        ptr::write(ptr as *mut OrderedFloat<f64>, OrderedFloat(value));
         F64Ptr(ptr::NonNull::new_unchecked(ptr as *mut _))
     }
 }
@@ -297,9 +299,36 @@ pub trait ArenaAllocated {
         Self: Sized;
 }
 
-#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
+#[derive(Copy, Clone, Debug)]
 pub struct F64Ptr(pub ptr::NonNull<OrderedFloat<f64>>);
 
+impl PartialEq for F64Ptr {
+    fn eq(&self, other: &F64Ptr) -> bool {
+        self.0 == other.0 || &**self == &**other
+    }
+}
+
+impl Eq for F64Ptr {}
+
+impl PartialOrd for F64Ptr {
+    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
+        (**self).partial_cmp(&**other)
+    }
+}
+
+impl Ord for F64Ptr {
+    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
+        (**self).cmp(&**other)
+    }
+}
+
+impl Hash for F64Ptr {
+    #[inline(always)]
+    fn hash<H: Hasher>(&self, hasher: &mut H) {
+        (&*self as &OrderedFloat<f64>).hash(hasher)
+    }
+}
+
 impl fmt::Display for F64Ptr {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         write!(f, "{}", *self)
@@ -331,8 +360,69 @@ impl F64Ptr {
     }
 
     #[inline(always)]
-    pub fn as_offset(&self) -> usize {
-        self.0.as_ptr() as usize - get_f64_tbl_buf_base() as usize
+    pub fn as_offset(&self) -> F64Offset {
+        F64Offset(self.0.as_ptr() as usize - get_f64_tbl_buf_base() as usize)
+    }
+}
+
+#[derive(Clone, Copy, Debug)]
+pub struct F64Offset(usize);
+
+impl F64Offset {
+    #[inline(always)]
+    pub fn new(offset: usize) -> Self {
+        Self(offset)
+    }
+
+    #[inline(always)]
+    pub fn from_ptr(ptr: F64Ptr) -> Self {
+        ptr.as_offset()
+    }
+
+    #[inline(always)]
+    pub fn as_ptr(self) -> F64Ptr {
+        F64Ptr::from_offset(self.0)
+    }
+
+    #[inline(always)]
+    pub fn to_u64(self) -> u64 {
+        self.0 as u64
+    }
+}
+
+impl PartialEq for F64Offset {
+    #[inline(always)]
+    fn eq(&self, other: &F64Offset) -> bool {
+        self.as_ptr() == other.as_ptr()
+    }
+}
+
+impl Eq for F64Offset {}
+
+impl PartialOrd for F64Offset {
+    #[inline(always)]
+    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
+        self.as_ptr().partial_cmp(&other.as_ptr())
+    }
+}
+
+impl Ord for F64Offset {
+    #[inline(always)]
+    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
+        self.as_ptr().cmp(&other.as_ptr())
+    }
+}
+
+impl Hash for F64Offset {
+    #[inline(always)]
+    fn hash<H: Hasher>(&self, hasher: &mut H) {
+        self.as_ptr().hash(hasher)
+    }
+}
+
+impl fmt::Display for F64Offset {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        write!(f, "F64Offset({})", self.0)
     }
 }
 
index 77274fbdc63f8a0e9d8992938322b14f5fbc3393..1bac6bf81e7b76c733c14c08da54d04e0714643f 100644 (file)
@@ -167,7 +167,7 @@ fn push_literal(interm: &mut Vec<ArithmeticTerm>, c: &Literal) -> Result<(), Ari
     match c {
         Literal::Fixnum(n) => interm.push(ArithmeticTerm::Number(Number::Fixnum(*n))),
         Literal::Integer(n) => interm.push(ArithmeticTerm::Number(Number::Integer(*n))),
-        Literal::Float(n) => interm.push(ArithmeticTerm::Number(Number::Float(**n))),
+        Literal::Float(n) => interm.push(ArithmeticTerm::Number(Number::Float(*n.as_ptr()))),
         Literal::Rational(n) => interm.push(ArithmeticTerm::Number(Number::Rational(*n))),
         Literal::Atom(name) if name == &atom!("e") => interm.push(ArithmeticTerm::Number(
             Number::Float(OrderedFloat(std::f64::consts::E))
index b14271933463350e6b10452bed95b9c9727db014..ee632b6d07ac4e63b8dbea13b7a74a2931847e4f 100644 (file)
@@ -619,7 +619,7 @@ impl ArenaFrom<Number> for Literal {
         match value {
             Number::Fixnum(n) => Literal::Fixnum(n),
             Number::Integer(n) => Literal::Integer(n),
-            Number::Float(OrderedFloat(f)) => Literal::Float(float_alloc!(f, arena)),
+            Number::Float(OrderedFloat(f)) => Literal::from(float_alloc!(f, arena)),
             Number::Rational(r) => Literal::Rational(r),
         }
     }
index 9d7af8079e6c9f7314c0cec2a20eb958cf1aa3e8..ceace331203cd6b6e077e1cc4386c6290d35b695 100644 (file)
@@ -4,6 +4,7 @@ use crate::parser::ast::*;
 use crate::forms::*;
 use crate::instructions::*;
 
+use fxhash::FxBuildHasher;
 use indexmap::IndexMap;
 
 use std::collections::VecDeque;
@@ -107,7 +108,7 @@ impl<'a> IndexingCodeMergingPtr<'a> {
             self.append_or_prepend,
         );
 
-        let mut constants = IndexMap::new();
+        let mut constants = IndexMap::with_hasher(FxBuildHasher::default());
 
         match constant_key {
             Some(OptArgIndexKey::Literal(_, _, constant, _)) => {
@@ -249,7 +250,7 @@ impl<'a> IndexingCodeMergingPtr<'a> {
                             break;
                         }
                         IndexingCodePtr::DynamicExternal(_) | IndexingCodePtr::External(_) => {
-                            let mut constants = IndexMap::new();
+                            let mut constants = IndexMap::with_hasher(FxBuildHasher::default());
                             constants.insert(orig_constant, *c);
 
                             *c = IndexingCodePtr::Internal(indexing_code_len);
@@ -389,7 +390,7 @@ impl<'a> IndexingCodeMergingPtr<'a> {
             self.append_or_prepend,
         );
 
-        let mut structures = IndexMap::new();
+        let mut structures = IndexMap::with_hasher(FxBuildHasher::default());
 
         match structure_key {
             Some(OptArgIndexKey::Structure(_, _, name, arity)) => {
@@ -1121,15 +1122,6 @@ pub(crate) fn constant_key_alternatives(
                 }).unwrap();
             }
         }
-        /*
-        Literal::Usize(n) => {
-            constants.push(Literal::Integer(Rc::new(Integer::from(*n))));
-
-            if let Ok(n) = isize::try_from(*n) {
-                constants.push(Literal::Fixnum(n));
-            }
-        }
-        */
         _ => {}
     }
 
@@ -1138,16 +1130,16 @@ pub(crate) fn constant_key_alternatives(
 
 #[derive(Debug)]
 pub(crate) struct StaticCodeIndices {
-    constants: IndexMap<Literal, VecDeque<IndexedChoiceInstruction>>,
+    constants: IndexMap<Literal, VecDeque<IndexedChoiceInstruction>, FxBuildHasher>,
     lists: VecDeque<IndexedChoiceInstruction>,
-    structures: IndexMap<(Atom, usize), VecDeque<IndexedChoiceInstruction>>,
+    structures: IndexMap<(Atom, usize), VecDeque<IndexedChoiceInstruction>, FxBuildHasher>,
 }
 
 #[derive(Debug)]
 pub(crate) struct DynamicCodeIndices {
-    constants: IndexMap<Literal, VecDeque<usize>>,
+    constants: IndexMap<Literal, VecDeque<usize>, FxBuildHasher>,
     lists: VecDeque<usize>,
-    structures: IndexMap<(Atom, usize), VecDeque<usize>>,
+    structures: IndexMap<(Atom, usize), VecDeque<usize>, FxBuildHasher>,
 }
 
 pub(crate) trait Indexer {
@@ -1155,20 +1147,20 @@ pub(crate) trait Indexer {
 
     fn new() -> Self;
 
-    fn constants(&mut self) -> &mut IndexMap<Literal, VecDeque<Self::ThirdLevelIndex>>;
+    fn constants(&mut self) -> &mut IndexMap<Literal, VecDeque<Self::ThirdLevelIndex>, FxBuildHasher>;
     fn lists(&mut self) -> &mut VecDeque<Self::ThirdLevelIndex>;
-    fn structures(&mut self) -> &mut IndexMap<(Atom, usize), VecDeque<Self::ThirdLevelIndex>>;
+    fn structures(&mut self) -> &mut IndexMap<(Atom, usize), VecDeque<Self::ThirdLevelIndex>, FxBuildHasher>;
 
     fn compute_index(is_initial_index: bool, index: usize) -> Self::ThirdLevelIndex;
 
     fn second_level_index<IndexKey: Eq + Hash>(
-        indices: IndexMap<IndexKey, VecDeque<Self::ThirdLevelIndex>>,
+        indices: IndexMap<IndexKey, VecDeque<Self::ThirdLevelIndex>, FxBuildHasher>,
         prelude: &mut VecDeque<IndexingLine>,
-    ) -> IndexMap<IndexKey, IndexingCodePtr>;
+    ) -> IndexMap<IndexKey, IndexingCodePtr, FxBuildHasher>;
 
     fn switch_on<IndexKey: Eq + Hash>(
-        instr_fn: impl FnMut(IndexMap<IndexKey, IndexingCodePtr>) -> IndexingInstruction,
-        index: &mut IndexMap<IndexKey, VecDeque<Self::ThirdLevelIndex>>,
+        instr_fn: impl FnMut(IndexMap<IndexKey, IndexingCodePtr, FxBuildHasher>) -> IndexingInstruction,
+        index: &mut IndexMap<IndexKey, VecDeque<Self::ThirdLevelIndex>, FxBuildHasher>,
         prelude: &mut VecDeque<IndexingLine>,
     ) -> IndexingCodePtr;
 
@@ -1188,14 +1180,14 @@ impl Indexer for StaticCodeIndices {
     #[inline]
     fn new() -> Self {
         Self {
-            constants: IndexMap::new(),
+            constants: IndexMap::with_hasher(FxBuildHasher::default()),
             lists: VecDeque::new(),
-            structures: IndexMap::new(),
+            structures: IndexMap::with_hasher(FxBuildHasher::default()),
         }
     }
 
     #[inline]
-    fn constants(&mut self) -> &mut IndexMap<Literal, VecDeque<IndexedChoiceInstruction>> {
+    fn constants(&mut self) -> &mut IndexMap<Literal, VecDeque<IndexedChoiceInstruction>, FxBuildHasher> {
         &mut self.constants
     }
 
@@ -1205,7 +1197,7 @@ impl Indexer for StaticCodeIndices {
     }
 
     #[inline]
-    fn structures(&mut self) -> &mut IndexMap<(Atom, usize), VecDeque<IndexedChoiceInstruction>> {
+    fn structures(&mut self) -> &mut IndexMap<(Atom, usize), VecDeque<IndexedChoiceInstruction>, FxBuildHasher> {
         &mut self.structures
     }
 
@@ -1218,10 +1210,10 @@ impl Indexer for StaticCodeIndices {
     }
 
     fn second_level_index<IndexKey: Eq + Hash>(
-        indices: IndexMap<IndexKey, VecDeque<IndexedChoiceInstruction>>,
+        indices: IndexMap<IndexKey, VecDeque<IndexedChoiceInstruction>, FxBuildHasher>,
         prelude: &mut VecDeque<IndexingLine>,
-    ) -> IndexMap<IndexKey, IndexingCodePtr> {
-        let mut index_locs = IndexMap::new();
+    ) -> IndexMap<IndexKey, IndexingCodePtr, FxBuildHasher> {
+        let mut index_locs = IndexMap::with_hasher(FxBuildHasher::default());
 
         for (key, mut code) in indices.into_iter() {
             if code.len() > 1 {
@@ -1239,11 +1231,11 @@ impl Indexer for StaticCodeIndices {
     }
 
     fn switch_on<IndexKey: Eq + Hash>(
-        mut instr_fn: impl FnMut(IndexMap<IndexKey, IndexingCodePtr>) -> IndexingInstruction,
-        index: &mut IndexMap<IndexKey, VecDeque<IndexedChoiceInstruction>>,
+        mut instr_fn: impl FnMut(IndexMap<IndexKey, IndexingCodePtr, FxBuildHasher>) -> IndexingInstruction,
+        index: &mut IndexMap<IndexKey, VecDeque<IndexedChoiceInstruction>, FxBuildHasher>,
         prelude: &mut VecDeque<IndexingLine>,
     ) -> IndexingCodePtr {
-        let index = mem::replace(index, IndexMap::new());
+        let index = mem::replace(index, IndexMap::with_hasher(FxBuildHasher::default()));
         let index = Self::second_level_index(index, prelude);
 
         if index.len() > 1 {
@@ -1304,14 +1296,14 @@ impl Indexer for DynamicCodeIndices {
     #[inline]
     fn new() -> Self {
         Self {
-            constants: IndexMap::new(),
+            constants: IndexMap::with_hasher(FxBuildHasher::default()),
             lists: VecDeque::new(),
-            structures: IndexMap::new(),
+            structures: IndexMap::with_hasher(FxBuildHasher::default()),
         }
     }
 
     #[inline]
-    fn constants(&mut self) -> &mut IndexMap<Literal, VecDeque<usize>> {
+    fn constants(&mut self) -> &mut IndexMap<Literal, VecDeque<usize>, FxBuildHasher> {
         &mut self.constants
     }
 
@@ -1321,7 +1313,7 @@ impl Indexer for DynamicCodeIndices {
     }
 
     #[inline]
-    fn structures(&mut self) -> &mut IndexMap<(Atom, usize), VecDeque<usize>> {
+    fn structures(&mut self) -> &mut IndexMap<(Atom, usize), VecDeque<usize>, FxBuildHasher> {
         &mut self.structures
     }
 
@@ -1331,10 +1323,10 @@ impl Indexer for DynamicCodeIndices {
     }
 
     fn second_level_index<IndexKey: Eq + Hash>(
-        indices: IndexMap<IndexKey, VecDeque<usize>>,
+        indices: IndexMap<IndexKey, VecDeque<usize>, FxBuildHasher>,
         prelude: &mut VecDeque<IndexingLine>,
-    ) -> IndexMap<IndexKey, IndexingCodePtr> {
-        let mut index_locs = IndexMap::new();
+    ) -> IndexMap<IndexKey, IndexingCodePtr, FxBuildHasher> {
+        let mut index_locs = IndexMap::with_hasher(FxBuildHasher::default());
 
         for (key, code) in indices.into_iter() {
             if code.len() > 1 {
@@ -1351,11 +1343,11 @@ impl Indexer for DynamicCodeIndices {
     }
 
     fn switch_on<IndexKey: Eq + Hash>(
-        mut instr_fn: impl FnMut(IndexMap<IndexKey, IndexingCodePtr>) -> IndexingInstruction,
-        index: &mut IndexMap<IndexKey, VecDeque<usize>>,
+        mut instr_fn: impl FnMut(IndexMap<IndexKey, IndexingCodePtr, FxBuildHasher>) -> IndexingInstruction,
+        index: &mut IndexMap<IndexKey, VecDeque<usize>, FxBuildHasher>,
         prelude: &mut VecDeque<IndexingLine>,
     ) -> IndexingCodePtr {
-        let index = mem::replace(index, IndexMap::new());
+        let index = mem::replace(index, IndexMap::with_hasher(FxBuildHasher::default()));
         let index = Self::second_level_index(index, prelude);
 
         if index.len() > 1 {
index 514f80ac8fa0f18cfb8896410edc14f88f47ffe5..9d031c71db3d3f6364a44d4a180ec74fd842cc4c 100644 (file)
@@ -415,7 +415,7 @@ impl Machine {
                             Literal::Fixnum(n)
                         }
                         (HeapCellValueTag::F64, f) => {
-                            Literal::Float(f)
+                            Literal::Float(f.as_offset())
                         }
                         (HeapCellValueTag::Atom, (atom, arity)) => {
                             debug_assert_eq!(arity, 0);
index 5f9d4909f34f68b8ceebb21115ee42e591b15cd5..9ef796b509a496d00a57649b9eacb94e656da7a7 100644 (file)
@@ -24,7 +24,7 @@ impl From<Literal> for HeapCellValue {
             Literal::Rational(bigint_ptr) => {
                 typed_arena_ptr_as_cell!(bigint_ptr)
             }
-            Literal::Float(f) => HeapCellValue::from(f),
+            Literal::Float(f) => HeapCellValue::from(f.as_ptr()),
             Literal::String(s) => {
                 if s == atom!("") {
                     empty_list_as_cell!()
@@ -55,7 +55,7 @@ impl TryFrom<HeapCellValue> for Literal {
                 Ok(Literal::Fixnum(n))
             }
             (HeapCellValueTag::F64, f) => {
-                Ok(Literal::Float(f))
+                Ok(Literal::Float(f.as_offset()))
             }
             (HeapCellValueTag::Cons, cons_ptr) => {
                 match_untyped_arena_ptr!(cons_ptr,
index fcbeb5538b6f623ad81567eff717bec7645c316f..01c6fae233a3c559eecfe929cc153294fbcaa28e 100644 (file)
@@ -742,7 +742,7 @@ impl MachineState {
                 self.unify_rational(n, nx);
             }
             Ok(Term::Literal(_, Literal::Float(n))) => {
-                self.unify_f64(n, nx);
+                self.unify_f64(n.as_ptr(), nx);
             }
             Ok(Term::Literal(_, Literal::Integer(n))) => {
                 self.unify_big_int(n, nx);
index 3cc1ccbbe40d676afd73c15957f0586ab67426ff..ece4c90eca1aeb8760866988507682643221826a 100644 (file)
@@ -533,10 +533,17 @@ pub enum Literal {
     Fixnum(Fixnum),
     Integer(TypedArenaPtr<Integer>),
     Rational(TypedArenaPtr<Rational>),
-    Float(F64Ptr),
+    Float(F64Offset),
     String(Atom),
 }
 
+impl From<F64Ptr> for Literal {
+    #[inline(always)]
+    fn from(ptr: F64Ptr) -> Literal {
+        Literal::Float(ptr.as_offset())
+    }
+}
+
 impl fmt::Display for Literal {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         match self {
index 02bbd1d1cb86120b96bf734fc387dc42cd0793df..887a3562aea0f335b6fdf0626a76a4bf116b1a79 100644 (file)
@@ -633,7 +633,7 @@ impl<'a, R: CharRead> Lexer<'a, R> {
     fn vacate_with_float(&mut self, mut token: String) -> Result<Token, ParserError> {
         self.return_char(token.pop().unwrap());
         let n = parse_lossy::<f64, _>(token.as_bytes())?;
-        Ok(Token::Literal(Literal::Float(float_alloc!(n, self.machine_st.arena))))
+        Ok(Token::Literal(Literal::from(float_alloc!(n, self.machine_st.arena))))
     }
 
     fn skip_underscore_in_number(&mut self) -> Result<char, ParserError> {
@@ -744,7 +744,7 @@ impl<'a, R: CharRead> Lexer<'a, R> {
                         }
 
                         let n = parse_lossy::<f64, _>(token.as_bytes())?;
-                        Ok(Token::Literal(Literal::Float(
+                        Ok(Token::Literal(Literal::from(
                             float_alloc!(n, self.machine_st.arena)
                         )))
                     } else {
@@ -752,7 +752,7 @@ impl<'a, R: CharRead> Lexer<'a, R> {
                     }
                 } else {
                     let n = parse_lossy::<f64, _>(token.as_bytes())?;
-                    Ok(Token::Literal(Literal::Float(
+                    Ok(Token::Literal(Literal::from(
                         float_alloc!(n, self.machine_st.arena)
                     )))
                 }
index ecdc2ab00eceb88adddbdd502d32bb285c4f3bfc..ee08cec1a8ec8cc11257580f199bd82b4796d324 100644 (file)
@@ -949,9 +949,9 @@ impl<'a, R: CharRead> Parser<'a, R> {
                 self.negate_number(n, negate_rc, |r, _| Literal::Rational(r))
             }
             Token::Literal(Literal::Float(n)) => self.negate_number(
-                **n,
+                **n.as_ptr(),
                 |n| -n,
-                |n, arena| Literal::Float(float_alloc!(n, arena))
+                |n, arena| Literal::from(float_alloc!(n, arena)),
             ),
             Token::Literal(c) => {
                 if let Some(name) = atomize_constant(&mut self.lexer.machine_st.atom_tbl, c) {
index d39c65ca18234db8681bf383dff7ce0bd1e30ae3..a96ae1aff613fed432705c308a4dd17b6aaa15a9 100644 (file)
@@ -58,13 +58,6 @@ impl<T: RawBlockTraits> RawBlock<T> {
         }
     }
 
-    /*
-    #[inline]
-    pub fn take(&mut self) -> Self {
-        mem::replace(self, Self::empty_block())
-    }
-    */
-
     #[inline]
     pub fn size(&self) -> usize {
         self.top as usize - self.base as usize
index 578014b7f28ef79725429382c274311f4313d155..be940a54949e2d7a3c31dd9199ea12201b893c25 100644 (file)
@@ -248,13 +248,22 @@ pub struct HeapCellValue {
 impl fmt::Debug for HeapCellValue {
     fn fmt(&self, f: &mut std::fmt::Formatter) -> fmt::Result {
         match self.get_tag() {
-            tag @ (HeapCellValueTag::Cons | HeapCellValueTag::F64) => {
+            HeapCellValueTag::F64 => {
+                f.debug_struct("HeapCellValue")
+                    .field("tag", &HeapCellValueTag::F64)
+                    .field("offset", &self.get_value())
+                    .field("m", &self.m())
+                    .field("f", &self.f())
+                    .finish()
+            }
+            HeapCellValueTag::Cons => {
                 let cons_ptr = ConsPtr::from_bytes(self.into_bytes());
 
                 f.debug_struct("HeapCellValue")
-                    .field("tag", &tag)
+                    .field("tag", &HeapCellValueTag::Cons)
                     .field("ptr", &cons_ptr.ptr())
                     .field("m", &cons_ptr.m())
+                    .field("f", &cons_ptr.f())
                     .finish()
             }
             HeapCellValueTag::Atom => {
@@ -304,7 +313,7 @@ impl From<F64Ptr> for HeapCellValue {
     fn from(f64_ptr: F64Ptr) -> HeapCellValue {
         HeapCellValue::build_with(
             HeapCellValueTag::F64,
-            f64_ptr.as_offset() as u64,
+            f64_ptr.as_offset().to_u64(),
         )
     }
 }