From 80d343d30ae56616df8b83d918597a8c0ce068b7 Mon Sep 17 00:00:00 2001 From: dload0 <170800883+dload0@users.noreply.github.com> Date: Fri, 27 Sep 2024 23:54:03 +0100 Subject: [PATCH 1/2] feat: Implement From for u16. Signed-off-by: dload0 <170800883+dload0@users.noreply.github.com> --- src/ir/moka_instruction.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ir/moka_instruction.rs b/src/ir/moka_instruction.rs index 5bf17a5..b90003f 100644 --- a/src/ir/moka_instruction.rs +++ b/src/ir/moka_instruction.rs @@ -191,6 +191,12 @@ impl LocalValue { } } +impl From for u16 { + fn from(value: LocalValue) -> Self { + value.0 + } +} + /// Represents an identifier of a value in the current scope. #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, derive_more::Display)] #[cfg_attr(test, derive(proptest_derive::Arbitrary))] From c51a5d020b67c9222d1bb8dd40d151f2227f9931 Mon Sep 17 00:00:00 2001 From: Henry Chu Date: Sun, 29 Sep 2024 13:10:56 +0800 Subject: [PATCH 2/2] test(ir): local_value_inner_convertion --- src/ir/moka_instruction.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/ir/moka_instruction.rs b/src/ir/moka_instruction.rs index b90003f..6d6ecda 100644 --- a/src/ir/moka_instruction.rs +++ b/src/ir/moka_instruction.rs @@ -225,6 +225,15 @@ pub(super) mod test { use super::*; use proptest::prelude::*; + proptest! { + #[test] + fn local_value_inner_convertion(id in 0..u16::MAX) { + let value = LocalValue::new(id); + let id: u16 = value.into(); + assert_eq!(id, value.0); + } + } + pub(crate) fn arb_argument() -> impl Strategy { prop_oneof![ any::().prop_map(Operand::Just),