From e88007f6b9ffc3ddee05a12914fc87d7f5fa6563 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 1 Jun 2024 20:30:34 +0900 Subject: [PATCH 01/25] Add an experimental detailed error reporting mechanism Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/error.hpp | 29 +++++++++++++++++++++++++++-- src/kernel/environment.cpp | 2 +- src/kernel/error.cpp | 19 +++++++++++++++++++ src/main.cpp | 2 +- 6 files changed, 52 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 8d5ad77d5..2b90aa2cb 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ Procedures for each standard are provided by the following R7RS-style libraries: cmake -B build -DCMAKE_BUILD_TYPE=Release cd build make package -sudo apt install build/meevax_0.5.187_amd64.deb +sudo apt install build/meevax_0.5.188_amd64.deb ``` or @@ -122,9 +122,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |-------------|------------- -| `all` | Build shared-library `libmeevax.0.5.187.so` and executable `meevax` +| `all` | Build shared-library `libmeevax.0.5.188.so` and executable `meevax` | `test` | Test executable `meevax` -| `package` | Generate debian package `meevax_0.5.187_amd64.deb` +| `package` | Generate debian package `meevax_0.5.188_amd64.deb` | `install` | Copy files into `/usr/local` directly ## Usage diff --git a/VERSION b/VERSION index c8c8d1f59..0de0d7ec3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.187 +0.5.188 diff --git a/include/meevax/kernel/error.hpp b/include/meevax/kernel/error.hpp index f441bc983..b8e6af5e3 100644 --- a/include/meevax/kernel/error.hpp +++ b/include/meevax/kernel/error.hpp @@ -26,15 +26,40 @@ inline namespace kernel { struct error : public virtual pair // ( . ) { + struct detail + { + let expression; + + explicit detail(let const& expression) + : expression { expression } + {} + }; + + std::vector details {}; + using pair::pair; + template + auto append(Ts&&... xs) -> auto & + { + details.emplace_back(std::forward(xs)...); + return *this; + } + auto irritants() const noexcept -> object const&; auto message() const noexcept -> object const&; - [[noreturn]] // NOTE: GCC ignores this attribute when accessed through pointer (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84476) + /* + GCC ignores this attribute when accessed through pointer + (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84476) + */ + [[noreturn]] virtual auto raise() const -> void; + auto report(std::ostream &) const -> std::ostream &; + + [[deprecated]] auto what() const -> std::string; }; @@ -73,7 +98,7 @@ inline namespace kernel } catch (error const& error) { - std::cerr << error << std::endl; + error.report(std::cerr); return EXIT_FAILURE; } catch (std::exception const& exception) diff --git a/src/kernel/environment.cpp b/src/kernel/environment.cpp index ec4790efb..671adc64c 100644 --- a/src/kernel/environment.cpp +++ b/src/kernel/environment.cpp @@ -96,7 +96,7 @@ inline namespace kernel { if (x.is_also()) { - x.as().raise(); + x.as().append(expression).raise(); return unspecified; } else diff --git a/src/kernel/error.cpp b/src/kernel/error.cpp index 622688962..e94e8fc91 100644 --- a/src/kernel/error.cpp +++ b/src/kernel/error.cpp @@ -37,6 +37,25 @@ inline namespace kernel throw *this; } + auto error::report(std::ostream & output) const -> std::ostream & + { + output << red("; error! ", static_cast(message().as())); + + if (irritants()) + { + output << red(": ", irritants()); + } + + output << std::endl; + + for (auto iter = details.rbegin(); iter != details.rend(); ++iter) + { + output << "; at " << iter->expression << std::endl; + } + + return output; + } + auto error::what() const -> std::string { std::stringstream ss {}; diff --git a/src/main.cpp b/src/main.cpp index 217d7a0c7..e21ccec84 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,7 +54,7 @@ auto main(int const argc, char const* const* const argv) -> int } catch (error const& error) { - std::cerr << error << std::endl; + error.report(std::cerr); } } } From 07abd19c7d6b643f33ab93c03e3c20057c204c3b Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sat, 1 Jun 2024 21:39:02 +0900 Subject: [PATCH 02/25] Update the struct `error` to inherit from `std::exception` Signed-off-by: yamacir-kit --- README.md | 6 ++-- VERSION | 2 +- include/meevax/kernel/dynamic_environment.hpp | 8 ++--- include/meevax/kernel/error.hpp | 8 +++-- src/kernel/error.cpp | 36 +++++++++++-------- 5 files changed, 35 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 2b90aa2cb..aa563887b 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ Procedures for each standard are provided by the following R7RS-style libraries: cmake -B build -DCMAKE_BUILD_TYPE=Release cd build make package -sudo apt install build/meevax_0.5.188_amd64.deb +sudo apt install build/meevax_0.5.189_amd64.deb ``` or @@ -122,9 +122,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |-------------|------------- -| `all` | Build shared-library `libmeevax.0.5.188.so` and executable `meevax` +| `all` | Build shared-library `libmeevax.0.5.189.so` and executable `meevax` | `test` | Test executable `meevax` -| `package` | Generate debian package `meevax_0.5.188_amd64.deb` +| `package` | Generate debian package `meevax_0.5.189_amd64.deb` | `install` | Copy files into `/usr/local` directly ## Usage diff --git a/VERSION b/VERSION index 0de0d7ec3..a8816aa2e 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.188 +0.5.189 diff --git a/include/meevax/kernel/dynamic_environment.hpp b/include/meevax/kernel/dynamic_environment.hpp index b51f26c9f..8dcf56e03 100644 --- a/include/meevax/kernel/dynamic_environment.hpp +++ b/include/meevax/kernel/dynamic_environment.hpp @@ -525,14 +525,14 @@ inline namespace kernel }(); } } - catch (std::exception const& exception) - { - return reraise(make(make(exception.what()))); - } catch (error const& error) { return reraise(make(error)); } + catch (std::exception const& exception) + { + return reraise(make(make(exception.what()))); + } } }; } // namespace kernel diff --git a/include/meevax/kernel/error.hpp b/include/meevax/kernel/error.hpp index b8e6af5e3..297dcc249 100644 --- a/include/meevax/kernel/error.hpp +++ b/include/meevax/kernel/error.hpp @@ -25,6 +25,7 @@ namespace meevax inline namespace kernel { struct error : public virtual pair // ( . ) + , public std::exception { struct detail { @@ -37,8 +38,12 @@ inline namespace kernel std::vector details {}; + mutable std::string brief {}; + using pair::pair; + ~error() override = default; + template auto append(Ts&&... xs) -> auto & { @@ -59,8 +64,7 @@ inline namespace kernel auto report(std::ostream &) const -> std::ostream &; - [[deprecated]] - auto what() const -> std::string; + auto what() const noexcept -> char const* override; }; auto operator <<(std::ostream &, error const&) -> std::ostream &; diff --git a/src/kernel/error.cpp b/src/kernel/error.cpp index e94e8fc91..b37d9db96 100644 --- a/src/kernel/error.cpp +++ b/src/kernel/error.cpp @@ -39,14 +39,7 @@ inline namespace kernel auto error::report(std::ostream & output) const -> std::ostream & { - output << red("; error! ", static_cast(message().as())); - - if (irritants()) - { - output << red(": ", irritants()); - } - - output << std::endl; + output << red("; error! ", what()) << std::endl; for (auto iter = details.rbegin(); iter != details.rend(); ++iter) { @@ -56,18 +49,31 @@ inline namespace kernel return output; } - auto error::what() const -> std::string + auto error::what() const noexcept -> char const* { - std::stringstream ss {}; + try + { + if (brief.empty()) + { + auto output = std::stringstream(); - ss << "error: " << static_cast(message().as()); + output << static_cast(message().as()); - if (irritants()) + if (irritants()) + { + output << ": " << irritants(); + } + + brief = output.str(); + } + + return brief.c_str(); + } + catch (...) { - ss << ": " << irritants(); + std::cerr << "meevax::error::what failed to create an explanatory string for std::exception::what" << std::endl; + std::exit(EXIT_FAILURE); } - - return ss.str(); } auto operator <<(std::ostream & os, error const& datum) -> std::ostream & From 9ca298fbeb63347aebee192a127e72cca40fdf49 Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sun, 2 Jun 2024 10:28:41 +0900 Subject: [PATCH 03/25] Remove macro `DEFINE_ERROR` Signed-off-by: yamacir-kit --- README.md | 6 +++--- VERSION | 2 +- include/meevax/kernel/error.hpp | 35 +++++++++++++++++---------------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index aa563887b..f13fbd235 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ Procedures for each standard are provided by the following R7RS-style libraries: cmake -B build -DCMAKE_BUILD_TYPE=Release cd build make package -sudo apt install build/meevax_0.5.189_amd64.deb +sudo apt install build/meevax_0.5.190_amd64.deb ``` or @@ -122,9 +122,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |-------------|------------- -| `all` | Build shared-library `libmeevax.0.5.189.so` and executable `meevax` +| `all` | Build shared-library `libmeevax.0.5.190.so` and executable `meevax` | `test` | Test executable `meevax` -| `package` | Generate debian package `meevax_0.5.189_amd64.deb` +| `package` | Generate debian package `meevax_0.5.190_amd64.deb` | `install` | Copy files into `/usr/local` directly ## Usage diff --git a/VERSION b/VERSION index a8816aa2e..a81dc9010 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.189 +0.5.190 diff --git a/include/meevax/kernel/error.hpp b/include/meevax/kernel/error.hpp index 297dcc249..d69342f18 100644 --- a/include/meevax/kernel/error.hpp +++ b/include/meevax/kernel/error.hpp @@ -69,24 +69,25 @@ inline namespace kernel auto operator <<(std::ostream &, error const&) -> std::ostream &; - /* - - error - |-- file-error - `-- read_error - */ - #define DEFINE_ERROR(TYPENAME) \ - struct TYPENAME ## _error : public error \ - { \ - using error::error; \ - \ - auto raise() const -> void override \ - { \ - throw *this; \ - } \ - } + struct file_error : public error + { + using error::error; + + auto raise() const -> void override + { + throw *this; + } + }; - DEFINE_ERROR(file); - DEFINE_ERROR(read); + struct read_error : public error + { + using error::error; + + auto raise() const -> void override + { + throw *this; + } + }; template auto with_exception_handler(Thunk && thunk) From e870a1700157ea2ed6b843815dd5d436bdb44cfc Mon Sep 17 00:00:00 2001 From: yamacir-kit Date: Sun, 2 Jun 2024 22:03:30 +0900 Subject: [PATCH 04/25] Cleanup `configurator` Signed-off-by: yamacir-kit --- CMakeLists.txt | 12 ++++ README.md | 6 +- VERSION | 2 +- include/meevax/kernel/configurator.hpp | 84 +++++++------------------- include/meevax/kernel/error.hpp | 4 +- src/kernel/error.cpp | 6 +- test/option.sh | 8 +++ 7 files changed, 50 insertions(+), 72 deletions(-) create mode 100755 test/option.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 31eaf18d6..3e92ccc68 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -209,6 +209,18 @@ foreach(EACH IN LISTS ${PROJECT_NAME}_TEST_CPP) ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/test_${FILENAME}) endforeach() +file(GLOB ${PROJECT_NAME}_TEST_SH ${CMAKE_CURRENT_SOURCE_DIR}/test/*.sh) + +foreach(EACH IN LISTS ${PROJECT_NAME}_TEST_SH) + get_filename_component(FILENAME ${EACH} NAME_WE) + add_test( + NAME ${FILENAME} + COMMAND ${${PROJECT_NAME}_MEMORY_CHECK_COMMAND} + ${${PROJECT_NAME}_MEMORY_CHECK_OPTIONS} + ${EACH} + ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/meevax) +endforeach() + # ---- Additional Targets ------------------------------------------------------ execute_process(COMMAND nproc OUTPUT_VARIABLE ${PROJECT_NAME}_NPROC) diff --git a/README.md b/README.md index f13fbd235..23e4fc726 100644 --- a/README.md +++ b/README.md @@ -90,7 +90,7 @@ Procedures for each standard are provided by the following R7RS-style libraries: cmake -B build -DCMAKE_BUILD_TYPE=Release cd build make package -sudo apt install build/meevax_0.5.190_amd64.deb +sudo apt install build/meevax_0.5.191_amd64.deb ``` or @@ -122,9 +122,9 @@ sudo rm -rf /usr/local/share/meevax | Target Name | Description |-------------|------------- -| `all` | Build shared-library `libmeevax.0.5.190.so` and executable `meevax` +| `all` | Build shared-library `libmeevax.0.5.191.so` and executable `meevax` | `test` | Test executable `meevax` -| `package` | Generate debian package `meevax_0.5.190_amd64.deb` +| `package` | Generate debian package `meevax_0.5.191_amd64.deb` | `install` | Copy files into `/usr/local` directly ## Usage diff --git a/VERSION b/VERSION index a81dc9010..d1f514113 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.5.190 +0.5.191 diff --git a/include/meevax/kernel/configurator.hpp b/include/meevax/kernel/configurator.hpp index 6ad24186f..252456a71 100644 --- a/include/meevax/kernel/configurator.hpp +++ b/include/meevax/kernel/configurator.hpp @@ -35,12 +35,12 @@ inline namespace kernel { std::regex const pattern; - std::function const&)> build; + std::function object> const&) -> void> evaluate; template explicit option(S&& s, F&& f) - : pattern { std::forward(s) } - , build { std::forward(f) } + : pattern { std::forward(s) } + , evaluate { std::forward(f) } {} }; @@ -60,71 +60,44 @@ inline namespace kernel auto configure(std::vector const& args) -> void { - static auto const pattern = std::regex(R"(--(\w[-\w]+)(=(.*))?|-([\w]+))"); + auto const static pattern = std::regex(R"(--(\w[-\w]+)(=(.*))?|-([\w]+))"); - auto const options = std::vector