mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
wasm_interp: don't panic when unwrapping Value
This commit is contained in:
parent
d49ae6701a
commit
9d912a6cc7
5 changed files with 49 additions and 39 deletions
|
@ -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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue