mirror of
https://github.com/fluencelabs/marine.git
synced 2024-12-12 14:55:32 +00:00
code cleaning
This commit is contained in:
parent
6e2f17e07f
commit
ddb5c9881a
@ -7,3 +7,11 @@ members = [
|
|||||||
"wit_fce/examples/ipfs_node",
|
"wit_fce/examples/ipfs_node",
|
||||||
"wit_fce/examples/ipfs_rpc",
|
"wit_fce/examples/ipfs_rpc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
opt-level = 3
|
||||||
|
debug = false
|
||||||
|
lto = true
|
||||||
|
debug-assertions = false
|
||||||
|
overflow-checks = false
|
||||||
|
panic = "abort"
|
||||||
|
@ -7,7 +7,6 @@ edition = "2018"
|
|||||||
license = "Apache-2.0"
|
license = "Apache-2.0"
|
||||||
keywords = ["fluence", "webassembly", "wasmer", "execution environment"]
|
keywords = ["fluence", "webassembly", "wasmer", "execution environment"]
|
||||||
categories = ["webassembly"]
|
categories = ["webassembly"]
|
||||||
maintenance = { status = "actively-developed" }
|
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
name = "fce"
|
name = "fce"
|
||||||
@ -35,11 +34,3 @@ pwasm-utils = "0.12.0"
|
|||||||
reqwest = "0.10.4"
|
reqwest = "0.10.4"
|
||||||
bytes = "0.5.4"
|
bytes = "0.5.4"
|
||||||
tokio = { version = "0.2.20", features = ["blocking", "macros"] }
|
tokio = { version = "0.2.20", features = ["blocking", "macros"] }
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
#opt-level = 3
|
|
||||||
#debug = false
|
|
||||||
#lto = true
|
|
||||||
#debug-assertions = false
|
|
||||||
#overflow-checks = false
|
|
||||||
#panic = "abort"
|
|
||||||
|
@ -12,11 +12,3 @@ either = "1.5.3"
|
|||||||
clap = "2.33.1"
|
clap = "2.33.1"
|
||||||
exitfailure = "0.5.1"
|
exitfailure = "0.5.1"
|
||||||
failure = "0.1.5"
|
failure = "0.1.5"
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
opt-level = 3
|
|
||||||
debug = false
|
|
||||||
lto = true
|
|
||||||
debug-assertions = false
|
|
||||||
overflow-checks = false
|
|
||||||
panic = "abort"
|
|
||||||
|
@ -9,11 +9,3 @@ wasmer-runtime = "0.17.0"
|
|||||||
wasmer-runtime-core = { version = "0.17.0", features = ["dynamicfunc-fat-closures"] }
|
wasmer-runtime-core = { version = "0.17.0", features = ["dynamicfunc-fat-closures"] }
|
||||||
wasmer-interface-types = { git = "http://github.com/fluencelabs/interface-types" }
|
wasmer-interface-types = { git = "http://github.com/fluencelabs/interface-types" }
|
||||||
multimap = "0.8.1"
|
multimap = "0.8.1"
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
opt-level = 3
|
|
||||||
debug = false
|
|
||||||
lto = true
|
|
||||||
debug-assertions = false
|
|
||||||
overflow-checks = false
|
|
||||||
panic = "abort"
|
|
||||||
|
@ -127,25 +127,23 @@ impl wasm::structures::LocalImport for WITFunction {
|
|||||||
use super::{ival_to_wval, wval_to_ival};
|
use super::{ival_to_wval, wval_to_ival};
|
||||||
|
|
||||||
match &self.inner {
|
match &self.inner {
|
||||||
WITFunctionInner::Export { func, .. } => {
|
WITFunctionInner::Export { func, .. } => func
|
||||||
func.as_ref()
|
.as_ref()
|
||||||
.call(&arguments.iter().map(ival_to_wval).collect::<Vec<Value>>())
|
.call(&arguments.iter().map(ival_to_wval).collect::<Vec<Value>>())
|
||||||
.map(|results| results.iter().map(wval_to_ival).collect())
|
.map(|results| results.iter().map(wval_to_ival).collect())
|
||||||
.map_err(|_| ())
|
.map_err(|_| ()),
|
||||||
}
|
|
||||||
WITFunctionInner::Import {
|
WITFunctionInner::Import {
|
||||||
wit_module,
|
wit_module,
|
||||||
func_name,
|
func_name,
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
let mut tt = wit_module.clone();
|
let mut wit_module_caller = wit_module.clone();
|
||||||
unsafe {
|
unsafe {
|
||||||
let result = Arc::get_mut_unchecked(&mut tt)
|
// get_mut_unchecked here is safe because it is single-threaded environment
|
||||||
|
// without cyclic reference between modules
|
||||||
|
Arc::get_mut_unchecked(&mut wit_module_caller)
|
||||||
.call(func_name, arguments)
|
.call(func_name, arguments)
|
||||||
.map_err(|_| ());
|
.map_err(|_| ())
|
||||||
|
|
||||||
// println!("result is {:?}", result);
|
|
||||||
result
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,6 +57,7 @@ impl WITInstance {
|
|||||||
Ok(Self { funcs, memories })
|
Ok(Self { funcs, memories })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[allow(unused)]
|
||||||
pub fn get_func_signature(
|
pub fn get_func_signature(
|
||||||
&self,
|
&self,
|
||||||
func_idx: usize,
|
func_idx: usize,
|
||||||
@ -88,9 +89,7 @@ impl WITInstance {
|
|||||||
// here it is safe because dyn func is never lives WITInstance
|
// here it is safe because dyn func is never lives WITInstance
|
||||||
let export_func =
|
let export_func =
|
||||||
std::mem::transmute::<DynFunc<'_>, DynFunc<'static>>(export_func);
|
std::mem::transmute::<DynFunc<'_>, DynFunc<'static>>(export_func);
|
||||||
let tt = WITFunction::from_export(export_func)?;
|
Ok((export_id, WITFunction::from_export(export_func)?))
|
||||||
println!("{}, {} - {:?}", export_id, export.name, tt.inputs());
|
|
||||||
Ok((export_id, tt))
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
@ -112,19 +111,13 @@ impl WITInstance {
|
|||||||
let mut non_wit_callable_imports = HashMap::new();
|
let mut non_wit_callable_imports = HashMap::new();
|
||||||
|
|
||||||
for import in interfaces.imports.iter() {
|
for import in interfaces.imports.iter() {
|
||||||
if let Some(_) = core_to_adapter.get(&import.function_type) {
|
if core_to_adapter.get(&import.function_type).is_some() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
match modules.get(import.namespace) {
|
match modules.get(import.namespace) {
|
||||||
Some(module) => {
|
Some(module) => {
|
||||||
let func = WITFunction::from_import(module.clone(), import.name.to_string())?;
|
let func = WITFunction::from_import(module.clone(), import.name.to_string())?;
|
||||||
println!(
|
|
||||||
"{}, {} - {:?}",
|
|
||||||
start_index + non_wit_callable_imports.len(),
|
|
||||||
import.name,
|
|
||||||
func.inputs()
|
|
||||||
);
|
|
||||||
non_wit_callable_imports
|
non_wit_callable_imports
|
||||||
.insert(start_index + non_wit_callable_imports.len() as usize, func);
|
.insert(start_index + non_wit_callable_imports.len() as usize, func);
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,7 @@ type WITInterpreter =
|
|||||||
Interpreter<WITInstance, WITExport, WITFunction, WITMemory, WITMemoryView<'static>>;
|
Interpreter<WITInstance, WITExport, WITFunction, WITMemory, WITMemoryView<'static>>;
|
||||||
|
|
||||||
pub struct WITModule {
|
pub struct WITModule {
|
||||||
|
#[allow(unused)]
|
||||||
instance: WasmerInstance,
|
instance: WasmerInstance,
|
||||||
wit_instance: Arc<WITInstance>,
|
wit_instance: Arc<WITInstance>,
|
||||||
funcs: HashMap<String, (WITInterpreter, Vec<InterfaceType>, Vec<InterfaceType>)>,
|
funcs: HashMap<String, (WITInterpreter, Vec<InterfaceType>, Vec<InterfaceType>)>,
|
||||||
@ -77,6 +78,8 @@ impl WITModule {
|
|||||||
let wasmer_instance = wasmer_instance.instantiate(&import_object)?;
|
let wasmer_instance = wasmer_instance.instantiate(&import_object)?;
|
||||||
|
|
||||||
let wit_instance = unsafe {
|
let wit_instance = unsafe {
|
||||||
|
// get_mut_unchecked here is safe because currently only this modules have reference to
|
||||||
|
// it and the environment is single-threaded
|
||||||
*Arc::get_mut_unchecked(&mut wit_instance) =
|
*Arc::get_mut_unchecked(&mut wit_instance) =
|
||||||
MaybeUninit::new(WITInstance::new(&wasmer_instance, &interfaces, modules)?);
|
MaybeUninit::new(WITInstance::new(&wasmer_instance, &interfaces, modules)?);
|
||||||
std::mem::transmute::<_, Arc<WITInstance>>(wit_instance)
|
std::mem::transmute::<_, Arc<WITInstance>>(wit_instance)
|
||||||
@ -96,17 +99,17 @@ impl WITModule {
|
|||||||
) -> Result<Vec<InterfaceValue>, WITFCEError> {
|
) -> Result<Vec<InterfaceValue>, WITFCEError> {
|
||||||
match self.funcs.get(function_name) {
|
match self.funcs.get(function_name) {
|
||||||
Some(func) => {
|
Some(func) => {
|
||||||
let tt = Arc::make_mut(&mut self.wit_instance);
|
let result = func
|
||||||
|
.0
|
||||||
let result = func.0.run(args, tt)?.as_slice().to_owned();
|
.run(args, Arc::make_mut(&mut self.wit_instance))?
|
||||||
|
.as_slice()
|
||||||
|
.to_owned();
|
||||||
Ok(result)
|
Ok(result)
|
||||||
}
|
}
|
||||||
None => {
|
None => Err(WITFCEError::NoSuchFunction(format!(
|
||||||
Err(WITFCEError::NoSuchFunction(format!(
|
|
||||||
"{} hasn't been found while calling",
|
"{} hasn't been found while calling",
|
||||||
function_name
|
function_name
|
||||||
)))
|
))),
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +198,7 @@ impl WITModule {
|
|||||||
use crate::instance::{itype_to_wtype, wval_to_ival};
|
use crate::instance::{itype_to_wtype, wval_to_ival};
|
||||||
use wasmer_interface_types::ast::Type as IType;
|
use wasmer_interface_types::ast::Type as IType;
|
||||||
use wasmer_runtime_core::typed_func::DynamicFunc;
|
use wasmer_runtime_core::typed_func::DynamicFunc;
|
||||||
use wasmer_runtime_core::types::{FuncSig, Type as WType, Value};
|
use wasmer_runtime_core::types::{FuncSig, Value};
|
||||||
use wasmer_runtime_core::vm::Ctx;
|
use wasmer_runtime_core::vm::Ctx;
|
||||||
|
|
||||||
// returns function that will be called from imports of Wasmer module
|
// returns function that will be called from imports of Wasmer module
|
||||||
|
@ -57,7 +57,7 @@ fn main() {
|
|||||||
.expect("module successfully created");
|
.expect("module successfully created");
|
||||||
|
|
||||||
let result1 = ipfs_rpc
|
let result1 = ipfs_rpc
|
||||||
.call("invoke", &[InterfaceValue::String("aaaaaa".to_string())])
|
.call("invoke", &[InterfaceValue::String("0xffffff".to_string())])
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
println!("stack state {:?}", result1);
|
println!("stack state {:?}", result1);
|
||||||
|
Loading…
Reference in New Issue
Block a user