message: Add experimental invoke support to WASI in wasmer cli
diff: @@ -230,6 +230,23 @@ struct Run {
  args: Vec<String>,
  }
  +impl Run {
  + /// Used with the `invoke` argument
  + fn parse_args(&self) -> Result<Vec<Value>, String> {
  + let mut args: Vec<Value> = Vec::new();
  + for arg in self.args.iter() {
  + let x = arg.as_str().parse().map_err(|_| {
  + format!(
  + "Can't parse the provided argument {:?} as a integer",
  + arg.as_str()
  + )
  + })?;
  + args.push(Value::I32(x));
  + }
  + Ok(args)
  + }
  +}
  +
  #[allow(dead_code)]
  #[derive(Debug, Copy, Clone)]
  enum LoaderName {
  @@ -448,9 +465,7 @@ fn execute_wasi(
  let result;
  #[cfg(unix)]
  - {
  - let cv_pushed =
  - if let Some(msm) = instance.module.runnable_module.get_module_state_map() {
  + let cv_pushed = if let Some(msm) = instance.module.runnable_module.get_module_state_map() {
  push_code_version(CodeVersion {
  baseline: true,
  msm: msm,
  @@ -461,15 +476,27 @@ fn execute_wasi(
  } else {
  false
  };
  +
  + if let Some(invoke_fn) = options.invoke.as_ref() {
  + eprintln!("WARNING: Invoking a function with WASI is not officially supported in the WASI standard yet. Use this feature at your own risk, things may not work!");
  + let args = options.parse_args()?;
  + let invoke_result = instance
  + .dyn_func(invoke_fn)
  + .map_err(|e| format!("Invoke failed: {:?}", e))?
  + .call(&args)
  + .map_err(|e| format!("Calling invoke fn failed: {:?}", e))?;
  + println!("{} returned {:?}", invoke_fn, invoke_result);
  + return Ok(());
  + } else {
  result = start.call();
  + }
  +
  + #[cfg(unix)]
  + {
  if cv_pushed {
  pop_code_version().unwrap();
  }
  }
  - #[cfg(not(unix))]
  - {
  - result = start.call();
  - }
  if let Err(ref err) = result {
  match err {
  @@ -755,16 +782,7 @@ fn execute_wasm(options: &Run) -> Result<(), String> {
  .instantiate(&import_object)
  .map_err(|e| format!("Can't instantiate module: {:?}", e))?;
  - let mut args: Vec<Value> = Vec::new();
  - for arg in options.args.iter() {
  - let x = arg.as_str().parse().map_err(|_| {
  - format!(
  - "Can't parse the provided argument {:?} as a integer",
  - arg.as_str()
  - )
  - })?;
  - args.push(Value::I32(x));
  - }
  + let args = options.parse_args()?;
  let invoke_fn = match options.invoke.as_ref() {
  Some(fun) => fun,
  