Skip to content

Commit

Permalink
Properly handle either integer/float term type
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyalIcing committed Jan 17, 2024
1 parent 1959f81 commit b6fe620
Showing 1 changed file with 47 additions and 38 deletions.
85 changes: 47 additions & 38 deletions native/wasmex/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,55 +244,64 @@ pub fn decode_function_param_terms(
.enumerate()
{
let value = match (param, given_param.get_type()) {
(ValType::I32, TermType::Integer) => match given_param.decode::<i32>() {
Ok(value) => WasmValue::I32(value),
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly i32 value.",
nth + 1
));
(ValType::I32, TermType::Integer | TermType::Float) => {
match given_param.decode::<i32>() {
Ok(value) => WasmValue::I32(value),
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly i32 value.",
nth + 1
));
}
}
},
(ValType::I64, TermType::Integer) => match given_param.decode::<i64>() {
Ok(value) => WasmValue::I64(value),
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly i64 value.",
nth + 1
));
}
(ValType::I64, TermType::Integer | TermType::Float) => {
match given_param.decode::<i64>() {
Ok(value) => WasmValue::I64(value),
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly i64 value.",
nth + 1
));
}
}
},
(ValType::F32, TermType::Float) => match given_param.decode::<f32>() {
Ok(value) => {
if value.is_finite() {
WasmValue::F32(value)
} else {
}
(ValType::F32, TermType::Integer | TermType::Float) => {
match given_param.decode::<f32>() {
Ok(value) => {
if value.is_finite() {
WasmValue::F32(value)
} else {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly f32 value.",
nth + 1
));
}
}
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly f32 value.",
nth + 1
));
}
}
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly f32 value.",
nth + 1
));
}
},
(ValType::F64, TermType::Float) => match given_param.decode::<f64>() {
Ok(value) => WasmValue::F64(value),
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly f64 value.",
nth + 1
));
}
(ValType::F64, TermType::Integer | TermType::Float) => {
match given_param.decode::<f64>() {
Ok(value) => WasmValue::F64(value),
Err(_) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly f64 value.",
nth + 1
));
}
}
},
(_, term_type) => {
}
(val_type, term_type) => {
return Err(format!(
"Cannot convert argument #{} to a WebAssembly value. Given `{:?}`.",
"Cannot convert argument #{} to a WebAssembly {:?} value. Given `{:?}`.",
nth + 1,
val_type,
PrintableTermType::PrintTerm(term_type)
));
}
Expand Down

0 comments on commit b6fe620

Please sign in to comment.