-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
everywhere: Isolated all macros into separeted files.
- Loading branch information
1 parent
4016eed
commit c721aee
Showing
10 changed files
with
128 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#pragma once | ||
|
||
#define wasm_import(name) __attribute__((import_module("env"), import_name(#name))) name | ||
#define wasm_export(name) __attribute__((visibility("default"), export_name(#name))) name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#pragma once | ||
|
||
namespace Karm { | ||
|
||
#define lifetimebound [[clang::lifetimebound]] | ||
#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 always_inline [[gnu::always_inline]] | ||
|
||
// MARK: Enum ------------------------------------------------------------------ | ||
|
||
#define FlagsEnum$(T) \ | ||
inline T operator~(T a) { \ | ||
using U = ::Karm::Meta::UnderlyingType<T>; \ | ||
return (T) ~(U)a; \ | ||
} \ | ||
inline T operator|(T a, T b) { \ | ||
using U = ::Karm::Meta::UnderlyingType<T>; \ | ||
return (T)((U)a | (U)b); \ | ||
} \ | ||
inline T operator&(T a, T b) { \ | ||
using U = ::Karm::Meta::UnderlyingType<T>; \ | ||
return (T)((U)a & (U)b); \ | ||
} \ | ||
inline T operator^(T a, T b) { \ | ||
using U = ::Karm::Meta::UnderlyingType<T>; \ | ||
return (T)((U)a ^ (U)b); \ | ||
} \ | ||
inline bool operator!(T a) { \ | ||
using U = ::Karm::Meta::UnderlyingType<T>; \ | ||
return not(U) a; \ | ||
} \ | ||
inline T &operator|=(T &a, T b) { \ | ||
using U = ::Karm::Meta::UnderlyingType<T>; \ | ||
return (T &)((U &)a |= (U)b); \ | ||
} \ | ||
inline T &operator&=(T &a, T b) { \ | ||
using U = ::Karm::Meta::UnderlyingType<T>; \ | ||
return (T &)((U &)a &= (U)b); \ | ||
} \ | ||
inline T &operator^=(T &a, T b) { \ | ||
using U = ::Karm::Meta::UnderlyingType<T>; \ | ||
return (T &)((U &)a ^= (U)b); \ | ||
} | ||
|
||
// MARK: Try ------------------------------------------------------------------- | ||
|
||
// Give us a symbole to break one when debbuging error handling. | ||
// This is a no-op in release mode. | ||
#if defined(__ck_debug__) and !defined(KARM_DISABLE_TRY_FAIL_HOOK) | ||
extern "C" void __try_failed(); | ||
# define __tryFail() __try_failed() | ||
#else | ||
# define __tryFail() /* NOP */ | ||
#endif | ||
|
||
#define __try$(EXPR, RET, AWAIT) ({ \ | ||
auto __expr = AWAIT(EXPR); \ | ||
if (not static_cast<bool>(__expr)) [[unlikely]] { \ | ||
__tryFail(); \ | ||
RET __expr.none(); \ | ||
} \ | ||
__expr.take(); \ | ||
}) | ||
|
||
#define try$(EXPR) __try$(EXPR, return, ) | ||
|
||
#define co_try$(EXPR) __try$(EXPR, co_return, ) | ||
|
||
#define co_trya$(EXPR) __try$(EXPR, co_return, co_await) | ||
|
||
} // namespace Karm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
namespace Karm::Ui { | ||
|
||
#define slot$(EXPR) \ | ||
Karm::Ui::Slot { \ | ||
[=] { \ | ||
return EXPR; \ | ||
} \ | ||
} | ||
|
||
#define slots$(...) \ | ||
Karm::Ui::Slots { \ | ||
[=] -> Ui::Children { \ | ||
return {__VA_ARGS__}; \ | ||
} \ | ||
} | ||
|
||
} // namespace Karm::Ui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
namespace Handover { | ||
|
||
// clang-format off | ||
|
||
#define HandoverSection$() \ | ||
[[gnu::used, gnu::section(".handover")]] | ||
|
||
#define HandoverRequests$(...) \ | ||
HandoverSection$() \ | ||
static ::Handover::Request const __handover__[] = { \ | ||
{::Handover::Tag::MAGIC, 0, 0}, \ | ||
__VA_ARGS__ __VA_OPT__(, ) \ | ||
{::Handover::Tag::END, 0, 0}, \ | ||
}; | ||
|
||
// clang-format on | ||
|
||
} // namespace Handover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters