From 0da80081f39ad23fc070641fc581063a1e555670 Mon Sep 17 00:00:00 2001
From: Gary Talent <gtalent2@gmail.com>
Date: Sat, 26 May 2018 10:08:11 -0500
Subject: [PATCH] [ox/std] Add optional file/line information to ox::Error

---
 deps/ox/src/ox/std/bitops.hpp | 11 +++++++++--
 deps/ox/src/ox/std/random.hpp |  6 ++----
 deps/ox/src/ox/std/types.hpp  | 36 ++++++++++++++++++++++++++++++++++-
 3 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/deps/ox/src/ox/std/bitops.hpp b/deps/ox/src/ox/std/bitops.hpp
index 61607d75..febc9cb0 100644
--- a/deps/ox/src/ox/std/bitops.hpp
+++ b/deps/ox/src/ox/std/bitops.hpp
@@ -8,8 +8,6 @@
 
 #pragma once
 
-#include "types.hpp"
-
 namespace ox {
 
 template<typename T>
@@ -18,4 +16,13 @@ inline constexpr T rotateLeft(T i, int shift) {
 	return (i << shift) | (i >> (bits - shift));
 }
 
+template<typename T>
+constexpr T onMask(int bits) {
+	T out = 0;
+	for (auto i = 0; i < bits; i++) {
+		out |= 1 << i;
+	}
+	return out;
+}
+
 }
diff --git a/deps/ox/src/ox/std/random.hpp b/deps/ox/src/ox/std/random.hpp
index a6be6b02..ce089d1c 100644
--- a/deps/ox/src/ox/std/random.hpp
+++ b/deps/ox/src/ox/std/random.hpp
@@ -8,15 +8,13 @@
 
 #pragma once
 
-uint64_t ox_rand();
+#include "types.hpp"
 
 namespace ox {
 
-typedef uint64_t RandomSeed[2];
+using RandomSeed = uint64_t[2];
 
 class Random {
-	public:
-
 	private:
 		RandomSeed m_seed;
 
diff --git a/deps/ox/src/ox/std/types.hpp b/deps/ox/src/ox/std/types.hpp
index 0bff8d03..20b96063 100644
--- a/deps/ox/src/ox/std/types.hpp
+++ b/deps/ox/src/ox/std/types.hpp
@@ -8,6 +8,8 @@
 
 #pragma once
 
+#include "bitops.hpp"
+
 #if OX_USE_STDLIB
 
 #include <cstdint>
@@ -52,7 +54,39 @@ typedef uint32_t uintptr_t;
 
 namespace ox {
 
-using Error = uint32_t;
+using Error = uint64_t;
+
+struct ErrorInfo {
+	const char *file = nullptr;
+	int line = -1;
+	Error errCode = 0;
+
+	ErrorInfo() = default;
+
+	ErrorInfo(Error err) {
+		this->file = reinterpret_cast<const char*>(err & onMask<Error>(48));
+		this->line = static_cast<int>((err >> 48) & onMask<Error>(5));
+		this->errCode = (err >> 59) & onMask<Error>(11);
+	}
+};
+
+constexpr Error ErrorTags(Error line, Error errCode) {
+	line &= onMask<Error>(5);
+	line <<= 48;
+	errCode &= onMask<Error>(11);
+	errCode <<= 59;
+	return errCode | line;
+}
+
+}
+
+#ifdef DEBUG
+#define OxError(x) reinterpret_cast<uint64_t>(__FILE__) | ErrorTags(__LINE__, x)
+#else
+#define OxError(x) x
+#endif
+
+namespace ox {
 
 template<typename T>
 struct ValErr {