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 wasmerio#3762
  • Loading branch information
kajacx committed Apr 12, 2023
1 parent c608eb8 commit 64fda39
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ Looking for changes that affect our C API? See the [C API Changelog](lib/c-api/C

## **Unreleased**

## 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

Bug fixes for this beta release, and some exciting new possibilities with the `run-unstable` function from the CLI tools.
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 @@ -77,6 +77,50 @@ impl NativeWasmTypeInto for i64 {
}
}

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 @@ -179,6 +179,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 64fda39

Please sign in to comment.