diff --git a/include/zecalculator/evaluation/rpn/impl/evaluation.h b/include/zecalculator/evaluation/rpn/impl/evaluation.h index d3353465..0779a1c7 100644 --- a/include/zecalculator/evaluation/rpn/impl/evaluation.h +++ b/include/zecalculator/evaluation/rpn/impl/evaluation.h @@ -45,8 +45,6 @@ template template inline void Evaluator::operator()(const zc::parsing::node::rpn::Function& node) { - if (max_recursion_depth < current_recursion_depth) [[unlikely]] - expected_eval_stack = tl::unexpected(Error::recursion_depth_overflow()); if (not bool(node.f)) [[unlikely]] expected_eval_stack = tl::unexpected(Error::calling_invalid_function(node)); else @@ -73,26 +71,21 @@ template template inline void Evaluator::operator()(const zc::parsing::node::rpn::CppFunction& node) { - if (expected_eval_stack->size() < args_num) [[unlikely]] - expected_eval_stack = tl::unexpected(Error::mismatched_fun_args(node)); - else + // points on the before last value on the stack + const auto it = expected_eval_stack->end() - args_num; + + auto compute_overwrite_val = [&](std::integer_sequence) { - // points on the before last value on the stack - const auto it = expected_eval_stack->end() - args_num; - - auto compute_overwrite_val = [&](std::integer_sequence) - { - // since the function pops two elements, then pushes back one - // we can overwrite directly the value that will get replaced - *it = node.f(*(it+i)...); - }; - compute_overwrite_val(std::make_index_sequence()); - - // remove args_num-1 values from the stack, - // why the minus one: one value got overwritten with the computation result, as an optim - if constexpr (args_num >= 2) - expected_eval_stack->resize(expected_eval_stack->size() - (args_num - 1)); - } + // since the function pops two elements, then pushes back one + // we can overwrite directly the value that will get replaced + *it = node.f(*(it+i)...); + }; + compute_overwrite_val(std::make_index_sequence()); + + // remove args_num-1 values from the stack, + // why the minus one: one value got overwritten with the computation result, as an optim + if constexpr (args_num >= 2) + expected_eval_stack->resize(expected_eval_stack->size() - (args_num - 1)); } template @@ -101,8 +94,6 @@ inline void Evaluator::operator()(const zc::parsing::node::rpn::Sequ // std::cout << "Evaluating zc function: " << node.name << std::endl; if (not bool(node.u)) expected_eval_stack = tl::unexpected(Error::calling_invalid_function(node)); - else if (expected_eval_stack->empty()) - expected_eval_stack = tl::unexpected(Error::mismatched_fun_args(node)); else { // sequence handles only one argument