Refactor the types.rs types and structures (#681)
* Refactor the `types.rs` types and structures A few changes applied along the way: * Documentation added to most methods and types. * Limits are now stored with the maximum as optional rather than a sentinel u32 value for `None`. * The `Name` type was removed in favor of just using a bare `String`. * The `Extern` prefix in the varaints of `ExternType` has been removed since it was redundant. * Accessors of `ExternType` variants no longer panic, and unwrapping versions were added with "unwrap" in the name. * Fields and methods named `r#type` were renamed to `ty` to avoid requiring a raw identifier to use them. * Remove `fail-fast: false` This was left around since the development of GitHub Actions for wasmtime, but they're no longer needed! * Fix compilation of the test-programs code * Fix compilation of wasmtime-py package * Run rustfmt
This commit is contained in:
@@ -22,8 +22,8 @@ impl Instance {
|
||||
let exports = PyDict::new(py);
|
||||
let module = self.instance.borrow().module().clone();
|
||||
for (i, e) in module.borrow().exports().iter().enumerate() {
|
||||
match e.r#type() {
|
||||
wasmtime::ExternType::ExternFunc(ft) => {
|
||||
match e.ty() {
|
||||
wasmtime::ExternType::Func(ft) => {
|
||||
let mut args_types = Vec::new();
|
||||
for ty in ft.params().iter() {
|
||||
args_types.push(ty.clone());
|
||||
@@ -39,7 +39,7 @@ impl Instance {
|
||||
)?;
|
||||
exports.set_item(e.name().to_string(), f)?;
|
||||
}
|
||||
wasmtime::ExternType::ExternMemory(_) => {
|
||||
wasmtime::ExternType::Memory(_) => {
|
||||
let f = Py::new(
|
||||
py,
|
||||
Memory {
|
||||
|
||||
@@ -111,21 +111,18 @@ pub fn instantiate(
|
||||
|
||||
let mut imports: Vec<wasmtime::Extern> = Vec::new();
|
||||
for i in module.borrow().imports() {
|
||||
let module_name = i.module().as_str();
|
||||
let module_name = i.module();
|
||||
if let Some(m) = import_obj.get_item(module_name) {
|
||||
let e = find_export_in(m, &store, i.name().as_str())?;
|
||||
let e = find_export_in(m, &store, i.name())?;
|
||||
imports.push(e);
|
||||
} else if wasi.is_some() && module_name == wasi.as_ref().unwrap().0 {
|
||||
let e = wasi
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.1
|
||||
.find_export_by_name(i.name().as_str())
|
||||
.find_export_by_name(i.name())
|
||||
.ok_or_else(|| {
|
||||
PyErr::new::<Exception, _>(format!(
|
||||
"wasi export {} is not found",
|
||||
i.name().as_str()
|
||||
))
|
||||
PyErr::new::<Exception, _>(format!("wasi export {} is not found", i.name(),))
|
||||
})?;
|
||||
imports.push(e.clone());
|
||||
} else {
|
||||
|
||||
@@ -69,13 +69,13 @@ fn generate_load(item: &syn::ItemTrait) -> syn::Result<TokenStream> {
|
||||
let wasi_instance = #root::wasmtime_wasi::create_wasi_instance(&store, &[], &[], &[])
|
||||
.map_err(|e| format_err!("wasm instantiation error: {:?}", e))?;
|
||||
for i in module.borrow().imports().iter() {
|
||||
if i.module().as_str() != module_name {
|
||||
bail!("unknown import module {}", i.module().as_str());
|
||||
if i.module() != module_name {
|
||||
bail!("unknown import module {}", i.module());
|
||||
}
|
||||
if let Some(export) = wasi_instance.find_export_by_name(i.name().as_str()) {
|
||||
if let Some(export) = wasi_instance.find_export_by_name(i.name()) {
|
||||
imports.push(export.clone());
|
||||
} else {
|
||||
bail!("unknown import {}:{}", i.module().as_str(), i.name().as_str())
|
||||
bail!("unknown import {}:{}", i.module(), i.name())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user