run cargo fmt

This commit is contained in:
Skgland
2023-08-26 01:29:53 +02:00
committed by Bennet Bleßmann
parent 5585e83fd6
commit b2130c2a48
50 changed files with 10821 additions and 9258 deletions

View File

@@ -24,7 +24,7 @@ pub enum HeapCellValueTag {
PStrOffset = 0b001111,
// constants.
Cons = 0b0,
F64 = 0b010001,
F64 = 0b010001,
Fixnum = 0b010011,
Char = 0b010101,
Atom = 0b010111,
@@ -45,7 +45,7 @@ pub enum HeapCellValueView {
PStrOffset = 0b001111,
// constants.
Cons = 0b0,
F64 = 0b010001,
F64 = 0b010001,
Fixnum = 0b010011,
Char = 0b010101,
Atom = 0b010111,
@@ -56,9 +56,9 @@ pub enum HeapCellValueView {
TrailedHeapVar = 0b101111,
TrailedStackVar = 0b101011,
TrailedAttrVar = 0b100001,
TrailedAttrVarListLink = 0b100011,
TrailedAttachedValue = 0b100101,
TrailedBlackboardEntry = 0b100111,
TrailedAttrVarListLink = 0b100011,
TrailedAttachedValue = 0b100101,
TrailedBlackboardEntry = 0b100111,
TrailedBlackboardOffset = 0b110011,
}
@@ -88,7 +88,7 @@ impl ConsPtr {
.with_tag(tag)
}
#[cfg(target_pointer_width="32")]
#[cfg(target_pointer_width = "32")]
#[inline(always)]
pub fn as_ptr(self) -> *mut u8 {
let bytes = self.into_bytes();
@@ -96,7 +96,7 @@ impl ConsPtr {
unsafe { mem::transmute(raw_ptr_bytes) }
}
#[cfg(target_pointer_width="64")]
#[cfg(target_pointer_width = "64")]
#[inline(always)]
pub fn as_ptr(self) -> *mut u8 {
self.ptr() as *mut _
@@ -121,28 +121,24 @@ pub(crate) enum RefTag {
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub struct Ref {
val: B56,
#[allow(unused)] m: bool,
#[allow(unused)] f: bool,
#[allow(unused)]
m: bool,
#[allow(unused)]
f: bool,
tag: RefTag,
}
impl Ord for Ref {
fn cmp(&self, rhs: &Ref) -> Ordering {
match self.get_tag() {
RefTag::HeapCell | RefTag::AttrVar => {
match rhs.get_tag() {
RefTag::StackCell => Ordering::Less,
_ => self.get_value().cmp(&rhs.get_value()),
}
}
RefTag::StackCell => {
match rhs.get_tag() {
RefTag::StackCell =>
self.get_value().cmp(&rhs.get_value()),
_ =>
Ordering::Greater,
}
}
RefTag::HeapCell | RefTag::AttrVar => match rhs.get_tag() {
RefTag::StackCell => Ordering::Less,
_ => self.get_value().cmp(&rhs.get_value()),
},
RefTag::StackCell => match rhs.get_tag() {
RefTag::StackCell => self.get_value().cmp(&rhs.get_value()),
_ => Ordering::Greater,
},
}
}
}
@@ -204,9 +200,9 @@ pub(crate) enum TrailEntryTag {
TrailedHeapVar = 0b101111,
TrailedStackVar = 0b101011,
TrailedAttrVar = 0b100001,
TrailedAttrVarListLink = 0b100011,
TrailedAttachedValue = 0b100101,
TrailedBlackboardEntry = 0b100111,
TrailedAttrVarListLink = 0b100011,
TrailedAttachedValue = 0b100101,
TrailedBlackboardEntry = 0b100111,
TrailedBlackboardOffset = 0b110011,
}
@@ -215,9 +211,12 @@ pub(crate) enum TrailEntryTag {
#[repr(u64)]
pub(crate) struct TrailEntry {
val: B56,
#[allow(unused)] f: bool,
#[allow(unused)] m: bool,
#[allow(unused)] tag: TrailEntryTag,
#[allow(unused)]
f: bool,
#[allow(unused)]
m: bool,
#[allow(unused)]
tag: TrailEntryTag,
}
impl TrailEntry {
@@ -233,9 +232,9 @@ impl TrailEntry {
#[inline(always)]
pub(crate) fn get_tag(self) -> TrailEntryTag {
match self.tag_or_err() {
Ok(tag) => tag,
Err(_) => TrailEntryTag::TrailedAttachedValue,
}
Ok(tag) => tag,
Err(_) => TrailEntryTag::TrailedAttachedValue,
}
}
#[inline]
@@ -257,14 +256,13 @@ pub struct HeapCellValue {
impl fmt::Debug for HeapCellValue {
fn fmt(&self, f: &mut std::fmt::Formatter) -> fmt::Result {
match self.get_tag() {
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::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());
@@ -276,8 +274,7 @@ impl fmt::Debug for HeapCellValue {
.finish()
}
HeapCellValueTag::Atom => {
let (name, arity) = cell_as_atom_cell!(self)
.get_name_and_arity();
let (name, arity) = cell_as_atom_cell!(self).get_name_and_arity();
f.debug_struct("HeapCellValue")
.field("tag", &HeapCellValueTag::Atom)
@@ -288,8 +285,7 @@ impl fmt::Debug for HeapCellValue {
.finish()
}
HeapCellValueTag::PStr => {
let (name, _) = cell_as_atom_cell!(self)
.get_name_and_arity();
let (name, _) = cell_as_atom_cell!(self).get_name_and_arity();
f.debug_struct("HeapCellValue")
.field("tag", &HeapCellValueTag::PStr)
@@ -298,14 +294,13 @@ impl fmt::Debug for HeapCellValue {
.field("f", &self.f())
.finish()
}
tag => {
f.debug_struct("HeapCellValue")
.field("tag", &tag)
.field("value", &self.get_value())
.field("m", &self.get_mark_bit())
.field("f", &self.get_forwarding_bit())
.finish()
}
tag => f
.debug_struct("HeapCellValue")
.field("tag", &tag)
.field("value", &self.get_value())
.field("m", &self.get_mark_bit())
.field("f", &self.get_forwarding_bit())
.finish(),
}
}
}
@@ -320,10 +315,7 @@ impl<T: ArenaAllocated> From<TypedArenaPtr<T>> for HeapCellValue {
impl From<F64Ptr> for HeapCellValue {
#[inline]
fn from(f64_ptr: F64Ptr) -> HeapCellValue {
HeapCellValue::build_with(
HeapCellValueTag::F64,
f64_ptr.as_offset().to_u64(),
)
HeapCellValue::build_with(HeapCellValueTag::F64, f64_ptr.as_offset().to_u64())
}
}
@@ -402,9 +394,13 @@ impl HeapCellValue {
#[inline]
pub fn is_ref(self) -> bool {
match self.get_tag() {
HeapCellValueTag::Str | HeapCellValueTag::Lis | HeapCellValueTag::Var |
HeapCellValueTag::StackVar | HeapCellValueTag::AttrVar | HeapCellValueTag::PStrLoc |
HeapCellValueTag::PStrOffset => true,
HeapCellValueTag::Str
| HeapCellValueTag::Lis
| HeapCellValueTag::Var
| HeapCellValueTag::StackVar
| HeapCellValueTag::AttrVar
| HeapCellValueTag::PStrLoc
| HeapCellValueTag::PStrOffset => true,
_ => false,
}
}
@@ -431,16 +427,13 @@ impl HeapCellValue {
#[inline]
pub fn is_constant(self) -> bool {
match self.get_tag() {
HeapCellValueTag::Cons | HeapCellValueTag::F64 | HeapCellValueTag::Fixnum |
HeapCellValueTag::Char | HeapCellValueTag::CStr => {
true
}
HeapCellValueTag::Atom => {
cell_as_atom_cell!(self).get_arity() == 0
}
_ => {
false
}
HeapCellValueTag::Cons
| HeapCellValueTag::F64
| HeapCellValueTag::Fixnum
| HeapCellValueTag::Char
| HeapCellValueTag::CStr => true,
HeapCellValueTag::Atom => cell_as_atom_cell!(self).get_arity() == 0,
_ => false,
}
}
@@ -455,17 +448,13 @@ impl HeapCellValue {
HeapCellValueTag::Str => {
cell_as_atom_cell!(heap[self.get_value() as usize]).get_arity() > 0
}
HeapCellValueTag::Lis |
HeapCellValueTag::CStr |
HeapCellValueTag::PStr |
HeapCellValueTag::PStrLoc |
HeapCellValueTag::PStrOffset => {
true
}
HeapCellValueTag::Atom => {
cell_as_atom_cell!(self).get_arity() > 0
}
_ => { false }
HeapCellValueTag::Lis
| HeapCellValueTag::CStr
| HeapCellValueTag::PStr
| HeapCellValueTag::PStrLoc
| HeapCellValueTag::PStrOffset => true,
HeapCellValueTag::Atom => cell_as_atom_cell!(self).get_arity() > 0,
_ => false,
}
}
@@ -530,9 +519,7 @@ impl HeapCellValue {
#[inline]
pub fn to_pstr(self) -> Option<PartialString> {
match self.tag() {
HeapCellValueTag::PStr => {
Some(PartialString::from(Atom::from(self.val() << 3)))
}
HeapCellValueTag::PStr => Some(PartialString::from(Atom::from(self.val() << 3))),
_ => None,
}
}
@@ -545,26 +532,35 @@ impl HeapCellValue {
}
}
#[cfg(target_pointer_width="32")]
#[cfg(target_pointer_width = "32")]
#[inline]
pub fn from_raw_ptr_bytes(ptr_bytes: [u8; 4]) -> Self {
HeapCellValue::from_bytes([ptr_bytes[0], ptr_bytes[1], ptr_bytes[2], ptr_bytes[3], 0, 0, 0, 0])
HeapCellValue::from_bytes([
ptr_bytes[0],
ptr_bytes[1],
ptr_bytes[2],
ptr_bytes[3],
0,
0,
0,
0,
])
}
#[cfg(target_pointer_width="64")]
#[cfg(target_pointer_width = "64")]
#[inline]
pub fn from_raw_ptr_bytes(ptr_bytes: [u8; 8]) -> Self {
HeapCellValue::from_bytes(ptr_bytes)
}
#[inline]
#[cfg(target_pointer_width="32")]
#[cfg(target_pointer_width = "32")]
pub fn to_raw_ptr_bytes(self) -> [u8; 4] {
let bytes = self.into_bytes();
[bytes[0], bytes[1], bytes[2], bytes[3]]
}
#[inline]
#[cfg(target_pointer_width="64")]
#[cfg(target_pointer_width = "64")]
pub fn to_raw_ptr_bytes(self) -> [u8; 8] {
self.into_bytes()
}
@@ -577,7 +573,9 @@ impl HeapCellValue {
#[inline]
pub fn to_untyped_arena_ptr(self) -> Option<UntypedArenaPtr> {
match self.get_tag() {
HeapCellValueTag::Cons => Some(UntypedArenaPtr::from_bytes(self.to_untyped_arena_ptr_bytes())),
HeapCellValueTag::Cons => Some(UntypedArenaPtr::from_bytes(
self.to_untyped_arena_ptr_bytes(),
)),
_ => None,
}
}
@@ -586,7 +584,7 @@ impl HeapCellValue {
pub fn get_forwarding_bit(self) -> bool {
match self.get_tag() {
HeapCellValueTag::Cons => ConsPtr::from_bytes(self.into_bytes()).f(),
_ => self.f()
_ => self.f(),
}
}
@@ -604,9 +602,7 @@ impl HeapCellValue {
#[inline(always)]
pub fn get_mark_bit(self) -> bool {
match self.get_tag() {
HeapCellValueTag::Cons => {
ConsPtr::from_bytes(self.into_bytes()).m()
}
HeapCellValueTag::Cons => ConsPtr::from_bytes(self.into_bytes()).m(),
_ => self.m(),
}
}
@@ -633,15 +629,12 @@ impl HeapCellValue {
Some(TermOrderCategory::Variable)
}
HeapCellValueTag::Char => Some(TermOrderCategory::Atom),
HeapCellValueTag::Atom => {
Some(if cell_as_atom_cell!(self).get_arity() > 0 {
TermOrderCategory::Compound
} else {
TermOrderCategory::Atom
})
}
HeapCellValueTag::Lis | HeapCellValueTag::PStrLoc |
HeapCellValueTag::CStr => {
HeapCellValueTag::Atom => Some(if cell_as_atom_cell!(self).get_arity() > 0 {
TermOrderCategory::Compound
} else {
TermOrderCategory::Atom
}),
HeapCellValueTag::Lis | HeapCellValueTag::PStrLoc | HeapCellValueTag::CStr => {
Some(TermOrderCategory::Compound)
}
HeapCellValueTag::Str => {
@@ -654,9 +647,7 @@ impl HeapCellValue {
Some(TermOrderCategory::Compound)
}
}
_ => {
None
}
_ => None,
},
}
}
@@ -680,16 +671,17 @@ const_assert!(mem::size_of::<HeapCellValue>() == 8);
#[repr(u64)]
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
pub struct UntypedArenaPtr {
#[allow(unused)] ptr: B61,
#[allow(unused)]
ptr: B61,
m: bool,
#[allow(unused)] padding: B2,
#[allow(unused)]
padding: B2,
}
impl UntypedArenaPtr {
#[inline(always)]
pub fn build_with(ptr: usize) -> Self {
UntypedArenaPtr::new()
.with_ptr(ptr as u64)
UntypedArenaPtr::new().with_ptr(ptr as u64)
}
}
@@ -722,7 +714,7 @@ impl UntypedArenaPtr {
self.set_m(m);
}
#[cfg(target_pointer_width="32")]
#[cfg(target_pointer_width = "32")]
#[inline]
pub fn get_ptr(self) -> *const u8 {
let bytes = self.into_bytes();
@@ -730,10 +722,10 @@ impl UntypedArenaPtr {
unsafe { mem::transmute(raw_ptr_bytes) }
}
#[cfg(target_pointer_width="64")]
#[cfg(target_pointer_width = "64")]
#[inline]
pub fn get_ptr(self) -> *const u8 {
self.ptr() as *const u8
self.ptr() as *const u8
}
#[inline]
@@ -763,17 +755,15 @@ impl Add<usize> for HeapCellValue {
fn add(self, rhs: usize) -> Self::Output {
match self.get_tag() {
tag @ HeapCellValueTag::Str |
tag @ HeapCellValueTag::Lis |
tag @ HeapCellValueTag::PStrOffset |
tag @ HeapCellValueTag::PStrLoc |
tag @ HeapCellValueTag::Var |
tag @ HeapCellValueTag::AttrVar => {
tag @ HeapCellValueTag::Str
| tag @ HeapCellValueTag::Lis
| tag @ HeapCellValueTag::PStrOffset
| tag @ HeapCellValueTag::PStrLoc
| tag @ HeapCellValueTag::Var
| tag @ HeapCellValueTag::AttrVar => {
HeapCellValue::build_with(tag, (self.get_value() as usize + rhs) as u64)
}
_ => {
self
}
_ => self,
}
}
}
@@ -783,17 +773,15 @@ impl Sub<usize> for HeapCellValue {
fn sub(self, rhs: usize) -> Self::Output {
match self.get_tag() {
tag @ HeapCellValueTag::Str |
tag @ HeapCellValueTag::Lis |
tag @ HeapCellValueTag::PStrOffset |
tag @ HeapCellValueTag::PStrLoc |
tag @ HeapCellValueTag::Var |
tag @ HeapCellValueTag::AttrVar => {
tag @ HeapCellValueTag::Str
| tag @ HeapCellValueTag::Lis
| tag @ HeapCellValueTag::PStrOffset
| tag @ HeapCellValueTag::PStrLoc
| tag @ HeapCellValueTag::Var
| tag @ HeapCellValueTag::AttrVar => {
HeapCellValue::build_with(tag, (self.get_value() as usize - rhs) as u64)
}
_ => {
self
}
_ => self,
}
}
}
@@ -811,21 +799,18 @@ impl Sub<i64> for HeapCellValue {
fn sub(self, rhs: i64) -> Self::Output {
if rhs < 0 {
match self.get_tag() {
tag @ HeapCellValueTag::Str |
tag @ HeapCellValueTag::Lis |
tag @ HeapCellValueTag::PStrOffset |
tag @ HeapCellValueTag::PStrLoc |
tag @ HeapCellValueTag::Var |
tag @ HeapCellValueTag::AttrVar => {
tag @ HeapCellValueTag::Str
| tag @ HeapCellValueTag::Lis
| tag @ HeapCellValueTag::PStrOffset
| tag @ HeapCellValueTag::PStrLoc
| tag @ HeapCellValueTag::Var
| tag @ HeapCellValueTag::AttrVar => {
HeapCellValue::build_with(tag, self.get_value() + rhs.abs() as u64)
}
_ => {
self
}
_ => self,
}
} else {
self.sub(rhs as usize)
}
}
}