Skip to content

Commit

Permalink
Fix fmt issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ironcev authored and xunilrj committed Nov 8, 2023
1 parent a4505fb commit 64945a3
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions sway-core/src/ir_generation/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,27 @@ pub fn serialize_to_storage_slots(

/// Given a constant value `constant` and a type `ty`, serialize the constant into a vector of
/// words and apply the requested padding if needed.
fn serialize_to_words(constant: &Constant, context: &Context, ty: &Type, padding: InByte8Padding) -> Vec<Bytes8> {
fn serialize_to_words(
constant: &Constant,
context: &Context,
ty: &Type,
padding: InByte8Padding,
) -> Vec<Bytes8> {
match &constant.value {
ConstantValue::Undef => vec![],
ConstantValue::Unit if ty.is_unit(context) => vec![Bytes8::new([0; 8])],
ConstantValue::Bool(b) if ty.is_bool(context) => {
match padding {
InByte8Padding::Right => vec![Bytes8::new([if *b { 1 } else { 0 }, 0, 0, 0, 0, 0, 0, 0])],
InByte8Padding::Left => vec![Bytes8::new([0, 0, 0, 0, 0, 0, 0, if *b { 1 } else { 0 }])],
ConstantValue::Bool(b) if ty.is_bool(context) => match padding {
InByte8Padding::Right => {
vec![Bytes8::new([if *b { 1 } else { 0 }, 0, 0, 0, 0, 0, 0, 0])]
}
}
ConstantValue::Uint(n) if ty.is_uint8(context) => {
match padding {
InByte8Padding::Right => vec![Bytes8::new([*n as u8, 0, 0, 0, 0, 0, 0, 0])],
InByte8Padding::Left => vec![Bytes8::new([0, 0, 0, 0, 0, 0, 0, *n as u8])],
InByte8Padding::Left => {
vec![Bytes8::new([0, 0, 0, 0, 0, 0, 0, if *b { 1 } else { 0 }])]
}
}
},
ConstantValue::Uint(n) if ty.is_uint8(context) => match padding {
InByte8Padding::Right => vec![Bytes8::new([*n as u8, 0, 0, 0, 0, 0, 0, 0])],
InByte8Padding::Left => vec![Bytes8::new([0, 0, 0, 0, 0, 0, 0, *n as u8])],
},
ConstantValue::Uint(n) if ty.is_uint(context) => {
vec![Bytes8::new(n.to_be_bytes())]
}
Expand Down

0 comments on commit 64945a3

Please sign in to comment.