Apply formating to all files. CLeanup

This commit is contained in:
IlyaShurupov 2023-10-22 17:07:28 +03:00 committed by Ilya Shurupov
parent b4ae5dde77
commit 91fb72bd49
928 changed files with 14515 additions and 21479 deletions

View file

@ -1,26 +1,22 @@
#include "Assert.hpp"
#include <cstdio>
#include <cstdlib>
using namespace tp;
void tp::_assert_(const char* exp, const char* file, int line) {
if (!exp) {
exp = "no info";
}
printf("\nERROR: Assertion Failure - %s -- %s:%i\n", exp, file, line);
#ifdef ENV_BUILD_DEBUG
DEBUG_BREAK(true);
#else
exit(1);
#endif
}
void tp::terminate(tp::alni code) {
exit((int)code);
}
#include "Assert.hpp"
#include <cstdio>
#include <cstdlib>
using namespace tp;
void tp::_assert_(const char* exp, const char* file, int line) {
if (!exp) {
exp = "no info";
}
printf("\nERROR: Assertion Failure - %s -- %s:%i\n", exp, file, line);
#ifdef ENV_BUILD_DEBUG
DEBUG_BREAK(true);
#else
exit(1);
#endif
}
void tp::terminate(tp::alni code) { exit((int) code); }

View file

@ -39,7 +39,7 @@ namespace tp {
}
ualni hash(alni bytes) { return abs(bytes); }
ualni hash(alnf bytes) { return (alni)(abs(bytes)); }
ualni hash(alnf bytes) { return (alni) (abs(bytes)); }
ualni hash(halni bytes) { return hash(alni(bytes)); }
ualni hash(uhalni bytes) { return hash(alni(bytes)); }
ualni hash(ualni bytes) { return hash(alni(bytes)); }

View file

@ -9,13 +9,12 @@ const char* ToolchainString[] = { "UNDEF", "GNU", "LLVM", "MSVC" };
const char* OSString[] = { "UNDEF", "LINUX", "WINDOWS", "ANDROID", "IOS" };
const char* ArchWidthString[] = { "UNDEF", "X64", "X32" };
const tp::Environment tp::gEnvironment;
void tp::Environment::log() const {
std::cout << "ARCH : " << ArchString[(int)mArch] << "\n";
std::cout << "WIDTH : " << ArchWidthString[(int)mWidth] << "\n";
std::cout << "CURRENT OS : " << OSString[(int)mOS] << "\n";
std::cout << "TOOLCHAIN : " << ToolchainString[(int)mToolchain] << "\n";
std::cout << "BUILD TYPE : " << BuildTypeString[(int)mBuildType] << "\n";
std::cout << "ARCH : " << ArchString[(int) mArch] << "\n";
std::cout << "WIDTH : " << ArchWidthString[(int) mWidth] << "\n";
std::cout << "CURRENT OS : " << OSString[(int) mOS] << "\n";
std::cout << "TOOLCHAIN : " << ToolchainString[(int) mToolchain] << "\n";
std::cout << "BUILD TYPE : " << BuildTypeString[(int) mBuildType] << "\n";
}

View file

@ -1,85 +1,81 @@
#include "Module.hpp"
#include <iostream>
using namespace tp;
static bool init(const ModuleManifest* self) {
gEnvironment.log();
return true;
}
static ModuleManifest* deps[] = { nullptr };
ModuleManifest tp::gModuleBase = ModuleManifest("Common", init, nullptr, deps);
ModuleManifest::ModuleManifest(const char* aModuleName, ModuleInit aInit, ModuleDeinit aDeinit, ModuleManifest** aDependencies) {
mInit = aInit;
mDeinit = aDeinit;
mDependencies = aDependencies;
mModuleName = aModuleName;
}
bool ModuleManifest::isInitialized() const {
return mInitialized;
}
bool ModuleManifest::initialize(const ModuleManifest* parent) {
if (!parent) std::cout << "===== Initialization Start =====\n";
mInitCount++;
if (isInitialized()) {
return true;
}
mInitialized = true;
for (auto module = mDependencies; module && *module; module++) {
mInitialized &= (*module)->initialize(this);
}
std::cout << " * Initializing \"" << mModuleName << "\" from \"" << (parent ? parent->mModuleName : mModuleName ) << "\"\n";
if (mInit) mInitialized &= mInit(this);
if (!mInitialized) {
std::cout << "Failed to Initialize.\n";
}
if (!parent) std::cout << "===== Initialization End =====\n\n";
return mInitialized;
}
void ModuleManifest::deinitialize() {
mInitCount--;
if (mInitCount > 0) {
return;
}
if (!isInitialized()) {
return;
}
if (mDeinit) mDeinit(this);
mInitialized = false;
auto len = 0;
for (auto module = mDependencies; module && *module; module++) {
len++;
}
for (auto i = 0; i < len; i++) {
auto module = mDependencies + (len - i - 1);
if ((*module)->isInitialized()) {
(*module)->deinitialize();
}
}
}
const char *ModuleManifest::getName() const {
return mModuleName;
}
#include "Module.hpp"
#include <iostream>
using namespace tp;
static bool init(const ModuleManifest* self) {
gEnvironment.log();
return true;
}
static ModuleManifest* deps[] = { nullptr };
ModuleManifest tp::gModuleBase = ModuleManifest("Common", init, nullptr, deps);
ModuleManifest::ModuleManifest(const char* aModuleName, ModuleInit aInit, ModuleDeinit aDeinit, ModuleManifest** aDependencies) {
mInit = aInit;
mDeinit = aDeinit;
mDependencies = aDependencies;
mModuleName = aModuleName;
}
bool ModuleManifest::isInitialized() const { return mInitialized; }
bool ModuleManifest::initialize(const ModuleManifest* parent) {
if (!parent) std::cout << "===== Initialization Start =====\n";
mInitCount++;
if (isInitialized()) {
return true;
}
mInitialized = true;
for (auto module = mDependencies; module && *module; module++) {
mInitialized &= (*module)->initialize(this);
}
std::cout << " * Initializing \"" << mModuleName << "\" from \"" << (parent ? parent->mModuleName : mModuleName) << "\"\n";
if (mInit) mInitialized &= mInit(this);
if (!mInitialized) {
std::cout << "Failed to Initialize.\n";
}
if (!parent) std::cout << "===== Initialization End =====\n\n";
return mInitialized;
}
void ModuleManifest::deinitialize() {
mInitCount--;
if (mInitCount > 0) {
return;
}
if (!isInitialized()) {
return;
}
if (mDeinit) mDeinit(this);
mInitialized = false;
auto len = 0;
for (auto module = mDependencies; module && *module; module++) {
len++;
}
for (auto i = 0; i < len; i++) {
auto module = mDependencies + (len - i - 1);
if ((*module)->isInitialized()) {
(*module)->deinitialize();
}
}
}
const char* ModuleManifest::getName() const { return mModuleName; }

