-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add-returnning-value-functiom-to-program (#688)
ReturningValueProgram provide the ability to build a program based on a returning value function.
- Loading branch information
Showing
4 changed files
with
177 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <functional> | ||
#include "icicle/program/symbol.h" | ||
#include "icicle/program/program.h" | ||
|
||
namespace icicle { | ||
|
||
/** | ||
* @brief A class that convert the function with inputs and return value described by user into a program that can be | ||
* executed. | ||
*/ | ||
|
||
template <typename S> | ||
class ReturningValueProgram : public Program<S> | ||
{ | ||
public: | ||
// Generate a program based on a lambda function with multiple inputs and 1 output as a return value | ||
ReturningValueProgram(std::function<Symbol<S>(std::vector<Symbol<S>>&)> program_func, int nof_inputs) | ||
{ | ||
this->m_nof_parameters = nof_inputs + 1; | ||
std::vector<Symbol<S>> program_parameters(this->m_nof_parameters); | ||
this->set_as_inputs(program_parameters); | ||
program_parameters[nof_inputs] = program_func(program_parameters); // place the output after the all inputs | ||
this->generate_program(program_parameters); | ||
} | ||
|
||
// Generate a program based on a PreDefinedPrograms | ||
ReturningValueProgram(PreDefinedPrograms pre_def) : Program<S>(pre_def) {} | ||
}; | ||
} // namespace icicle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters