From 421db65331663304466577b7187780d9eba18077 Mon Sep 17 00:00:00 2001 From: Amlal Date: Sat, 28 Sep 2024 19:13:46 +0200 Subject: feat: Add common XPCOM controls directory, restructure project, and introduce API breaking changes - Added a new directory for common XPCOM controls to organize reusable components. - Restructured project layout for better modularity and maintainability. - Introduced API breaking changes in the process, requiring adjustments for backward compatibility. Signed-off-by: Amlal --- dev/crt/ReadMe.md | 2 +- dev/crt/__ndk_alloca.hxx | 18 ------ dev/crt/__ndk_defines.hxx | 121 ----------------------------------------- dev/crt/__ndk_exception.hxx | 35 ------------ dev/crt/__ndk_new_delete.hxx | 28 ---------- dev/crt/alloca.hxx | 18 ++++++ dev/crt/base_alloc.hxx | 49 +++++++++++++++++ dev/crt/base_exception.hxx | 35 ++++++++++++ dev/crt/crt.json | 4 +- dev/crt/defines.hxx | 124 ++++++++++++++++++++++++++++++++++++++++++ dev/crt/math.hxx | 34 ++++++------ dev/crt/src/__ndk_runtime.cxx | 12 ---- dev/crt/src/crt_lib.cxx | 13 +++++ 13 files changed, 258 insertions(+), 235 deletions(-) delete mode 100644 dev/crt/__ndk_alloca.hxx delete mode 100644 dev/crt/__ndk_defines.hxx delete mode 100644 dev/crt/__ndk_exception.hxx delete mode 100644 dev/crt/__ndk_new_delete.hxx create mode 100644 dev/crt/alloca.hxx create mode 100644 dev/crt/base_alloc.hxx create mode 100644 dev/crt/base_exception.hxx create mode 100644 dev/crt/defines.hxx delete mode 100644 dev/crt/src/__ndk_runtime.cxx create mode 100644 dev/crt/src/crt_lib.cxx (limited to 'dev/crt') diff --git a/dev/crt/ReadMe.md b/dev/crt/ReadMe.md index c90f5b5f..4f8ad4f5 100644 --- a/dev/crt/ReadMe.md +++ b/dev/crt/ReadMe.md @@ -1,4 +1,4 @@ -# ZKA C++ RunTime. +# ZKA C++ RunTime Kit. This is the public interface of ZKA' C++ RunTime. diff --git a/dev/crt/__ndk_alloca.hxx b/dev/crt/__ndk_alloca.hxx deleted file mode 100644 index 3c796bf2..00000000 --- a/dev/crt/__ndk_alloca.hxx +++ /dev/null @@ -1,18 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - - File: __ndk_alloca.hxx - Purpose: Stack allocation functions. - -------------------------------------------- */ - -#pragma once - -typedef void* ptr_type; -typedef __SIZE_TYPE__ size_type; - -inline ptr_type __ndk_alloca(size_type sz) -{ - return __builtin_alloca(sz); -} diff --git a/dev/crt/__ndk_defines.hxx b/dev/crt/__ndk_defines.hxx deleted file mode 100644 index bea3f67c..00000000 --- a/dev/crt/__ndk_defines.hxx +++ /dev/null @@ -1,121 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#ifndef __NDK_DEFINES_HXX__ -#define __NDK_DEFINES_HXX__ - -#ifndef __GNUC__ - -typedef __SIZE_TYPE__ size_t; - -#ifdef __LP64__ -typedef long int ssize_t; -#else -typedef int ssize_t; -#endif // __LP64__ - -typedef size_t ptrdiff_t; -typedef size_t uintptr_t; -typedef void* voidptr_t; -typedef void* any_t; -typedef char* caddr_t; - -#ifndef NULL -#define NULL ((voidptr_t)0) -#endif // !null - -#ifdef __GNUC__ -#include -#define __ndk_alloca(sz) __ndk_alloca(sz) -#elif defined(__NDK__) - -#define __alloca(sz) __ndk_alloca(sz) -#endif - -#define __deref(ptr) (*(ptr)) - -#ifdef __cplusplus -#define __init_decl() \ - extern "C" \ - { -#define __fini_decl() \ - } \ - ; -#else -#define __init_decl() -#define __fini_decl() -#endif - -#if __has_builtin(__builtin_alloca) -#define alloca(sz) __builtin_alloca(sz) -#ifdef __alloca -#undef __alloca -#endif -#define __alloca alloca -#else -#warning alloca not detected -#endif - -typedef long long off_t; -typedef unsigned long long uoff_t; - -typedef union float_cast { - struct - { - unsigned int mantissa : 23; - unsigned int exponent : 8; - unsigned int sign : 1; - }; - - float f; -} __attribute__((packed)) float_cast_t; - -typedef union double_cast { - struct - { - unsigned long long int mantissa : 52; - unsigned int exponent : 11; - unsigned int sign : 1; - }; - - double f; -} __attribute__((packed)) double_cast_t; - -#endif // ifndef __GNUC__ - -/// Include these helpers as well. - -#ifdef __STD_CXX__ - -#include -#include - -#endif // ifdef __STD_CXX__ - -namespace std -{ - /// @brief Forward object. - /// @tparam Args the object type. - /// @param arg the object. - /// @return object's rvalue - template - inline Args&& forward(Args& arg) - { - return static_cast(arg); - } - - /// @brief Move object. - /// @tparam Args the object type. - /// @param arg the object. - /// @return object's rvalue - template - inline Args&& move(Args&& arg) - { - return static_cast(arg); - } -} // namespace std - -#endif /* __NDK_DEFINES_HXX__ */ diff --git a/dev/crt/__ndk_exception.hxx b/dev/crt/__ndk_exception.hxx deleted file mode 100644 index 67735a9d..00000000 --- a/dev/crt/__ndk_exception.hxx +++ /dev/null @@ -1,35 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#pragma once - -#include - -/// @brief CRT exit, with exit code (!!! exits all threads. !!!) -/// @param code -/// @return -extern "C" int __exit(int code); - -/// @brief Standard C++ namespace -namespace std -{ - inline void __throw_general(void) - { - __exit(33); - } - - inline void __throw_domain_error(const char* error) - { - __throw_general(); - __builtin_unreachable(); // prevent from continuing. - } - - inline void __throw_bad_array_new_length(void) - { - __throw_general(); - __builtin_unreachable(); // prevent from continuing. - } -} // namespace std diff --git a/dev/crt/__ndk_new_delete.hxx b/dev/crt/__ndk_new_delete.hxx deleted file mode 100644 index fad61aa9..00000000 --- a/dev/crt/__ndk_new_delete.hxx +++ /dev/null @@ -1,28 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#pragma once - -#include - -namespace stdx -{ - /// @brief allocate a new class. - /// @tparam KindClass the class type to allocate. - template - inline void* allocate(Args&&... args) - { - return new KindClass(forward(args)...); - } - - /// @brief free a class. - /// @tparam KindClass the class type to allocate. - template - inline void release(KindClass ptr) - { - delete ptr; - } -} // namespace stdx diff --git a/dev/crt/alloca.hxx b/dev/crt/alloca.hxx new file mode 100644 index 00000000..fedcb25d --- /dev/null +++ b/dev/crt/alloca.hxx @@ -0,0 +1,18 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + + File: alloca.hxx + Purpose: Stack allocation functions. + +------------------------------------------- */ + +#pragma once + +typedef void* ptr_type; +typedef __SIZE_TYPE__ size_type; + +inline ptr_type __ndk_alloca(size_type sz) +{ + return __builtin_alloca(sz); +} diff --git a/dev/crt/base_alloc.hxx b/dev/crt/base_alloc.hxx new file mode 100644 index 00000000..de157866 --- /dev/null +++ b/dev/crt/base_alloc.hxx @@ -0,0 +1,49 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include + +namespace std::base_alloc +{ + /// @brief allocate a new class. + /// @tparam KindClass the class type to allocate. + template + inline KindClass* allocate(Args&&... args) + { + return new KindClass(forward(args)...); + } + + /// @brief allocate a new class. + /// @note aborts on error. + /// @tparam KindClass the class type to allocate. + template + inline KindClass* allocate_nothrow(Args&&... args) noexcept + { + return allocate(forward(args)...); + } + + /// @brief free a class. + /// @tparam KindClass the class type to allocate. + template + inline void release(KindClass ptr) + { + if (!ptr) + return; + + delete ptr; + } + + /// @brief destroy and free a class. + /// @note aborts on error. + /// @tparam KindClass the class type to allocate. + template + inline void release_nothrow(KindClass ptr) noexcept + { + release(ptr); + } +} // namespace std::base_alloc diff --git a/dev/crt/base_exception.hxx b/dev/crt/base_exception.hxx new file mode 100644 index 00000000..9d3fd208 --- /dev/null +++ b/dev/crt/base_exception.hxx @@ -0,0 +1,35 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#pragma once + +#include + +/// @brief CRT exit, with exit code (!!! exits all threads. !!!) +/// @param code +/// @return +extern "C" int __exit(int code); + +/// @brief Standard C++ namespace +namespace std +{ + inline void __throw_general(void) + { + __exit(33); + } + + inline void __throw_domain_error(const char* error) + { + __throw_general(); + __builtin_unreachable(); // prevent from continuing. + } + + inline void __throw_bad_array_new_length(void) + { + __throw_general(); + __builtin_unreachable(); // prevent from continuing. + } +} // namespace std diff --git a/dev/crt/crt.json b/dev/crt/crt.json index dbca05fa..07368550 100644 --- a/dev/crt/crt.json +++ b/dev/crt/crt.json @@ -3,13 +3,13 @@ "compiler_std": "c++20", "headers_path": ["../", "./"], "sources_path": ["src/*.cxx"], - "output_name": "ndkcrt.dll", + "output_name": "zka-crt-cxx.dll", "compiler_flags": [ "-ffreestanding", "-shared", "-fno-rtti", "-fno-exceptions", - " -Wl,--subsystem=17" + "-Wl,--subsystem=17" ], "cpp_macros": [ "__CRT_AMD64__", diff --git a/dev/crt/defines.hxx b/dev/crt/defines.hxx new file mode 100644 index 00000000..11a76ded --- /dev/null +++ b/dev/crt/defines.hxx @@ -0,0 +1,124 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#ifndef __NDK_DEFINES_HXX__ +#define __NDK_DEFINES_HXX__ + +#include +#include + +#ifndef __GNUC__ + +typedef __SIZE_TYPE__ size_t; + +#ifdef __LP64__ +typedef long int ssize_t; +#else +typedef int ssize_t; +#endif // __LP64__ + +typedef size_t ptrdiff_t; +typedef size_t uintptr_t; +typedef void* voidptr_t; +typedef void* any_t; +typedef char* caddr_t; + +#ifndef NULL +#define NULL ((voidptr_t)0) +#endif // !null + +#ifdef __GNUC__ +#include +#define __ndk_alloca(sz) __ndk_alloca(sz) +#elif defined(__NDK__) + +#define __alloca(sz) __ndk_alloca(sz) +#endif + +#define __deref(ptr) (*(ptr)) + +#ifdef __cplusplus +#define __init_decl() \ + extern "C" \ + { +#define __fini_decl() \ + } \ + ; +#else +#define __init_decl() +#define __fini_decl() +#endif + +#if __has_builtin(__builtin_alloca) +#define alloca(sz) __builtin_alloca(sz) +#ifdef __alloca +#undef __alloca +#endif +#define __alloca alloca +#else +#warning alloca not detected +#endif + +typedef long long off_t; +typedef unsigned long long uoff_t; + +typedef union float_cast { + struct + { + unsigned int mantissa : 23; + unsigned int exponent : 8; + unsigned int sign : 1; + }; + + float f; +} __attribute__((packed)) float_cast_t; + +typedef union double_cast { + struct + { + unsigned long long int mantissa : 52; + unsigned int exponent : 11; + unsigned int sign : 1; + }; + + double f; +} __attribute__((packed)) double_cast_t; + +#endif // ifndef __GNUC__ + +/// Include these helpers as well. + +#ifdef __STD_CXX__ + +#include +#include + +#endif // ifdef __STD_CXX__ + +namespace std +{ + /// @brief Forward object. + /// @tparam Args the object type. + /// @param arg the object. + /// @return object's rvalue + template + inline Args&& forward(Args& arg) + { + return static_cast(arg); + } + + /// @brief Move object. + /// @tparam Args the object type. + /// @param arg the object. + /// @return object's rvalue + template + inline Args&& move(Args&& arg) + { + return static_cast(arg); + } +} // namespace std + +#endif /* __NDK_DEFINES_HXX__ */ diff --git a/dev/crt/math.hxx b/dev/crt/math.hxx index 5f55b430..56bb1236 100644 --- a/dev/crt/math.hxx +++ b/dev/crt/math.hxx @@ -6,24 +6,22 @@ #pragma once -#include +#include /// @file Math.hxx /// @brief Math functions. -namespace CRT -{ - using namespace Kernel; - #ifdef __ZKA_USE_DOUBLE__ - typedef double Real; +typedef double real_type; #else - typedef float Real; +typedef float real_type; #endif +namespace std::math +{ /// @brief Power function, with Repeat argument. - template - inline Real Pow(Real in) + template + inline real_type pow(real_type in) { if (Exponent == 0) return 1; // Any number to the power of 0 is 1. @@ -31,11 +29,11 @@ namespace CRT if (Exponent == 1) return in; // Any number to the power of 1 is itself. - UInt64 cnt = Exponent; + size_t cnt = Exponent; - Real result = 1; + real_type result = 1; - for (auto i = 0; i < (cnt); ++i) + for (auto i = 0; i < cnt; ++i) result *= in; return result; @@ -43,22 +41,22 @@ namespace CRT /// @brief Square of function, with Base template argument. /// @param of Base argument to find sqquare of - template - inline Real SqrOf(Real in) + template + inline real_type sqr(real_type in) { if (in == 0) return 0; - return Pow<1 / Base>(in); + return pow<1 / Base>(in); } /// @brief Linear interpolation equation solver. /// @param from where? /// @param to to? /// @param Updated diff value according to difference. - inline Real CGLerp(Real to, Real from, Real stat) + inline real_type lerp(real_type to, real_type from, real_type stat) { - Real diff = (to - from); + real_type diff = (to - from); return from + (diff * stat); } -} // namespace CRT +} // namespace std::math diff --git a/dev/crt/src/__ndk_runtime.cxx b/dev/crt/src/__ndk_runtime.cxx deleted file mode 100644 index b81963a8..00000000 --- a/dev/crt/src/__ndk_runtime.cxx +++ /dev/null @@ -1,12 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Technologies. - -------------------------------------------- */ - -#include -#include -#include -#include - -/// @note No sources needed for now. diff --git a/dev/crt/src/crt_lib.cxx b/dev/crt/src/crt_lib.cxx new file mode 100644 index 00000000..530e40db --- /dev/null +++ b/dev/crt/src/crt_lib.cxx @@ -0,0 +1,13 @@ +/* ------------------------------------------- + + Copyright ZKA Technologies. + +------------------------------------------- */ + +#include +#include +#include +#include +#include + +/// @note Just here for building. -- cgit v1.2.3