Alexandria  2.25.0
SDC-CH common library for the Euclid project
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
28 namespace Pyston {
29 
37 template <typename R, typename... Args>
38 class Function : public Node<R> {
39 public:
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 
73 private:
77 };
78 
79 template <typename Signature>
81 
90 template <typename R, typename... Args>
91 class FunctionFactory<R(Args...)> {
92 public:
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 
114 protected:
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::string repr() const final
Definition: Function.h:59
std::shared_ptr< Node< R > > operator()(const std::shared_ptr< Node< Args >> &...nodes) const
Definition: Function.h:110
STL class.
STL class.
R eval(const Context &context, const Arguments &args) const final
children_t m_children
Definition: Function.h:76
void visit(Visitor &visitor) const final
std::function< R(const Context &, Args...)> m_functor
Definition: Function.h:116
STL class.
std::string m_repr
Definition: Function.h:74
T make_shared(T...args)
Function(const std::string &repr_, std::function< R(const Context &, Args...)> functor, const std::shared_ptr< Node< Args >>...args)
Definition: Function.h:52
functor_t m_functor
Definition: Function.h:75