wasm_interp: use Result instead of panic. Focus debug info on *Wasm app*, not interp.

This commit is contained in:
Brian Carroll 2022-12-04 11:14:45 +00:00
parent 284dc6fa51
commit 5bdd1b5628
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0
5 changed files with 358 additions and 323 deletions

View file

@ -7,7 +7,7 @@ pub mod wasi;
// Main external interface
pub use instance::Instance;
use roc_wasm_module::Value;
use roc_wasm_module::{Value, ValueType};
use value_stack::ValueStack;
use wasi::WasiDispatcher;
@ -56,3 +56,21 @@ impl<'a> ImportDispatcher for DefaultImportDispatcher<'a> {
}
}
}
#[derive(Debug, PartialEq)]
pub(crate) enum Error {
ValueStackType(ValueType, ValueType),
ValueStackEmpty,
}
impl Error {
fn value_stack_type(expected: ValueType, is_float: bool, is_64: bool) -> Self {
let ty = match (is_float, is_64) {
(false, false) => ValueType::I32,
(false, true) => ValueType::I64,
(true, false) => ValueType::F32,
(true, true) => ValueType::F64,
};
Error::ValueStackType(expected, ty)
}
}