Merge pull request #13 from pepyakin/static-signatures

Allow static signatures
This commit is contained in:
Nikolay Volf 2018-01-24 14:28:31 +03:00 committed by GitHub
commit f6f23accdd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 7 deletions

View File

@ -176,9 +176,9 @@ impl<'a> ModuleImportResolver for RuntimeModuleImportResolver {
) -> Result<FuncRef, InterpreterError> { ) -> Result<FuncRef, InterpreterError> {
let func_ref = match field_name { let func_ref = match field_name {
"set" => { "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( _ => return Err(
InterpreterError::Function( InterpreterError::Function(
format!("host module doesn't export function with name {}", field_name) 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; self.added_funcs += 1;
let added_func = FuncInstance::alloc_host( let added_func = FuncInstance::alloc_host(
Signature::new(&[], Some(ValueType::I32)), Signature::new(&[][..], Some(ValueType::I32)),
host_func_index as usize, host_func_index as usize,
); );
self.table.set(table_index, Some(added_func))?; self.table.set(table_index, Some(added_func))?;

View File

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