From b250510d60d903788d599d87f2749b3aa160f947 Mon Sep 17 00:00:00 2001 From: Andrei Maiboroda Date: Tue, 20 Oct 2020 21:06:42 +0200 Subject: [PATCH] Simplify calls --- lib/fizzy/execute.cpp | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/lib/fizzy/execute.cpp b/lib/fizzy/execute.cpp index 956fbc5f1..e93d42a8c 100644 --- a/lib/fizzy/execute.cpp +++ b/lib/fizzy/execute.cpp @@ -481,15 +481,14 @@ void branch(const Code& code, OperandStack& stack, const Instr*& pc, const uint8 stack.drop(stack_drop); } -template -inline bool invoke_function( - const FuncType& func_type, const F& func, Instance& instance, OperandStack& stack, int depth) +inline bool invoke_function(const FuncType& func_type, uint32_t func_idx, Instance& instance, + OperandStack& stack, int depth) { const auto num_args = func_type.inputs.size(); assert(stack.size() >= num_args); const auto call_args = stack.rend() - num_args; - const auto ret = func(instance, call_args, depth + 1); + const auto ret = execute(instance, func_idx, call_args, depth + 1); // Bubble up traps if (ret.trapped) return false; @@ -507,14 +506,6 @@ inline bool invoke_function( return true; } -inline bool invoke_function(const FuncType& func_type, uint32_t func_idx, Instance& instance, - OperandStack& stack, int depth) -{ - const auto func = [func_idx](Instance& _instance, const Value* args, int _depth) { - return execute(_instance, func_idx, args, _depth); - }; - return invoke_function(func_type, func, instance, stack, depth); -} } // namespace ExecutionResult execute(Instance& instance, FuncIdx func_idx, const Value* args, int depth) @@ -643,12 +634,8 @@ ExecutionResult execute(Instance& instance, FuncIdx func_idx, const Value* args, if (expected_type != actual_type) goto trap; - // TODO simplify to get rid of lambda - const auto func = [&called_func](Instance&, const Value* called_args, int _depth) { - return execute(*called_func->instance, called_func->func_idx, called_args, _depth); - }; - - if (!invoke_function(actual_type, func, instance, stack, depth)) + if (!invoke_function( + actual_type, called_func->func_idx, *called_func->instance, stack, depth)) goto trap; break; }