Functions: introduce multi-function namespace

This moves all multi-function related code in the `functions` module
into a new `multi_function` namespace. This is similar to how there
is a `lazy_function` namespace.

The main benefit of this is that many types names that were prefixed
with `MF` (for "multi function") can be simplified.

There is also a common shorthand for the `multi_function` namespace: `mf`.
This is also similar to lazy-functions where the shortened namespace
is called `lf`.
This commit is contained in:
2023-01-07 17:32:28 +01:00
parent a5b27f9858
commit eedcf1876a
87 changed files with 1437 additions and 1459 deletions

View File

@@ -2,65 +2,65 @@
#include "FN_multi_function_procedure_builder.hh"
namespace blender::fn {
namespace blender::fn::multi_function {
void MFProcedureBuilder::add_destruct(MFVariable &variable)
void ProcedureBuilder::add_destruct(Variable &variable)
{
MFDestructInstruction &instruction = procedure_->new_destruct_instruction();
DestructInstruction &instruction = procedure_->new_destruct_instruction();
instruction.set_variable(&variable);
this->link_to_cursors(&instruction);
cursors_ = {MFInstructionCursor{instruction}};
cursors_ = {InstructionCursor{instruction}};
}
void MFProcedureBuilder::add_destruct(Span<MFVariable *> variables)
void ProcedureBuilder::add_destruct(Span<Variable *> variables)
{
for (MFVariable *variable : variables) {
for (Variable *variable : variables) {
this->add_destruct(*variable);
}
}
MFReturnInstruction &MFProcedureBuilder::add_return()
ReturnInstruction &ProcedureBuilder::add_return()
{
MFReturnInstruction &instruction = procedure_->new_return_instruction();
ReturnInstruction &instruction = procedure_->new_return_instruction();
this->link_to_cursors(&instruction);
cursors_ = {};
return instruction;
}
MFCallInstruction &MFProcedureBuilder::add_call_with_no_variables(const MultiFunction &fn)
CallInstruction &ProcedureBuilder::add_call_with_no_variables(const MultiFunction &fn)
{
MFCallInstruction &instruction = procedure_->new_call_instruction(fn);
CallInstruction &instruction = procedure_->new_call_instruction(fn);
this->link_to_cursors(&instruction);
cursors_ = {MFInstructionCursor{instruction}};
cursors_ = {InstructionCursor{instruction}};
return instruction;
}
MFCallInstruction &MFProcedureBuilder::add_call_with_all_variables(
const MultiFunction &fn, Span<MFVariable *> param_variables)
CallInstruction &ProcedureBuilder::add_call_with_all_variables(const MultiFunction &fn,
Span<Variable *> param_variables)
{
MFCallInstruction &instruction = this->add_call_with_no_variables(fn);
CallInstruction &instruction = this->add_call_with_no_variables(fn);
instruction.set_params(param_variables);
return instruction;
}
Vector<MFVariable *> MFProcedureBuilder::add_call(const MultiFunction &fn,
Span<MFVariable *> input_and_mutable_variables)
Vector<Variable *> ProcedureBuilder::add_call(const MultiFunction &fn,
Span<Variable *> input_and_mutable_variables)
{
Vector<MFVariable *> output_variables;
MFCallInstruction &instruction = this->add_call_with_no_variables(fn);
Vector<Variable *> output_variables;
CallInstruction &instruction = this->add_call_with_no_variables(fn);
for (const int param_index : fn.param_indices()) {
const MFParamType param_type = fn.param_type(param_index);
const ParamType param_type = fn.param_type(param_index);
switch (param_type.interface_type()) {
case MFParamType::Input:
case MFParamType::Mutable: {
MFVariable *variable = input_and_mutable_variables.first();
case ParamType::Input:
case ParamType::Mutable: {
Variable *variable = input_and_mutable_variables.first();
instruction.set_param_variable(param_index, variable);
input_and_mutable_variables = input_and_mutable_variables.drop_front(1);
break;
}
case MFParamType::Output: {
MFVariable &variable = procedure_->new_variable(param_type.data_type(),
fn.param_name(param_index));
case ParamType::Output: {
Variable &variable = procedure_->new_variable(param_type.data_type(),
fn.param_name(param_index));
instruction.set_param_variable(param_index, &variable);
output_variables.append(&variable);
break;
@@ -72,26 +72,26 @@ Vector<MFVariable *> MFProcedureBuilder::add_call(const MultiFunction &fn,
return output_variables;
}
MFProcedureBuilder::Branch MFProcedureBuilder::add_branch(MFVariable &condition)
ProcedureBuilder::Branch ProcedureBuilder::add_branch(Variable &condition)
{
MFBranchInstruction &instruction = procedure_->new_branch_instruction();
BranchInstruction &instruction = procedure_->new_branch_instruction();
instruction.set_condition(&condition);
this->link_to_cursors(&instruction);
/* Clear cursors because this builder ends here. */
cursors_.clear();
Branch branch{*procedure_, *procedure_};
branch.branch_true.set_cursor(MFInstructionCursor{instruction, true});
branch.branch_false.set_cursor(MFInstructionCursor{instruction, false});
branch.branch_true.set_cursor(InstructionCursor{instruction, true});
branch.branch_false.set_cursor(InstructionCursor{instruction, false});
return branch;
}
MFProcedureBuilder::Loop MFProcedureBuilder::add_loop()
ProcedureBuilder::Loop ProcedureBuilder::add_loop()
{
MFDummyInstruction &loop_begin = procedure_->new_dummy_instruction();
MFDummyInstruction &loop_end = procedure_->new_dummy_instruction();
DummyInstruction &loop_begin = procedure_->new_dummy_instruction();
DummyInstruction &loop_end = procedure_->new_dummy_instruction();
this->link_to_cursors(&loop_begin);
cursors_ = {MFInstructionCursor{loop_begin}};
cursors_ = {InstructionCursor{loop_begin}};
Loop loop;
loop.begin = &loop_begin;
@@ -100,18 +100,18 @@ MFProcedureBuilder::Loop MFProcedureBuilder::add_loop()
return loop;
}
void MFProcedureBuilder::add_loop_continue(Loop &loop)
void ProcedureBuilder::add_loop_continue(Loop &loop)
{
this->link_to_cursors(loop.begin);
/* Clear cursors because this builder ends here. */
cursors_.clear();
}
void MFProcedureBuilder::add_loop_break(Loop &loop)
void ProcedureBuilder::add_loop_break(Loop &loop)
{
this->link_to_cursors(loop.end);
/* Clear cursors because this builder ends here. */
cursors_.clear();
}
} // namespace blender::fn
} // namespace blender::fn::multi_function