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>
134 defCastOperations<double>(node);
135 defCastOperations<int64_t>(node);
141 template <
typename Y>
147 defCastOperations<double>(node);
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);
196 specialized<T>(node);
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>>());
PyObject * pyRecoverableError
py::object attributeSetGetter(const AttributeSet &attr_set, const std::string &name)
static boost::python::object makeFunction(const std::string &repr, std::function< Signature > functor)
void translateRecoverable(const RecoverableError &e)
void translateUnrecoverable(const UnrecoverableError &e)
static boost::python::object makeBinaryFunction(const std::string &repr, std::function< Signature > functor, bool reversed=false)
PyObject * pyUnrecoverableError
BOOST_PYTHON_MODULE(pyston)
static PyObject * createExceptionClass(const std::string &name)
void RegisterAttributeSet()
PyObject * shared_ptr_to_python(std::shared_ptr< T > const &x)
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