Skip to content

Commit

Permalink
Add i32/i64 converters from unsigned ints
Browse files Browse the repository at this point in the history
  • Loading branch information
webmaster128 committed Oct 6, 2020
1 parent b950081 commit 281c886
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions lib/wasmer-types/src/values.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ use crate::types::Type;
/// produce.
#[derive(Clone, PartialEq)]
pub enum Value<T> {
/// A 32-bit integer
/// A 32-bit integer.
///
/// In Wasm integers are sign-agnostic, i.e. this can either be signed or unsigned.
I32(i32),

/// A 64-bit integer
/// A 64-bit integer.
///
/// In Wasm integers are sign-agnostic, i.e. this can either be signed or unsigned.
I64(i64),

/// A 32-bit float.
Expand Down Expand Up @@ -175,12 +179,26 @@ impl<T> From<i32> for Value<T> {
}
}

impl<T> From<u32> for Value<T> {
fn from(val: u32) -> Self {
// In Wasm integers are sign-agnostic, so i32 is basically a 4 byte storage we can use for signed or unsigned 32-bit integers.
Self::I32(val as i32)
}
}

impl<T> From<i64> for Value<T> {
fn from(val: i64) -> Self {
Self::I64(val)
}
}

impl<T> From<u64> for Value<T> {
fn from(val: u64) -> Self {
// In Wasm integers are sign-agnostic, so i64 is basically an 8 byte storage we can use for signed or unsigned 64-bit integers.
Self::I64(val as i64)
}
}

impl<T> From<f32> for Value<T> {
fn from(val: f32) -> Self {
Self::F32(val)
Expand Down

0 comments on commit 281c886

Please sign in to comment.