From 7af8a19e2f18d3777f366237a9d295d429b21523 Mon Sep 17 00:00:00 2001 From: Adrian Conlon Date: Fri, 17 Dec 2021 09:19:16 +0000 Subject: [PATCH] Coroutine generator becomes a part of the core EightBit library. --- M6502/HarteTest_6502/HarteTest_6502.vcxproj | 1 - .../HarteTest_6502.vcxproj.filters | 3 -- M6502/HarteTest_6502/opcode_test_suite_t.cpp | 4 +-- M6502/HarteTest_6502/opcode_test_suite_t.h | 10 ++---- .../HarteTest_6502/processor_test_suite_t.cpp | 6 +--- M6502/HarteTest_6502/processor_test_suite_t.h | 8 ++--- M6502/HarteTest_6502/stdafx.h | 3 +- M6502/HarteTest_6502/tests.cpp | 35 ------------------- .../HarteTest_6502 => inc}/co_generator_t.h | 7 ++-- src/EightBit.vcxproj | 1 + src/EightBit.vcxproj.filters | 3 ++ src/stdafx.h | 1 + 12 files changed, 16 insertions(+), 66 deletions(-) rename {M6502/HarteTest_6502 => inc}/co_generator_t.h (96%) diff --git a/M6502/HarteTest_6502/HarteTest_6502.vcxproj b/M6502/HarteTest_6502/HarteTest_6502.vcxproj index 7eb9da1..e5974a7 100644 --- a/M6502/HarteTest_6502/HarteTest_6502.vcxproj +++ b/M6502/HarteTest_6502/HarteTest_6502.vcxproj @@ -185,7 +185,6 @@ - diff --git a/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters b/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters index d1e5904..df774bc 100644 --- a/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters +++ b/M6502/HarteTest_6502/HarteTest_6502.vcxproj.filters @@ -100,9 +100,6 @@ Header Files - - Header Files - Header Files diff --git a/M6502/HarteTest_6502/opcode_test_suite_t.cpp b/M6502/HarteTest_6502/opcode_test_suite_t.cpp index 91b7643..0a19628 100644 --- a/M6502/HarteTest_6502/opcode_test_suite_t.cpp +++ b/M6502/HarteTest_6502/opcode_test_suite_t.cpp @@ -4,9 +4,7 @@ opcode_test_suite_t::opcode_test_suite_t(const std::string path) noexcept : parser_t(path) {} -#ifdef USE_COROUTINES -co_generator_t opcode_test_suite_t::generator() { +EightBit::co_generator_t opcode_test_suite_t::generator() { for (const auto element : *this) co_yield test_t(element); } -#endif \ No newline at end of file diff --git a/M6502/HarteTest_6502/opcode_test_suite_t.h b/M6502/HarteTest_6502/opcode_test_suite_t.h index b358b10..0e32687 100644 --- a/M6502/HarteTest_6502/opcode_test_suite_t.h +++ b/M6502/HarteTest_6502/opcode_test_suite_t.h @@ -2,13 +2,11 @@ #include +#include + #include "parser_t.h" #include "test_t.h" -#ifdef USE_COROUTINES -#include "co_generator_t.h" -#endif - class opcode_test_suite_t final : public parser_t { private: [[nodiscard]] auto array() const noexcept { return raw().get_array(); } @@ -20,7 +18,5 @@ public: [[nodiscard]] auto begin() const noexcept { return array().begin(); } [[nodiscard]] auto end() const noexcept { return array().end(); } -#ifdef USE_COROUTINES - co_generator_t generator(); -#endif + EightBit::co_generator_t generator(); }; diff --git a/M6502/HarteTest_6502/processor_test_suite_t.cpp b/M6502/HarteTest_6502/processor_test_suite_t.cpp index 4f60063..2a06842 100644 --- a/M6502/HarteTest_6502/processor_test_suite_t.cpp +++ b/M6502/HarteTest_6502/processor_test_suite_t.cpp @@ -1,18 +1,14 @@ #include "stdafx.h" #include "processor_test_suite_t.h" -#ifdef USE_COROUTINES #include -#endif processor_test_suite_t::processor_test_suite_t(std::string location) noexcept : m_location(location) { } -#ifdef USE_COROUTINES -co_generator_t processor_test_suite_t::generator() { +EightBit::co_generator_t processor_test_suite_t::generator() { std::filesystem::path directory = location(); for (const auto& entry : std::filesystem::directory_iterator{ directory }) co_yield opcode_test_suite_t(entry.path().string()); } -#endif diff --git a/M6502/HarteTest_6502/processor_test_suite_t.h b/M6502/HarteTest_6502/processor_test_suite_t.h index 191e6d9..b2f0bc7 100644 --- a/M6502/HarteTest_6502/processor_test_suite_t.h +++ b/M6502/HarteTest_6502/processor_test_suite_t.h @@ -3,9 +3,7 @@ #include #include -#ifdef USE_COROUTINES -#include "co_generator_t.h" -#endif +#include #include "opcode_test_suite_t.h" @@ -18,7 +16,5 @@ public: std::string_view location() const noexcept { return m_location; } -#ifdef USE_COROUTINES - co_generator_t generator(); -#endif + EightBit::co_generator_t generator(); }; diff --git a/M6502/HarteTest_6502/stdafx.h b/M6502/HarteTest_6502/stdafx.h index 5fefad5..6a06d44 100644 --- a/M6502/HarteTest_6502/stdafx.h +++ b/M6502/HarteTest_6502/stdafx.h @@ -21,7 +21,6 @@ #include #include #include +#include #include "simdjson/simdjson.h" - -#define USE_COROUTINES diff --git a/M6502/HarteTest_6502/tests.cpp b/M6502/HarteTest_6502/tests.cpp index 404f67a..7d6a38b 100644 --- a/M6502/HarteTest_6502/tests.cpp +++ b/M6502/HarteTest_6502/tests.cpp @@ -26,8 +26,6 @@ int main() { checker_t checker(runner); checker.initialise(); -#ifdef USE_COROUTINES - processor_test_suite_t m6502_tests(directory); auto opcode_generator = m6502_tests.generator(); while (opcode_generator) { @@ -58,39 +56,6 @@ int main() { } } -#else - - std::filesystem::path location = directory; - - for (const auto& entry : std::filesystem::directory_iterator{ location }) { - - const auto& path = entry.path(); - - std::cout << "Processing: " << path.filename() << "\n"; - opcode_test_suite_t opcode(path.string()); - opcode.load(); - - for (const auto opcode_test_element : opcode) { - - const auto test = test_t(opcode_test_element); - checker.check(test); - - if (checker.invalid()) { - ++invalid_opcode_count; - if (checker.unimplemented()) - ++unimplemented_opcode_count; - if (checker.undocumented()) - ++undocumented_opcode_count; - std::cout << "** Failed: " << test.name() << "\n"; - for (const auto& message : checker.messages()) - std::cout << "**** " << message << "\n"; - break; - } - } - } - -#endif - const auto finish_time = std::chrono::steady_clock::now(); const auto elapsed_time = finish_time - start_time; const auto seconds = std::chrono::duration_cast>(elapsed_time).count(); diff --git a/M6502/HarteTest_6502/co_generator_t.h b/inc/co_generator_t.h similarity index 96% rename from M6502/HarteTest_6502/co_generator_t.h rename to inc/co_generator_t.h index f471a47..412bebf 100644 --- a/M6502/HarteTest_6502/co_generator_t.h +++ b/inc/co_generator_t.h @@ -1,12 +1,12 @@ #pragma once -#ifdef USE_COROUTINES - #include #include // from https://www.scs.stanford.edu/~dm/blog/c++-coroutines.html +namespace EightBit { + template struct co_generator_t final { @@ -57,5 +57,4 @@ private: } } }; - -#endif // USE_COROUTINES \ No newline at end of file +} diff --git a/src/EightBit.vcxproj b/src/EightBit.vcxproj index 6c41c2e..246e6cc 100644 --- a/src/EightBit.vcxproj +++ b/src/EightBit.vcxproj @@ -148,6 +148,7 @@ + diff --git a/src/EightBit.vcxproj.filters b/src/EightBit.vcxproj.filters index 905720c..df28b78 100644 --- a/src/EightBit.vcxproj.filters +++ b/src/EightBit.vcxproj.filters @@ -77,6 +77,9 @@ Header Files + + Header Files + diff --git a/src/stdafx.h b/src/stdafx.h index 3442d95..2f99750 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -3,6 +3,7 @@ #endif #include +#include #include #include #include