From f61014d99d1fffe6beed9a891ecf2e6515cc9ca2 Mon Sep 17 00:00:00 2001 From: Klemens Date: Sun, 10 Mar 2024 14:21:41 +0800 Subject: [PATCH] first step on custom coro frame hacking. --- .drone.star | 1 + include/boost/cobalt/experimental/fiber.hpp | 38 +++++++++++++++++++++ test/CMakeLists.txt | 7 +++- test/Jamfile.jam | 1 + test/experimental/fiber.cpp | 27 +++++++++++++++ 5 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 include/boost/cobalt/experimental/fiber.hpp create mode 100644 test/experimental/fiber.cpp diff --git a/.drone.star b/.drone.star index d507de30..aa7cd95f 100644 --- a/.drone.star +++ b/.drone.star @@ -18,6 +18,7 @@ deps = [ 'libs/concept_check', 'libs/config', 'libs/container', + 'libs/context', 'libs/core', 'libs/date_time', 'libs/detail', diff --git a/include/boost/cobalt/experimental/fiber.hpp b/include/boost/cobalt/experimental/fiber.hpp new file mode 100644 index 00000000..0605ec40 --- /dev/null +++ b/include/boost/cobalt/experimental/fiber.hpp @@ -0,0 +1,38 @@ +// Copyright (c) 2023 Klemens D. Morgenstern +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) +#ifndef BOOST_COBALT_FIBER_HPP +#define BOOST_COBALT_FIBER_HPP + +#include + +// this is all UB according to the standard. BUT it shouldn't be! + +namespace boost::cobalt::experimental +{ + +namespace detail +{ + +struct fiber_promise +{ + +}; + +struct fiber_frame +{ + void (*resume_) (fiber_frame *) = +[](fiber_frame * ff) { ff->resume();}; + void (*destroy_)(fiber_frame *) = +[](fiber_frame * ff) { ff->destroy();}; + + fiber_promise promise; + + void resume() {} + void destroy() {} +}; + +} + +} + +#endif //BOOST_COBALT_FIBER_HPP diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 032ff54b..928a65da 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -21,4 +21,9 @@ add_test(NAME boost_cobalt_main COMMAND boost_cobalt_main) add_test(NAME boost_cobalt_basic_tests COMMAND boost_cobalt_basic_tests) target_compile_features(boost_cobalt PUBLIC cxx_std_20) -add_dependencies(tests boost_cobalt_main boost_cobalt_basic_tests boost_cobalt_static_tests) + +add_executable(boost_cobalt_experimental test_main.cpp experimental/fiber.cpp) +target_link_libraries(boost_cobalt_experimental Boost::cobalt Boost::unit_test_framework Boost::context) +add_test(NAME boost_cobalt_experimental COMMAND boost_cobalt_experimental) + +add_dependencies(tests boost_cobalt_main boost_cobalt_basic_tests boost_cobalt_static_tests boost_cobalt_experimental) diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 450c8ea4..34b96dd6 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -32,3 +32,4 @@ for local src in [ glob *.cpp : main.cpp main_compile.cpp test_main.cpp concepts run $(src) test_impl ; } +run experimental/fiber.cpp test_impl ; \ No newline at end of file diff --git a/test/experimental/fiber.cpp b/test/experimental/fiber.cpp new file mode 100644 index 00000000..e43c4d69 --- /dev/null +++ b/test/experimental/fiber.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2023 Klemens D. Morgenstern +// +// Distributed under the Boost Software License, Version 1.0. (See accompanying +// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +#include + +#include "../test.hpp" + +BOOST_AUTO_TEST_SUITE(fiber); + +BOOST_AUTO_TEST_CASE(basics) +{ + boost::cobalt::experimental::detail::fiber_frame ff; + + using pro = boost::cobalt::experimental::detail::fiber_promise; + auto hh = std::coroutine_handle::from_address(&ff); + BOOST_CHECK(!hh.done()); + ff.resume_ = nullptr; + BOOST_CHECK(hh.done()); + + BOOST_CHECK(&ff.promise == &hh.promise()); + BOOST_CHECK(std::coroutine_handle::from_promise(ff.promise).address() == &ff); +} + + +BOOST_AUTO_TEST_SUITE_END(); \ No newline at end of file