Make Atom 64-bit regardless of architecture

This commit is contained in:
Rujia Liu
2023-08-20 19:43:13 +08:00
parent 7da321ab4f
commit f6d3b2f896
3 changed files with 9 additions and 9 deletions

View File

@@ -150,7 +150,7 @@ pub fn index_static_strings(instruction_rs_path: &std::path::Path) -> TokenStrea
Err(_) => {} 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 indices_iter = indices.clone();
let static_strs_len = visitor.static_strs.len(); let static_strs_len = visitor.static_strs.len();

View File

@@ -16,7 +16,7 @@ use modular_bitfield::prelude::*;
#[derive(Copy, Clone, Debug, PartialEq, Eq)] #[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub struct Atom { pub struct Atom {
pub index: usize, pub index: u64,
} }
const_assert!(mem::size_of::<Atom>() == 8); const_assert!(mem::size_of::<Atom>() == 8);
@@ -156,7 +156,7 @@ impl Atom {
#[inline(always)] #[inline(always)]
pub fn is_static(self) -> bool { pub fn is_static(self) -> bool {
self.index < STRINGS.len() << 3 (self.index as usize) < STRINGS.len() << 3
} }
#[inline(always)] #[inline(always)]
@@ -164,19 +164,19 @@ impl Atom {
if self.is_static() { if self.is_static() {
ptr::null() ptr::null()
} else { } 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)] #[inline(always)]
pub fn from(index: usize) -> Self { pub fn from(index: usize) -> Self {
Self { index } Self { index: index as u64 }
} }
#[inline(always)] #[inline(always)]
pub fn len(self) -> usize { pub fn len(self) -> usize {
if self.is_static() { if self.is_static() {
STRINGS[self.index >> 3].len() STRINGS[(self.index >> 3) as usize].len()
} else { } else {
unsafe { ptr::read(self.as_ptr() as *const AtomHeader).len() as _ } unsafe { ptr::read(self.as_ptr() as *const AtomHeader).len() as _ }
} }
@@ -208,7 +208,7 @@ impl Atom {
let ptr = self.as_ptr(); let ptr = self.as_ptr();
if ptr.is_null() { if ptr.is_null() {
return STRINGS[self.index >> 3]; return STRINGS[(self.index >> 3) as usize];
} }
let header = ptr::read::<AtomHeader>(ptr as *const _); let header = ptr::read::<AtomHeader>(ptr as *const _);
@@ -339,7 +339,7 @@ impl AtomTable {
write_to_ptr(string, len_ptr); write_to_ptr(string, len_ptr);
let atom = Atom { 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); self.table.insert(atom);

View File

@@ -27,7 +27,7 @@ pub struct BranchNumber {
impl Default for BranchNumber { impl Default for BranchNumber {
fn default() -> Self { fn default() -> Self {
Self { Self {
branch_num: Rational::from(1usize << 63), branch_num: Rational::from(1u64 << 63),
delta: Rational::from(1), delta: Rational::from(1),
} }
} }