diff --git a/crates/wasm_interp/src/lib.rs b/crates/wasm_interp/src/lib.rs index 1417751561..f134b54857 100644 --- a/crates/wasm_interp/src/lib.rs +++ b/crates/wasm_interp/src/lib.rs @@ -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; +} diff --git a/crates/wasm_interp/src/wasi.rs b/crates/wasm_interp/src/wasi.rs index d768561bee..a1f8e573e9 100644 --- a/crates/wasm_interp/src/wasi.rs +++ b/crates/wasm_interp/src/wasi.rs @@ -1,88 +1,54 @@ 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; -} +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; -} - -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 { - match function_name { - "args_get" => todo!("WASI {}({:?})", function_name, arguments), - "args_sizes_get" => todo!("WASI {}({:?})", function_name, arguments), - "environ_get" => todo!("WASI {}({:?})", function_name, arguments), - "environ_sizes_get" => todo!("WASI {}({:?})", function_name, arguments), - "clock_res_get" => todo!("WASI {}({:?})", function_name, arguments), - "clock_time_get" => todo!("WASI {}({:?})", function_name, arguments), - "fd_advise" => todo!("WASI {}({:?})", function_name, arguments), - "fd_allocate" => todo!("WASI {}({:?})", function_name, arguments), - "fd_close" => todo!("WASI {}({:?})", function_name, arguments), - "fd_datasync" => todo!("WASI {}({:?})", function_name, arguments), - "fd_fdstat_get" => todo!("WASI {}({:?})", function_name, arguments), - "fd_fdstat_set_flags" => todo!("WASI {}({:?})", function_name, arguments), - "fd_fdstat_set_rights" => todo!("WASI {}({:?})", function_name, arguments), - "fd_filestat_get" => todo!("WASI {}({:?})", function_name, arguments), - "fd_filestat_set_size" => todo!("WASI {}({:?})", function_name, arguments), - "fd_filestat_set_times" => todo!("WASI {}({:?})", function_name, arguments), - "fd_pread" => todo!("WASI {}({:?})", function_name, arguments), - "fd_prestat_get" => todo!("WASI {}({:?})", function_name, arguments), - "fd_prestat_dir_name" => todo!("WASI {}({:?})", function_name, arguments), - "fd_pwrite" => todo!("WASI {}({:?})", function_name, arguments), - "fd_read" => todo!("WASI {}({:?})", function_name, arguments), - "fd_readdir" => todo!("WASI {}({:?})", function_name, arguments), - "fd_renumber" => todo!("WASI {}({:?})", 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), - } +pub fn dispatch(function_name: &str, arguments: &[Value], _memory: &mut [u8]) -> Option { + match function_name { + "args_get" => todo!("WASI {}({:?})", function_name, arguments), + "args_sizes_get" => todo!("WASI {}({:?})", function_name, arguments), + "environ_get" => todo!("WASI {}({:?})", function_name, arguments), + "environ_sizes_get" => todo!("WASI {}({:?})", function_name, arguments), + "clock_res_get" => todo!("WASI {}({:?})", function_name, arguments), + "clock_time_get" => todo!("WASI {}({:?})", function_name, arguments), + "fd_advise" => todo!("WASI {}({:?})", function_name, arguments), + "fd_allocate" => todo!("WASI {}({:?})", function_name, arguments), + "fd_close" => todo!("WASI {}({:?})", function_name, arguments), + "fd_datasync" => todo!("WASI {}({:?})", function_name, arguments), + "fd_fdstat_get" => todo!("WASI {}({:?})", function_name, arguments), + "fd_fdstat_set_flags" => todo!("WASI {}({:?})", function_name, arguments), + "fd_fdstat_set_rights" => todo!("WASI {}({:?})", function_name, arguments), + "fd_filestat_get" => todo!("WASI {}({:?})", function_name, arguments), + "fd_filestat_set_size" => todo!("WASI {}({:?})", function_name, arguments), + "fd_filestat_set_times" => todo!("WASI {}({:?})", function_name, arguments), + "fd_pread" => todo!("WASI {}({:?})", function_name, arguments), + "fd_prestat_get" => todo!("WASI {}({:?})", function_name, arguments), + "fd_prestat_dir_name" => todo!("WASI {}({:?})", function_name, arguments), + "fd_pwrite" => todo!("WASI {}({:?})", function_name, arguments), + "fd_read" => todo!("WASI {}({:?})", function_name, arguments), + "fd_readdir" => todo!("WASI {}({:?})", function_name, arguments), + "fd_renumber" => todo!("WASI {}({:?})", 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), } }