Merge pull request #13 from pepyakin/static-signatures
Allow static signatures
This commit is contained in:
commit
f6f23accdd
|
@ -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)
|
||||
|
|
|
@ -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))?;
|
||||
|
|
13
src/types.rs
13
src/types.rs
|
@ -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> {
|
||||
|
|
Loading…
Reference in New Issue