View file

@ -12,14 +12,20 @@ namespace tp {
public:
struct HasFunc {
typedef ArchiverTemplate& ArchRef;
template <typename T, typename = void> struct Write : FalseType {};
template <typename T> struct Write<T, VoidType<decltype(DeclareValue<T>()().archiveWrite(DeclareValue<ArchRef>()()))>> : TrueType {};
template <typename T, typename = void>
struct Write : FalseType {};
template <typename T>
struct Write<T, VoidType<decltype(DeclareValue<T>()().archiveWrite(DeclareValue<ArchRef>()()))>> : TrueType {};
template <typename T, typename = void> struct Read : FalseType {};
template <typename T> struct Read<T, VoidType<decltype(DeclareValue<T>()().archiveRead(DeclareValue<ArchRef>()()))>> : TrueType {};
template <typename T, typename = void>
struct Read : FalseType {};
template <typename T>
struct Read<T, VoidType<decltype(DeclareValue<T>()().archiveRead(DeclareValue<ArchRef>()()))>> : TrueType {};
template <typename T, typename = void> struct Archive : FalseType {};
template <typename T> struct Archive<T, VoidType<decltype(DeclareValue<T>()().archive(DeclareValue<ArchRef>()()))>> : TrueType {};
template <typename T, typename = void>
struct Archive : FalseType {};
template <typename T>
struct Archive<T, VoidType<decltype(DeclareValue<T>()().archive(DeclareValue<ArchRef>()()))>> : TrueType {};
template <typename T>
struct AssertCombinations {
@ -35,14 +41,14 @@ namespace tp {
public:
virtual void writeBytes(const int1* val, ualni size) = 0;
virtual void readBytes(int1* val, ualni size) = 0;
virtual void readBytes(int1* val, ualni size) = 0;
public:
ArchiverTemplate() = default;
// check if type has explicit write method. if not write as bytes
template<typename Type>
void operator <<(const Type& val) {
template <typename Type>
void operator<<(const Type& val) {
static_assert(!tRead);
static_assert(HasFunc::template AssertCombinations<Type>::assert());
if constexpr (HasFunc::template Write<Type>::value) {
@ -53,8 +59,8 @@ namespace tp {
}
// check if type has explicit read method. if not read as bytes
template<typename Type>
void operator >>(Type& val) {
template <typename Type>
void operator>>(Type& val) {
static_assert(tRead);
static_assert(HasFunc::template AssertCombinations<Type>::assert());
if constexpr (HasFunc::template Read<Type>::value) {
@ -65,8 +71,8 @@ namespace tp {
}
// check if type has explicit archive method. if not read/write as bytes
template<typename Type>
void operator %(Type& val) {
template <typename Type>
void operator%(Type& val) {
static_assert(HasFunc::template AssertCombinations<Type>::assert());
if constexpr (HasFunc::template Archive<Type>::value) {
val.archive(*this);
@ -79,11 +85,11 @@ namespace tp {
}
}
template<typename Type>
void operator %(const Type& val) {
template <typename Type>
void operator%(const Type& val) {
static_assert(HasFunc::template AssertCombinations<Type>::assert());
if constexpr (HasFunc::template Archive<Type>::value) {
((Type&)val).archive(*this);
((Type&) val).archive(*this);
} else {
if constexpr (tRead) {
operator>>(val);
@ -94,7 +100,7 @@ namespace tp {
}
};
template<ualni tMaxMemory, bool tRead>
template <ualni tMaxMemory, bool tRead>
class ArchiverExample : public ArchiverTemplate<tRead> {
public:
ArchiverExample() = default;
@ -106,12 +112,14 @@ namespace tp {
}
void writeBytes(const int1* val, ualni size) override {
for (auto i = 0; i < size; i++) mBuff[mAddress + i] = val[i];
for (auto i = 0; i < size; i++)
mBuff[mAddress + i] = val[i];
incrementAddresses(size);
}
void readBytes(int1* val, ualni size) override {
for (auto i = 0; i < size; i++) val[i] = mBuff[mAddress + i];
for (auto i = 0; i < size; i++)
val[i] = mBuff[mAddress + i];
incrementAddresses(size);
}

View file

@ -1,32 +1,48 @@
#pragma once
#include "Environment.hpp"
namespace tp {
void _assert_(const char* exp, const char* file, int line);
void terminate(tp::alni code = 0);
};
#define FAIL(exp) tp::_assert_(#exp, __FILE__, __LINE__);
#define ASSERT(exp) if (!(exp)) { FAIL(exp) }
#undef assert
#ifdef ENV_BUILD_DEBUG
#define DEBUG_ASSERT(exp) ASSERT(exp)
#else
#define DEBUG_ASSERT(exp) {}
#endif
#if defined(ENV_OS_WINDOWS)
#define DEBUG_BREAK(expr) if (expr) { __debugbreak(); }
#elif defined(ENV_OS_ANDROID)
#define DEBUG_BREAK(expr) if (expr) { __builtin_debugtrap(); }
#elif defined(ENV_OS_LINUX)
#define DEBUG_BREAK(expr) if (expr) { __builtin_trap(); }
#else
#define DEBUG_BREAK(expr) ()
#endif
#define SWITCH_NO_DEF default : { FAIL("No Default Case Possible"); }
#pragma once
#include "Environment.hpp"
namespace tp {
void _assert_(const char* exp, const char* file, int line);
void terminate(tp::alni code = 0);
};
#define FAIL(exp) tp::_assert_(#exp, __FILE__, __LINE__);
#define ASSERT(exp) \
if (!(exp)) { \
FAIL(exp) \
}
#undef assert
#ifdef ENV_BUILD_DEBUG
#define DEBUG_ASSERT(exp) ASSERT(exp)
#else
#define DEBUG_ASSERT(exp) \
{}
#endif
#if defined(ENV_OS_WINDOWS)
#define DEBUG_BREAK(expr) \
if (expr) { \
__debugbreak(); \
}
#elif defined(ENV_OS_ANDROID)
#define DEBUG_BREAK(expr) \
if (expr) { \
__builtin_debugtrap(); \
}
#elif defined(ENV_OS_LINUX)
#define DEBUG_BREAK(expr) \
if (expr) { \
__builtin_trap(); \
}
#else
#define DEBUG_BREAK(expr) ()
#endif
#define SWITCH_NO_DEF \
default: \
{ \
FAIL("No Default Case Possible"); \
}

View file

@ -8,7 +8,7 @@
#include <utility>
namespace tp {
template<typename Type>
template <typename Type>
using InitialierList = std::initializer_list<Type>;
// Selects whether to pass by constant reference or by value
@ -25,15 +25,15 @@ namespace tp {
template <typename tType>
struct DeclareValue {
tType operator()() {}
tType operator()() {}
};
struct TrueType {
static constexpr auto value = true;
static constexpr auto value = true;
};
struct FalseType {
static constexpr auto value = false;
static constexpr auto value = false;
};
}
@ -50,35 +50,64 @@ namespace tp {
ualni hash(alnf bytes);
template <typename T>
[[nodiscard]] T clamp(T v, T l, T u) { if (v < l) { v = l; } else if (v > u) { v = u; } return v; }
[[nodiscard]] T clamp(T v, T l, T u) {
if (v < l) {
v = l;
} else if (v > u) {
v = u;
}
return v;
}
template <typename T>
[[nodiscard]] T max(T a, T b) { return (a > b) ? a : b; }
[[nodiscard]] T max(T a, T b) {
return (a > b) ? a : b;
}
template <typename T>
[[nodiscard]] T min(T a, T b) { return (a < b) ? a : b; }
[[nodiscard]] T min(T a, T b) {
return (a < b) ? a : b;
}
template <typename T>
[[nodiscard]] T abs(T v) { if (v < 0) { return -v; } return v; }
[[nodiscard]] T abs(T v) {
if (v < 0) {
return -v;
}
return v;
}
template <typename T>
inline void swap(T& t1, T& t2) { const T tmp = t1; t1 = t2; t2 = tmp; }
inline void swap(T& t1, T& t2) {
const T tmp = t1;
t1 = t2;
t2 = tmp;
}
// only for x > 0 and y > 0
template <typename T>
[[nodiscard]] T ceil_positive(T x, T y) { return T( 1 + ((x - 1) / (tp::alnf)y) ); }
[[nodiscard]] T ceil_positive(T x, T y) {
return T(1 + ((x - 1) / (tp::alnf) y));
}
// power
template <typename T>
[[nodiscard]] T pow(T x, uhalni n) {
T out = x; for (uhalni i = 0; i < n - 1; i++) { out = out * x; }
T out = x;
for (uhalni i = 0; i < n - 1; i++) {
out = out * x;
}
return out;
}
template<typename Type>
template <typename Type>
halni nDig10(Type val) {
val = abs(val); halni out = 0;
while (val != 0) { val = halni(val / 10); out++; }
val = abs(val);
halni out = 0;
while (val != 0) {
val = halni(val / 10);
out++;
}
return out;
}
}

View file

@ -1,198 +1,197 @@
#pragma once
#include <climits>
#include <cfloat>
namespace tp {
class Environment {
public:
enum class Arch { UNDEF, INTEL, ARM } mArch = Arch::UNDEF;
// Build Type
#if defined(__DEBUG__) || defined(_DEBUG) || defined(DEBUG) || !defined(NDEBUG)
#define ENV_BUILD_DEBUG
enum class BuildType { UNDEF, DEBUG, RELEASE } mBuildType = BuildType::DEBUG;
#else
#define ENV_BUILD_RELEASE
enum class BuildType { UNDEF, DEBUG, RELEASE } mBuildType = BuildType::RELEASE;
#endif
// MCVS
#ifdef _MSC_VER
#define ENV_COMPILER_MSVC
enum class Toolchain { UNDEF, GNU, LLVM, MSVC } mToolchain = Toolchain::MSVC;
// VERSION
// TODO
// TARGET OS
#if defined(_WIN32) || defined(_WIN64)
#define ENV_OS_WINDOWS
enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::WINDOWS;
#else
enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::UNDEF;
#error "unexplored compilation to os target"
#endif
// TARGET ALIGNED SIZE
#ifdef _WIN64
enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X64;
#define ENV_BITS_64
#else
enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X32;
#define ENV_BITS_32
#endif
#endif
// GCC
#if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER)
#define ENV_COMPILER_GCC
enum class Toolchain { UNDEF, GNU, LLVM, MSVC } mToolchain = Toolchain::GNU;
// VERSION
#if (__GNUC___ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1))
// TODO
#endif
// TARGET OS
#if defined(__linux__) && !defined(__ANDROID__)
#define ENV_OS_LINUX
enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::LINUX;
#else
#error "unexplored compilation to os target"
#endif
// TARGET ALIGNED SIZE
#if defined(__aarch64__) || defined(__x86_64__) || defined(__ARM_64BIT_STATE)
#define ENV_BITS_64
enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X64;
#elif defined(__x86_64__) || defined(i386)
#define ENV_BITS_32
enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X32;
#endif
#endif
// CLANG
#if defined(__clang__) && !defined(ENV_COMPILER_GCC)
#define ENV_COMPILER_CLANG
enum class Toolchain { UNDEF, GNU, LLVM, MSVC } mToolchain = Toolchain::LLVM;
// VERSION
#if (__clang_major__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1))
// TODO
#endif
// TARGET OS
#if defined(__linux__) && !defined(__ANDROID__)
#define ENV_OS_LINUX
enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::LINUX;
#elif defined(__ANDROID__)
enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::ANDOID;
#define ENV_OS_ANDROID
#else
#error "unexplored compilation to target os"
#endif
// TARGET ALIGNED SIZE
#if defined(__aarch64__) || defined(__x86_64__) || defined(__ARM_64BIT_STATE)
#define ENV_BITS_64
enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X64;
#elif defined(__x86_64__) || defined(i386)
#define ENV_BITS_32
enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X32;
#endif
#endif
#if defined(__EMSCRIPTEN__) || defined(__MINGW32__) || defined(__MINGW32__) || defined(__MINGW64__)
#error "compiler is not supported"
#else
#if !(defined(ENV_COMPILER_MSVC) || defined(ENV_COMPILER_CLANG) || defined(ENV_COMPILER_GCC))
// Linux and Linux - derived __linux__
// Darwin(Mac OS X and iOS) __APPLE__
// Akaros __ros__
// NaCL __native_client__
// AsmJS __asmjs__
// Fuschia __Fuchsia__
#error "unknown compiler"
#endif
#endif
void log() const;
};
#ifndef ENV_BITS_64
#error "ERROR - not 64 bit archytectures are out of support"
#endif
const extern Environment gEnvironment;
typedef char int1;
typedef unsigned char uint1;
typedef short int2;
typedef unsigned short uint2;
typedef unsigned int uint4;
typedef uint2 ufalni;
typedef uint4 uhalni;
typedef int int4;
typedef int4 halni;
typedef unsigned long long uint8;
typedef uint8 ualni;
typedef long long int8;
typedef int8 alni;
typedef double flt8;
typedef flt8 alnf;
typedef float flt4;
typedef flt4 halnf;
#define ENV_INT1_MAX tp::int1( 0x7f)
#define ENV_INT1_MIN (-tp::int1(0x80))
#define ENV_UINT1_MAX tp::uint1(0xff)
#define ENV_UINT1_MIN tp::uint1(0x00)
#define ENV_INT2_MAX tp::int2( 0x7fff)
#define ENV_INT2_MIN (-tp::int2(0x8000))
#define ENV_UINT2_MAX tp::uint2(0xffff)
#define ENV_UINT2_MIN tp::uint2(0x0000)
#define ENV_UHALNI_MAX tp::uhalni(0xffffffff)
#define ENV_UHALNI_MIN tp::uhalni(0x00000000)
#define ENV_HALNI_MAX tp::halni( 0x7fffffff)
#define ENV_HALNI_MIN (-tp::halni(0x80000000))
#define ENV_UALNI_MAX tp::ualni(0xffffffffffffffff)
#define ENV_UALNI_MIN tp::ualni(0x0000000000000000)
#define ENV_ALNI_MAX tp::alni( 0x7fffffffffffffff)
#define ENV_ALNI_MIN (-tp::alni(0x8000000000000000))
#define ENV_ALNI_SIZE_B (8)
#define ENV_ALNF_DECIMAL_DIG DBL_DECIMAL_DIG
#define ENV_ALNF_DIG DBL_DIG
#define ENV_ALNF_EPSILON DBL_EPSILON
#define ENV_ALNF_HAS_SUBNORM DBL_HAS_SUBNORM
#define ENV_ALNF_MANT_DIG DBL_MANT_DIG
#define ENV_ALNF_MAX DBL_MAX
#define ENV_ALNF_MAX_10_EXP DBL_MAX_10_EXP
#define ENV_ALNF_MAX_EXP DBL_MAX_EXP
#define ENV_ALNF_MIN DBL_MIN
#define ENV_ALNF_MIN_10_EXP DBL_MIN_10_EXP
#define ENV_ALNF_MIN_EXP DBL_MIN_EXP
#define ENV_ALNF_RADIX _DBL_RADIX
#define ENV_ALNF_TRUE_MIN DBL_TRUE_MIN
#define ENV_HALNF_DECIMAL_DIG FLT_DECIMAL_DIG
#define ENV_HALNF_DIG FLT_DIG
#define ENV_HALNF_EPSILON FLT_EPSILON
#define ENV_HALNF_HAS_SUBNORM FLT_HAS_SUBNORM
#define ENV_HALNF_GUARD FLT_GUARD
#define ENV_HALNF_MANT_DIG FLT_MANT_DIG
#define ENV_HALNF_MAX FLT_MAX
#define ENV_HALNF_MAX_10_EXP FLT_MAX_10_EXP
#define ENV_HALNF_MAX_EXP FLT_MAX_EXP
#define ENV_HALNF_MIN FLT_MIN
#define ENV_HALNF_MIN_10_EXP FLT_MIN_10_EXP
#define ENV_HALNF_MIN_EXP FLT_MIN_EXP
#define ENV_HALNF_NORMALIZE FLT_NORMALIZE
#define ENV_HALNF_RADIX FLT_RADIX
#define ENV_HALNF_TRUE_MIN FLT_TRUE_MIN
#pragma once
#include <cfloat>
#include <climits>
namespace tp {
class Environment {
public:
enum class Arch { UNDEF, INTEL, ARM } mArch = Arch::UNDEF;
// Build Type
#if defined(__DEBUG__) || defined(_DEBUG) || defined(DEBUG) || !defined(NDEBUG)
#define ENV_BUILD_DEBUG
enum class BuildType { UNDEF, DEBUG, RELEASE } mBuildType = BuildType::DEBUG;
#else
#define ENV_BUILD_RELEASE
enum class BuildType { UNDEF, DEBUG, RELEASE } mBuildType = BuildType::RELEASE;
#endif
// MCVS
#ifdef _MSC_VER
#define ENV_COMPILER_MSVC
enum class Toolchain { UNDEF, GNU, LLVM, MSVC } mToolchain = Toolchain::MSVC;
// VERSION
// TODO
// TARGET OS
#if defined(_WIN32) || defined(_WIN64)
#define ENV_OS_WINDOWS
enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::WINDOWS;
#else
enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::UNDEF;
#error "unexplored compilation to os target"
#endif
// TARGET ALIGNED SIZE
#ifdef _WIN64
enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X64;
#define ENV_BITS_64
#else
enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X32;
#define ENV_BITS_32
#endif
#endif
// GCC
#if defined(__GNUC__) && !defined(__llvm__) && !defined(__INTEL_COMPILER)
#define ENV_COMPILER_GCC
enum class Toolchain { UNDEF, GNU, LLVM, MSVC } mToolchain = Toolchain::GNU;
// VERSION
#if (__GNUC___ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1))
// TODO
#endif
// TARGET OS
#if defined(__linux__) && !defined(__ANDROID__)
#define ENV_OS_LINUX
enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::LINUX;
#else
#error "unexplored compilation to os target"
#endif
// TARGET ALIGNED SIZE
#if defined(__aarch64__) || defined(__x86_64__) || defined(__ARM_64BIT_STATE)
#define ENV_BITS_64
enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X64;
#elif defined(__x86_64__) || defined(i386)
#define ENV_BITS_32
enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X32;
#endif
#endif
// CLANG
#if defined(__clang__) && !defined(ENV_COMPILER_GCC)
#define ENV_COMPILER_CLANG
enum class Toolchain { UNDEF, GNU, LLVM, MSVC } mToolchain = Toolchain::LLVM;
// VERSION
#if (__clang_major__ > 5 || (__GNUC__ == 5 && __GNUC_MINOR__ >= 1))
// TODO
#endif
// TARGET OS
#if defined(__linux__) && !defined(__ANDROID__)
#define ENV_OS_LINUX
enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::LINUX;
#elif defined(__ANDROID__)
enum class OS { UNDEF, LINUX, WINDOWS, ANDROID, IOS } mOS = OS::ANDOID;
#define ENV_OS_ANDROID
#else
#error "unexplored compilation to target os"
#endif
// TARGET ALIGNED SIZE
#if defined(__aarch64__) || defined(__x86_64__) || defined(__ARM_64BIT_STATE)
#define ENV_BITS_64
enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X64;
#elif defined(__x86_64__) || defined(i386)
#define ENV_BITS_32
enum class ArchWidth { UNDEF, X64, X32 } mWidth = ArchWidth::X32;
#endif
#endif
#if defined(__EMSCRIPTEN__) || defined(__MINGW32__) || defined(__MINGW32__) || defined(__MINGW64__)
#error "compiler is not supported"
#else
#if !(defined(ENV_COMPILER_MSVC) || defined(ENV_COMPILER_CLANG) || defined(ENV_COMPILER_GCC))
// Linux and Linux - derived __linux__
// Darwin(Mac OS X and iOS) __APPLE__
// Akaros __ros__
// NaCL __native_client__
// AsmJS __asmjs__
// Fuschia __Fuchsia__
#error "unknown compiler"
#endif
#endif
void log() const;
};
#ifndef ENV_BITS_64
#error "ERROR - not 64 bit archytectures are out of support"
#endif
const extern Environment gEnvironment;
typedef char int1;
typedef unsigned char uint1;
typedef short int2;
typedef unsigned short uint2;
typedef unsigned int uint4;
typedef uint2 ufalni;
typedef uint4 uhalni;
typedef int int4;
typedef int4 halni;
typedef unsigned long long uint8;
typedef uint8 ualni;
typedef long long int8;
typedef int8 alni;
typedef double flt8;
typedef flt8 alnf;
typedef float flt4;
typedef flt4 halnf;
#define ENV_INT1_MAX tp::int1(0x7f)
#define ENV_INT1_MIN (-tp::int1(0x80))
#define ENV_UINT1_MAX tp::uint1(0xff)
#define ENV_UINT1_MIN tp::uint1(0x00)
#define ENV_INT2_MAX tp::int2(0x7fff)
#define ENV_INT2_MIN (-tp::int2(0x8000))
#define ENV_UINT2_MAX tp::uint2(0xffff)
#define ENV_UINT2_MIN tp::uint2(0x0000)
#define ENV_UHALNI_MAX tp::uhalni(0xffffffff)
#define ENV_UHALNI_MIN tp::uhalni(0x00000000)
#define ENV_HALNI_MAX tp::halni(0x7fffffff)
#define ENV_HALNI_MIN (-tp::halni(0x80000000))
#define ENV_UALNI_MAX tp::ualni(0xffffffffffffffff)
#define ENV_UALNI_MIN tp::ualni(0x0000000000000000)
#define ENV_ALNI_MAX tp::alni(0x7fffffffffffffff)
#define ENV_ALNI_MIN (-tp::alni(0x8000000000000000))
#define ENV_ALNI_SIZE_B (8)
#define ENV_ALNF_DECIMAL_DIG DBL_DECIMAL_DIG
#define ENV_ALNF_DIG DBL_DIG
#define ENV_ALNF_EPSILON DBL_EPSILON
#define ENV_ALNF_HAS_SUBNORM DBL_HAS_SUBNORM
#define ENV_ALNF_MANT_DIG DBL_MANT_DIG
#define ENV_ALNF_MAX DBL_MAX
#define ENV_ALNF_MAX_10_EXP DBL_MAX_10_EXP
#define ENV_ALNF_MAX_EXP DBL_MAX_EXP
#define ENV_ALNF_MIN DBL_MIN
#define ENV_ALNF_MIN_10_EXP DBL_MIN_10_EXP
#define ENV_ALNF_MIN_EXP DBL_MIN_EXP
#define ENV_ALNF_RADIX _DBL_RADIX
#define ENV_ALNF_TRUE_MIN DBL_TRUE_MIN
#define ENV_HALNF_DECIMAL_DIG FLT_DECIMAL_DIG
#define ENV_HALNF_DIG FLT_DIG
#define ENV_HALNF_EPSILON FLT_EPSILON
#define ENV_HALNF_HAS_SUBNORM FLT_HAS_SUBNORM
#define ENV_HALNF_GUARD FLT_GUARD
#define ENV_HALNF_MANT_DIG FLT_MANT_DIG
#define ENV_HALNF_MAX FLT_MAX
#define ENV_HALNF_MAX_10_EXP FLT_MAX_10_EXP
#define ENV_HALNF_MAX_EXP FLT_MAX_EXP
#define ENV_HALNF_MIN FLT_MIN
#define ENV_HALNF_MIN_10_EXP FLT_MIN_10_EXP
#define ENV_HALNF_MIN_EXP FLT_MIN_EXP
#define ENV_HALNF_NORMALIZE FLT_NORMALIZE
#define ENV_HALNF_RADIX FLT_RADIX
#define ENV_HALNF_TRUE_MIN FLT_TRUE_MIN
};

View file

@ -1,35 +1,35 @@
#pragma once
#include "Common.hpp"
#include "Assert.hpp"
#define MODULE_SANITY_CHECK(name) DEBUG_ASSERT(name.isInitialized() && "Modules Is Not Initialized" && #name)
namespace tp {
class ModuleManifest {
public:
typedef bool (*ModuleInit)(const ModuleManifest*);
typedef void (*ModuleDeinit)(const ModuleManifest*);
ModuleManifest(const char* aModuleName, ModuleInit aInit, ModuleDeinit aDeinit, ModuleManifest** aDependencies);
[[nodiscard]] bool isInitialized() const;
bool initialize(const ModuleManifest* parent = nullptr);
void deinitialize();
[[nodiscard]] const char* getName() const;
void setCustomData(void* data) { mCustomData = data; }
void* getCustomData(void* data) const { return mCustomData; }
private:
const char* mModuleName = nullptr;
ModuleManifest** mDependencies; // NULL terminated
bool mInitialized = false;
ModuleInit mInit = nullptr;
ModuleDeinit mDeinit = nullptr;
uhalni mInitCount = 0;
void* mCustomData = nullptr;
};
extern ModuleManifest gModuleBase;
};
#pragma once
#include "Assert.hpp"
#include "Common.hpp"
#define MODULE_SANITY_CHECK(name) DEBUG_ASSERT(name.isInitialized() && "Modules Is Not Initialized" && #name)
namespace tp {
class ModuleManifest {
public:
typedef bool (*ModuleInit)(const ModuleManifest*);
typedef void (*ModuleDeinit)(const ModuleManifest*);
ModuleManifest(const char* aModuleName, ModuleInit aInit, ModuleDeinit aDeinit, ModuleManifest** aDependencies);
[[nodiscard]] bool isInitialized() const;
bool initialize(const ModuleManifest* parent = nullptr);
void deinitialize();
[[nodiscard]] const char* getName() const;
void setCustomData(void* data) { mCustomData = data; }
void* getCustomData(void* data) const { return mCustomData; }
private:
const char* mModuleName = nullptr;
ModuleManifest** mDependencies; // NULL terminated
bool mInitialized = false;
ModuleInit mInit = nullptr;
ModuleDeinit mDeinit = nullptr;
uhalni mInitCount = 0;
void* mCustomData = nullptr;
};
extern ModuleManifest gModuleBase;
};

View file

@ -8,7 +8,7 @@ namespace tp {
public:
SaveSizeCounter() = default;
template < typename tType>
template <typename tType>
static ualni calc(const tType& val) {
SaveSizeCounter cnt;
cnt << val;
@ -25,19 +25,19 @@ namespace tp {
ualni mSize = 0;
};
// TODO
template <bool tRecursive>
class SizeCounter {
typedef SizeCounter& ArchRef;
template <typename T, typename = void> struct HasSizeCounter : FalseType {};
template <typename T> struct HasSizeCounter<T, VoidType<decltype(DeclareValue<T>()().count(DeclareValue<ArchRef>()()))>> : TrueType {};
template <typename T, typename = void>
struct HasSizeCounter : FalseType {};
template <typename T>
struct HasSizeCounter<T, VoidType<decltype(DeclareValue<T>()().count(DeclareValue<ArchRef>()()))>> : TrueType {};
public:
SizeCounter() = default;
template<typename Type>
template <typename Type>
void count(const Type& val) {
if constexpr (HasSizeCounter<Type>::value) {
val.count(*this);
@ -50,21 +50,13 @@ namespace tp {
}
}
void countSizeUnused(ualni size) {
mSizeUnused += size;
}
void countSizeUnused(ualni size) { mSizeUnused += size; }
void countSize(ualni size) {
mSize += size;
}
void countSize(ualni size) { mSize += size; }
[[nodiscard]] ualni getSizeUnused() const {
return mSizeUnused;
}
[[nodiscard]] ualni getSizeUnused() const { return mSizeUnused; }
[[nodiscard]] ualni getSize() const {
return mSize;
}
[[nodiscard]] ualni getSize() const { return mSize; }
private:
ualni mSize = 0;

File diff suppressed because it is too large Load diff

View file

@ -8,204 +8,204 @@ using namespace tp;
bool sFailed = false;
struct Undef {
char character1 = 'a';
bool boolean = true;
ualni integer = 321;
char character2 = 'a';
char character1 = 'a';
bool boolean = true;
ualni integer = 321;
char character2 = 'a';
void change() {
character1++;
character2--;
integer++;
boolean = !boolean;
}
void change() {
character1++;
character2--;
integer++;
boolean = !boolean;
}
[[nodiscard]] bool operator!=(const Undef& in) const {
if (character1 != in.character1) {
return true;
}
if (character2 != in.character2) {
return true;
}
if (integer != in.integer) {
return true;
}
if (boolean != in.boolean) {
return true;
}
return false;
}
[[nodiscard]] bool operator!=(const Undef& in) const {
if (character1 != in.character1) {
return true;
}
if (character2 != in.character2) {
return true;
}
if (integer != in.integer) {
return true;
}
if (boolean != in.boolean) {
return true;
}
return false;
}
};
struct SimpleArchive {
char character = 'a';
ualni integer = 123;
bool boolean = true;
Undef undef;
char character = 'a';
ualni integer = 123;
bool boolean = true;
Undef undef;
template <typename tArchiver>
void archive(tArchiver& ar) {
ar % character;
ar % integer;
ar % boolean;
ar % undef;
}
template <typename tArchiver>
void archive(tArchiver& ar) {
ar % character;
ar % integer;
ar % boolean;
ar % undef;
}
void change() {
character++;
integer++;
boolean = !boolean;
undef.change();
}
void change() {
character++;
integer++;
boolean = !boolean;
undef.change();
}
[[nodiscard]] bool operator!=(const SimpleArchive& in) const {
if (character != in.character) {
return true;
}
if (integer != in.integer) {
return true;
}
if (boolean != in.boolean) {
return true;
}
if (undef != in.undef) {
return true;
}
return false;
}
[[nodiscard]] bool operator!=(const SimpleArchive& in) const {
if (character != in.character) {
return true;
}
if (integer != in.integer) {
return true;
}
if (boolean != in.boolean) {
return true;
}
if (undef != in.undef) {
return true;
}
return false;
}
};
struct Simple {
char character = 'a';
ualni integer = 123;
bool boolean = true;
Undef undef;
char character = 'a';
ualni integer = 123;
bool boolean = true;
Undef undef;
template <typename tArchiver>
void archiveRead(tArchiver& ar) {
ar >> character;
ar >> integer;
ar >> boolean;
ar >> undef;
}
template <typename tArchiver>
void archiveRead(tArchiver& ar) {
ar >> character;
ar >> integer;
ar >> boolean;
ar >> undef;
}
template <typename tArchiver>
void archiveWrite(tArchiver& ar) const {
ar << character;
ar << integer;
ar << boolean;
ar << undef;
}
template <typename tArchiver>
void archiveWrite(tArchiver& ar) const {
ar << character;
ar << integer;
ar << boolean;
ar << undef;
}
void change() {
character++;
integer++;
boolean = !boolean;
undef.change();
}
void change() {
character++;
integer++;
boolean = !boolean;
undef.change();
}
[[nodiscard]] bool operator!=(const Simple& in) const {
if (character != in.character) {
return true;
}
if (integer != in.integer) {
return true;
}
if (boolean != in.boolean) {
return true;
}
if (undef != in.undef) {
return true;
}
return false;
}
[[nodiscard]] bool operator!=(const Simple& in) const {
if (character != in.character) {
return true;
}
if (integer != in.integer) {
return true;
}
if (boolean != in.boolean) {
return true;
}
if (undef != in.undef) {
return true;
}
return false;
}
};
template <typename tType>
struct Set {
tType buff[10];
ualni len = 5;
tType buff[10];
ualni len = 5;
template <typename tArchiver>
void archiveRead(tArchiver& ar) {
ar >> len;
for (auto i = 0; i < len; i++) {
ar >> buff[i];
}
}
template <typename tArchiver>
void archiveRead(tArchiver& ar) {
ar >> len;
for (auto i = 0; i < len; i++) {
ar >> buff[i];
}
}
template <typename tArchiver>
void archiveWrite(tArchiver& ar) const {
ar << len;
for (auto i = 0; i < len; i++) {
ar << buff[i];
}
}
template <typename tArchiver>
void archiveWrite(tArchiver& ar) const {
ar << len;
for (auto i = 0; i < len; i++) {
ar << buff[i];
}
}
void change() {
len = 2;
for (auto i = 0; i < len; i++) {
buff[i].change();
}
}
void change() {
len = 2;
for (auto i = 0; i < len; i++) {
buff[i].change();
}
}
[[nodiscard]] bool operator!=(const Set& in) const {
for (auto i = 0; i < len; i++) {
if (buff[i] != in.buff[i]) {
return true;
}
}
[[nodiscard]] bool operator!=(const Set& in) const {
for (auto i = 0; i < len; i++) {
if (buff[i] != in.buff[i]) {
return true;
}
}
if (len != in.len) {
return true;
}
return false;
}
if (len != in.len) {
return true;
}
return false;
}
};
template <typename tType>
struct ComplexCart {
Undef undef;
Set<tType> set;
Undef undef;
Set<tType> set;
template <typename tArchiver>
void archive(tArchiver& ar) {
ar % set;
ar % undef;
}
template <typename tArchiver>
void archive(tArchiver& ar) {
ar % set;
ar % undef;
}
void change() {
undef.change();
set.change();
}
void change() {
undef.change();
set.change();
}
[[nodiscard]] bool operator!=(const ComplexCart& in) const { return undef != in.undef || set != in.set; }
[[nodiscard]] bool operator!=(const ComplexCart& in) const { return undef != in.undef || set != in.set; }
};
template <typename tType>
void test() {
constexpr auto size = 1024;
constexpr auto size = 1024;
const tType val;
tType res;
const tType val;
tType res;
res.change();
res.change();
ArchiverExample<size, false> write;
ArchiverExample<size, true> read;
ArchiverExample<size, false> write;
ArchiverExample<size, true> read;
write % val;
write % val;
for (auto i = 0; i < size; i++) {
read.mBuff[i] = write.mBuff[i];
}
for (auto i = 0; i < size; i++) {
read.mBuff[i] = write.mBuff[i];
}
read % res;
read % res;
if (val != res) {
printf("Test %s Failed\n", typeid(tType).name());
sFailed = true;
}
if (val != res) {
printf("Test %s Failed\n", typeid(tType).name());
sFailed = true;
}
}
template <typename T, typename A, typename = void>
@ -215,16 +215,16 @@ template <typename T, typename A>
struct HasArchive<T, A, VoidType<decltype(DeclareValue<T>()().archive(DeclareValue<A&>()()))>> : TrueType {};
void testArchiver() {
printf("has archive method - %i\n", HasArchive<SimpleArchive, ArchiverExample<10, false>>::value);
printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive<SimpleArchive>::value);
printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive<Simple>::value);
printf("has archive method - %i\n", HasArchive<SimpleArchive, ArchiverExample<10, false>>::value);
printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive<SimpleArchive>::value);
printf("has archive method - %i\n", ArchiverExample<10, false>::HasFunc::Archive<Simple>::value);
test<SimpleArchive>();
test<Simple>();
test<Set<Simple>>();
test<ComplexCart<Simple>>();
test<SimpleArchive>();
test<Simple>();
test<Set<Simple>>();
test<ComplexCart<Simple>>();
if (sFailed) {
exit(1);
}
if (sFailed) {
exit(1);
}
}

View file

@ -1,24 +1,24 @@
#include "Module.hpp"
void testArchiver();
int main() {
tp::ModuleManifest* ModuleDependencies[] = { &tp::gModuleBase, nullptr };
tp::ModuleManifest TestModule("Test", nullptr, nullptr, ModuleDependencies);
if (!TestModule.initialize()) {
return 1;
}
ASSERT(tp::gEnvironment.mWidth == tp::Environment::ArchWidth::X64);
ASSERT(tp::max(2, 1) == 2)
ASSERT(tp::max(-1, 0) == 0)
ASSERT(tp::max(0, -1) == 0)
ASSERT(tp::min(0, -1) == -1)
testArchiver();
TestModule.deinitialize();
#include "Module.hpp"
void testArchiver();
int main() {
tp::ModuleManifest* ModuleDependencies[] = { &tp::gModuleBase, nullptr };
tp::ModuleManifest TestModule("Test", nullptr, nullptr, ModuleDependencies);
if (!TestModule.initialize()) {
return 1;
}
ASSERT(tp::gEnvironment.mWidth == tp::Environment::ArchWidth::X64);
ASSERT(tp::max(2, 1) == 2)
ASSERT(tp::max(-1, 0) == 0)
ASSERT(tp::max(0, -1) == 0)
ASSERT(tp::min(0, -1) == -1)
testArchiver();
TestModule.deinitialize();
}