From f130a27685e701ca615a3fdf143ee2934c0ff9df Mon Sep 17 00:00:00 2001 From: Erin Date: Mon, 7 Aug 2023 01:50:21 +0200 Subject: [PATCH] Shrunk --- hbvm/src/lib.rs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/hbvm/src/lib.rs b/hbvm/src/lib.rs index 5c1021a..f71aeb9 100644 --- a/hbvm/src/lib.rs +++ b/hbvm/src/lib.rs @@ -11,9 +11,10 @@ // - Mapped pages should be at least 4 KiB #![no_std] - #![cfg_attr(feature = "nightly", feature(fn_align))] +use core::marker::PhantomData; + #[cfg(feature = "alloc")] extern crate alloc; @@ -47,11 +48,14 @@ pub struct Vm<'a, PfHandler, const TIMER_QUOTIENT: usize> { pub pc: usize, /// Program - program: &'a [u8], + program: *const u8, /// Cached program length (without unreachable end) program_len: usize, + /// Program lifetime + _program_lt: PhantomData<&'a [u8]>, + /// Program timer timer: usize, @@ -73,7 +77,8 @@ impl<'a, PfHandler: HandlePageFault, const TIMER_QUOTIENT: usize> pfhandler: traph, pc: 0, program_len: program.len() - 12, - program: &program[4..], + program: program[4..].as_ptr(), + _program_lt: Default::default(), timer: 0, copier: None, } @@ -121,7 +126,7 @@ impl<'a, PfHandler: HandlePageFault, const TIMER_QUOTIENT: usize> // - Yes, we assume you run 64 bit CPU. Else ?conradluget a better CPU // sorry 8 bit fans, HBVM won't run on your Speccy :( unsafe { - match *self.program.get_unchecked(self.pc) { + match *self.program.add(self.pc) { UN => { self.decode::<()>(); return Err(VmRunError::Unreachable); @@ -386,7 +391,7 @@ impl<'a, PfHandler: HandlePageFault, const TIMER_QUOTIENT: usize> /// Decode instruction operands #[inline] unsafe fn decode(&mut self) -> T { - let data = self.program.as_ptr().add(self.pc + 1).cast::().read(); + let data = self.program.add(self.pc + 1).cast::().read(); self.pc += 1 + size_of::(); data }