wasm_interp: simplified ImportDispatcher

We don't really need a trait for the 'import module' concept.
This commit is contained in:
Brian Carroll 2022-12-01 08:47:32 +00:00
parent ec8950816a
commit b10ac827f1
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0
2 changed files with 67 additions and 85 deletions

View file

@ -2,9 +2,25 @@ mod call_stack;
mod instance;
pub mod test_utils;
mod value_stack;
mod wasi;
pub mod wasi;
// Main external interface
pub use instance::Instance;
// Exposed for testing only. Should eventually become private.
pub use call_stack::CallStack;
pub use instance::{Action, Instance};
pub use instance::Action;
pub use value_stack::ValueStack;
use roc_wasm_module::Value;
pub trait ImportDispatcher {
/// Dispatch a call from WebAssembly to your own code, based on module and function name.
fn dispatch(
&mut self,
module_name: &str,
function_name: &str,
arguments: &[Value],
memory: &mut [u8],
) -> Option<Value>;
}

View file

@ -1,41 +1,8 @@
use roc_wasm_module::Value;
pub trait ImportDispatcher {
/// Dispatch a call from WebAssembly to your own code, based on module and function name.
/// The call arguments are passed in, along with a mutable pointer to WebAssembly memory.
fn dispatch(
&mut self,
module_name: &str,
function_name: &str,
arguments: &[Value],
memory: &mut [u8],
) -> Option<Value>;
}
pub const MODULE_NAME: &'static str = "wasi_snapshot_preview1";
pub trait ImportDispatcherModule {
const NAME: &'static str;
/// Dispatch a call from WebAssembly to your own code, based on the function name.
/// The call arguments are passed in, along with a mutable pointer to WebAssembly memory.
fn dispatch(
&mut self,
function_name: &str,
arguments: &[Value],
memory: &mut [u8],
) -> Option<Value>;
}
pub struct WasiDispatcher {}
impl ImportDispatcherModule for WasiDispatcher {
const NAME: &'static str = "wasi_snapshot_preview1";
fn dispatch(
&mut self,
function_name: &str,
arguments: &[Value],
_memory: &mut [u8],
) -> Option<Value> {
pub fn dispatch(function_name: &str, arguments: &[Value], _memory: &mut [u8]) -> Option<Value> {
match function_name {
"args_get" => todo!("WASI {}({:?})", function_name, arguments),
"args_sizes_get" => todo!("WASI {}({:?})", function_name, arguments),
@ -85,4 +52,3 @@ impl ImportDispatcherModule for WasiDispatcher {
_ => panic!("Unknown WASI function {}({:?})", function_name, arguments),
}
}
}