Skip to content

Commit

Permalink
Simplify calls
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Oct 21, 2020
1 parent cfd872b commit b044571
Showing 1 changed file with 5 additions and 18 deletions.
23 changes: 5 additions & 18 deletions lib/fizzy/execute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,15 +481,14 @@ void branch(const Code& code, OperandStack& stack, const Instr*& pc, const uint8
stack.drop(stack_drop);
}

template <class F>
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;
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit b044571

Please sign in to comment.