Table operation; refactor Callable

This commit is contained in:
Yury Delendik
2019-08-27 11:44:02 -05:00
committed by Dan Gohman
parent e60bf7f7e8
commit de1c0f63eb
17 changed files with 641 additions and 114 deletions

View File

@@ -5,6 +5,7 @@ mod create_handle;
mod func;
mod global;
mod memory;
mod table;
use failure::Error;
use std::cell::RefCell;
@@ -13,16 +14,19 @@ use std::rc::Rc;
use self::func::create_handle_with_function;
use self::global::create_global;
use self::memory::create_handle_with_memory;
use super::{Func, GlobalType, MemoryType, Val};
use self::table::create_handle_with_table;
use super::{Callable, FuncType, GlobalType, MemoryType, Store, TableType, Val};
pub use self::global::GlobalState;
pub fn generate_func_export(f: &Rc<RefCell<Func>>) -> Result<(), Error> {
let mut instance = create_handle_with_function(f)?;
pub fn generate_func_export(
ft: &FuncType,
func: &Rc<dyn Callable + 'static>,
store: &Rc<RefCell<Store>>,
) -> Result<(wasmtime_runtime::InstanceHandle, wasmtime_runtime::Export), Error> {
let mut instance = create_handle_with_function(ft, func, store)?;
let export = instance.lookup("trampoline").expect("trampoline export");
f.borrow_mut().anchor = Some((instance, export));
Ok(())
Ok((instance, export))
}
pub fn generate_global_export(
@@ -39,3 +43,11 @@ pub fn generate_memory_export(
let export = instance.lookup("memory").expect("memory export");
Ok((instance, export))
}
pub fn generate_table_export(
t: &TableType,
) -> Result<(wasmtime_runtime::InstanceHandle, wasmtime_runtime::Export), Error> {
let mut instance = create_handle_with_table(t)?;
let export = instance.lookup("table").expect("table export");
Ok((instance, export))
}