From 57f30109c8d5ccd3945076b2e86ed6d9add47ea1 Mon Sep 17 00:00:00 2001 From: Erin Date: Sun, 29 Oct 2023 20:38:57 +0100 Subject: [PATCH] Fixed smaller units --- hbvm/src/value.rs | 2 ++ hbvm/src/vmrun.rs | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) 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::(), + ); + }; } }