mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-12 14:55:32 +00:00
add more comments
This commit is contained in:
parent
d94a20f0ed
commit
a18d35580c
@ -26,25 +26,25 @@ use wasmer_runtime_core::import::ImportObject;
|
|||||||
use wasmer_runtime_core::memory::ptr::{Array, WasmPtr};
|
use wasmer_runtime_core::memory::ptr::{Array, WasmPtr};
|
||||||
use wasmer_wasi::generate_import_object_for_version;
|
use wasmer_wasi::generate_import_object_for_version;
|
||||||
|
|
||||||
/// Desribes Application Binary Interface of a module.
|
/// Describes Application Binary Interface of a module.
|
||||||
/// For more details see comment in abi.rs.
|
/// For more details see comment in abi.rs.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub(crate) struct ABI<'a> {
|
pub(crate) struct ABI {
|
||||||
// It is safe to use unwrap() while calling these functions because Option is used here
|
// It is safe to use unwrap() while calling these functions because Option is used here
|
||||||
// just to allow partially initialization. And all Option fields will contain Some if
|
// just to allow partially initialization. And all Option fields will contain Some if
|
||||||
// invoking FCE::new has been succeed.
|
// invoking FCE::new has been succeed.
|
||||||
pub(crate) allocate: Option<Func<'a, i32, i32>>,
|
pub(crate) allocate: Option<Func<'static, i32, i32>>,
|
||||||
pub(crate) deallocate: Option<Func<'a, (i32, i32), ()>>,
|
pub(crate) deallocate: Option<Func<'static, (i32, i32), ()>>,
|
||||||
pub(crate) invoke: Option<Func<'a, (i32, i32), i32>>,
|
pub(crate) invoke: Option<Func<'static, (i32, i32), i32>>,
|
||||||
pub(crate) store: Option<Func<'a, (i32, i32)>>,
|
pub(crate) store: Option<Func<'static, (i32, i32)>>,
|
||||||
pub(crate) load: Option<Func<'a, i32, i32>>,
|
pub(crate) load: Option<Func<'static, i32, i32>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A building block of multi-modules scheme of FCE, represents one module that corresponds
|
/// A building block of multi-modules scheme of FCE, represents one module that corresponds
|
||||||
/// to a one Wasm file.
|
/// to a one Wasm file.
|
||||||
pub(crate) struct FCEModule {
|
pub(crate) struct FCEModule {
|
||||||
instance: Instance,
|
instance: Instance,
|
||||||
abi: ABI<'static>,
|
abi: ABI,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FCEModule {
|
impl FCEModule {
|
||||||
@ -75,7 +75,8 @@ impl FCEModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
fn create_abi(instance: &Instance, config: &Config) -> Result<ABI<'static>, FCEError> {
|
/// Extracts ABI from a module.
|
||||||
|
fn create_abi(instance: &Instance, config: &Config) -> Result<ABI, FCEError> {
|
||||||
unsafe {
|
unsafe {
|
||||||
let allocate = std::mem::transmute::<Func<'_, i32, i32>, Func<'static, i32, i32>>(
|
let allocate = std::mem::transmute::<Func<'_, i32, i32>, Func<'static, i32, i32>>(
|
||||||
instance.exports.get(&config.allocate_fn_name)?
|
instance.exports.get(&config.allocate_fn_name)?
|
||||||
@ -107,7 +108,10 @@ impl FCEModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_abi(&self) -> &ABI<'static> {
|
/// Returns ABI of a module.
|
||||||
|
/// (!) Be carefull and delete all instances of ABI before dropping corresponding module.
|
||||||
|
/// There is no any internal ref counter due to the internals of Wasmer.
|
||||||
|
pub fn get_abi(&self) -> &ABI {
|
||||||
&self.abi
|
&self.abi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -193,6 +197,7 @@ impl ModuleAPI for FCEModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[rustfmt::skip]
|
||||||
impl ModuleABI for FCEModule {
|
impl ModuleABI for FCEModule {
|
||||||
fn allocate(&self, size: i32) -> Result<i32, FCEError> {
|
fn allocate(&self, size: i32) -> Result<i32, FCEError> {
|
||||||
Ok(self.abi.allocate.as_ref().unwrap().call(size)?)
|
Ok(self.abi.allocate.as_ref().unwrap().call(size)?)
|
||||||
@ -203,12 +208,7 @@ impl ModuleABI for FCEModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn invoke(&self, arg_address: i32, arg_size: i32) -> Result<i32, FCEError> {
|
fn invoke(&self, arg_address: i32, arg_size: i32) -> Result<i32, FCEError> {
|
||||||
Ok(self
|
Ok(self.abi.invoke.as_ref().unwrap().call(arg_address, arg_size)?)
|
||||||
.abi
|
|
||||||
.invoke
|
|
||||||
.as_ref()
|
|
||||||
.unwrap()
|
|
||||||
.call(arg_address, arg_size)?)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn store(&self, address: i32, value: i32) -> Result<(), FCEError> {
|
fn store(&self, address: i32, value: i32) -> Result<(), FCEError> {
|
||||||
|
Loading…
Reference in New Issue
Block a user