From 65f08eb44cbe8a467edf8dc56a57f9325d39409f Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 24 Jan 2018 14:14:24 +0300 Subject: [PATCH] allow static signatures --- examples/tictactoe.rs | 4 ++-- src/tests/host.rs | 2 +- src/types.rs | 13 +++++++++---- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/examples/tictactoe.rs b/examples/tictactoe.rs index 203d185..9624128 100644 --- a/examples/tictactoe.rs +++ b/examples/tictactoe.rs @@ -176,9 +176,9 @@ impl<'a> ModuleImportResolver for RuntimeModuleImportResolver { ) -> Result { 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) diff --git a/src/tests/host.rs b/src/tests/host.rs index 9f53b75..39b655c 100644 --- a/src/tests/host.rs +++ b/src/tests/host.rs @@ -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))?; diff --git a/src/types.rs b/src/types.rs index c5d3864..7e1e185 100644 --- a/src/types.rs +++ b/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, + params: Cow<'static, [ValueType]>, return_type: Option, } impl Signature { - pub fn new(params: &[ValueType], return_type: Option) -> Signature { + pub fn new>>( + params: C, + return_type: Option + ) -> 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 {