Skip to content

Commit 30965cc

Browse files
committed
Pass only number of args to invoke_function()
1 parent bfd9543 commit 30965cc

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

lib/fizzy/execute.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -426,10 +426,9 @@ void branch(const Code& code, OperandStack& stack, const Instr*& pc, const uint8
426426
}
427427

428428
template <class F>
429-
inline bool invoke_function(const FuncType& func_type, const F& func, Instance& instance,
430-
OperandStack& stack, int depth) noexcept
429+
inline bool invoke_function(
430+
size_t num_args, const F& func, Instance& instance, OperandStack& stack, int depth) noexcept
431431
{
432-
const auto num_args = func_type.inputs.size();
433432
assert(stack.size() >= num_args);
434433
span<const Value> call_args{stack.rend() - num_args, num_args};
435434

@@ -447,13 +446,13 @@ inline bool invoke_function(const FuncType& func_type, const F& func, Instance&
447446
return true;
448447
}
449448

450-
inline bool invoke_function(const FuncType& func_type, uint32_t func_idx, Instance& instance,
451-
OperandStack& stack, int depth) noexcept
449+
inline bool invoke_function(
450+
size_t num_args, uint32_t func_idx, Instance& instance, OperandStack& stack, int depth) noexcept
452451
{
453452
const auto func = [func_idx](Instance& _instance, span<const Value> args, int _depth) noexcept {
454453
return execute(_instance, func_idx, args.data(), _depth);
455454
};
456-
return invoke_function(func_type, func, instance, stack, depth);
455+
return invoke_function(num_args, func, instance, stack, depth);
457456
}
458457
} // namespace
459458

@@ -557,9 +556,10 @@ ExecutionResult execute(Instance& instance, FuncIdx func_idx, const Value* args,
557556
case Instr::call:
558557
{
559558
const auto called_func_idx = read<uint32_t>(immediates);
560-
const auto& called_func_type = instance.module.get_function_type(called_func_idx);
559+
const auto called_func_num_args =
560+
instance.module.get_function_type(called_func_idx).inputs.size();
561561

562-
if (!invoke_function(called_func_type, called_func_idx, instance, stack, depth))
562+
if (!invoke_function(called_func_num_args, called_func_idx, instance, stack, depth))
563563
goto trap;
564564
break;
565565
}
@@ -584,7 +584,8 @@ ExecutionResult execute(Instance& instance, FuncIdx func_idx, const Value* args,
584584
if (expected_type != actual_type)
585585
goto trap;
586586

587-
if (!invoke_function(actual_type, called_func->function, instance, stack, depth))
587+
if (!invoke_function(
588+
actual_type.inputs.size(), called_func->function, instance, stack, depth))
588589
goto trap;
589590
break;
590591
}

0 commit comments

Comments
 (0)