From 72662f374272481848e3d98e87ddb35c0baa0aa3 Mon Sep 17 00:00:00 2001 From: light7734 Date: Mon, 17 Nov 2025 13:17:05 +0330 Subject: [PATCH] wip: feat: lsd --- modules/CMakeLists.txt | 13 ++++++----- modules/logger/logger.cppm | 24 ++++++++++---------- modules/lsd/arr.cppm | 1 + modules/lsd/literals.cppm | 12 ++++++++++ modules/lsd/lsd.cppm | 3 ++- modules/lsd/primitives.cppm | 2 ++ modules/lsd/span.cppm | 6 +++++ modules/lsd/str.cppm | 1 - modules/lsd/utils.cppm | 32 +++++++++++++++++++++++++++ modules/test/entrypoint.cpp | 44 +++++++++++++++++++++---------------- 10 files changed, 98 insertions(+), 40 deletions(-) create mode 100644 modules/lsd/literals.cppm create mode 100644 modules/lsd/span.cppm create mode 100644 modules/lsd/utils.cppm diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index db1762e..29d34be 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -8,7 +8,9 @@ add_module( arr.cppm str.cppm set.cppm + span.cppm hash.cppm + utils.cppm scope.cppm bitwise.cppm thread.cppm @@ -16,12 +18,6 @@ add_module( src_location.cppm ) add_module(NAME logger INTERFACES logger.cppm DEPENDENCIES lsd) -return() -add_module(NAME bitwise INTERFACES operations.cppm) -add_module(NAME env INTERFACES constants.cppm) -add_module(NAME memory INTERFACES null_on_move.cppm reference.cppm scope.cppm) -add_module(NAME time INTERFACES timer.cppm) - add_module( NAME test @@ -32,8 +28,13 @@ add_module( SOURCES entrypoint.cpp DEPENDENCIES + lsd logger ) +return() +add_module(NAME env INTERFACES constants.cppm) +add_module(NAME memory INTERFACES null_on_move.cppm reference.cppm scope.cppm) +add_module(NAME time INTERFACES timer.cppm) add_module( NAME diff --git a/modules/logger/logger.cppm b/modules/logger/logger.cppm index 9a419cc..b962d93 100644 --- a/modules/logger/logger.cppm +++ b/modules/logger/logger.cppm @@ -1,6 +1,4 @@ export module logger; - -import std; import lsd; namespace lt::log { @@ -64,16 +62,16 @@ struct [[maybe_unused]] print } // clang-format on - std::unreachable(); + lsd::unreachable(); }; - const auto path = std::filesystem::path { location.file_name() }; + const auto path = lsd::filesystem::path { location.file_name() }; - std::println( + lsd::println( "{} {} ==> {}", to_string(level, location), - std::format("{}:{}", path.filename().string(), location.line()), - std::format(format, std::forward(arguments)...) + lsd::format("{}:{}", path.filename().string(), location.line()), + lsd::format(format, lsd::forward(arguments)...) ); } }; @@ -91,7 +89,7 @@ struct [[maybe_unused]] trace const lsd::src_location &location = lsd::src_location::current() ) noexcept { - print(Level::trace, location, format, std::forward(arguments)...); + print(Level::trace, location, format, lsd::forward(arguments)...); } }; @@ -107,7 +105,7 @@ struct [[maybe_unused]] debug const lsd::src_location &location = lsd::src_location::current() ) noexcept { - print(Level::debug, location, format, std::forward(arguments)...); + print(Level::debug, location, format, lsd::forward(arguments)...); } }; @@ -123,7 +121,7 @@ struct [[maybe_unused]] info const lsd::src_location &location = lsd::src_location::current() ) noexcept { - print(Level::info, location, format, std::forward(arguments)...); + print(Level::info, location, format, lsd::forward(arguments)...); } }; @@ -139,7 +137,7 @@ struct [[maybe_unused]] warn const lsd::src_location &location = lsd::src_location::current() ) noexcept { - print(Level::warn, location, format, std::forward(arguments)...); + print(Level::warn, location, format, lsd::forward(arguments)...); } }; @@ -155,7 +153,7 @@ struct [[maybe_unused]] error const lsd::src_location &location = lsd::src_location::current() ) noexcept { - print(Level::error, location, format, std::forward(arguments)...); + print(Level::error, location, format, lsd::forward(arguments)...); } }; @@ -171,7 +169,7 @@ struct [[maybe_unused]] critical const lsd::src_location &location = lsd::src_location::current() ) noexcept { - print(Level::critical, location, format, std::forward(arguments)...); + print(Level::critical, location, format, lsd::forward(arguments)...); } }; diff --git a/modules/lsd/arr.cppm b/modules/lsd/arr.cppm index 769ee02..2674418 100644 --- a/modules/lsd/arr.cppm +++ b/modules/lsd/arr.cppm @@ -1,4 +1,5 @@ export module lsd.arr; +import lsd.primitives; import std; export namespace lt::lsd { diff --git a/modules/lsd/literals.cppm b/modules/lsd/literals.cppm new file mode 100644 index 0000000..50c9962 --- /dev/null +++ b/modules/lsd/literals.cppm @@ -0,0 +1,12 @@ +export module lsd.literals; +import lsd.str; +import std; + +export namespace lt { + +constexpr str_view operator""sv(const char *str, unsigned long len) noexcept +{ + return str_view { str, len }; +} + +} // namespace lt diff --git a/modules/lsd/lsd.cppm b/modules/lsd/lsd.cppm index 0d58e1b..f367c45 100644 --- a/modules/lsd/lsd.cppm +++ b/modules/lsd/lsd.cppm @@ -4,7 +4,8 @@ export import lsd.vec; export import lsd.arr; export import lsd.str; export import lsd.hash; -export import lsd.hash; +export import lsd.span; +export import lsd.utils; export import lsd.thread; export import lsd.ref_ptr; export import lsd.bitwise; diff --git a/modules/lsd/primitives.cppm b/modules/lsd/primitives.cppm index f7377c8..56dac2e 100644 --- a/modules/lsd/primitives.cppm +++ b/modules/lsd/primitives.cppm @@ -18,4 +18,6 @@ using i64 = std::int64_t; using f32 = float; using f64 = double; +using size_t = std::size_t; + } // namespace lt diff --git a/modules/lsd/span.cppm b/modules/lsd/span.cppm new file mode 100644 index 0000000..ecaa0f5 --- /dev/null +++ b/modules/lsd/span.cppm @@ -0,0 +1,6 @@ +export module lsd.span; +import std; + +export namespace lt::lsd { +using ::std::span; +} diff --git a/modules/lsd/str.cppm b/modules/lsd/str.cppm index add1fe5..dd95143 100644 --- a/modules/lsd/str.cppm +++ b/modules/lsd/str.cppm @@ -9,7 +9,6 @@ using str = std::string; using str_view = std::string_view; - template using format_str = std::format_string; diff --git a/modules/lsd/utils.cppm b/modules/lsd/utils.cppm new file mode 100644 index 0000000..e0c1a72 --- /dev/null +++ b/modules/lsd/utils.cppm @@ -0,0 +1,32 @@ +export module lsd.utils; +import std; + +export namespace lt::lsd { + +[[noreturn]] void unreachable() noexcept +{ +#if defined(__clang__) || defined(__GNUC__) + __builtin_unreachable(); +#elif defined(_MSC_VER) + std::terminate(); + __assume(0); +#else + std::terminate(); +#endif +} + +// NOLINTBEGIN +using ::std::declval; +using ::std::format; +using ::std::forward; +using ::std::move; +using ::std::println; + +namespace filesystem { + +using ::std::filesystem::path; + +} +// NOLINTEND + +} // namespace lt::lsd diff --git a/modules/test/entrypoint.cpp b/modules/test/entrypoint.cpp index fa3132b..f4ec802 100644 --- a/modules/test/entrypoint.cpp +++ b/modules/test/entrypoint.cpp @@ -2,22 +2,28 @@ import logger; import test.test; import test.registry; -import std; +import lsd; +using namespace ::lt; using namespace ::lt::test; -void parse_option(std::string_view argument, Registry::Options &options) +constexpr lsd::str_view operator""_sv(const char *str, unsigned long len) noexcept { - constexpr auto case_str = std::string_view { "--case=" }; - constexpr auto suite_str = std::string_view { "--suite=" }; + return lsd::str_view { str, len }; +} - if (argument == "--stop-on-fail") +void parse_option(lsd::str_view argument, Registry::Options &options) +{ + constexpr auto case_str = lsd::str_view { "--case=" }; + constexpr auto suite_str = lsd::str_view { "--suite=" }; + + if (argument == "--stop-on-fail"_sv) { options.stop_on_fail = true; return; } - if (argument.starts_with("--mode=") && argument.substr(7ul) == "stats") + if (argument.starts_with("--mode="_sv) && argument.substr(7ul) == "stats") { options.execution_policy = Registry::ExecutionPolicy::stats; return; @@ -26,14 +32,14 @@ void parse_option(std::string_view argument, Registry::Options &options) if (argument.starts_with(suite_str) && argument.length() > suite_str.size()) { options.suite_regex = argument.substr(suite_str.length()); - std::println("SUITE REGEX: {}", options.suite_regex); + lsd::println("SUITE REGEX: {}", options.suite_regex); return; } if (argument.starts_with(case_str) && argument.length() > case_str.size()) { options.case_regex = argument.substr(case_str.length()); - std::println("CASE REGEX: {}", options.case_regex); + lsd::println("CASE REGEX: {}", options.case_regex); return; } @@ -42,19 +48,19 @@ void parse_option(std::string_view argument, Registry::Options &options) void print_help() { - std::println("Options: "); - std::println("--stop-on-fail --> Stops executing the remaining tests on first failure"); - std::println("--suite --> Regex for running specific suite(s)"); - std::println("--case --> Regex for running specific test(s)"); - std::println("--mode=stats --> Executes tests with an alternative policy"); - std::println("\t---> stats: Print statistics about the tests without running any"); - std::println("--help | -h --> ~You just used it! :D"); + lsd::println("Options: "); + lsd::println("--stop-on-fail --> Stops executing the remaining tests on first failure"); + lsd::println("--suite --> Regex for running specific suite(s)"); + lsd::println("--case --> Regex for running specific test(s)"); + lsd::println("--mode=stats --> Executes tests with an alternative policy"); + lsd::println("\t---> stats: Print statistics about the tests without running any"); + lsd::println("--help | -h --> ~You just used it! :D"); } -auto main(std::int32_t argc, char **argv) -> std::int32_t +auto main(i32 argc, char **argv) -> i32 try { - auto raw_arguments = std::span(argv, argc); + auto raw_arguments = lsd::span(argv, argc); auto options = Registry::Options {}; for (auto idx = 0; auto &raw_argument : raw_arguments) @@ -65,7 +71,7 @@ try continue; } - auto argument = std::string_view(raw_argument); + auto argument = lsd::str_view(raw_argument); if (argument == "-h" || argument == "--help") { @@ -83,7 +89,7 @@ try } } - return static_cast(Registry::run_all(options)); + return static_cast(Registry::run_all(options)); } catch (const std::exception &exp) {