mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-06 11:31:35 +00:00
Ditch HostFuncIndex
This commit is contained in:
parent
3432b325c0
commit
cefe26ef35
@ -4,7 +4,7 @@ use std::collections::HashMap;
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use elements::{FunctionType, Local, Opcodes};
|
use elements::{FunctionType, Local, Opcodes};
|
||||||
use interpreter::Error;
|
use interpreter::Error;
|
||||||
use interpreter::host::{Externals, HostFuncIndex};
|
use interpreter::host::Externals;
|
||||||
use interpreter::runner::{prepare_function_args, FunctionContext, Interpreter};
|
use interpreter::runner::{prepare_function_args, FunctionContext, Interpreter};
|
||||||
use interpreter::value::RuntimeValue;
|
use interpreter::value::RuntimeValue;
|
||||||
use interpreter::module::ModuleRef;
|
use interpreter::module::ModuleRef;
|
||||||
@ -30,7 +30,7 @@ pub enum FuncInstance {
|
|||||||
},
|
},
|
||||||
Host {
|
Host {
|
||||||
func_type: FunctionType,
|
func_type: FunctionType,
|
||||||
host_func: HostFuncIndex,
|
host_func_index: usize,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,10 +70,10 @@ impl FuncInstance {
|
|||||||
FuncRef(Rc::new(func))
|
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 {
|
let func = FuncInstance::Host {
|
||||||
func_type,
|
func_type,
|
||||||
host_func,
|
host_func_index,
|
||||||
};
|
};
|
||||||
FuncRef(Rc::new(func))
|
FuncRef(Rc::new(func))
|
||||||
}
|
}
|
||||||
@ -99,7 +99,7 @@ impl FuncInstance {
|
|||||||
) -> Result<Option<RuntimeValue>, Error> {
|
) -> Result<Option<RuntimeValue>, Error> {
|
||||||
enum InvokeKind<'a> {
|
enum InvokeKind<'a> {
|
||||||
Internal(FunctionContext),
|
Internal(FunctionContext),
|
||||||
Host(HostFuncIndex, &'a [RuntimeValue]),
|
Host(usize, &'a [RuntimeValue]),
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = match *func {
|
let result = match *func {
|
||||||
@ -116,8 +116,8 @@ impl FuncInstance {
|
|||||||
);
|
);
|
||||||
InvokeKind::Internal(context)
|
InvokeKind::Internal(context)
|
||||||
}
|
}
|
||||||
FuncInstance::Host { ref host_func, .. } => {
|
FuncInstance::Host { ref host_func_index, .. } => {
|
||||||
InvokeKind::Host(*host_func, &*args)
|
InvokeKind::Host(*host_func_index, &*args)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -32,16 +32,14 @@ impl HostError {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type HostFuncIndex = u32;
|
|
||||||
|
|
||||||
pub trait Externals {
|
pub trait Externals {
|
||||||
fn invoke_index(
|
fn invoke_index(
|
||||||
&mut self,
|
&mut self,
|
||||||
index: HostFuncIndex,
|
index: usize,
|
||||||
args: &[RuntimeValue],
|
args: &[RuntimeValue],
|
||||||
) -> Result<Option<RuntimeValue>, Error>;
|
) -> Result<Option<RuntimeValue>, Error>;
|
||||||
|
|
||||||
fn check_signature(&self, index: HostFuncIndex, signature: &FunctionType) -> bool;
|
fn check_signature(&self, index: usize, signature: &FunctionType) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct NopExternals;
|
pub struct NopExternals;
|
||||||
@ -49,13 +47,13 @@ pub struct NopExternals;
|
|||||||
impl Externals for NopExternals {
|
impl Externals for NopExternals {
|
||||||
fn invoke_index(
|
fn invoke_index(
|
||||||
&mut self,
|
&mut self,
|
||||||
_index: HostFuncIndex,
|
_index: usize,
|
||||||
_args: &[RuntimeValue],
|
_args: &[RuntimeValue],
|
||||||
) -> Result<Option<RuntimeValue>, Error> {
|
) -> Result<Option<RuntimeValue>, Error> {
|
||||||
Err(Error::Trap("invoke index on no-op externals".into()))
|
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
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ mod tests;
|
|||||||
pub use self::memory::{MemoryInstance, MemoryRef};
|
pub use self::memory::{MemoryInstance, MemoryRef};
|
||||||
pub use self::table::{TableInstance, TableRef};
|
pub use self::table::{TableInstance, TableRef};
|
||||||
pub use self::value::{RuntimeValue, TryInto};
|
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::imports::{ImportResolver, Imports};
|
||||||
pub use self::module::{ModuleInstance, ModuleRef, ExternVal, InstantiationBuilder, NotStartedModuleRef};
|
pub use self::module::{ModuleInstance, ModuleRef, ExternVal, InstantiationBuilder, NotStartedModuleRef};
|
||||||
pub use self::global::{GlobalInstance, GlobalRef};
|
pub use self::global::{GlobalInstance, GlobalRef};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user