Skip to content

Commit aa1049f

Browse files
committed
feat(runtime): implement F64 instructions and fix CallIndirect LEB128 parsing
- Add comprehensive F64 instruction support in stackless engine: - Memory operations: F64Const, F64Load, F64Store - Arithmetic: F64Add, F64Sub, F64Mul, F64Div - Comparisons: F64Eq, F64Ne, F64Lt, F64Gt, F64Le, F64Ge - Unary: F64Abs, F64Neg, F64Ceil, F64Floor, F64Trunc, F64Nearest, F64Sqrt - Binary: F64Min, F64Max, F64Copysign - Conversions: F64ConvertI32S/U, F64ConvertI64S/U, F64PromoteF32 - Reinterpret: F64ReinterpretI64, I64ReinterpretF64 - Fix CallIndirect instruction parsing to properly read table_idx as LEB128 instead of assuming single byte (was causing instruction stream corruption) - Disable bump allocator in favor of cabi_realloc for proper dlmalloc headers (prevents memory corruption when Rust frees allocated strings) These fixes enable calculator.wasm to correctly compute: 5+3=8, 10-7=3, 6*7=42, 100/4=25
1 parent 9904250 commit aa1049f

File tree

2 files changed

+709
-139
lines changed

2 files changed

+709
-139
lines changed

wrt-runtime/src/instruction_parser.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,13 @@ fn parse_instruction_with_provider(
236236
Instruction::Call(func_idx)
237237
},
238238
0x11 => {
239-
// CallIndirect
240-
let (type_idx, bytes) = read_leb128_u32(bytecode, offset + 1)?;
241-
consumed += bytes;
242-
consumed += 1; // Skip table index (always 0 in MVP)
243-
Instruction::CallIndirect(type_idx, 0)
239+
// CallIndirect: type_idx (LEB128 u32) followed by table_idx (LEB128 u32)
240+
// Note: table_idx can be multi-byte LEB128, not always single byte!
241+
let (type_idx, type_bytes) = read_leb128_u32(bytecode, offset + 1)?;
242+
consumed += type_bytes;
243+
let (table_idx, table_bytes) = read_leb128_u32(bytecode, offset + 1 + type_bytes)?;
244+
consumed += table_bytes;
245+
Instruction::CallIndirect(type_idx, table_idx)
244246
},
245247

246248
// Parametric instructions

0 commit comments

Comments
 (0)