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
081e3685
Commit
081e3685
authored
Mar 19, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add basic coroutine+await support
parent
e643dbd0
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
155 additions
and
50 deletions
+155
-50
rt/include/python/builtins.hpp
rt/include/python/builtins.hpp
+3
-1
rt/include/python/builtins/print.hpp
rt/include/python/builtins/print.hpp
+22
-5
trans/tests/_gen_test.py
trans/tests/_gen_test.py
+0
-0
trans/tests/naive_fibonacci_fork.py
trans/tests/naive_fibonacci_fork.py
+8
-1
trans/transpiler/__init__.py
trans/transpiler/__init__.py
+122
-43
No files found.
rt/include/python/builtins.hpp
View file @
081e3685
...
@@ -10,6 +10,8 @@
...
@@ -10,6 +10,8 @@
#include <ostream>
#include <ostream>
#include <string>
#include <string>
#include <typon/typon.hpp>
#ifdef __cpp_lib_unreachable
#ifdef __cpp_lib_unreachable
#include <utility>
#include <utility>
[[
noreturn
]]
inline
void
TYPON_UNREACHABLE
()
{
std
::
unreachable
();
}
[[
noreturn
]]
inline
void
TYPON_UNREACHABLE
()
{
std
::
unreachable
();
}
...
@@ -58,7 +60,7 @@ std::ostream &operator<<(std::ostream &os, std::optional<T> const &opt) {
...
@@ -58,7 +60,7 @@ std::ostream &operator<<(std::ostream &os, std::optional<T> const &opt) {
return
opt
?
os
<<
opt
.
value
()
:
os
<<
"None"
;
return
opt
?
os
<<
opt
.
value
()
:
os
<<
"None"
;
}
}
bool
is_cpp
()
{
return
true
;
}
typon
::
Task
<
bool
>
is_cpp
()
{
co_
return
true
;
}
class
NoneType
{
class
NoneType
{
public:
public:
...
...
rt/include/python/builtins/print.hpp
View file @
081e3685
...
@@ -8,6 +8,8 @@
...
@@ -8,6 +8,8 @@
#include <iostream>
#include <iostream>
#include <ostream>
#include <ostream>
#include <typon/typon.hpp>
template
<
typename
T
>
template
<
typename
T
>
concept
Streamable
=
requires
(
const
T
&
x
,
std
::
ostream
&
s
)
{
concept
Streamable
=
requires
(
const
T
&
x
,
std
::
ostream
&
s
)
{
{
s
<<
x
}
->
std
::
same_as
<
std
::
ostream
&>
;
{
s
<<
x
}
->
std
::
same_as
<
std
::
ostream
&>
;
...
@@ -39,13 +41,28 @@ template <typename T>
...
@@ -39,13 +41,28 @@ template <typename T>
concept
Printable
=
requires
(
const
T
&
x
,
std
::
ostream
&
s
)
{
concept
Printable
=
requires
(
const
T
&
x
,
std
::
ostream
&
s
)
{
{
print_to
(
x
,
s
)
}
->
std
::
same_as
<
void
>
;
{
print_to
(
x
,
s
)
}
->
std
::
same_as
<
void
>
;
};
};
/*
template <Printable T, Printable... Args>
template <Printable T, Printable... Args>
void
print
(
T
const
&
head
,
Args
const
&
...
args
)
{
typon::Task<void> print(T const &head, Args const &...args) {
print_to(head, std::cout);
(((std::cout << ' '), print_to(args, std::cout)), ...);
std::cout << '\n'; co_return;
}*/
struct
{
void
sync
()
{
std
::
cout
<<
'\n'
;
}
template
<
Printable
T
,
Printable
...
Args
>
void
sync
(
T
const
&
head
,
Args
const
&
...
args
)
{
print_to
(
head
,
std
::
cout
);
print_to
(
head
,
std
::
cout
);
(((
std
::
cout
<<
' '
),
print_to
(
args
,
std
::
cout
)),
...);
(((
std
::
cout
<<
' '
),
print_to
(
args
,
std
::
cout
)),
...);
std
::
cout
<<
'\n'
;
std
::
cout
<<
'\n'
;
}
}
void
print
()
{
std
::
cout
<<
'\n'
;
}
template
<
Printable
...
Args
>
typon
::
Task
<
void
>
operator
()(
Args
const
&
...
args
)
{
co_return
sync
(
args
...);
}
}
print
;
//typon::Task<void> print() { std::cout << '\n'; co_return; }
#endif // TYPON_PRINT_HPP
#endif // TYPON_PRINT_HPP
trans/tests/gen_test.py
→
trans/tests/
_
gen_test.py
View file @
081e3685
File moved
trans/tests/naive_fibonacci_fork.py
View file @
081e3685
from
typon
import
fork
,
sync
from
typon
import
fork
,
sync
def
fibo
(
n
):
if
n
<
2
:
return
n
a
=
fibo
(
n
-
1
)
b
=
fibo
(
n
-
2
)
return
a
+
b
#def fibo(n: int) -> int:
#def fibo(n: int) -> int:
# if n < 2:
# if n < 2:
...
@@ -11,4 +18,4 @@ from typon import fork, sync
...
@@ -11,4 +18,4 @@ from typon import fork, sync
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
print
(
"res="
,
5
,
"."
)
print
(
fibo
(
30
))
# should display 832040
\ No newline at end of file
\ No newline at end of file
trans/transpiler/__init__.py
View file @
081e3685
This diff is collapsed.
Click to expand it.
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