diff --git a/deps/ox/src/ox/std/CMakeLists.txt b/deps/ox/src/ox/std/CMakeLists.txt index ed79b4ac..4e4b32ca 100644 --- a/deps/ox/src/ox/std/CMakeLists.txt +++ b/deps/ox/src/ox/std/CMakeLists.txt @@ -24,7 +24,6 @@ add_library( buffer.cpp buildinfo.cpp byteswap.cpp - defer.hpp fmt.cpp heapmgr.cpp memops.cpp @@ -71,7 +70,9 @@ install( buffer.hpp buildinfo.hpp byteswap.hpp + def.hpp defines.hpp + defer.hpp error.hpp fmt.hpp hardware.hpp diff --git a/deps/ox/src/ox/std/assert.hpp b/deps/ox/src/ox/std/assert.hpp index f6b1e2f7..666f1ab9 100644 --- a/deps/ox/src/ox/std/assert.hpp +++ b/deps/ox/src/ox/std/assert.hpp @@ -11,9 +11,10 @@ #if __has_include() #include #else -#define assert(e) {} +#define assert(e) while (1); #endif +#include "def.hpp" #include "defines.hpp" #include "error.hpp" @@ -26,11 +27,3 @@ void assertFunc(const char *file, int line, const Error &err, const char *assert void panic([[maybe_unused]]const char *file, [[maybe_unused]]int line, [[maybe_unused]]const char *msg, [[maybe_unused]]const Error &err = OxError(0)) noexcept; } - -#define oxPanic(errCode, msg) ox::panic(__FILE__, __LINE__, msg, errCode) -#ifndef NDEBUG -#define oxAssert(pass, msg) ox::assertFunc(__FILE__, __LINE__, pass, #pass, msg) -#else -inline void oxAssert(bool, const char*) {} -inline void oxAssert(ox::Error, const char*) {} -#endif diff --git a/deps/ox/src/ox/std/def.hpp b/deps/ox/src/ox/std/def.hpp new file mode 100644 index 00000000..d8c45e50 --- /dev/null +++ b/deps/ox/src/ox/std/def.hpp @@ -0,0 +1,97 @@ +/* + * Copyright 2015 - 2022 gary@drinkingtea.net + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + + +// Logging + +#define oxLogError(...) ox::trace::logError(__FILE__, __LINE__, __VA_ARGS__) + +#define oxTrace(...) ox::trace::TraceStream(__FILE__, __LINE__, __VA_ARGS__) +#define oxOut(...) ox::trace::OutStream(__FILE__, __LINE__, "stdout", __VA_ARGS__) +#define oxErr(...) ox::trace::OutStream(__FILE__, __LINE__, "stderr", __VA_ARGS__) + +#ifdef OX_USE_STDLIB +// Non-GCC compilers don't like ##__VA_ARGS__, so use initializer list, which relies on std lib +#define oxTracef(ch, fmt, ...) ox::trace::TraceStream(__FILE__, __LINE__, ch, ox::detail::fmtSegments(fmt), {__VA_ARGS__}) +#define oxOutf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "stdout", ox::detail::fmtSegments(fmt), {__VA_ARGS__}) +#define oxErrf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "stderr", ox::detail::fmtSegments(fmt), {__VA_ARGS__}) +#else +#define oxTracef(ch, fmt, ...) ox::trace::TraceStream(__FILE__, __LINE__, ch, ox::detail::fmtSegments(fmt), ##__VA_ARGS__) +#define oxOutf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "stdout", ox::detail::fmtSegments(fmt), ##__VA_ARGS__) +#define oxErrf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "stderr", ox::detail::fmtSegments(fmt), ##__VA_ARGS__) +#endif + +#define oxInfo(...) oxTrace("info", __VA_ARGS__) +#define oxInfof(...) oxTracef("info", __VA_ARGS__) +#define oxError(...) oxTrace("error", __VA_ARGS__) +#define oxErrorf(...) oxTracef("error", __VA_ARGS__) + +#ifndef OX_NODEBUG +#define oxDebug(...) oxTrace("debug", __VA_ARGS__) +#define oxDebugf(...) oxTracef("debug", __VA_ARGS__) +#else +#define oxDebug(...) static_assert(false, "Debug prints were checked in."); oxTrace("debug", __VA_ARGS__) +#define oxDebugf(...) static_assert(false, "Debug prints were checked in."); oxTracef("debug", __VA_ARGS__) +#endif + + +// Error handling + +#if __cplusplus >= 202002L +#define oxReturnError(x) if (const auto _ox_error = ox::detail::toError(x)) [[unlikely]] return _ox_error +#define oxThrowError(x) if (const auto _ox_error = ox::detail::toError(x)) [[unlikely]] throw ox::Exception(_ox_error) +#else +#define oxReturnError(err) if (const auto _ox_error = ox::detail::toError(err)) return _ox_error +#define oxThrowError(err) if (const auto _ox_error = ox::detail::toError(err)) throw ox::Exception(_ox_error) +#endif +#define oxConcatImpl(a, b) a##b +#define oxConcat(a, b) oxConcatImpl(a, b) +// oxRequire Mutable +#define oxRequireM(out, x) auto [out, oxConcat(oxRequire_err_, __LINE__)] = x; oxReturnError(oxConcat(oxRequire_err_, __LINE__)) +#define oxRequire(out, x) const oxRequireM(out, x) +// oxRequire Mutable Throw +#define oxRequireMT(out, x) auto [out, oxConcat(oxRequire_err_, __LINE__)] = x; oxThrowError(oxConcat(oxRequire_err_, __LINE__)) +// oxRequire Throw +#define oxRequireT(out, x) const oxRequireMT(out, x) + + +// Asserts + +#define oxPanic(errCode, msg) ox::panic(__FILE__, __LINE__, msg, errCode) +#ifndef NDEBUG +#define oxAssert(pass, msg) ox::assertFunc(__FILE__, __LINE__, pass, #pass, msg) +#else +namespace ox { +struct [[nodiscard]] Error; +} +inline void oxAssert(bool, const char*) {} +inline void oxAssert(const ox::Error&, const char*) {} +#endif + + +// Alloca + +#if defined(_MSC_VER) +#define ox_alloca(size) _alloca(size) +#elif OX_USE_STDLIB +#define ox_alloca(size) alloca(size) +#else +#define ox_alloca(size) __builtin_alloca(size) +#endif + +/** + * @return an ox::MallocaPtr of the given type pointing to the requested size memory allocation + */ +#if defined(OX_USE_STDLIB) +#define ox_malloca(size, Type, ...) ox::MallocaPtr(size > ox::MallocaStackLimit, new (size > ox::MallocaStackLimit ? new uint8_t[size] : ox_alloca(size)) Type(__VA_ARGS__)) +#else +#define ox_malloca(size, Type, ...) ox::MallocaPtr(false, new (ox_alloca(size)) Type(__VA_ARGS__)) +#endif + diff --git a/deps/ox/src/ox/std/error.hpp b/deps/ox/src/ox/std/error.hpp index b6172f54..28175844 100644 --- a/deps/ox/src/ox/std/error.hpp +++ b/deps/ox/src/ox/std/error.hpp @@ -24,6 +24,7 @@ class exception { } #endif +#include "def.hpp" #include "defines.hpp" #include "strongint.hpp" #include "typetraits.hpp" @@ -176,20 +177,3 @@ constexpr Error toError(const Result &ve) noexcept { constexpr void oxIgnoreError(const ox::Error&) noexcept {} template constexpr void oxIgnoreError(const ox::Result&) noexcept {} -#if __cplusplus >= 202002L -#define oxReturnError(x) if (const auto _ox_error = ox::detail::toError(x)) [[unlikely]] return _ox_error -#define oxThrowError(x) if (const auto _ox_error = ox::detail::toError(x)) [[unlikely]] throw ox::Exception(_ox_error) -#else -#define oxReturnError(err) if (const auto _ox_error = ox::detail::toError(err)) return _ox_error -#define oxThrowError(err) if (const auto _ox_error = ox::detail::toError(err)) throw ox::Exception(_ox_error) -#endif -#define oxConcatImpl(a, b) a##b -#define oxConcat(a, b) oxConcatImpl(a, b) -// oxRequire Mutable -#define oxRequireM(out, x) auto [out, oxConcat(oxRequire_err_, __LINE__)] = x; oxReturnError(oxConcat(oxRequire_err_, __LINE__)) -#define oxRequire(out, x) const oxRequireM(out, x) -// oxRequire Mutable Throw -#define oxRequireMT(out, x) auto [out, oxConcat(oxRequire_err_, __LINE__)] = x; oxThrowError(oxConcat(oxRequire_err_, __LINE__)) -// oxRequire Throw -#define oxRequireT(out, x) const oxRequireMT(out, x) - diff --git a/deps/ox/src/ox/std/new.hpp b/deps/ox/src/ox/std/new.hpp index 2a2b3644..a0fb6eae 100644 --- a/deps/ox/src/ox/std/new.hpp +++ b/deps/ox/src/ox/std/new.hpp @@ -13,12 +13,8 @@ #if defined(_MSC_VER) #include -#define ox_alloca(size) _alloca(size) #elif OX_USE_STDLIB #include -#define ox_alloca(size) alloca(size) -#else -#define ox_alloca(size) __builtin_alloca(size) #endif @@ -35,15 +31,6 @@ constexpr void *operator new[](std::size_t, void *addr) noexcept { #endif -/** - * @return an ox::MallocaPtr of the given type pointing to the requested size memory allocation - */ -#if defined(OX_USE_STDLIB) -#define ox_malloca(size, Type, ...) ox::MallocaPtr(size > ox::MallocaStackLimit, new (size > ox::MallocaStackLimit ? new uint8_t[size] : ox_alloca(size)) Type(__VA_ARGS__)) -#else -#define ox_malloca(size, Type, ...) ox::MallocaPtr(false, new (ox_alloca(size)) Type(__VA_ARGS__)) -#endif - namespace ox { constexpr auto MallocaStackLimit = defines::UseStdLib ? 1024 : 0; diff --git a/deps/ox/src/ox/std/std.hpp b/deps/ox/src/ox/std/std.hpp index 6eb49845..6ed72cbc 100644 --- a/deps/ox/src/ox/std/std.hpp +++ b/deps/ox/src/ox/std/std.hpp @@ -13,6 +13,7 @@ #include "bstring.hpp" #include "byteswap.hpp" #include "defer.hpp" +#include "def.hpp" #include "defines.hpp" #include "error.hpp" #include "fmt.hpp" diff --git a/deps/ox/src/ox/std/trace.hpp b/deps/ox/src/ox/std/trace.hpp index 33e06901..ea17d914 100644 --- a/deps/ox/src/ox/std/trace.hpp +++ b/deps/ox/src/ox/std/trace.hpp @@ -13,6 +13,7 @@ #endif #include "bstring.hpp" +#include "def.hpp" #include "fmt.hpp" #include "hashmap.hpp" #include "string.hpp" @@ -282,33 +283,3 @@ inline void logError(const char *file, int line, const Error &err) noexcept { void init(); } - -#define oxLogError(...) ox::trace::logError(__FILE__, __LINE__, __VA_ARGS__) - -#define oxTrace(...) ox::trace::TraceStream(__FILE__, __LINE__, __VA_ARGS__) -#define oxOut(...) ox::trace::OutStream(__FILE__, __LINE__, "stdout", __VA_ARGS__) -#define oxErr(...) ox::trace::OutStream(__FILE__, __LINE__, "stderr", __VA_ARGS__) - -#ifdef OX_USE_STDLIB -// Non-GCC compilers don't like ##__VA_ARGS__, so use initializer list, which relies on std lib -#define oxTracef(ch, fmt, ...) ox::trace::TraceStream(__FILE__, __LINE__, ch, ox::detail::fmtSegments(fmt), {__VA_ARGS__}) -#define oxOutf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "stdout", ox::detail::fmtSegments(fmt), {__VA_ARGS__}) -#define oxErrf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "stderr", ox::detail::fmtSegments(fmt), {__VA_ARGS__}) -#else -#define oxTracef(ch, fmt, ...) ox::trace::TraceStream(__FILE__, __LINE__, ch, ox::detail::fmtSegments(fmt), ##__VA_ARGS__) -#define oxOutf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "stdout", ox::detail::fmtSegments(fmt), ##__VA_ARGS__) -#define oxErrf(fmt, ...) ox::trace::OutStream(__FILE__, __LINE__, "stderr", ox::detail::fmtSegments(fmt), ##__VA_ARGS__) -#endif - -#define oxInfo(...) oxTrace("info", __VA_ARGS__) -#define oxInfof(...) oxTracef("info", __VA_ARGS__) -#define oxError(...) oxTrace("error", __VA_ARGS__) -#define oxErrorf(...) oxTracef("error", __VA_ARGS__) - -#ifndef OX_NODEBUG -#define oxDebug(...) oxTrace("debug", __VA_ARGS__) -#define oxDebugf(...) oxTracef("debug", __VA_ARGS__) -#else -#define oxDebug(...) static_assert(false, "Debug prints were checked in."); oxTrace("debug", __VA_ARGS__) -#define oxDebugf(...) static_assert(false, "Debug prints were checked in."); oxTracef("debug", __VA_ARGS__) -#endif