mirror of
https://github.com/fluencelabs/wasmer
synced 2025-04-22 17:02:13 +00:00
More review fixes
This commit is contained in:
parent
767fdbd950
commit
581363119b
@ -11,8 +11,8 @@ use wasmer_runtime_core::{
|
|||||||
module::{DataInitializer, ExportIndex, ImportName, TableInitializer},
|
module::{DataInitializer, ExportIndex, ImportName, TableInitializer},
|
||||||
structures::{Map, TypedIndex},
|
structures::{Map, TypedIndex},
|
||||||
types::{
|
types::{
|
||||||
ElementType, FuncSig, GlobalDesc, GlobalIndex, GlobalInit, Initializer, LocalFuncIndex,
|
ElementType, FuncSig, GlobalDescriptor, GlobalIndex, GlobalInit, Initializer,
|
||||||
LocalOrImport, MemoryDesc, SigIndex, TableDesc, Value,
|
LocalFuncIndex, LocalOrImport, MemoryDescriptor, SigIndex, TableDescriptor, Value,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
|
|||||||
|
|
||||||
/// Declares a global to the environment.
|
/// Declares a global to the environment.
|
||||||
fn declare_global(&mut self, global: cranelift_wasm::Global) {
|
fn declare_global(&mut self, global: cranelift_wasm::Global) {
|
||||||
let desc = GlobalDesc {
|
let desc = GlobalDescriptor {
|
||||||
mutable: global.mutability,
|
mutable: global.mutability,
|
||||||
ty: Converter(global.ty).into(),
|
ty: Converter(global.ty).into(),
|
||||||
};
|
};
|
||||||
@ -155,7 +155,7 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
|
|||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let desc = GlobalDesc {
|
let desc = GlobalDescriptor {
|
||||||
mutable: global.mutability,
|
mutable: global.mutability,
|
||||||
ty: Converter(global.ty).into(),
|
ty: Converter(global.ty).into(),
|
||||||
};
|
};
|
||||||
@ -175,8 +175,8 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
|
|||||||
fn declare_table(&mut self, table: cranelift_wasm::Table) {
|
fn declare_table(&mut self, table: cranelift_wasm::Table) {
|
||||||
use cranelift_wasm::TableElementType;
|
use cranelift_wasm::TableElementType;
|
||||||
// Add table ir to the list of tables
|
// Add table ir to the list of tables
|
||||||
self.module.tables.push(TableDesc {
|
self.module.tables.push(TableDescriptor {
|
||||||
ty: match table.ty {
|
element: match table.ty {
|
||||||
TableElementType::Func => ElementType::Anyfunc,
|
TableElementType::Func => ElementType::Anyfunc,
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
},
|
},
|
||||||
@ -199,8 +199,8 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
|
|||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let imported_table = TableDesc {
|
let imported_table = TableDescriptor {
|
||||||
ty: match table.ty {
|
element: match table.ty {
|
||||||
TableElementType::Func => ElementType::Anyfunc,
|
TableElementType::Func => ElementType::Anyfunc,
|
||||||
_ => unimplemented!(),
|
_ => unimplemented!(),
|
||||||
},
|
},
|
||||||
@ -250,7 +250,7 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
|
|||||||
|
|
||||||
/// Declares a memory to the environment
|
/// Declares a memory to the environment
|
||||||
fn declare_memory(&mut self, memory: cranelift_wasm::Memory) {
|
fn declare_memory(&mut self, memory: cranelift_wasm::Memory) {
|
||||||
self.module.memories.push(MemoryDesc {
|
self.module.memories.push(MemoryDescriptor {
|
||||||
min: memory.minimum,
|
min: memory.minimum,
|
||||||
max: memory.maximum,
|
max: memory.maximum,
|
||||||
shared: memory.shared,
|
shared: memory.shared,
|
||||||
@ -269,7 +269,7 @@ impl<'module, 'isa, 'data> ModuleEnvironment<'data> for ModuleEnv<'module, 'isa>
|
|||||||
name: name.to_string(),
|
name: name.to_string(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let memory = MemoryDesc {
|
let memory = MemoryDescriptor {
|
||||||
min: memory.minimum,
|
min: memory.minimum,
|
||||||
max: memory.maximum,
|
max: memory.maximum,
|
||||||
shared: memory.shared,
|
shared: memory.shared,
|
||||||
|
@ -10,7 +10,7 @@ use wasmer_runtime_core::{
|
|||||||
import::{ImportObject, Namespace},
|
import::{ImportObject, Namespace},
|
||||||
memory::Memory,
|
memory::Memory,
|
||||||
types::{
|
types::{
|
||||||
FuncSig, GlobalDesc,
|
FuncSig, GlobalDescriptor,
|
||||||
Type::{self, *},
|
Type::{self, *},
|
||||||
},
|
},
|
||||||
vm::LocalGlobal,
|
vm::LocalGlobal,
|
||||||
|
@ -6,7 +6,7 @@ use wasmer_runtime_core::{
|
|||||||
memory::Memory,
|
memory::Memory,
|
||||||
prelude::*,
|
prelude::*,
|
||||||
table::Table,
|
table::Table,
|
||||||
types::{ElementType, MemoryDesc, TableDesc, Value},
|
types::{ElementType, MemoryDescriptor, TableDescriptor, Value},
|
||||||
};
|
};
|
||||||
|
|
||||||
static EXAMPLE_WASM: &'static [u8] = include_bytes!("simple.wasm");
|
static EXAMPLE_WASM: &'static [u8] = include_bytes!("simple.wasm");
|
||||||
@ -15,7 +15,7 @@ fn main() -> Result<()> {
|
|||||||
let wasm_binary = wat2wasm(IMPORT_MODULE.as_bytes()).expect("WAST not valid or malformed");
|
let wasm_binary = wat2wasm(IMPORT_MODULE.as_bytes()).expect("WAST not valid or malformed");
|
||||||
let inner_module = wasmer_runtime_core::compile_with(&wasm_binary, &CraneliftCompiler::new())?;
|
let inner_module = wasmer_runtime_core::compile_with(&wasm_binary, &CraneliftCompiler::new())?;
|
||||||
|
|
||||||
let memory = Memory::new(MemoryDesc {
|
let memory = Memory::new(MemoryDescriptor {
|
||||||
min: 1,
|
min: 1,
|
||||||
max: Some(1),
|
max: Some(1),
|
||||||
shared: false,
|
shared: false,
|
||||||
@ -24,8 +24,8 @@ fn main() -> Result<()> {
|
|||||||
|
|
||||||
let global = Global::new(Value::I32(42));
|
let global = Global::new(Value::I32(42));
|
||||||
|
|
||||||
let table = Table::new(TableDesc {
|
let table = Table::new(TableDescriptor {
|
||||||
ty: ElementType::Anyfunc,
|
element: ElementType::Anyfunc,
|
||||||
min: 10,
|
min: 10,
|
||||||
max: None,
|
max: None,
|
||||||
})
|
})
|
||||||
|
@ -434,15 +434,15 @@ fn import_memories(
|
|||||||
.and_then(|namespace| namespace.get_export(&name));
|
.and_then(|namespace| namespace.get_export(&name));
|
||||||
match memory_import {
|
match memory_import {
|
||||||
Some(Export::Memory(mut memory)) => {
|
Some(Export::Memory(mut memory)) => {
|
||||||
if expected_memory_desc.fits_in_imported(memory.description()) {
|
if expected_memory_desc.fits_in_imported(memory.descriptor()) {
|
||||||
memories.push(memory.clone());
|
memories.push(memory.clone());
|
||||||
vm_memories.push(memory.vm_local_memory());
|
vm_memories.push(memory.vm_local_memory());
|
||||||
} else {
|
} else {
|
||||||
link_errors.push(LinkError::IncorrectMemoryDescription {
|
link_errors.push(LinkError::IncorrectMemoryDescriptor {
|
||||||
namespace: namespace.clone(),
|
namespace: namespace.clone(),
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
expected: *expected_memory_desc,
|
expected: *expected_memory_desc,
|
||||||
found: memory.description(),
|
found: memory.descriptor(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -493,15 +493,15 @@ fn import_tables(
|
|||||||
.and_then(|namespace| namespace.get_export(&name));
|
.and_then(|namespace| namespace.get_export(&name));
|
||||||
match table_import {
|
match table_import {
|
||||||
Some(Export::Table(mut table)) => {
|
Some(Export::Table(mut table)) => {
|
||||||
if expected_table_desc.fits_in_imported(table.description()) {
|
if expected_table_desc.fits_in_imported(table.descriptor()) {
|
||||||
vm_tables.push(table.vm_local_table());
|
vm_tables.push(table.vm_local_table());
|
||||||
tables.push(table);
|
tables.push(table);
|
||||||
} else {
|
} else {
|
||||||
link_errors.push(LinkError::IncorrectTableDescription {
|
link_errors.push(LinkError::IncorrectTableDescriptor {
|
||||||
namespace: namespace.clone(),
|
namespace: namespace.clone(),
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
expected: *expected_table_desc,
|
expected: *expected_table_desc,
|
||||||
found: table.description(),
|
found: table.descriptor(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -552,15 +552,15 @@ fn import_globals(
|
|||||||
.and_then(|namespace| namespace.get_export(name));
|
.and_then(|namespace| namespace.get_export(name));
|
||||||
match import {
|
match import {
|
||||||
Some(Export::Global(mut global)) => {
|
Some(Export::Global(mut global)) => {
|
||||||
if global.description() == *imported_global_desc {
|
if global.descriptor() == *imported_global_desc {
|
||||||
vm_globals.push(global.vm_local_global());
|
vm_globals.push(global.vm_local_global());
|
||||||
globals.push(global);
|
globals.push(global);
|
||||||
} else {
|
} else {
|
||||||
link_errors.push(LinkError::IncorrectGlobalDescription {
|
link_errors.push(LinkError::IncorrectGlobalDescriptor {
|
||||||
namespace: namespace.clone(),
|
namespace: namespace.clone(),
|
||||||
name: name.clone(),
|
name: name.clone(),
|
||||||
expected: *imported_global_desc,
|
expected: *imported_global_desc,
|
||||||
found: global.description(),
|
found: global.descriptor(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
use crate::types::{FuncSig, GlobalDesc, MemoryDesc, MemoryIndex, TableDesc, TableIndex, Type};
|
use crate::types::{
|
||||||
|
FuncSig, GlobalDescriptor, MemoryDescriptor, MemoryIndex, TableDescriptor, TableIndex, Type,
|
||||||
|
};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
pub type Result<T> = std::result::Result<T, Box<Error>>;
|
pub type Result<T> = std::result::Result<T, Box<Error>>;
|
||||||
@ -47,23 +49,23 @@ pub enum LinkError {
|
|||||||
namespace: String,
|
namespace: String,
|
||||||
name: String,
|
name: String,
|
||||||
},
|
},
|
||||||
IncorrectMemoryDescription {
|
IncorrectMemoryDescriptor {
|
||||||
namespace: String,
|
namespace: String,
|
||||||
name: String,
|
name: String,
|
||||||
expected: MemoryDesc,
|
expected: MemoryDescriptor,
|
||||||
found: MemoryDesc,
|
found: MemoryDescriptor,
|
||||||
},
|
},
|
||||||
IncorrectTableDescription {
|
IncorrectTableDescriptor {
|
||||||
namespace: String,
|
namespace: String,
|
||||||
name: String,
|
name: String,
|
||||||
expected: TableDesc,
|
expected: TableDescriptor,
|
||||||
found: TableDesc,
|
found: TableDescriptor,
|
||||||
},
|
},
|
||||||
IncorrectGlobalDescription {
|
IncorrectGlobalDescriptor {
|
||||||
namespace: String,
|
namespace: String,
|
||||||
name: String,
|
name: String,
|
||||||
expected: GlobalDesc,
|
expected: GlobalDescriptor,
|
||||||
found: GlobalDesc,
|
found: GlobalDescriptor,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,13 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
export::Export,
|
export::Export,
|
||||||
import::IsExport,
|
import::IsExport,
|
||||||
types::{GlobalDesc, Type, Value},
|
types::{GlobalDescriptor, Type, Value},
|
||||||
vm,
|
vm,
|
||||||
};
|
};
|
||||||
use std::{cell::RefCell, fmt, rc::Rc};
|
use std::{cell::RefCell, fmt, rc::Rc};
|
||||||
|
|
||||||
pub struct Global {
|
pub struct Global {
|
||||||
desc: GlobalDesc,
|
desc: GlobalDescriptor,
|
||||||
storage: Rc<RefCell<vm::LocalGlobal>>,
|
storage: Rc<RefCell<vm::LocalGlobal>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ impl Global {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn new_internal(value: Value, mutable: bool) -> Self {
|
fn new_internal(value: Value, mutable: bool) -> Self {
|
||||||
let desc = GlobalDesc {
|
let desc = GlobalDescriptor {
|
||||||
mutable,
|
mutable,
|
||||||
ty: value.ty(),
|
ty: value.ty(),
|
||||||
};
|
};
|
||||||
@ -41,7 +41,7 @@ impl Global {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn description(&self) -> GlobalDesc {
|
pub fn descriptor(&self) -> GlobalDescriptor {
|
||||||
self.desc
|
self.desc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
memory::{WASM_MAX_PAGES, WASM_PAGE_SIZE},
|
memory::{WASM_MAX_PAGES, WASM_PAGE_SIZE},
|
||||||
sys,
|
sys,
|
||||||
types::MemoryDesc,
|
types::MemoryDescriptor,
|
||||||
vm,
|
vm,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ pub struct DynamicMemory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl DynamicMemory {
|
impl DynamicMemory {
|
||||||
pub(super) fn new(desc: MemoryDesc, local: &mut vm::LocalMemory) -> Option<Box<Self>> {
|
pub(super) fn new(desc: MemoryDescriptor, local: &mut vm::LocalMemory) -> Option<Box<Self>> {
|
||||||
let memory = {
|
let memory = {
|
||||||
let mut memory =
|
let mut memory =
|
||||||
sys::Memory::with_size((desc.min as usize * WASM_PAGE_SIZE) + DYNAMIC_GUARD_SIZE)
|
sys::Memory::with_size((desc.min as usize * WASM_PAGE_SIZE) + DYNAMIC_GUARD_SIZE)
|
||||||
|
@ -3,7 +3,7 @@ use crate::{
|
|||||||
import::IsExport,
|
import::IsExport,
|
||||||
memory::dynamic::DYNAMIC_GUARD_SIZE,
|
memory::dynamic::DYNAMIC_GUARD_SIZE,
|
||||||
memory::static_::{SAFE_STATIC_GUARD_SIZE, SAFE_STATIC_HEAP_SIZE},
|
memory::static_::{SAFE_STATIC_GUARD_SIZE, SAFE_STATIC_HEAP_SIZE},
|
||||||
types::{MemoryDesc, ValueType},
|
types::{MemoryDescriptor, ValueType},
|
||||||
vm,
|
vm,
|
||||||
};
|
};
|
||||||
use std::{cell::RefCell, fmt, mem, ptr, rc::Rc, slice};
|
use std::{cell::RefCell, fmt, mem, ptr, rc::Rc, slice};
|
||||||
@ -18,12 +18,12 @@ pub const WASM_PAGE_SIZE: usize = 65_536;
|
|||||||
pub const WASM_MAX_PAGES: usize = 65_536;
|
pub const WASM_MAX_PAGES: usize = 65_536;
|
||||||
|
|
||||||
pub struct Memory {
|
pub struct Memory {
|
||||||
desc: MemoryDesc,
|
desc: MemoryDescriptor,
|
||||||
storage: Rc<RefCell<(MemoryStorage, Box<vm::LocalMemory>)>>,
|
storage: Rc<RefCell<(MemoryStorage, Box<vm::LocalMemory>)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Memory {
|
impl Memory {
|
||||||
pub fn new(desc: MemoryDesc) -> Option<Self> {
|
pub fn new(desc: MemoryDescriptor) -> Option<Self> {
|
||||||
let mut vm_local_memory = Box::new(vm::LocalMemory {
|
let mut vm_local_memory = Box::new(vm::LocalMemory {
|
||||||
base: ptr::null_mut(),
|
base: ptr::null_mut(),
|
||||||
bound: 0,
|
bound: 0,
|
||||||
@ -46,7 +46,7 @@ impl Memory {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn description(&self) -> MemoryDesc {
|
pub fn descriptor(&self) -> MemoryDescriptor {
|
||||||
self.desc
|
self.desc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ use crate::{
|
|||||||
WASM_MAX_PAGES, WASM_PAGE_SIZE,
|
WASM_MAX_PAGES, WASM_PAGE_SIZE,
|
||||||
},
|
},
|
||||||
sys,
|
sys,
|
||||||
types::MemoryDesc,
|
types::MemoryDescriptor,
|
||||||
vm,
|
vm,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ pub struct StaticMemory {
|
|||||||
|
|
||||||
impl StaticMemory {
|
impl StaticMemory {
|
||||||
pub(in crate::memory) fn new(
|
pub(in crate::memory) fn new(
|
||||||
desc: MemoryDesc,
|
desc: MemoryDescriptor,
|
||||||
local: &mut vm::LocalMemory,
|
local: &mut vm::LocalMemory,
|
||||||
) -> Option<Box<Self>> {
|
) -> Option<Box<Self>> {
|
||||||
let memory = {
|
let memory = {
|
||||||
|
@ -5,9 +5,10 @@ use crate::{
|
|||||||
sig_registry::SigRegistry,
|
sig_registry::SigRegistry,
|
||||||
structures::Map,
|
structures::Map,
|
||||||
types::{
|
types::{
|
||||||
FuncIndex, GlobalDesc, GlobalIndex, GlobalInit, ImportedFuncIndex, ImportedGlobalIndex,
|
FuncIndex, GlobalDescriptor, GlobalIndex, GlobalInit, ImportedFuncIndex,
|
||||||
ImportedMemoryIndex, ImportedTableIndex, Initializer, LocalGlobalIndex, LocalMemoryIndex,
|
ImportedGlobalIndex, ImportedMemoryIndex, ImportedTableIndex, Initializer,
|
||||||
LocalTableIndex, MemoryDesc, MemoryIndex, SigIndex, TableDesc, TableIndex,
|
LocalGlobalIndex, LocalMemoryIndex, LocalTableIndex, MemoryDescriptor, MemoryIndex,
|
||||||
|
SigIndex, TableDescriptor, TableIndex,
|
||||||
},
|
},
|
||||||
Instance,
|
Instance,
|
||||||
};
|
};
|
||||||
@ -21,15 +22,15 @@ pub struct ModuleInner {
|
|||||||
pub protected_caller: Box<dyn ProtectedCaller>,
|
pub protected_caller: Box<dyn ProtectedCaller>,
|
||||||
|
|
||||||
// This are strictly local and the typsystem ensures that.
|
// This are strictly local and the typsystem ensures that.
|
||||||
pub memories: Map<LocalMemoryIndex, MemoryDesc>,
|
pub memories: Map<LocalMemoryIndex, MemoryDescriptor>,
|
||||||
pub globals: Map<LocalGlobalIndex, GlobalInit>,
|
pub globals: Map<LocalGlobalIndex, GlobalInit>,
|
||||||
pub tables: Map<LocalTableIndex, TableDesc>,
|
pub tables: Map<LocalTableIndex, TableDescriptor>,
|
||||||
|
|
||||||
// These are strictly imported and the typesystem ensures that.
|
// These are strictly imported and the typesystem ensures that.
|
||||||
pub imported_functions: Map<ImportedFuncIndex, ImportName>,
|
pub imported_functions: Map<ImportedFuncIndex, ImportName>,
|
||||||
pub imported_memories: Map<ImportedMemoryIndex, (ImportName, MemoryDesc)>,
|
pub imported_memories: Map<ImportedMemoryIndex, (ImportName, MemoryDescriptor)>,
|
||||||
pub imported_tables: Map<ImportedTableIndex, (ImportName, TableDesc)>,
|
pub imported_tables: Map<ImportedTableIndex, (ImportName, TableDescriptor)>,
|
||||||
pub imported_globals: Map<ImportedGlobalIndex, (ImportName, GlobalDesc)>,
|
pub imported_globals: Map<ImportedGlobalIndex, (ImportName, GlobalDescriptor)>,
|
||||||
|
|
||||||
pub exports: HashMap<String, ExportIndex>,
|
pub exports: HashMap<String, ExportIndex>,
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ use crate::{
|
|||||||
instance::Function,
|
instance::Function,
|
||||||
sig_registry::SigRegistry,
|
sig_registry::SigRegistry,
|
||||||
structures::TypedIndex,
|
structures::TypedIndex,
|
||||||
types::{FuncSig, TableDesc},
|
types::{FuncSig, TableDescriptor},
|
||||||
vm,
|
vm,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -32,13 +32,6 @@ impl<'a> Anyfunc<'a> {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn raw(&self) -> *const vm::Func {
|
|
||||||
match self.inner {
|
|
||||||
AnyfuncInner::Host { ptr, .. } => ptr,
|
|
||||||
AnyfuncInner::Managed(ref func) => func.raw(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> From<Function<'a>> for Anyfunc<'a> {
|
impl<'a> From<Function<'a>> for Anyfunc<'a> {
|
||||||
@ -55,7 +48,7 @@ pub struct AnyfuncTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AnyfuncTable {
|
impl AnyfuncTable {
|
||||||
pub fn new(desc: TableDesc, local: &mut vm::LocalTable) -> Result<Box<Self>, ()> {
|
pub fn new(desc: TableDescriptor, local: &mut vm::LocalTable) -> Result<Box<Self>, ()> {
|
||||||
let initial_table_backing_len = match desc.max {
|
let initial_table_backing_len = match desc.max {
|
||||||
Some(max) => max,
|
Some(max) => max,
|
||||||
None => desc.min,
|
None => desc.min,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
export::Export,
|
export::Export,
|
||||||
import::IsExport,
|
import::IsExport,
|
||||||
types::{ElementType, TableDesc},
|
types::{ElementType, TableDescriptor},
|
||||||
vm,
|
vm,
|
||||||
};
|
};
|
||||||
use std::{cell::RefCell, fmt, ptr, rc::Rc};
|
use std::{cell::RefCell, fmt, ptr, rc::Rc};
|
||||||
@ -22,19 +22,19 @@ pub enum TableStorage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub struct Table {
|
pub struct Table {
|
||||||
desc: TableDesc,
|
desc: TableDescriptor,
|
||||||
storage: Rc<RefCell<(TableStorage, vm::LocalTable)>>,
|
storage: Rc<RefCell<(TableStorage, vm::LocalTable)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Table {
|
impl Table {
|
||||||
pub fn new(desc: TableDesc) -> Result<Self, ()> {
|
pub fn new(desc: TableDescriptor) -> Result<Self, ()> {
|
||||||
let mut local = vm::LocalTable {
|
let mut local = vm::LocalTable {
|
||||||
base: ptr::null_mut(),
|
base: ptr::null_mut(),
|
||||||
count: 0,
|
count: 0,
|
||||||
table: ptr::null_mut(),
|
table: ptr::null_mut(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let storage = match desc.ty {
|
let storage = match desc.element {
|
||||||
ElementType::Anyfunc => TableStorage::Anyfunc(AnyfuncTable::new(desc, &mut local)?),
|
ElementType::Anyfunc => TableStorage::Anyfunc(AnyfuncTable::new(desc, &mut local)?),
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ impl Table {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn description(&self) -> TableDesc {
|
pub fn descriptor(&self) -> TableDescriptor {
|
||||||
self.desc
|
self.desc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,21 +128,21 @@ pub enum ElementType {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy)]
|
#[derive(Debug, Clone, Copy)]
|
||||||
pub struct TableDesc {
|
pub struct TableDescriptor {
|
||||||
/// Type of data stored in this table.
|
/// Type of data stored in this table.
|
||||||
pub ty: ElementType,
|
pub element: ElementType,
|
||||||
/// The minimum number of elements that must be stored in this table.
|
/// The minimum number of elements that must be stored in this table.
|
||||||
pub min: u32,
|
pub min: u32,
|
||||||
/// The maximum number of elements in this table.
|
/// The maximum number of elements in this table.
|
||||||
pub max: Option<u32>,
|
pub max: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TableDesc {
|
impl TableDescriptor {
|
||||||
pub(crate) fn fits_in_imported(&self, imported: TableDesc) -> bool {
|
pub(crate) fn fits_in_imported(&self, imported: TableDescriptor) -> bool {
|
||||||
// TODO: We should define implementation limits.
|
// TODO: We should define implementation limits.
|
||||||
let imported_max = imported.max.unwrap_or(u32::max_value());
|
let imported_max = imported.max.unwrap_or(u32::max_value());
|
||||||
let self_max = self.max.unwrap_or(u32::max_value());
|
let self_max = self.max.unwrap_or(u32::max_value());
|
||||||
self.ty == imported.ty && imported_max <= self_max && self.min <= imported.min
|
self.element == imported.element && imported_max <= self_max && self.min <= imported.min
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ pub enum Initializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct GlobalDesc {
|
pub struct GlobalDescriptor {
|
||||||
pub mutable: bool,
|
pub mutable: bool,
|
||||||
pub ty: Type,
|
pub ty: Type,
|
||||||
}
|
}
|
||||||
@ -166,13 +166,13 @@ pub struct GlobalDesc {
|
|||||||
/// A wasm global.
|
/// A wasm global.
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct GlobalInit {
|
pub struct GlobalInit {
|
||||||
pub desc: GlobalDesc,
|
pub desc: GlobalDescriptor,
|
||||||
pub init: Initializer,
|
pub init: Initializer,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A wasm memory.
|
/// A wasm memory.
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub struct MemoryDesc {
|
pub struct MemoryDescriptor {
|
||||||
/// The minimum number of allowed pages.
|
/// The minimum number of allowed pages.
|
||||||
pub min: u32,
|
pub min: u32,
|
||||||
/// The maximum number of allowed pages.
|
/// The maximum number of allowed pages.
|
||||||
@ -181,7 +181,7 @@ pub struct MemoryDesc {
|
|||||||
pub shared: bool,
|
pub shared: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MemoryDesc {
|
impl MemoryDescriptor {
|
||||||
pub fn memory_type(self) -> MemoryType {
|
pub fn memory_type(self) -> MemoryType {
|
||||||
match (self.max.is_some(), self.shared) {
|
match (self.max.is_some(), self.shared) {
|
||||||
(true, true) => MemoryType::SharedStatic,
|
(true, true) => MemoryType::SharedStatic,
|
||||||
@ -191,7 +191,7 @@ impl MemoryDesc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn fits_in_imported(&self, imported: MemoryDesc) -> bool {
|
pub(crate) fn fits_in_imported(&self, imported: MemoryDescriptor) -> bool {
|
||||||
let imported_max = imported.max.unwrap_or(65_536);
|
let imported_max = imported.max.unwrap_or(65_536);
|
||||||
let self_max = self.max.unwrap_or(65_536);
|
let self_max = self.max.unwrap_or(65_536);
|
||||||
|
|
||||||
|
@ -110,7 +110,7 @@ impl Ctx {
|
|||||||
/// fn read_memory(ctx: &Ctx) -> u8 {
|
/// fn read_memory(ctx: &Ctx) -> u8 {
|
||||||
/// let first_memory = ctx.memory(0);
|
/// let first_memory = ctx.memory(0);
|
||||||
/// // Read the first byte of that linear memory.
|
/// // Read the first byte of that linear memory.
|
||||||
/// first_memory.get(0)
|
/// first_memory.read(0).unwrap()
|
||||||
/// }
|
/// }
|
||||||
/// ```
|
/// ```
|
||||||
pub fn memory<'a>(&'a self, mem_index: u32) -> &'a Memory {
|
pub fn memory<'a>(&'a self, mem_index: u32) -> &'a Memory {
|
||||||
|
@ -92,7 +92,7 @@ pub mod wasm {
|
|||||||
pub use wasmer_runtime_core::instance::Function;
|
pub use wasmer_runtime_core::instance::Function;
|
||||||
pub use wasmer_runtime_core::memory::Memory;
|
pub use wasmer_runtime_core::memory::Memory;
|
||||||
pub use wasmer_runtime_core::table::Table;
|
pub use wasmer_runtime_core::table::Table;
|
||||||
pub use wasmer_runtime_core::types::{FuncSig, MemoryDesc, TableDesc, Type, Value};
|
pub use wasmer_runtime_core::types::{FuncSig, MemoryDescriptor, TableDescriptor, Type, Value};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Compile WebAssembly binary code into a [`Module`].
|
/// Compile WebAssembly binary code into a [`Module`].
|
||||||
|
Loading…
x
Reference in New Issue
Block a user