diff --git a/sway-lib-std/src/storage/storage_api.sw b/sway-lib-std/src/storage/storage_api.sw index a61baba1ee9..c69fa86478e 100644 --- a/sway-lib-std/src/storage/storage_api.sw +++ b/sway-lib-std/src/storage/storage_api.sw @@ -177,7 +177,7 @@ fn slot_calculator(slot: b256, offset: u64) -> (b256, u64, u64) { // TODO: Update when u256 <-> b256 conversions exist. // Determine which starting slot `T` will be stored based on the offset. - let mut u256_slot = asm(r1: slot) {r1: u256}; + let mut u256_slot = slot.as_u256(); let u256_increment = asm(r1: (0, 0, 0, last_slot - number_of_slots)) { r1: u256 }; u256_slot += u256_increment; let offset_slot = asm(r1: u256_slot) { r1: b256 }; diff --git a/sway-lib-std/src/u16.sw b/sway-lib-std/src/u16.sw index 59ae998ed09..a96eb6a7424 100644 --- a/sway-lib-std/src/u16.sw +++ b/sway-lib-std/src/u16.sw @@ -5,20 +5,20 @@ use ::option::Option; impl TryFrom for u16 { fn try_from(u: u32) -> Option { - if u > asm(r1: u16::max()) { r1: u32 } { - return Option::None + if u > u16::max().as_u32() { + Option::None } else { - return Option::Some(asm(r1: u) {r1: u16}) + Option::Some(asm(r1: u) {r1: u16}) } } } impl TryFrom for u16 { fn try_from(u: u64) -> Option { - if u > asm(r1: u16::max()) { r1: u64 } { - return Option::None + if u > u16::max().as_u64() { + Option::None } else { - return Option::Some(asm(r1: u) {r1: u16}) + Option::Some(asm(r1: u) {r1: u16}) } } } @@ -27,10 +27,10 @@ impl TryFrom for u16 { fn try_from(u: u256) -> Option { let parts = asm(r1: u) { r1: (u64, u64, u64, u64) }; - if parts.0 != 0 || parts.1 != 0 || parts.2 != 0 || parts.3 > asm(r1: u16::max()) { r1: u64 } { - return Option::None + if parts.0 != 0 || parts.1 != 0 || parts.2 != 0 || parts.3 > u16::max().as_u64() { + Option::None } else { - return Option::Some(asm(r1: parts.3) {r1: u16}) + Option::Some(asm(r1: parts.3) {r1: u16}) } } } @@ -40,7 +40,7 @@ fn test_u16_try_from_u32() { use ::assert::assert; let u32_1: u32 = 2u32; - let u32_2: u32 = asm(r1: u16::max()) { r1: u32 } + 1; + let u32_2: u32 = u16::max().as_u32() + 1; let u16_1 = >::try_from(u32_1); let u16_2 = >::try_from(u32_2); @@ -56,7 +56,7 @@ fn test_u16_try_from_u64() { use ::assert::assert; let u64_1: u64 = 2; - let u64_2: u64 = asm(r1: u16::max()) { r1: u64 } + 1; + let u64_2: u64 = u16::max().as_u64() + 1; let u16_1 = >::try_from(u64_1); let u16_2 = >::try_from(u64_2); diff --git a/sway-lib-std/src/u32.sw b/sway-lib-std/src/u32.sw index ced2405bd38..7b851cbf94f 100644 --- a/sway-lib-std/src/u32.sw +++ b/sway-lib-std/src/u32.sw @@ -5,10 +5,10 @@ use ::option::Option; impl TryFrom for u32 { fn try_from(u: u64) -> Option { - if u > asm(r1: u32::max()) { r1: u64 } { - return Option::None + if u > u32::max().as_u64() { + Option::None } else { - return Option::Some(asm(r1: u) {r1: u32}) + Option::Some(asm(r1: u) {r1: u32}) } } } @@ -17,10 +17,10 @@ impl TryFrom for u32 { fn try_from(u: u256) -> Option { let parts = asm(r1: u) { r1: (u64, u64, u64, u64) }; - if parts.0 != 0 || parts.1 != 0 || parts.2 != 0 || parts.3 > asm(r1: u32::max()) { r1: u64 } { - return Option::None + if parts.0 != 0 || parts.1 != 0 || parts.2 != 0 || parts.3 > u32::max().as_u64() { + Option::None } else { - return Option::Some(asm(r1: parts.3) {r1: u32}) + Option::Some(asm(r1: parts.3) {r1: u32}) } } } @@ -30,7 +30,7 @@ fn test_u32_try_from_u64() { use ::assert::assert; let u64_1: u64 = 2; - let u64_2: u64 = asm(r1: u32::max()) { r1: u64 } + 1; + let u64_2: u64 = u32::max().as_u64() + 1; let u32_1 = >::try_from(u64_1); let u32_2 = >::try_from(u64_2); diff --git a/sway-lib-std/src/u64.sw b/sway-lib-std/src/u64.sw index c9a73e95caf..0984b8f4e1f 100644 --- a/sway-lib-std/src/u64.sw +++ b/sway-lib-std/src/u64.sw @@ -8,9 +8,9 @@ impl TryFrom for u64 { let parts = asm(r1: u) { r1: (u64, u64, u64, u64) }; if parts.0 != 0 || parts.1 != 0 || parts.2 != 0 { - return Option::None + Option::None } else { - return Option::Some(parts.3) + Option::Some(parts.3) } } } diff --git a/sway-lib-std/src/u8.sw b/sway-lib-std/src/u8.sw index 8f3d438a968..f0b57308374 100644 --- a/sway-lib-std/src/u8.sw +++ b/sway-lib-std/src/u8.sw @@ -5,30 +5,30 @@ use ::option::Option; impl TryFrom for u8 { fn try_from(u: u16) -> Option { - if u > asm(r1: u8::max()) { r1: u16 } { - return Option::None + if u > u8::max().as_u16() { + Option::None } else { - return Option::Some(asm(r1: u) {r1: u8}) + Option::Some(asm(r1: u) {r1: u8}) } } } impl TryFrom for u8 { fn try_from(u: u32) -> Option { - if u > asm(r1: u8::max()) { r1: u32 } { - return Option::None + if u > u8::max().as_u32() { + Option::None } else { - return Option::Some(asm(r1: u) {r1: u8}) + Option::Some(asm(r1: u) {r1: u8}) } } } impl TryFrom for u8 { fn try_from(u: u64) -> Option { - if u > asm(r1: u8::max()) { r1: u64 } { - return Option::None + if u > u8::max().as_u64() { + Option::None } else { - return Option::Some(asm(r1: u) {r1: u8}) + Option::Some(asm(r1: u) {r1: u8}) } } } @@ -37,10 +37,10 @@ impl TryFrom for u8 { fn try_from(u: u256) -> Option { let parts = asm(r1: u) { r1: (u64, u64, u64, u64) }; - if parts.0 != 0 || parts.1 != 0 || parts.2 != 0 || parts.3 > asm(r1: u8::max()) { r1: u64 } { - return Option::None + if parts.0 != 0 || parts.1 != 0 || parts.2 != 0 || parts.3 > u8::max().as_u64() { + Option::None } else { - return Option::Some(asm(r1: parts.3) {r1: u8}) + Option::Some(asm(r1: parts.3) {r1: u8}) } } } @@ -50,7 +50,7 @@ fn test_u8_try_from_u16() { use ::assert::assert; let u16_1: u16 = 2u16; - let u16_2: u16 = asm(r1: u8::max()) { r1: u16 } + 1; + let u16_2: u16 = u8::max().as_u16() + 1; let u8_1 = >::try_from(u16_1); let u8_2 = >::try_from(u16_2); @@ -66,7 +66,7 @@ fn test_u8_try_from_u32() { use ::assert::assert; let u32_1: u32 = 2u32; - let u32_2: u32 = asm(r1: u16::max()) { r1: u32 } + 1; + let u32_2: u32 = u16::max().as_u32() + 1; let u8_1 = >::try_from(u32_1); let u8_2 = >::try_from(u32_2); @@ -82,7 +82,7 @@ fn test_u8_try_from_u64() { use ::assert::assert; let u64_1: u64 = 2; - let u64_2: u64 = asm(r1: u16::max()) { r1: u64 } + 1; + let u64_2: u64 = u16::max().as_u64() + 1; let u8_1 = >::try_from(u64_1); let u8_2 = >::try_from(u64_2);