Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/herkos-runtime/src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl<const MAX_PAGES: usize> IsolatedMemory<MAX_PAGES> {
/// # Errors
/// Returns `ConstructionError::MemoryInitialPagesExceedsMax` if `initial_pages > MAX_PAGES`.
#[inline(never)]
pub fn try_new(initial_pages: usize) -> Result<Self, crate::ConstructionError> {
pub const fn try_new(initial_pages: usize) -> Result<Self, crate::ConstructionError> {
if initial_pages > MAX_PAGES {
return Err(crate::ConstructionError::MemoryInitialPagesExceedsMax {
initial: initial_pages,
Expand Down Expand Up @@ -81,13 +81,13 @@ impl<const MAX_PAGES: usize> IsolatedMemory<MAX_PAGES> {

/// Current number of active pages.
#[inline(always)]
pub fn page_count(&self) -> usize {
pub const fn page_count(&self) -> usize {
self.active_pages
}

/// Current active size in bytes.
#[inline(always)]
pub fn active_size(&self) -> usize {
pub const fn active_size(&self) -> usize {
self.active_pages * PAGE_SIZE
}

Expand All @@ -109,7 +109,7 @@ impl<const MAX_PAGES: usize> IsolatedMemory<MAX_PAGES> {

/// Wasm `memory.size` — returns current page count.
#[inline(always)]
pub fn size(&self) -> i32 {
pub const fn size(&self) -> i32 {
self.active_pages as i32
}

Expand Down
2 changes: 1 addition & 1 deletion crates/herkos-runtime/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub struct LibraryModule<G, const TABLE_SIZE: usize> {
impl<G, const TABLE_SIZE: usize> LibraryModule<G, TABLE_SIZE> {
/// Create a new library module with the given globals and table.
#[inline]
pub fn new(globals: G, table: Table<TABLE_SIZE>) -> Self {
pub const fn new(globals: G, table: Table<TABLE_SIZE>) -> Self {
Self { globals, table }
}
}
Expand Down
12 changes: 6 additions & 6 deletions crates/herkos-runtime/src/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ pub fn i32_div_u(lhs: i32, rhs: i32) -> WasmResult<i32> {
/// for this case (because the underlying division overflows), so we handle it
/// with an explicit branch.
#[inline(never)]
pub fn i32_rem_s(lhs: i32, rhs: i32) -> WasmResult<i32> {
pub const fn i32_rem_s(lhs: i32, rhs: i32) -> WasmResult<i32> {
if rhs == 0 {
return Err(WasmTrap::DivisionByZero);
}
Expand Down Expand Up @@ -174,7 +174,7 @@ pub fn i64_div_u(lhs: i64, rhs: i64) -> WasmResult<i64> {
///
/// Same special case as `i32_rem_s`: `i64::MIN rem_s -1 = 0` per Wasm spec.
#[inline(never)]
pub fn i64_rem_s(lhs: i64, rhs: i64) -> WasmResult<i64> {
pub const fn i64_rem_s(lhs: i64, rhs: i64) -> WasmResult<i64> {
if rhs == 0 {
return Err(WasmTrap::DivisionByZero);
}
Expand All @@ -198,7 +198,7 @@ pub fn i64_rem_u(lhs: i64, rhs: i64) -> WasmResult<i64> {

/// Wasm `f32.min`: propagates NaN (unlike Rust's `f32::min` which ignores it).
/// Also preserves the Wasm rule `min(-0.0, +0.0) = -0.0`.
pub fn wasm_min_f32(a: f32, b: f32) -> f32 {
pub const fn wasm_min_f32(a: f32, b: f32) -> f32 {
if a.is_nan() || b.is_nan() {
return f32::NAN;
}
Expand All @@ -213,7 +213,7 @@ pub fn wasm_min_f32(a: f32, b: f32) -> f32 {
}

/// Wasm `f32.max`: propagates NaN. `max(-0.0, +0.0) = +0.0`.
pub fn wasm_max_f32(a: f32, b: f32) -> f32 {
pub const fn wasm_max_f32(a: f32, b: f32) -> f32 {
if a.is_nan() || b.is_nan() {
return f32::NAN;
}
Expand All @@ -228,7 +228,7 @@ pub fn wasm_max_f32(a: f32, b: f32) -> f32 {
}

/// Wasm `f64.min`: propagates NaN. `min(-0.0, +0.0) = -0.0`.
pub fn wasm_min_f64(a: f64, b: f64) -> f64 {
pub const fn wasm_min_f64(a: f64, b: f64) -> f64 {
if a.is_nan() || b.is_nan() {
return f64::NAN;
}
Expand All @@ -243,7 +243,7 @@ pub fn wasm_min_f64(a: f64, b: f64) -> f64 {
}

/// Wasm `f64.max`: propagates NaN. `max(-0.0, +0.0) = +0.0`.
pub fn wasm_max_f64(a: f64, b: f64) -> f64 {
pub const fn wasm_max_f64(a: f64, b: f64) -> f64 {
if a.is_nan() || b.is_nan() {
return f64::NAN;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/herkos-runtime/src/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl<const MAX_SIZE: usize> Table<MAX_SIZE> {
///
/// # Errors
/// Returns `ConstructionError::TableInitialSizeExceedsMax` if `initial_size > MAX_SIZE`.
pub fn try_new(initial_size: usize) -> Result<Self, crate::ConstructionError> {
pub const fn try_new(initial_size: usize) -> Result<Self, crate::ConstructionError> {
if initial_size > MAX_SIZE {
return Err(crate::ConstructionError::TableInitialSizeExceedsMax {
initial: initial_size,
Expand All @@ -60,7 +60,7 @@ impl<const MAX_SIZE: usize> Table<MAX_SIZE> {

/// Current number of active table slots.
#[inline(always)]
pub fn size(&self) -> usize {
pub const fn size(&self) -> usize {
self.active_size
}

Expand Down
Loading