mirror of
https://github.com/fluencelabs/parity-wasm
synced 2025-06-12 06:21:40 +00:00
Clean module stuff
This commit is contained in:
@ -1,17 +1,9 @@
|
||||
use std::collections::HashMap;
|
||||
use std::iter::repeat;
|
||||
use std::sync::{Arc, Weak};
|
||||
use std::fmt;
|
||||
use elements::{Module, InitExpr, Opcode, Type, FunctionType, Internal, External, ResizableLimits, Local, ValueType, BlockType};
|
||||
use elements::{InitExpr, Opcode, Type, FunctionType, Internal, External, ResizableLimits, Local, ValueType, BlockType};
|
||||
use interpreter::Error;
|
||||
use interpreter::native::UserFunctionDescriptor;
|
||||
use interpreter::memory::MemoryInstance;
|
||||
use interpreter::runner::{FunctionContext, prepare_function_args};
|
||||
use interpreter::table::TableInstance;
|
||||
use interpreter::value::{RuntimeValue, TryInto};
|
||||
use interpreter::variable::{VariableInstance, VariableType};
|
||||
use interpreter::runner::{FunctionContext};
|
||||
use interpreter::VariableType;
|
||||
use interpreter::RuntimeValue;
|
||||
use common::stack::StackWithLimit;
|
||||
use interpreter::store::FuncId;
|
||||
|
||||
/// Maximum number of entries in value stack.
|
||||
const DEFAULT_VALUE_STACK_LIMIT: usize = 16384;
|
||||
@ -26,24 +18,13 @@ pub struct ExecutionParams<'a, St: 'static> {
|
||||
|
||||
/// Export type.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum ExportEntryType<'a> {
|
||||
pub enum ExportEntryType {
|
||||
/// Any type.
|
||||
Any,
|
||||
/// Type of function.
|
||||
Function(FunctionSignature<'a>),
|
||||
/// Type of global.
|
||||
Global(VariableType),
|
||||
}
|
||||
|
||||
/// Function signature.
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum FunctionSignature<'a> {
|
||||
/// Module function reference.
|
||||
Module(&'a FunctionType),
|
||||
/// Native user function refrence.
|
||||
User(&'a UserFunctionDescriptor),
|
||||
}
|
||||
|
||||
/// Item index in items index space.
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum ItemIndex {
|
||||
@ -65,23 +46,6 @@ pub struct CallerContext<'a> {
|
||||
pub value_stack: &'a mut StackWithLimit<RuntimeValue>,
|
||||
}
|
||||
|
||||
/// Internal function ready for interpretation.
|
||||
pub struct InternalFunction<'a> {
|
||||
/// Function locals.
|
||||
pub locals: &'a [Local],
|
||||
/// Function body.
|
||||
pub body: &'a [Opcode],
|
||||
/// Function labels.
|
||||
pub labels: &'a HashMap<usize, usize>,
|
||||
}
|
||||
|
||||
impl<'a, St> ExecutionParams<'a, St> {
|
||||
/// Add argument.
|
||||
pub fn add_argument(mut self, arg: RuntimeValue) -> Self {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> CallerContext<'a> {
|
||||
/// Top most args
|
||||
pub fn topmost(args: &'a mut StackWithLimit<RuntimeValue>) -> Self {
|
||||
@ -111,41 +75,3 @@ pub fn check_limits(limits: &ResizableLimits) -> Result<(), Error> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
impl<'a> FunctionSignature<'a> {
|
||||
/// Get return type of this function.
|
||||
pub fn return_type(&self) -> Option<ValueType> {
|
||||
match self {
|
||||
&FunctionSignature::Module(ft) => ft.return_type(),
|
||||
&FunctionSignature::User(fd) => fd.return_type(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get parameters of this function.
|
||||
pub fn params(&self) -> &[ValueType] {
|
||||
match self {
|
||||
&FunctionSignature::Module(ft) => ft.params(),
|
||||
&FunctionSignature::User(fd) => fd.params(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> PartialEq for FunctionSignature<'a> {
|
||||
fn eq<'b>(&self, other: &FunctionSignature<'b>) -> bool {
|
||||
match self {
|
||||
&FunctionSignature::Module(ft1) => match other {
|
||||
&FunctionSignature::Module(ft2) => ft1 == ft2,
|
||||
&FunctionSignature::User(ft2) => ft1.params() == ft2.params() && ft1.return_type() == ft2.return_type(),
|
||||
},
|
||||
&FunctionSignature::User(ft1) => match other {
|
||||
&FunctionSignature::User(ft2) => ft1 == ft2,
|
||||
&FunctionSignature::Module(ft2) => ft1.params() == ft2.params() && ft1.return_type() == ft2.return_type(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
impl<'a> From<&'a FunctionType> for FunctionSignature<'a> {
|
||||
fn from(other: &'a FunctionType) -> Self {
|
||||
FunctionSignature::Module(other)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user