26#include <boost/python.hpp>
27#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
29#if BOOST_VERSION < 105600
30#include <boost/units/detail/utility.hpp>
31using boost::units::detail::demangle;
33using boost::core::demangle;
38#if BOOST_VERSION < 106300
46 return python::detail::none();
47 else if (shared_ptr_deleter* d = std::get_deleter<shared_ptr_deleter>(x))
48 return xincref(get_pointer(d->owner));
50 return converter::registered<std::shared_ptr<T>
const&>::converters.to_python(&x);
67 using NodeType = py::class_<Node<T>, boost::noncopyable>;
74 template <
typename To>
131 template <
typename Y>
141 template <
typename Y>
176#if PY_MAJOR_VERSION >= 3
177#define AS_BOOL_METHOD "__bool__"
179#define AS_BOOL_METHOD "__nonzero__"
182 py::make_function(
ExceptionRaiser<T>(
"Can not use variable placeholders in conditionals",
true),
183 py::default_call_policies(),
188 auto node_name =
std::string(
"Node<") + demangle(
typeid(T).name()) +
">";
189 NodeType node(node_name.c_str(),
"AST Node", py::no_init);
199 py::register_ptr_to_python<std::shared_ptr<Node<T>>>();
200#if BOOST_VERSION < 106300
208 auto placeholder_name =
std::string(
"Placeholder<") + demangle(
typeid(T).name()) +
">";
209 py::class_<Placeholder<T>, py::bases<Node<T>>>(placeholder_name.c_str(),
"Variable placeholder", py::no_init);
210 py::register_ptr_to_python<std::shared_ptr<Placeholder<T>>>();
218 template <
typename Content>
220 return py::object(c);
225 auto vi = attr_set.
find(name);
226 if (vi == attr_set.
end()) {
236 py::class_<Placeholder<AttributeSet>, boost::noncopyable> node(
"AttributeSet",
"AST Node", py::no_init);
239 py::register_ptr_to_python<std::shared_ptr<Placeholder<AttributeSet>>>();
246 py::class_<AttributeSet> attr_set(
"AttributeSet",
"Attribute set", py::no_init);
257 std::string scope = py::extract<std::string>(py::scope().attr(
"__name__"));
259 PyObject* excType = PyErr_NewException(
const_cast<char*
>(qname.
c_str()), PyExc_RuntimeError,
nullptr);
261 py::throw_error_already_set();
262 py::scope().attr(name.
c_str()) = py::handle<>(py::borrowed(excType));
289 py::class_<std::vector<double>>(
"_DoubleVector").def(py::vector_indexing_suite<
std::vector<double>>());
290 py::class_<std::vector<int64_t>>(
"_IntVector").def(py::vector_indexing_suite<
std::vector<int64_t>>());
UnaryWrapper< T, T, std::sqrt > Sqrt
Wraps the square root function.
UnaryWrapper< T, T, std::atan > ArcTan
Wraps the arctan function.
UnaryWrapper< T, T, std::exp2 > Exp2
Wraps the exponential, base 2, function.
PyObject * pyRecoverableError
UnaryWrapper< T, T, std::asin > ArcSin
Wraps the arcsin function.
UnaryWrapper< T, T, std::sin > Sin
Wraps the sin function.
UnaryWrapper< T, T, std::acosh > ArcCosh
Wraps the hyperbolic arccos function.
py::object attributeSetGetter(const AttributeSet &attr_set, const std::string &name)
UnaryWrapper< T, T, std::atanh > ArcTanh
Wraps the hyperbolic arctan function.
UnaryWrapper< T, T, std::cosh > Cosh
Wraps the hyperbolic cos function.
static boost::python::object makeFunction(const std::string &repr, std::function< Signature > functor)
UnaryWrapper< T, T, std::abs > Abs
Wraps the abs function.
void translateRecoverable(const RecoverableError &e)
void translateUnrecoverable(const UnrecoverableError &e)
UnaryWrapper< T, T, std::tan > Tan
Wraps the tan function.
std::map< std::string, Attribute > AttributeSet
UnaryWrapper< T, T, std::log2 > Log2
Wraps the log, base 2, function.
UnaryWrapper< T, T, std::round > Round
Wraps the round function.
UnaryWrapper< T, T, std::acos > ArcCos
Wraps the arcos function.
UnaryWrapper< T, T, std::log > Log
Wraps the log function.
UnaryWrapper< T, T, std::cos > Cos
Wraps the cos function.
UnaryWrapper< T, T, std::sinh > Sinh
Wraps the hyperbolic sin function.
BinaryWrapper< T, T, std::pow > Pow
Wraps the power function.
UnaryWrapper< T, T, std::exp > Exp
Wraps the exponential function.
BinaryWrapper< T, T, std::fmod > Fmod
Wraps fmod.
UnaryWrapper< T, T, std::log10 > Log10
Wraps the log, base 10, function.
static boost::python::object makeBinaryFunction(const std::string &repr, std::function< Signature > functor, bool reversed=false)
PyObject * pyUnrecoverableError
BinaryWrapper< T, T, std::atan2 > ArcTan2
Wraps atan2.
BOOST_PYTHON_MODULE(pyston)
static PyObject * createExceptionClass(const std::string &name)
UnaryWrapper< T, T, std::tanh > Tanh
Wraps the hyperbolic tan function.
UnaryWrapper< T, T, std::asinh > ArcSinh
Wraps the hyperbolic arcsin function.
void RegisterAttributeSet()
PyObject * shared_ptr_to_python(std::shared_ptr< T > const &x)
static void construct(PyObject *obj_ptr, boost::python::converter::rvalue_from_python_stage1_data *data)
static void * isConvertible(PyObject *obj_ptr)
static void specialized(NodeType &node, typename std::enable_if< std::is_floating_point< Y >::value >::type *=nullptr)
py::class_< Node< T >, boost::noncopyable > NodeType
static void specialized(NodeType &node, void *)
static void general(NodeType &node)
static void defCastOperations(NodeType &node)
static void specialized(NodeType &node, typename std::enable_if< std::is_integral< Y >::value &&!std::is_same< Y, bool >::value >::type *=nullptr)
static void specialized(NodeType &node, typename std::enable_if< std::is_same< Y, bool >::value >::type *=nullptr)
py::object operator()(Content c) const