tinywasm_types/value.rs
1use crate::{RefType, StorageType};
2
3/// Type of a WebAssembly value.
4///
5/// See <https://webassembly.github.io/spec/core/syntax/types.html#syntax-valtype>
6#[derive(Clone, Copy, PartialEq, Eq)]
7#[cfg_attr(feature = "debug", derive(Debug))]
8#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
9pub enum WasmType {
10 /// A 32-bit integer.
11 I32,
12 /// A 64-bit integer.
13 I64,
14 /// A 32-bit float.
15 F32,
16 /// A 64-bit float.
17 F64,
18 /// A 128-bit vector.
19 V128,
20 /// A reference type.
21 Ref(RefType),
22}
23
24impl From<StorageType> for WasmType {
25 fn from(value: StorageType) -> Self {
26 match value {
27 StorageType::I8 | StorageType::I16 => Self::I32,
28 StorageType::Value(value) => value,
29 }
30 }
31}