Browse Source

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.
pull/544/head
Alex Crichton 5 years ago
committed by GitHub
parent
commit
cd8cc4d375
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 23
      crates/misc/py/src/instance.rs
  2. 7
      crates/misc/py/src/lib.rs

23
crates/misc/py/src/instance.rs

@ -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");

7
crates/misc/py/src/lib.rs

@ -9,6 +9,7 @@ use pyo3::types::{PyBytes, PyDict, PySet};
use pyo3::wrap_pyfunction;
use std::rc::Rc;
use wasmtime_interface_types::ModuleData;
use wasmtime_jit::Features;
mod function;
mod import;
@ -61,7 +62,11 @@ pub fn instantiate(
isa_builder.finish(cranelift_codegen::settings::Flags::new(flag_builder))
};
let mut context = wasmtime_jit::Context::with_isa(isa, wasmtime_jit::CompilationStrategy::Auto);
let mut context = wasmtime_jit::Context::with_isa(isa, wasmtime_jit::CompilationStrategy::Auto)
.with_features(Features {
multi_value: true,
..Features::default()
});
context.set_debug_info(generate_debug_info);
let global_exports = context.get_global_exports();

Loading…
Cancel
Save