mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-12 14:55:32 +00:00
delete excess options
This commit is contained in:
parent
28fd4b4ad2
commit
5e8505c3e7
@ -46,13 +46,13 @@ impl FCE {
|
||||
let module_abi = module.acquire_abi();
|
||||
|
||||
// TODO: introduce a macro for such things
|
||||
let allocate = module_abi.allocate.unwrap();
|
||||
let allocate = module_abi.allocate;
|
||||
namespace.insert(
|
||||
config.allocate_fn_name.clone(),
|
||||
func!(move |size: i32| -> i32 { allocate.call(size).expect("allocate failed") }),
|
||||
);
|
||||
|
||||
let invoke = module_abi.invoke.unwrap();
|
||||
let invoke = module_abi.invoke;
|
||||
namespace.insert(
|
||||
config.invoke_fn_name.clone(),
|
||||
func!(move |offset: i32, size: i32| -> i32 {
|
||||
@ -60,7 +60,7 @@ impl FCE {
|
||||
}),
|
||||
);
|
||||
|
||||
let deallocate = module_abi.deallocate.unwrap();
|
||||
let deallocate = module_abi.deallocate;
|
||||
namespace.insert(
|
||||
config.deallocate_fn_name.clone(),
|
||||
func!(move |ptr: i32, size: i32| {
|
||||
@ -68,7 +68,7 @@ impl FCE {
|
||||
}),
|
||||
);
|
||||
|
||||
let store = module_abi.store.unwrap();
|
||||
let store = module_abi.store;
|
||||
namespace.insert(
|
||||
config.store_fn_name.clone(),
|
||||
func!(move |offset: i32, value: i32| {
|
||||
@ -76,7 +76,7 @@ impl FCE {
|
||||
}),
|
||||
);
|
||||
|
||||
let load = module_abi.load.unwrap();
|
||||
let load = module_abi.load;
|
||||
namespace.insert(
|
||||
config.load_fn_name.clone(),
|
||||
func!(move |offset: i32| -> i32 { load.call(offset).expect("load failed") }),
|
||||
@ -139,7 +139,7 @@ impl FCEService for FCE {
|
||||
|
||||
Entry::Occupied(module) => {
|
||||
if module.get().get_abi_ref_counter() != 0 {
|
||||
return Err(FCEError::ModuleInUse)
|
||||
return Err(FCEError::ModuleInUse);
|
||||
}
|
||||
module.remove_entry();
|
||||
Ok(())
|
||||
|
@ -30,17 +30,17 @@ use crate::vm::errors::FCEError;
|
||||
/// 5. deallocate(res, strlen(sql)) to clean memory.
|
||||
pub(crate) trait ModuleABI {
|
||||
/// Allocates a region of memory inside a module. Used for passing argument inside the module.
|
||||
fn allocate(&self, size: i32) -> Result<i32, FCEError>;
|
||||
fn allocate(&mut self, size: i32) -> Result<i32, FCEError>;
|
||||
|
||||
/// Deallocates previously allocated memory region.
|
||||
fn deallocate(&self, ptr: i32, size: i32) -> Result<(), FCEError>;
|
||||
fn deallocate(&mut self, ptr: i32, size: i32) -> Result<(), FCEError>;
|
||||
|
||||
/// Calls the main entry point of a module called invoke.
|
||||
fn invoke(&self, arg_address: i32, arg_size: i32) -> Result<i32, FCEError>;
|
||||
fn invoke(&mut self, arg_address: i32, arg_size: i32) -> Result<i32, FCEError>;
|
||||
|
||||
/// Stores one byte on given address.
|
||||
fn store(&self, address: i32, value: i32) -> Result<(), FCEError>;
|
||||
fn store(&mut self, address: i32, value: i32) -> Result<(), FCEError>;
|
||||
|
||||
/// Loads one byte from given address.
|
||||
fn load(&self, address: i32) -> Result<i32, FCEError>;
|
||||
fn load(&mut self, address: i32) -> Result<i32, FCEError>;
|
||||
}
|
||||
|
@ -34,11 +34,11 @@ pub(crate) struct ABI {
|
||||
// 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
|
||||
// invoking FCE::new has been succeed.
|
||||
pub(crate) allocate: Option<Func<'static, i32, i32>>,
|
||||
pub(crate) deallocate: Option<Func<'static, (i32, i32), ()>>,
|
||||
pub(crate) invoke: Option<Func<'static, (i32, i32), i32>>,
|
||||
pub(crate) store: Option<Func<'static, (i32, i32)>>,
|
||||
pub(crate) load: Option<Func<'static, i32, i32>>,
|
||||
pub(crate) allocate: Func<'static, i32, i32>,
|
||||
pub(crate) deallocate: Func<'static, (i32, i32), ()>,
|
||||
pub(crate) invoke: Func<'static, (i32, i32), i32>,
|
||||
pub(crate) store: Func<'static, (i32, i32)>,
|
||||
pub(crate) load: Func<'static, i32, i32>,
|
||||
}
|
||||
|
||||
/// A building block of multi-modules scheme of FCE, represents one module that corresponds
|
||||
@ -106,11 +106,11 @@ impl FCEModule {
|
||||
);
|
||||
|
||||
Ok(ABI {
|
||||
allocate: Some(allocate),
|
||||
deallocate: Some(deallocate),
|
||||
invoke: Some(invoke),
|
||||
store: Some(store),
|
||||
load: Some(load),
|
||||
allocate,
|
||||
deallocate,
|
||||
invoke,
|
||||
store,
|
||||
load,
|
||||
})
|
||||
}
|
||||
}
|
||||
@ -219,25 +219,24 @@ impl ModuleAPI for FCEModule {
|
||||
}
|
||||
}
|
||||
|
||||
#[rustfmt::skip]
|
||||
impl ModuleABI for FCEModule {
|
||||
fn allocate(&self, size: i32) -> Result<i32, FCEError> {
|
||||
Ok(self.abi.allocate.as_ref().unwrap().call(size)?)
|
||||
fn allocate(&mut self, size: i32) -> Result<i32, FCEError> {
|
||||
Ok(self.abi.allocate.call(size)?)
|
||||
}
|
||||
|
||||
fn deallocate(&self, ptr: i32, size: i32) -> Result<(), FCEError> {
|
||||
Ok(self.abi.deallocate.as_ref().unwrap().call(ptr, size)?)
|
||||
fn deallocate(&mut self, ptr: i32, size: i32) -> Result<(), FCEError> {
|
||||
Ok(self.abi.deallocate.call(ptr, size)?)
|
||||
}
|
||||
|
||||
fn invoke(&self, arg_address: i32, arg_size: i32) -> Result<i32, FCEError> {
|
||||
Ok(self.abi.invoke.as_ref().unwrap().call(arg_address, arg_size)?)
|
||||
fn invoke(&mut self, arg_address: i32, arg_size: i32) -> Result<i32, FCEError> {
|
||||
Ok(self.abi.invoke.call(arg_address, arg_size)?)
|
||||
}
|
||||
|
||||
fn store(&self, address: i32, value: i32) -> Result<(), FCEError> {
|
||||
Ok(self.abi.store.as_ref().unwrap().call(address, value)?)
|
||||
fn store(&mut self, address: i32, value: i32) -> Result<(), FCEError> {
|
||||
Ok(self.abi.store.call(address, value)?)
|
||||
}
|
||||
|
||||
fn load(&self, address: i32) -> Result<i32, FCEError> {
|
||||
Ok(self.abi.load.as_ref().unwrap().call(address)?)
|
||||
fn load(&mut self, address: i32) -> Result<i32, FCEError> {
|
||||
Ok(self.abi.load.call(address)?)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user