summaryrefslogtreecommitdiffhomepage
path: root/CompilerKit/StdKit/ErrorOr.hpp
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-04 21:36:54 +0100
committerAmlal El Mahrouss <amlal.elmahrouss@icloud.com>2024-01-04 21:48:09 +0100
commit6cda526bd4efcee31b1ea7405dc46d7985ba64e6 (patch)
treef7d138fd5652cdc0e7a2c4918b36d754969d6cf5 /CompilerKit/StdKit/ErrorOr.hpp
parent60271b79a91a06772241aed737426f5d097ca533 (diff)
masm: fix assembler bug where addr1, 0x0 (add r1, 0x0) doesn't error
out. cc/ccplus: minor compiler changes, will get to them very soon... refactor: rename C++Kit to CompilerKit. Signed-off-by: Amlal El Mahrouss <amlal.elmahrouss@icloud.com>
Diffstat (limited to 'CompilerKit/StdKit/ErrorOr.hpp')
-rw-r--r--CompilerKit/StdKit/ErrorOr.hpp58
1 files changed, 58 insertions, 0 deletions
diff --git a/CompilerKit/StdKit/ErrorOr.hpp b/CompilerKit/StdKit/ErrorOr.hpp
new file mode 100644
index 0000000..c2457df
--- /dev/null
+++ b/CompilerKit/StdKit/ErrorOr.hpp
@@ -0,0 +1,58 @@
+/*
+ * ========================================================
+ *
+ * CompilerKit
+ * Copyright Western Company, all rights reserved.
+ *
+ * ========================================================
+ */
+
+#pragma once
+
+#include <CompilerKit/Defines.hpp>
+#include <CompilerKit/StdKit/Ref.hpp>
+
+namespace CompilerKit
+{
+using ErrorT = UInt32;
+
+template <typename T>
+class ErrorOr final
+{
+ public:
+ ErrorOr() = default;
+ ~ErrorOr() = default;
+
+ public:
+ explicit ErrorOr(Int32 err)
+ : mId(err)
+ {}
+
+ explicit ErrorOr(nullPtr Null)
+ {}
+
+ explicit ErrorOr(T Class)
+ : mRef(Class)
+ {}
+
+ ErrorOr &operator=(const ErrorOr &) = default;
+ ErrorOr(const ErrorOr &) = default;
+
+ Ref<T> Leak()
+ {
+ return mRef;
+ }
+
+ operator bool()
+ {
+ return mRef;
+ }
+
+ private:
+ Ref<T> mRef;
+ Int32 mId{0};
+};
+
+using ErrorOrAny = ErrorOr<voidPtr>;
+
+} // namespace CompilerKit