From 8d6e7af9d886d2a582f2532c8641f3811cd1e94e Mon Sep 17 00:00:00 2001 From: Erin Date: Tue, 6 Jun 2023 23:08:26 +0200 Subject: [PATCH] Validated VM creator --- hbvm/src/vm/mod.rs | 7 +++++++ hbvm/src/vm/value.rs | 5 +---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/hbvm/src/vm/mod.rs b/hbvm/src/vm/mod.rs index c6e8c93f..0275558d 100644 --- a/hbvm/src/vm/mod.rs +++ b/hbvm/src/vm/mod.rs @@ -1,3 +1,5 @@ +use crate::validate; + mod value; use { @@ -43,6 +45,11 @@ impl<'a> Vm<'a> { } } + pub fn new_validated(program: &'a [u8]) -> Result { + validate::validate(program)?; + Ok(unsafe { Self::new_unchecked(program) }) + } + pub fn run(&mut self) { use crate::bytecode::opcode::*; loop { diff --git a/hbvm/src/vm/value.rs b/hbvm/src/vm/value.rs index 3544dd4e..3b95c0fa 100644 --- a/hbvm/src/vm/value.rs +++ b/hbvm/src/vm/value.rs @@ -1,7 +1,4 @@ -use core::{ - fmt::Debug, - ops::{Index, IndexMut}, -}; +use core::fmt::Debug; /// # Safety /// The macro invoker shall make sure that byte reinterpret-cast