Commit e3cc4548 authored by Tom Niget's avatar Tom Niget

Add basic coroutine+await support

parent 45014685
......@@ -10,6 +10,8 @@
#include <ostream>
#include <string>
#include <typon/typon.hpp>
#ifdef __cpp_lib_unreachable
#include <utility>
[[noreturn]] inline void TYPON_UNREACHABLE() { std::unreachable(); }
......@@ -58,7 +60,7 @@ std::ostream &operator<<(std::ostream &os, std::optional<T> const &opt) {
return opt ? os << opt.value() : os << "None";
}
bool is_cpp() { return true; }
typon::Task<bool> is_cpp() { co_return true; }
class NoneType {
public:
......
......@@ -8,6 +8,8 @@
#include <iostream>
#include <ostream>
#include <typon/typon.hpp>
template <typename T>
concept Streamable = requires(const T &x, std::ostream &s) {
{ s << x } -> std::same_as<std::ostream &>;
......@@ -39,13 +41,28 @@ template <typename T>
concept Printable = requires(const T &x, std::ostream &s) {
{ print_to(x, s) } -> std::same_as<void>;
};
/*
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';
}
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);
(((std::cout << ' '), print_to(args, std::cout)), ...);
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
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:
# if n < 2:
......@@ -11,4 +18,4 @@ from typon import fork, sync
if __name__ == "__main__":
print("res=", 5, ".")
\ No newline at end of file
print(fibo(30)) # should display 832040
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment