diff options
Diffstat (limited to 'dev/crt')
| -rw-r--r-- | dev/crt/ReadMe.md | 2 | ||||
| -rw-r--r-- | dev/crt/__ndk_new_delete.hxx | 28 | ||||
| -rw-r--r-- | dev/crt/alloca.hxx (renamed from dev/crt/__ndk_alloca.hxx) | 2 | ||||
| -rw-r--r-- | dev/crt/base_alloc.hxx | 49 | ||||
| -rw-r--r-- | dev/crt/base_exception.hxx (renamed from dev/crt/__ndk_exception.hxx) | 2 | ||||
| -rw-r--r-- | dev/crt/crt.json | 4 | ||||
| -rw-r--r-- | dev/crt/defines.hxx (renamed from dev/crt/__ndk_defines.hxx) | 3 | ||||
| -rw-r--r-- | dev/crt/math.hxx | 34 | ||||
| -rw-r--r-- | dev/crt/src/__ndk_runtime.cxx | 12 | ||||
| -rw-r--r-- | dev/crt/src/crt_lib.cxx | 13 |
10 files changed, 86 insertions, 63 deletions
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_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 <crt/__ndk_defines.hxx> - -namespace stdx -{ - /// @brief allocate a new class. - /// @tparam KindClass the class type to allocate. - template <typename KindClass, typename... Args> - inline void* allocate(Args&&... args) - { - return new KindClass(forward(args)...); - } - - /// @brief free a class. - /// @tparam KindClass the class type to allocate. - template <typename KindClass> - inline void release(KindClass ptr) - { - delete ptr; - } -} // namespace stdx diff --git a/dev/crt/__ndk_alloca.hxx b/dev/crt/alloca.hxx index 3c796bf2..fedcb25d 100644 --- a/dev/crt/__ndk_alloca.hxx +++ b/dev/crt/alloca.hxx @@ -2,7 +2,7 @@ Copyright ZKA Technologies. - File: __ndk_alloca.hxx + File: alloca.hxx Purpose: Stack allocation functions. ------------------------------------------- */ 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 <crt/defines.hxx> + +namespace std::base_alloc +{ + /// @brief allocate a new class. + /// @tparam KindClass the class type to allocate. + template <typename KindClass, typename... Args> + 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 <typename KindClass, typename... Args> + inline KindClass* allocate_nothrow(Args&&... args) noexcept + { + return allocate(forward(args)...); + } + + /// @brief free a class. + /// @tparam KindClass the class type to allocate. + template <typename KindClass> + 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 <typename KindClass> + inline void release_nothrow(KindClass ptr) noexcept + { + release(ptr); + } +} // namespace std::base_alloc diff --git a/dev/crt/__ndk_exception.hxx b/dev/crt/base_exception.hxx index 67735a9d..9d3fd208 100644 --- a/dev/crt/__ndk_exception.hxx +++ b/dev/crt/base_exception.hxx @@ -6,7 +6,7 @@ #pragma once -#include <crt/__ndk_defines.hxx> +#include <crt/defines.hxx> /// @brief CRT exit, with exit code (!!! exits all threads. !!!) /// @param code 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/__ndk_defines.hxx b/dev/crt/defines.hxx index bea3f67c..11a76ded 100644 --- a/dev/crt/__ndk_defines.hxx +++ b/dev/crt/defines.hxx @@ -7,6 +7,9 @@ #ifndef __NDK_DEFINES_HXX__ #define __NDK_DEFINES_HXX__ +#include <stdint.h> +#include <stddef.h> + #ifndef __GNUC__ typedef __SIZE_TYPE__ size_t; 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 <NewKit/Defines.hxx> +#include <crt/defines.hxx> /// @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 <SizeT Exponent> - inline Real Pow(Real in) + template <size_t Exponent> + 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 <SizeT Base> - inline Real SqrOf(Real in) + template <size_t Base> + 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 <crt/__ndk_alloca.hxx>
-#include <crt/__ndk_defines.hxx>
-#include <crt/__ndk_exception.hxx>
-#include <crt/__ndk_new_delete.hxx>
-
-/// @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 <crt/alloca.hxx>
+#include <crt/defines.hxx>
+#include <crt/base_exception.hxx>
+#include <crt/math.hxx>
+#include <crt/base_alloc.hxx>
+
+/// @note Just here for building.
|
