Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon-compiler
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
typon
typon-compiler
Commits
45014685
Commit
45014685
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
37e3c944
Changes
2
Hide 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 @
45014685
...
...
@@ -10,6 +10,14 @@
#include <ostream>
#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
;
// typon_len
...
...
trans/transpiler/__init__.py
View file @
45014685
...
...
@@ -408,9 +408,13 @@ class BlockVisitor(NodeVisitor):
return
result
except
UnsupportedNodeError
as
e
:
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
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
]:
templ
,
args
,
names
=
self
.
process_args
(
node
.
args
)
if
templ
:
...
...
@@ -478,6 +482,8 @@ class BlockVisitor(NodeVisitor):
elif
decl
.
kind
in
(
VarKind
.
GLOBAL
,
VarKind
.
NONLOCAL
):
# `global` and `nonlocal` just get hoisted as-is.
inner_scope
.
vars
[
var
]
=
decl
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
"}"
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