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
e643dbd0
Commit
e643dbd0
authored
Mar 16, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make fake function end unreachable so the compiler doesn't complain about missing return
parent
f964bee3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletion
+15
-1
rt/include/python/builtins.hpp
rt/include/python/builtins.hpp
+8
-0
trans/transpiler/__init__.py
trans/transpiler/__init__.py
+7
-1
No files found.
rt/include/python/builtins.hpp
View file @
e643dbd0
...
@@ -10,6 +10,14 @@
...
@@ -10,6 +10,14 @@
#include <ostream>
#include <ostream>
#include <string>
#include <string>
#ifdef __cpp_lib_unreachable
#include <utility>
[[
noreturn
]]
inline
void
TYPON_UNREACHABLE
()
{
std
::
unreachable
();
}
#else
#include <cstdlib>
[[
noreturn
]]
inline
void
TYPON_UNREACHABLE
()
{
std
::
abort
();
}
#endif
using
namespace
std
::
literals
;
using
namespace
std
::
literals
;
// typon_len
// typon_len
...
...
trans/transpiler/__init__.py
View file @
e643dbd0
...
@@ -408,9 +408,13 @@ class BlockVisitor(NodeVisitor):
...
@@ -408,9 +408,13 @@ class BlockVisitor(NodeVisitor):
return
result
return
result
except
UnsupportedNodeError
as
e
:
except
UnsupportedNodeError
as
e
:
if
isinstance
(
e
.
node
,
ast
.
Yield
):
if
isinstance
(
e
.
node
,
ast
.
Yield
):
return
chain
(
self
.
visit_func
(
node
,
CoroutineMode
.
FAKE
),
self
.
visit_func
(
node
,
CoroutineMode
.
GENERATOR
)
)
return
self
.
visit_coroutine
(
node
)
raise
raise
def
visit_coroutine
(
self
,
node
:
ast
.
FunctionDef
)
->
Iterable
[
str
]:
yield
from
self
.
visit_func
(
node
,
CoroutineMode
.
FAKE
)
yield
from
self
.
visit_func
(
node
,
CoroutineMode
.
GENERATOR
)
def
visit_func
(
self
,
node
:
ast
.
FunctionDef
,
generator
:
CoroutineMode
)
->
Iterable
[
str
]:
def
visit_func
(
self
,
node
:
ast
.
FunctionDef
,
generator
:
CoroutineMode
)
->
Iterable
[
str
]:
templ
,
args
,
names
=
self
.
process_args
(
node
.
args
)
templ
,
args
,
names
=
self
.
process_args
(
node
.
args
)
if
templ
:
if
templ
:
...
@@ -478,6 +482,8 @@ class BlockVisitor(NodeVisitor):
...
@@ -478,6 +482,8 @@ class BlockVisitor(NodeVisitor):
elif
decl
.
kind
in
(
VarKind
.
GLOBAL
,
VarKind
.
NONLOCAL
):
# `global` and `nonlocal` just get hoisted as-is.
elif
decl
.
kind
in
(
VarKind
.
GLOBAL
,
VarKind
.
NONLOCAL
):
# `global` and `nonlocal` just get hoisted as-is.
inner_scope
.
vars
[
var
]
=
decl
inner_scope
.
vars
[
var
]
=
decl
yield
from
child_code
# Yeet back the child node code.
yield
from
child_code
# Yeet back the child node code.
if
generator
==
CoroutineMode
.
FAKE
:
yield
"TYPON_UNREACHABLE();"
# So the compiler doesn't complain about missing return statements.
yield
"}"
yield
"}"
def
visit_lvalue
(
self
,
lvalue
:
ast
.
expr
,
val
:
Optional
[
ast
.
AST
]
=
None
)
->
Iterable
[
str
]:
def
visit_lvalue
(
self
,
lvalue
:
ast
.
expr
,
val
:
Optional
[
ast
.
AST
]
=
None
)
->
Iterable
[
str
]:
...
...
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