Compare commits

..

3 Commits

Author SHA1 Message Date
110d4a2e6a [keel] Cleanup
All checks were successful
Build / build (push) Successful in 1m16s
2026-02-07 15:29:53 -06:00
e29a50d0dc [ox] Rename UniquePtr to UPtr 2026-02-07 14:17:55 -06:00
93d16cafb2 [ox/std] Add Error::throwException() 2026-02-07 14:15:15 -06:00
14 changed files with 68 additions and 61 deletions

View File

@@ -12,7 +12,7 @@
namespace ox { namespace ox {
ox::Result<ox::StringView> readClawTypeId(ox::BufferView buff) noexcept { Result<StringView> readClawTypeId(BufferView const buff) noexcept {
auto buffRaw = buff.data(); auto buffRaw = buff.data();
auto buffLen = buff.size(); auto buffLen = buff.size();
size_t outSz{}; size_t outSz{};
@@ -43,7 +43,7 @@ ox::Result<ox::StringView> readClawTypeId(ox::BufferView buff) noexcept {
return {{buff.data() + fmtSz, outSz - fmtSz - 1}}; return {{buff.data() + fmtSz, outSz - fmtSz - 1}};
} }
Result<ClawHeader> readClawHeader(ox::BufferView buff) noexcept { Result<ClawHeader> readClawHeader(BufferView const buff) noexcept {
auto buffRaw = buff.data(); auto buffRaw = buff.data();
auto buffLen = buff.size(); auto buffLen = buff.size();
const auto s1End = ox::strchr(buffRaw, ';', buffLen); const auto s1End = ox::strchr(buffRaw, ';', buffLen);
@@ -87,7 +87,7 @@ Result<ClawHeader> readClawHeader(ox::BufferView buff) noexcept {
return hdr; return hdr;
} }
Result<BufferView> stripClawHeader(ox::BufferView buff) noexcept { Result<BufferView> stripClawHeader(BufferView const buff) noexcept {
OX_REQUIRE(header, readClawHeader(buff)); OX_REQUIRE(header, readClawHeader(buff));
return {{header.data, header.dataSize}}; return {{header.data, header.dataSize}};
} }

View File

@@ -122,7 +122,7 @@ class Signal {
} }
}; };
mutable Vector<UniquePtr<BaseSlot>> m_slots; mutable Vector<UPtr<BaseSlot>> m_slots;
public: public:
~Signal() noexcept; ~Signal() noexcept;
@@ -303,7 +303,7 @@ class Signal<Error(Args...)> {
} }
}; };
mutable Vector<UniquePtr<BaseSlot>> m_slots; mutable Vector<UPtr<BaseSlot>> m_slots;
public: public:
~Signal() noexcept; ~Signal() noexcept;

View File

@@ -34,7 +34,7 @@ static ox::Result<Buff> loadFsBuff(const char *path) noexcept {
} }
} }
static ox::Result<ox::UniquePtr<ox::FileSystem>> loadFs(const char *path) noexcept { static ox::Result<ox::UPtr<ox::FileSystem>> loadFs(const char *path) noexcept {
OX_REQUIRE(buff, loadFsBuff(path)); OX_REQUIRE(buff, loadFsBuff(path));
return {ox::make_unique<ox::FileSystem32>(buff.data, buff.size)}; return {ox::make_unique<ox::FileSystem32>(buff.data, buff.size)};
} }

View File

@@ -51,7 +51,7 @@ constexpr auto buildSubscriptStack(const T**, SubscriptStack *s) noexcept {
} }
template<typename T> template<typename T>
constexpr auto buildSubscriptStack(const UniquePtr<T>*, SubscriptStack *s) noexcept { constexpr auto buildSubscriptStack(const UPtr<T>*, SubscriptStack *s) noexcept {
s->push_back({.subscriptType = Subscript::SubscriptType::Ptr}); s->push_back({.subscriptType = Subscript::SubscriptType::Ptr});
} }

