From 65e5fdf324ac58c57c87225433b2b67b41791084 Mon Sep 17 00:00:00 2001 From: CHatingPython Date: Fri, 19 Jun 2026 14:26:09 +0200 Subject: [PATCH] refactor(furvm): move bad access exceptions to exceptions.hpp Refs: #12 --- furvm/include/furvm/constant.hpp | 40 +---------------- furvm/include/furvm/exceptions.hpp | 71 +++++++++++++++++++++++++++++- furvm/include/furvm/thing.hpp | 34 +------------- 3 files changed, 73 insertions(+), 72 deletions(-) diff --git a/furvm/include/furvm/constant.hpp b/furvm/include/furvm/constant.hpp index 419aba5..70ed4b7 100644 --- a/furvm/include/furvm/constant.hpp +++ b/furvm/include/furvm/constant.hpp @@ -1,49 +1,13 @@ #ifndef FURVM_CONSTANT_HPP #define FURVM_CONSTANT_HPP +#include "furvm/exceptions.hpp" #include "furvm/fwd.hpp" -#include #include namespace furvm { -/** - * @brief Bad constant access exception. - */ -class bad_constant_access : public std::exception { -public: - bad_constant_access() = default; - ~bad_constant_access() override = default; - - /** - * @brief Move constructor. - */ - bad_constant_access(bad_constant_access&&) noexcept = default; - - /** - * @brief Move constructor. - */ - bad_constant_access& operator=(bad_constant_access&&) noexcept = default; - - /** - * @brief Copy constructor. - */ - bad_constant_access(const bad_constant_access&) = default; - - /** - * @brief Copy constructor. - */ - bad_constant_access& operator=(const bad_constant_access&) = default; -public: - /** - * @brief Returns a C-style string describing the cause of the error. - * - * @return The cause of the error. - */ - const char* what() const noexcept override { return "bad constant access"; } -}; - enum class constant_t : std::uint8_t { String, /**< String constant. */ }; @@ -109,4 +73,4 @@ private: } // namespace furvm -#endif // FURVM_CONSTANT_HPP \ No newline at end of file +#endif // FURVM_CONSTANT_HPP diff --git a/furvm/include/furvm/exceptions.hpp b/furvm/include/furvm/exceptions.hpp index e9a0c58..87efc79 100644 --- a/furvm/include/furvm/exceptions.hpp +++ b/furvm/include/furvm/exceptions.hpp @@ -5,6 +5,75 @@ namespace furvm { +class bad_thing_access : public std::exception { +public: + bad_thing_access() = default; + ~bad_thing_access() override = default; + + /** + * @brief Move constructor. + */ + bad_thing_access(bad_thing_access&&) noexcept = default; + + /** + * @brief Move constructor. + */ + bad_thing_access& operator=(bad_thing_access&&) noexcept = default; + + /** + * @brief Copy constructor. + */ + bad_thing_access(const bad_thing_access&) = default; + + /** + * @brief Copy constructor. + */ + bad_thing_access& operator=(const bad_thing_access&) = default; +public: + /** + * @brief Returns a C-style string describing the cause of the error. + * + * @return The cause of the error. + */ + const char* what() const noexcept override { return "bad thing access"; } +}; + +/** + * @brief Bad constant access exception. + */ +class bad_constant_access : public std::exception { +public: + bad_constant_access() = default; + ~bad_constant_access() override = default; + + /** + * @brief Move constructor. + */ + bad_constant_access(bad_constant_access&&) noexcept = default; + + /** + * @brief Move constructor. + */ + bad_constant_access& operator=(bad_constant_access&&) noexcept = default; + + /** + * @brief Copy constructor. + */ + bad_constant_access(const bad_constant_access&) = default; + + /** + * @brief Copy constructor. + */ + bad_constant_access& operator=(const bad_constant_access&) = default; +public: + /** + * @brief Returns a C-style string describing the cause of the error. + * + * @return The cause of the error. + */ + const char* what() const noexcept override { return "bad constant access"; } +}; + class stack_underflow : public std::exception { public: stack_underflow() = default; @@ -40,4 +109,4 @@ public: } // namespace furvm -#endif // FURVM_EXCEPTIONS_HPP \ No newline at end of file +#endif // FURVM_EXCEPTIONS_HPP diff --git a/furvm/include/furvm/thing.hpp b/furvm/include/furvm/thing.hpp index 3b3247a..9a2c1d9 100644 --- a/furvm/include/furvm/thing.hpp +++ b/furvm/include/furvm/thing.hpp @@ -2,6 +2,7 @@ #define FURVM_THING_HPP #include "furlang/arena.hpp" +#include "furvm/exceptions.hpp" #include "furvm/fwd.hpp" #include @@ -30,39 +31,6 @@ static inline std::size_t thing_type_size(thing_t type) { } } -class bad_thing_access : public std::exception { -public: - bad_thing_access() = default; - ~bad_thing_access() override = default; - - /** - * @brief Move constructor. - */ - bad_thing_access(bad_thing_access&&) noexcept = default; - - /** - * @brief Move constructor. - */ - bad_thing_access& operator=(bad_thing_access&&) noexcept = default; - - /** - * @brief Copy constructor. - */ - bad_thing_access(const bad_thing_access&) = default; - - /** - * @brief Copy constructor. - */ - bad_thing_access& operator=(const bad_thing_access&) = default; -public: - /** - * @brief Returns a C-style string describing the cause of the error. - * - * @return The cause of the error. - */ - const char* what() const noexcept override { return "bad thing access"; } -}; - template