diff --git a/hbvm/src/value.rs b/hbvm/src/value.rs index fd74b7b..b3d24e8 100644 --- a/hbvm/src/value.rs +++ b/hbvm/src/value.rs @@ -45,6 +45,8 @@ impl Value { /// # Safety /// - N/A, not to be implemented manually pub unsafe trait ValueVariant: private::Sealed + Copy + Into {} +impl private::Sealed for Value {} +unsafe impl ValueVariant for Value {} mod private { pub trait Sealed {} diff --git a/hbvm/src/vmrun.rs b/hbvm/src/vmrun.rs index fbf7f3d..13bcbc3 100644 --- a/hbvm/src/vmrun.rs +++ b/hbvm/src/vmrun.rs @@ -543,9 +543,15 @@ where /// Write a register. /// Writing to register 0 is no-op. #[inline(always)] - fn write_reg(&mut self, n: u8, value: impl Into) { + fn write_reg(&mut self, n: u8, value: T) { if n != 0 { - unsafe { *self.registers.get_unchecked_mut(n as usize) = value.into() }; + unsafe { + core::ptr::copy_nonoverlapping( + (&value as *const T).cast::(), + self.registers.as_mut_ptr().add(n.into()).cast::(), + core::mem::size_of::(), + ); + }; } }