allow static signatures

This commit is contained in:
NikVolf 2018-01-24 14:14:24 +03:00
parent 9dc45eacbf
commit 65f08eb44c
3 changed files with 12 additions and 7 deletions

View File

@ -176,9 +176,9 @@ impl<'a> ModuleImportResolver for RuntimeModuleImportResolver {
) -> Result<FuncRef, InterpreterError> {
let func_ref = match field_name {
"set" => {
FuncInstance::alloc_host(Signature::new(&[ValueType::I32], None), SET_FUNC_INDEX)
FuncInstance::alloc_host(Signature::new(&[ValueType::I32][..], None), SET_FUNC_INDEX)
},
"get" => FuncInstance::alloc_host(Signature::new(&[ValueType::I32], Some(ValueType::I32)), GET_FUNC_INDEX),
"get" => FuncInstance::alloc_host(Signature::new(&[ValueType::I32][..], Some(ValueType::I32)), GET_FUNC_INDEX),
_ => return Err(
InterpreterError::Function(
format!("host module doesn't export function with name {}", field_name)

View File

@ -657,7 +657,7 @@ fn dynamically_add_host_func() {
self.added_funcs += 1;
let added_func = FuncInstance::alloc_host(
Signature::new(&[], Some(ValueType::I32)),
Signature::new(&[][..], Some(ValueType::I32)),
host_func_index as usize,
);
self.table.set(table_index, Some(added_func))?;

View File

@ -1,3 +1,5 @@
use std::borrow::Cow;
use parity_wasm::elements::{
FunctionType, ValueType as EValueType, GlobalType, TableType, MemoryType};
@ -10,20 +12,23 @@ use parity_wasm::elements::{
/// [type]: enum.ValueType.html
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Signature {
params: Vec<ValueType>,
params: Cow<'static, [ValueType]>,
return_type: Option<ValueType>,
}
impl Signature {
pub fn new(params: &[ValueType], return_type: Option<ValueType>) -> Signature {
pub fn new<C: Into<Cow<'static, [ValueType]>>>(
params: C,
return_type: Option<ValueType>
) -> Signature {
Signature {
params: params.to_vec(),
params: params.into(),
return_type: return_type,
}
}
pub fn params(&self) -> &[ValueType] {
&self.params
&self.params.as_ref()
}
pub fn return_type(&self) -> Option<ValueType> {