Alexandria 2.31.0
SDC-CH common library for the Euclid project
Loading...
Searching...
No Matches
Function.h
Go to the documentation of this file.
1
19#ifndef PYSTON_FUNCTION_H
20#define PYSTON_FUNCTION_H
21
22#include "Node.h"
23#include <functional>
24#include <memory>
25#include <string>
26#include <vector>
27
28namespace Pyston {
29
37template <typename R, typename... Args>
38class Function : public Node<R> {
39public:
40 using functor_t = std::function<R(const Context&, Args...)>;
42
52 Function(const std::string& repr_, std::function<R(const Context&, Args...)> functor,
53 const std::shared_ptr<Node<Args>>... args)
54 : m_repr(repr_), m_functor(functor), m_children(args...) {}
55
59 std::string repr() const final {
60 return m_repr;
61 }
62
66 R eval(const Context& context, const Arguments& args) const final;
67
71 void visit(Visitor& visitor) const final;
72
73private:
77};
78
79template <typename Signature>
81
90template <typename R, typename... Args>
91class FunctionFactory<R(Args...)> {
92public:
100 FunctionFactory(const std::string& repr, std::function<R(const Context&, Args...)> functor)
101 : m_repr(repr), m_functor(functor) {}
102
111 return std::make_shared<Function<R, Args...>>(m_repr, m_functor, nodes...);
112 }
113
114protected:
116 std::function<R(const Context&, Args...)> m_functor;
117};
118
119} // end of namespace Pyston
120
121#define PYSTON_GRAPH_FUNCTION_IMPL
122#include "_impl/Function.icpp"
123#undef PYSTON_GRAPH_FUNCTION_IMPL
124
125#endif // PYSTON_FUNCTION_H
std::shared_ptr< Node< R > > operator()(const std::shared_ptr< Node< Args > > &... nodes) const
Definition Function.h:110
std::function< R(const Context &, Args...)> m_functor
Definition Function.h:116
FunctionFactory(const std::string &repr, std::function< R(const Context &, Args...)> functor)
Definition Function.h:100
children_t m_children
Definition Function.h:76
functor_t m_functor
Definition Function.h:75
Function(const std::string &repr_, std::function< R(const Context &, Args...)> functor, const std::shared_ptr< Node< Args > >... args)
Definition Function.h:52
std::string m_repr
Definition Function.h:74
R eval(const Context &context, const Arguments &args) const final
void visit(Visitor &visitor) const final
std::string repr() const final
Definition Function.h:59
T make_shared(T... args)