[keel] Style updates

This commit is contained in:
Gary Talent 2025-04-17 21:36:24 -05:00
parent ee63a4a1e4
commit 8f03af99a7
3 changed files with 32 additions and 31 deletions

View File

@ -36,7 +36,7 @@ ox::Result<ox::ModelObject> readAsset(ox::TypeStore &ts, ox::BufferView buff) no
return ox::readClaw(ts, buff); return ox::readClaw(ts, buff);
} }
ox::Result<ox::StringView> readAssetTypeId(ox::BufferView buff) noexcept { ox::Result<ox::StringView> readAssetTypeId(ox::BufferView const buff) noexcept {
const auto err = readUuidHeader(buff).error; const auto err = readUuidHeader(buff).error;
const auto offset = err ? 0u : K1HdrSz; const auto offset = err ? 0u : K1HdrSz;
if (offset >= buff.size()) [[unlikely]] { if (offset >= buff.size()) [[unlikely]] {

View File

@ -6,13 +6,11 @@
#include <ox/clargs/clargs.hpp> #include <ox/clargs/clargs.hpp>
#include <ox/fs/fs.hpp> #include <ox/fs/fs.hpp>
#include <ox/logconn/def.hpp>
#include <ox/logconn/logconn.hpp>
#include <ox/oc/write.hpp> #include <ox/oc/write.hpp>
#include <keel/keel.hpp> #include <keel/keel.hpp>
static ox::Error writeFileBuff(ox::StringView path, ox::BufferView const buff) noexcept { static ox::Error writeFileBuff(ox::StringViewCR path, ox::BufferView const &buff) noexcept {
try { try {
std::ofstream f(std::string(toStdStringView(path)), std::ios::binary); std::ofstream f(std::string(toStdStringView(path)), std::ios::binary);
f.write(buff.data(), static_cast<intptr_t>(buff.size())); f.write(buff.data(), static_cast<intptr_t>(buff.size()));
@ -22,7 +20,7 @@ static ox::Error writeFileBuff(ox::StringView path, ox::BufferView const buff) n
return {}; return {};
} }
static ox::Result<ox::Buffer> readFileBuff(ox::StringView path) noexcept { static ox::Result<ox::Buffer> readFileBuff(ox::StringViewCR path) noexcept {
std::ifstream file(std::string(toStdStringView(path)), std::ios::binary | std::ios::ate); std::ifstream file(std::string(toStdStringView(path)), std::ios::binary | std::ios::ate);
if (!file.good()) { if (!file.good()) {
oxErrorf("Could not find OxFS file: {}", path); oxErrorf("Could not find OxFS file: {}", path);
@ -42,7 +40,7 @@ static ox::Result<ox::Buffer> readFileBuff(ox::StringView path) noexcept {
static ox::Error generateTypes(ox::TypeStore &ts) noexcept { static ox::Error generateTypes(ox::TypeStore &ts) noexcept {
for (auto const mod : keel::modules()) { for (auto const mod : keel::modules()) {
for (auto gen : mod->types()) { for (auto const gen : mod->types()) {
OX_RETURN_ERROR(gen(ts)); OX_RETURN_ERROR(gen(ts));
} }
} }
@ -50,10 +48,10 @@ static ox::Error generateTypes(ox::TypeStore &ts) noexcept {
} }
static ox::Error pack( static ox::Error pack(
ox::StringView argSrc, ox::StringViewCR argSrc,
ox::StringView argRomBin, ox::StringViewCR argRomBin,
ox::StringView argManifest, ox::StringViewCR argManifest,
ox::StringView projectDataDir) noexcept { ox::StringViewCR projectDataDir) noexcept {
ox::Buffer dstBuff(32 * ox::units::MB); ox::Buffer dstBuff(32 * ox::units::MB);
OX_RETURN_ERROR(ox::FileSystem32::format(dstBuff.data(), dstBuff.size())); OX_RETURN_ERROR(ox::FileSystem32::format(dstBuff.data(), dstBuff.size()));
ox::FileSystem32 dst(dstBuff); ox::FileSystem32 dst(dstBuff);
@ -82,10 +80,10 @@ static ox::Error pack(
} }
ox::Error run( ox::Error run(
[[maybe_unused]] ox::StringView project, [[maybe_unused]] ox::StringView const project,
[[maybe_unused]] ox::StringView appName, [[maybe_unused]] ox::StringView const appName,
ox::StringView projectDataDir, ox::StringView const projectDataDir,
ox::SpanView<ox::CString> argv) noexcept { ox::SpanView<ox::CString> const argv) noexcept {
ox::ClArgs const args(argv); ox::ClArgs const args(argv);
auto const argSrc = args.getString("src", ""); auto const argSrc = args.getString("src", "");
auto const argRomBin = args.getString("rom-bin", ""); auto const argRomBin = args.getString("rom-bin", "");

View File

@ -11,13 +11,12 @@
namespace keel { namespace keel {
static ox::Error pathToInode( static ox::Error pathToInode(
keel::Context &ctx, Context &ctx,
ox::FileSystem &dest, ox::FileSystem const &dest,
ox::ModelObject &obj) noexcept { ox::ModelObject &obj) noexcept {
auto &o = obj; OX_REQUIRE(typeVal, obj.at("type"));
OX_REQUIRE(typeVal, o.at("type"));
auto const type = static_cast<ox::FileAddressType>(typeVal->get<int8_t>()); auto const type = static_cast<ox::FileAddressType>(typeVal->get<int8_t>());
OX_REQUIRE(dataVal, o.at("data")); OX_REQUIRE(dataVal, obj.at("data"));
auto &data = dataVal->get<ox::ModelUnion>(); auto &data = dataVal->get<ox::ModelUnion>();
ox::String path; ox::String path;
switch (type) { switch (type) {
@ -47,13 +46,17 @@ static ox::Error pathToInode(
} }
static ox::Error transformFileAddressesObj( static ox::Error transformFileAddressesObj(
keel::Context &ctx, ox::FileSystem &dest, ox::ModelObject &obj) noexcept; Context &ctx,
ox::FileSystem const &dest,
ox::ModelObject &obj) noexcept;
static ox::Error transformFileAddressesVec( static ox::Error transformFileAddressesVec(
keel::Context &ctx, ox::FileSystem &dest, ox::ModelValueVector &v) noexcept; Context &ctx,
ox::FileSystem const &dest,
ox::ModelValueVector &v) noexcept;
static ox::Error transformFileAddresses( static ox::Error transformFileAddresses(
keel::Context &ctx, Context &ctx,
ox::FileSystem &dest, ox::FileSystem const &dest,
ox::ModelValue &v) noexcept { ox::ModelValue &v) noexcept {
if (v.type() == ox::ModelValue::Type::Object) { if (v.type() == ox::ModelValue::Type::Object) {
auto &obj = v.get<ox::ModelObject>(); auto &obj = v.get<ox::ModelObject>();
@ -66,8 +69,8 @@ static ox::Error transformFileAddresses(
} }
static ox::Error transformFileAddressesVec( static ox::Error transformFileAddressesVec(
keel::Context &ctx, Context &ctx,
ox::FileSystem &dest, ox::FileSystem const &dest,
ox::ModelValueVector &v) noexcept { ox::ModelValueVector &v) noexcept {
for (auto &f : v) { for (auto &f : v) {
OX_RETURN_ERROR(transformFileAddresses(ctx, dest, f)); OX_RETURN_ERROR(transformFileAddresses(ctx, dest, f));
@ -80,13 +83,13 @@ static ox::Error transformFileAddressesVec(
* @return error * @return error
*/ */
static ox::Error transformFileAddressesObj( static ox::Error transformFileAddressesObj(
keel::Context &ctx, Context &ctx,
ox::FileSystem &dest, ox::FileSystem const &dest,
ox::ModelObject &obj) noexcept { ox::ModelObject &obj) noexcept {
if (obj.typeName() == "net.drinkingtea.ox.FileAddress" && obj.typeVersion() == 1) { if (obj.typeName() == "net.drinkingtea.ox.FileAddress" && obj.typeVersion() == 1) {
return pathToInode(ctx, dest, obj); return pathToInode(ctx, dest, obj);
} }
for (auto &f : obj) { for (auto const &f : obj) {
auto &v = f->value; auto &v = f->value;
OX_RETURN_ERROR(transformFileAddresses(ctx, dest, v)); OX_RETURN_ERROR(transformFileAddresses(ctx, dest, v));
} }
@ -111,7 +114,7 @@ static ox::Error performPackTransforms(
static ox::Error doTransformations( static ox::Error doTransformations(
Manifest &manifest, Manifest &manifest,
keel::Context &ctx, Context &ctx,
ox::TypeStore &ts, ox::TypeStore &ts,
ox::FileSystem &dest, ox::FileSystem &dest,
ox::StringViewCR filePath) noexcept { ox::StringViewCR filePath) noexcept {
@ -134,7 +137,7 @@ static ox::Error doTransformations(
// transformations need to be done after the copy to the new FS is complete // transformations need to be done after the copy to the new FS is complete
static ox::Error transformClaw( static ox::Error transformClaw(
Manifest &manifest, Manifest &manifest,
keel::Context &ctx, Context &ctx,
ox::TypeStore &ts, ox::TypeStore &ts,
ox::FileSystem &dest, ox::FileSystem &dest,
ox::StringViewCR path) noexcept { ox::StringViewCR path) noexcept {
@ -200,7 +203,7 @@ static ox::Error copy(
ox::Error pack( ox::Error pack(
Manifest &manifest, Manifest &manifest,
keel::Context &ctx, Context &ctx,
ox::TypeStore &ts, ox::TypeStore &ts,
ox::FileSystem &dest) noexcept { ox::FileSystem &dest) noexcept {
OX_RETURN_ERROR(copy(manifest, *ctx.rom, dest, "/")); OX_RETURN_ERROR(copy(manifest, *ctx.rom, dest, "/"));