diff --git a/src/runtime/backing.rs b/src/runtime/backing.rs index f326f4b86..5a5ab133c 100644 --- a/src/runtime/backing.rs +++ b/src/runtime/backing.rs @@ -4,7 +4,7 @@ use crate::runtime::{ module::{ImportName, Module}, sig_registry::SigRegistry, table::{TableBacking, TableElements}, - types::{GlobalInit, MapIndex, Val}, + types::{Initializer, MapIndex, Val}, vm, }; @@ -149,11 +149,11 @@ impl LocalBacking { ) -> Box<[vm::LocalGlobal]> { for (to, (_, from)) in globals.iter_mut().zip(module.globals.into_iter()) { to.data = match from.init { - GlobalInit::Val(Val::I32(x)) => x as u64, - GlobalInit::Val(Val::I64(x)) => x as u64, - GlobalInit::Val(Val::F32(x)) => x as u64, - GlobalInit::Val(Val::F64(x)) => x, - GlobalInit::GetGlobal(index) => (imports.globals[index.index()].global).data, + Initializer::Const(Val::I32(x)) => x as u64, + Initializer::Const(Val::I64(x)) => x as u64, + Initializer::Const(Val::F32(x)) => x as u64, + Initializer::Const(Val::F64(x)) => x, + Initializer::GetGlobal(index) => (imports.globals[index.index()].global).data, }; } diff --git a/src/runtime/module.rs b/src/runtime/module.rs index 707684682..89d379fcb 100644 --- a/src/runtime/module.rs +++ b/src/runtime/module.rs @@ -11,14 +11,14 @@ use std::ptr::NonNull; /// This is used to instantiate a new webassembly module. pub struct Module { pub function_resolver: Box Option>>, - pub memories: Map, - pub globals: Map, - pub tables: Map, + pub memories: Map, + pub globals: Map, + pub tables: Map, - pub imported_functions: Map, - pub imported_memories: Map<(ImportName, Memory), MemoryIndex>, - pub imported_tables: Map<(ImportName, Table), TableIndex>, - pub imported_globals: Map<(ImportName, GlobalDesc), GlobalIndex>, + pub imported_functions: Map, + pub imported_memories: Map, + pub imported_tables: Map, + pub imported_globals: Map, pub exports: HashMap, @@ -26,8 +26,8 @@ pub struct Module { pub table_initializers: Vec, pub start_func: Option, - pub signature_assoc: Map, - pub signatures: Map, + pub signature_assoc: Map, + pub signatures: Map, } impl Module { diff --git a/src/runtime/sig_registry.rs b/src/runtime/sig_registry.rs index 1912211fb..bc60bae5e 100644 --- a/src/runtime/sig_registry.rs +++ b/src/runtime/sig_registry.rs @@ -7,7 +7,7 @@ use hashbrown::HashMap; pub struct SigRegistry { sig_set: HashMap, - signatures: Map, + signatures: Map, } impl SigRegistry { @@ -19,7 +19,8 @@ impl SigRegistry { for (_, &sig_index) in &module.signature_assoc { let func_sig = module.signatures[sig_index].clone(); - registry.register(func_sig); + let new_sig_index = registry.register(func_sig); + assert_eq!(sig_index, new_sig_index); } registry @@ -33,12 +34,12 @@ impl SigRegistry { self.signatures[sig_index] } - fn register(&mut self, signature: FuncSig) { + fn register(&mut self, signature: FuncSig) -> SigIndex { let index = self.sig_set.len(); let vm_sig_id = *self .sig_set .entry(signature) .or_insert_with(|| vm::SigId(index as u32)); - self.signatures.push(vm_sig_id); + self.signatures.push(vm_sig_id) } } diff --git a/src/runtime/types.rs b/src/runtime/types.rs index 34e3e39eb..f41fab26e 100644 --- a/src/runtime/types.rs +++ b/src/runtime/types.rs @@ -84,8 +84,10 @@ pub struct Table { /// Overtime, this will be able to represent more and more /// complex expressions. #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum GlobalInit { - Val(Val), +pub enum Initializer { + /// Corresponds to a `const.*` instruction. + Const(Val), + /// Corresponds to a `get_global` instruction. GetGlobal(GlobalIndex), } @@ -99,7 +101,7 @@ pub struct GlobalDesc { #[derive(Debug, Clone, Copy)] pub struct Global { pub desc: GlobalDesc, - pub init: GlobalInit, + pub init: Initializer, } /// A wasm memory. @@ -144,7 +146,7 @@ pub trait MapIndex { /// Dense item map #[derive(Debug, Clone)] -pub struct Map +pub struct Map where I: MapIndex, { @@ -152,7 +154,7 @@ where _marker: PhantomData, } -impl Map +impl Map where I: MapIndex, { @@ -189,7 +191,7 @@ where } } -impl Index for Map +impl Index for Map where I: MapIndex, { @@ -199,7 +201,7 @@ where } } -impl IndexMut for Map +impl IndexMut for Map where I: MapIndex, { @@ -208,7 +210,7 @@ where } } -impl<'a, T, I> IntoIterator for &'a Map +impl<'a, I, T> IntoIterator for &'a Map where I: MapIndex, { @@ -220,7 +222,7 @@ where } } -impl<'a, T, I> IntoIterator for &'a mut Map +impl<'a, I, T> IntoIterator for &'a mut Map where I: MapIndex, {