diff --git a/deps/ox/src/ox/std/assert.cpp b/deps/ox/src/ox/std/assert.cpp index c7541e0e..c7f27d7e 100644 --- a/deps/ox/src/ox/std/assert.cpp +++ b/deps/ox/src/ox/std/assert.cpp @@ -6,17 +6,19 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#if defined(OX_USE_STDLIB) +#include +#include +#endif + #include -#if defined(OX_USE_STDLIB) - -#include - -#endif +#include "assert.hpp" namespace ox { -void _assert([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]bool pass, [[maybe_unused]]const char *msg) { +template<> +void _assert([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]bool pass, [[maybe_unused]]const char *msg) { #if defined(OX_USE_STDLIB) if (!pass) { std::cerr << "\033[31;1;1mASSERT FAILURE:\033[0m (" << file << ':' << line << "): " << msg << std::endl; @@ -25,4 +27,20 @@ void _assert([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe #endif } +template<> +void _assert([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]Error err, [[maybe_unused]]const char *msg) { +#if defined(OX_USE_STDLIB) + if (err) { + auto ei = ErrorInfo(err); + std::cerr << "\033[31;1;1mASSERT FAILURE:\033[0m (" << file << ':' << line << "): " << msg << '\n'; + std::cerr << "\tError Info: " << ei.errCode; + if (ei.file != nullptr) { + std::cerr << " (" << reinterpret_cast(ei.file) << ':' << ei.line << ')'; + } + std::cerr << std::endl; + std::abort(); + } +#endif +} + } diff --git a/deps/ox/src/ox/std/assert.hpp b/deps/ox/src/ox/std/assert.hpp index 7163db79..41bbe4c9 100644 --- a/deps/ox/src/ox/std/assert.hpp +++ b/deps/ox/src/ox/std/assert.hpp @@ -8,14 +8,30 @@ #pragma once +#if defined(OX_USE_STDLIB) +#include +#endif + +#include + +#include "types.hpp" + namespace ox { -void _assert(const char *file, int line, bool pass, const char *msg); +template +void _assert(const char*, int, T, const char*) { +} + +template<> +void _assert(const char *file, int line, bool pass, const char *msg); + +template<> +void _assert(const char *file, int line, Error err, const char*); } #ifndef NDEBUG -#define oxAssert(pass, msg) ox::_assert(__FILE__, __LINE__, pass, msg) +#define oxAssert(pass, msg) ox::_assert(__FILE__, __LINE__, pass, msg) #else #define oxAssert(pass, msg) #endif diff --git a/deps/ox/src/ox/std/bitops.hpp b/deps/ox/src/ox/std/bitops.hpp index febc9cb0..8a2956af 100644 --- a/deps/ox/src/ox/std/bitops.hpp +++ b/deps/ox/src/ox/std/bitops.hpp @@ -20,9 +20,14 @@ template constexpr T onMask(int bits) { T out = 0; for (auto i = 0; i < bits; i++) { - out |= 1 << i; + out |= static_cast(1) << i; } return out; } +static_assert(onMask(1) == 1); +static_assert(onMask(2) == 3); +static_assert(onMask(3) == 7); +static_assert(onMask(4) == 15); + } diff --git a/deps/ox/src/ox/std/types.hpp b/deps/ox/src/ox/std/types.hpp index 20b96063..891eea32 100644 --- a/deps/ox/src/ox/std/types.hpp +++ b/deps/ox/src/ox/std/types.hpp @@ -65,15 +65,15 @@ struct ErrorInfo { ErrorInfo(Error err) { this->file = reinterpret_cast(err & onMask(48)); - this->line = static_cast((err >> 48) & onMask(5)); - this->errCode = (err >> 59) & onMask(11); + this->line = static_cast((err >> 48) & onMask(11)); + this->errCode = (err >> 58) & onMask(5); } }; constexpr Error ErrorTags(Error line, Error errCode) { - line &= onMask(5); + line &= onMask(11); line <<= 48; - errCode &= onMask(11); + errCode &= onMask(5); errCode <<= 59; return errCode | line; } @@ -81,7 +81,7 @@ constexpr Error ErrorTags(Error line, Error errCode) { } #ifdef DEBUG -#define OxError(x) reinterpret_cast(__FILE__) | ErrorTags(__LINE__, x) +#define OxError(x) x ? reinterpret_cast(__FILE__) | ErrorTags(__LINE__, x) : 0 #else #define OxError(x) x #endif