Skip to content
This repository was archived by the owner on Oct 3, 2025. It is now read-only.

Commit cfcd1f7

Browse files
wip: tables
Signed-off-by: Henry Gressmann <mail@henrygressmann.de>
1 parent ed24d26 commit cfcd1f7

File tree

2 files changed

+29
-1
lines changed
  • crates/tinywasm

2 files changed

+29
-1
lines changed

crates/tinywasm/src/runtime/interpreter/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ impl<'store, 'stack> Executor<'store, 'stack> {
9696
I64Const(val) => self.exec_const(*val),
9797
F32Const(val) => self.exec_const(*val),
9898
F64Const(val) => self.exec_const(*val),
99+
RefFunc(func_idx) => self.exec_const(*func_idx),
100+
RefNull(_) => self.exec_const(-1i64),
101+
RefIsNull => self.exec_ref_is_null()?,
99102

100103
MemorySize(addr, byte) => self.exec_memory_size(*addr, *byte)?,
101104
MemoryGrow(addr, byte) => self.exec_memory_grow(*addr, *byte)?,
@@ -285,6 +288,8 @@ impl<'store, 'stack> Executor<'store, 'stack> {
285288
TableSet(table_idx) => self.exec_table_set(*table_idx)?,
286289
TableSize(table_idx) => self.exec_table_size(*table_idx)?,
287290
TableInit(table_idx, elem_idx) => self.exec_table_init(*elem_idx, *table_idx)?,
291+
TableGrow(table_idx) => self.exec_table_grow(*table_idx)?,
292+
TableFill(table_idx) => self.exec_table_fill(*table_idx)?,
288293

289294
I32TruncSatF32S => arithmetic_single!(trunc, f32, i32, self),
290295
I32TruncSatF32U => arithmetic_single!(trunc, f32, u32, self),
@@ -391,6 +396,11 @@ impl<'store, 'stack> Executor<'store, 'stack> {
391396
Err(Error::Trap(Trap::Unreachable))
392397
}
393398

399+
#[inline(always)]
400+
fn exec_ref_is_null(&mut self) -> Result<()> {
401+
self.stack.values.replace_top(|val| ((i32::from(val) == -1) as i32).into())
402+
}
403+
394404
#[inline(always)]
395405
fn exec_const(&mut self, val: impl Into<RawWasmValue>) {
396406
self.stack.values.push(val.into());
@@ -535,6 +545,24 @@ impl<'store, 'stack> Executor<'store, 'stack> {
535545
Ok(())
536546
}
537547

548+
#[inline(always)]
549+
// todo: this is just a placeholder, need to check the spec
550+
fn exec_table_grow(&mut self, table_index: u32) -> Result<()> {
551+
let table_idx = self.module.resolve_table_addr(table_index);
552+
let table = self.store.get_table(table_idx)?;
553+
let delta: i32 = self.stack.values.pop()?.into();
554+
let prev_size = table.borrow().size() as i32;
555+
table.borrow_mut().grow_to_fit((prev_size + delta) as usize)?;
556+
self.stack.values.push(prev_size.into());
557+
Ok(())
558+
}
559+
560+
#[inline(always)]
561+
fn exec_table_fill(&mut self, table_index: u32) -> Result<()> {
562+
// TODO: implement
563+
Ok(())
564+
}
565+
538566
#[inline(always)]
539567
fn exec_select(&mut self) -> Result<()> {
540568
let cond: i32 = self.stack.values.pop()?.into();

0 commit comments

Comments
 (0)