mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49: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,88 +1,54 @@
|
||||||
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;
|
match function_name {
|
||||||
|
"args_get" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
/// Dispatch a call from WebAssembly to your own code, based on the function name.
|
"args_sizes_get" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
/// The call arguments are passed in, along with a mutable pointer to WebAssembly memory.
|
"environ_get" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
fn dispatch(
|
"environ_sizes_get" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
&mut self,
|
"clock_res_get" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
function_name: &str,
|
"clock_time_get" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
arguments: &[Value],
|
"fd_advise" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
memory: &mut [u8],
|
"fd_allocate" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
) -> Option<Value>;
|
"fd_close" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
}
|
"fd_datasync" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
|
"fd_fdstat_get" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
pub struct WasiDispatcher {}
|
"fd_fdstat_set_flags" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
|
"fd_fdstat_set_rights" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
impl ImportDispatcherModule for WasiDispatcher {
|
"fd_filestat_get" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
const NAME: &'static str = "wasi_snapshot_preview1";
|
"fd_filestat_set_size" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
|
"fd_filestat_set_times" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
fn dispatch(
|
"fd_pread" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
&mut self,
|
"fd_prestat_get" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
function_name: &str,
|
"fd_prestat_dir_name" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
arguments: &[Value],
|
"fd_pwrite" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
_memory: &mut [u8],
|
"fd_read" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
) -> Option<Value> {
|
"fd_readdir" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
match function_name {
|
"fd_renumber" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"args_get" => todo!("WASI {}({:?})", function_name, arguments),
|
"fd_seek" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"args_sizes_get" => todo!("WASI {}({:?})", function_name, arguments),
|
"fd_sync" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"environ_get" => todo!("WASI {}({:?})", function_name, arguments),
|
"fd_tell" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"environ_sizes_get" => todo!("WASI {}({:?})", function_name, arguments),
|
"fd_write" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"clock_res_get" => todo!("WASI {}({:?})", function_name, arguments),
|
"path_create_directory" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"clock_time_get" => todo!("WASI {}({:?})", function_name, arguments),
|
"path_filestat_get" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_advise" => todo!("WASI {}({:?})", function_name, arguments),
|
"path_filestat_set_times" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_allocate" => todo!("WASI {}({:?})", function_name, arguments),
|
"path_link" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_close" => todo!("WASI {}({:?})", function_name, arguments),
|
"path_open" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_datasync" => todo!("WASI {}({:?})", function_name, arguments),
|
"path_readlink" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_fdstat_get" => todo!("WASI {}({:?})", function_name, arguments),
|
"path_remove_directory" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_fdstat_set_flags" => todo!("WASI {}({:?})", function_name, arguments),
|
"path_rename" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_fdstat_set_rights" => todo!("WASI {}({:?})", function_name, arguments),
|
"path_symlink" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_filestat_get" => todo!("WASI {}({:?})", function_name, arguments),
|
"path_unlink_file" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_filestat_set_size" => todo!("WASI {}({:?})", function_name, arguments),
|
"poll_oneoff" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_filestat_set_times" => todo!("WASI {}({:?})", function_name, arguments),
|
"proc_exit" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_pread" => todo!("WASI {}({:?})", function_name, arguments),
|
"proc_raise" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_prestat_get" => todo!("WASI {}({:?})", function_name, arguments),
|
"sched_yield" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_prestat_dir_name" => todo!("WASI {}({:?})", function_name, arguments),
|
"random_get" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_pwrite" => todo!("WASI {}({:?})", function_name, arguments),
|
"sock_recv" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_read" => todo!("WASI {}({:?})", function_name, arguments),
|
"sock_send" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_readdir" => todo!("WASI {}({:?})", function_name, arguments),
|
"sock_shutdown" => todo!("WASI {}({:?})", function_name, arguments),
|
||||||
"fd_renumber" => todo!("WASI {}({:?})", function_name, arguments),
|
_ => panic!("Unknown WASI function {}({:?})", function_name, arguments),
|
||||||
"fd_seek" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"fd_sync" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"fd_tell" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"fd_write" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"path_create_directory" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"path_filestat_get" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"path_filestat_set_times" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"path_link" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"path_open" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"path_readlink" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"path_remove_directory" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"path_rename" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"path_symlink" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"path_unlink_file" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"poll_oneoff" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"proc_exit" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"proc_raise" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"sched_yield" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"random_get" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"sock_recv" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"sock_send" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
"sock_shutdown" => todo!("WASI {}({:?})", function_name, arguments),
|
|
||||||
_ => panic!("Unknown WASI function {}({:?})", function_name, arguments),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue