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
1f9e68f2
Commit
1f9e68f2
authored
Mar 14, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add basic support for generators (co_yield)
parent
776ac174
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
120 additions
and
25 deletions
+120
-25
rt/include/python/builtins.hpp
rt/include/python/builtins.hpp
+15
-0
rt/include/python/builtins/range.hpp
rt/include/python/builtins/range.hpp
+17
-0
trans/test_runner.py
trans/test_runner.py
+3
-0
trans/tests/gen_test.py
trans/tests/gen_test.py
+13
-0
trans/transpiler/__init__.py
trans/transpiler/__init__.py
+72
-25
No files found.
rt/include/python/builtins.hpp
View file @
1f9e68f2
...
@@ -33,6 +33,19 @@ concept PyLen = requires(const T &t) {
...
@@ -33,6 +33,19 @@ concept PyLen = requires(const T &t) {
template
<
PyLen
T
>
size_t
len
(
const
T
&
t
)
{
return
t
.
py_len
();
}
template
<
PyLen
T
>
size_t
len
(
const
T
&
t
)
{
return
t
.
py_len
();
}
template
<
typename
T
>
concept
PyNext
=
requires
(
T
t
)
{
t
.
py_next
();
};
template
<
PyNext
T
>
auto
next
(
T
&
t
)
{
return
t
.
py_next
();
}
template
<
typename
T
>
std
::
ostream
&
operator
<<
(
std
::
ostream
&
os
,
std
::
optional
<
T
>
const
&
opt
)
{
return
opt
?
os
<<
opt
.
value
()
:
os
<<
"None"
;
}
bool
is_cpp
()
{
return
true
;
}
bool
is_cpp
()
{
return
true
;
}
#include "builtins/bool.hpp"
#include "builtins/bool.hpp"
...
@@ -44,4 +57,6 @@ bool is_cpp() { return true; }
...
@@ -44,4 +57,6 @@ bool is_cpp() { return true; }
#include "builtins/set.hpp"
#include "builtins/set.hpp"
#include "builtins/str.hpp"
#include "builtins/str.hpp"
#include "../typon/generator.hpp"
#endif // TYPON_BUILTINS_HPP
#endif // TYPON_BUILTINS_HPP
rt/include/python/builtins/range.hpp
0 → 100644
View file @
1f9e68f2
//
// Created by Tom on 13/03/2023.
//
#ifndef TYPON_RANGE_HPP
#define TYPON_RANGE_HPP
#include <ranges>
// todo: proper range support
template
<
typename
T
>
auto
range
(
T
stop
)
{
return
std
::
views
::
iota
(
0
,
stop
);
}
template
<
typename
T
>
auto
range
(
T
start
,
T
stop
)
{
return
std
::
views
::
iota
(
start
,
stop
);
}
#endif // TYPON_RANGE_HPP
trans/test_runner.py
View file @
1f9e68f2
...
@@ -10,6 +10,9 @@ from transpiler.format import format_code
...
@@ -10,6 +10,9 @@ from transpiler.format import format_code
def
run_tests
():
def
run_tests
():
for
path
in
Path
(
'tests'
).
glob
(
'*.py'
):
for
path
in
Path
(
'tests'
).
glob
(
'*.py'
):
print
(
path
.
name
)
print
(
path
.
name
)
if
path
.
name
.
startswith
(
'_'
):
print
(
"Skipping"
)
continue
with
open
(
path
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
with
open
(
path
,
"r"
,
encoding
=
"utf-8"
)
as
f
:
res
=
format_code
(
transpile
(
f
.
read
()))
res
=
format_code
(
transpile
(
f
.
read
()))
name_cpp
=
path
.
with_suffix
(
'.cpp'
)
name_cpp
=
path
.
with_suffix
(
'.cpp'
)
...
...
trans/tests/gen_test.py
0 → 100644
View file @
1f9e68f2
# coding: utf-8
def
fib
():
a
=
0
b
=
1
while
True
:
yield
a
a
,
b
=
b
,
a
+
b
if
__name__
==
"__main__"
:
f
=
fib
()
for
i
in
range
(
10
):
print
(
next
(
f
))
\ No newline at end of file
trans/transpiler/__init__.py
View file @
1f9e68f2
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