Commit e33bf6d1 authored by Tom Niget's avatar Tom Niget

Fix call_sync for bound methods

parent c307f373
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include <typon/typon.hpp> #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(); }
...@@ -394,6 +393,21 @@ using InterpGuard = py::scoped_interpreter; ...@@ -394,6 +393,21 @@ using InterpGuard = py::scoped_interpreter;
template <typename T> template <typename T>
concept HasSync = requires(T t) { typename T::has_sync; }; concept HasSync = requires(T t) { typename T::has_sync; };
template <typename T> struct HasBoundSync_t {
static constexpr bool value = false;
};
template <typename S, typename F> struct HasBoundSync_t<referencemodel::boundmethod<S, F>> {
static constexpr bool value = HasSync<F>;
auto operator()(auto... args) {
return F{}.typon$$sync(S{}, std::forward<decltype(args)>(args)...);
}
};
template <typename T>
concept HasBoundSync = HasBoundSync_t<T>::value;
/*auto call_sync(auto f, auto... args) { /*auto call_sync(auto f, auto... args) {
if constexpr (HasSync<decltype(f)>) { if constexpr (HasSync<decltype(f)>) {
return f.sync(std::forward<decltype(args)>(args)...); return f.sync(std::forward<decltype(args)>(args)...);
...@@ -407,6 +421,8 @@ auto call_sync(auto f) { ...@@ -407,6 +421,8 @@ auto call_sync(auto f) {
return [f](auto... args) { return [f](auto... args) {
return f.typon$$sync(std::forward<decltype(args)>(args)...); return f.typon$$sync(std::forward<decltype(args)>(args)...);
}; };
} else if constexpr (HasBoundSync<decltype(f)>) {
return HasBoundSync_t<decltype(f)>{};
} else { } else {
return f; return f;
} }
...@@ -422,23 +438,22 @@ template <auto IDX, typename T> auto constant_get(T &&val) { ...@@ -422,23 +438,22 @@ template <auto IDX, typename T> auto constant_get(T &&val) {
} }
struct { struct {
using has_sync = std::true_type; using has_sync = std::true_type;
template <typename T> template <typename T>
auto typon$$sync(T value) const -> decltype(referencemodel::Rc(future(std::declval<Task<T>>()))) auto typon$$sync(T value) const
{ -> decltype(referencemodel::Rc(future(std::declval<Task<T>>()))) {
//return referencemodel::Rc(future(task)); // return referencemodel::Rc(future(task));
throw; throw;
} }
template <typename Task> template <typename Task>
auto operator()(Task task) const -> typon::Task<decltype(referencemodel::Rc(future(std::move(task))))> auto operator()(Task task) const
{ -> typon::Task<decltype(referencemodel::Rc(future(std::move(task))))> {
co_return referencemodel::Rc(co_await future(std::move(task))); co_return referencemodel::Rc(co_await future(std::move(task)));
} }
} static constexpr future_stdlib{}; } static constexpr future_stdlib{};
}; // namespace typon }; // namespace typon
#endif // TYPON_BUILTINS_HPP #endif // TYPON_BUILTINS_HPP
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
namespace view = std::views; namespace view = std::views;
#include <python/basedef.hpp>
#include "print.hpp" #include "print.hpp"
#include <python/basedef.hpp>
namespace typon { namespace typon {
using namespace referencemodel; using namespace referencemodel;
...@@ -40,7 +40,7 @@ struct TyMutex__oo : classtype<_Base0, TyMutex__oo<>> { ...@@ -40,7 +40,7 @@ struct TyMutex__oo : classtype<_Base0, TyMutex__oo<>> {
auto typon$$sync(auto, auto) -> TyNone const { return None; } auto typon$$sync(auto, auto) -> TyNone const { return None; }
auto operator()(auto _self, auto callback) -> typon::Task<TyNone> const { auto operator()(auto _self, auto callback) -> typon::Task<TyNone> const {
print("1"_ps); print("1"_ps);
auto self = arc(_self); auto self = arc(_self);
print("2"_ps); print("2"_ps);
auto lock = dot(self, mutex).lock(); auto lock = dot(self, mutex).lock();
......
...@@ -9,8 +9,8 @@ ...@@ -9,8 +9,8 @@
namespace view = std::views; namespace view = std::views;
#include <python/basedef.hpp>
#include "int.hpp" #include "int.hpp"
#include <python/basedef.hpp>
auto stride = [](int n) { auto stride = [](int n) {
return [s = -1, n](auto const &) mutable { return [s = -1, n](auto const &) mutable {
......
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