]> Repositorios git - scryer-prolog.git/commitdiff
Make Atom 64-bit regardless of architecture
authorRujia Liu <{ID}+{username}@user.noreply.github.com>
Sun, 20 Aug 2023 11:43:13 +0000 (19:43 +0800)
committerRujia Liu <{ID}+{username}@user.noreply.github.com>
Sun, 20 Aug 2023 11:43:13 +0000 (19:43 +0800)
build/static_string_indexing.rs
src/atom_table.rs
src/machine/disjuncts.rs

index ca5ac7658d9a1699d5a62272a037ee86f83ee243..15f0441f3a4e1c0355ff7ed6b458e0a74eeddb94 100644 (file)
@@ -150,7 +150,7 @@ pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStrea
         Err(_) => {}
     }
 
-    let indices = (0..visitor.static_strs.len()).map(|i| i << 3);
+    let indices = (0..visitor.static_strs.len()).map(|i| (i << 3) as u64);
     let indices_iter = indices.clone();
 
     let static_strs_len = visitor.static_strs.len();
index 48f50ec948a162b7fe2c4cfa70823c228490958b..f0661db26b0fed941e2258b43787165d2a592c59 100644 (file)
@@ -16,7 +16,7 @@ use modular_bitfield::prelude::*;
 
 #[derive(Copy, Clone, Debug, PartialEq, Eq)]
 pub struct Atom {
-    pub index: usize,
+    pub index: u64,
 }
 
 const_assert!(mem::size_of::<Atom>() == 8);
@@ -156,7 +156,7 @@ impl Atom {
 
     #[inline(always)]
     pub fn is_static(self) -> bool {
-        self.index < STRINGS.len() << 3
+        (self.index as usize) < STRINGS.len() << 3
     }
 
     #[inline(always)]
@@ -164,19 +164,19 @@ impl Atom {
         if self.is_static() {
             ptr::null()
         } else {
-            (get_atom_tbl_buf_base() as usize + self.index - (STRINGS.len() << 3)) as *const u8
+            (get_atom_tbl_buf_base() as usize + (self.index as usize) - (STRINGS.len() << 3)) as *const u8
         }
     }
 
     #[inline(always)]
     pub fn from(index: usize) -> Self {
-        Self { index }
+        Self { index: index as u64 }
     }
 
     #[inline(always)]
     pub fn len(self) -> usize {
         if self.is_static() {
-            STRINGS[self.index >> 3].len()
+            STRINGS[(self.index >> 3) as usize].len()
         } else {
             unsafe { ptr::read(self.as_ptr() as *const AtomHeader).len() as _ }
         }
@@ -208,7 +208,7 @@ impl Atom {
             let ptr = self.as_ptr();
 
             if ptr.is_null() {
-                return STRINGS[self.index >> 3];
+                return STRINGS[(self.index >> 3) as usize];
             }
 
             let header = ptr::read::<AtomHeader>(ptr as *const _);
@@ -339,7 +339,7 @@ impl AtomTable {
             write_to_ptr(string, len_ptr);
 
             let atom = Atom {
-                index: (STRINGS.len() << 3) + len_ptr as usize - ptr_base,
+                index: ((STRINGS.len() << 3) + len_ptr as usize - ptr_base) as u64,
             };
 
             self.table.insert(atom);
index a17240f1ce2ae23396f79ac372b9dac6d3ab514e..96da0a8d48a4eaf8b7eaa5330e44e854f5fb55c5 100644 (file)
@@ -27,7 +27,7 @@ pub struct BranchNumber {
 impl Default for BranchNumber {
     fn default() -> Self {
         Self {
-            branch_num: Rational::from(1usize << 63),
+            branch_num: Rational::from(1u64 << 63),
             delta: Rational::from(1),
         }
     }