Skip to content

Commit 180d1a3

Browse files
committed
Unwrap invoke_function
1 parent fba680b commit 180d1a3

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

lib/fizzy/execute.cpp

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,25 @@ bool invoke_function(const FuncType& func_type, const F& func, Instance& instanc
8080
inline bool invoke_function(const FuncType& func_type, uint32_t func_idx, Instance& instance,
8181
OperandStack& stack, int depth) noexcept
8282
{
83-
const auto func = [func_idx](Instance& _instance, span<const Value> args, int _depth) noexcept {
84-
return execute(_instance, func_idx, args, _depth);
85-
};
86-
return invoke_function(func_type, func, instance, stack, depth);
83+
const auto num_args = func_type.inputs.size();
84+
assert(stack.size() >= num_args);
85+
span<const Value> call_args{stack.rend() - num_args, num_args};
86+
stack.drop(num_args);
87+
88+
const auto ret = execute(instance, func_idx, call_args, depth + 1);
89+
// Bubble up traps
90+
if (ret.trapped)
91+
return false;
92+
93+
const auto num_outputs = func_type.outputs.size();
94+
// NOTE: we can assume these two from validation
95+
assert(num_outputs <= 1);
96+
assert(ret.has_value == (num_outputs == 1));
97+
// Push back the result
98+
if (num_outputs != 0)
99+
stack.push(ret.value);
100+
101+
return true;
87102
}
88103

89104
template <typename T>

0 commit comments

Comments
 (0)