In preparation for eventual support for wasm interface types this commit moves around a few panics internally inside of conversions between the `wasmtime` crate and the underlying jit support crates. This should have any immediately-visible user changes, but the goal is that this'll help support interface types which means `wasmtime` will have types that are not supported by wasmtime itself and we'll be able to more gracefully support that with error messages instead of accidental panics.
33 lines
1.1 KiB
Rust
33 lines
1.1 KiB
Rust
use super::create_handle::create_handle;
|
|
use crate::{TableType, ValType};
|
|
use anyhow::{bail, Result};
|
|
use wasmtime_environ::entity::PrimaryMap;
|
|
use wasmtime_environ::{wasm, Module};
|
|
use wasmtime_runtime::InstanceHandle;
|
|
|
|
pub fn create_handle_with_table(table: &TableType) -> Result<InstanceHandle> {
|
|
let mut module = Module::new();
|
|
|
|
let table = wasm::Table {
|
|
minimum: table.limits().min(),
|
|
maximum: table.limits().max(),
|
|
ty: match table.element() {
|
|
ValType::FuncRef => wasm::TableElementType::Func,
|
|
_ => match table.element().get_wasmtime_type() {
|
|
Some(t) => wasm::TableElementType::Val(t),
|
|
None => bail!("cannot support {:?} as a table element", table.element()),
|
|
},
|
|
},
|
|
};
|
|
let tunable = Default::default();
|
|
|
|
let table_plan = wasmtime_environ::TablePlan::for_table(table, &tunable);
|
|
let table_id = module.table_plans.push(table_plan);
|
|
module.exports.insert(
|
|
"table".to_string(),
|
|
wasmtime_environ::Export::Table(table_id),
|
|
);
|
|
|
|
create_handle(module, None, PrimaryMap::new(), Box::new(()))
|
|
}
|