diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-15 11:22:55 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-15 11:25:36 +0100 |
| commit | 6b4d761818b79a6fc17607e15d939154b4d8314f (patch) | |
| tree | 0a6188f201afebc4b5a22bae9f0744d7be7495f1 /src/kernel | |
| parent | cceb0a70efef009b87198796eb9016ffb82c7130 (diff) | |
feat: New Nullable system, and improved Vettable system.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src/kernel')
| -rw-r--r-- | src/kernel/NeKit/Config.h | 7 | ||||
| -rw-r--r-- | src/kernel/NeKit/ErrorOr.h | 9 | ||||
| -rw-r--r-- | src/kernel/NeKit/Nullable.h | 26 | ||||
| -rw-r--r-- | src/kernel/NeKit/Ref.h | 18 | ||||
| -rw-r--r-- | src/kernel/NeKit/Vettable.h | 13 |
5 files changed, 58 insertions, 15 deletions
diff --git a/src/kernel/NeKit/Config.h b/src/kernel/NeKit/Config.h index 39f40401..900ea28c 100644 --- a/src/kernel/NeKit/Config.h +++ b/src/kernel/NeKit/Config.h @@ -189,7 +189,12 @@ class ISchedulable { }; template <class Type> -struct FalseResult final {}; +struct FalseResult final { + using ResultType = Type; + using ResultTypeRef = ResultType&; + + static constexpr bool kValue = false; +}; template <class Type> struct TrueResult final { diff --git a/src/kernel/NeKit/ErrorOr.h b/src/kernel/NeKit/ErrorOr.h index 4e43cb27..5fa8054b 100644 --- a/src/kernel/NeKit/ErrorOr.h +++ b/src/kernel/NeKit/ErrorOr.h @@ -25,10 +25,15 @@ class ErrorOr final { public: using RefType = Ref<T>; using Type = T; + using TypePtr = T*; + + explicit ErrorOr(ErrorT err) : mRef((T*) RTL_ALLOCA(sizeof(T))), mId(err) { + // AMLALE: Invalidate the value of mRef to make computational evaluations false. + mRef = nullptr; + } - explicit ErrorOr(ErrorT err) : mRef((T*) RTL_ALLOCA(sizeof(T))), mId(err) {} explicit ErrorOr(nullPtr) {} - explicit ErrorOr(Type* klass) : mRef(klass) {} + explicit ErrorOr(TypePtr klass) : mRef(klass) {} explicit ErrorOr(Type klass) : mRef(klass) {} ErrorOr& operator=(const ErrorOr&) = default; diff --git a/src/kernel/NeKit/Nullable.h b/src/kernel/NeKit/Nullable.h new file mode 100644 index 00000000..c17009fc --- /dev/null +++ b/src/kernel/NeKit/Nullable.h @@ -0,0 +1,26 @@ +#ifndef __NE_KIT_NULLABLE_H__ +#define __NE_KIT_NULLABLE_H__ + +#include <NeKit/Config.h> + +namespace Kernel { +template <class Type> +struct IsDefined final { + using ResultType = Type; + using ResultTypeRef = Type&; + + static constexpr bool kValue = true; +}; + +template <> +struct IsDefined<nullPtr> final { + static constexpr bool kValue = false; +}; + +template <class Type> +concept IsAcceptable = requires() { + { IsDefined<Type>::kValue }; +}; +} // namespace Kernel + +#endif // !__NE_KIT_NULLABLE_H__
\ No newline at end of file diff --git a/src/kernel/NeKit/Ref.h b/src/kernel/NeKit/Ref.h index 25706437..62460568 100644 --- a/src/kernel/NeKit/Ref.h +++ b/src/kernel/NeKit/Ref.h @@ -12,6 +12,7 @@ #include <KernelKit/HeapMgr.h> #include <NeKit/Config.h> #include <NeKit/KernelPanic.h> +#include <NeKit/Nullable.h> #include <NeKit/Vettable.h> namespace Kernel { @@ -30,6 +31,13 @@ class Ref final { Ref(Type* cls) : fClass(*cls) {} Ref(Type cls) : fClass(cls) {} + Ref& operator=(nullPtr) { return *this; } + + Ref& operator=(Type* ref) { + fClass = *ref; + return *this; + } + Ref& operator=(Type ref) { fClass = ref; return *this; @@ -59,11 +67,13 @@ class NonNullRef final { using RefType = Ref<T>; using Type = T; - NonNullRef() = delete; - NonNullRef(nullPtr) = delete; + NonNullRef() = delete; + + NonNullRef(Type* ref) : fRef(ref) {} + + NonNullRef(nullPtr ref) = delete; - NonNullRef(Type* ref) : fRef(ref) { MUST_PASS(ref); } - NonNullRef(RefType ref) : fRef(ref) { MUST_PASS(ref); } + NonNullRef(RefType ref) : fRef(ref) {} Ref<T>& operator->() { MUST_PASS(fRef); diff --git a/src/kernel/NeKit/Vettable.h b/src/kernel/NeKit/Vettable.h index 04d51b1d..c8c27fe3 100644 --- a/src/kernel/NeKit/Vettable.h +++ b/src/kernel/NeKit/Vettable.h @@ -40,15 +40,12 @@ struct Vettable<IVettable> final { static constexpr bool kValue = true; }; -/// @brief Concept version of Vettable. -template <typename Type, typename OnFallback> -concept IsVettable = requires(OnFallback fallback) { - { Vettable<Type>::kValue ? TrueResult<Type>::kValue : fallback() }; -}; +using FallbackType = bool (*)(bool); -template <class Type, typename OnFallback> -concept IsNotVettable = requires(OnFallback fallback) { - { !Vettable<Type>::kValue ? TrueResult<Type>::kValue : fallback() }; +/// @brief Concept version of Vettable. +template <typename Type, FallbackType OnFallback> +concept IsVettable = requires() { + { Vettable<Type>::kValue ? TrueResult<Type>::kValue : OnFallback(FalseResult<Type>::kValue) }; }; } // namespace Kernel |
