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
acfcb8fd
Commit
acfcb8fd
authored
Aug 23, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Emit nested functions
parent
f2468418
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
6 deletions
+15
-6
trans/transpiler/phases/emit_cpp/block.py
trans/transpiler/phases/emit_cpp/block.py
+15
-6
No files found.
trans/transpiler/phases/emit_cpp/block.py
View file @
acfcb8fd
...
...
@@ -46,7 +46,9 @@ class BlockVisitor(NodeVisitor):
yield
ast
.
Return
()
from
transpiler.phases.emit_cpp.function
import
FunctionVisitor
yield
from
FunctionVisitor
(
self
.
scope
,
CoroutineMode
.
TASK
).
emit_block
(
node
.
scope
,
block
())
yield
"{"
yield
from
self
.
visit_func_decls
(
block
(),
node
.
scope
,
CoroutineMode
.
TASK
)
yield
"}"
return
if
emission
==
FunctionEmissionKind
.
DECLARATION
:
...
...
@@ -55,6 +57,17 @@ class BlockVisitor(NodeVisitor):
if
emission
==
FunctionEmissionKind
.
DECLARATION
:
yield
f"}}
{
node
.
name
}
;"
def
visit_func_decls
(
self
,
body
:
list
[
ast
.
stmt
],
inner_scope
:
Scope
,
mode
=
CoroutineMode
.
ASYNC
)
->
Iterable
[
str
]:
for
child
in
body
:
from
transpiler.phases.emit_cpp.function
import
FunctionVisitor
child_visitor
=
FunctionVisitor
(
inner_scope
,
mode
)
for
name
,
decl
in
getattr
(
child
,
"decls"
,
{}).
items
():
#yield f"decltype({' '.join(self.expr().visit(decl.type))}) {name};"
yield
from
self
.
visit
(
decl
.
type
)
yield
f"
{
name
}
;"
yield
from
child_visitor
.
visit
(
child
)
def
visit_func_new
(
self
,
node
:
ast
.
FunctionDef
,
emission
:
FunctionEmissionKind
,
skip_first_arg
:
bool
=
False
)
->
Iterable
[
str
]:
if
emission
==
FunctionEmissionKind
.
LAMBDA
:
yield
"[&]"
...
...
@@ -117,11 +130,7 @@ class BlockVisitor(NodeVisitor):
from
transpiler.phases.emit_cpp.function
import
FunctionVisitor
child_visitor
=
FunctionVisitor
(
inner_scope
,
CoroutineMode
.
ASYNC
)
for
name
,
decl
in
getattr
(
child
,
"decls"
,
{}).
items
():
#yield f"decltype({' '.join(self.expr().visit(decl.type))}) {name};"
yield
from
self
.
visit
(
decl
.
type
)
yield
f"
{
name
}
;"
yield
from
child_visitor
.
visit
(
child
)
yield
from
self
.
visit_func_decls
(
node
.
body
,
inner_scope
)
if
not
has_return
and
isinstance
(
node
.
type
.
return_type
,
Promise
):
yield
"co_return;"
...
...
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