Skip to content

Commit

Permalink
refactor: less verbose syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
nerodesu017 committed Jul 3, 2024
1 parent 2884967 commit 6711141
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/execution/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use crate::execution::store::{FuncInst, GlobalInst, MemInst, Store};
use crate::execution::value::Value;
use crate::validation::code::read_declared_locals;
use crate::value::InteropValueList;
use crate::Error::RuntimeError;
use crate::RuntimeError::{DivideBy0, UnrepresentableResult};
use crate::{Result, ValidationInfo};

// TODO
Expand Down Expand Up @@ -224,14 +226,10 @@ impl<'b> RuntimeInstance<'b> {
let divisor: i32 = stack.pop_value(ValType::NumType(NumType::I32)).into();

if dividend == 0 {
return Err(crate::Error::RuntimeError(
crate::core::error::RuntimeError::DivideBy0,
));
return Err(RuntimeError(DivideBy0));
}
if divisor == i32::MIN && dividend == -1 {
return Err(crate::Error::RuntimeError(
crate::core::error::RuntimeError::UnrepresentableResult,
));
return Err(RuntimeError(UnrepresentableResult));
}

let res = divisor / dividend;
Expand All @@ -248,9 +246,7 @@ impl<'b> RuntimeInstance<'b> {
let divisor = divisor as u32;

if dividend == 0 {
return Err(crate::Error::RuntimeError(
crate::core::error::RuntimeError::DivideBy0,
));
return Err(RuntimeError(DivideBy0));
}

let res = (divisor / dividend) as i32;
Expand Down

0 comments on commit 6711141

Please sign in to comment.