Skip to content

Commit 4cbaa9c

Browse files
committed
replace exec_return macro with function
1 parent 57f3ae8 commit 4cbaa9c

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

crates/wasmi/src/engine/executor/handler/exec.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::{
1313
exec_copy_span,
1414
exec_copy_span_asc,
1515
exec_copy_span_des,
16+
exec_return,
1617
extract_mem0,
1718
fetch_global,
1819
fetch_memory,
@@ -308,7 +309,7 @@ pub fn r#return(
308309
mem0_len: Mem0Len,
309310
instance: NonNull<InstanceEntity>,
310311
) -> Done {
311-
exec_return!(state, sp, mem0, mem0_len, instance)
312+
exec_return(state, sp, mem0, mem0_len, instance)
312313
}
313314

314315
pub fn return_span(
@@ -324,7 +325,7 @@ pub fn return_span(
324325
let src = values.span();
325326
let len = values.len();
326327
exec_copy_span_asc(sp, dst, src, len);
327-
exec_return!(state, sp, mem0, mem0_len, instance)
328+
exec_return(state, sp, mem0, mem0_len, instance)
328329
}
329330

330331
macro_rules! handler_return {
@@ -341,7 +342,7 @@ macro_rules! handler_return {
341342
let (_ip, crate::ir::decode::$op { value }) = unsafe { decode_op(ip) };
342343
let value = get_value(value, sp);
343344
set_value(sp, Slot::from(0), $eval(value));
344-
exec_return!(state, sp, mem0, mem0_len, instance)
345+
exec_return(state, sp, mem0, mem0_len, instance)
345346
}
346347
)*
347348
};

crates/wasmi/src/engine/executor/handler/utils.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
use super::state::{mem0_bytes, Ip, Mem0Len, Mem0Ptr, Sp, VmState};
22
use crate::{
33
core::{CoreElementSegment, CoreGlobal, CoreMemory, CoreTable, ReadAs, UntypedVal, WriteAs},
4-
engine::{DedupFuncType, EngineFunc},
4+
engine::{
5+
executor::handler::{Done, DoneReason},
6+
DedupFuncType,
7+
EngineFunc,
8+
},
59
func::FuncEntity,
610
instance::InstanceEntity,
711
ir::{index, Address, BranchOffset, Offset16, Sign, Slot, SlotSpan},
@@ -124,19 +128,20 @@ macro_rules! impl_expand_to_result {
124128
}
125129
impl_expand_to_result!(bool, i32, i64, u32, u64, f32, f64);
126130

127-
macro_rules! exec_return {
128-
($state:expr, $sp:expr, $mem0:expr, $mem0_len:expr, $instance:expr) => {{
129-
let Some((ip, sp, mem0, mem0_len, instance)) =
130-
$state
131-
.stack
132-
.pop_frame(&mut $state.store, $mem0, $mem0_len, $instance)
133-
else {
134-
// No more frames on the call stack -> break out of execution!
135-
$state.done(DoneReason::Return($sp));
136-
return Done::control_break();
137-
};
138-
dispatch!($state, ip, sp, mem0, mem0_len, instance)
139-
}};
131+
pub fn exec_return(
132+
state: &mut VmState,
133+
sp: Sp,
134+
mem0: Mem0Ptr,
135+
mem0_len: Mem0Len,
136+
instance: NonNull<InstanceEntity>,
137+
) -> Done {
138+
let Some((ip, sp, mem0, mem0_len, instance)) =
139+
state.stack.pop_frame(state.store, mem0, mem0_len, instance)
140+
else {
141+
// No more frames on the call stack -> break out of execution!
142+
done!(state, DoneReason::Return(sp))
143+
};
144+
dispatch!(state, ip, sp, mem0, mem0_len, instance)
140145
}
141146

142147
pub fn exec_copy_span(sp: Sp, dst: SlotSpan, src: SlotSpan, len: u16) {

0 commit comments

Comments
 (0)