Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon-concurrency
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Xavier Thompson
typon-concurrency
Commits
3060d6c4
Commit
3060d6c4
authored
Mar 21, 2024
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix tuple constant access
parent
c9cb938b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
5 deletions
+17
-5
typon/include/python/builtins.hpp
typon/include/python/builtins.hpp
+10
-0
typon/trans/transpiler/phases/emit_cpp/expr.py
typon/trans/transpiler/phases/emit_cpp/expr.py
+7
-5
No files found.
typon/include/python/builtins.hpp
View file @
3060d6c4
...
...
@@ -406,4 +406,14 @@ auto call_sync(auto f) {
}
}
namespace
typon
{
template
<
auto
IDX
,
typename
T
>
auto
constant_get
(
T
&&
val
)
{
if
constexpr
(
requires
{
std
::
get
<
IDX
>
(
std
::
forward
<
T
>
(
val
));
})
{
return
std
::
get
<
IDX
>
(
std
::
forward
<
T
>
(
val
));
}
else
{
return
dot
(
std
::
forward
<
T
>
(
val
),
oo__getitem__oo
)(
IDX
);
}
}
};
// namespace typon
#endif // TYPON_BUILTINS_HPP
typon/trans/transpiler/phases/emit_cpp/expr.py
View file @
3060d6c4
...
...
@@ -336,14 +336,16 @@ class ExpressionVisitor(NodeVisitor):
if
isinstance
(
node
.
type
,
ClassTypeType
):
yield
from
self
.
visit_BaseType
(
node
.
type
.
inner_type
)
return
if
isinstance
(
node
.
value
.
type
,
TupleInstanceType
):
if
not
(
isinstance
(
node
.
slice
,
ast
.
Constant
)
and
isinstance
(
node
.
slice
.
value
,
int
)):
raise
NotImplementedError
(
"Tuple subscript with non-constant not handled yet"
)
yield
"std::get<"
if
isinstance
(
node
.
slice
,
ast
.
Constant
)
and
isinstance
(
node
.
slice
.
value
,
int
):
# when the index is a constant, we special case the emitted code so we can use std::get
# if the subscripted object is a tuple because tuples are not subscriptable in C++ because
# the language is statically typed
yield
"(co_await typon::constant_get<"
yield
str
(
node
.
slice
.
value
)
yield
">("
yield
from
self
.
visit
(
node
.
value
)
yield
")"
yield
")
)
"
return
# yield "("
# yield from self.visit(node.value)
...
...
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