Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tom Niget
typon
Commits
67c00f47
Commit
67c00f47
authored
Jun 13, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Define wrapper type for shared_ptr
parent
3ddf3249
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
2 deletions
+22
-2
rt/include/python/builtins.hpp
rt/include/python/builtins.hpp
+20
-0
trans/transpiler/phases/emit_cpp/__init__.py
trans/transpiler/phases/emit_cpp/__init__.py
+1
-1
trans/transpiler/phases/emit_cpp/class_.py
trans/transpiler/phases/emit_cpp/class_.py
+1
-1
No files found.
rt/include/python/builtins.hpp
View file @
67c00f47
...
...
@@ -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
>
...
...
trans/transpiler/phases/emit_cpp/__init__.py
View file @
67c00f47
...
...
@@ -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
):
...
...
trans/transpiler/phases/emit_cpp/class_.py
View file @
67c00f47
...
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment