Commit 67c00f47 authored by Tom Niget's avatar Tom Niget

Define wrapper type for shared_ptr

parent 3ddf3249
......@@ -23,6 +23,26 @@
using namespace std::literals;
template<typename T>
concept PyUserType = requires { typename T::type; };
template<typename T>
struct RealType {
using type = T;
};
template<PyUserType T>
struct RealType<T> {
using type = typename T::type;
};
template <typename T> using PyObj = std::shared_ptr<typename RealType<T>::type>;
template <typename T, typename... Args>
auto pyobj(Args &&... args) -> PyObj<T> {
return std::make_shared<typename RealType<T>::type>(std::forward<Args>(args)...);
}
// typon_len
template <typename T>
......
......@@ -59,7 +59,7 @@ class NodeVisitor(UniversalVisitor):
elif node is TY_STR:
yield "std::string"
elif isinstance(node, UserType):
yield f"std::shared_ptr<decltype({node.name})::type>"
yield f"PyObj<decltype({node.name})>"
elif isinstance(node, TypeType):
yield "auto" # TODO
elif isinstance(node, Promise):
......
......@@ -24,7 +24,7 @@ class ClassVisitor(NodeVisitor):
yield "};"
yield "template<typename... T> auto operator()(T&&... args) {"
yield "return std::make_shared<type>(std::forward<T>(args)...);"
yield "return pyobj<type>(std::forward<T>(args)...);"
yield "}"
outer = ClassOuterVisitor(node.inner_scope)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment