[wasmtime-api] Implementation of classes for run-{reflect,start,global,memory}-c (#295)

Implements apis for reflect-c, start-c, run-global-c and run-memory-c
This commit is contained in:
Yury Delendik
2019-08-26 10:07:02 -05:00
committed by GitHub
parent 45fd9dadd8
commit c94c383a7c
9 changed files with 1324 additions and 431 deletions

View File

@@ -2,18 +2,40 @@
mod code_memory;
mod create_handle;
mod func;
mod global;
mod memory;
use failure::Error;
use std::cell::RefCell;
use std::rc::Rc;
use self::create_handle::create_handle;
use super::externals::Func;
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};
pub use self::global::GlobalState;
pub fn generate_func_export(f: &Rc<RefCell<Func>>) -> Result<(), Error> {
let mut instance = create_handle(f)?;
let mut instance = create_handle_with_function(f)?;
let export = instance.lookup("trampoline").expect("trampoline export");
f.borrow_mut().anchor = Some((instance, export));
Ok(())
}
pub fn generate_global_export(
gt: &GlobalType,
val: Val,
) -> Result<(wasmtime_runtime::Export, GlobalState), Error> {
create_global(gt, val)
}
pub fn generate_memory_export(
m: &MemoryType,
) -> Result<(wasmtime_runtime::InstanceHandle, wasmtime_runtime::Export), Error> {
let mut instance = create_handle_with_memory(m)?;
let export = instance.lookup("memory").expect("memory export");
Ok((instance, export))
}