summaryrefslogtreecommitdiff
path: root/crates/types
diff options
context:
space:
mode:
authorHenry <mail@henrygressmann.de>2026-04-16 23:29:00 +0200
committerHenry <mail@henrygressmann.de>2026-04-16 23:29:00 +0200
commit5de0533875b6f439ea9e562cba93204ec15e3ba8 (patch)
treeedd4a4ea369d9ea0dfa599e9f01b960ca28c6802 /crates/types
parente47089bf4c53323a22bd9d8ba4b7a8836fcb45a6 (diff)
chore: remove ref stack
Signed-off-by: Henry <mail@henrygressmann.de>
Diffstat (limited to 'crates/types')
-rw-r--r--crates/types/src/instructions.rs7
-rw-r--r--crates/types/src/lib.rs5
-rw-r--r--crates/types/src/value.rs52
3 files changed, 46 insertions, 18 deletions
diff --git a/crates/types/src/instructions.rs b/crates/types/src/instructions.rs
index 01398b5..7db9f79 100644
--- a/crates/types/src/instructions.rs
+++ b/crates/types/src/instructions.rs
@@ -59,7 +59,7 @@ pub enum ConstInstruction {
#[cfg_attr(feature = "debug", derive(Debug))]
#[cfg_attr(feature = "archive", derive(serde::Serialize, serde::Deserialize))]
pub enum Instruction {
- LocalCopy32(LocalAddr, LocalAddr), LocalCopy64(LocalAddr, LocalAddr), LocalCopy128(LocalAddr, LocalAddr), LocalCopyRef(LocalAddr, LocalAddr),
+ LocalCopy32(LocalAddr, LocalAddr), LocalCopy64(LocalAddr, LocalAddr), LocalCopy128(LocalAddr, LocalAddr),
I32AddLocals(LocalAddr, LocalAddr), I64AddLocals(LocalAddr, LocalAddr),
I32AddConst(i32), I64AddConst(i64),
LocalAddConst32(LocalAddr, i32), LocalAddConst64(LocalAddr, i64),
@@ -78,11 +78,10 @@ pub enum Instruction {
Jump(u32),
JumpIfZero(u32),
JumpIfNonZero(u32),
- DropKeepSmall { base32: u8, keep32: u8, base64: u8, keep64: u8, base128: u8, keep128: u8, base_ref: u8, keep_ref: u8 },
+ DropKeep { base32: u16, keep32: u8, base64: u16, keep64: u8, base128: u16, keep128: u8 },
DropKeep32(u16, u16),
DropKeep64(u16, u16),
DropKeep128(u16, u16),
- DropKeepRef(u16, u16),
BranchTable(u32, u32, u32), // (default_landing_pad_ip, branch_table_start, target_count)
Return,
Call(FuncAddr),
@@ -97,7 +96,6 @@ pub enum Instruction {
Drop32, Select32,
Drop64, Select64,
Drop128, Select128,
- DropRef, SelectRef,
SelectMulti(ValueCounts),
// > Variable Instructions
@@ -106,7 +104,6 @@ pub enum Instruction {
LocalGet32(LocalAddr), LocalSet32(LocalAddr), LocalTee32(LocalAddr), GlobalSet32(GlobalAddr),
LocalGet64(LocalAddr), LocalSet64(LocalAddr), LocalTee64(LocalAddr), GlobalSet64(GlobalAddr),
LocalGet128(LocalAddr), LocalSet128(LocalAddr), LocalTee128(LocalAddr), GlobalSet128(GlobalAddr),
- LocalGetRef(LocalAddr), LocalSetRef(LocalAddr), LocalTeeRef(LocalAddr), GlobalSetRef(GlobalAddr),
// > Memory Instructions
I32Load(MemoryArg),
diff --git a/crates/types/src/lib.rs b/crates/types/src/lib.rs
index ece6086..28d52a7 100644
--- a/crates/types/src/lib.rs
+++ b/crates/types/src/lib.rs
@@ -230,13 +230,12 @@ pub struct ValueCounts {
pub c32: u16,
pub c64: u16,
pub c128: u16,
- pub cref: u16,
}
impl ValueCounts {
#[inline]
pub fn is_empty(&self) -> bool {
- self.c32 == 0 && self.c64 == 0 && self.c128 == 0 && self.cref == 0
+ self.c32 == 0 && self.c64 == 0 && self.c128 == 0
}
}
@@ -248,7 +247,7 @@ impl<'a> FromIterator<&'a WasmType> for ValueCounts {
WasmType::I32 | WasmType::F32 => counts.c32 += 1,
WasmType::I64 | WasmType::F64 => counts.c64 += 1,
WasmType::V128 => counts.c128 += 1,
- WasmType::RefExtern | WasmType::RefFunc => counts.cref += 1,
+ WasmType::RefExtern | WasmType::RefFunc => counts.c32 += 1,
}
counts
})
diff --git a/crates/types/src/value.rs b/crates/types/src/value.rs
index 462749b..20c822e 100644
--- a/crates/types/src/value.rs
+++ b/crates/types/src/value.rs
@@ -42,16 +42,18 @@ impl Debug for WasmValue {
}
}
+const NULL_REF: u32 = u32::MAX;
+
#[derive(Clone, Copy, PartialEq, Eq)]
-pub struct ExternRef(Option<ExternAddr>);
+pub struct ExternRef(u32);
#[derive(Clone, Copy, PartialEq, Eq)]
-pub struct FuncRef(Option<FuncAddr>);
+pub struct FuncRef(u32);
#[cfg(feature = "debug")]
impl Debug for ExternRef {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match self.0 {
+ match self.addr() {
Some(addr) => write!(f, "extern({addr:?})"),
None => write!(f, "extern(null)"),
}
@@ -61,7 +63,7 @@ impl Debug for ExternRef {
#[cfg(feature = "debug")]
impl Debug for FuncRef {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
- match self.0 {
+ match self.addr() {
Some(addr) => write!(f, "func({addr:?})"),
None => write!(f, "func(null)"),
}
@@ -72,24 +74,39 @@ impl FuncRef {
#[inline]
/// Create a new [`FuncRef`] from a [`FuncAddr`].
pub const fn new(addr: Option<FuncAddr>) -> Self {
- Self(addr)
+ match addr {
+ Some(addr) => Self(addr),
+ None => Self::null(),
+ }
}
#[inline]
/// Create a null [`FuncRef`].
pub const fn null() -> Self {
- Self(None)
+ Self(NULL_REF)
}
#[inline]
/// Check if the [`FuncRef`] is null.
pub const fn is_null(&self) -> bool {
- self.0.is_none()
+ self.0 == NULL_REF
}
#[inline]
/// Get the [`FuncAddr`] from the [`FuncRef`].
pub const fn addr(&self) -> Option<FuncAddr> {
+ if self.is_null() { None } else { Some(self.0) }
+ }
+
+ #[inline]
+ #[doc(hidden)]
+ pub const fn from_raw(raw: u32) -> Self {
+ Self(raw)
+ }
+
+ #[inline]
+ #[doc(hidden)]
+ pub const fn raw(&self) -> u32 {
self.0
}
}
@@ -99,24 +116,39 @@ impl ExternRef {
/// Create a new [`ExternRef`] from an [`ExternAddr`].
/// Should only be used by the runtime.
pub const fn new(addr: Option<ExternAddr>) -> Self {
- Self(addr)
+ match addr {
+ Some(addr) => Self(addr),
+ None => Self::null(),
+ }
}
/// Create a null [`ExternRef`].
#[inline]
pub const fn null() -> Self {
- Self(None)
+ Self(NULL_REF)
}
/// Check if the [`ExternRef`] is null.
#[inline]
pub const fn is_null(&self) -> bool {
- self.0.is_none()
+ self.0 == NULL_REF
}
/// Get the [`ExternAddr`] from the [`ExternRef`].
#[inline]
pub const fn addr(&self) -> Option<ExternAddr> {
+ if self.is_null() { None } else { Some(self.0) }
+ }
+
+ #[inline]
+ #[doc(hidden)]
+ pub const fn from_raw(raw: u32) -> Self {
+ Self(raw)
+ }
+
+ #[inline]
+ #[doc(hidden)]
+ pub const fn raw(&self) -> u32 {
self.0
}
}