Commit 8e1baff7 authored by Tom Niget's avatar Tom Niget

Define wrapper type for shared_ptr

parent 4ff63464
...@@ -23,6 +23,26 @@ ...@@ -23,6 +23,26 @@
using namespace std::literals; 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 // typon_len
template <typename T> template <typename T>
......
...@@ -59,7 +59,7 @@ class NodeVisitor(UniversalVisitor): ...@@ -59,7 +59,7 @@ class NodeVisitor(UniversalVisitor):
elif node is TY_STR: elif node is TY_STR:
yield "std::string" yield "std::string"
elif isinstance(node, UserType): elif isinstance(node, UserType):
yield f"std::shared_ptr<decltype({node.name})::type>" yield f"PyObj<decltype({node.name})>"
elif isinstance(node, TypeType): elif isinstance(node, TypeType):
yield "auto" # TODO yield "auto" # TODO
elif isinstance(node, Promise): elif isinstance(node, Promise):
......
...@@ -24,7 +24,7 @@ class ClassVisitor(NodeVisitor): ...@@ -24,7 +24,7 @@ class ClassVisitor(NodeVisitor):
yield "};" yield "};"
yield "template<typename... T> auto operator()(T&&... args) {" 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 "}" yield "}"
outer = ClassOuterVisitor(node.inner_scope) 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