wasm_interp: implement WASI random_get & refactor default imports

This commit is contained in:
Brian Carroll 2022-12-14 23:35:57 +00:00
parent eaa3f14fb0
commit b7fef386ee
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0
8 changed files with 112 additions and 31 deletions

View file

@ -8,6 +8,7 @@ pub mod wasi;
pub use instance::Instance;
pub use wasi::WasiDispatcher;
use rand::prelude::*;
use roc_wasm_module::{Value, ValueType, WasmModule};
use value_stack::ValueStack;
@ -22,9 +23,16 @@ pub trait ImportDispatcher {
) -> Option<Value>;
}
pub const DEFAULT_IMPORTS: DefaultImportDispatcher = DefaultImportDispatcher {
wasi: WasiDispatcher { args: &[] },
};
impl Default for DefaultImportDispatcher<'_> {
fn default() -> Self {
DefaultImportDispatcher {
wasi: WasiDispatcher {
args: &[],
rng: thread_rng(),
},
}
}
}
pub struct DefaultImportDispatcher<'a> {
wasi: WasiDispatcher<'a>,
@ -33,7 +41,10 @@ pub struct DefaultImportDispatcher<'a> {
impl<'a> DefaultImportDispatcher<'a> {
pub fn new(args: &'a [&'a String]) -> Self {
DefaultImportDispatcher {
wasi: WasiDispatcher { args },
wasi: WasiDispatcher {
args,
rng: thread_rng(),
},
}
}
}