From cefe26ef354911ab06cfaf7f48f9203eb3e8eeee Mon Sep 17 00:00:00 2001 From: Sergey Pepyakin Date: Wed, 10 Jan 2018 18:15:58 +0300 Subject: [PATCH] Ditch HostFuncIndex --- src/interpreter/func.rs | 14 +++++++------- src/interpreter/host.rs | 10 ++++------ src/interpreter/mod.rs | 2 +- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/interpreter/func.rs b/src/interpreter/func.rs index 2afe3af..7245b53 100644 --- a/src/interpreter/func.rs +++ b/src/interpreter/func.rs @@ -4,7 +4,7 @@ use std::collections::HashMap; use std::borrow::Cow; use elements::{FunctionType, Local, Opcodes}; use interpreter::Error; -use interpreter::host::{Externals, HostFuncIndex}; +use interpreter::host::Externals; use interpreter::runner::{prepare_function_args, FunctionContext, Interpreter}; use interpreter::value::RuntimeValue; use interpreter::module::ModuleRef; @@ -30,7 +30,7 @@ pub enum FuncInstance { }, Host { func_type: FunctionType, - host_func: HostFuncIndex, + host_func_index: usize, }, } @@ -70,10 +70,10 @@ impl FuncInstance { FuncRef(Rc::new(func)) } - pub fn alloc_host(func_type: FunctionType, host_func: HostFuncIndex) -> FuncRef { + pub fn alloc_host(func_type: FunctionType, host_func_index: usize) -> FuncRef { let func = FuncInstance::Host { func_type, - host_func, + host_func_index, }; FuncRef(Rc::new(func)) } @@ -99,7 +99,7 @@ impl FuncInstance { ) -> Result, Error> { enum InvokeKind<'a> { Internal(FunctionContext), - Host(HostFuncIndex, &'a [RuntimeValue]), + Host(usize, &'a [RuntimeValue]), } let result = match *func { @@ -116,8 +116,8 @@ impl FuncInstance { ); InvokeKind::Internal(context) } - FuncInstance::Host { ref host_func, .. } => { - InvokeKind::Host(*host_func, &*args) + FuncInstance::Host { ref host_func_index, .. } => { + InvokeKind::Host(*host_func_index, &*args) } }; diff --git a/src/interpreter/host.rs b/src/interpreter/host.rs index 86e448f..5d1ffab 100644 --- a/src/interpreter/host.rs +++ b/src/interpreter/host.rs @@ -32,16 +32,14 @@ impl HostError { } } -pub type HostFuncIndex = u32; - pub trait Externals { fn invoke_index( &mut self, - index: HostFuncIndex, + index: usize, args: &[RuntimeValue], ) -> Result, Error>; - fn check_signature(&self, index: HostFuncIndex, signature: &FunctionType) -> bool; + fn check_signature(&self, index: usize, signature: &FunctionType) -> bool; } pub struct NopExternals; @@ -49,13 +47,13 @@ pub struct NopExternals; impl Externals for NopExternals { fn invoke_index( &mut self, - _index: HostFuncIndex, + _index: usize, _args: &[RuntimeValue], ) -> Result, Error> { Err(Error::Trap("invoke index on no-op externals".into())) } - fn check_signature(&self, _index: HostFuncIndex, _signature: &FunctionType) -> bool { + fn check_signature(&self, _index: usize, _signature: &FunctionType) -> bool { false } } diff --git a/src/interpreter/mod.rs b/src/interpreter/mod.rs index 3821d07..c838f42 100644 --- a/src/interpreter/mod.rs +++ b/src/interpreter/mod.rs @@ -113,7 +113,7 @@ mod tests; pub use self::memory::{MemoryInstance, MemoryRef}; pub use self::table::{TableInstance, TableRef}; pub use self::value::{RuntimeValue, TryInto}; -pub use self::host::{Externals, HostFuncIndex, NopExternals, HostError}; +pub use self::host::{Externals, NopExternals, HostError}; pub use self::imports::{ImportResolver, Imports}; pub use self::module::{ModuleInstance, ModuleRef, ExternVal, InstantiationBuilder, NotStartedModuleRef}; pub use self::global::{GlobalInstance, GlobalRef};