]> Repositorios git - scryer-prolog.git/commitdiff
retrieve F64 behind Cons tags properly (#1369)
authorMark Thom <[email protected]>
Sun, 27 Mar 2022 03:18:07 +0000 (21:18 -0600)
committerMark Thom <[email protected]>
Sun, 27 Mar 2022 03:18:07 +0000 (21:18 -0600)
src/macros.rs
src/types.rs

index 0b83bbb7444a9a1d1606542aadf420fee84ef681..a51a30b29378b15dba6108584fa1ab765e065374 100644 (file)
@@ -87,10 +87,21 @@ macro_rules! cell_as_atom_cell {
 
 macro_rules! cell_as_f64_ptr {
     ($cell:expr) => {{
-        let ptr_u64 = ConsPtr::from_bytes($cell.into_bytes());
-        F64Ptr(TypedArenaPtr::new(
-            ptr_u64.as_ptr() as *mut OrderedFloat<f64>
-        ))
+        let cons_ptr = ConsPtr::from_bytes($cell.into_bytes());
+
+        match cons_ptr.get_tag() {
+            ConsPtrMaskTag::F64 => {
+                F64Ptr(TypedArenaPtr::new(
+                    cons_ptr.as_ptr() as *mut OrderedFloat<f64>
+                ))
+            }
+            ConsPtrMaskTag::Cons => {
+                let ptr = cell_as_untyped_arena_ptr!($cell).payload_offset();
+                unsafe {
+                    F64Ptr(TypedArenaPtr::new(std::mem::transmute(ptr)))
+                }
+            }
+        }
     }};
 }
 
index 0c2f289dbf990af1579359c95be1a8564c5eada6..3a18e845e3c8aae1d3d64234200cdd58a9040850 100644 (file)
@@ -87,10 +87,15 @@ impl ConsPtr {
             .with_tag(tag)
     }
 
-    #[inline]
+    #[inline(always)]
     pub fn as_ptr(self) -> *mut u8 {
         self.ptr() as *mut _
     }
+
+    #[inline(always)]
+    pub fn get_tag(self) -> ConsPtrMaskTag {
+        self.tag()
+    }
 }
 
 #[derive(BitfieldSpecifier, Copy, Clone, Debug)]