Commit e33bf6d1 authored by Tom Niget's avatar Tom Niget

Fix call_sync for bound methods

parent c307f373
......@@ -15,7 +15,6 @@
#include <typon/typon.hpp>
#ifdef __cpp_lib_unreachable
#include <utility>
[[noreturn]] inline void TYPON_UNREACHABLE() { std::unreachable(); }
......@@ -394,6 +393,21 @@ using InterpGuard = py::scoped_interpreter;
template <typename T>
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) {
if constexpr (HasSync<decltype(f)>) {
return f.sync(std::forward<decltype(args)>(args)...);
......@@ -407,6 +421,8 @@ auto call_sync(auto f) {
return [f](auto... args) {
return f.typon$$sync(std::forward<decltype(args)>(args)...);
};
} else if constexpr (HasBoundSync<decltype(f)>) {
return HasBoundSync_t<decltype(f)>{};
} else {
return f;
}
......@@ -425,20 +441,19 @@ struct {
using has_sync = std::true_type;
template <typename T>
auto typon$$sync(T value) const -> decltype(referencemodel::Rc(future(std::declval<Task<T>>())))
{
//return referencemodel::Rc(future(task));
auto typon$$sync(T value) const
-> decltype(referencemodel::Rc(future(std::declval<Task<T>>()))) {
// return referencemodel::Rc(future(task));
throw;
}
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)));
}
} static constexpr future_stdlib{};
}; // namespace typon
#endif // TYPON_BUILTINS_HPP
......@@ -6,8 +6,8 @@
namespace view = std::views;
#include <python/basedef.hpp>
#include "print.hpp"
#include <python/basedef.hpp>
namespace typon {
using namespace referencemodel;
......
......@@ -9,8 +9,8 @@
namespace view = std::views;
#include <python/basedef.hpp>
#include "int.hpp"
#include <python/basedef.hpp>
auto stride = [](int n) {
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