Skip to content

Commit

Permalink
everywhere: Enabled SeparateDefinitionBlocks and reformated code.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Aug 2, 2024
1 parent 8952035 commit 7858fab
Show file tree
Hide file tree
Showing 45 changed files with 111 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/.clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ForEachMacros: ["__dummy_foreach"]
SpaceBeforeParens: ControlStatementsExceptForEachMacros
QualifierAlignment: Right
AlignAfterOpenBracket: BlockIndent
SeparateDefinitionBlocks: Always

IncludeBlocks: Regroup
IncludeCategories:
Expand Down
2 changes: 1 addition & 1 deletion src/impls/impl-posix/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ Res<> consumeErrno() {
if (errno == 0) {
return Ok();
}

auto err = fromLastErrno();
errno = 0;
return err;
Expand Down
1 change: 1 addition & 0 deletions src/impls/impl-uring/async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ struct UringSched : public Sys::Sched {
struct Job : public _Job {
TimeStamp _until;
Async::Promise<> _promise;

struct __kernel_timespec _ts {};

Job(TimeStamp until)
Expand Down
2 changes: 2 additions & 0 deletions src/impls/impl-wasm/sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ struct JSConsole : public Sys::Fd {
} _proto;

Io::BufferWriter _buf;

JSConsole(Proto proto) : _proto(proto) {}

Sys::Handle handle() const override {
return Handle{(usize)_proto};
}

Res<usize> read(MutBytes) override {
notImplemented();
}
Expand Down
10 changes: 10 additions & 0 deletions src/libs/karm-base/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ namespace Karm::Async {
// MARK: Concepts --------------------------------------------------------------

struct Inline {};

static constexpr Inline INLINE;

struct Later {};

static constexpr Later LATER;

struct InlineOrLater {
constexpr InlineOrLater(Inline) {}

constexpr InlineOrLater(Later) {}
};

Expand Down Expand Up @@ -133,10 +136,13 @@ Awaiter<S> operator co_await(S s) {
template <Sender S>
static inline typename S::Inner run(S s, auto wait) {
Opt<typename S::Inner> ret;

struct Receiver {
Opt<typename S::Inner> &_ret;

void recv(InlineOrLater, typename S::Inner r) { _ret = r; }
};

auto op = s.connect(Receiver{ret});
if (op.start())
return ret.take();
Expand All @@ -148,10 +154,13 @@ static inline typename S::Inner run(S s, auto wait) {
template <Sender S>
static inline typename S::Inner run(S s) {
Opt<typename S::Inner> ret;

struct Receiver {
Opt<typename S::Inner> &_ret;

void recv(InlineOrLater, typename S::Inner r) { _ret = r; }
};

auto op = s.connect(Receiver{ret});
if (not op.start()) [[unlikely]]
panic("run() called on pending operation without a wait function");
Expand Down Expand Up @@ -209,6 +218,7 @@ struct Cancelation : public Meta::Static {
Cancelation *_c = nullptr;

Token() = default;

Token(Cancelation &c) : _c{&c} {}

bool canceled() const {
Expand Down
1 change: 1 addition & 0 deletions src/libs/karm-base/defer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ struct Defer : Meta::Static {
F _f;

always_inline Defer(F f) : _f(f) {}

always_inline ~Defer() {
_f();
}
Expand Down
4 changes: 4 additions & 0 deletions src/libs/karm-base/func.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ struct Func<Out(In...)> {
template <typename F>
struct Wrap : _Wrap {
F _f;

Wrap(F &&f) : _f(std::move(f)) {}

Out operator()(In... in) const override { return _f(std::forward<In>(in)...); }
};

Expand Down Expand Up @@ -88,7 +90,9 @@ struct SharedFunc<Out(In...)> {
template <typename F>
struct Wrap : _Wrap {
F _f;

Wrap(F &&f) : _f(std::move(f)) {}

Out operator()(In... in) const override { return _f(std::forward<In>(in)...); }
};

Expand Down
2 changes: 2 additions & 0 deletions src/libs/karm-base/list.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,11 @@ struct Ll {
}

T *head() { return _head; }

T const *head() const { return _head; }

T *tail() { return _tail; }

T const *tail() const { return _tail; }

usize len() const { return _len; }
Expand Down
1 change: 1 addition & 0 deletions src/libs/karm-base/opt.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct [[nodiscard]] Opt {
struct _Empty {};

bool _present;

union {
_Empty _empty;
T _value;
Expand Down
7 changes: 7 additions & 0 deletions src/libs/karm-base/rune.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,15 @@ struct _Multiple {
}

always_inline constexpr Unit &operator[](usize i) { return _buf[i]; }

always_inline constexpr Unit const &operator[](usize i) const { return _buf[i]; }

always_inline always_inline constexpr Unit *buf() { return _buf.buf(); }

always_inline constexpr Unit const *buf() const { return _buf.buf(); }

always_inline constexpr usize len() const { return _buf.len(); }

always_inline constexpr usize rem() const { return N - len(); }
};

Expand All @@ -62,10 +66,13 @@ struct _Single {
}

always_inline constexpr Unit &operator[](usize) { return _buf; }

always_inline constexpr Unit const &operator[](usize) const { return _buf; }

always_inline constexpr Unit *buf() { return &_buf; }

always_inline constexpr Unit const *buf() const { return &_buf; }

always_inline constexpr usize len() const { return 1; }
};

Expand Down
6 changes: 6 additions & 0 deletions src/libs/karm-base/size.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
namespace Karm {

inline constexpr usize kib(usize v) { return v * 1024; }

inline constexpr usize mib(usize v) { return kib(v * 1024); }

inline constexpr usize gib(usize v) { return mib(v * 1024); }

inline constexpr usize tib(usize v) { return gib(v * 1024); }

inline constexpr usize toKib(usize v) { return v / 1024; }

inline constexpr usize toMib(usize v) { return toKib(v) / 1024; }

inline constexpr usize toGib(usize v) { return toMib(v) / 1024; }

inline constexpr usize toTib(usize v) { return toGib(v) / 1024; }

} // namespace Karm
3 changes: 3 additions & 0 deletions src/libs/karm-base/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,15 @@ using String = _String<Utf8>;
template <auto N>
struct StrLit {
char _buf[N];

constexpr StrLit(char const (&buf)[N]) {
for (usize i = 0; i < N; i++) {
_buf[i] = buf[i];
}
}

constexpr operator Str() const { return _buf; }

constexpr operator char const *() const { return _buf; }
};

Expand Down
2 changes: 2 additions & 0 deletions src/libs/karm-base/time.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ struct Day {

struct Month {
enum _Name {

#define ITER(NAME, ...) NAME,
FOREACH_MONTH(ITER)
#undef ITER
Expand Down Expand Up @@ -392,6 +393,7 @@ struct Year {

struct DayOfWeek {
enum _Raw : usize {

#define ITER(NAME, ...) NAME,
FOREACH_DAY_OF_WEEK(ITER)
#undef ITER
Expand Down
1 change: 1 addition & 0 deletions src/libs/karm-events/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ struct MouseEvent {
SCROLL,
MOVE,
} type;

Math::Vec2i pos{};
Math::Vec2f scroll{};
Math::Vec2i delta{};
Expand Down
1 change: 1 addition & 0 deletions src/libs/karm-gfx/filters.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ using _Filters = Union<

struct Filter : public _Filters {
using _Filters::_Filters;

void apply(MutPixels s) const {
visit([&](auto const &filter) {
filter.apply(s);
Expand Down
1 change: 1 addition & 0 deletions src/libs/karm-image/jpeg/decoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ void Decoder::idct(Array<short, 64> &mcu) {
mcu[i * 8 + 7] = b0 - b7;
}
}

Res<> Decoder::decode(Gfx::MutPixels pixels) {
for (usize i = 0; i < _mcus.len(); i += _componentCount) {
usize x = (i / _componentCount) % mcuWidth();
Expand Down
2 changes: 2 additions & 0 deletions src/libs/karm-image/jpeg/decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,11 @@ struct Decoder {
isize _height = 8;

isize width() const { return _width; }

isize height() const { return _height; }

isize mcuWidth() const { return (_width + 7) / 8; }

isize mcuHeight() const { return (_height + 7) / 8; }

struct Component {
Expand Down
24 changes: 24 additions & 0 deletions src/libs/karm-io/bscan.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,43 +184,67 @@ struct BScan {
}

always_inline constexpr u8 nextU8be() { return nextBe<u8>(); }

always_inline constexpr u16 nextU16be() { return nextBe<u16>(); }

always_inline constexpr u32 nextU32be() { return nextBe<u32>(); }

always_inline constexpr u64 nextU64be() { return nextBe<u64>(); }

always_inline constexpr u8 nextU8le() { return nextLe<u8>(); }

always_inline constexpr u16 nextU16le() { return nextLe<u16>(); }

always_inline constexpr u32 nextU32le() { return nextLe<u32>(); }

always_inline constexpr u64 nextU64le() { return nextLe<u64>(); }

always_inline constexpr i8 nextI8be() { return nextBe<i8>(); }

always_inline constexpr i16 nextI16be() { return nextBe<i16>(); }

always_inline constexpr i32 nextI32be() { return nextBe<i32>(); }

always_inline constexpr i64 nextI64be() { return nextBe<i64>(); }

always_inline constexpr i8 nextI8le() { return nextLe<i8>(); }

always_inline constexpr i16 nextI16le() { return nextLe<i16>(); }

always_inline constexpr i32 nextI32le() { return nextLe<i32>(); }

always_inline constexpr i64 nextI64le() { return nextLe<i64>(); }

always_inline constexpr u8 peekU8be() { return peekBe<u8>(); }

always_inline constexpr u16 peekU16be() { return peekBe<u16>(); }

always_inline constexpr u32 peekU32be() { return peekBe<u32>(); }

always_inline constexpr u64 peekU64be() { return peekBe<u64>(); }

always_inline constexpr u8 peekU8le() { return peekLe<u8>(); }

always_inline constexpr u16 peekU16le() { return peekLe<u16>(); }

always_inline constexpr u32 peekU32le() { return peekLe<u32>(); }

always_inline constexpr u64 peekU64le() { return peekLe<u64>(); }

always_inline constexpr i8 peekI8be() { return peekBe<i8>(); }

always_inline constexpr i16 peekI16be() { return peekBe<i16>(); }

always_inline constexpr i32 peekI32be() { return peekBe<i32>(); }

always_inline constexpr i64 peekI64be() { return peekBe<i64>(); }

always_inline constexpr i8 peekI8le() { return peekLe<i8>(); }

always_inline constexpr i16 peekI16le() { return peekLe<i16>(); }

always_inline constexpr i32 peekI32le() { return peekLe<i32>(); }

always_inline constexpr i64 peekI64le() { return peekLe<i64>(); }

always_inline constexpr Str nextStr(usize n) {
Expand Down
2 changes: 0 additions & 2 deletions src/libs/karm-io/traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,6 @@ struct TextEncoder :
Res<usize> write(Bytes bytes) override {
return _writer.write(bytes);
}


};

} // namespace Karm::Io
1 change: 1 addition & 0 deletions src/libs/karm-kira/dialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Ui::Child dialogContent(Ui::Children children) {
Ui::align(Math::Align::CENTER | Math::Align::CLAMP) |
Ui::insets(32);
}

Ui::Child dialogTitleBar(String title) {
return Ui::vflow(
Ui::hflow(
Expand Down
1 change: 1 addition & 0 deletions src/libs/karm-math/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct Path {
auto iterContours() const {
struct _Contour : public Slice<Math::Vec2f> {
bool close;

_Contour(Slice<Math::Vec2f> slice, bool close)
: Slice<Math::Vec2f>(slice), close(close) {}
};
Expand Down
1 change: 1 addition & 0 deletions src/libs/karm-math/radii.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ struct Radii {
struct {
T a, b, c, d, e, f, g, h;
};

Array<T, 8> radii;
};

Expand Down
6 changes: 6 additions & 0 deletions src/libs/karm-math/rect.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,21 @@ union Rect {
}

always_inline constexpr Vec2<T> topStart() const { return {x, y}; }

always_inline constexpr Vec2<T> topEnd() const { return {x + width, y}; }

always_inline constexpr Vec2<T> bottomStart() const { return {x, y + height}; }

always_inline constexpr Vec2<T> bottomEnd() const { return {x + width, y + height}; }

always_inline constexpr Vec2<T> center() const { return {x + width / 2, y + height / 2}; }

always_inline constexpr Vec2<T> topCenter() const { return {x + width / 2, y}; }

always_inline constexpr Vec2<T> bottomCenter() const { return {x + width / 2, y + height}; }

always_inline constexpr Vec2<T> startCenter() const { return {x, y + height / 2}; }

always_inline constexpr Vec2<T> endCenter() const { return {x + width, y + height / 2}; }

always_inline constexpr Array<Vec2<T>, 4> vertices() const {
Expand Down
1 change: 1 addition & 0 deletions src/libs/karm-media/icon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Karm::Media {

static Opt<Strong<Text::Fontface>> _fontface = NONE;

Strong<Text::Fontface> Icon::fontface() {
if (not _fontface)
_fontface = Text::loadFontfaceOrFallback("bundle://fonts-mdi/fonts/Material-Design-Icons.ttf"_url).unwrap();
Expand Down
Loading

0 comments on commit 7858fab

Please sign in to comment.