summaryrefslogtreecommitdiffhomepage
path: root/dev/LibC++
diff options
context:
space:
mode:
Diffstat (limited to 'dev/LibC++')
-rw-r--r--dev/LibC++/base_alloc.hxx49
-rw-r--r--dev/LibC++/base_exception.hxx30
-rw-r--r--dev/LibC++/defines.hxx125
-rw-r--r--dev/LibC++/exit.hxx21
-rw-r--r--dev/LibC++/math.hxx62
-rw-r--r--dev/LibC++/power64.inc35
6 files changed, 322 insertions, 0 deletions
diff --git a/dev/LibC++/base_alloc.hxx b/dev/LibC++/base_alloc.hxx
new file mode 100644
index 0000000..51ed861
--- /dev/null
+++ b/dev/LibC++/base_alloc.hxx
@@ -0,0 +1,49 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <LibC++/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/LibC++/base_exception.hxx b/dev/LibC++/base_exception.hxx
new file mode 100644
index 0000000..9efe209
--- /dev/null
+++ b/dev/LibC++/base_exception.hxx
@@ -0,0 +1,30 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <LibC++/defines.hxx>
+#include <LibC++/exit.hxx>
+
+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/LibC++/defines.hxx b/dev/LibC++/defines.hxx
new file mode 100644
index 0000000..c65b254
--- /dev/null
+++ b/dev/LibC++/defines.hxx
@@ -0,0 +1,125 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+#ifndef __NDK_DEFINES_HXX__
+#define __NDK_DEFINES_HXX__
+
+#include <stdint.h>
+#include <stddef.h>
+
+#ifndef __GNUC__
+
+typedef __SIZE_TYPE__ size_t;
+
+#ifdef __LP64__
+typedef long int ssize_t;
+#else
+typedef int ssize_t;
+#endif // __LP64__
+
+typedef void* ptr_type;
+typedef __SIZE_TYPE__ size_type;
+
+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 <LibC++/alloca.hxx>
+#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 <LibC++/base_exception.hxx>
+#include <LibC++/base_alloc.hxx>
+
+#endif // ifdef __STD_CXX__
+
+namespace std
+{
+ /// @brief Forward object.
+ /// @tparam Args the object type.
+ /// @param arg the object.
+ /// @return object's rvalue
+ template <typename Args>
+ inline Args&& forward(Args& arg)
+ {
+ return static_cast<Args&&>(arg);
+ }
+
+ /// @brief Move object.
+ /// @tparam Args the object type.
+ /// @param arg the object.
+ /// @return object's rvalue
+ template <typename Args>
+ inline Args&& move(Args&& arg)
+ {
+ return static_cast<Args&&>(arg);
+ }
+} // namespace std
+
+#endif /* __NDK_DEFINES_HXX__ */
diff --git a/dev/LibC++/exit.hxx b/dev/LibC++/exit.hxx
new file mode 100644
index 0000000..0878e43
--- /dev/null
+++ b/dev/LibC++/exit.hxx
@@ -0,0 +1,21 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+#pragma once
+
+/// @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 int exit(int code)
+ {
+ exit(code);
+ }
+} // namespace std
diff --git a/dev/LibC++/math.hxx b/dev/LibC++/math.hxx
new file mode 100644
index 0000000..b6cd6a8
--- /dev/null
+++ b/dev/LibC++/math.hxx
@@ -0,0 +1,62 @@
+/* -------------------------------------------
+
+ Copyright ZKA Web Services Co.
+
+------------------------------------------- */
+
+#pragma once
+
+#include <LibC++/defines.hxx>
+
+/// @file Math.hxx
+/// @brief Math functions.
+
+#ifdef __ZKA_USE_DOUBLE__
+typedef double real_type;
+#else
+typedef float real_type;
+#endif
+
+namespace std::math
+{
+ /// @brief Power function, with Repeat argument.
+ 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.
+
+ if (Exponent == 1)
+ return in; // Any number to the power of 1 is itself.
+
+ size_t cnt = Exponent;
+
+ real_type result = 1;
+
+ for (auto i = 0; i < cnt; ++i)
+ result *= in;
+
+ return result;
+ }
+
+ /// @brief Square of function, with Base template argument.
+ /// @param of Base argument to find sqquare of
+ template <size_t Base>
+ inline real_type sqr(real_type in)
+ {
+ if (in == 0)
+ return 0;
+
+ 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_type lerp(real_type to, real_type from, real_type stat)
+ {
+ real_type diff = (to - from);
+ return from + (diff * stat);
+ }
+} // namespace std::math
diff --git a/dev/LibC++/power64.inc b/dev/LibC++/power64.inc
new file mode 100644
index 0000000..33523a3
--- /dev/null
+++ b/dev/LibC++/power64.inc
@@ -0,0 +1,35 @@
+# Path: LibC++/power.inc
+# Language: NDK POWER Assembly support for GNU.
+# Build Date: 2024-6-4
+
+%ifdef __NDK__
+
+%define lda li
+%define sta stw
+%define ldw li
+
+%define r0 0
+%define r1 1
+%define r2 2
+%define r3 3
+%define r4 4
+%define r5 5
+%define r6 6
+%define r7 7
+%define r8 8
+%define r9 9
+%define r10 10
+%define r11 11
+%define r12 12
+%define r13 13
+%define r14 14
+%define r15 15
+%define r16 16
+%define r17 17
+%define r18 18
+%define r19 19
+%define r20 20
+
+%endif
+
+%define nop mr 0, 0