View File

@@ -519,7 +519,7 @@ class ModelObject {
protected: protected:
OX_MODEL_FRIEND(ModelObject); OX_MODEL_FRIEND(ModelObject);
friend ModelValue; friend ModelValue;
Vector<UniquePtr<Field>> m_fieldsOrder; Vector<UPtr<Field>> m_fieldsOrder;
HashMap<String, ModelValue*> m_fields; HashMap<String, ModelValue*> m_fields;
const DescriptorType *m_type = nullptr; const DescriptorType *m_type = nullptr;
@@ -692,7 +692,7 @@ class ModelUnion {
}; };
friend constexpr Error model(auto *h, CommonPtrWith<ModelUnion> auto *obj) noexcept; friend constexpr Error model(auto *h, CommonPtrWith<ModelUnion> auto *obj) noexcept;
friend ModelValue; friend ModelValue;
Vector<UniquePtr<Field>> m_fieldsOrder; Vector<UPtr<Field>> m_fieldsOrder;
HashMap<String, Field*> m_fields; HashMap<String, Field*> m_fields;
const DescriptorType *m_type = nullptr; const DescriptorType *m_type = nullptr;
int m_unionIdx = -1; int m_unionIdx = -1;
@@ -718,14 +718,14 @@ class ModelUnion {
m_unionIdx = other.m_unionIdx; m_unionIdx = other.m_unionIdx;
} }
static constexpr Result<UniquePtr<ModelUnion>> make(const DescriptorType *type) noexcept { static constexpr Result<UPtr<ModelUnion>> make(const DescriptorType *type) noexcept {
UniquePtr<ModelUnion> out(new ModelUnion); UPtr<ModelUnion> out(new ModelUnion);
OX_RETURN_ERROR(out->setType(type)); OX_RETURN_ERROR(out->setType(type));
return out; return out;
} }
static constexpr Result<UniquePtr<ModelUnion>> make(const ModelUnion &other) noexcept { static constexpr Result<UPtr<ModelUnion>> make(const ModelUnion &other) noexcept {
return UniquePtr<ModelUnion>(new ModelUnion(other)); return UPtr<ModelUnion>(new ModelUnion(other));
} }
constexpr ox::Result<ModelValue*> at(StringView const&k) noexcept { constexpr ox::Result<ModelValue*> at(StringView const&k) noexcept {

View File

@@ -161,7 +161,7 @@ template<typename T>
constexpr bool isSmartPtr_v = false; constexpr bool isSmartPtr_v = false;
template<typename T> template<typename T>
constexpr bool isSmartPtr_v<::ox::UniquePtr<T>> = true; constexpr bool isSmartPtr_v<::ox::UPtr<T>> = true;
#if __has_include(<array>) #if __has_include(<array>)
template<typename T> template<typename T>

View File

@@ -21,7 +21,7 @@ namespace ox {
class TypeStore { class TypeStore {
private: private:
HashMap<String, UniquePtr<DescriptorType>> m_cache; HashMap<String, UPtr<DescriptorType>> m_cache;
public: public:
constexpr TypeStore() noexcept = default; constexpr TypeStore() noexcept = default;
@@ -86,12 +86,12 @@ class TypeStore {
return getLoad(typeName, typeVersion); return getLoad(typeName, typeVersion);
} }
constexpr void set(const auto &typeId, UniquePtr<DescriptorType> dt) noexcept { constexpr void set(const auto &typeId, UPtr<DescriptorType> dt) noexcept {
m_cache[typeId] = std::move(dt); m_cache[typeId] = std::move(dt);
} }
constexpr void set(const auto &typeId, DescriptorType *dt) noexcept { constexpr void set(const auto &typeId, DescriptorType *dt) noexcept {
m_cache[typeId] = UniquePtr<DescriptorType>(dt); m_cache[typeId] = UPtr<DescriptorType>(dt);
} }
[[nodiscard]] [[nodiscard]]
@@ -105,11 +105,11 @@ class TypeStore {
} }
protected: protected:
virtual Result<UniquePtr<DescriptorType>> loadDescriptor(ox::StringView) noexcept { virtual Result<UPtr<DescriptorType>> loadDescriptor(ox::StringView) noexcept {
return ox::Error(1); return ox::Error(1);
} }
Result<UniquePtr<DescriptorType>> loadDescriptor(ox::StringViewCR name, int version, Result<UPtr<DescriptorType>> loadDescriptor(ox::StringViewCR name, int version,
const ox::TypeParamPack &typeParams) noexcept { const ox::TypeParamPack &typeParams) noexcept {
const auto typeId = buildTypeId(name, version, typeParams); const auto typeId = buildTypeId(name, version, typeParams);
return loadDescriptor(typeId); return loadDescriptor(typeId);

View File

@@ -282,7 +282,7 @@ Error readOC(BufferView const buff, auto &val) noexcept {
try { try {
Json::Value doc; Json::Value doc;
Json::CharReaderBuilder parserBuilder; Json::CharReaderBuilder parserBuilder;
auto parser = UniquePtr<Json::CharReader>(parserBuilder.newCharReader()); auto parser = UPtr<Json::CharReader>(parserBuilder.newCharReader());
OX_ALLOW_UNSAFE_BUFFERS_BEGIN OX_ALLOW_UNSAFE_BUFFERS_BEGIN
if (!parser->parse(buff.data(), buff.data() + buff.size(), &doc, nullptr)) { if (!parser->parse(buff.data(), buff.data() + buff.size(), &doc, nullptr)) {
OX_ALLOW_UNSAFE_BUFFERS_END OX_ALLOW_UNSAFE_BUFFERS_END

View File

@@ -74,7 +74,7 @@ class Preloader: public ModelHandlerBase<Preloader<PlatSpec>, OpType::Reflect> {
const Preloader &operator=(const Preloader &src) = delete; const Preloader &operator=(const Preloader &src) = delete;
const Preloader &operator=(Preloader &&src) = delete; const Preloader &operator=(Preloader &&src) = delete;
constexpr static ox::Result<ox::UniquePtr<Preloader>> make(ox::ios_base::seekdir anchor = ox::ios_base::cur, constexpr static ox::Result<ox::UPtr<Preloader>> make(ox::ios_base::seekdir anchor = ox::ios_base::cur,
std::size_t sz = 0) noexcept; std::size_t sz = 0) noexcept;
template<typename T> template<typename T>
@@ -141,9 +141,9 @@ class Preloader: public ModelHandlerBase<Preloader<PlatSpec>, OpType::Reflect> {
}; };
template<typename PlatSpec> template<typename PlatSpec>
constexpr ox::Result<ox::UniquePtr<Preloader<PlatSpec>>> constexpr ox::Result<ox::UPtr<Preloader<PlatSpec>>>
Preloader<PlatSpec>::make(ox::ios_base::seekdir anchor, std::size_t sz) noexcept { Preloader<PlatSpec>::make(ox::ios_base::seekdir anchor, std::size_t sz) noexcept {
auto p = ox::UniquePtr<Preloader>(new Preloader); auto p = ox::UPtr<Preloader>(new Preloader);
if (const auto err = p->m_writer.seekp(0, anchor)) { if (const auto err = p->m_writer.seekp(0, anchor)) {
return {std::move(p), err}; return {std::move(p), err};
} }

View File

@@ -62,6 +62,8 @@ struct [[nodiscard]] Error {
return errCode; return errCode;
} }
constexpr void throwException() const;
constexpr Error reoriginate( constexpr Error reoriginate(
ErrorCode const pErrCode, ErrorCode const pErrCode,
CString const pMsg = nullptr, CString const pMsg = nullptr,
@@ -121,6 +123,14 @@ struct Exception: public std::exception {
} }
}; };
constexpr void Error::throwException() const {
if (errCode) [[unlikely]] {
throw Exception{*this};
}
}
[[noreturn]] [[noreturn]]
void panic( void panic(
Error const &err, Error const &err,

View File

@@ -179,26 +179,26 @@ constexpr bool operator!=(std::nullptr_t, const SharedPtr<T> &p2) noexcept {
template<typename T, typename Deleter = DefaultDelete> template<typename T, typename Deleter = DefaultDelete>
class UniquePtr { class UPtr {
private: private:
T *m_t = nullptr; T *m_t = nullptr;
public: public:
using value_type = T; using value_type = T;
explicit constexpr UniquePtr(T *t = nullptr) noexcept: m_t(t) { explicit constexpr UPtr(T *t = nullptr) noexcept: m_t(t) {
} }
constexpr UniquePtr(UniquePtr&) = delete; constexpr UPtr(UPtr&) = delete;
constexpr UniquePtr(const UniquePtr&) = delete; constexpr UPtr(const UPtr&) = delete;
template<typename U, typename UDeleter> template<typename U, typename UDeleter>
constexpr UniquePtr(UniquePtr<U, UDeleter> &&other) noexcept { constexpr UPtr(UPtr<U, UDeleter> &&other) noexcept {
m_t = other.release(); m_t = other.release();
} }
constexpr ~UniquePtr() { constexpr ~UPtr() {
Deleter()(m_t); Deleter()(m_t);
} }
@@ -213,24 +213,24 @@ class UniquePtr {
return m_t; return m_t;
} }
constexpr void reset(UniquePtr &&other = UniquePtr()) { constexpr void reset(UPtr &&other = UPtr()) {
auto t = m_t; auto t = m_t;
m_t = other.release(); m_t = other.release();
Deleter()(t); Deleter()(t);
} }
constexpr UniquePtr &operator=(UniquePtr const&other) = delete; constexpr UPtr &operator=(UPtr const&other) = delete;
template<typename U, typename UDeleter> template<typename U, typename UDeleter>
constexpr UniquePtr &operator=(UniquePtr<U, UDeleter> const&other) = delete; constexpr UPtr &operator=(UPtr<U, UDeleter> const&other) = delete;
constexpr UniquePtr &operator=(UniquePtr<T> &&other) noexcept { constexpr UPtr &operator=(UPtr<T> &&other) noexcept {
reset(std::move(other)); reset(std::move(other));
return *this; return *this;
} }
template<typename U, typename UDeleter> template<typename U, typename UDeleter>
constexpr UniquePtr &operator=(UniquePtr<U, UDeleter> &&other) noexcept { constexpr UPtr &operator=(UPtr<U, UDeleter> &&other) noexcept {
reset(std::move(other)); reset(std::move(other));
return *this; return *this;
} }
@@ -249,37 +249,34 @@ class UniquePtr {
}; };
template<typename T, typename Deleter = DefaultDelete>
using UPtr = UniquePtr<T, Deleter>;
template<typename T> template<typename T>
constexpr bool operator==(const UniquePtr<T> &p1, const UniquePtr<T> &p2) noexcept { constexpr bool operator==(const UPtr<T> &p1, const UPtr<T> &p2) noexcept {
return p1.get() == p2.get(); return p1.get() == p2.get();
} }
template<typename T> template<typename T>
constexpr bool operator==(const UniquePtr<T> &p1, std::nullptr_t) noexcept { constexpr bool operator==(const UPtr<T> &p1, std::nullptr_t) noexcept {
return p1.get() == nullptr; return p1.get() == nullptr;
} }
template<typename T> template<typename T>
constexpr bool operator==(std::nullptr_t, const UniquePtr<T> &p2) noexcept { constexpr bool operator==(std::nullptr_t, const UPtr<T> &p2) noexcept {
return p2.get() == nullptr; return p2.get() == nullptr;
} }
template<typename T> template<typename T>
constexpr bool operator!=(const UniquePtr<T> &p1, const UniquePtr<T> &p2) noexcept { constexpr bool operator!=(const UPtr<T> &p1, const UPtr<T> &p2) noexcept {
return p1.get() != p2.get(); return p1.get() != p2.get();
} }
template<typename T> template<typename T>
constexpr bool operator!=(const UniquePtr<T> &p1, std::nullptr_t) noexcept { constexpr bool operator!=(const UPtr<T> &p1, std::nullptr_t) noexcept {
return !p1.get(); return !p1.get();
} }
template<typename T> template<typename T>
constexpr bool operator!=(std::nullptr_t, const UniquePtr<T> &p2) noexcept { constexpr bool operator!=(std::nullptr_t, const UPtr<T> &p2) noexcept {
return !p2.get(); return !p2.get();
} }
@@ -287,14 +284,14 @@ constexpr bool operator!=(std::nullptr_t, const UniquePtr<T> &p2) noexcept {
template<typename T, typename U = T, typename ...Args> template<typename T, typename U = T, typename ...Args>
[[nodiscard]] [[nodiscard]]
constexpr auto make_unique(Args&&... args) { constexpr auto make_unique(Args&&... args) {
return UniquePtr<U>(new T(ox::forward<Args>(args)...)); return UPtr<U>(new T(ox::forward<Args>(args)...));
} }
template<typename T, typename U = T, typename ...Args> template<typename T, typename U = T, typename ...Args>
[[nodiscard]] [[nodiscard]]
constexpr Result<UniquePtr<U>> make_unique_catch(Args&&... args) noexcept { constexpr Result<UPtr<U>> make_unique_catch(Args&&... args) noexcept {
try { try {
return UniquePtr<U>(new T(ox::forward<Args>(args)...)); return UPtr<U>(new T(ox::forward<Args>(args)...));
} catch (ox::Exception const&ex) { } catch (ox::Exception const&ex) {
return ex.toError(); return ex.toError();
} }

View File

@@ -189,8 +189,4 @@ ox::Error setRomFs(Context &ctx, ox::UPtr<ox::FileSystem> &&fs) noexcept;
ox::Result<ox::UPtr<ox::FileSystem>> loadRomFs(ox::StringViewCR path) noexcept; ox::Result<ox::UPtr<ox::FileSystem>> loadRomFs(ox::StringViewCR path) noexcept;
ox::Result<char*> loadRom(ox::StringViewCR path = "") noexcept;
void unloadRom(char*) noexcept;
} }

View File

@@ -37,9 +37,9 @@ class Module {
virtual ox::Vector<PackTransform> packTransforms() const noexcept; virtual ox::Vector<PackTransform> packTransforms() const noexcept;
}; };
void registerModule(Module const*mod) noexcept; void registerModule(Module const *mod) noexcept;
[[nodiscard]] [[nodiscard]]
ox::Vector<keel::Module const*> const &modules() noexcept; ox::Vector<Module const*> const &modules() noexcept;
} }

View File

@@ -19,7 +19,7 @@ class Wrap {
public: public:
virtual ~Wrap() = default; virtual ~Wrap() = default;
[[nodiscard]] [[nodiscard]]
virtual ox::CStringView typeName() const noexcept = 0; virtual ox::StringLiteral typeName() const noexcept = 0;
[[nodiscard]] [[nodiscard]]
virtual int typeVersion() const noexcept = 0; virtual int typeVersion() const noexcept = 0;
[[nodiscard]] [[nodiscard]]
@@ -48,7 +48,7 @@ class WrapRef final: public WrapT<T> {
constexpr explicit WrapRef(T &obj): m_obj{obj} {} constexpr explicit WrapRef(T &obj): m_obj{obj} {}
[[nodiscard]] [[nodiscard]]
ox::CStringView typeName() const noexcept override { ox::StringLiteral typeName() const noexcept override {
return ox::ModelTypeName_v<T>; return ox::ModelTypeName_v<T>;
} }
@@ -77,7 +77,7 @@ class WrapInline final: public WrapT<T> {
} }
[[nodiscard]] [[nodiscard]]
ox::CStringView typeName() const noexcept override { ox::StringLiteral typeName() const noexcept override {
return ox::ModelTypeName_v<T>; return ox::ModelTypeName_v<T>;
} }
@@ -108,7 +108,7 @@ class BaseConverter {
constexpr virtual ~BaseConverter() noexcept = default; constexpr virtual ~BaseConverter() noexcept = default;
[[nodiscard]] [[nodiscard]]
constexpr virtual ox::StringView srcTypeName() const noexcept = 0; constexpr virtual ox::StringLiteral srcTypeName() const noexcept = 0;
[[nodiscard]] [[nodiscard]]
constexpr virtual int srcTypeVersion() const noexcept = 0; constexpr virtual int srcTypeVersion() const noexcept = 0;
@@ -154,7 +154,7 @@ class ConverterFunc final: public BaseConverter {
using DstType = typename decltype(extractParams(Func))::Dst; using DstType = typename decltype(extractParams(Func))::Dst;
[[nodiscard]] [[nodiscard]]
constexpr ox::StringView srcTypeName() const noexcept override { constexpr ox::StringLiteral srcTypeName() const noexcept override {
return ox::ModelTypeName_v<SrcType>; return ox::ModelTypeName_v<SrcType>;
} }
@@ -253,19 +253,22 @@ template<typename DstType>
ox::Result<DstType> convertObjToObj( ox::Result<DstType> convertObjToObj(
Context &ctx, Context &ctx,
auto &src) noexcept { auto &src) noexcept {
OX_REQUIRE_M(out, convert(ctx, WrapRef{src}, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>)); OX_REQUIRE_M(out,
convert(ctx, WrapRef{src}, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
return std::move(wrapCast(*out)); return std::move(wrapCast(*out));
} }
template<typename DstType> template<typename DstType>
ox::Result<DstType> convert(Context &ctx, ox::BufferView const &src) noexcept { ox::Result<DstType> convert(Context &ctx, ox::BufferView const &src) noexcept {
OX_REQUIRE(out, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>)); OX_REQUIRE(out,
convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
return std::move(wrapCast<DstType>(*out)); return std::move(wrapCast<DstType>(*out));
} }
template<typename DstType> template<typename DstType>
ox::Error convert(Context &ctx, ox::BufferView const &buff, DstType &outObj) noexcept { ox::Error convert(Context &ctx, ox::BufferView const &buff, DstType &outObj) noexcept {
OX_REQUIRE(out, convert(ctx, buff, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>)); OX_REQUIRE(out,
convert(ctx, buff, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
outObj = std::move(wrapCast<DstType>(*out)); outObj = std::move(wrapCast<DstType>(*out));
return {}; return {};
} }
@@ -280,7 +283,8 @@ ox::Error convertObjToObj(Context &ctx, auto &src, DstType &outObj) noexcept {
template<typename DstType> template<typename DstType>
ox::Result<ox::Buffer> convertBuffToBuff( ox::Result<ox::Buffer> convertBuffToBuff(
Context &ctx, ox::BufferView const &src, ox::ClawFormat const fmt) noexcept { Context &ctx, ox::BufferView const &src, ox::ClawFormat const fmt) noexcept {
OX_REQUIRE(out, convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>)); OX_REQUIRE(out,
convert(ctx, src, ox::ModelTypeName_v<DstType>, ox::ModelTypeVersion_v<DstType>));
return ox::writeClaw<DstType>(wrapCast<DstType>(*out), fmt); return ox::writeClaw<DstType>(wrapCast<DstType>(*out), fmt);
} }