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
19d31953
Commit
19d31953
authored
Mar 21, 2024
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Futures work
parent
4de648a2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
6 deletions
+21
-6
typon/trans/tests/naive_fibonacci_future.py
typon/trans/tests/naive_fibonacci_future.py
+0
-2
typon/trans/transpiler/phases/emit_cpp/expr.py
typon/trans/transpiler/phases/emit_cpp/expr.py
+21
-4
No files found.
typon/trans/tests/naive_fibonacci_future.py
View file @
19d31953
from
typon
import
future
def
fibo
(
n
):
def
fibo
(
n
):
if
n
<
2
:
if
n
<
2
:
return
n
return
n
...
...
typon/trans/transpiler/phases/emit_cpp/expr.py
View file @
19d31953
...
@@ -5,7 +5,7 @@ from typing import Iterable
...
@@ -5,7 +5,7 @@ from typing import Iterable
from
transpiler.phases.emit_cpp.visitors
import
NodeVisitor
,
CoroutineMode
,
join
from
transpiler.phases.emit_cpp.visitors
import
NodeVisitor
,
CoroutineMode
,
join
from
transpiler.phases.typing.scope
import
Scope
from
transpiler.phases.typing.scope
import
Scope
from
transpiler.phases.typing.types
import
ClassTypeType
,
TupleInstanceType
from
transpiler.phases.typing.types
import
ClassTypeType
,
TupleInstanceType
,
TY_FUTURE
,
ResolvedConcreteType
from
transpiler.phases.utils
import
make_lnd
from
transpiler.phases.utils
import
make_lnd
from
transpiler.utils
import
linenodata
from
transpiler.utils
import
linenodata
...
@@ -122,12 +122,12 @@ class ExpressionVisitor(NodeVisitor):
...
@@ -122,12 +122,12 @@ class ExpressionVisitor(NodeVisitor):
yield
")"
yield
")"
def
visit_Call
(
self
,
node
:
ast
.
Call
)
->
Iterable
[
str
]:
def
visit_Call
(
self
,
node
:
ast
.
Call
)
->
Iterable
[
str
]:
if
isinstance
(
node
.
func
,
ast
.
Name
)
and
node
.
func
.
id
==
"fork"
:
if
isinstance
(
node
.
func
,
ast
.
Name
)
and
node
.
func
.
id
in
(
"fork"
,
"future"
)
:
assert
len
(
node
.
args
)
==
1
assert
len
(
node
.
args
)
==
1
arg
=
node
.
args
[
0
]
arg
=
node
.
args
[
0
]
assert
isinstance
(
arg
,
ast
.
Lambda
)
assert
isinstance
(
arg
,
ast
.
Lambda
)
if
self
.
generator
!=
CoroutineMode
.
SYNC
:
if
self
.
generator
!=
CoroutineMode
.
SYNC
:
yield
"co_await typon::fork
("
yield
f"co_await typon::
{
node
.
func
.
id
}
("
assert
isinstance
(
arg
.
body
,
ast
.
Call
)
assert
isinstance
(
arg
.
body
,
ast
.
Call
)
yield
from
self
.
visit
(
arg
.
body
.
func
)
yield
from
self
.
visit
(
arg
.
body
.
func
)
yield
"("
yield
"("
...
@@ -138,12 +138,29 @@ class ExpressionVisitor(NodeVisitor):
...
@@ -138,12 +138,29 @@ class ExpressionVisitor(NodeVisitor):
yield
from
self
.
visit
(
arg
.
body
)
yield
from
self
.
visit
(
arg
.
body
)
return
return
# async : co_await f(args)
# async : co_await f(args)
# sync : call_sync(f, args)
# sync : call_sync(f, args)
if
self
.
generator
!=
CoroutineMode
.
SYNC
:
if
self
.
generator
!=
CoroutineMode
.
SYNC
:
yield
"co_await"
nty
=
node
.
type
.
resolve
()
if
not
(
isinstance
(
nty
,
ResolvedConcreteType
)
and
nty
.
inherits
(
TY_FUTURE
)):
yield
"co_await"
else
:
else
:
yield
"call_sync"
yield
"call_sync"
if
isinstance
(
node
.
func
,
ast
.
Attribute
)
and
node
.
func
.
attr
==
"get"
and
node
.
func
.
value
.
type
.
inherits
(
TY_FUTURE
):
yield
"("
if
self
.
generator
==
CoroutineMode
.
SYNC
:
yield
from
self
.
visit
(
node
.
func
.
value
)
else
:
yield
"("
yield
from
self
.
visit
(
node
.
func
.
value
)
yield
").get()"
yield
")"
return
yield
"("
yield
"("
yield
from
self
.
visit
(
node
.
func
)
yield
from
self
.
visit
(
node
.
func
)
yield
")("
yield
")("
...
...
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