15 statement_vector children;
17 formula_post_process_context::function_type super_function;
21 formula_post_process_context &context,
22 formula_node
const &function_declaration_expression) noexcept :
25 auto name_and_arguments = function_declaration_expression.get_name_and_argument_names();
26 hi_assert(name_and_arguments.size() >= 1);
28 name = name_and_arguments[0];
29 name_and_arguments.erase(name_and_arguments.begin());
30 argument_names =
std::move(name_and_arguments);
32 super_function = context.set_function(
33 name, [
this, &location](formula_evaluation_context &context, datum::vector_type
const &arguments) {
35 return this->evaluate_call(context, arguments);
38 throw operation_error(std::format(
"{}: Failed during handling of function call.\n{}", location, e.
what()));
51 void post_process(formula_post_process_context &context)
override
53 if (ssize(children) > 0) {
54 children.back()->left_align();
57 context.push_super(super_function);
58 for (hilet &child : children) {
59 child->post_process(context);
64 datum
evaluate(formula_evaluation_context &context)
override
69 datum evaluate_call(formula_evaluation_context &context, datum::vector_type
const &arguments)
72 if (ssize(argument_names) != ssize(arguments)) {
73 throw operation_error(std::format(
74 "{}: Invalid number of arguments to function {}() expecting {} got {}.",
77 argument_names.
size(),
81 for (ssize_t i = 0; i != ssize(argument_names); ++i) {
82 context.set(argument_names[i], arguments[i]);
85 hilet output_size = context.output_size();
86 auto tmp = evaluate_children(context, children);
90 throw operation_error(std::format(
"{}: Found #break not inside a loop statement.", location));
92 }
else if (tmp.is_continue()) {
93 throw operation_error(std::format(
"{}: Found #continue not inside a loop statement.", location));
95 }
else if (tmp.is_undefined()) {
100 context.set_output_size(output_size);
110 s += join(argument_names,
",");
bool append(std::unique_ptr< skeleton_node > x) noexcept override
Append a template-piece to the current template.
Definition skeleton_function_node.hpp:45