Skip to content

Commit

Permalink
Implement NativeWasmTypeInto for u32 and u64
Browse files Browse the repository at this point in the history
Implements feature request #3762
  • Loading branch information
kajacx committed May 10, 2023
1 parent a32fb73 commit dbe4b05
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ RISCV Support, new Runners (WCGI), API convergence for JS/SYS, and WASI eXtended
- [#3761](https://github.com/wasmerio/wasmer/pull/3761) Fix error in Korean translation


## Added

- [#3762](https://github.com/wasmerio/wasmer/issues/3762) Implemented `NativeWasmTypeInto` for `u32` and `u64` for the web target (`js` feature)

## 3.2.0-beta.2 - 05/04/2023

Expand Down
44 changes: 44 additions & 0 deletions lib/api/src/native_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,50 @@ impl NativeWasmTypeInto for u64 {
}
}

impl NativeWasmTypeInto for u32 {
#[inline]
unsafe fn from_abi(_store: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
abi
}

#[inline]
fn into_abi(self, _store: &mut impl AsStoreMut) -> Self::Abi {
self
}

#[inline]
fn into_raw(self, _store: &mut impl AsStoreMut) -> RawValue {
RawValue { u32: self }
}

#[inline]
unsafe fn from_raw(_store: &mut impl AsStoreMut, raw: RawValue) -> Self {
raw.u32
}
}

impl NativeWasmTypeInto for u64 {
#[inline]
unsafe fn from_abi(_store: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
abi
}

#[inline]
fn into_abi(self, _store: &mut impl AsStoreMut) -> Self::Abi {
self
}

#[inline]
fn into_raw(self, _store: &mut impl AsStoreMut) -> RawValue {
RawValue { u64: self }
}

#[inline]
unsafe fn from_raw(_store: &mut impl AsStoreMut, raw: RawValue) -> Self {
raw.u64
}
}

impl NativeWasmTypeInto for f32 {
#[inline]
unsafe fn from_abi(_store: &mut impl AsStoreMut, abi: Self::Abi) -> Self {
Expand Down
10 changes: 10 additions & 0 deletions lib/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,16 @@ mod native {
type Abi = Self;
}

impl NativeWasmType for u32 {
const WASM_TYPE: Type = Type::I32;
type Abi = Self;
}

impl NativeWasmType for u64 {
const WASM_TYPE: Type = Type::I64;
type Abi = Self;
}

impl NativeWasmType for f32 {
const WASM_TYPE: Type = Type::F32;
type Abi = Self;
Expand Down

0 comments on commit dbe4b05

Please sign in to comment.