Skip to content

Commit 4af7096

Browse files
cemonemwucke13
authored andcommitted
refactor: remove outside of spec & unused store/module fields and methods
with export registry modules/stores do not have to hold on to module names. Signed-off-by: Cem Onem <cem.oenem@dlr.de>
1 parent f0971c9 commit 4af7096

File tree

3 files changed

+9
-52
lines changed

3 files changed

+9
-52
lines changed

src/execution/mod.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ where
9191
) -> Result<FunctionRef, RuntimeError> {
9292
// TODO fix error
9393
let store = self.store.as_ref().ok_or(RuntimeError::ModuleNotFound)?;
94-
if !store.module_names.contains_key(module_name) {
95-
return Err(RuntimeError::ModuleNotFound);
96-
};
9794
FunctionRef::new_from_name(module_name, function_name, store)
9895
.map_err(|_| RuntimeError::FunctionNotFound)
9996
}

src/execution/store.rs

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ pub struct Store<'b> {
4747

4848
// fields outside of the spec but are convenient are below
4949

50-
// kv pair for module names and module "addresses" (that make sense with `Self.modules[module_addr]`)
51-
pub module_names: BTreeMap<String, usize>,
52-
5350
// all visible exports and entities added by hand or module instantiation by the interpreter
5451
// currently, all of the exports of an instantiated module is made visible (this is outside of spec)
5552
pub registry: Registry,
@@ -114,7 +111,6 @@ impl<'b> Store<'b> {
114111
exports: BTreeMap::new(),
115112
wasm_bytecode: validation_info.wasm,
116113
sidetable: validation_info.sidetable.clone(),
117-
name: name.to_owned(),
118114
};
119115

120116
// TODO rewrite this part
@@ -280,10 +276,6 @@ impl<'b> Store<'b> {
280276
let current_module_idx = &self.modules.len();
281277
self.modules.push(module_inst);
282278

283-
// keep module names, this is outside of the spec
284-
self.module_names
285-
.insert(String::from(name), *current_module_idx);
286-
287279
// instantiation: step 12-15
288280
// TODO have to stray away from the spec a bit since our codebase does not lend itself well to freely executing instructions by themselves
289281
for (
@@ -739,41 +731,6 @@ impl<'b> Store<'b> {
739731
debug!("Successfully invoked function");
740732
Ok(ret)
741733
}
742-
743-
//TODO consider further refactor
744-
pub fn get_module_idx_from_name(&self, module_name: &str) -> Result<usize, RuntimeError> {
745-
self.module_names
746-
.get(module_name)
747-
.copied()
748-
.ok_or(RuntimeError::ModuleNotFound)
749-
}
750-
751-
//TODO consider further refactor
752-
pub fn get_global_function_idx_by_name(
753-
&self,
754-
module_addr: usize,
755-
function_name: &str,
756-
) -> Option<usize> {
757-
self.modules
758-
.get(module_addr)?
759-
.exports
760-
.get(function_name)
761-
.and_then(|value| match value {
762-
ExternVal::Func(func_addr) => Some(*func_addr),
763-
_ => None,
764-
})
765-
}
766-
767-
//TODO consider further refactor
768-
pub fn register_alias(&mut self, alias_name: String, module_idx: usize) {
769-
self.module_names.insert(alias_name, module_idx);
770-
}
771-
772-
//TODO consider further refactor
773-
pub fn lookup_function(&self, target_module: &str, target_function: &str) -> Option<usize> {
774-
let module_addr = *self.module_names.get(target_module)?;
775-
self.get_global_function_idx_by_name(module_addr, target_function)
776-
}
777734
}
778735

779736
#[derive(Debug)]
@@ -1068,7 +1025,7 @@ pub struct ModuleInst<'b> {
10681025
pub wasm_bytecode: &'b [u8],
10691026

10701027
// sidetable is not in the spec, but required for control flow
1071-
pub sidetable: Sidetable
1028+
pub sidetable: Sidetable,
10721029
}
10731030

10741031
#[derive(Debug, PartialEq, PartialOrd, Eq, Ord)]

tests/linker.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use wasm::{validate, Store};
1+
use wasm::{validate, ExternVal, Store};
22

33
const SIMPLE_IMPORT_BASE: &str = r#"
44
(module
@@ -41,12 +41,15 @@ pub fn compile_simple_import() {
4141
// let mut instance =
4242
// RuntimeInstance::new_named("base", &validation_info_base).expect("instantiation failed");
4343

44-
let func_addr = match store.registry.lookup("base".into(), "get_three".into()).unwrap() {
45-
ExternVal::Func(func_addr) => *func_addr,
46-
_ => panic!("this entity is not a function"),
44+
let &ExternVal::Func(func_addr) = store
45+
.registry
46+
.lookup("base".into(), "get_three".into())
47+
.unwrap()
48+
else {
49+
panic!("this entity is not a function")
4750
};
4851

49-
println!("{:#?}", store.invoke::<(), i32>(func_idx, ()).unwrap());
52+
println!("{:#?}", store.invoke::<(), i32>(func_addr, ()).unwrap());
5053

5154
// let mut instance_addon = linker
5255
// .instantiate(&mut store, &validation_info_addon)

0 commit comments

Comments
 (0)