mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 13:59:08 +00:00
wasm_interp: simplified ImportDispatcher
We don't really need a trait for the 'import module' concept.
This commit is contained in:
parent
ec8950816a
commit
b10ac827f1
2 changed files with 67 additions and 85 deletions
|
@ -2,9 +2,25 @@ mod call_stack;
|
||||||
mod instance;
|
mod instance;
|
||||||
pub mod test_utils;
|
pub mod test_utils;
|
||||||
mod value_stack;
|
mod value_stack;
|
||||||
mod wasi;
|
pub mod wasi;
|
||||||
|
|
||||||
|
// Main external interface
|
||||||
|
pub use instance::Instance;
|
||||||
|
|
||||||
// Exposed for testing only. Should eventually become private.
|
// Exposed for testing only. Should eventually become private.
|
||||||
pub use call_stack::CallStack;
|
pub use call_stack::CallStack;
|
||||||
pub use instance::{Action, Instance};
|
pub use instance::Action;
|
||||||
pub use value_stack::ValueStack;
|
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>;
|
||||||
|
}
|
||||||
|
|
|
@ -1,41 +1,8 @@
|
||||||
use roc_wasm_module::Value;
|
use roc_wasm_module::Value;
|
||||||
|
|
||||||
pub trait ImportDispatcher {
|
pub const MODULE_NAME: &'static str = "wasi_snapshot_preview1";
|
||||||
/// 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 trait ImportDispatcherModule {
|
pub fn dispatch(function_name: &str, arguments: &[Value], _memory: &mut [u8]) -> Option<Value> {
|
||||||
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> {
|
|
||||||
match function_name {
|
match function_name {
|
||||||
"args_get" => todo!("WASI {}({:?})", function_name, arguments),
|
"args_get" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"args_sizes_get" => todo!("WASI {}({:?})", function_name, arguments),
|
"args_sizes_get" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
|
@ -84,5 +51,4 @@ impl ImportDispatcherModule for WasiDispatcher {
|
||||||
"sock_shutdown" => todo!("WASI {}({:?})", function_name, arguments),
|
"sock_shutdown" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
_ => panic!("Unknown WASI function {}({:?})", function_name, arguments),
|
_ => panic!("Unknown WASI function {}({:?})", function_name, arguments),
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue