wasm_interp: don't panic when unwrapping Value

This commit is contained in:
Brian Carroll 2022-12-06 20:19:25 +00:00
parent d49ae6701a
commit 9d912a6cc7
No known key found for this signature in database
GPG key ID: 5C7B2EC4101703C0
5 changed files with 49 additions and 39 deletions

View file

@ -68,16 +68,26 @@ pub(crate) enum Error {
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,
};
let ty = type_from_flags_f_64(is_float, is_64);
Error::ValueStackType(expected, ty)
}
}
impl From<(ValueType, ValueType)> for Error {
fn from((expected, actual): (ValueType, ValueType)) -> Self {
Error::ValueStackType(expected, actual)
}
}
pub(crate) fn type_from_flags_f_64(is_float: bool, is_64: bool) -> ValueType {
match (is_float, is_64) {
(false, false) => ValueType::I32,
(false, true) => ValueType::I64,
(true, false) => ValueType::F32,
(true, true) => ValueType::F64,
}
}
// Determine which function the program counter is in
pub(crate) fn pc_to_fn_index(program_counter: usize, module: &WasmModule<'_>) -> usize {
if module.code.function_offsets.is_empty() {