Improve Tunables memory/table creation

This commit is contained in:
Syrus
2020-05-03 19:37:11 -07:00
parent d23a0fb76b
commit f94e2d6bcc
3 changed files with 11 additions and 8 deletions

View File

@@ -231,7 +231,9 @@ fn set_table_item(
impl Table { impl Table {
pub fn new(store: &Store, ty: TableType, init: Val) -> Result<Table, RuntimeError> { pub fn new(store: &Store, ty: TableType, init: Val) -> Result<Table, RuntimeError> {
let item = init.into_checked_anyfunc(store)?; let item = init.into_checked_anyfunc(store)?;
let table = store.engine().tunables().create_table(ty); let tunables = store.engine().tunables();
let table_plan = tunables.table_plan(ty);
let table = tunables.create_table(table_plan);
let definition = table.vmtable(); let definition = table.vmtable();
for i in 0..definition.current_elements { for i in 0..definition.current_elements {
@@ -345,7 +347,10 @@ pub struct Memory {
impl Memory { impl Memory {
pub fn new(store: &Store, ty: MemoryType) -> Memory { pub fn new(store: &Store, ty: MemoryType) -> Memory {
let memory = store.engine().tunables().create_memory(ty).unwrap(); let tunables = store.engine().tunables();
let memory_plan = tunables.memory_plan(ty);
let memory = tunables.create_memory(memory_plan).unwrap();
let definition = memory.vmmemory(); let definition = memory.vmmemory();
Memory { Memory {

View File

@@ -92,14 +92,12 @@ impl wasmer_jit::Tunables for Tunables {
} }
/// Create a memory given a memory type /// Create a memory given a memory type
fn create_memory(&self, memory_type: MemoryType) -> Result<LinearMemory, String> { fn create_memory(&self, plan: MemoryPlan) -> Result<LinearMemory, String> {
let plan = self.memory_plan(memory_type);
LinearMemory::new(&plan) LinearMemory::new(&plan)
} }
/// Create a memory given a memory type /// Create a memory given a memory type
fn create_table(&self, table_type: TableType) -> Table { fn create_table(&self, plan: TablePlan) -> Table {
let plan = self.table_plan(table_type);
Table::new(&plan) Table::new(&plan)
} }
} }

View File

@@ -11,8 +11,8 @@ pub trait Tunables {
fn table_plan(&self, table: TableType) -> TablePlan; fn table_plan(&self, table: TableType) -> TablePlan;
/// Create a memory given a memory type /// Create a memory given a memory type
fn create_memory(&self, memory_type: MemoryType) -> Result<LinearMemory, String>; fn create_memory(&self, memory_type: MemoryPlan) -> Result<LinearMemory, String>;
/// Create a memory given a memory type /// Create a memory given a memory type
fn create_table(&self, table_type: TableType) -> Table; fn create_table(&self, table_type: TablePlan) -> Table;
} }