summaryrefslogtreecommitdiffhomepage
path: root/CRTKit
diff options
context:
space:
mode:
Diffstat (limited to 'CRTKit')
-rw-r--r--CRTKit/__mpcc_alloca.hxx15
-rw-r--r--CRTKit/__mpcc_defines.hxx98
-rw-r--r--CRTKit/__mpcc_exception.hxx35
-rw-r--r--CRTKit/__mpcc_malloc.hxx30
4 files changed, 178 insertions, 0 deletions
diff --git a/CRTKit/__mpcc_alloca.hxx b/CRTKit/__mpcc_alloca.hxx
new file mode 100644
index 00000000..02b31230
--- /dev/null
+++ b/CRTKit/__mpcc_alloca.hxx
@@ -0,0 +1,15 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies
+
+------------------------------------------- */
+
+#pragma once
+
+typedef void* ptr_type;
+typedef __SIZE_TYPE__ size_type;
+
+inline void* __mpcc_alloca_gcc(size_type sz)
+{
+ return __builtin_alloca(sz);
+}
diff --git a/CRTKit/__mpcc_defines.hxx b/CRTKit/__mpcc_defines.hxx
new file mode 100644
index 00000000..9dfe51af
--- /dev/null
+++ b/CRTKit/__mpcc_defines.hxx
@@ -0,0 +1,98 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies
+
+------------------------------------------- */
+
+#ifndef __MPCC_DEFINES_HXX__
+#define __MPCC_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 <CRT/__mpcc_alloca.hxx>
+#define __mpcc_alloca(sz) __mpcc_alloca_gcc(sz)
+#elif defined(__NDK__)
+
+#define __alloca(sz) __mpcc_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 <CRT/__mpcc_exception.hxx>
+#include <CRT/__mpcc_malloc.hxx>
+
+#endif // ifdef __STD_CXX__
+
+#endif /* __MPCC_DEFINES_HXX__ */
diff --git a/CRTKit/__mpcc_exception.hxx b/CRTKit/__mpcc_exception.hxx
new file mode 100644
index 00000000..012ff43f
--- /dev/null
+++ b/CRTKit/__mpcc_exception.hxx
@@ -0,0 +1,35 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies
+
+------------------------------------------- */
+
+#pragma once
+
+extern "C" int __exit(int code);
+/// @brief Standard C++ namespace
+namespace std
+{
+ class ofstream;
+
+ extern ofstream cout;
+
+ inline void __throw_general(void)
+ {
+ __exit(33);
+ }
+
+ inline void __throw_domain_error(const char* error)
+ {
+ cout << "ZKA C++: Domain error: " << error << "\r";
+ __throw_general();
+ __builtin_unreachable(); // prevent from continuing.
+ }
+
+ inline void __throw_bad_array_new_length(void)
+ {
+ cout << "ZKAC C++: Bad array length.\r";
+ __throw_general();
+ __builtin_unreachable(); // prevent from continuing.
+ }
+} // namespace std
diff --git a/CRTKit/__mpcc_malloc.hxx b/CRTKit/__mpcc_malloc.hxx
new file mode 100644
index 00000000..95a27f86
--- /dev/null
+++ b/CRTKit/__mpcc_malloc.hxx
@@ -0,0 +1,30 @@
+/* -------------------------------------------
+
+ Copyright ZKA Technologies
+
+------------------------------------------- */
+
+#pragma once
+
+#include <NewKit/Defines.hxx>
+
+namespace stdx
+{
+ /// @brief allocate a new class.
+ /// @tparam KindClass the class type to allocate.
+ template <typename KindClass, typename... Args>
+ inline Kernel::VoidPtr allocate(Args&&... args)
+ {
+ return new KindClass(Kernel::forward(args)...);
+ }
+
+ /// @brief free a class.
+ /// @tparam KindClass the class type to allocate.
+ template <typename KindClass>
+ inline Kernel::Void release(KindClass ptr)
+ {
+ if (!ptr)
+ return;
+ delete ptr;
+ }
+} // namespace stdx