You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: export registry as a stand-in for linker
entities such as host functions and globals, tables, and memories without a native wasm module where they are defined are still referred within native wasm modules as imports with a module name, even though that module might not exist. Previous implementation necessitated existence of owning modules for these external entities. This implementation inspired by reference wasm interpreter removes that requirement.
Signed-off-by: Cem Onem <cem.oenem@dlr.de>
/// matches the list of ExportInst structs in the spec, however the spec never uses the name attribute
1063
+
/// except during linking, which is up to the embedder to implement.
1064
+
/// therefore this is a map data structure instead.
1065
+
pubexports:BTreeMap<String,ExternVal>,
1081
1066
1082
1067
// TODO the bytecode is not in the spec, but required for re-parsing
1083
1068
pubwasm_bytecode:&'b[u8],
1084
1069
1085
1070
// sidetable is not in the spec, but required for control flow
1086
-
pubsidetable:Sidetable,
1071
+
pubsidetable:Sidetable
1072
+
}
1073
+
1074
+
#[derive(Debug,PartialEq,PartialOrd,Eq,Ord)]
1075
+
structImportKey{
1076
+
module_name:Cow<'static,str>,
1077
+
name:Cow<'static,str>,
1078
+
}
1079
+
#[derive(Default,Debug)]
1080
+
pubstructRegistry(BTreeMap<ImportKey,ExternVal>);
1081
+
1082
+
implRegistry{
1083
+
pubfnregister(
1084
+
&mutself,
1085
+
module_name:Cow<'static,str>,
1086
+
name:Cow<'static,str>,
1087
+
extern_val:ExternVal,
1088
+
) -> Result<(),Error>{
1089
+
ifself
1090
+
.0
1091
+
.insert(ImportKey{ module_name, name }, extern_val)
1092
+
.is_some()
1093
+
{
1094
+
returnErr(Error::InvalidImportType);
1095
+
}
1096
+
1097
+
Ok(())
1098
+
}
1087
1099
1088
-
// TODO name field is not in the spec but used by the testsuite crate, might need to be refactored out
1089
-
// this data is unfortunately duplicated within store.module_names kv store.
1090
-
pubname:String,
1100
+
pubfnlookup(
1101
+
&self,
1102
+
module_name:Cow<'static,str>,
1103
+
name:Cow<'static,str>,
1104
+
) -> Result<&ExternVal,Error>{
1105
+
// Note: We cannot do a &str lookup on a [`String`] map key. Thus we have to use `Cow<'static, str> as a key (at least this prevents allocations with static names).
0 commit comments