Enable multi-value in the Python extension (#541)

This commit enables the multi-value features in the Python extension
to be usable by-default with interface types. Additionally this removes
some code which panics on multi-value but doesn't end up getting used
today.
This commit is contained in:
Alex Crichton
2019-11-11 17:19:33 -06:00
committed by GitHub
parent d9edb95218
commit cd8cc4d375
2 changed files with 6 additions and 24 deletions

View File

@@ -6,7 +6,6 @@ use crate::function::Function;
use crate::memory::Memory;
use alloc::rc::Rc;
use core::cell::RefCell;
use cranelift_codegen::ir::{self, types};
use pyo3::prelude::*;
use pyo3::types::PyDict;
use wasmtime_environ::Export;
@@ -21,16 +20,6 @@ pub struct Instance {
pub data: Rc<ModuleData>,
}
fn get_type_annot(ty: ir::Type) -> &'static str {
match ty {
types::I32 => "i32",
types::I64 => "i64",
types::F32 => "f32",
types::F64 => "f64",
_ => panic!("unknown type"),
}
}
#[pymethods]
impl Instance {
#[getter(exports)]
@@ -67,20 +56,10 @@ impl Instance {
}
for name in function_exports {
if let Some(RuntimeExport::Function { signature, .. }) = self.instance.lookup(&name) {
let annot = PyDict::new(py);
let mut args_types = Vec::new();
for index in 1..signature.params.len() {
let ty = signature.params[index].value_type;
args_types.push(ty);
annot.set_item(format!("param{}", index - 1), get_type_annot(ty))?;
}
match signature.returns.len() {
0 => (),
1 => {
annot
.set_item("return", get_type_annot(signature.returns[0].value_type))?;
}
_ => panic!("multi-return"),
}
let f = Py::new(
py,
@@ -92,8 +71,6 @@ impl Instance {
args_types,
},
)?;
// FIXME set the f object the `__annotations__` attribute somehow?
let _ = annot;
exports.set_item(name, f)?;
} else {
panic!("function");