Skip to content

Commit

Permalink
karm-base: Removed a bunch of unused macros.
Browse files Browse the repository at this point in the history
  • Loading branch information
sleepy-monax committed Dec 13, 2024
1 parent e969f7b commit 4016eed
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 82 deletions.
2 changes: 1 addition & 1 deletion src/apps/hideo-zoo/page-print-dialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ static inline Page PAGE_PRINT_DIALOG{
Ui::showDialog(
n,
Kr::printDialog([](Print::Settings const &Settings) -> Vec<Strong<Scene::Page>> {
return {makeStrong<Scene::Page>(Settings.paper.size().cast<isize>())};
return {makeStrong<Scene::Page>(Settings.paper)};
})
);
},
Expand Down
4 changes: 3 additions & 1 deletion src/impls/impl-sdl/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,9 @@ static Res<> _setWindowIcon(SDL_Window *window) {
auto *surface = SDL_CreateRGBSurface(0, image.width(), image.height(), 32, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
if (not surface)
return Error::other(SDL_GetError());
defer$(SDL_FreeSurface(surface));
Defer defer{[&] {
SDL_FreeSurface(surface);
}};

Gfx::MutPixels pixels{
surface->pixels,
Expand Down
1 change: 0 additions & 1 deletion src/impls/impl-wasm/macro.h

This file was deleted.

4 changes: 3 additions & 1 deletion src/kernel/hjert-core/syscalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ Res<> doLog(Task &self, UserSlice<Str> msg) {
try$(self.ensure(Hj::Pledge::LOG));
return msg.with(self.space(), [&](Str str) -> Res<> {
Logger::_Embed::loggerLock();
defer$(Logger::_Embed::loggerUnlock());
Defer defer{[] {
Logger::_Embed::loggerUnlock();
}};

auto styledLabel = Cli::styled(self.label(), Cli::style(Cli::random(self.id())));
try$(Io::format(Hjert::Arch::globalOut(), "{} | ", Io::aligned(styledLabel, Io::Align::LEFT, 26)));
Expand Down
63 changes: 0 additions & 63 deletions src/libs/karm-base/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,76 +8,13 @@ namespace Karm {

// MARK: Macros ----------------------------------------------------------------

// Banned functions and features

#define goto _Pragma("GCC error \"goto is not allowed\"") goto
#define throw _Pragma("GCC error \"throw is not allowed\"") throw
#define try _Pragma("GCC error \"try is not allowed\"") try
#define catch _Pragma("GCC error \"catch is not allowed\"") catch
#define throw_unless _Pragma("GCC error \"throw_unless is not allowed\"") throw_unless
#define dynamic_cast _Pragma("GCC error \"dynamic_cast is not allowed\"") dynamic_cast

// Safety

// https://clang.llvm.org/docs/AttributeReference.html#lifetimebound
#define lifetimebound [[clang::lifetimebound]]

// Utilities

#define arrayLen$(ARR) (sizeof(ARR) / sizeof(ARR[0]))

#define __concat$(LHS, RHS) LHS##RHS
#define concat$(LHS, RHS) __concat$(LHS, RHS)

#define __stringify$(SYM) #SYM
#define stringify$(SYM) __stringify$(SYM)

#define var$(NAME) concat$(__m_##NAME##_, __LINE__)

#define __count$(_0, _1_, _2_, _3_, _4_, _5_, _6_, _7_, _8_, _9_, _10_, _11_, _12_, _13_, _14_, _15_, _16_, _17_, _18_, _19_, _20_, _21_, _22_, _23_, _24_, _25_, _26_, _27_, _28_, _29_, _30_, _31_, _32_, _33_, _34_, _35_, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, count, ...) count
#define count$(__args...) __count$(0, ##__args, 70, 69, 68, 67, 66, 65, 64, 63, 62, 61, 60, 59, 58, 57, 56, 55, 54, 53, 52, 51, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)

// Eval

#define __eval0$(...) __VA_ARGS__
#define __eval1$(...) __eval0$(__eval0$(__eval0$(__VA_ARGS__)))
#define __eval2$(...) __eval1$(__eval1$(__eval1$(__VA_ARGS__)))
#define __eval3$(...) __eval2$(__eval2$(__eval2$(__VA_ARGS__)))
#define __eval4$(...) __eval3$(__eval3$(__eval3$(__VA_ARGS__)))
#define eval$(...) __eval4$(__eval4$(__eval4$(__VA_ARGS__)))

// Map

#define __MAP_END__(...)
#define __MAP_OUT__
#define __MAP_COMMA__ ,

#define __mapGetEnd2() 0, __MAP_END__
#define __mapGetEnd1(...) __mapGetEnd2
#define __mapGetEnd(...) __mapGetEnd1

#define __mapNext0(test, next, ...) next __MAP_OUT__
#define __mapNext1(test, next) __mapNext0(test, next, 0)
#define __mapNext(test, next) __mapNext1(__mapGetEnd test, next)

#define __map0(f, x, peek, ...) f(x) __mapNext(peek, __map1)(f, peek, __VA_ARGS__)
#define __map1(f, x, peek, ...) f(x) __mapNext(peek, __map0)(f, peek, __VA_ARGS__)

#define __mapListNext1(test, next) __mapNext0(test, __MAP_COMMA__ next, 0)
#define __mapListNext(test, next) __mapListNext1(__mapGetEnd test, next)

#define __mapList0(f, x, peek, ...) f(x) __mapListNext(peek, __mapList1)(f, peek, __VA_ARGS__)
#define __mapList1(f, x, peek, ...) f(x) __mapListNext(peek, __mapList0)(f, peek, __VA_ARGS__)

// Applies the function macro `f` to each of the remaining parameters.
#define map$(f, ...) eval$(__map1(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))

// Applies the function macro `f` to each of the remaining parameters and
// inserts commas between the results.
#define mapList$(f, ...) eval$(__mapList1(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0))

// Constructs

#define always_inline [[gnu::always_inline]]

// MARK: Unsigned --------------------------------------------------------------
Expand Down
7 changes: 0 additions & 7 deletions src/libs/karm-base/defer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@

namespace Karm {

#define defer$(expr) \
auto _ = Defer { \
[&] { \
expr; \
} \
}

/// Defer a computation until the end of the current scope.
/// The computation is executed in the reverse order of the defer calls.
template <typename F>
Expand Down
5 changes: 0 additions & 5 deletions src/libs/karm-base/panic.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,4 @@ inline void breakpoint() {
#endif
}

#define assume$(__expr, ...) \
if (not(__expr)) [[unlikely]] { \
panic(__FILE__ "::" stringify$(__func__) ":" stringify$(__LINE__) ": bad assumption: " #__expr __VA_OPT__(": ") __VA_ARGS__); \
}

} // namespace Karm
6 changes: 4 additions & 2 deletions src/libs/karm-text/run.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,14 @@ struct Run {
}

Slice<Cell> cells() const {
assume$(_shaped, "run not shaped");
if (not _shaped)
panic("run not shaped");
return _cells;
}

Math::Vec2f size() const {
assume$(_shaped, "run not shaped");
if (not _shaped)
panic("run not shaped");
return _size;
}

Expand Down
3 changes: 2 additions & 1 deletion src/web/vaev-base/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,8 @@ struct FontSize {
}

PercentOr<Length> value() const {
assume$(_named == LENGTH, "not a length");
if (_named != LENGTH)
panic("not a length");
return _value;
}

Expand Down

0 comments on commit 4016eed

Please sign in to comment.